/* =========================================================================
   GMAO Atelier — Système de design
   Direction : outil de terrain, sobre et robuste. Vert pin (agriculture /
   paysage), ocre pour le carburant et les alertes, et un traitement
   monospace pour toutes les données techniques (références, compteurs,
   quantités, niveaux). Polices système uniquement (fonctionne hors-ligne
   sur un serveur Windows : Segoe UI / Consolas sont présents).
   ========================================================================= */

:root {
  --pine: #1b5e3f;
  --pine-700: #164d34;
  --pine-600: #1f6e49;
  --pine-50: #eaf2ed;
  --ochre: #c2761a;
  --ochre-50: #fbf2e4;
  --ink: #1d201c;
  --muted: #6b716a;
  --faint: #969b93;
  --line: #e4e2db;
  --line-strong: #d2cfc6;
  --canvas: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #fafaf7;

  --red: #c0392b;
  --red-50: #fbebe9;
  --amber: #c2761a;
  --amber-50: #fbf2e4;
  --green: #2f8f4e;
  --green-50: #e9f4ec;
  --blue: #2563a8;
  --blue-50: #e9f0f8;
  --grey-50: #f0efeb;

  --r: 9px;
  --r-sm: 6px;
  --r-lg: 14px;
  --shadow: 0 1px 2px rgba(20,30,20,.05), 0 1px 3px rgba(20,30,20,.06);
  --shadow-lg: 0 10px 30px rgba(20,30,20,.13), 0 2px 8px rgba(20,30,20,.08);

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "Cascadia Mono", "Segoe UI Mono", Consolas, "Liberation Mono", monospace;

  --sidebar-w: 248px;
  --topbar-bg: rgba(246,245,241,.86);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--canvas);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

a { color: var(--pine-600); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ Login */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 600px at 80% -10%, #e7efe9 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #f3ead7 0%, transparent 55%),
    var(--canvas);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 32px 30px;
}
.login-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 22px; }
.login-brand .logo { width: 40px; height: 40px; border-radius: 9px; background: var(--pine); display: grid; place-items: center; flex: 0 0 auto; }
.login-brand h1 { font-size: 18px; margin: 0; letter-spacing: -.02em; }
.login-brand p { margin: 1px 0 0; font-size: 12px; color: var(--muted); }

/* ----------------------------------------------------------------- Layout */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--pine-700);
  color: #d7e4dc;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { display: flex; align-items: center; gap: 11px; padding: 18px 18px 14px; }
