/* ============ Stat Max design system ============ */
:root {
  --font-display: 'Sora', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;

  --grad-a: #7c3aed;
  --grad-b: #ec4899;
  --grad-c: #f97316;
  --accent: #a855f7;
  --accent-2: #ec4899;
  --brand-grad: linear-gradient(135deg, var(--grad-a), var(--grad-b) 55%, var(--grad-c));

  --ok: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;
  --info: #38bdf8;

  --radius: 18px;
  --radius-sm: 12px;
  --nav-h: 64px;
}

html[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0b0b14;
  --bg-glow-1: rgba(124, 58, 237, 0.22);
  --bg-glow-2: rgba(236, 72, 153, 0.14);
  --surface: rgba(255, 255, 255, 0.05);
  --surface-2: rgba(255, 255, 255, 0.09);
  --surface-solid: #161624;
  --border: rgba(255, 255, 255, 0.1);
  --text: #f3f2fa;
  --text-dim: #a3a0b8;
  --shadow: 0 10px 32px rgba(0, 0, 0, 0.45);
  --chip-bg: rgba(255, 255, 255, 0.08);
}

html[data-theme='light'] {
  color-scheme: light;
  --bg: #f6f5fb;
  --bg-glow-1: rgba(124, 58, 237, 0.14);
  --bg-glow-2: rgba(249, 115, 22, 0.1);
  --surface: rgba(255, 255, 255, 0.75);
  --surface-2: rgba(255, 255, 255, 0.95);
  --surface-solid: #ffffff;
  --border: rgba(20, 15, 45, 0.09);
  --text: #17142b;
  --text-dim: #6b6685;
  --shadow: 0 10px 28px rgba(60, 40, 130, 0.12);
  --chip-bg: rgba(124, 58, 237, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(600px 420px at 12% -6%, var(--bg-glow-1), transparent 65%),
    radial-gradient(520px 380px at 105% 12%, var(--bg-glow-2), transparent 65%);
  pointer-events: none;
}

h1, h2, h3 { font-family: var(--font-display); margin: 0; letter-spacing: -0.02em; }

#app {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom));
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0 18px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-weight: 800; font-size: 20px;
  text-decoration: none; color: var(--text);
}
.brand .logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--brand-grad);
  display: grid; place-items: center;
  color: #fff; font-size: 17px; font-weight: 800;
  box-shadow: 0 4px 14px rgba(168, 85, 247, 0.45);
}
.brand .max {
  background: var(--brand-grad);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.top-actions { display: flex; gap: 8px; align-items: center; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: grid; place-items: center;
  cursor: pointer; font-size: 17px;
  backdrop-filter: blur(10px);
  transition: transform 0.15s ease, background 0.15s ease;
}
.icon-btn:active { transform: scale(0.93); }

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }

.card.clickable { cursor: pointer; transition: transform 0.15s ease, border-color 0.15s ease; }
.card.clickable:active { transform: scale(0.985); }
.card.clickable:hover { border-color: rgba(168, 85, 247, 0.45); }

.card-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-title { font-size: 17px; font-weight: 700; font-family: var(--font-display); }
.card-sub { color: var(--text-dim); font-size: 13px; margin-top: 3px; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 22px 0 12px;
}
.section-head h2 { font-size: 19px; }

