/* Atlas Training Log — design tokens & components.
   Contrast: every text token on --bg/--card clears WCAG AA (4.5:1) at its size. */

:root {
  --bg: #14110f;
  --card: #1b1713;
  --card2: #211c17;
  --border: #2c2720;
  --border2: #36312a;
  --text: #f4efe6;
  --text2: #cbc3b6;   /* secondary body */
  --muted: #9a9286;   /* captions, 5.9:1 */
  --faint: #938a7d;   /* smallest labels, 5.5:1 */
  --accent: #cbb892;  /* gold */
  --accent-ink: #241f18;
  --green: #5fb98f;
  --green-ink: #11271d;
  --blue: #4fb0c6;
  --amber: #e0a24a;
  --red: #d1785a;
  --purple: #8b7fd4;
  --font: 'Space Grotesk', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', monospace;
  --radius: 14px;
  --nav-h: 58px;
  --border-faint: #241f19;   /* hairline inside cards, dimmer than --border */
  --placeholder: #8a8276;    /* input placeholders — clears WCAG AA (>4.5:1) on --bg */
  /* spacing scale — use these instead of ad-hoc px so density stays consistent */
  --s1: 6px;
  --s2: 10px;
  --s3: 16px;
  --s4: 24px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); -webkit-font-smoothing: antialiased; }
#app { min-height: 100vh; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }
input::placeholder { color: var(--placeholder); opacity: 1; }
input[type="date"] { color-scheme: dark; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 218px; flex: 0 0 218px; position: sticky; top: 0; height: 100vh; padding: 22px 14px; border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.main { flex: 1; min-width: 0; padding: 20px clamp(14px, 3vw, 30px) calc(24px + env(safe-area-inset-bottom)); max-width: 1060px; }
.bottomnav { display: none; }

@media (max-width: 800px) {
  .sidebar { display: none; }
  .main { padding-bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); }
  .bottomnav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: rgba(20, 17, 15, .96); backdrop-filter: blur(10px); border-top: 1px solid var(--border); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
}

.grid2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(280px, 1.4fr); gap: 20px; align-items: start; }
@media (max-width: 1000px) { .grid2 { grid-template-columns: 1fr; } }
.stack { display: flex; flex-direction: column; gap: var(--s3); min-width: 0; }

/* ---------- type ---------- */
h1 { font-size: 26px; font-weight: 700; line-height: 1.15; letter-spacing: -0.01em; margin: 0; }
h2 { font-size: 17px; font-weight: 700; line-height: 1.25; margin: 0; }
/* Data-bearing card titles: numbers should outrank their label, in tabular mono. */
h2.stat { font-family: var(--mono); font-size: 22px; font-variant-numeric: tabular-nums; letter-spacing: 0; }
.kicker { font-family: var(--mono); font-size: 10.5px; font-weight: 600; letter-spacing: .13em; text-transform: uppercase; color: var(--faint); }
.sub { font-size: 13px; color: var(--muted); line-height: 1.5; }
.mono { font-family: var(--mono); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- primitives ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s3) 18px; }
.panel { border: 1px solid var(--border); border-radius: 12px; padding: var(--s2) 12px; }
.card + .card { margin-top: 0; }

