/* Deux habillages, choisis par theme.js (attribut data-theme sur <html>) : « nuit » par défaut, fond sombre et accents
   dorés du site martinandco.ch ; « jour », en blanc. Les couleurs ne s'écrivent qu'ici, sous forme de variables.
   Typographie du système : San Francisco sur iPhone, iPad et Mac (la police du site Apple, qui ne peut pas être
   embarquée dans une app web), police de l'appareil ailleurs. L'ancien thème beige est dans design/. */
:root {
  color-scheme: dark;
  --navy: #0a0d18;         /* menu */
  --navy-2: #1c2338;       /* survol et rubrique active */
  --paper: #0e1220;        /* fond de page */
  --login-bg: #0a0d18;
  --card: #161b2c;
  --field: #0f1424;        /* champs de saisie */
  --raised: #20273c;       /* boutons et pastilles neutres */
  --hover: #1b2136;        /* ligne de tableau survolée */
  --ink: #f5f5f7;
  --soft-ink: #c9cfde;
  --muted: #9aa2b6;
  --placeholder: #6f7890;
  --line: #2a3148;
  --line-soft: #1f2538;
  --brand: #dcc692;
  --nav-ink: #a9b1c6;
  --nav-on-ink: #ffffff;
  --link: #dcc692;
  --focus: #cbb17a;
  --accent: #cbb17a;       /* bouton principal, barres du graphique */
  --accent-hover: #dcc692;
  --accent-ink: #171204;
  --accent-light: #2b2516;
  --ok: #6fdaa5;
  --ok-light: #12301f;
  --on-ok: #05281a;
  --warn: #f0c36b;
  --warn-light: #352a10;
  --bad: #ff9186;
  --bad-light: #3a1916;
  --on-bad: #3a0d08;
  --note-ink: #f6dfae;
  --note-bad-ink: #ffc9c2;
  --note-info-ink: #ecdcb8;
  --toast-bg: #f5f5f7;
  --toast-ink: #111522;
  --backdrop: rgba(3, 5, 10, 0.66);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --navy: #ffffff;
  --navy-2: #f0f0f3;
  --paper: #f5f5f7;
  --login-bg: #f5f5f7;
  --card: #ffffff;
  --field: #ffffff;
  --raised: #f2f2f5;
  --hover: #f7f7f9;
  --ink: #1d1d1f;
  --soft-ink: #424245;
  --muted: #6e6e73;
  --placeholder: #a1a1a6;
  --line: #d9d9de;
  --line-soft: #ebebf0;
  --brand: #1d1d1f;
  --nav-ink: #515154;
  --nav-on-ink: #1d1d1f;
  --link: #7d5f26;
  --focus: #8a6a2f;
  --accent: #cbb17a;
  --accent-hover: #bda26a;
  --accent-ink: #171204;
  --accent-light: #f6efdf;
  --ok: #1d7a46;
  --ok-light: #e3f3e9;
  --on-ok: #ffffff;
  --warn: #8a5a00;
  --warn-light: #fdf0d2;
  --bad: #b3261e;
  --bad-light: #fbe4e1;
  --on-bad: #ffffff;
  --note-ink: #5c3d00;
  --note-bad-ink: #7d1d16;
  --note-info-ink: #5e4a1f;
  --toast-bg: #1d1d1f;
  --toast-ink: #ffffff;
  --backdrop: rgba(0, 0, 0, 0.4);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.47; color: var(--ink); background: var(--paper); -webkit-font-smoothing: antialiased; }
