/* ==========================================================================
   tasking — theme tokens
   ========================================================================== */

:root {
  --primary: #003152;
  --primary-2: #0a4a75;
  --accent: #addff1;
  --accent-strong: #4fb8e0;
  /* readable accent text: deep navy on light, pale blue on dark */
  --accent-text: #0a4a75;
  /* light mode = clean white */
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f4f7fb;
  --line: rgba(0, 49, 82, 0.14);
  --text: #10263a;
  --muted: #5d7689;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --office: #0078d4;
  --personal: #8a63d2;
  /* per-surface tints (form fields, chart panel, header bar, sheet scrim) */
  --input-bg: rgba(0, 49, 82, 0.055);
  --chart-bg: rgba(0, 49, 82, 0.04);
  --appbar-bg: rgba(255, 255, 255, 0.85);
  --appbar-frost: rgba(255, 255, 255, 0.75);
  --scrim: rgba(0, 16, 32, 0.45);

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 16px 44px rgba(0, 49, 82, 0.14);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);

  --sab: max(env(safe-area-inset-bottom), var(--sab-floor, 0px));
  --sab-floor: 0px;
  --stack-lift: 0px;
  --kb-inset: 0px;
  --dock-h: 46px;
  --tabbar-h: calc(max(var(--sab), 14px) + var(--stack-lift) + var(--dock-h));

  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Plus Jakarta Sans', var(--font-ui);
}

