/* StayTrack design system — calm, mobile-first, 320px+.
   Light + dark via system preference, overridable with html[data-theme]. */

:root {
  --accent: #0F7B6C;
  --accent-strong: #0B6154;
  --accent-soft: #E3F1EE;
  --bg: #F6F7F9;
  --surface: #FFFFFF;
  --surface-2: #EFF1F4;
  --text: #1B2430;
  --text-soft: #5B6675;
  --line: #DFE3E8;
  --danger: #B3382E;
  --danger-soft: #F7E7E5;
  --warn: #9A6A18;
  --warn-soft: #F7EEDD;
  --ok: #2E7D4F;
  --ok-soft: #E4F1E9;
  --info: #2B6CB0;
  --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 4px 14px rgba(16, 24, 32, .05);
  --radius: 14px;
  --radius-sm: 9px;
  --space-1: 4px; --space-2: 8px; --space-3: 12px;
  --space-4: 16px; --space-5: 24px; --space-6: 36px;
  --nav-height: 58px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #35A08E;
    --accent-strong: #4DB8A6;
    --accent-soft: #12332E;
    --bg: #101418;
    --surface: #1A2026;
    --surface-2: #232B33;
    --text: #E8ECF1;
    --text-soft: #9AA6B4;
    --line: #2E3944;
    --danger: #E0766C;
    --danger-soft: #3A211E;
    --warn: #D3A75B;
    --warn-soft: #362B17;
    --ok: #6FBF8F;
    --ok-soft: #1C3126;
    --info: #7AA7D9;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 4px 14px rgba(0, 0, 0, .28);
    color-scheme: dark;
  }
}

html[data-theme="light"] {
  --accent: #0F7B6C; --accent-strong: #0B6154; --accent-soft: #E3F1EE;
  --bg: #F6F7F9; --surface: #FFFFFF; --surface-2: #EFF1F4;
  --text: #1B2430; --text-soft: #5B6675; --line: #DFE3E8;
  --danger: #B3382E; --danger-soft: #F7E7E5; --warn: #9A6A18; --warn-soft: #F7EEDD;
  --ok: #2E7D4F; --ok-soft: #E4F1E9; --info: #2B6CB0;
  --shadow: 0 1px 2px rgba(16,24,32,.06), 0 4px 14px rgba(16,24,32,.05);
  color-scheme: light;
}

html[data-theme="dark"] {
  --accent: #35A08E; --accent-strong: #4DB8A6; --accent-soft: #12332E;
  --bg: #101418; --surface: #1A2026; --surface-2: #232B33;
  --text: #E8ECF1; --text-soft: #9AA6B4; --line: #2E3944;
  --danger: #E0766C; --danger-soft: #3A211E; --warn: #D3A75B; --warn-soft: #362B17;
  --ok: #6FBF8F; --ok-soft: #1C3126; --info: #7AA7D9;
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 4px 14px rgba(0,0,0,.28);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 12px);
}
body.no-nav { padding-bottom: var(--space-5); }

main {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--space-4);
  padding-top: calc(var(--space-4) + env(safe-area-inset-top, 0px));
}
.wide main, main.wide { max-width: 960px; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 var(--space-3); }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 var(--space-3); }
a { color: var(--accent); }

.skip-link {
  position: absolute; left: -9999px; top: 0; background: var(--surface);
  padding: var(--space-2) var(--space-3); z-index: 100; border-radius: var(--radius-sm);
}
.skip-link:focus { left: var(--space-3); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}
.card.tight { padding: var(--space-3); }
.card-header {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--space-2); margin-bottom: var(--space-2);
}
.muted { color: var(--text-soft); }
.small { font-size: .85rem; }
.tiny { font-size: .75rem; }

/* -------------------------------------------------------------- top strip */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: var(--space-2); margin-bottom: var(--space-4);
}
.topbar .date { font-weight: 600; }
.status-dots { display: flex; gap: var(--space-2); align-items: center; }
.dot {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .72rem; color: var(--text-soft);
}
.dot::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-soft); display: inline-block;
}
.dot.on::before { background: var(--ok); }
.dot.off::before { background: var(--danger); }
.dot.warn::before { background: var(--warn); }

