:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --border: #dedcd5;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #d95926;
  --accent-ink: #ffffff;
  --ef: #199e70;
  --q: #eb6834;
  --sl: #2a78d6;
  --test: #d55181;
  --gym: #4a3aa7;
  --good: #137a3a;
  --warn: #a66300;
  --bad: #c22f2f;
  --series-1: #2a78d6;
  --ghost: #d9d7cf;
  --grid: #e6e4de;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  --ag-class: #b9b7ae;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #33332f;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --accent: #eb6834;
    --ef: #1baf7a;
    --q: #eb6834;
    --sl: #3987e5;
    --test: #e87ba4;
    --gym: #9085e9;
    --good: #3ec46d;
    --warn: #f0a92b;
    --bad: #f07070;
    --series-1: #3987e5;
    --ghost: #3a3a36;
    --grid: #2c2c29;
    --shadow: none;
    --ag-class: #5a5953;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #33332f;
  --text: #ffffff; --text-2: #c3c2b7; --text-3: #8f8e86; --accent: #eb6834;
  --ef: #1baf7a; --q: #eb6834; --sl: #3987e5; --test: #e87ba4; --gym: #9085e9;
  --good: #3ec46d; --warn: #f0a92b; --bad: #f07070; --series-1: #3987e5;
  --ghost: #3a3a36; --grid: #2c2c29; --shadow: none; --ag-class: #5a5953;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "tnum" 1;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 600; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.xs { font-size: 12px; color: var(--text-3); }

.wrap { max-width: 760px; margin: 0 auto; padding: 16px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 420px) { .grid3 { grid-template-columns: 1fr 1fr; } }