/* dark mode = pure black, keeps the same navy/ice accent pair */
[data-theme="dark"] {
  --accent-text: #addff1;
  --bg: #000000;
  --surface: rgba(13, 32, 52, 0.86);
  --surface-2: rgba(20, 44, 68, 0.9);
  --line: rgba(173, 223, 241, 0.14);
  --text: #e8f3fa;
  --muted: #8fb0c5;
  --success: #4ade80;
  --warning: #fbbf24;
  --danger: #f87171;
  --office: #4fb8e0;
  --personal: #c6a8ff;
  --input-bg: rgba(6, 18, 31, 0.7);
  --chart-bg: rgba(6, 18, 31, 0.5);
  --appbar-bg: rgba(6, 18, 31, 0.85);
  --appbar-frost: rgba(6, 18, 31, 0.6);
  --scrim: rgba(2, 8, 15, 0.6);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

@font-face {
  font-family: 'Inter';
  src: url('fonts/inter-latin-var.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: 'Plus Jakarta Sans';
  src: url('fonts/plus-jakarta-sans-latin-var.woff2') format('woff2');
  font-weight: 200 800;
  font-display: swap;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2, h3 { font-family: var(--font-display); margin: 0; }
p { margin: 0; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 16px; color: var(--text); }
img { display: block; }

.sprite { display: none; }
.icon { width: 22px; height: 22px; fill: currentColor; flex-shrink: 0; }
.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;
}
.muted { color: var(--muted); }

/* ==========================================================================
   buttons / fields
   ========================================================================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; border-radius: 12px; padding: 11px 18px;
  font-size: 14px; font-weight: 600; background: transparent; color: var(--text);
  transition: transform 0.12s var(--ease-out), background 0.15s, border-color 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn .icon { width: 18px; height: 18px; }
.btn.primary { background: linear-gradient(135deg, var(--accent-strong), #2f8fc0); color: #04283f; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: var(--line); color: var(--accent-text); background: var(--input-bg); }
.btn.ghost:hover { background: var(--appbar-frost); }
.btn.danger { border-color: rgba(248,113,113,0.4); color: var(--danger); background: rgba(248,113,113,0.08); }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; pointer-events: none; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid transparent;
  background: transparent; color: var(--accent-text); position: relative;
  transition: background 0.15s;
}
.icon-btn:hover { background: rgba(173,223,241,0.1); }
.icon-btn.ghost { color: var(--muted); }

.badge {
  position: absolute; top: 4px; right: 4px; min-width: 16px; height: 16px;
  border-radius: 999px; background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center; padding: 0 4px;
}

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; }
.field .opt { font-style: normal; font-weight: 400; opacity: 0.7; }
.field input, .field select, .field textarea {
  background: var(--input-bg); border: 1px solid var(--line); border-radius: 11px;
  padding: 11px 13px; outline: none; width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent-strong); box-shadow: 0 0 0 3px rgba(79,184,224,0.18);
}
.field textarea { resize: vertical; min-height: 42px; }
.field select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.field-hint { color: var(--muted); font-size: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check-row { flex-direction: row; align-items: center; gap: 10px; }
.check-row input { width: 18px; height: 18px; accent-color: var(--accent-strong); }
.check-row span { font-size: 14px; color: var(--text); }

.alert { padding: 10px 14px; border-radius: 10px; font-size: 13.5px; margin-top: 12px; }
.alert.error { background: rgba(248,113,113,0.12); border: 1px solid rgba(248,113,113,0.35); color: var(--danger); }

.input-affix { position: relative; }
.input-affix input { padding-right: 44px; }
.affix-btn {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; border: 0; border-radius: 9px; background: transparent;
  color: var(--muted); display: flex; align-items: center; justify-content: center;
}

/* toggle switch */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; border-radius: 999px; background: rgba(143,176,197,0.3);
  transition: background 0.2s; cursor: pointer;
}
.switch .slider::before {
  content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px;
  border-radius: 50%; background: #fff; transition: transform 0.2s var(--ease-out);
}
.switch input:checked + .slider { background: var(--accent-strong); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* ==========================================================================
   auth screen
   ========================================================================== */

.auth-screen {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px; padding-bottom: calc(24px + var(--sab));
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 22px; padding: 32px 26px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: stretch; text-align: center;
}
.auth-card .logo { margin: 0 auto 10px; border-radius: 18px; }
.auth-card h1 { font-size: 28px; letter-spacing: -0.02em; }
.auth-sub { margin: 4px 0 22px; font-size: 14px; }
.auth-card form { text-align: left; }
.auth-card .btn.block { margin-top: 6px; }
.auth-switch { margin-top: 18px; font-size: 13.5px; }
.auth-switch button { background: none; border: 0; color: var(--accent-strong); font-weight: 600; font-size: inherit; }

/* ==========================================================================
   app shell
   ========================================================================== */

.app { min-height: 100dvh; display: flex; flex-direction: column; padding-bottom: calc(var(--tabbar-h) + 92px); }

.appbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--appbar-bg);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.appbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand .logo { border-radius: 11px; }
.brand-text h1 { font-size: 19px; letter-spacing: -0.02em; }
.brand-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-actions { display: flex; align-items: center; gap: 4px; }

.banner {
  max-width: 1100px; margin: 12px auto 0; width: calc(100% - 32px);
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(135deg, rgba(79,184,224,0.16), rgba(198,168,255,0.1));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
}
.banner-icon { color: var(--warning); display: flex; }
.banner-text { flex: 1; min-width: 0; }
.banner-text strong { font-size: 14px; }
.banner-text p { font-size: 12.5px; color: var(--muted); }

/* rail (view dock / sidebar) */
.rail { max-width: 1100px; margin: 0 auto; width: 100%; padding: 0 16px; }

.view-toggle { position: relative; z-index: 40; }
.view-trigger {
  position: fixed; bottom: calc(max(var(--sab), 14px) + var(--stack-lift)); left: 16px;
  height: var(--dock-h); display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px;
  color: var(--text); padding: 0 16px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow);
}
.view-trigger-chevron { width: 18px; height: 18px; fill: currentColor; }
.view-menu {
  position: fixed; bottom: calc(max(var(--sab), 14px) + var(--stack-lift) + var(--dock-h) + 8px); left: 16px;
  display: flex; flex-direction: column-reverse; gap: 8px;
}
.view-menu[inert] .view-btn { transform: translateY(8px) scale(0.9); opacity: 0; pointer-events: none; }
.view-btn {
  display: flex; align-items: center; gap: 8px; height: 42px; padding: 0 16px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px;
  color: var(--muted); font-weight: 600; font-size: 13.5px; box-shadow: var(--shadow);
  transition: transform 0.18s var(--ease-out), opacity 0.18s, background 0.15s, color 0.15s;
}
.view-btn .icon { width: 19px; height: 19px; }
.view-btn.active { background: linear-gradient(135deg, var(--accent-strong), #2f8fc0); color: #04283f; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-top: 14px;
}

/* progress chart card */
.chart-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.pill { background: rgba(79,184,224,0.15); color: var(--accent-text); border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 700; }
.stacked-bar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: rgba(143,176,197,0.15); }
.stacked-bar > div { transition: width 0.4s var(--ease-out); }
.bar-done { background: var(--success); }
.bar-open { background: var(--accent-strong); }
.bar-skipped { background: var(--danger); }
.chart-labels { display: flex; gap: 14px; margin-top: 10px; flex-wrap: wrap; }
.legend { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.legend b { color: var(--text); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.done { background: var(--success); }
.dot.open { background: var(--accent-strong); }
.dot.skipped { background: var(--danger); }
.dot.intake { background: var(--success); }
.dot.high { background: var(--danger); }
.dot.medium { background: var(--accent-strong); }
.dot.low { background: var(--success); }

/* search + filters */
.search {
  display: flex; align-items: center; gap: 9px; margin-top: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 13px; padding: 0 12px;
}
.search .icon { color: var(--muted); width: 19px; height: 19px; }
.search input { flex: 1; background: none; border: 0; outline: none; padding: 11px 0; }
.search-clear { border: 0; background: none; color: var(--muted); display: flex; padding: 4px; }

.filters { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0 4px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filter {
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 600; white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.filter.active { background: var(--accent); color: #04283f; border-color: transparent; }

/* ==========================================================================
   main / task list
   ========================================================================== */

.main { max-width: 1100px; margin: 0 auto; width: 100%; padding: 0 16px; }
.task-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }

.task {
  --task-color: var(--accent-strong);
  display: flex; gap: 12px; align-items: flex-start;
  background: linear-gradient(90deg, color-mix(in srgb, var(--task-color) 9%, transparent), transparent 55%), var(--surface);
  border: 1px solid color-mix(in srgb, var(--task-color) 26%, var(--line));
  border-radius: var(--radius); padding: 13px 14px;
}
/* Only genuinely new cards pop in. A re-render keeps existing cards in place,
   so live sync, polls and toggles update instantly without flashing every card. */
.task.is-new { animation: pop 0.3s var(--ease-out) both; }
.task.done { opacity: 0.72; }
/* A completed task is not struck out - the tick, the person and the moment
   carry the meaning, and the title simply turns italic. */
.task.done .task-title { font-style: italic; }
.task-completed {
  display: flex; align-items: center; gap: 5px; margin-top: 7px;
  font-size: 11px; font-style: italic; color: var(--success);
  overflow-wrap: anywhere;
}
.task-completed .icon { width: 14px; height: 14px; flex-shrink: 0; }
.task.skipped { border-color: rgba(248,113,113,0.4); }

.task-check {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; margin-top: 2px;
  border: 2px solid var(--task-color); background: transparent; color: #04283f;
  display: flex; align-items: center; justify-content: center; padding: 0;
  transition: background 0.15s, transform 0.12s var(--ease-out);
}
.task-check .icon { width: 15px; height: 15px; opacity: 0; }
.task-check:hover { transform: scale(1.1); }
.task.done .task-check { background: var(--task-color); }
.task.done .task-check .icon { opacity: 1; }

.task-main { flex: 1; min-width: 0; }
.task-title { font-weight: 650; font-size: 15px; overflow-wrap: anywhere; }
.task-notes { font-size: 13px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600;
  border-radius: 999px; padding: 3px 9px; background: var(--input-bg); color: var(--accent-text);
}
.chip .icon { width: 13px; height: 13px; }
.chip.overdue { background: rgba(248,113,113,0.15); color: var(--danger); }
.chip.soon { background: rgba(251,191,36,0.15); color: var(--warning); }
.chip.office { background: rgba(79,184,224,0.15); color: var(--office); }
.chip.personal { background: rgba(198,168,255,0.15); color: var(--personal); }
.chip.series { background: rgba(143,176,197,0.15); color: var(--muted); }
.chip.assignees { background: rgba(74,222,128,0.12); color: var(--success); }
/* urgency badges: high = red, medium = blue, low = green */
.chip.prio-high { background: rgba(248,113,113,0.16); color: var(--danger); }
.chip.prio-medium { background: rgba(79,184,224,0.16); color: var(--accent-strong); }
.chip.prio-low { background: rgba(74,222,128,0.16); color: var(--success); }
.chip.prio-high .icon, .chip.prio-medium .icon, .chip.prio-low .icon { fill: currentColor; }

.subtasks { margin-top: 9px; display: flex; flex-direction: column; gap: 5px; }
.subtask { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 8px; font-size: 13px; color: var(--muted); }
.subtask input { width: 15px; height: 15px; accent-color: var(--accent-strong); margin-top: 1px; flex-shrink: 0; }
/* Completed subtasks turn italic rather than struck through. */
.subtask.done > span:first-of-type { font-style: italic; opacity: 0.75; }
.subtask > span:first-of-type { flex: 1; min-width: 0; }
/* on shared tasks: which person ticked this part off, and when. It sits on its
   own line under the subtask name (margin = checkbox 15px + gap 8px), so the
   name never wraps to make room for the long "completed by" line. */
.sub-who {
  flex: 1 0 100%; margin-left: 23px;
  font-size: 10px; color: var(--muted); font-style: italic;
  opacity: 0.9; overflow-wrap: anywhere;
}
.sub-progress { height: 4px; border-radius: 999px; background: rgba(143,176,197,0.18); margin-top: 8px; overflow: hidden; }
.sub-progress > div { height: 100%; background: var(--task-color); border-radius: 999px; transition: width 0.3s; }

.task-actions { display: flex; flex-direction: column; gap: 2px; }

.empty { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty .icon, .empty-icon { width: 56px; height: 56px; margin: 0 auto 14px; color: rgba(143,176,197,0.4); }
.empty p { margin: 4px 0; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--tabbar-h) + 92px - 46px + 14px);
  bottom: calc(max(var(--sab), 14px) + var(--stack-lift) + 14px);
  right: 16px;
  width: 56px; height: 56px; border-radius: 18px; border: 0; z-index: 40;
  background: linear-gradient(135deg, var(--accent-strong), #2f8fc0); color: #04283f;
  display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow);
  transition: transform 0.15s var(--ease-out);
}
.fab:hover { transform: scale(1.06); }
.fab:active { transform: scale(0.94); }
.fab .icon { width: 26px; height: 26px; }

/* ==========================================================================
   calendar
   ========================================================================== */

.calendar .cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.cal-head strong { flex: 1; text-align: center; font-size: 16px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); padding: 4px 0; text-transform: uppercase; }
.cal-cell {
  aspect-ratio: 1; border: 1px solid transparent; border-radius: 10px; background: rgba(173,223,241,0.04);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 13px; color: var(--text); padding: 2px; animation: calCell 0.25s var(--ease-out) both;
}
.cal-cell:hover { background: rgba(173,223,241,0.1); }
.cal-cell.other { opacity: 0.3; }
.cal-cell.today { border-color: var(--accent-strong); font-weight: 700; }
.cal-cell.selected { background: rgba(79,184,224,0.22); border-color: var(--accent-strong); }
.cal-dots { display: flex; gap: 2px; height: 5px; }
.cal-dots i { width: 5px; height: 5px; border-radius: 50%; }
.cal-key { display: flex; gap: 14px; margin-top: 12px; }

.day-header { margin-top: 16px; }
.day-header strong { font-size: 17px; }
.day-header .muted { font-size: 13px; }

/* ==========================================================================
   protein
   ========================================================================== */

.protein-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.protein-head strong { font-size: 16px; }
.protein-range { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chart-wrap { margin-top: 8px; background: var(--chart-bg); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.chart-wrap svg { width: 100%; height: 200px; display: block; }
.protein-legend { display: flex; gap: 14px; margin-top: 8px; }
.line-sample { width: 16px; height: 2px; background: var(--warning); display: inline-block; }
.protein-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.protein-form { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 14px; }
.protein-entries { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.protein-entry {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: rgba(173,223,241,0.05); border: 1px solid var(--line); border-radius: 11px;
}
.protein-entry .pe-main { flex: 1; min-width: 0; }
.protein-entry .pe-food { font-weight: 600; font-size: 14px; }
.protein-entry .pe-meta { font-size: 12px; color: var(--muted); }
.protein-entry .pe-grams { font-weight: 700; color: var(--accent-text); white-space: nowrap; }

/* ==========================================================================
   users / leaderboard
   ========================================================================== */

.users-head, .leaderboard-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.users-head strong, .leaderboard-head strong { font-size: 16px; }
.leaderboard-head .muted { font-size: 12px; text-align: right; }
.users-head-actions { display: flex; align-items: center; gap: 8px; }

.user-item { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.user-item:last-child { border-bottom: 0; }
.user-avatar {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
  background: linear-gradient(135deg, var(--accent-strong), var(--primary-2));
  display: flex; align-items: center; justify-content: center; font-weight: 700; color: #04283f; font-size: 16px;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-info { flex: 1; min-width: 0; }
.user-info .u-name { font-weight: 650; font-size: 14.5px; display: flex; align-items: center; gap: 8px; }
.user-info .u-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-tag { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding: 2px 8px; border-radius: 999px; background: rgba(173,223,241,0.12); color: var(--accent-text); }
.role-tag.admin { background: rgba(248,113,113,0.15); color: var(--danger); }
.role-tag.supervisor { background: rgba(251,191,36,0.15); color: var(--warning); }
.role-tag.held { background: rgba(143,176,197,0.2); color: var(--muted); }
.user-actions { display: flex; gap: 2px; }

.leaderboard-list { display: flex; flex-direction: column; gap: 6px; }
.leaderboard-item { display: flex; align-items: center; gap: 14px; padding: 10px 6px; border-bottom: 1px solid var(--line); }
.leaderboard-item:last-child { border-bottom: 0; }
.leader-circle { position: relative; width: 64px; height: 64px; flex-shrink: 0; }
.leader-circle svg.ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(143,176,197,0.2); stroke-width: 4; }
.ring-fg { fill: none; stroke: var(--accent-strong); stroke-width: 4; stroke-linecap: round; transition: stroke-dashoffset 0.6s var(--ease-out); }
.leader-avatar {
  position: absolute; inset: 7px; border-radius: 50%; overflow: hidden;
  background: linear-gradient(135deg, var(--accent-strong), var(--primary-2));
  display: flex; align-items: center; justify-content: center; font-weight: 700; color: #04283f; font-size: 19px;
}
.leader-avatar img { width: 100%; height: 100%; object-fit: cover; }
.leader-rank {
  position: absolute; left: -2px; bottom: -2px; min-width: 22px; height: 22px; padding: 0 5px;
  border-radius: 999px; background: var(--primary-2); border: 2px solid var(--bg);
  color: var(--accent); font-size: 11.5px; font-weight: 800; display: flex; align-items: center; justify-content: center;
}
.leaderboard-item.first .leader-rank { background: var(--warning); color: #3a2c00; }
.leader-card.first .leader-rank { background: var(--warning); color: #3a2c00; }
.leader-info { flex: 1; min-width: 0; }
.leader-info .l-name { font-weight: 650; font-size: 14.5px; }
.leader-info .l-sub { font-size: 12.5px; color: var(--muted); }
.leader-pct { font-weight: 800; font-size: 16px; color: var(--accent-strong); }
.leader-info .l-skipped { color: var(--danger); }
.leader-info .l-ontime { color: var(--success); }

/* expandable leaderboard cards */
.leader-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: rgba(173, 223, 241, 0.03);
  transition: border-color 0.2s var(--ease-out), background 0.2s var(--ease-out);
}
.leader-card.open { border-color: rgba(79, 184, 224, 0.45); background: rgba(173, 223, 241, 0.06); }
.leader-card .leaderboard-item { border-bottom: 0; cursor: pointer; padding: 10px 12px; }
.leader-card .leaderboard-item:hover { background: rgba(173, 223, 241, 0.05); }
.leader-card .leaderboard-item:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: -2px; }
.leader-right { display: flex; align-items: center; gap: 6px; }
.leader-chevron { color: var(--muted); transition: transform 0.25s var(--ease-out); }
.leader-card.open .leader-chevron { transform: rotate(180deg); }

.leader-details { max-height: 0; overflow: hidden; transition: max-height 0.3s var(--ease-out); }
.leader-card.open .leader-details { max-height: 420px; }
.leader-details-inner {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
  gap: 8px; padding: 4px 12px 14px;
}
.leader-metric {
  background: rgba(173, 223, 241, 0.06); border: 1px solid var(--line);
  border-radius: 11px; padding: 8px 10px; text-align: center;
}
.leader-metric .lm-value { font-size: 18px; font-weight: 800; line-height: 1.15; }
.leader-metric .lm-label { font-size: 11px; color: var(--muted); margin-top: 2px; }
.leader-metric.good .lm-value { color: var(--success); }
.leader-metric.warn .lm-value { color: var(--warning); }
.leader-metric.bad .lm-value { color: var(--danger); }
.leader-score { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); padding-top: 2px; }
.leader-score strong { color: var(--accent-strong); font-size: 14px; }
.leader-legend { grid-column: 1 / -1; font-size: 11px; color: var(--muted); opacity: 0.85; }

/* transfer tasks (admin) */
.transfer-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 8px; }
.transfer-bulk { display: flex; gap: 6px; }
.transfer-tasks {
  display: flex; flex-direction: column; gap: 4px; max-height: 46vh; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 12px; padding: 6px;
}
.transfer-item { display: flex; align-items: center; gap: 10px; padding: 8px 9px; border-radius: 9px; cursor: pointer; }
.transfer-item:hover { background: rgba(173,223,241,0.06); }
.transfer-item input { width: 17px; height: 17px; accent-color: var(--accent-strong); flex-shrink: 0; }
.transfer-info { min-width: 0; }
.transfer-info .t-title { font-weight: 600; font-size: 13.5px; overflow-wrap: anywhere; }
.transfer-info .t-sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; }

/* ==========================================================================
   overlays / sheets
   ========================================================================== */

.overlay {
  position: fixed; inset: 0; z-index: 100; background: var(--scrim);
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: var(--kb-inset);
  animation: fadeIn 0.18s ease both;
}
.overlay[hidden] { display: none; }

.sheet {
  width: 100%; max-width: 560px; max-height: calc(100dvh - var(--kb-inset) - env(safe-area-inset-top) - 10px);
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface-2); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 22px 22px 0 0; padding: 10px 20px calc(20px + var(--sab));
  box-shadow: var(--shadow); animation: sheetIn 0.28s var(--ease-out) both;
}
.sheet.wide { max-width: 640px; }
.sheet-grip { width: 40px; height: 4px; border-radius: 999px; background: rgba(143,176,197,0.35); margin: 4px auto 14px; }
.sheet h2 { font-size: 19px; margin-bottom: 14px; }
.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.sheet-head h2 { margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.sheet-mark { width: 36px; height: 36px; border-radius: 11px; background: rgba(79,184,224,0.15); color: var(--accent-text); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sheet-msg { color: var(--muted); font-size: 14px; margin: -6px 0 14px; }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; }
.sheet-actions .btn { width: 100%; justify-content: flex-start; padding: 13px 16px; }
.sheet-actions .btn .icon { width: 19px; height: 19px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; position: sticky; bottom: 0; padding: 10px 0 0; background: linear-gradient(transparent, var(--surface-2) 30%); }

.color-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.color-head > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.color-row { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid transparent; padding: 0;
  display: flex; align-items: center; justify-content: center; color: #04283f;
  transition: transform 0.12s var(--ease-out), border-color 0.15s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.selected { border-color: #fff; box-shadow: 0 0 0 2px var(--accent-strong); }
.swatch.default { background: rgba(143,176,197,0.15); color: var(--muted); font-size: 9.5px; font-weight: 700; }
.swatch .icon { width: 15px; height: 15px; }
/* Any-colour swatch: a rainbow disc that opens the native picker. */
.swatch.custom {
  position: relative; overflow: hidden; cursor: pointer;
  background: conic-gradient(from 0deg, #f87171, #fbbf24, #4ade80, #4fb8e0, #c6a8ff, #f472b6, #f87171);
}
.swatch.custom input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; border: 0; padding: 0; cursor: pointer;
}

.subtask-editor { margin-top: 4px; }
.subtask-editor-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.subtask-editor-label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.subtask-editor-label .opt { font-weight: 400; opacity: 0.7; font-style: normal; }
.subtask-field { display: flex; gap: 8px; margin-bottom: 8px; }
.subtask-field input {
  flex: 1; background: var(--input-bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px; outline: none;
}
.subtask-field button { border: 0; background: none; color: var(--muted); display: flex; padding: 4px; }

.assign-list { display: flex; flex-direction: column; gap: 4px; max-height: 180px; overflow-y: auto; border: 1px solid var(--line); border-radius: 11px; padding: 8px; }
.assign-item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; font-size: 14px; }
.assign-item:hover { background: rgba(173,223,241,0.06); }
.assign-item input { width: 17px; height: 17px; accent-color: var(--accent-strong); }
.assign-item .mini-avatar { width: 26px; height: 26px; border-radius: 50%; background: linear-gradient(135deg, var(--accent-strong), var(--primary-2)); color: #04283f; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0; }
.assign-item .mini-avatar img { width: 100%; height: 100%; object-fit: cover; }

.avatar-pick { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.avatar-preview {
  width: 64px; height: 64px; border-radius: 50%; overflow: hidden; flex-shrink: 0;
  background: rgba(173,223,241,0.1); border: 1px dashed var(--line);
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.avatar-preview .icon { width: 30px; height: 30px; }

.notif-list { display: flex; flex-direction: column; gap: 6px; max-height: 55vh; overflow-y: auto; }
.notif-item {
  display: flex; gap: 10px; padding: 11px 12px; border-radius: 11px; border: 1px solid var(--line);
  background: rgba(173,223,241,0.04); text-align: left; width: 100%; color: var(--text);
}
.notif-item.unread { background: rgba(79,184,224,0.12); border-color: rgba(79,184,224,0.35); }
.notif-item .n-body { flex: 1; min-width: 0; }
.notif-item .n-title { font-weight: 650; font-size: 13.5px; }
.notif-item .n-msg { font-size: 12.5px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.notif-item .n-time { font-size: 11px; color: var(--muted); margin-top: 4px; }
.notif-item .n-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-strong); margin-top: 6px; flex-shrink: 0; }
.notif-read {
  align-self: center; flex-shrink: 0; display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--line); background: var(--input-bg); color: var(--accent-text);
  border-radius: 999px; padding: 6px 10px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.notif-read:hover { background: var(--appbar-frost); }
.notif-read .icon { width: 14px; height: 14px; }

/* settings */
.setting-row { display: flex; align-items: center; gap: 14px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.theme-seg {
  display: inline-flex; flex-shrink: 0; background: var(--input-bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px;
}
.theme-opt {
  border: 0; background: transparent; color: var(--muted);
  border-radius: 9px; padding: 7px 13px; font-size: 12.5px; font-weight: 600;
  transition: background 0.15s, color 0.15s;
}
.theme-opt:hover { color: var(--text); }
.theme-opt[aria-checked="true"] {
  background: var(--accent-strong); color: #04283f;
}
.setting-row:last-of-type { border-bottom: 0; }
.setting-text { flex: 1; min-width: 0; }
.setting-text strong { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.setting-text .icon { width: 18px; height: 18px; color: var(--accent-text); }
.setting-text p { font-size: 12.5px; margin-top: 3px; }
.setting-text .log { font-size: 11px; opacity: 0.75; }
.goal-input { width: 90px; background: var(--input-bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; outline: none; text-align: right; }
.tz { font-size: 12px; margin: 8px 0 0; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(max(var(--sab), 14px) + var(--stack-lift) + 14px); transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 11px 18px; font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow); z-index: 200; animation: toastIn 0.25s var(--ease-out) both;
  max-width: calc(100vw - 32px); text-align: center;
}
.toast[hidden] { display: none; }
.toast.error { border-color: rgba(248,113,113,0.5); color: var(--danger); }

/* ==========================================================================
   animations
   ========================================================================== */

@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetIn { from { transform: translateY(100%); } to { transform: none; } }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 14px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes calCell { from { opacity: 0; transform: scale(0.86); } to { opacity: 1; transform: none; } }
.main, .banner { animation: pop 0.4s var(--ease-out) both; }

/* ==========================================================================
   desktop ≥900px — sidebar layout
   ========================================================================== */

@media (min-width: 900px) {
  :root { --tabbar-h: 0px; }
  .app {
    display: grid; grid-template-columns: 300px 1fr; grid-template-rows: auto auto 1fr;
    gap: 0 26px; max-width: 1160px; margin: 0 auto; padding-bottom: 40px;
  }
  .appbar { grid-column: 1 / -1; }
  .banner { grid-column: 1 / -1; width: auto; margin-left: 0; margin-right: 0; }
  .rail { position: sticky; top: 74px; align-self: start; padding: 0; margin: 0; }
  .main { padding: 0; margin: 0; }
  .view-trigger { display: none; }
  .view-menu { position: static; flex-direction: column; gap: 4px; margin-bottom: 14px; }
  .view-menu[inert] .view-btn { transform: none; opacity: 1; pointer-events: auto; }
  .view-btn { border-radius: 12px; box-shadow: none; height: 44px; width: 100%; justify-content: flex-start; }
  .fab { position: fixed; right: 32px; bottom: 32px; }
  .toast { bottom: 32px; }
  .overlay { align-items: center; padding: 24px; }
  .sheet { border-radius: 22px; border-bottom: 1px solid var(--line); padding-bottom: 24px; }
  .sheet-grip { display: none; }
  .chart-card { margin-top: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* There is no hover on a touchscreen, so the frost/backdrop-filter block below
   is skipped there entirely. */

/* ==========================================================================
   frosted glass — boxes blur the scrolling content behind them. Browsers
   without backdrop-filter keep the solid surfaces defined above.
   ========================================================================== */

:root {
  --frost-blur: 16px;
  --frost-card: rgba(255, 255, 255, 0.6);
  --frost-panel: rgba(244, 247, 251, 0.7);
}
[data-theme="dark"] {
  --frost-card: rgba(13, 32, 52, 0.55);
  --frost-panel: rgba(20, 44, 68, 0.62);
}

@media (hover: hover) and (pointer: fine) {
  @supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    /* content boxes: task cards, section cards, filter chips */
    .card,
    .task,
    .filter:not(.active) {
      background-color: var(--frost-card);
      -webkit-backdrop-filter: blur(var(--frost-blur)) saturate(140%);
      backdrop-filter: blur(var(--frost-blur)) saturate(140%);
    }

    /* tinted banner keeps its gradient, gains the blur */
    .banner {
      -webkit-backdrop-filter: blur(var(--frost-blur)) saturate(140%);
      backdrop-filter: blur(var(--frost-blur)) saturate(140%);
    }

    /* sticky header frosts whatever scrolls beneath it */
    .appbar {
      background-color: var(--appbar-frost);
      -webkit-backdrop-filter: blur(var(--frost-blur)) saturate(140%);
      backdrop-filter: blur(var(--frost-blur)) saturate(140%);
    }

    /* modal panels frost the dimmed scrim and the page behind it */
    .sheet {
      background-color: var(--frost-panel);
      -webkit-backdrop-filter: blur(calc(var(--frost-blur) * 1.4)) saturate(150%);
      backdrop-filter: blur(calc(var(--frost-blur) * 1.4)) saturate(150%);
    }

    /* floating dock pills frost the list scrolling under them */
    .view-trigger,
    .view-btn:not(.active) {
      background-color: var(--frost-panel);
      -webkit-backdrop-filter: blur(var(--frost-blur)) saturate(150%);
      backdrop-filter: blur(var(--frost-blur)) saturate(150%);
    }
  }
}
