/* ============================================================
   Dashboard theme — WHOOP-inspired, dark-first.
   Shared by /matlogg and /trening.
   ============================================================ */

:root, :root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0d12;
  --card: #12171f;
  --card2: #1a212b;
  --ink: #eef2f6;
  --muted: #8494a3;
  --green: #23d18b;  --green-soft: rgba(35, 209, 139, .13);
  --amber: #ffb020;  --amber-soft: rgba(255, 176, 32, .13);
  --red:   #ff5c5c;  --red-soft:   rgba(255, 92, 92, .13);
  --blue:  #38a6ff;  --blue-soft:  rgba(56, 166, 255, .13);
  --purple:#9d8cff;  --purple-soft: rgba(157, 140, 255, .13);
  --line: #222b36;
  --track: rgba(255, 255, 255, .08);
  --radius: 16px;
  --shadow: none;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f8;
  --card: #ffffff;
  --card2: #f0f3f6;
  --ink: #16202b;
  --muted: #64748b;
  --green: #0e9f6e;  --green-soft: rgba(14, 159, 110, .10);
  --amber: #b45309;  --amber-soft: rgba(180, 83, 9, .10);
  --red:   #dc2626;  --red-soft:   rgba(220, 38, 38, .10);
  --blue:  #1d6fd8;  --blue-soft:  rgba(29, 111, 216, .10);
  --purple:#6d5cd3;  --purple-soft: rgba(109, 92, 211, .10);
  --line: #e2e8f0;
  --track: rgba(22, 32, 43, .08);
  --shadow: 0 1px 3px rgba(20, 30, 40, .08);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg); color: var(--ink);
  padding: 14px 14px 48px;
  max-width: 560px; margin: 0 auto;
  font-feature-settings: "tnum";
}
@media (min-width: 900px) {
  body { max-width: 1160px; padding: 24px 28px 60px; }
}

/* ---------- header + nav ---------- */
header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
header h1 { font-size: 21px; font-weight: 800; letter-spacing: -0.4px; }
header span { color: var(--muted); font-size: 12px; }

nav.tabs {
  display: flex; gap: 4px; overflow-x: auto; margin: 0 -14px 16px; padding: 0 14px 8px;
  scrollbar-width: none;
}
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs a {
  text-decoration: none; color: var(--muted);
  padding: 8px 13px; border-radius: 10px; font-size: 13.5px; font-weight: 700; white-space: nowrap;
  border: 1px solid transparent;
}
nav.tabs a.on { background: var(--green-soft); color: var(--green); border-color: transparent; }
nav.tabs a:not(.on):hover { color: var(--ink); background: var(--card); }
@media (min-width: 900px) { nav.tabs { flex-wrap: wrap; overflow: visible; margin: 0 0 18px; padding: 0; } }

.theme-btn {
  background: var(--card); border: 1px solid var(--line); color: var(--ink);
  width: 34px; height: 34px; border-radius: 999px; cursor: pointer; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; line-height: 1; flex: none;
}
.theme-btn:hover { border-color: var(--green); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 1fr; gap: 12px; align-items: start; }
.layout > * { min-width: 0; }  /* let grid children shrink below min-content (mobile overflow fix) */
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr) 400px; gap: 16px; }
}

/* ---------- trening sections ---------- */
.tre-section { margin-bottom: 22px; }
.tre-title {
  font-size: 12.5px; font-weight: 800; letter-spacing: 1px; margin: 4px 2px 10px;
  display: flex; align-items: center; gap: 6px; text-transform: uppercase; color: var(--muted);
}
.tre-title::after { content: ''; flex: 1; height: 1px; background: var(--line); margin-left: 10px; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 12px;
}
.card h2 {
  font-size: 11.5px; font-weight: 800; margin-bottom: 14px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 1.1px;
  display: flex; align-items: center; gap: 6px;
}