button { font-family: var(--font); cursor: pointer; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border-radius: 10px; border: 1px solid transparent; font-size: 14px; font-weight: 600; background: var(--card2); color: var(--text); border-color: var(--border2); }
.btn:hover { border-color: #4a4438; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.good { background: var(--green); color: var(--green-ink); border-color: transparent; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: transparent; color: var(--red); border-color: var(--border2); }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, .navitem:focus-visible, .check:focus-visible, .tile:focus-visible, a:focus-visible, .linkish:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible { outline: none; border-color: var(--green) !important; }

.linkish { background: none; border: none; padding: 4px 2px; color: var(--accent); font-size: 13px; font-weight: 600; }

.input { background: var(--bg); border: 1px solid var(--border2); border-radius: 9px; padding: 10px 12px; color: var(--text); font: 500 16px var(--font); width: 100%; min-height: 44px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; flex: 1; }
.field > label { font-family: var(--mono); font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.row { display: flex; gap: 12px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.chip { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-family: var(--mono); font-size: 10.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; padding: 4px 9px; border-radius: 7px; }
/* Status chips — one definition of hue+tint so "Done"/"Synced"/etc. never drift. */
.chip.good { color: var(--green); background: rgba(95, 185, 143, .12); }
.chip.warn { color: var(--amber); background: rgba(224, 162, 74, .12); }

.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--border2); border-radius: 10px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg > button { min-height: 44px; padding: 7px 14px; border: none; border-radius: 8px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; }
.seg > button[aria-pressed="true"] { background: var(--card2); color: var(--text); box-shadow: inset 0 0 0 1px var(--border2); }

.check { width: 28px; height: 28px; min-width: 28px; border-radius: 8px; border: 1.5px solid var(--border2); background: transparent; display: inline-flex; align-items: center; justify-content: center; color: transparent; font-size: 15px; position: relative; padding: 0; }
.check::after { content: ""; position: absolute; inset: -9px; }
.check[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: var(--green-ink); }

.navitem { display: flex; align-items: center; gap: 10px; width: 100%; border: none; background: transparent; color: var(--muted); font-size: 14px; font-weight: 600; padding: 11px 12px; border-radius: 10px; text-align: left; }
.navitem[aria-current="page"] { background: var(--card2); color: var(--text); }
.bottomnav .navitem { flex: 1; flex-direction: column; gap: 3px; font-size: 10.5px; padding: 7px 2px; align-items: center; min-height: 50px; }
.navitem .ico { display: inline-flex; align-items: center; line-height: 1; }
.navitem .ico svg { width: 20px; height: 20px; }
.bottomnav .navitem .ico svg { width: 23px; height: 23px; }

.empty { text-align: center; padding: 30px 18px; color: var(--muted); }
.empty .big { font-size: 26px; margin-bottom: 8px; }
.empty b { color: var(--text); display: block; margin-bottom: 4px; font-size: 15px; }

/* ---------- toast ---------- */
.toastwrap { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
@media (min-width: 801px) { .toastwrap { bottom: 24px; } }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; background: #262019; border: 1px solid var(--border2); border-radius: 12px; padding: 11px 16px; font-size: 13.5px; font-weight: 500; box-shadow: 0 8px 30px rgba(0,0,0,.45); animation: rise .18s ease; max-width: min(92vw, 480px); }
.toast button { background: none; border: none; color: var(--accent); font-weight: 700; font-size: 13px; padding: 4px 6px; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- sheet / modal ---------- */
.sheetwrap { position: fixed; inset: 0; z-index: 80; background: rgba(8,6,5,.66); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 16px; }
.sheet { width: 420px; max-width: 100%; max-height: calc(100dvh - 32px); overflow: auto; background: var(--card); border: 1px solid var(--border2); border-radius: 16px; padding: 20px; animation: rise .16s ease; }
@media (max-width: 800px) {
  .sheetwrap { align-items: flex-end; padding: 0; }
  .sheet { width: 100%; border-radius: 18px 18px 0 0; max-height: calc(100dvh - max(20px, env(safe-area-inset-top))); padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}
.sheet .actions { display: flex; gap: 10px; position: sticky; bottom: 0; background: var(--card); padding-top: 12px; margin-top: 6px; border-top: 1px solid var(--border); box-shadow: 0 -10px 12px -6px var(--card); }
@keyframes sheetnudge { 0%, 100% { transform: none; } 30% { transform: translateY(-5px); } 65% { transform: translateY(2px); } }
.sheet.nudge { animation: sheetnudge .25s ease; }
.sheet .actions .btn { flex: 1; }

/* ---------- specific widgets ---------- */
.metric-tile { display: flex; flex-direction: column; gap: 2px; background: var(--card2); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.metric-tile .val { font-family: var(--mono); font-size: 20px; font-weight: 600; background: none; border: none; color: var(--text); width: 100%; padding: 0; min-height: 30px; }
.metric-tile .goal { font-size: 11px; color: var(--faint); font-family: var(--mono); }
.steppers { display: flex; gap: 6px; margin-top: 6px; }
.steppers button { flex: 1; min-height: 40px; border-radius: 8px; background: var(--bg); border: 1px solid var(--border2); color: var(--text2); font-size: 16px; font-weight: 600; }

.weekstrip { display: flex; gap: 5px; }
.weekstrip .tile { flex: 1; border: 1px solid var(--border); background: var(--card2); border-radius: 9px; padding: 7px 2px; text-align: center; font-family: var(--mono); font-size: 10px; color: var(--muted); cursor: pointer; min-height: 52px; }
.weekstrip .tile.today { border-color: var(--accent); }
.weekstrip .tile .d { font-size: 12px; font-weight: 700; color: var(--text2); }
.weekstrip .tile .done { color: var(--green); }

.setrow { display: grid; grid-template-columns: 28px 1fr 96px 76px; gap: 10px; align-items: center; padding: 7px 0; }
.setrow input { background: var(--bg); border: 1px solid var(--border2); border-radius: 8px; padding: 8px 9px; color: var(--text); font: 600 16px var(--mono); width: 100%; min-width: 0; text-align: right; min-height: 44px; }

.bar { height: 7px; border-radius: 4px; background: var(--card2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--green); border-radius: 4px; }

.ringwrap { position: relative; width: 66px; height: 66px; }
.ringwrap .lab { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 15px; font-weight: 700; }

table.mini { width: 100%; border-collapse: collapse; font-size: 13px; }
table.mini td { padding: 7px 4px; border-bottom: 1px solid var(--border-faint); }
table.mini td:last-child { text-align: right; }

.tag { font-family: var(--mono); font-size: 10px; font-weight: 700; letter-spacing: .08em; padding: 3px 7px; border-radius: 6px; }

details.fold > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::after { content: "▾"; color: var(--faint); transition: transform .15s; }
details.fold[open] > summary::after { transform: rotate(180deg); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