h1 { font-size: 30px; font-weight: 600; line-height: 1.1; margin: 0; letter-spacing: -0.022em; text-wrap: balance; }
h2 { font-size: 18px; font-weight: 600; line-height: 1.2; margin: 0 0 12px; letter-spacing: -0.012em; }
a { color: var(--link); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
::placeholder { color: var(--placeholder); opacity: 1; }

/* ---- structure ---- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--navy); color: var(--ink); padding: 22px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--line-soft); }
.brand { font-weight: 600; font-size: 20px; letter-spacing: -0.02em; color: var(--brand); padding: 0 10px; }
.brand-sub { font-size: 12px; color: var(--muted); padding: 0 10px 18px; }
.side a { display: flex; justify-content: space-between; align-items: center; color: var(--nav-ink); text-decoration: none; padding: 9px 10px; border-radius: 8px; font-weight: 500; }
.side a:hover { background: var(--navy-2); color: var(--ink); }
.side a.on { background: var(--navy-2); color: var(--nav-on-ink); }
.side .count { background: var(--bad); color: var(--on-bad); border-radius: 99px; font-size: 12px; padding: 0 7px; font-weight: 600; }
.side .who { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.side .who strong { display: block; color: var(--ink); font-size: 14px; font-weight: 600; }
.side .who button { margin-top: 8px; }
main { padding: 30px 34px 60px; max-width: 1180px; width: 100%; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.head p { margin: 6px 0 0; color: var(--muted); }
.back { display: inline-block; margin-bottom: 8px; font-size: 13px; text-decoration: none; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 18px; }
.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); margin-bottom: 18px; }

/* ---- cartes ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; min-width: 0; margin-bottom: 18px; }
.grid > .card { margin-bottom: 0; }
.kpi .label { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .value { white-space: nowrap; font-size: 22px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .hint { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.kpi.bad .value { color: var(--bad); }
.kpi.ok .value { color: var(--ok); }
.empty { color: var(--muted); padding: 10px 0; }
.note { background: var(--warn-light); color: var(--note-ink); border-radius: 8px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px; }
.note a { color: inherit; }
.note.bad { background: var(--bad-light); color: var(--note-bad-ink); }
.note.info { background: var(--accent-light); color: var(--note-info-ink); }

/* ---- tableaux ---- */
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12.5px; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th.num { text-align: right; }
td { padding: 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--hover); }
tfoot td { font-weight: 600; border-top: 2px solid var(--line); }
td .sub { display: block; font-size: 12.5px; color: var(--muted); }

.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 6px; padding: 2px 9px; font-size: 12.5px; font-weight: 600; white-space: nowrap; background: var(--raised); color: var(--soft-ink); }
.badge.ok { background: var(--ok-light); color: var(--ok); }
.badge.bad { background: var(--bad-light); color: var(--bad); }
.badge.warn { background: var(--warn-light); color: var(--warn); }
.badge.info { background: var(--accent-light); color: var(--link); }

/* ---- boutons et formulaires ---- */
button, .btn { font: inherit; font-weight: 500; border-radius: 8px; border: 1px solid var(--line); background: var(--raised); color: var(--ink); padding: 8px 14px; cursor: pointer; text-decoration: none; display: inline-block; white-space: nowrap; }
button:hover, .btn:hover { border-color: var(--focus); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover, .btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.ok { background: var(--ok); border-color: var(--ok); color: var(--on-ok); font-weight: 600; }
button.danger { color: var(--bad); }
button.mini, .btn.mini { padding: 4px 9px; font-size: 13px; }
button.ghost { background: transparent; border-color: var(--line); color: var(--soft-ink); width: 100%; }
button:disabled { opacity: 0.5; cursor: default; }
label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 12px; }
label .hint { font-weight: 400; color: var(--muted); }
input, select, textarea { display: block; width: 100%; margin-top: 4px; font: inherit; font-weight: 400; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--field); color: var(--ink); }
input[readonly] { color: var(--muted); }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
textarea { min-height: 90px; resize: vertical; }
textarea.tall { min-height: 340px; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
label.check input { width: auto; margin: 0; accent-color: var(--focus); }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 14px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chips button { border-radius: 99px; padding: 5px 13px; font-size: 13.5px; }
.chips button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; color: var(--soft-ink); }

