:root {
  --navy: #0b1f4d; --blue: #1a73e8; --blue-soft: #e8f0fe; --bg: #f5f7fb; --card: #ffffff; --text: #0f1b33; --muted: #5f6b7d;
  --line: #e3e8f0; --ok: #137333; --ok-soft: #e6f4ea; --warn: #8a5a00; --warn-soft: #fef7e0; --err: #b3261e; --err-soft: #fce8e6;
  --radius: 14px; --tap: 46px;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1220; --card: #131c2e; --text: #e8edf6; --muted: #9aa6b8; --line: #243149; --blue-soft: #16264a;
    --ok-soft: #12301f; --warn-soft: #3a2f10; --err-soft: #3b1513; --navy: #c9d6f2; --ok: #81c995; --warn: #f2c94c; --err: #f28b82; --blue: #6ea8fe; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
body.bare { padding-bottom: 24px; }
main { max-width: 860px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left)); }
a { color: var(--blue); text-decoration: none; }
h1 { font-size: 1.5rem; margin: 8px 0 14px; color: var(--navy); }
h2 { font-size: 1.1rem; margin: 22px 0 10px; color: var(--navy); }
.muted { color: var(--muted); } .small { font-size: .85rem; }
code { font-size: .8rem; word-break: break-all; }

.top { position: sticky; top: 0; z-index: 5; background: #0b1f4d; padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: #fff; max-width: 860px; margin: 0 auto; font-size: 1.05rem; }
.brand img { height: 30px; width: 30px; border-radius: 8px; background: #fff; object-fit: contain; padding: 2px; }
body.bare { padding-top: env(safe-area-inset-top); }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: .72rem; color: var(--muted); min-height: 56px; }
.tabs a.on { color: var(--blue); font-weight: 600; }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.card.narrow { max-width: 460px; margin: 24px auto; }
.card.ok { background: var(--ok-soft); border-color: transparent; }
.card.warn, p.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.card.error { background: var(--err-soft); border-color: transparent; }
.card.block { display: block; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.head h1 { margin: 8px 0; }
.actions { display: flex; gap: 10px; align-items: center; }
.actions.wrap { flex-wrap: wrap; margin: 12px 0; }
.row2, .row3 { display: grid; gap: 12px; grid-template-columns: 1fr; align-items: end; }
@media (min-width: 640px) { .row2 { grid-template-columns: 1fr 1fr; } .row3 { grid-template-columns: 1fr 1fr 1fr; } }

label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; font-weight: 600; color: var(--muted); }
label.check { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 500; color: var(--text); }
label.check input { width: 22px; height: 22px; margin-top: 1px; flex: none; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: var(--tap); width: 100%; }
textarea { resize: vertical; min-height: var(--tap); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 0; border-color: var(--blue); }
.seg { display: flex; gap: 8px; }
.seg label { flex: 1; flex-direction: row; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; min-height: var(--tap); color: var(--text); }
.seg input { width: auto; min-height: 0; }

button, .button { font: inherit; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--navy); cursor: pointer; text-align: center; }
button.primary, .button.primary { background: #1a73e8; color: #fff; border-color: #1a73e8; }
button.big, .button.big { min-height: 54px; font-size: 1.05rem; width: 100%; }
button.danger { color: var(--err); }
button.link { background: none; border: 0; color: var(--muted); text-decoration: underline; }
button.icon { min-height: 40px; padding: 0 10px; color: var(--muted); }
.inline { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.inline label { flex-direction: row; align-items: center; }
.inline input { width: 70px; }

.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 6px 0 14px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.kpi span { color: var(--muted); font-size: .82rem; }
.kpi b { font-size: 1.2rem; color: var(--navy); }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(3, 1fr); } }

.list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.list a { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 12px 14px; color: var(--text); min-height: 56px; align-items: center; }
.list a .muted { grid-column: 1; font-size: .85rem; }
.list a .amount { grid-column: 2; grid-row: 1; font-weight: 600; text-align: right; }
.list a .badge { grid-column: 2; grid-row: 2; justify-self: end; }
.list.menu a { grid-template-columns: 1fr; }
.amount.late, .late { color: var(--err); }
.paid { color: var(--ok); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 24px; }
.plain { padding-left: 18px; }
.search { margin-bottom: 12px; }

.badge { font-size: .72rem; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: var(--line); color: var(--muted); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.green { background: var(--ok-soft); color: var(--ok); }
.badge.red { background: var(--err-soft); color: var(--err); }
.pill { display: inline-block; background: var(--blue-soft); color: var(--blue); border-radius: 99px; padding: 4px 12px; font-size: .85rem; font-weight: 600; margin: 0; }

.flash { padding: 12px 14px; border-radius: 12px; margin-bottom: 12px; font-weight: 600; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error, .error { background: var(--err-soft); color: var(--err); padding: 12px 14px; border-radius: 12px; }
.error ul { margin: 6px 0 0; padding-left: 18px; }

.lines { display: flex; flex-direction: column; gap: 10px; }
.line { position: relative; display: grid; grid-template-columns: 58px minmax(0, 1fr) 86px; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); align-items: end; }
.line .f { gap: 4px; font-size: .75rem; min-width: 0; }
.line .f-label { grid-column: 1 / -1; padding-right: 36px; }
.line .icon { position: absolute; top: 6px; right: 6px; min-height: 36px; width: 36px; padding: 0; border: 0; background: transparent; }
@media (min-width: 720px) {
  .line { grid-template-columns: minmax(0, 1fr) 70px 120px 90px 40px; }
  .line .f-label { grid-column: auto; padding-right: 0; }
  .line .icon { position: static; align-self: end; min-height: var(--tap); }
}
.totals { text-align: right; font-weight: 600; }
.totals div { display: flex; justify-content: flex-end; gap: 16px; }
.totals .grand { font-size: 1.15rem; color: var(--blue); }

.summary p { margin: 6px 0; }
.big-amount { font-size: 1.8rem; font-weight: 700; color: var(--navy); }
.login-logo { display: block; max-width: 200px; margin: 0 auto 8px; }
.qr { display: block; margin: 8px auto; border-radius: 8px; background: #fff; padding: 6px; }
details summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; font-size: .9rem; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }

.company-search { position: relative; }
.suggestions { margin-top: 6px; }
.suggestions a { grid-template-columns: 1fr; }
.item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 14px; }

.pin { font-size: 1.6rem; letter-spacing: .5em; text-align: center; }
.center { text-align: center; margin: 0; }

/* iPhone : champs de date à la bonne largeur, sans style natif qui déborde. */
input[type=date] { -webkit-appearance: none; appearance: none; display: block; min-width: 0; text-align: left; }
input[type=date]::-webkit-date-and-time-value { text-align: left; }
select { -webkit-appearance: none; appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 28px; }
.card h2 { margin: 0 0 4px; }
.kpis .kpi:nth-child(3) { grid-column: 1 / -1; }
@media (min-width: 640px) { .kpis .kpi:nth-child(3) { grid-column: auto; } }
.actions.two > * { flex: 1 1 140px; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.login-logo { background: #fff; border-radius: 14px; padding: 10px; }
.head h1 { font-size: 1.35rem; }
.list a b { overflow-wrap: anywhere; }
[hidden] { display: none !important; }
p:empty { display: none; }
.viewer-bar { position: sticky; top: calc(50px + env(safe-area-inset-top)); z-index: 4; display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; background: var(--bg); }
.pdf-pages { display: flex; flex-direction: column; gap: 12px; }
.pdf-pages canvas { display: block; background: #fff; border-radius: 6px; box-shadow: 0 1px 6px rgba(0, 0, 0, .25); }