.btn {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px;
  padding: 9px 14px; cursor: pointer; font-weight: 550; min-height: 40px;
}
.btn:hover { border-color: var(--text-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; width: 40px; height: 40px; cursor: pointer; font-size: 18px; }

/* Nav */
nav.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs button {
  flex: 1; max-width: 150px; background: none; border: 0; padding: 9px 4px 10px; cursor: pointer;
  color: var(--text-3); font-size: 11.5px; font-weight: 550; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
nav.tabs button .ico { font-size: 19px; line-height: 1; filter: grayscale(1); opacity: .75; }
nav.tabs button.active { color: var(--accent); }
nav.tabs button.active .ico { filter: none; opacity: 1; }

/* Hero */
.hero { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; }
.stat .label { font-size: 12px; color: var(--text-2); font-weight: 550; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.stat .sub { font-size: 12.5px; color: var(--text-2); }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 99px; }

.next {
  border-left: 4px solid var(--accent);
}
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 650; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill.EF { color: var(--ef); }
.pill.Q { color: var(--q); }
.pill.SL { color: var(--sl); }
.pill.TEST { color: var(--test); }
.pill.gym { color: var(--gym); }
.pill.good { color: var(--good); }
.pill.warn { color: var(--warn); }
.pill.bad { color: var(--bad); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: currentColor; }

.asthma { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; }
.asthma b { font-weight: 650; }

/* Semaine */
.weeknav { display: flex; align-items: center; gap: 8px; }
.weeknav .title { flex: 1; text-align: center; }
.day { display: grid; grid-template-columns: 54px 1fr; gap: 10px; padding: 12px 0; border-top: 1px solid var(--border); }
.day:first-child { border-top: 0; }
.day.today .dnum { background: var(--accent); color: var(--accent-ink); }
.day.blocked { opacity: .55; }
.dcol { text-align: center; }
.dname { font-size: 12px; color: var(--text-2); font-weight: 600; text-transform: uppercase; }
.dnum { font-size: 18px; font-weight: 700; width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; }
.classes { font-size: 13px; color: var(--text-2); cursor: pointer; }
.classes summary { list-style: none; }
.classes summary::-webkit-details-marker { display: none; }
.classes ul { margin: 6px 0 0; padding-left: 16px; }
.chips { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.chip {
  display: flex; align-items: center; gap: 10px; text-align: left; width: 100%;
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; padding: 8px 10px; cursor: pointer;
}
.chip .bar { width: 4px; align-self: stretch; border-radius: 4px; }
.chip.EF .bar { background: var(--ef); }
.chip.Q .bar { background: var(--q); }
.chip.SL .bar { background: var(--sl); }
.chip.TEST .bar { background: var(--test); }
.chip.gym .bar { background: var(--gym); }
.chip .t { font-weight: 600; font-size: 14px; }
.chip .s { font-size: 12.5px; color: var(--text-2); }
.chip .st { margin-left: auto; font-size: 18px; }
.chip.done { opacity: .8; }
.chip.done .t { text-decoration: line-through; text-decoration-color: var(--text-3); }
.day-actions { display: flex; gap: 6px; margin-top: 6px; }
.linkbtn { background: none; border: 0; color: var(--text-3); font-size: 12.5px; padding: 2px 0; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

/* Agenda */
.agenda { padding: 10px 8px 12px; }
.ag-head, .ag-grid { display: grid; grid-template-columns: 30px 1fr; }
.ag-head { grid-template-columns: 30px repeat(7, 1fr); margin-bottom: 4px; }
.ag-day { background: none; border: 0; padding: 2px 0 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 1px; border-radius: 10px; min-width: 0; }
.ag-day .n { font-size: 11px; font-weight: 600; color: var(--text-2); text-transform: uppercase; }
.ag-day .num { font-size: 15px; font-weight: 700; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; }
.ag-day.today .num { background: var(--accent); color: var(--accent-ink); }
.ag-day.sel { background: var(--surface-2); }
.ag-day.blocked .num { text-decoration: line-through; color: var(--text-3); }
.ag-grid { position: relative; }
.ag-gutter { position: relative; }
.ag-h { position: absolute; right: 5px; transform: translateY(-50%); font-size: 10.5px; color: var(--text-3); }
.ag-h:first-child { transform: none; }
.ag-cols { position: relative; display: grid; grid-template-columns: repeat(7, 1fr); border-left: 1px solid var(--grid); }
.ag-line { position: absolute; left: 0; right: 0; border-top: 1px solid var(--grid); pointer-events: none; }
.ag-col { position: relative; border-right: 1px solid var(--grid); cursor: pointer; min-width: 0; }
.ag-col.sel { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.ag-col.blocked { background: repeating-linear-gradient(135deg, transparent 0 6px, var(--grid) 6px 7px); }
.ag-ev {
  position: absolute; overflow: hidden; border-radius: 5px; padding: 2px 3px; text-align: left;
  display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; min-width: 0;
  font-size: 10.5px; line-height: 1.2; color: var(--text); border: 0; border-left: 3px solid var(--ag-class);
  background: color-mix(in srgb, var(--ag-class) 28%, var(--surface)); cursor: pointer; z-index: 1;
}
.ag-ev .lbl { display: block; overflow: hidden; word-break: break-word; hyphens: auto; }
.ag-ev .ln { display: block; white-space: nowrap; overflow: hidden; flex: none; }
.ag-ev b { font-weight: 650; }
.ag-ev.class { color: var(--text-2); font-size: 9.5px; }
.ag-ev.gym { border-left-color: var(--gym); background: color-mix(in srgb, var(--gym) 22%, var(--surface)); z-index: 2; }
.ag-ev.ag-run { z-index: 3; box-shadow: 0 0 0 1.5px var(--surface); }
.ag-ev.gym, .ag-ev.ag-run { letter-spacing: -.01em; }
.ag-ev.EF { border-left-color: var(--ef); background: color-mix(in srgb, var(--ef) 26%, var(--surface)); }
.ag-ev.Q { border-left-color: var(--q); background: color-mix(in srgb, var(--q) 26%, var(--surface)); }
.ag-ev.SL { border-left-color: var(--sl); background: color-mix(in srgb, var(--sl) 26%, var(--surface)); }
.ag-ev.TEST { border-left-color: var(--test); background: color-mix(in srgb, var(--test) 26%, var(--surface)); }
.ag-ev.skipped, .ag-ev.missed { opacity: .5; }
.ag-now { position: absolute; left: -1px; right: 0; border-top: 2px solid var(--bad); z-index: 4; pointer-events: none; }
.ag-now::before { content: ""; position: absolute; left: -4px; top: -5px; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); }
.ag-legend { margin: 10px 0 4px; gap: 10px; font-size: 12px; }
@media (min-width: 600px) { .ag-ev { font-size: 11.5px; padding: 3px 5px; } .ag-ev.class { font-size: 10.5px; } }

/* Plan */
.wk { cursor: pointer; }
.wk.current { border-color: var(--accent); }
.wk-sessions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* Upload */
.drop {
  border: 2px dashed var(--border); border-radius: 14px; padding: 26px 16px; text-align: center; cursor: pointer;
  background: var(--surface);
}
.drop.over { border-color: var(--accent); background: var(--surface-2); }
.drop .big { font-size: 30px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.form .full { grid-column: 1 / -1; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-2); font-weight: 550; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=password], select, textarea {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 9px 10px; width: 100%; min-height: 40px; font-size: 15px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; background: var(--surface-2); padding: 7px 12px; cursor: pointer; min-width: 38px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

.crops { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
.crops img { width: 100%; border-radius: 8px; border: 1px solid var(--border); cursor: zoom-in; display: block; }

.run { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; cursor: pointer; }
.run .main { font-size: 17px; font-weight: 700; }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kv > div { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.kv .k { font-size: 11.5px; color: var(--text-2); font-weight: 550; }
.kv .v { font-size: 17px; font-weight: 700; }
@media (max-width: 420px) { .kv { grid-template-columns: 1fr 1fr; } }

.feedback { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: 14px; }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; color: var(--text-2); font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--border); }
table.t td { padding: 7px 4px; border-bottom: 1px solid var(--border); }
table.t td.num, table.t th.num { text-align: right; }

.zbar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; }
.zbar > div { height: 100%; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 640px) { .modal-bg { align-items: center; } }
.modal {
  background: var(--surface); width: 100%; max-width: 620px; max-height: 92vh; overflow: auto;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) { .modal { border-radius: 18px; } }
.modal .close { float: right; }
.blocks { margin: 0; padding: 0; list-style: none; }
.blocks li { display: grid; grid-template-columns: 44px 1fr; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.blocks li:last-child { border-bottom: 0; }
.blocks .min { font-weight: 700; color: var(--text-2); }
.pace { font-weight: 650; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 60; font-size: 14px; max-width: calc(100% - 32px); }

/* Charts */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--text-3); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .ref { stroke: var(--text-3); stroke-dasharray: 4 4; stroke-width: 1.5; }
.chart .reflabel { fill: var(--text-2); font-size: 11px; font-weight: 600; }
.tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12.5px; padding: 6px 9px; border-radius: 8px; white-space: nowrap; transform: translate(-50%, -110%); z-index: 5; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; flex-wrap: wrap; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 5px; vertical-align: -1px; }

.hidden { display: none !important; }