/* ---------- hero (rings row) ---------- */
.hero {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 12px 12px; margin-bottom: 12px;
}
.hero-rings { display: flex; justify-content: space-around; align-items: flex-start; gap: 6px; }
.ring { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; flex: 1; }
.ring svg { width: 86px; height: 86px; display: block; }
@media (min-width: 900px) { .ring svg { width: 104px; height: 104px; } }
.ring-num { font-size: 23px; font-weight: 800; letter-spacing: -0.5px; fill: var(--ink); }
.ring-unit { font-size: 9px; font-weight: 700; fill: var(--muted); letter-spacing: .4px; }
.ring-label {
  font-size: 10px; font-weight: 800; color: var(--muted);
  text-transform: uppercase; letter-spacing: .8px; text-align: center;
}
.ring-sub { font-size: 10.5px; color: var(--muted); text-align: center; }
.hero-chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 12px; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (min-width: 900px) { .kpis { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); } }
.kpi { background: var(--card2); border-radius: 12px; padding: 11px 13px; border-left: 3px solid transparent; }
.kpi b { display: block; font-size: 19px; font-weight: 800; letter-spacing: -0.4px; }
.kpi span { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.kpi.amber { border-left-color: var(--amber); background: var(--amber-soft); }
.kpi.amber b { color: var(--amber); }
.kpi.blue { border-left-color: var(--blue); background: var(--blue-soft); }
.kpi.blue b { color: var(--blue); }
.kpi.red { border-left-color: var(--red); background: var(--red-soft); }
.kpi.red b { color: var(--red); }
.kpi.wide { grid-column: 1 / -1; }

/* ---------- meal / list rows ---------- */
.meal { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
.meal:last-child { border-bottom: 0; }
.meal .t { font-size: 11.5px; font-weight: 700; color: var(--muted); min-width: 42px; padding-top: 2px; }
.meal .d { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; line-height: 1.35; }
.meal .d .sub { font-size: 12px; color: var(--muted); font-weight: 500; margin-top: 2px; display: block; }
.meal .m { text-align: right; font-size: 12px; color: var(--muted); white-space: normal; }  /* allow wrap: prevents mobile overflow */
.meal .m b { color: var(--ink); font-size: 13.5px; white-space: nowrap; }
.meal .m .pct { white-space: nowrap; }
.meal .pct { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; margin: 3px 0 0; justify-content: flex-end; }
.meal .pct input {
  width: 46px; padding: 3px 4px; font-size: 12px; font-family: inherit; text-align: center;
  border: 1px solid var(--line); border-radius: 8px; background: var(--card2); color: var(--ink);
}
.meal .pct.low { color: var(--amber); }
.meal .pct.low input { border-color: var(--amber); color: var(--amber); }

.badge {
  display: inline-block; background: var(--blue-soft); color: var(--blue);
  font-size: 10.5px; font-weight: 700; border-radius: 999px; padding: 2px 8px; margin-top: 3px;
}
.del { background: none; border: 0; color: var(--muted); font-size: 15px; cursor: pointer; padding: 2px 4px; border-radius: 8px; }
.del:active { background: var(--red-soft); color: var(--red); }

/* ---------- totals / progress bars ---------- */
.totals { margin-top: 12px; background: var(--card2); border-radius: 12px; padding: 12px 14px; }
.totals .row { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 5px; color: var(--muted); font-weight: 600; }
.totals .row b { font-size: 14px; color: var(--ink); }
.bar-track { height: 8px; background: var(--track); border-radius: 999px; overflow: hidden; margin-bottom: 10px; }
.bar-fill { height: 100%; background: var(--green); border-radius: 999px; transition: width .4s; }
.bar-fill.over { background: var(--blue); }
.bar-fill.low { background: var(--amber); }

/* legacy bar chart bits (kept for compatibility) */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 130px; padding-top: 6px; position: relative; }
.band { position: absolute; left: 0; right: 0; background: var(--green-soft); border-radius: 4px; opacity: .9; }
.target-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--red); opacity: .55; border-radius: 2px; z-index: 2; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; z-index: 1; }
.bar { width: 100%; max-width: 34px; background: var(--green); border-radius: 6px 6px 2px 2px; min-height: 3px; }
.bar-stack { width: 100%; max-width: 34px; display: flex; flex-direction: column; justify-content: flex-end; border-radius: 6px 6px 2px 2px; overflow: hidden; min-height: 3px; }
.bar-stack.low { outline: 1px dashed var(--amber); outline-offset: -1px; }
.seg { width: 100%; }
.seg.p { background: var(--green); }
.seg.c { background: var(--amber); }
.seg.f { background: var(--blue); }
.bar.over { background: var(--blue); }
.bar.low { background: var(--amber); }
.bar-col .v { font-size: 10px; color: var(--muted); font-weight: 700; }
.bar-col .l { font-size: 10px; color: var(--muted); }
.v.low { color: var(--amber); }

