/* GesTime : mobile first. Les règles de base visent le téléphone, puis min-width élargit pour tablette et ordinateur. */
:root {
  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #f8fafc; --text: #0f172a; --muted: #5b6b82; --line: #e3e8ef;
  --primary: #0f766e; --primary-600: #0d6660; --primary-soft: #e0f2f0; --on-primary: #ffffff;
  --ok: #15803d; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7;
  --bad: #b91c1c; --bad-soft: #fee2e2; --info: #1d4ed8; --info-soft: #dbeafe; --neutral-soft: #e8edf3;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 14px rgba(15,23,42,.06);
  --radius: 16px; --radius-sm: 10px; --nav-h: 64px; --top-h: 56px;
  color-scheme: light;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b1220; --surface: #121a2b; --surface-2: #17213a; --text: #e8eefc; --muted: #93a3bd; --line: #24314d;
    --primary: #2dd4bf; --primary-600: #5eead4; --primary-soft: #0f2f36; --on-primary: #04211e;
    --ok: #4ade80; --ok-soft: #10301f; --warn: #fbbf24; --warn-soft: #3a2a0c;
    --bad: #f87171; --bad-soft: #3d1618; --info: #93c5fd; --info-soft: #14284a; --neutral-soft: #1d2a45;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1220; --surface: #121a2b; --surface-2: #17213a; --text: #e8eefc; --muted: #93a3bd; --line: #24314d;
  --primary: #2dd4bf; --primary-600: #5eead4; --primary-soft: #0f2f36; --on-primary: #04211e;
  --ok: #4ade80; --ok-soft: #10301f; --warn: #fbbf24; --warn-soft: #3a2a0c;
  --bad: #f87171; --bad-soft: #3d1618; --info: #93c5fd; --info-soft: #14284a; --neutral-soft: #1d2a45;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 var(--font); min-height: 100vh; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic.sm { width: 18px; height: 18px; } .ic.lg { width: 28px; height: 28px; }
.hide { display: none !important; }
.muted { color: var(--muted); } .small { font-size: .875rem; } .strong { font-weight: 650; }
.row { display: flex; align-items: center; gap: 10px; } .row.wrap { flex-wrap: wrap; } .between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; } .grow { flex: 1; min-width: 0; }
.num { font-variant-numeric: tabular-nums; }

/* Boutons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-600); }
.btn.danger { color: var(--bad); border-color: var(--bad-soft); background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: .9rem; border-radius: 10px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent; display: grid; place-items: center; cursor: pointer; position: relative; }
.icon-btn:hover { background: var(--neutral-soft); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 2px; }

/* Mise en page générale */
.app { min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 20; height: var(--top-h); display: flex; align-items: center; gap: 8px; padding: 0 12px 0 16px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; letter-spacing: -.01em; }
.brand .logo { width: 32px; height: 32px; border-radius: 10px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; }
.topbar .title { font-weight: 700; }
.dot { position: absolute; top: 6px; right: 6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff;
  font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.topbar > .small { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.est-select { max-width: 46vw; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); padding: 0 8px; }
.content { padding: 16px 16px calc(var(--nav-h) + 96px); max-width: 1120px; margin: 0 auto; }
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--surface); border-top: 1px solid var(--line); }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted);
  font-size: 11.5px; font-weight: 600; position: relative; min-width: 0; }