.sidebar .brand .logo { width: 34px; height: 34px; border-radius: 8px; background: rgba(255,255,255,.1); display: grid; place-items: center; flex: 0 0 auto; }
.sidebar .brand b { color: #fff; font-size: 15.5px; letter-spacing: -.01em; }
.sidebar .brand span { display: block; font-size: 11px; color: #9bb6a8; }

.nav { flex: 1; overflow-y: auto; padding: 6px 10px 16px; }
.nav-group { margin-top: 14px; }
.nav-group > .label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: #7fa190; padding: 6px 10px 4px; font-weight: 700; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; margin: 1px 0;
  border-radius: var(--r-sm);
  color: #cdded6; font-size: 13.5px; font-weight: 500;
  text-decoration: none; cursor: pointer;
}
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav a.active { background: var(--ochre); color: #fff; }
.nav a.active svg { color: #fff; }
.nav a svg { width: 17px; height: 17px; flex: 0 0 auto; color: #8fb0a0; }
.nav a .badge-count { margin-left: auto; background: rgba(255,255,255,.16); color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 20px; font-family: var(--mono); }
.nav a.active .badge-count { background: rgba(0,0,0,.18); }

.sidebar .foot { border-top: 1px solid rgba(255,255,255,.1); padding: 12px; }
.userbox { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--ochre); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: 0 0 auto; }
.userbox .meta { min-width: 0; }
.userbox .meta b { color: #fff; font-size: 13px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.userbox .meta span { font-size: 11px; color: #9bb6a8; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  background: var(--topbar-bg); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 13px 26px;
}
.topbar h2 { margin: 0; font-size: 19px; letter-spacing: -.02em; }
.topbar .sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.topbar .spacer { flex: 1; }
.burger { display: none; background: none; border: 1px solid var(--line-strong); border-radius: var(--r-sm); width: 36px; height: 36px; cursor: pointer; }

.content { padding: 22px 26px 48px; max-width: 1280px; width: 100%; }

/* --------------------------------------------------------------- Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-size: 13.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .04s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--pine); border-color: var(--pine); color: #fff; }
.btn.primary:hover { background: var(--pine-600); }
.btn.danger { background: var(--surface); border-color: var(--line-strong); color: var(--red); }
.btn.danger:hover { background: var(--red-50); border-color: var(--red); }
.btn.ochre { background: var(--ochre); border-color: var(--ochre); color: #fff; }
.btn.ochre:hover { filter: brightness(1.05); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--grey-50); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-icon { width: 32px; height: 32px; padding: 0; justify-content: center; }

/* ----------------------------------------------------------------- Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.card .card-h { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.card .card-h h3 { margin: 0; font-size: 15px; letter-spacing: -.01em; }
.card .card-b { padding: 18px; }

.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }

/* ------------------------------------------------------------ Stat tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 15px 16px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-family: var(--mono); margin-top: 5px; }
.stat .h { font-size: 11.5px; color: var(--faint); margin-top: 2px; }
.stat .ic { position: absolute; top: 13px; right: 13px; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
.stat .ic svg { width: 17px; height: 17px; }
.stat.alert .v { color: var(--red); }
.stat.warn .v { color: var(--ochre); }

/* ---------------------------------------------------------------- Tables */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); }
table.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tbody tr { cursor: default; }
table.tbl tbody tr.clickable:hover { background: var(--surface-2); cursor: pointer; }
table.tbl td.right, table.tbl th.right { text-align: right; }
table.tbl .strong { font-weight: 600; }
table.tbl .sub { color: var(--muted); font-size: 12px; }

/* --------------------------------------------------------------- Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; white-space: nowrap; line-height: 1.6; border: 1px solid transparent; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.green { background: var(--green-50); color: #1f6f3b; }
.badge.amber { background: var(--amber-50); color: #9a5d12; }
.badge.red { background: var(--red-50); color: var(--red); }
.badge.blue { background: var(--blue-50); color: var(--blue); }
.badge.grey { background: var(--grey-50); color: var(--muted); }
.badge.pine { background: var(--pine-50); color: var(--pine); }
.badge.outline { background: transparent; border-color: var(--line-strong); color: var(--muted); }
.chip-cat { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; }
.chip-cat .sw { width: 9px; height: 9px; border-radius: 3px; flex: 0 0 auto; }

/* ----------------------------------------------------------------- Forms */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink); margin-bottom: 5px; }
.field .hint { font-size: 11.5px; color: var(--faint); margin-top: 4px; }
.field.req > label::after { content: " *"; color: var(--red); }
input, select, textarea {
  width: 100%; padding: 8px 11px; font-size: 14px; font-family: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--pine-600); box-shadow: 0 0 0 3px rgba(31,110,73,.13); }
input[type="number"] { font-family: var(--mono); }
textarea { resize: vertical; min-height: 76px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* ------------------------------------------------------------ Filter bar */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.toolbar .search { position: relative; flex: 1; min-width: 200px; max-width: 360px; }
.toolbar .search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--faint); }
.toolbar .search input { padding-left: 33px; }
.toolbar select { width: auto; min-width: 130px; }
.toolbar .spacer { flex: 1; }