.navbtn {
  background: var(--card2); border: 1px solid var(--line); color: var(--ink);
  font-weight: 800; font-size: 15px; padding: 4px 12px; border-radius: 10px; cursor: pointer;
}
.navbtn:hover { border-color: var(--green); color: var(--green); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { font-size: 12px; font-weight: 700; background: var(--blue-soft); color: var(--blue); border-radius: 999px; padding: 4px 10px; }
.note { font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.55; }

svg { width: 100%; height: auto; display: block; }

.progress { height: 12px; background: var(--track); border-radius: 999px; overflow: hidden; position: relative; margin: 6px 0 4px; }
.progress .fill { height: 100%; background: linear-gradient(90deg, var(--green), #4be0a8); border-radius: 999px; transition: width .5s; }
.progress .mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--red); border-radius: 2px; }
.goal-row { display: flex; justify-content: space-between; font-size: 13px; margin-top: 8px; }
.goal-row b { font-size: 14px; }

/* ---------- add form ---------- */
.add-toggle {
  width: 100%; background: transparent; border: 1px dashed var(--line); color: var(--muted);
  padding: 10px; border-radius: 12px; font-size: 13.5px; font-weight: 700; cursor: pointer; margin-top: 12px;
}
.add-toggle:hover { border-color: var(--green); color: var(--green); background: var(--green-soft); }
.add-form { display: none; margin-top: 10px; }
.add-form.open { display: block; }
.add-form input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; margin-bottom: 8px; font-family: inherit; background: var(--card2); color: var(--ink);
}
.add-form .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.add-form .grid input { margin-bottom: 0; }
.add-form button {
  width: 100%; background: var(--green); color: #04140c; border: 0; padding: 11px;
  border-radius: 12px; font-size: 15px; font-weight: 800; cursor: pointer; margin-top: 10px;
}
:root[data-theme="light"] .add-form button { color: #fff; }

.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 14px 0; }
.thumb { width: 54px; height: 54px; object-fit: cover; border-radius: 8px; display: block; margin: 4px 0 0; cursor: pointer; border: 1px solid var(--line); }