.nav a span.lbl { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.nav a.active { color: var(--primary); }
.nav a.active::before { content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 4px 4px; background: var(--primary); }
.nav .dot { top: 6px; right: calc(50% - 22px); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.page-head h1 { font-size: 1.35rem; letter-spacing: -.01em; }
.page-head .btn.primary { display: none; }
.fab { position: fixed; right: 16px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 15; width: 56px; height: 56px; border-radius: 18px; border: 0;
  background: var(--primary); color: var(--on-primary); box-shadow: 0 8px 22px rgba(15,118,110,.4); display: grid; place-items: center; cursor: pointer; }

/* Cartes et grilles */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card h2 { font-size: 1rem; margin-bottom: 10px; }
.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
.kpi .label { color: var(--muted); font-size: .85rem; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 2rem; font-weight: 750; letter-spacing: -.02em; margin-top: 4px; }
.kpi .value small { font-size: .95rem; font-weight: 600; color: var(--muted); }
.bar { height: 10px; border-radius: 6px; background: var(--neutral-soft); overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; border-radius: 6px; background: var(--primary); }
.bar.warn > i { background: var(--warn); }
.hello { margin-bottom: 14px; } .hello h1 { font-size: 1.5rem; letter-spacing: -.02em; } .hello p { color: var(--muted); }

/* Badges et puces */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; background: var(--neutral-soft); color: var(--muted); }
.badge.draft { background: var(--neutral-soft); color: var(--muted); } .badge.pending { background: var(--info-soft); color: var(--info); }
.badge.needs_correction { background: var(--warn-soft); color: var(--warn); } .badge.approved, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.rejected, .badge.bad { background: var(--bad-soft); color: var(--bad); } .badge.cancelled { background: var(--neutral-soft); color: var(--muted); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chip { flex: none; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; font-size: .9rem; }
.chip.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

/* Listes */
.list { display: flex; flex-direction: column; gap: 10px; }
.item { display: flex; align-items: center; gap: 12px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; cursor: pointer; text-align: left; width: 100%; }
.item:hover { border-color: color-mix(in srgb, var(--primary) 50%, var(--line)); }
.item .ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex: none; }
.item.unread { border-left: 4px solid var(--primary); }
.item .t { font-weight: 650; } .item .s { color: var(--muted); font-size: .875rem; overflow: hidden; text-overflow: ellipsis; }
.amount { font-weight: 700; font-variant-numeric: tabular-nums; } .amount.pos { color: var(--ok); } .amount.neg { color: var(--bad); }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty .ic { width: 42px; height: 42px; margin-bottom: 8px; opacity: .6; } .empty h3 { color: var(--text); font-size: 1.05rem; margin-bottom: 4px; }
.notice { display: flex; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--info-soft); color: var(--info); font-size: .92rem; }
.notice.warn { background: var(--warn-soft); color: var(--warn); } .notice.bad { background: var(--bad-soft); color: var(--bad); }
.kv { display: grid; grid-template-columns: 1fr; gap: 2px 16px; } .kv dt { color: var(--muted); font-size: .85rem; margin-top: 8px; } .kv dd { margin: 0; font-weight: 550; }

/* Tableaux : cartes sur mobile, vrai tableau dès la tablette */
.tbl { width: 100%; border-collapse: collapse; }
.tbl thead { display: none; }
.tbl tr { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; cursor: pointer; }
.tbl td { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; text-align: right; }
.tbl td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; text-align: left; flex: none; }
.tbl td.actions { justify-content: flex-end; padding-top: 8px; } .tbl td.actions::before { display: none; }
.tbl td.name { font-weight: 650; }

/* Formulaires */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label, .field .lbl { font-weight: 600; font-size: .92rem; }
.field .hint { color: var(--muted); font-size: .82rem; }
.input, .select, .textarea { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.textarea { min-height: 88px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); outline: 3px solid color-mix(in srgb, var(--primary) 25%, transparent); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: flex-start; gap: 10px; min-height: 30px; } .check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--primary); }
.radio-cards { display: grid; gap: 8px; margin-bottom: 14px; }
.radio-card { display: flex; gap: 10px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.radio-card:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.radio-card input { accent-color: var(--primary); width: 18px; height: 18px; }
.form-error { color: var(--bad); background: var(--bad-soft); padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: .92rem; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { appearance: none; -webkit-appearance: none; width: 46px; height: 28px; border-radius: 14px; background: var(--neutral-soft); border: 1px solid var(--line); cursor: pointer; margin: 0; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
.switch input:checked { background: var(--primary); border-color: var(--primary); } .switch input:checked::after { transform: translateX(18px); }

/* Feuilles (fenêtres) */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(8,13,25,.55); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
.sheet { width: 100%; max-height: 92vh; overflow: auto; background: var(--surface); border-radius: 22px 22px 0 0; padding: 8px 18px calc(22px + env(safe-area-inset-bottom)); animation: up .2s ease; }
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 10px; }
.sheet .sh-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; } .sheet h2 { font-size: 1.15rem; }
.sheet .actions { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.toasts { position: fixed; z-index: 80; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 76px); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; max-width: 480px; padding: 12px 16px; border-radius: 12px; background: #0f172a; color: #fff; box-shadow: var(--shadow); animation: up .2s ease; }
.toast.ok { background: #166534; } .toast.bad { background: #991b1b; }
@keyframes up { from { transform: translateY(24px); opacity: 0 } to { transform: none; opacity: 1 } } @keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg) } }

