/* Outil de gestion Fly Runnqvist : couleurs du site (papier, encre, orange), pensé
   d'abord pour le téléphone, avec une barre latérale sur ordinateur. */

:root {
  --papier: #fbf6ed;
  --papier-fonce: #f3e9d8;
  --carte: #fffdf8;
  --encre: #2b2622;
  --gris: #6b6058;
  --trait: #e2d6c2;
  --accent: #b8541f;
  --accent-fonce: #96421a;
  --accent-clair: #f9ece3;
  --sombre: #2f3d33;
  --ok: #2f7a45;
  --ok-fond: #e5f4e4;
  --warn: #9a6400;
  --warn-fond: #f9eeda;
  --late: #b3261e;
  --late-fond: #fbebeb;
  --info: #2a5d8f;
  --info-fond: #e7f1fb;
  --rayon: 8px;
  --titres: Bahnschrift, "DIN Alternate", "Avenir Next Condensed", "Segoe UI", system-ui, sans-serif;
  --texte: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --papier: #1d1b19;
    --papier-fonce: #26231f;
    --carte: #2a2723;
    --encre: #efe7da;
    --gris: #b3a797;
    --trait: #3d3832;
    --accent: #e0814a;
    --accent-fonce: #f0975f;
    --accent-clair: #3a2a20;
    --sombre: #141a16;
    --ok: #7cc890;
    --ok-fond: #1f3325;
    --warn: #e6b45a;
    --warn-fond: #3a3020;
    --late: #f08a80;
    --late-fond: #3d2222;
    --info: #8db9e6;
    --info-fond: #1f2c3b;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--papier);
  color: var(--encre);
  font: 16px/1.5 var(--texte);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--titres); font-weight: 500; line-height: 1.2; margin: 0; }
a { color: var(--accent-fonce); }
code { background: var(--papier-fonce); padding: 0 4px; border-radius: 4px; font-size: .9em; word-break: break-all; }
.loading { text-align: center; margin-top: 40vh; color: var(--gris); }
.muted { color: var(--gris); }
.center { text-align: center; }
.empty { color: var(--gris); padding: 16px 0; }
[hidden] { display: none !important; }

/* ---------- Accès ---------- */
.auth { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-logo { width: min(280px, 70vw); margin-bottom: 24px; }
@media (prefers-color-scheme: dark) { .auth-logo, .side-logo { filter: invert(1) hue-rotate(180deg); } }
.auth-card { width: 100%; max-width: 420px; background: var(--carte); border: 1px solid var(--trait); border-radius: 14px; padding: 24px; display: grid; gap: 12px; }
.auth-card h1 { font-size: 1.6rem; }
.auth-form { display: grid; gap: 12px; }
.auth-form label { display: grid; gap: 4px; font-size: .9rem; color: var(--gris); }
.pin-input { font-size: 1.6rem; letter-spacing: .4em; text-align: center; }
.error { color: var(--late); margin: 0; }
.hint { font-size: .85rem; color: var(--gris); margin: 0; }

/* ---------- Champs et boutons ---------- */
input, select, textarea {
  font: inherit;
  color: var(--encre);
  background: var(--carte);
  border: 1px solid var(--trait);
  border-radius: var(--rayon);
  padding: 10px 12px;
  min-height: 44px;
  width: 100%;
}
textarea { min-height: 0; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
.btn {
  font: inherit; font-weight: 600; font-size: .95rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px;
  border-radius: var(--rayon); border: 1px solid var(--trait);
  background: var(--carte); color: var(--encre); cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--gris); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-fonce); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--late); border-color: var(--late); }
