/* ============================================================================
   PostFinance · Factures fournisseurs — feuille de style (dark, responsive).
   Servie en local (CSP stricte, aucun CDN).
   ========================================================================== */

:root {
  --bg: #0b0e14;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #16203a44, transparent),
             radial-gradient(900px 500px at -10% 10%, #1a14334d, transparent);
  --panel: #141925;
  --panel-2: #1b2233;
  --line: #262f42;
  --line-soft: #1e2536;
  --fg: #e7eaf2;
  --mut: #93a0b5;
  --accent: #5b8cff;
  --accent-press: #3f6fe0;
  --ok: #34d399;
  --ok-bg: #064e3b66;
  --warn: #fbbf24;
  --warn-bg: #78350f55;
  --err: #f87171;
  --err-bg: #7f1d1d66;
  --info-bg: #1e3a8a33;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 4px 16px -10px #0009, 0 1px 3px -2px #0006;
  --maxw: 1600px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* fiabilise le masquage des champs flex */

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 13.5px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- Header --- */
header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 8px clamp(16px, 3vw, 36px);
  background: #0d111aee;
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
header .brand {
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  display: flex;
  align-items: center;
}
header nav {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
header nav::-webkit-scrollbar { display: none; }
header nav a {
  color: var(--mut);
  padding: 6px 11px;
  border-radius: 7px;
  white-space: nowrap;
  font-weight: 500;
  font-size: 13px;
}
header nav a:hover { color: var(--fg); background: var(--panel-2); text-decoration: none; }
header nav a.active { color: var(--fg); background: var(--panel-2); }
header .spacer { flex: 1; }
.s3-status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--line); white-space: nowrap; user-select: none;
}
.s3-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.s3-status.checking { color: var(--mut); }
.s3-status.ok  { color: #6ee7b7; background: var(--ok-bg);  border-color: #0f5132; }
.s3-status.err { color: #fca5a5; background: var(--err-bg); border-color: #842029; }
header .user { display: flex; align-items: center; gap: 10px; white-space: nowrap; }

.muted { color: var(--mut); }
.mono { font-family: ui-monospace, "SF Mono", SFMono-Regular, Consolas, monospace; font-size: 0.92em; }
.right { text-align: right; }

/* ------------------------------------------------------------------ Main --- */
main {
  max-width: var(--maxw);
  margin: 22px auto;
  padding: 0 clamp(16px, 3vw, 36px);
}
h1 { font-size: 18px; font-weight: 650; letter-spacing: -0.02em; margin: 0 0 16px; }
h2 { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; color: var(--mut); margin: 0 0 11px; display: flex; align-items: center; gap: 6px; }

/* ----------------------------------------------------------------- Panel --- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.panel.info { background: linear-gradient(0deg, var(--info-bg), var(--info-bg)), var(--panel); border-color: #2a3a66; }
.panel.warn { background: linear-gradient(0deg, var(--warn-bg), var(--warn-bg)), var(--panel); border-color: #6b4a17; }
/* Bandeaux explicatifs : plus discrets (texte secondaire). */
.panel.info, .panel.warn { font-size: 12.5px; line-height: 1.5; color: #aeb9cc; }
.panel.info b, .panel.warn b { color: var(--fg); font-weight: 600; }
.panel-tight { padding: 11px 15px; }

/* ------------------------------------------------------------------ Form --- */
label { display: block; margin: 0 0 5px; color: var(--mut); font-size: 12px; font-weight: 500; }
input, select, button, textarea { font: inherit; }
input, select {
  width: 100%;
  background: #0c1018;
  border: 1px solid var(--line);
  color: var(--fg);
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
input::placeholder { color: #55607a; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #5b8cff33; }

.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.row .field { display: flex; flex-direction: column; }
.row .field.end { justify-content: flex-end; }

/* --------------------------------------------------------------- Buttons --- */
button {
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  transition: filter .12s, background .12s, transform .04s;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: none; box-shadow: 0 0 0 3px #5b8cff44; }
button:disabled { opacity: .45; cursor: not-allowed; filter: none; }
button.ghost { background: transparent; border-color: var(--line); color: var(--fg); }
button.ghost:hover { background: var(--panel-2); filter: none; }
button.danger { background: var(--err); }
button.sm { padding: 5px 10px; font-size: 12px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions input, .actions select { width: auto; flex: 1 1 140px; }
.actions.end { justify-content: flex-end; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 0 0 14px; }
.toolbar .filter-bar { flex: 1; margin: 0; }
.add-invoice { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; }
.toolbar-actions { margin-left: auto; display: inline-flex; gap: 10px; align-items: center; }
.toolbar-actions .add-invoice { margin-left: 0; }
.pay-trigger { display: inline-flex; align-items: center; gap: 6px; background: #18a058; color: #fff; }
/* Tableau de bord */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin: 16px 0 24px; }
.kpi { display: flex; flex-direction: column; gap: 2px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); text-decoration: none; color: var(--fg); }
a.kpi:hover { border-color: var(--accent); }
.kpi-n { font-size: 30px; font-weight: 700; line-height: 1.1; }
.kpi-l { font-size: 13px; color: var(--mut); }
.kpi-sub { font-size: 12px; color: var(--mut); margin-top: 2px; }
.kpi.warn .kpi-n { color: #f0a020; }
.kpi.danger .kpi-n { color: #fca5a5; }
.kpi.ok .kpi-n { color: #4ade80; }
.dash-h2 { display: flex; align-items: center; gap: 6px; font-size: 15px; margin: 8px 0 12px; }
.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
.chart-head .dash-h2 { margin: 0; }
.chart-year { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.bar-chart { width: 100%; max-width: 1600px; height: auto; display: block; margin: 6px auto 18px; }
.bar-chart .bar-rect { fill: url(#barGrad); transition: opacity .12s; }
.bar-chart .bar-rect:hover { opacity: .82; }
.bar-chart .chart-grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 5; opacity: .55; }
.bar-chart .chart-axis { fill: var(--mut); font-size: 10px; }
.bar-chart .chart-v { fill: var(--fg); font-size: 11px; font-weight: 600; }
.bar-chart .chart-l { fill: var(--mut); font-size: 11px; }
.grid th.sel, .grid td.sel { width: 28px; text-align: center; padding-left: 6px; padding-right: 6px; }
.grid th.sel input, .grid td.sel input { width: auto; margin: 0; accent-color: var(--accent); cursor: pointer; }
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 0 0 14px; }
.filter-bar select { width: auto; min-width: 180px; }
.filter-bar select.narrow { min-width: 110px; }
.filter-bar label { color: var(--mut); font-size: 13px; }
.filter-bar label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }
.filter-bar label.check input { width: auto; margin: 0; accent-color: var(--accent); }
.badge.dismissed { background: var(--line); color: var(--mut); }
.page-head { display: flex; align-items: center; gap: 8px; margin: 0 0 16px; }
.page-head h1 { margin: 0; }
.help { position: relative; display: inline-flex; }
.help .help-body {
  display: none;
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0;
  width: min(680px, 86vw); margin: 0; box-shadow: var(--shadow);
}
.help:hover .info-dot, .help:focus-within .info-dot { color: var(--accent); }
.help:hover .help-body, .help:focus-within .help-body { display: block; }
.info-dot {
  display: inline-flex; align-items: center; justify-content: center;
  line-height: 1; color: var(--mut);
  cursor: default; user-select: none; vertical-align: middle;
  transition: color .12s ease, transform .12s ease;
}
.info-dot:hover, .info-dot:focus {
  color: var(--accent); transform: scale(1.12); outline: none;
}
.block { width: 100%; }
.small { font-size: 12px; }
.mt { margin-top: 16px; }
.stack > * + * { margin-top: 10px; }

/* --------------------------------------------------------------- Badges ---- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; line-height: 1.45;
  border: 1px solid transparent; white-space: nowrap;
}
.badge.scheduled  { background: #1e3a8a44; color: #93c5fd; }
.badge.needs_review { background: var(--warn-bg); color: #fcd34d; }
.badge.submitted, .badge.paid { background: var(--ok-bg); color: #6ee7b7; }
.badge.received   { background: #33415544; color: #cbd5e1; }
.badge.rejected, .badge.error { background: var(--err-bg); color: #fca5a5; }
.badge.verified, .badge.auto { background: var(--ok-bg); color: #6ee7b7; }
.badge.pending, .badge.manual { background: var(--warn-bg); color: #fcd34d; }
.fraud { color: var(--err); font-weight: 700; white-space: nowrap; display: inline-flex; align-items: center; gap: 3px; vertical-align: middle; }
.lucide { vertical-align: middle; flex-shrink: 0; }
.pdf-link, .lock-hint { display: inline-flex; align-items: center; gap: 4px; }
.upload-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.upload-form input[type="file"] { color: var(--mut); }
.upload-form input[type="file"]::file-selector-button {
  font: inherit; cursor: pointer; color: var(--fg);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px 12px; margin-right: 10px;
}
.upload-form input[type="file"]::file-selector-button:hover { border-color: var(--accent); }

/* ----------------------------------------------------------------- Flash --- */
.flash { padding: 9px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; border: 1px solid transparent; font-size: 13px; }
.flash.ok  { background: var(--ok-bg);  color: #6ee7b7; border-color: #0f5132; }
.flash.err { background: var(--err-bg); color: #fca5a5; border-color: #842029; }

/* ----------------------------------------------------------------- Table --- */
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;            /* scroll horizontal si le tableau dépasse */
  box-shadow: var(--shadow);
}
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td {
  padding: 6px 12px; text-align: left; vertical-align: middle;
  white-space: nowrap;          /* pas de retour à la ligne (lignes compactes) */
}
table.grid td.wrap { white-space: normal; }  /* sauf colonnes texte long */
table.grid thead th {
  color: var(--mut); font-weight: 600; font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.06em;
  background: #0f1420; border-bottom: 1px solid var(--line);
  padding-top: 8px; padding-bottom: 8px;
}
table.grid tbody tr { border-bottom: 1px solid var(--line-soft); }
table.grid tbody tr:last-child { border-bottom: none; }
table.grid tbody tr:hover { background: #ffffff05; }
table.grid td.right, table.grid th.right { text-align: right; }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.empty { color: var(--mut); padding: 28px 14px; text-align: center; }

/* Cellules « actions » dans une grille : tout sur une ligne, compact. */
table.grid td .actions { flex-wrap: nowrap; gap: 6px; }
table.grid td form.actions { margin: 0; }
table.grid .actions input, table.grid .actions select { flex: 0 0 auto; }
table.grid input[type="date"] { width: 132px; min-width: 0; padding: 6px 8px; }
table.grid button { padding: 6px 12px; }
table.grid td .small { white-space: nowrap; }

/* --------------------------------------------------------------- Login ----- */
.login-wrap { max-width: 380px; margin: 8vh auto; }
.login-wrap h1 { text-align: center; }
.totp-qr { display: flex; justify-content: center; margin: 4px 0 2px; }
.totp-qr svg { width: 208px; height: 208px; background: #fff; border-radius: 8px; padding: 8px; }

/* ===================== RESPONSIVE : tables → cartes ======================== */
@media (max-width: 860px) {
  table.grid thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table-wrap { background: transparent; border: none; box-shadow: none; overflow: visible; }
  table.grid, table.grid tbody, table.grid tr, table.grid td { display: block; width: 100%; }
  table.grid tr {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 14px;
    padding: 6px 14px;
  }
  table.grid tr:hover { background: var(--panel); }
  table.grid td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    padding: 9px 0;
    border-bottom: 1px solid var(--line-soft);
    text-align: right;
    white-space: normal;     /* en mode carte, on autorise le retour à la ligne */
  }
  table.grid td:last-child { border-bottom: none; }
  table.grid td::before {
    content: attr(data-label);
    color: var(--mut);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    text-align: left;
    flex: 0 0 auto;
  }
  table.grid td.right { text-align: right; }
  table.grid td .actions { justify-content: flex-end; }
  .empty::before { content: ""; }
}

@media (max-width: 560px) {
  header { gap: 12px; }
  header .brand span.long { display: none; }
  main { margin: 18px auto; }
  table.grid td { flex-wrap: wrap; }
}

/* ---------------------------------------------------------------- Modal ---- */
dialog.modal {
  width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--fg);
  box-shadow: var(--shadow);
  padding: 20px;
}
dialog.modal::backdrop { background: #0009; backdrop-filter: blur(2px); }
dialog.modal h3 { margin: 0 0 8px; font-size: 16px; }
dialog.modal .table-wrap { margin: 12px 0; }
.modal-actions { margin-top: 16px; display: flex; gap: 10px; justify-content: flex-end; }
dialog.pay-modal { width: min(700px, calc(100vw - 32px)); }
dialog.pay-modal .table-wrap { max-height: 50vh; overflow: auto; }
.pay-total { margin: 12px 0 0; text-align: right; font-size: 13px; }
.pay-total b { font-size: 15px; }
#pay-confirm:disabled { opacity: .5; cursor: not-allowed; }