/* Écrans d'authentification */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: 100%; max-width: 420px; padding: 24px; }
.auth h1 { font-size: 1.4rem; margin: 14px 0 4px; } .auth .tabs { display: flex; gap: 6px; background: var(--neutral-soft); padding: 4px; border-radius: 12px; margin: 16px 0; }
.auth .tabs button { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: transparent; font-weight: 650; cursor: pointer; color: var(--muted); }
.auth .tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.menu { position: absolute; right: 8px; top: calc(var(--top-h) - 4px); z-index: 40; min-width: 240px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 8px; }
.menu .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu button { display: flex; width: 100%; align-items: center; gap: 10px; min-height: 42px; border: 0; background: transparent; padding: 0 10px; border-radius: 10px; cursor: pointer; text-align: left; }
.menu button:hover { background: var(--neutral-soft); }
.json { font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; overflow: auto; max-height: 160px; white-space: pre-wrap; word-break: break-word; }

/* Tablette */
@media (min-width: 768px) {
  .content { padding: 24px 24px 40px; padding-bottom: calc(var(--nav-h) + 40px); }
  .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: repeat(2, 1fr); }
  .kv { grid-template-columns: 1fr 1fr; }
  .overlay { align-items: center; padding: 24px; }
  .sheet { max-width: 560px; border-radius: 22px; max-height: 88vh; padding-top: 16px; } .sheet.wide { max-width: 760px; } .sheet .grab { display: none; }
  .sheet .actions { flex-direction: row; justify-content: flex-end; }
  .toasts { bottom: calc(var(--nav-h) + 16px); }
  .tbl thead { display: table-header-group; }
  .tbl thead th { text-align: left; color: var(--muted); font-size: .8rem; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; padding: 0 12px 8px; }
  .tbl tbody { display: table-row-group; } .tbl tr { display: table-row; border: 0; border-radius: 0; padding: 0; background: transparent; margin: 0; }
  .tbl tbody tr:hover td { background: var(--surface-2); }
  .tbl td { display: table-cell; padding: 12px; text-align: left; border-top: 1px solid var(--line); background: var(--surface); }
  .tbl td::before { display: none; }
  .tbl tbody tr:first-child td:first-child { border-top-left-radius: 12px; } .tbl tbody tr:first-child td:last-child { border-top-right-radius: 12px; }
  .tbl tbody tr:last-child td:first-child { border-bottom-left-radius: 12px; } .tbl tbody tr:last-child td:last-child { border-bottom-right-radius: 12px; }
  .tbl td.actions { text-align: right; white-space: nowrap; }
  .tblwrap { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); } .tblwrap .tbl td { border-top: 1px solid var(--line); }
  .tblwrap .tbl tbody tr:first-child td { border-top: 0; }
}
/* Ordinateur : menu latéral à gauche */
@media (min-width: 1024px) {
  .app { padding-left: 248px; }
  .topbar { padding-left: 24px; }
  .nav { top: 0; bottom: auto; right: auto; width: 248px; height: 100vh; flex-direction: column; justify-content: flex-start; padding: 84px 12px 12px; border-top: 0; border-right: 1px solid var(--line); gap: 4px; }
  .nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 0 14px; height: 46px; border-radius: 12px; font-size: 15px; }
  .nav a:hover { background: var(--neutral-soft); } .nav a.active { background: var(--primary-soft); } .nav a.active::before { display: none; }
  .nav .dot { position: static; margin-left: auto; }
  .side-brand { display: flex !important; position: fixed; top: 0; left: 0; width: 248px; height: var(--top-h); align-items: center; padding: 0 20px; z-index: 30; }
  .topbar .brand { display: none; }
  .fab { display: none; } .page-head .btn.primary { display: inline-flex; }
  .grid.c3 { grid-template-columns: repeat(3, 1fr); } .grid.c4 { grid-template-columns: repeat(4, 1fr); }
  .toasts { bottom: 24px; }
}
.side-brand { display: none; }
@media (min-width: 768px) and (max-width: 1023px) { .fab { display: none; } .page-head .btn.primary { display: inline-flex; } }
@media print { .nav, .topbar, .fab { display: none !important; } .app { padding: 0; } }

.auth-theme { position: fixed; top: 12px; right: 12px; z-index: 30; }

/* Champs date : le calendrier natif s'ouvre au toucher et l'icône reste visible en thème sombre. */
input[type="date"] { cursor: pointer; }
input[type="date"]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: .9; }