.btn.danger:not(.ghost) { background: var(--late); color: #fff; }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: .85rem; }
.btn.big { min-height: 56px; font-size: 1.05rem; flex: 1; }
.btn.block { width: 100%; }
.btn.left { margin-right: auto; }
.btn small { display: block; font-weight: 400; color: var(--gris); }
.file-btn { position: relative; }
.link { background: none; border: 0; padding: 4px 0; font: inherit; font-size: .85rem; color: var(--accent-fonce); cursor: pointer; text-decoration: underline; }
.icon-btn { background: none; border: 0; font-size: 1.6rem; line-height: 1; width: 44px; height: 44px; cursor: pointer; color: var(--encre); display: inline-flex; align-items: center; justify-content: center; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }

/* ---------- Mise en page ---------- */
.sidebar { display: none; }
.main-wrap { min-height: 100vh; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--sombre); color: #fbf6ed;
}
.topbar h1 { font-size: 1.3rem; flex: 1; }
.topbar .icon-btn { color: #fbf6ed; }
.sync-dot { width: 10px; height: 10px; border-radius: 50%; background: #7cc890; }
.sync-dot.warn { background: #e6b45a; }
.view { padding: 16px; max-width: 1100px; margin: 0 auto; }
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--carte); border-top: 1px solid var(--trait);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: .72rem; color: var(--gris); text-decoration: none; }
.bottom-nav a.on { color: var(--accent); font-weight: 600; }
.bottom-nav svg, .sidebar svg, .big-links svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

@media (min-width: 900px) {
  #app.shell { display: grid; grid-template-columns: 220px 1fr; }
  .sidebar { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; padding: 16px 12px; background: var(--carte); border-right: 1px solid var(--trait); }
  .side-logo { width: 170px; margin: 4px 8px 20px; }
  .sidebar nav { display: grid; gap: 2px; }
  .sidebar a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--rayon); color: var(--encre); text-decoration: none; }
  .sidebar a:hover { background: var(--papier-fonce); }
  .sidebar a.on { background: var(--accent-clair); color: var(--accent-fonce); font-weight: 600; }
  .lock-btn { margin-top: auto; }
  .bottom-nav, .mobile-only { display: none; }
  .main-wrap { padding-bottom: 24px; }
  .topbar { padding: 14px 24px; }
  .view { padding: 24px; }
}