/* ---------------------------------------------------------------- Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(25,32,25,.42); display: grid; place-items: center; z-index: 100; padding: 20px; animation: fade .14s ease; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; max-height: 90vh; display: flex; flex-direction: column; animation: pop .16s ease; }
.modal.wide { max-width: 760px; }
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity: 0; } }
.modal .m-h { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal .m-h h3 { margin: 0; font-size: 16px; }
.modal .m-h .x { margin-left: auto; }
.modal .m-b { padding: 20px; overflow-y: auto; }
.modal .m-f { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }

/* ---------------------------------------------------------------- Toast */
#toast-zone { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: var(--r); box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 360px; display: flex; align-items: center; gap: 9px; animation: slidein .18s ease; }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }
.toast.ok { background: #1d5236; }
.toast.err { background: #8e2b20; }
.toast svg { width: 17px; height: 17px; flex: 0 0 auto; }

/* ------------------------------------------------------------- Gauges */
.gauge { margin-bottom: 13px; }
.gauge:last-child { margin-bottom: 0; }
.gauge .g-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 5px; }
.gauge .g-top b { font-size: 13.5px; }
.gauge .g-top .lvl { font-family: var(--mono); font-size: 12.5px; color: var(--muted); }
.gauge .bar { height: 12px; background: var(--grey-50); border-radius: 20px; overflow: hidden; border: 1px solid var(--line); }
.gauge .bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--ochre), #d98e2f); border-radius: 20px; transition: width .3s; }
.gauge.low .bar > span { background: linear-gradient(90deg, var(--red), #d4574a); }

/* ------------------------------------------------------------- Detail */
.detail-grid { display: grid; grid-template-columns: 1fr 320px; gap: 16px; }
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 8px 14px; font-size: 13.5px; }
.dl dt { color: var(--muted); font-weight: 600; }
.dl dd { margin: 0; }
.kvs { display: flex; flex-direction: column; gap: 0; }
.kv { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 600; text-align: right; }

/* --------------------------------------------------------- Comments */
.comment { display: flex; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.comment:last-child { border-bottom: none; }
.comment .body { flex: 1; min-width: 0; }
.comment .body .meta { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.comment .body .meta b { color: var(--ink); }
.comment .body p { margin: 0; font-size: 13.5px; white-space: pre-wrap; word-break: break-word; }

/* --------------------------------------------------------- Empty state */
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty svg { width: 38px; height: 38px; color: var(--line-strong); margin-bottom: 12px; }
.empty h4 { margin: 0 0 4px; color: var(--ink); font-size: 15px; }
.empty p { margin: 0 0 16px; font-size: 13.5px; }

/* --------------------------------------------------------- Bar chart */
.barchart { display: flex; flex-direction: column; gap: 9px; }
.barchart .row { display: grid; grid-template-columns: 120px 1fr 42px; align-items: center; gap: 10px; font-size: 13px; }
.barchart .row .lab { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.barchart .row .track { height: 9px; background: var(--grey-50); border-radius: 20px; overflow: hidden; }
.barchart .row .track > span { display: block; height: 100%; background: var(--pine-600); border-radius: 20px; }
.barchart .row .n { text-align: right; font-family: var(--mono); color: var(--muted); }

.section-title { font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 26px 0 12px; }
.muted { color: var(--muted); }
.hr { height: 1px; background: var(--line); border: none; margin: 18px 0; }
.tag-overdue { color: var(--red); font-weight: 600; }
.flex { display: flex; align-items: center; gap: 8px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap-actions { display: flex; gap: 6px; }
.nowrap { white-space: nowrap; }

/* --------------------------------------------------------- Responsive */
.overlay-nav { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: var(--sidebar-w); z-index: 60; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .overlay-nav.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 55; }
  .burger { display: grid; place-items: center; }
  .content { padding: 16px 14px 40px; }
  .topbar { padding: 11px 14px; }
  .detail-grid { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .dl { grid-template-columns: 1fr; gap: 2px 0; }
  .dl dt { margin-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
:focus-visible { outline: 2px solid var(--pine-600); outline-offset: 2px; }

/* ============================== Thème sombre ============================== */
[data-theme="dark"] {
  --ink: #e7e9e7;
  --muted: #9ba1a0;
  --faint: #757b79;
  --line: #2a3138;
  --line-strong: #3b434b;
  --canvas: #15181c;
  --surface: #1c2127;
  --surface-2: #232a31;
  --pine-50: #15301f;
  --ochre-50: #36280f;
  --red-50: #3a1d18;
  --amber-50: #36280f;
  --green-50: #15311f;
  --blue-50: #16273a;
  --grey-50: #262c32;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 1px 3px rgba(0,0,0,.3);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.55), 0 2px 8px rgba(0,0,0,.4);
  --topbar-bg: rgba(21,24,28,.86);
  --green: #4caf6a;
}
[data-theme="dark"] body { background: var(--canvas); color: var(--ink); }
[data-theme="dark"] .badge.green { background: #15351f; color: #7fd29a; }
[data-theme="dark"] .badge.amber { background: #3a2a12; color: #e3b072; }
[data-theme="dark"] .badge.red { background: #3a1c18; color: #ec9385; }
[data-theme="dark"] .badge.blue { background: #16273a; color: #87b4e6; }
[data-theme="dark"] .badge.grey { background: #272d33; color: #aab0af; }
[data-theme="dark"] .badge.pine { background: #163a2a; color: #74c79c; }
[data-theme="dark"] .login-wrap {
  background: radial-gradient(1200px 600px at 80% -10%, #1a2a20 0%, transparent 60%),
              radial-gradient(900px 500px at -10% 110%, #2a2414 0%, transparent 55%), var(--canvas);
}
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea { background: var(--surface-2); color: var(--ink); }
[data-theme="dark"] .btn { background: var(--surface-2); color: var(--ink); }
[data-theme="dark"] .btn:hover { background: var(--surface); }
[data-theme="dark"] .btn.primary { background: var(--pine); color: #fff; }
[data-theme="dark"] .btn.ochre { background: var(--ochre); color: #fff; }
[data-theme="dark"] .stat .ic { filter: brightness(1.3); }
[data-theme="dark"] input[type="color"] { background: var(--surface-2); }