/* ---------- hero / stats ---------- */
.hero {
  border-radius: 22px;
  padding: 22px 20px;
  background: var(--brand-grad);
  color: #fff;
  box-shadow: 0 14px 40px rgba(168, 85, 247, 0.35);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(340px 200px at 88% -20%, rgba(255, 255, 255, 0.35), transparent 60%);
}
.hero h1 { font-size: 24px; position: relative; z-index: 1; }
.hero p { margin: 6px 0 0; opacity: 0.92; font-size: 14px; position: relative; z-index: 1; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 14px;
}
@media (min-width: 560px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat-tile { text-align: left; }
.stat-tile .num {
  font-family: var(--font-display); font-weight: 800; font-size: 26px; line-height: 1.1;
  background: var(--brand-grad);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.stat-tile .lbl { color: var(--text-dim); font-size: 12px; margin-top: 4px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }

/* ---------- buttons / inputs ---------- */
.btn {
  appearance: none; border: none; cursor: pointer;
  font-family: var(--font-body); font-weight: 700; font-size: 15px;
  padding: 13px 20px; border-radius: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
  color: var(--text);
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary {
  background: var(--brand-grad); color: #fff;
  box-shadow: 0 6px 20px rgba(168, 85, 247, 0.4);
}
.btn-ghost { background: var(--surface); border: 1px solid var(--border); }
.btn-danger { background: rgba(239, 68, 68, 0.12); color: var(--bad); border: 1px solid rgba(239, 68, 68, 0.3); }
.btn-sm { padding: 8px 14px; font-size: 13px; border-radius: 11px; }
.btn-block { width: 100%; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 13px 14px;
  border-radius: 13px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px; /* prevents iOS zoom */
  outline: none;
  transition: border-color 0.15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* ---------- chips / badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
  background: var(--chip-bg); color: var(--text-dim);
}
.chip.completed { background: rgba(16, 185, 129, 0.14); color: var(--ok); }
.chip.skipped { background: rgba(245, 158, 11, 0.14); color: var(--warn); }
.chip.na { background: rgba(239, 68, 68, 0.13); color: var(--bad); }
.chip.substituted { background: rgba(56, 189, 248, 0.14); color: var(--info); }
.chip.planned { background: var(--chip-bg); color: var(--text-dim); }
.chip.admin { background: rgba(168, 85, 247, 0.16); color: var(--accent); }
.chip.disabled-chip { background: rgba(239, 68, 68, 0.13); color: var(--bad); }

.progress-bar {
  height: 7px; border-radius: 999px; background: var(--chip-bg); overflow: hidden; margin-top: 10px;
}
.progress-bar > div { height: 100%; border-radius: 999px; background: var(--brand-grad); transition: width 0.4s ease; }

/* ---------- bottom nav ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-around;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface-solid) 82%, transparent);
  backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-width: 64px; padding: 6px 8px; border-radius: 12px;
  text-decoration: none; color: var(--text-dim);
  font-size: 11px; font-weight: 600;
  transition: color 0.15s ease;
}
.bottom-nav a .ni { font-size: 21px; line-height: 1; }
.bottom-nav a.active { color: var(--accent); }
.bottom-nav a.active .ni { filter: drop-shadow(0 2px 8px rgba(168, 85, 247, 0.55)); }

/* ---------- auth screens ---------- */
.auth-wrap { max-width: 420px; margin: 0 auto; padding-top: 8vh; }
.auth-logo { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 28px; text-align: center; }
.auth-logo .logo-big {
  width: 76px; height: 76px; border-radius: 22px;
  background: var(--brand-grad);
  display: grid; place-items: center;
  color: #fff; font-size: 36px; font-weight: 800; font-family: var(--font-display);
  box-shadow: 0 14px 44px rgba(168, 85, 247, 0.5);
}
.auth-logo h1 { font-size: 30px; }
.auth-logo p { margin: 0; color: var(--text-dim); font-size: 14px; }
.auth-switch { text-align: center; margin-top: 18px; color: var(--text-dim); font-size: 14px; }
.auth-switch a { color: var(--accent); font-weight: 700; text-decoration: none; }

/* ---------- tables (week logs, admin) ---------- */
.table-scroll { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table.sm-table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 430px; }
.sm-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-dim); padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.sm-table td { padding: 11px 10px; border-bottom: 1px solid var(--border); }
.sm-table tr:last-child td { border-bottom: none; }
.sm-table tr.row-click { cursor: pointer; }
.sm-table tr.row-click:hover td { background: var(--chip-bg); }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(8, 6, 18, 0.6);
  backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.18s ease;
}
@media (min-width: 560px) { .modal-overlay { align-items: center; } }
.modal {
  width: 100%; max-width: 480px; max-height: 88dvh; overflow-y: auto;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  animation: slideUp 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@media (min-width: 560px) { .modal { border-radius: 24px; } }
.modal h3 { font-size: 19px; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }

@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideUp { from { transform: translateY(26px); opacity: 0.6; } }

/* ---------- toasts ---------- */
#toasts {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 380px);
}
.toast {
  padding: 13px 16px; border-radius: 14px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 9px;
  animation: slideDown 0.25s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.toast.ok { border-color: rgba(16, 185, 129, 0.4); }
.toast.err { border-color: rgba(239, 68, 68, 0.45); }
@keyframes slideDown { from { transform: translateY(-18px); opacity: 0; } }

/* ---------- charts ---------- */
.chart-wrap { margin-top: 6px; }
.chart-wrap svg { width: 100%; height: auto; display: block; }

/* ---------- misc ---------- */
.empty {
  text-align: center; padding: 42px 20px; color: var(--text-dim);
}
.empty .big { font-size: 42px; margin-bottom: 10px; }
.empty p { margin: 4px 0 16px; font-size: 14px; }

.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-dim); text-decoration: none; font-size: 13px; font-weight: 600;
  margin-bottom: 12px;
}
.back-link:hover { color: var(--accent); }

.crumb-title { font-size: 24px; margin-bottom: 2px; }
.crumb-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 16px; }

.list-gap { display: flex; flex-direction: column; gap: 12px; }

.spinner {
  width: 34px; height: 34px; margin: 60px auto;
  border-radius: 50%;
  border: 3px solid var(--chip-bg);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.status-select { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.status-select button {
  border: 1.5px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 700;
  color: var(--text-dim); cursor: pointer; font-family: var(--font-body);
}
.status-select button.sel-completed { border-color: var(--ok); color: var(--ok); background: rgba(16,185,129,0.1); }
.status-select button.sel-skipped { border-color: var(--warn); color: var(--warn); background: rgba(245,158,11,0.1); }
.status-select button.sel-na { border-color: var(--bad); color: var(--bad); background: rgba(239,68,68,0.1); }
.status-select button.sel-substituted { border-color: var(--info); color: var(--info); background: rgba(56,189,248,0.1); }
.status-select button.sel-planned { border-color: var(--accent); color: var(--accent); background: rgba(168,85,247,0.1); }

.user-line { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--brand-grad); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 16px;
  flex-shrink: 0;
}