/* ---- mode jour ou nuit ---- */
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.theme-toggle svg { width: 15px; height: 15px; flex: none; }

/* ---- grille des mois ---- */
.months { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.month { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--field); text-align: left; font-weight: 400; white-space: normal; }
.month strong { display: block; text-transform: capitalize; font-weight: 600; }
.month .amt { font-size: 18px; font-weight: 600; letter-spacing: -0.015em; font-variant-numeric: tabular-nums; margin: 2px 0 6px; }
.prop-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: baseline; margin-bottom: 12px; }

/* ---- graphique ---- */
.bars { display: flex; align-items: flex-end; gap: 10px; height: 170px; padding-top: 22px; }
.bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; min-width: 0; }
.bar i { display: block; width: 100%; max-width: 54px; background: var(--accent); border-radius: 5px 5px 0 0; min-height: 2px; }
.bar .v { font-size: 11.5px; font-weight: 600; margin-bottom: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar .m { font-size: 12px; color: var(--muted); margin-top: 6px; text-transform: capitalize; }

dl.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px 18px; margin: 0; }
dl.facts dt { font-size: 12.5px; color: var(--muted); }
dl.facts dd { margin: 0; font-weight: 600; }

/* ---- connexion ---- */
.login { min-height: 100vh; display: grid; place-items: center; background: var(--login-bg); padding: calc(20px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom)); }
.login .card { width: 100%; max-width: 420px; margin: 0; padding: 26px; }
.login h1 { margin-bottom: 4px; color: var(--brand); }
.login .switch { text-align: center; margin: 14px 0 0; font-size: 14px; color: var(--muted); }
.demo { border-top: 1px dashed var(--line); margin-top: 18px; padding-top: 14px; }
.demo button { width: 100%; margin-top: 6px; text-align: left; font-weight: 500; }

/* ---- fenêtre et messages ---- */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(620px, calc(100vw - 28px)); background: var(--card); color: var(--ink); }
dialog.wide { width: min(900px, calc(100vw - 28px)); }
dialog::backdrop { background: var(--backdrop); }
dialog form { padding: 22px; }
dialog h2 { font-size: 20px; margin-bottom: 16px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--toast-bg); color: var(--toast-ink); padding: 10px 18px; border-radius: 10px; font-weight: 500; z-index: 50; max-width: calc(100vw - 30px); box-shadow: var(--shadow); }
#toast.bad { background: var(--bad); color: var(--on-bad); }
[hidden] { display: none !important; }

@media (max-width: 820px) {
  h1 { font-size: 26px; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .kpi .value { font-size: 18px; } /* « CHF 19’860.00 » doit tenir dans une demi-largeur d'iPhone */
  .bars { gap: 4px; }
  .bar .v { font-size: 10px; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--line-soft);
    padding: calc(12px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 12px calc(12px + env(safe-area-inset-left)); }
  .brand-sub { display: none; }
  .side .who { margin: 0 0 0 auto; border: 0; padding: 0; display: flex; gap: 8px; align-items: center; }
  .side .who strong, .side .who span { display: none; }
  .side .who button { margin: 0; width: auto; }
  main { padding: 20px calc(16px + env(safe-area-inset-right)) calc(50px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); }
  input, select, textarea { font-size: 16px; } /* en dessous, l'iPhone zoome à chaque saisie */
}
.nowrap { white-space: nowrap; }
td.wide { min-width: 230px; }

/* ---- accords, signature, saisie rapide ---- */
.amount-inline { width: 118px; margin: 0 0 0 auto; text-align: right; padding: 5px 8px; }
ol.steps { margin: 0; padding-left: 20px; }
ol.steps li { margin-bottom: 6px; }
.note .row { margin-top: 10px; }
.filters { padding: 12px 16px; }
.filters select { width: auto; margin: 0; }
a.tile { display: block; text-decoration: none; color: inherit; }
a.tile:hover { border-color: var(--focus); }

.link-field { min-width: 250px; margin: 0; }