/* ---------- Blocs ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 16px; }
.toolbar select, .toolbar input[type=search] { width: auto; flex: 1 1 140px; max-width: 240px; }
.toolbar .spacer { flex: 1; }
.summary { color: var(--gris); margin: 0 0 12px; }
.group { margin-bottom: 24px; }
.group-title { font-size: 1.15rem; margin: 8px 0 8px; text-transform: capitalize; }
.group-title small, .group-title + small { font-family: var(--texte); font-size: .85rem; color: var(--gris); text-transform: none; font-weight: 400; }
.day-title { font-size: 1rem; margin: 14px 0 6px; color: var(--gris); text-transform: capitalize; }
.card { background: var(--carte); border: 1px solid var(--trait); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.card h2 { font-size: 1.15rem; margin-bottom: 8px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.cols2 { display: grid; gap: 16px; }
@media (min-width: 760px) { .cols2 { grid-template-columns: 1fr 1fr; } .cols2 > .card { margin-bottom: 0; } .cols2 { margin-bottom: 16px; } }
.quick { display: flex; gap: 10px; margin-bottom: 16px; }

.rows { list-style: none; margin: 0; padding: 0; background: var(--carte); border: 1px solid var(--trait); border-radius: 12px; overflow: hidden; }
.card .rows { border: 0; border-radius: 0; background: transparent; }
.row { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; padding: 12px 14px; border-top: 1px solid var(--trait); cursor: pointer; color: inherit; text-decoration: none; }
.rows > li:first-child .row, .rows > .row:first-child { border-top: 0; }
.row:hover { background: var(--papier-fonce); }
.row.sub { cursor: default; font-size: .88rem; color: var(--gris); border-top-style: dashed; padding-top: 6px; }
.row-main { flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.row-sub { font-size: .85rem; color: var(--gris); }
.row-side { text-align: right; display: grid; gap: 4px; justify-items: end; flex-shrink: 0; max-width: 50%; }
.row-actions { display: flex; gap: 10px; }
.amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rows.compact .row { padding: 8px 0; }
.big-links .row { align-items: center; justify-content: flex-start; font-size: 1.1rem; padding: 18px 16px; }

.pill { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--papier-fonce); color: var(--gris); white-space: nowrap; }
.pill.ok { background: var(--ok-fond); color: var(--ok); }
.pill.warn { background: var(--warn-fond); color: var(--warn); }
.pill.late { background: var(--late-fond); color: var(--late); }
.pill.info { background: var(--info-fond); color: var(--info); }
.alert { background: var(--late-fond); color: var(--late); padding: 8px 12px; border-radius: var(--rayon); margin: 0 0 12px; }
.alert.inline { display: inline-block; padding: 2px 8px; margin: 0; }
.hint-box { background: var(--info-fond); color: var(--info); padding: 8px 12px; border-radius: var(--rayon); margin: 0; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { background: var(--carte); border: 1px solid var(--trait); border-radius: 12px; padding: 12px 14px; display: grid; gap: 2px; }
.kpi span { font-size: .8rem; color: var(--gris); }
.kpi strong { font-family: var(--titres); font-size: 1.45rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.kpi small { font-size: .78rem; color: var(--gris); }
.kpi.accent { border-color: var(--accent); background: var(--accent-clair); }
.kpis.small .kpi strong { font-size: 1.15rem; }

.todo { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.todo a { display: flex; gap: 10px; align-items: baseline; padding: 6px 0; color: var(--encre); text-decoration: none; }
.todo a:hover { color: var(--accent-fonce); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: var(--gris); }
.dot.warn { background: var(--warn); } .dot.late { background: var(--late); } .dot.info { background: var(--info); } .dot.ok { background: var(--ok); }
.sync-line { font-size: .85rem; color: var(--gris); text-align: center; }
.sync-line.warn { color: var(--warn); }

.tabs { display: flex; gap: 4px; overflow-x: auto; margin: -4px -16px 16px; padding: 0 16px; border-bottom: 1px solid var(--trait); scrollbar-width: none; }
.tabs a { padding: 10px 12px; white-space: nowrap; color: var(--gris); text-decoration: none; border-bottom: 3px solid transparent; }
.tabs a.on { color: var(--accent-fonce); border-color: var(--accent); font-weight: 600; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--trait); border-radius: var(--rayon); overflow: hidden; }
.seg button { font: inherit; font-size: .85rem; border: 0; background: var(--carte); color: var(--gris); padding: 8px 12px; min-height: 40px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--trait); }
.seg button.on { background: var(--accent-clair); color: var(--accent-fonce); font-weight: 600; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--trait); vertical-align: top; }
.table th { font-weight: 600; color: var(--gris); font-size: .8rem; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr[data-act] { cursor: pointer; }
.table tr[data-act]:hover { background: var(--papier-fonce); }
.table tr.flag { background: var(--warn-fond); }
.table.import select { min-height: 34px; padding: 4px 6px; font-size: .85rem; }
ul.plain { padding-left: 18px; margin: 4px 0 12px; }
ol.steps { padding-left: 20px; display: grid; gap: 6px; }

/* Graphique du bilan */
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; height: 170px; align-items: end; margin: 8px 0 4px; }
.bar-col { display: grid; grid-template-rows: 1fr auto; height: 100%; text-align: center; }
.bar-col small { font-size: .7rem; color: var(--gris); }
.bar-pair { display: flex; align-items: flex-end; justify-content: center; gap: 2px; height: 100%; }
.bar { width: 42%; min-height: 1px; border-radius: 3px 3px 0 0; }
.bar.in, .sw.in { background: var(--accent); }
.bar.out, .sw.out { background: var(--gris); opacity: .55; }
.legend { font-size: .82rem; color: var(--gris); display: flex; gap: 6px; align-items: center; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-left: 8px; }

