/* Factures Pharmacies HAC
   Registre de créances : bandeau des soldes en tête, onglets, liste dense lisible au téléphone.
   Les couleurs de statut reprennent celles du classeur (rouge, orange, vert). */
:root {
  --bg: #F1F4F3;
  --surface: #FFFFFF;
  --surface-2: #F7F9F8;
  --ink: #16292D;
  --muted: #5A6B6E;
  --line: #D7DFDD;
  --accent: #0E5E6F;
  --accent-soft: #DCEDEF;
  --on-accent: #FFFFFF;
  --bad: #B3261E;  --bad-bg: #FBE3E0;
  --warn: #A85400; --warn-bg: #FCEAD3;
  --ok: #1B7339;   --ok-bg: #DDF0E2;
  --veil: rgba(10, 20, 22, .45);
  --shadow: 0 1px 2px rgba(22,41,45,.06), 0 8px 24px rgba(22,41,45,.10);
  --f-body: "Instrument Sans", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --f-num: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, "Roboto Mono", monospace;
  --r: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1618; --surface: #162124; --surface-2: #1B282B; --ink: #E3ECEA; --muted: #92A4A6;
    --line: #2A3B3E; --accent: #5BBAC6; --accent-soft: #1C3A40; --on-accent: #08262B;
    --bad: #FF8F84; --bad-bg: #3B1E1C; --warn: #FFB36B; --warn-bg: #3A2915; --ok: #7DD597; --ok-bg: #173022;
    --veil: rgba(0, 0, 0, .6);
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--f-body);
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
[hidden] { display: none !important; }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-family: var(--f-num); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.sub { color: var(--muted); font-size: 13px; }
.wrap { max-width: 1080px; margin: 0 auto; padding-inline: 16px; padding-block: 0 110px; }

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-box { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.login-box img { border-radius: 14px; }
.login-box h1 { margin: 0; font-size: 22px; text-wrap: balance; }
.btn.large { padding: 13px 16px; justify-content: center; font-size: 16px; }
.pwd { position: relative; }
.pwd input { padding-right: 46px !important; }
.oeil { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 38px; height: 38px; border: 0; background: transparent; cursor: pointer; color: var(--muted); border-radius: 6px;
  background-repeat: no-repeat; background-position: center; }
.oeil::before { content: ""; display: block; width: 22px; height: 22px; margin: auto; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7S2 12 2 12z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7S2 12 2 12z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3C/svg%3E") center / contain no-repeat; }
.oeil[aria-pressed="true"]::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7S2 12 2 12z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M3 3l18 18'/%3E%3C/svg%3E");
          mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7S2 12 2 12z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M3 3l18 18'/%3E%3C/svg%3E"); }

/* En-tête */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 16px 12px; flex-wrap: wrap; }
.brand { display: flex; flex-direction: column; min-width: 0; }
.brand small { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.brand h1 { margin: 0; font-size: 22px; font-weight: 700; text-wrap: balance; }
.top-r { display: flex; align-items: center; gap: 10px; position: relative; }
.sync { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.sync i { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.sync[data-s="ok"] i { background: var(--ok); }
.sync[data-s="busy"] i { background: var(--warn); animation: pulse 1s infinite; }
.sync[data-s="off"] i { background: var(--bad); }
@keyframes pulse { 50% { opacity: .3; } }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 15; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); min-width: 240px; padding: 6px; display: flex; flex-direction: column; }
.menu button { text-align: left; border: 0; background: transparent; padding: 10px 12px; border-radius: 6px; cursor: pointer; font-weight: 600; }
.menu button:hover { background: var(--surface-2); }
.menu p { margin: 4px 12px 6px; }

/* Bandeau des soldes */
.kpis { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1.2fr; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.kpi { background: var(--surface); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; min-width: 0; border: 0; text-align: left; }
.kpi span { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.kpi b { font-family: var(--f-num); font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi.solde b { font-size: 28px; color: var(--bad); }
.kpi.bureau { cursor: pointer; }
.kpi.bureau b { color: var(--warn); }
.kpi.bureau:hover { background: var(--surface-2); }
.kpi em { font-style: normal; font-size: 12px; color: var(--muted); }

/* Onglets */
.tabs { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bg); display: flex; gap: 4px; padding-block: 12px 10px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { border: 0; background: transparent; padding: 8px 14px; border-radius: 999px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--bg); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Barre d'outils */
.tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.search { flex: 1 1 220px; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.tools select { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 5px 11px; border-radius: 999px; font-size: 13px; font-weight: 600; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.chip[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--bg); }
.chip .n { font-family: var(--f-num); font-weight: 500; opacity: .75; }
.btn { border: 1px solid var(--line); background: var(--surface); padding: 9px 14px; border-radius: 8px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.danger.armed { background: var(--bad); color: var(--surface); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); padding-inline: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Statuts */
.pill { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .06em; padding: 3px 8px; border-radius: 5px; white-space: nowrap; }
.pill.IMPAYEE { color: var(--bad); background: var(--bad-bg); }
.pill.PARTIELLE { color: var(--warn); background: var(--warn-bg); }
.pill.PAYEE { color: var(--ok); background: var(--ok-bg); }
.pill.attente { color: var(--muted); background: var(--surface-2); border: 1px dashed var(--line); }
.flag { font-size: 11px; font-weight: 600; color: var(--warn); }

/* Listes */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.head, .row { display: grid; gap: 4px 12px; align-items: center; padding: 10px 14px; }
.head { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.row { border: 0; border-bottom: 1px solid var(--line); cursor: pointer; position: relative; background: var(--surface); width: 100%; text-align: left; }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }
.row::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: transparent; }
.row.IMPAYEE::before { background: var(--bad); }
.row.PARTIELLE::before { background: var(--warn); }
.row.PAYEE::before { background: var(--ok); }
.r { text-align: right; }
.gF { grid-template-columns: 110px minmax(0,1.6fr) 92px repeat(3, minmax(0,1fr)) 96px; }
.gP { grid-template-columns: 110px minmax(0,1.4fr) 92px minmax(0,1fr) 120px minmax(0,1fr); }
.gC { grid-template-columns: minmax(0,1.6fr) 70px repeat(3, minmax(0,1fr)); }
.gPr { grid-template-columns: minmax(0,1fr) 140px; }
.cell-l { display: none; }
.more { padding: 12px; text-align: center; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }
.verse-oui { color: var(--ok); font-weight: 700; font-size: 13px; }
.verse-non { color: var(--warn); font-weight: 700; font-size: 13px; }
.verse-autre { color: var(--muted); font-weight: 700; font-size: 13px; }

@media (max-width: 760px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi.solde, .kpi.bureau { grid-column: 1 / -1; }
  .head { display: none; }
  .gF { grid-template-columns: 1fr auto; }
  .gF .c-client { grid-column: 1 / -1; order: 1; font-weight: 600; }
  .gF .c-num { order: 0; } .gF .c-stat { order: 0; text-align: right; }
  .gF .c-date { order: 2; } .gF .c-mt { order: 2; }
  .gF .c-paye { display: none; }
  .gF .c-solde { order: 3; grid-column: 1 / -1; text-align: left; }
  .gP { grid-template-columns: 1fr auto; }
  .gP .c-client { order: 1; grid-column: 1 / -1; font-weight: 600; }
  .gP .c-ver { order: 2; text-align: right; }
  .gP .c-bq { order: 3; grid-column: 1 / -1; }
  .gC { grid-template-columns: 1fr auto; }
  .gC .c-nb, .gC .c-fact, .gC .c-paye { display: none; }
  .cell-l { display: inline; color: var(--muted); font-family: var(--f-body); font-size: 12px; }
}

/* Panneau (fiche ou formulaire) */
.veil { position: fixed; inset: 0; background: var(--veil); z-index: 20; display: flex; justify-content: flex-end; }
.sheet { background: var(--bg); width: min(620px, 100%); height: 100%; overflow-y: auto; box-shadow: var(--shadow); display: flex; flex-direction: column; overscroll-behavior: contain; }
.sheet-h { position: sticky; top: 0; z-index: 2; background: var(--bg); display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 12px; border-bottom: 1px solid var(--line); }
.sheet-h h2 { margin: 0; font-size: 18px; }
.sheet-b { padding: 16px; display: flex; flex-direction: column; gap: 16px; padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px)); }
.x { border: 0; background: transparent; font-size: 28px; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 10px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card h3 { margin: 0; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.kv { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px; }
.kv div { display: flex; flex-direction: column; min-width: 0; }
.kv span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.kv b { font-family: var(--f-num); font-size: 17px; font-weight: 600; overflow-wrap: anywhere; }
.mini { width: 100%; border-collapse: collapse; font-size: 14px; }
.mini td, .mini th { padding: 7px 4px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.mini th { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.mini tr:last-child td { border-bottom: 0; }
.tbl { overflow-x: auto; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Formulaires */
.form { display: flex; flex-direction: column; gap: 14px; }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.f { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.f.full { grid-column: 1 / -1; }
.f label, .f .lab { font-size: 12px; font-weight: 600; color: var(--muted); }
.f input, .f select, .f textarea { padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); width: 100%; min-width: 0; font-size: 16px; }
.f input:focus, .f select:focus, .search:focus, .line input:focus, .line select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.f .hint { font-size: 13px; color: var(--muted); }
.f .err, .err-box { font-size: 13px; color: var(--bad); font-weight: 600; }
.f.bad input { border-color: var(--bad); }
.err-box { background: var(--bad-bg); padding: 10px 12px; border-radius: 8px; }
.ok-box { font-size: 13px; color: var(--ok); background: var(--ok-bg); padding: 10px 12px; border-radius: 8px; font-weight: 600; }
.warn-box { font-size: 13px; color: var(--warn); background: var(--warn-bg); padding: 10px 12px; border-radius: 8px; font-weight: 600; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1 1 120px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-weight: 600; cursor: pointer; }
.seg button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); box-shadow: inset 0 0 0 1px var(--accent); }
/* Suggestions de factures et confirmation du paiement */
.ac { position: relative; }
.ac-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 6; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 340px; overflow-y: auto; padding: 4px; min-width: min(340px, calc(100vw - 32px)); }
.ac-opt { display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; border: 0; background: transparent; padding: 10px; border-radius: 6px; cursor: pointer; }
.ac-opt[aria-selected="true"], .ac-opt:hover { background: var(--accent-soft); }
.ac-l1 { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.ac-opt mark { background: transparent; color: var(--accent); font-weight: 700; text-decoration: underline; }
.ac-vide { padding: 10px; font-size: 13px; color: var(--muted); }
.confirm { background: var(--surface); border: 2px solid var(--accent); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.confirm h3 { margin: 0; font-size: 16px; }
.confirm p { margin: 0; }
.confirm .kv b.txt { font-family: var(--f-body); font-size: 15px; }
details.plus { border-top: 1px dashed var(--line); padding-top: 10px; }
details.plus summary { cursor: pointer; font-weight: 600; color: var(--accent); }
details.plus .fgrid { margin-top: 12px; }
.lines { display: flex; flex-direction: column; gap: 8px; }
.line { display: grid; grid-template-columns: minmax(0,2fr) 80px 96px minmax(0,1fr) 34px; gap: 6px; align-items: center; }
.line input, .line select { padding: 10px 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); width: 100%; min-width: 0; font-size: 16px; }
.line .mt { text-align: right; font-family: var(--f-num); font-size: 14px; }
.line .del { border: 0; background: transparent; color: var(--muted); font-size: 22px; cursor: pointer; }
.lines-h { display: grid; grid-template-columns: minmax(0,2fr) 80px 96px minmax(0,1fr) 34px; gap: 6px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.total-line { display: flex; justify-content: space-between; align-items: baseline; padding-top: 8px; border-top: 1px dashed var(--line); }
.total-line b { font-family: var(--f-num); font-size: 20px; }
@media (max-width: 520px) {
  .fgrid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr 1fr; }
  .line { grid-template-columns: 1fr 72px 30px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
  .line select { grid-column: 1 / -1; }
  .line .del { grid-row: 1; grid-column: 3; }
  .line select { grid-column: 1 / 3; grid-row: 1; }
  .line .q { grid-column: 1; } .line .u { grid-column: 2 / 4; }
  .line .mt { grid-column: 1 / -1; text-align: left; font-size: 13px; color: var(--muted); }
  .lines-h { display: none; }
}

/* Boutons flottants et notifications */
.fab-bar { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 10; display: flex; gap: 8px; }
.fab-bar .btn { box-shadow: var(--shadow); padding: 13px 18px; border-radius: 999px; font-size: 15px; }
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom, 0px)); z-index: 40; max-width: calc(100% - 32px); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-weight: 600; box-shadow: var(--shadow); display: flex; gap: 12px; align-items: center; }
.toast.bad { background: var(--bad); color: var(--surface); }
.toast button { border: 0; background: transparent; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }
.notice { background: var(--warn-bg); color: var(--ink); border-radius: var(--r); padding: 12px 16px; margin-bottom: 14px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