/* -------------------------------------------------------------- current */
.current-card { border-left: 5px solid var(--accent); }
.current-card.overdue { border-left-color: var(--danger); }
.current-card .title { font-size: 1.3rem; font-weight: 700; margin: 2px 0 4px; }
.current-card .instruction { color: var(--text-soft); }
.current-card .times { font-variant-numeric: tabular-nums; }
.countdown { font-weight: 600; font-variant-numeric: tabular-nums; }
.countdown.overdue { color: var(--danger); }

.cat-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .78rem; color: var(--text-soft);
  border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px;
  background: var(--surface-2);
}
.cat-chip .swatch { width: 9px; height: 9px; border-radius: 50%; }

.actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }

/* ------------------------------------------------------------- buttons */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); border-radius: var(--radius-sm);
  padding: 10px 16px; font-size: .95rem; font-weight: 600;
  cursor: pointer; min-height: 44px; min-width: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
html[data-theme="dark"] .btn.primary, .btn.primary.dark-safe { color: #06251F; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .btn.primary { color: #06251F; }
}
.btn.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* -------------------------------------------------------------- badges */
.badge {
  display: inline-block; font-size: .72rem; font-weight: 600;
  border-radius: 999px; padding: 2px 9px; white-space: nowrap;
}
.badge.pending, .badge.upcoming { background: var(--surface-2); color: var(--text-soft); }
.badge.active { background: var(--accent-soft); color: var(--accent); }
.badge.in_progress { background: var(--accent-soft); color: var(--accent); }
.badge.done { background: var(--ok-soft); color: var(--ok); }
.badge.snoozed { background: var(--warn-soft); color: var(--warn); }
.badge.overdue, .badge.missed { background: var(--danger-soft); color: var(--danger); }
.badge.skipped, .badge.rescheduled, .badge.carried_over { background: var(--surface-2); color: var(--text-soft); }
.badge.win { background: var(--accent-soft); color: var(--accent); }

/* -------------------------------------------------------------- timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: grid;
  grid-template-columns: 52px 14px 1fr auto;
  gap: 0 var(--space-2);
  align-items: start;
  padding: var(--space-2) 0;
  position: relative;
}
.timeline .t-time { font-size: .8rem; color: var(--text-soft); font-variant-numeric: tabular-nums; padding-top: 2px; }
.timeline .t-rail { position: relative; height: 100%; min-height: 30px; }
.timeline .t-rail::before {
  content: ""; position: absolute; left: 5px; top: 18px; bottom: -10px;
  width: 2px; background: var(--line);
}
.timeline li:last-child .t-rail::before { display: none; }
.timeline .t-dot {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--line); background: var(--surface);
  position: relative; top: 4px;
}
.timeline li.done .t-dot { background: var(--ok); border-color: var(--ok); }
.timeline li.active .t-dot, .timeline li.in_progress .t-dot { background: var(--accent); border-color: var(--accent); }
.timeline li.overdue .t-dot { background: var(--danger); border-color: var(--danger); }
.timeline li.snoozed .t-dot { background: var(--warn); border-color: var(--warn); }
.timeline li.skipped .t-dot, .timeline li.missed .t-dot { background: var(--line); }
.timeline .t-body { min-width: 0; }
.timeline .t-title { font-weight: 600; font-size: .92rem; }
.timeline li.done .t-title, .timeline li.skipped .t-title, .timeline li.missed .t-title {
  color: var(--text-soft); font-weight: 500;
}
.timeline li.skipped .t-title, .timeline li.missed .t-title { text-decoration: line-through; text-decoration-thickness: 1px; }
.timeline .t-sub { font-size: .78rem; color: var(--text-soft); }
.timeline .t-status { justify-self: end; padding-top: 2px; }

/* ------------------------------------------------------------ wins/lists */
.win-list { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--space-2); }
.win-list li {
  display: flex; align-items: center; gap: var(--space-2);
  background: var(--surface-2); border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
}
.win-list .num {
  width: 24px; height: 24px; border-radius: 50%; flex: none;
  background: var(--accent); color: #fff; font-size: .8rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.win-list li.done { opacity: .72; }
.win-list li.done .txt { text-decoration: line-through; }

.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li {
  display: flex; justify-content: space-between; align-items: center;
  gap: var(--space-2); padding: var(--space-2) 0; border-bottom: 1px solid var(--line);
}
.plain-list li:last-child { border-bottom: 0; }

/* ------------------------------------------------------------- progress */
.meter { background: var(--surface-2); border-radius: 999px; height: 8px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.stat-row { display: flex; justify-content: space-between; gap: var(--space-2); font-size: .88rem; padding: 4px 0; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.stat-tile { background: var(--surface-2); border-radius: var(--radius-sm); padding: var(--space-3); }
.stat-tile .big { font-size: 1.35rem; font-weight: 700; }

/* -------------------------------------------------------------- banners */
.banner {
  border-radius: var(--radius); padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4); font-size: .92rem;
  border: 1px solid transparent;
}
.banner.rescue { background: var(--warn-soft); border-color: var(--warn); color: var(--text); }
.banner.low-energy { background: var(--accent-soft); color: var(--text); }
.banner.offline { background: var(--surface-2); color: var(--text-soft); }

/* ---------------------------------------------------------------- forms */
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 4px; }
input[type="text"], input[type="password"], input[type="email"], input[type="number"],
input[type="date"], input[type="time"], select, textarea {
  width: 100%; padding: 10px 12px; font-size: 1rem;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  min-height: 44px;
}
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: var(--space-3); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.field .hint { font-size: .78rem; color: var(--text-soft); margin-top: 3px; }
.field .error, .form-error { color: var(--danger); font-size: .85rem; margin-top: 4px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); margin: 0 0 var(--space-3); }
legend { font-size: .85rem; font-weight: 600; padding: 0 6px; }
.check-row { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); }
.check-row input { width: 20px; height: 20px; min-height: 0; }
.check-row label { margin: 0; font-weight: 500; }