/* Calendrier */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-h { text-align: center; font-size: .75rem; color: var(--gris); padding: 4px 0; }
.cal-day { font: inherit; text-align: left; min-height: 72px; padding: 4px; border: 1px solid var(--trait); border-radius: 6px; background: var(--carte); color: var(--encre); cursor: pointer; display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.cal-day.out { opacity: .45; }
.cal-day.today { border-color: var(--accent); border-width: 2px; }
.cal-n { font-size: .8rem; font-weight: 600; }
.cal-ev { font-size: .68rem; padding: 0 4px; border-radius: 4px; background: var(--papier-fonce); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-ev.info { background: var(--info-fond); color: var(--info); } .cal-ev.warn { background: var(--warn-fond); color: var(--warn); } .cal-ev.ok { background: var(--ok-fond); color: var(--ok); }
.cal-fl { font-size: .66rem; color: var(--gris); }

/* ---------- Fenêtres ---------- */
dialog.sheet { border: 0; padding: 0; background: var(--carte); color: var(--encre); width: 100%; max-width: 100%; height: 100%; max-height: 100%; margin: 0; border-radius: 0; }
dialog.sheet::backdrop { background: rgba(20, 16, 12, .5); }
.sheet-form { display: flex; flex-direction: column; height: 100%; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 10px 8px 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); border-bottom: 1px solid var(--trait); }
.sheet-head h2 { flex: 1; font-size: 1.2rem; }
.sheet-body { flex: 1; overflow-y: auto; padding: 16px; }
.sheet-body h3 { font-size: 1rem; margin: 16px 0 6px; }
.sheet-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--trait); background: var(--papier); }
@media (min-width: 700px) {
  dialog.sheet { width: min(560px, 94vw); height: auto; max-height: 90vh; margin: auto; border-radius: 14px; }
  dialog.sheet.wide { width: min(860px, 94vw); }
  .sheet-form { max-height: 90vh; }
}
.form-grid { display: grid; gap: 12px; }
@media (min-width: 700px) { .wide .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .full, .form-grid .form-heading, .form-grid .form-html { grid-column: 1 / -1; } }
.field { display: grid; gap: 4px; align-content: start; }
.field label, .field .label { font-size: .85rem; color: var(--gris); }
.field.check { align-content: center; }
label.check { display: flex !important; align-items: center; gap: 8px; color: var(--encre) !important; font-size: .95rem !important; cursor: pointer; min-height: 32px; }
.form-heading { font-size: .95rem; margin: 8px 0 -4px; padding-top: 8px; border-top: 1px solid var(--trait); color: var(--accent-fonce); }
.form-html:empty { display: none; }
.multi-list { display: grid; gap: 2px; max-height: 260px; overflow-y: auto; border: 1px solid var(--trait); border-radius: var(--rayon); padding: 6px 10px; }
.multi-list .check { font-size: .88rem !important; }
.file-ok { font-size: .85rem; color: var(--ok); }
.choice-list { display: grid; gap: 8px; }
.choice-list .btn { justify-content: flex-start; text-align: left; flex-direction: column; align-items: flex-start; }
.declaration { white-space: pre-wrap; font-size: .9rem; background: var(--papier); border: 1px solid var(--trait); border-radius: var(--rayon); padding: 10px; max-height: 200px; overflow-y: auto; }
canvas.signature { width: 100%; height: auto; aspect-ratio: 600 / 220; border: 1px dashed var(--gris); border-radius: var(--rayon); background: #fff; touch-action: none; display: block; margin: 4px 0; }

.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100; background: var(--encre); color: var(--papier); padding: 10px 16px; border-radius: 10px; max-width: calc(100vw - 32px); box-shadow: 0 6px 20px rgba(0, 0, 0, .2); transition: opacity .4s; }
.toast.error { background: var(--late); color: #fff; }
.toast.out { opacity: 0; }
@media (min-width: 900px) { .toast { bottom: 24px; } }

/* Photos des bons cadeaux */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.tpl { margin: 0; border: 2px solid var(--trait); border-radius: 10px; overflow: hidden; background: var(--papier); }
.tpl.on { border-color: var(--accent); }
.tpl img { display: block; width: 100%; aspect-ratio: 297 / 210; object-fit: cover; }
.tpl figcaption { padding: 6px 10px 0; font-size: .9rem; }
.tpl-actions { display: flex; gap: 12px; padding: 0 10px 8px; }

/* Vérification d'un bon */
.verdict { border: 2px solid var(--trait); border-radius: 10px; padding: 10px 12px; margin-top: 10px; display: grid; gap: 3px; cursor: pointer; font-size: .92rem; }
.verdict.ok { border-color: var(--ok); background: var(--ok-fond); }
.verdict.warn { border-color: var(--warn); background: var(--warn-fond); }
.verdict.late { border-color: var(--late); background: var(--late-fond); }
.verdict-head { font-weight: 700; font-size: 1.05rem; display: flex; gap: 8px; align-items: center; }
.quick { flex-wrap: wrap; }
