:root {
  --bg: #0e0f13; --panel: #171920; --panel2: #1f222b; --line: #2a2e39; --text: #eef0f4; --muted: #8b91a1;
  --green: #7cf29c; --red: #ff6b6b; --orange: #ffb454; --blue: #6cb6ff; --violet: #b48cff;
  --r: 14px; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); text-decoration: none; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1.2em; margin: 0; }
.small { font-size: 13px; }

/* Connexion */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(360px, 100%); display: grid; gap: 12px; text-align: center; justify-items: center; }
.login-card h1 { margin: 4px 0 0; font-size: 26px; }
.login-card input, .login-card button { width: 100%; }

/* Champs et boutons */
input, select, textarea { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--green); }
textarea { min-height: 80px; resize: vertical; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.btn { border: 1px solid var(--line); background: var(--panel2); border-radius: 10px; padding: 10px 14px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: #3a3f4d; }
.btn.primary { background: var(--green); color: #0b1a10; border-color: var(--green); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Structure */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100dvh; }
.nav { position: sticky; top: 0; height: 100dvh; padding: 18px 12px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; background: var(--bg); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; padding: 4px 10px 18px; }
.tab { display: flex; align-items: center; gap: 12px; background: none; border: 0; padding: 11px 12px; border-radius: 10px; cursor: pointer; color: var(--muted); font-weight: 600; text-align: left; }
.tab .ico { width: 20px; text-align: center; font-size: 16px; }
.tab.on { background: var(--panel2); color: var(--text); }
.tab.logout { margin-top: auto; }
.main { padding: 24px 28px 60px; max-width: 1180px; width: 100%; min-width: 0; }
h2 { font-size: 24px; margin: 0 0 4px; }
h3 { font-size: 15px; margin: 26px 0 10px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.head > * { min-width: 0; max-width: 100%; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }

/* Cartes chiffres */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.kpi { min-width: 0; overflow-wrap: anywhere; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.kpi .v { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin-top: 2px; }
.kpi .l { color: var(--muted); font-size: 13px; }
.kpi .s { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.good .v { color: var(--green); } .kpi.warn .v { color: var(--orange); } .kpi.bad .v { color: var(--red); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.item { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; gap: 12px; align-items: center; cursor: pointer; text-align: left; width: 100%; }
.item:hover { border-color: #3a3f4d; }
.item .t { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .d { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .r { text-align: right; flex-shrink: 0; }
.item .r .big { font-weight: 800; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--panel2); display: grid; place-items: center; font-weight: 800; flex-shrink: 0; color: var(--green); }

.chips { max-width: 100%; min-width: 0; display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 7px 12px; cursor: pointer; white-space: nowrap; font-size: 13px; font-weight: 600; color: var(--muted); }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip b { margin-left: 4px; }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--panel2); color: var(--muted); }
.pill.green { color: var(--green); } .pill.orange { color: var(--orange); } .pill.red { color: var(--red); } .pill.blue { color: var(--blue); } .pill.violet { color: var(--violet); }

.todo { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.todo .item .ico { font-size: 18px; width: 26px; text-align: center; }

/* Graphiques */
.chart { width: 100%; height: 160px; display: block; }
.chart .bar { fill: var(--green); } .chart .bar2 { fill: var(--violet); }
.chart text { fill: var(--muted); font-size: 10px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.funnel { display: grid; gap: 8px; }
.funnel .f { display: grid; grid-template-columns: 150px 1fr 60px; gap: 10px; align-items: center; font-size: 13px; }
.funnel .track { background: var(--panel2); border-radius: 6px; height: 12px; overflow: hidden; }
.funnel .fill { background: var(--blue); height: 100%; border-radius: 6px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
.scroll-x { overflow-x: auto; }

/* Feuille (détail) */
.sheet { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.sheet-card { position: relative; width: min(620px, 100%); max-height: 92dvh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 22px; }
.sheet-x { position: absolute; right: 12px; top: 10px; background: none; border: 0; font-size: 28px; color: var(--muted); cursor: pointer; }
.sheet-card h2 { padding-right: 30px; }
.form { display: grid; gap: 12px; margin-top: 14px; }
.notes { white-space: pre-wrap; background: var(--panel2); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: var(--muted); max-height: 200px; overflow-y: auto; }
.sep { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; padding: 6px 0; }
.check input { width: auto; }
.checks { max-height: 220px; overflow-y: auto; background: var(--panel2); border-radius: 10px; padding: 6px 12px; }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 30; max-width: 90vw; }
.toast.err { background: var(--red); color: #fff; }
.empty { color: var(--muted); padding: 22px; text-align: center; background: var(--panel); border: 1px dashed var(--line); border-radius: var(--r); }
.skeleton { height: 90px; border-radius: var(--r); background: linear-gradient(90deg, var(--panel) 0%, var(--panel2) 50%, var(--panel) 100%); background-size: 200% 100%; animation: sh 1.2s infinite; }
@keyframes sh { to { background-position: -200% 0; } }

/* Téléphone : onglets en bas */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .nav { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; flex-direction: row; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); z-index: 10; gap: 0; }
  .brand, .tab.logout { display: none; }
  .tab { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; flex: 1; align-items: center; }
  .tab .ico { font-size: 18px; }
  .tab.on { background: none; color: var(--green); }
  .main { padding: calc(16px + env(safe-area-inset-top)) 14px 100px; }
  h2 { font-size: 21px; }
  .kpis { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .kpi .v { font-size: 22px; }
  .sheet { place-items: end center; }
  .sheet-card { border-radius: 18px 18px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
  .funnel .f { grid-template-columns: 110px 1fr 44px; }
  .grid2 { grid-template-columns: 1fr; }
}