/* --------------------------------------------------------------- dialog */
dialog {
  border: none; border-radius: var(--radius); box-shadow: var(--shadow);
  background: var(--surface); color: var(--text);
  width: min(92vw, 420px); padding: var(--space-4);
}
dialog::backdrop { background: rgba(10, 14, 18, .45); }
dialog h2 { margin-bottom: var(--space-3); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-4); }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }

/* ------------------------------------------------------------ bottom nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: .68rem; color: var(--text-soft); text-decoration: none;
  min-height: 44px; padding-top: 6px;
}
.bottom-nav a .ico { font-size: 1.15rem; line-height: 1; }
.bottom-nav a.active { color: var(--accent); font-weight: 700; }

/* ---------------------------------------------------------------- toast */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 14px);
  z-index: 60; display: grid; gap: 8px; width: min(92vw, 420px);
}
.toast-item {
  background: var(--text); color: var(--bg);
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: .9rem;
  box-shadow: var(--shadow); text-align: center;
}
.toast-item.error { background: var(--danger); color: #fff; }

/* ---------------------------------------------------------------- login */
.login-wrap { max-width: 360px; margin: 12vh auto 0; padding: var(--space-4); }
.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: var(--space-4); }
.login-logo img { width: 44px; height: 44px; border-radius: 11px; }
.login-logo .name { font-size: 1.3rem; font-weight: 800; }

/* ---------------------------------------------------------------- focus */
.focus-wrap { text-align: center; padding-top: var(--space-6); }
.focus-timer { font-size: 3rem; font-weight: 800; font-variant-numeric: tabular-nums; margin: var(--space-4) 0; }
.focus-timer.overdue { color: var(--danger); }
.focus-target {
  background: var(--accent-soft); color: var(--text);
  border-radius: var(--radius); padding: var(--space-3); margin: var(--space-4) 0;
}

/* ----------------------------------------------------------------- week */
.week-day { margin-bottom: var(--space-4); }
.week-day h2 { display: flex; justify-content: space-between; align-items: baseline; }
.week-day h2 .today-tag { color: var(--accent); font-size: .75rem; }

/* ---------------------------------------------------------------- admin */
.admin-tabs {
  display: flex; gap: 2px; overflow-x: auto; margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--line); -webkit-overflow-scrolling: touch;
}
.admin-tabs a {
  padding: 10px 14px; text-decoration: none; color: var(--text-soft);
  font-size: .88rem; font-weight: 600; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.admin-tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--text-soft); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }

details { border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: var(--space-3); }
details > summary {
  cursor: pointer; padding: var(--space-3); font-weight: 600;
  list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
details > summary::after { content: "▾"; color: var(--text-soft); }
details[open] > summary::after { content: "▴"; }
details .details-body { padding: 0 var(--space-3) var(--space-3); }

.hidden { display: none !important; }
.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;
}

@media (min-width: 720px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
html[data-reduced-motion="true"] *, html[data-reduced-motion="true"] *::before, html[data-reduced-motion="true"] *::after {
  animation: none !important; transition: none !important;
}