.legend { display: flex; gap: 12px; font-size: 11px; color: var(--muted); margin-top: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* ---------- glance chips (legacy) + hero chips ---------- */
.glance { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.glance-chip, .hero-chips .glance-chip {
  background: var(--card2); border: 1px solid transparent; border-radius: 10px; padding: 6px 11px;
  display: inline-flex; align-items: baseline; gap: 6px;
}
.glance-chip b { font-size: 15px; font-weight: 800; color: var(--ink); }
.glance-chip i { font-style: normal; color: var(--muted); font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.glance-chip.green { background: var(--green-soft); }
.glance-chip.green b, .glance-chip.green i { color: var(--green); }
.glance-chip.amber { background: var(--amber-soft); }
.glance-chip.amber b, .glance-chip.amber i { color: var(--amber); }
.glance-chip.red { background: var(--red-soft); }
.glance-chip.red b, .glance-chip.red i { color: var(--red); }

.readiness { display: flex; align-items: center; gap: 8px; border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; font-size: 13px; flex-wrap: wrap; }
.readiness.green { background: var(--green-soft); color: var(--green); }
.readiness.amber { background: var(--amber-soft); color: var(--amber); }
.readiness.red { background: var(--red-soft); color: var(--red); }
.readiness b { font-weight: 800; font-size: 14px; }
.readiness .r-emoji { font-size: 18px; }

.quickadd { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.quickadd .qa-label { font-weight: 700; font-size: 13px; }
.quickadd .qa-info { color: var(--muted); font-size: 12px; }
.quickadd input { width: 58px; padding: 7px 8px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; background: var(--card2); color: var(--ink); }
.quickadd .qa-btn { background: var(--green); color: #04140c; border: 0; padding: 8px 14px; border-radius: 10px; font-size: 13px; font-weight: 800; cursor: pointer; }
:root[data-theme="light"] .quickadd .qa-btn { color: #fff; }

.vitals { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.vital { background: var(--card2); border-radius: 10px; padding: 9px 11px; }
.vital .v-label { font-size: 11px; color: var(--muted); font-weight: 700; display: block; margin-bottom: 4px; }
.vital .v-label b { color: var(--ink); font-size: 14px; }
.vital-chart { width: 100%; height: auto; display: block; overflow: visible; }
.vital-chart .vital-grid { stroke: var(--line); stroke-width: .7px; stroke-dasharray: 2 2; }
.vital-chart .vital-y-label, .vital-chart .vital-x-label { fill: var(--muted); font-size: 7px; }
.vital-hrv .vital-line { stroke: var(--blue); }
.vital-hrv .vital-dot { fill: var(--blue); stroke: var(--card2); stroke-width: 1px; }
.vital-rhr .vital-line { stroke: var(--red); }
.vital-rhr .vital-dot { fill: var(--red); stroke: var(--card2); stroke-width: 1px; }
.up { color: var(--green); font-weight: 700; }
.down { color: var(--red); font-weight: 700; }
.flat { color: var(--muted); }

/* ---------- run rows + modal ---------- */
.meal.runrow { cursor: pointer; border-radius: 10px; padding: 10px 8px; margin: 0 -8px; border-bottom: 1px solid var(--line); }
.meal.runrow:hover { background: var(--card2); }
.meal.runrow:last-child { border-bottom: 0; }
.run-modal-backdrop {
  position: fixed; inset: 0; background: rgba(5, 8, 12, .72); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 24px 14px 60px;
  overflow-y: auto; -webkit-overflow-scrolling: touch; backdrop-filter: blur(3px);
}
.run-modal {
  background: var(--bg); border: 1px solid var(--line); border-radius: 20px; width: 100%; max-width: 620px;
  padding: 20px; box-shadow: 0 18px 60px rgba(0, 0, 0, .5);
}
.run-modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.run-modal-title { font-size: 19px; font-weight: 800; letter-spacing: -.3px; }
.run-modal-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.run-kpis .kpi { background: var(--card); border: 1px solid var(--line); }
.run-block { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-top: 12px; }
.run-block-title { font-size: 11px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .9px; margin-bottom: 6px; }
.zbar { display: flex; height: 16px; border-radius: 999px; overflow: hidden; }
.zseg { height: 100%; }
.zlabels { display: flex; gap: 10px; flex-wrap: wrap; font-size: 11px; color: var(--muted); font-weight: 600; margin-top: 6px; }
.run-map { height: 260px; border-radius: 12px; z-index: 1; }
.run-map svg { width: initial; height: initial; }  /* undo global chart-svg rule for Leaflet */
.run-map .leaflet-container { border-radius: 12px; }
.run-notes { font-size: 13px; line-height: 1.5; }
.run-notes .badge { margin-right: 6px; }

/* ---------- balance card ---------- */
.lf-row { display: flex; align-items: center; gap: 8px; font-size: 12px; margin-bottom: 7px; }
.lf-label { min-width: 72px; color: var(--muted); font-weight: 700; }
.lf-main { flex: 1; min-width: 0; }
.lf-track { height: 9px; background: var(--track); border-radius: 999px; position: relative; overflow: hidden; }
.lf-band { position: absolute; top: 0; bottom: 0; background: var(--green-soft); border-left: 1px dashed var(--green); border-right: 1px dashed var(--green); opacity: .9; }
.lf-fill { height: 100%; background: var(--green); border-radius: 999px; }
.lf-fill.over { background: var(--red); }
.lf-fill.under { background: var(--amber); }
.lf-scale { display: flex; justify-content: space-between; font-size: 9px; color: var(--muted); margin-top: 2px; }
.lf-val { min-width: 100px; text-align: right; font-weight: 700; }
.lf-status { margin-left: 4px; font-size: 11px; font-weight: 600; }
.lf-status.ok { color: var(--green); }
.lf-status.low { color: var(--amber); }
.lf-status.high { color: var(--red); }
.lf-range { display: block; font-size: 10px; color: var(--muted); font-weight: 400; }
.bal-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.bal-row:last-child { border-bottom: 0; }
.bal-name { min-width: 96px; font-weight: 700; }
.bal-bar-wrap { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.bal-bar { flex: 1; height: 9px; background: var(--track); border-radius: 999px; position: relative; overflow: hidden; }
.bal-band { position: absolute; top: 0; bottom: 0; background: var(--green-soft); border-left: 1px dashed var(--green); border-right: 1px dashed var(--green); opacity: .9; }
.bal-band.z-red { background: var(--red-soft); border: 0; }
.bal-band.z-amber { background: var(--amber-soft); border: 0; }
.bal-band.z-green { background: var(--green-soft); border: 0; }
.bal-fill { height: 100%; background: var(--blue); border-radius: 999px; }
.bal-fill.over { background: var(--red); }
.bal-sets { min-width: 52px; text-align: right; color: var(--muted); font-weight: 600; white-space: nowrap; font-size: 12px; }
.bal-readiness { min-width: 118px; text-align: right; color: var(--muted); white-space: nowrap; font-size: 12px; }
.bal-sug { font-size: 12.5px; line-height: 1.6; padding: 6px 0; color: var(--ink); }
.bal-sug + .bal-sug { border-top: 1px dashed var(--line); }
.train-today {
  margin-top: 12px; background: var(--green-soft); border-radius: 12px; padding: 11px 13px;
  font-size: 13px; line-height: 1.4; border-left: 3px solid var(--green);
}
.train-today.hvile { background: var(--red-soft); border-left-color: var(--red); }
.train-today.lett { background: var(--amber-soft); border-left-color: var(--amber); }
.train-today.conflict { background: var(--amber-soft); border-left-color: var(--amber); }

/* ---------- sprint card ---------- */
.sp-phase { margin-top: 8px; }
.sp-dots { display: flex; align-items: center; gap: 0; margin-bottom: 8px; }
.sp-dot {
  width: 26px; height: 26px; border-radius: 999px; display: inline-flex;
  align-items: center; justify-content: center; font-size: 12px; font-weight: 800;
  background: var(--track); color: var(--muted); border: 2px solid var(--line); flex: none;
}
.sp-dot.done { background: var(--green); color: #04140c; border-color: var(--green); }
.sp-dot.now { background: var(--card); color: var(--green); border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.sp-line { flex: 1; height: 2px; background: var(--line); max-width: 34px; }
.sp-name { font-weight: 800; font-size: 15px; }
.sp-dur { color: var(--muted); font-weight: 600; font-size: 12px; }
.sp-gate { font-size: 13px; padding: 4px 0; }
.sp-gate.ok { color: var(--ink); }
.sp-gate.no { color: var(--amber); }
.train-today .chips { margin-top: 6px; }

/* ---------- section divider inside cards ---------- */
.sect { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.sect-title { font-size: 11px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .9px; margin-bottom: 8px; }
