/* ==========================================================================
   Focus Board — calm, low-clutter UI. Tokens first, then layout, then parts.
   ========================================================================== */

:root {
  color-scheme: light;
  --bg: #f6f5fb;
  --surface: #ffffff;
  --surface-2: #efeef7;
  --text: #1c1b22;
  --text-muted: #62616f;
  --border: #e3e1ec;
  --accent: #6d5dfc;
  --accent-soft: #ebe8ff;
  --accent-ink: #ffffff;
  --danger: #d23c44;
  --danger-soft: #fde8e9;
  --warn: #a86400;
  --warn-soft: #fff1d6;
  --success: #17875c;
  --prio-low: #1baf7a;
  --prio-medium: #eda100;
  --prio-high: #e34948;
  --series-1: #2a78d6;
  --cat-blue: #2a78d6;
  --cat-orange: #eb6834;
  --cat-aqua: #1baf7a;
  --cat-yellow: #eda100;
  --cat-magenta: #e87ba4;
  --cat-green: #008300;
  --cat-violet: #4a3aa7;
  --cat-red: #e34948;
  --shadow: 0 1px 2px rgb(20 18 40 / 6%), 0 4px 14px rgb(20 18 40 / 6%);
  --shadow-lift: 0 10px 30px rgb(20 18 40 / 18%);
  --radius: 14px;
  --radius-sm: 10px;
  --topbar-h: 60px;
  --bottomnav-h: 64px;
}

/* theme.js always sets data-theme (stored choice, else the OS preference). */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121118;
  --surface: #1c1b24;
  --surface-2: #17161e;
  --text: #f1f0f7;
  --text-muted: #a3a2b3;
  --border: #2e2d3a;
  --accent: #8b7dff;
  --accent-soft: #2a2748;
  --accent-ink: #110f24;
  --danger: #f06b72;
  --danger-soft: #3a1c20;
  --warn: #f0b44c;
  --warn-soft: #3a2c12;
  --success: #4fcf98;
  --prio-low: #199e70;
  --prio-medium: #c98500;
  --prio-high: #e66767;
  --series-1: #3987e5;
  --cat-blue: #3987e5;
  --cat-orange: #d95926;
  --cat-aqua: #199e70;
  --cat-yellow: #c98500;
  --cat-magenta: #d55181;
  --cat-green: #008300;
  --cat-violet: #9085e9;
  --cat-red: #e66767;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 14px rgb(0 0 0 / 25%);
  --shadow-lift: 0 10px 30px rgb(0 0 0 / 50%);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1rem; font-weight: 600; }
a { color: var(--accent); }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

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

.container { max-width: 1440px; margin: 0 auto; padding: 24px 24px 48px; }
.spacer { flex: 1; }
.subtitle { margin: 4px 0 0; color: var(--text-muted); }

/* --- Top bar & navigation --------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  height: var(--topbar-h); padding: 0 24px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand, .auth-brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none;
}
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px;
  background: radial-gradient(circle at 50% 50%, var(--surface) 0 26%, transparent 27%),
              linear-gradient(135deg, var(--accent), #b36bff);
}

.nav { display: flex; gap: 4px; }
.nav a {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px;
  color: var(--text-muted); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 20px; height: 20px; }

.user-menu { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.user-menu form { margin: 0; }
.username { font-weight: 500; }
.role-badge {
  padding: 2px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
}

/* --- Buttons & form controls ------------------------------------------ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 18px; border: 1px solid transparent; border-radius: 999px;
  background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 0.875rem; }
.btn-block { width: 100%; }

.icon-btn {
  width: 38px; height: 38px; border: 0; border-radius: 50%;
  background: transparent; color: var(--text-muted); font-size: 1.5rem; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.theme-toggle { display: grid; place-items: center; flex: none; }

/* Language switch: shows both options, the active one filled; one click swaps. */
.language-toggle { margin: 0; flex: none; }
.lang-switch {
  display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2); cursor: pointer; font: inherit;
}
.lang-option {
  min-width: 30px; padding: 3px 7px; border-radius: 999px;
  color: var(--text-muted); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em;
}
.lang-option.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.lang-switch:hover .lang-option:not(.is-active) { color: var(--text); }
.theme-toggle svg { width: 20px; height: 20px; }
.theme-toggle .icon-sun, [data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
textarea, select {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit;
  /* 16px prevents iOS/Android zoom on focus */
  font-size: 16px;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
.field-title, .field-notes, .field-categories, .field-full, .auth-form .field { grid-column: 1 / -1; }

/* Category picker (task form): toggle chips. The checkbox stays focusable but invisible. */
.field-categories > div { display: flex; flex-wrap: wrap; gap: 8px; }
.field-categories > div > div { display: contents; }
.chip-toggle {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 4px 14px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text); font-size: 0.9rem; font-weight: 500; cursor: pointer;
}
.field .chip-toggle { color: var(--text); font-size: 0.9rem; font-weight: 500; }
.chip-toggle::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--cat); }
.chip-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.chip-toggle:has(input:checked) { border-color: var(--cat); background: color-mix(in srgb, var(--cat) 16%, var(--surface)); }
.chip-toggle:has(input:checked)::after { content: "✓"; font-weight: 700; }
.chip-toggle:has(input:focus-visible), .swatch:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Colour picker (category form): round swatches. */
.field-color > div, .swatches > div { display: flex; flex-wrap: wrap; gap: 10px; }
.field-color > div > div, .swatches > div > div { display: contents; }
.swatch {
  position: relative; display: grid; place-items: center; width: 34px; height: 34px;
  border-radius: 50%; background: var(--cat); cursor: pointer;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px transparent;
}
.swatch input { position: absolute; opacity: 0; pointer-events: none; }
.swatch:has(input:checked) { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
.swatch:has(input:checked)::after { content: "✓"; color: #fff; font-weight: 700; }
.field .help { color: var(--text-muted); font-size: 0.8rem; }
.field .help ul { margin: 4px 0 0; padding-left: 18px; }
.field .error { color: var(--danger); font-size: 0.85rem; }
.form-errors {
  margin-bottom: 14px; padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--danger-soft); color: var(--danger);
}
.form-errors ul { margin: 0; padding-left: 18px; }
.form-actions { display: flex; align-items: center; gap: 10px; margin-top: 20px; }

/* --- Page chrome ------------------------------------------------------- */

.page-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 20px;
}
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.filter-select select { min-height: 42px; width: auto; min-width: 150px; max-width: 240px; border-radius: 999px; padding: 8px 14px; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.panel.narrow { max-width: 640px; margin: 0 auto; }
.panel h1 { margin-bottom: 16px; }
.panel h2 { margin-bottom: 14px; }
.panel h2 small { font-weight: 400; color: var(--text-muted); }

.segmented {
  display: inline-flex; padding: 4px; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
}
.segmented a {
  padding: 6px 14px; border-radius: 999px;
  color: var(--text-muted); text-decoration: none; font-weight: 500; font-size: 0.9rem; white-space: nowrap;
}
.segmented a[aria-current="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.active-filter { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: -6px 0 14px; color: var(--text-muted); }

/* --- Kanban board ------------------------------------------------------ */

.board {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; align-items: start;
}

.column {
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--border);
  min-height: 60vh;
}
.column-head { display: flex; align-items: center; gap: 10px; padding: 2px 4px; }
.column-head::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--text-muted);
}
.column-in_progress .column-head::before { background: var(--accent); }
.column-done .column-head::before { background: var(--success); }

.count {
  min-width: 26px; padding: 1px 8px; border-radius: 999px; text-align: center;
  background: var(--surface); color: var(--text-muted); font-size: 0.8rem; font-weight: 600;
}

.wip-warning {
  margin: 0; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--warn-soft); color: var(--warn); font-size: 0.875rem; font-weight: 500;
}

.quick-add input { background: var(--surface); border-style: dashed; }

.card-list { display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 120px; padding-bottom: 8px; }
.card-list:not(:has(.card))::before {
  content: attr(data-empty);
  display: grid; place-items: center; min-height: 110px; padding: 16px;
  border: 2px dashed var(--border); border-radius: var(--radius-sm);
  color: var(--text-muted); text-align: center; font-size: 0.9rem;
}

.card {
  --prio: var(--prio-medium);
  position: relative; display: flex; align-items: flex-start; gap: 8px;
  padding: 14px 12px 14px 16px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  cursor: grab; user-select: none; -webkit-user-select: none; touch-action: manipulation;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.card::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 4px;
  border-radius: 0 4px 4px 0; background: var(--prio);
}
.card:hover { box-shadow: var(--shadow-lift); }
.card-body { flex: 1; min-width: 0; }
.card-title { font-size: 0.975rem; font-weight: 600; overflow-wrap: anywhere; }
.card-notes { margin: 4px 0 0; color: var(--text-muted); font-size: 0.875rem; overflow-wrap: anywhere; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.card[data-status="done"] .card-title { color: var(--text-muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.card.is-overdue { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }

.prio-1 { --prio: var(--prio-low); }
.prio-2 { --prio: var(--prio-medium); }
.prio-3 { --prio: var(--prio-high); }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-muted);
  font-size: 0.78rem; font-weight: 500; white-space: nowrap;
}
.cat-blue { --cat: var(--cat-blue); }
.cat-orange { --cat: var(--cat-orange); }
.cat-aqua { --cat: var(--cat-aqua); }
.cat-yellow { --cat: var(--cat-yellow); }
.cat-magenta { --cat: var(--cat-magenta); }
.cat-green { --cat: var(--cat-green); }
.cat-violet { --cat: var(--cat-violet); }
.cat-red { --cat: var(--cat-red); }

/* Category chip: a tinted pill with a solid dot; text stays in text colours. */
.chip-cat { background: color-mix(in srgb, var(--cat) 14%, var(--surface)); color: var(--text); }
.chip-cat::before, .cat-dot {
  content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--cat);
}
.chip-prio::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--prio); }
.chip-due.is-warn { background: var(--warn-soft); color: var(--warn); }
.chip-due.is-danger { background: var(--danger-soft); color: var(--danger); }
.chip-time { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }

.advance {
  flex: none; display: grid; place-items: center;
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); cursor: pointer;
}
.advance svg { width: 20px; height: 20px; stroke-width: 2.5; }
.advance:hover { background: var(--accent); color: var(--accent-ink); }
.card[data-status="in_progress"] .advance { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.card[data-status="in_progress"] .advance:hover { background: var(--success); color: #fff; }

.card-ghost { opacity: 0.35; }
.card-chosen { box-shadow: var(--shadow-lift); }
.card-drag { transform: rotate(2deg); }

.celebrate { animation: celebrate 0.9s ease; }
@keyframes celebrate {
  0% { transform: scale(1); }
  30% { transform: scale(1.04); box-shadow: 0 0 0 6px color-mix(in srgb, var(--success) 35%, transparent); }
  100% { transform: scale(1); }
}

.inline-icon {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 700;
}

.column-tabs { display: none; }

/* --- Dialog ------------------------------------------------------------ */

.dialog {
  width: min(560px, calc(100vw - 32px)); padding: 0;
  border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lift);
}
.dialog::backdrop { background: rgb(10 8 25 / 45%); backdrop-filter: blur(2px); }
.dialog form#task-form { padding: 20px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.dialog-head h2 { font-size: 1.2rem; }
.dialog-actions { display: flex; align-items: center; gap: 10px; margin-top: 20px; }

/* --- Toasts ------------------------------------------------------------ */

.toasts {
  position: fixed; right: 20px; bottom: 20px; z-index: 50;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  max-width: 360px; padding: 12px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow-lift);
  font-weight: 500; animation: toast-in 0.25s ease; transition: opacity 0.4s ease, transform 0.4s ease;
}
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
.toast.leaving { opacity: 0; transform: translateY(8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* --- Auth pages -------------------------------------------------------- */

.auth-page .container { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 16px; }
.auth-card {
  width: 100%; max-width: 420px; padding: 32px 28px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow-lift);
}
.auth-head { display: flex; align-items: center; justify-content: space-between; }
.auth-tools { display: flex; align-items: center; gap: 6px; }
.auth-brand { font-size: 1.5rem; }
.auth-tagline { margin: 6px 0 24px; color: var(--text-muted); }
.auth-form .btn-block { margin-top: 20px; }
.auth-switch { margin: 18px 0 0; text-align: center; color: var(--text-muted); }

/* --- Calendar (FullCalendar theming) ----------------------------------- */

.calendar-panel { padding: 16px; }
#calendar {
  --fc-border-color: var(--border);
  --fc-page-bg-color: var(--surface);
  --fc-neutral-bg-color: var(--surface-2);
  --fc-list-event-hover-bg-color: var(--surface-2);
  --fc-today-bg-color: var(--accent-soft);
  --fc-button-bg-color: var(--surface-2);
  --fc-button-border-color: var(--border);
  --fc-button-text-color: var(--text);
  --fc-button-hover-bg-color: var(--border);
  --fc-button-hover-border-color: var(--border);
  --fc-button-active-bg-color: var(--accent);
  --fc-button-active-border-color: var(--accent);
}
#calendar .fc-toolbar-title { font-size: 1.2rem; font-weight: 700; }
#calendar .fc-button { border-radius: 999px; font-weight: 600; text-transform: none; box-shadow: none; }
#calendar .fc-button-active { color: var(--accent-ink); }
#calendar .fc-col-header-cell-cushion, #calendar .fc-daygrid-day-number { color: var(--text-muted); text-decoration: none; }
#calendar .fc-daygrid-event {
  padding: 2px 6px; border-radius: 6px; border: 0; background: var(--prio); color: #fff; font-weight: 500;
}
#calendar .fc-daygrid-event .fc-event-title { overflow: hidden; text-overflow: ellipsis; }
#calendar .fc-daygrid-dot-event .fc-daygrid-event-dot { display: none; }
#calendar .fc-list-event-dot { border-color: var(--prio); }
#calendar .fc-list-event a { color: var(--text); text-decoration: none; }
#calendar .status-done { opacity: 0.5; }
#calendar .status-done .fc-event-title, #calendar .status-done .fc-list-event-title { text-decoration: line-through; }
#calendar .fc-daygrid-event.overdue { box-shadow: 0 0 0 2px var(--danger); }
#calendar .fc-list-event.overdue .fc-list-event-title a { color: var(--danger); font-weight: 600; }
#calendar .fc-list-event-time { display: none; }

.legend { display: flex; flex-wrap: wrap; gap: 16px; margin: 0 0 14px; padding: 0; list-style: none; color: var(--text-muted); font-size: 0.875rem; }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend li::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--prio); }
.legend .legend-done::before { background: var(--text-muted); opacity: 0.5; }

/* --- Categories -------------------------------------------------------- */

.category-create { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; margin-bottom: 18px; }
.category-create-name { display: flex; flex-direction: column; gap: 6px; flex: 1 1 220px; }
.category-create-name label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
.swatches { margin: 0; padding: 0 0 5px; border: 0; }

.category-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; align-items: start; }
.category-panel { border-top: 4px solid var(--cat); }
.category-panel.is-uncategorized { --cat: var(--text-muted); }
.category-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.category-head h2 { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-size: 1.1rem; overflow-wrap: anywhere; }
.category-head .cat-dot { width: 12px; height: 12px; }
.icon-link { display: grid; place-items: center; }
.icon-link svg { width: 18px; height: 18px; }

.category-progress { display: flex; gap: 2px; height: 8px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.segment-todo { background: var(--text-muted); opacity: 0.45; }
.segment-in_progress { background: var(--accent); }
.segment-done { background: var(--success); }
.category-stats { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 8px 0 4px; color: var(--text-muted); font-size: 0.85rem; }
.category-stats strong { color: var(--text); font-variant-numeric: tabular-nums; }

.status-heading {
  display: flex; align-items: center; gap: 8px; margin: 14px 0 6px;
  color: var(--text-muted); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
}
.status-heading::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.status-heading.status-in_progress::before { background: var(--accent); }
.status-heading.status-done::before { background: var(--success); }

.task-rows { margin: 0; padding: 0; list-style: none; }
.task-row {
  display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 10px;
  border-left: 3px solid var(--prio); border-radius: 0 8px 8px 0; background: var(--surface-2);
}
.task-row + .task-row { margin-top: 4px; }
.task-row > a, .task-row > span:first-child { flex: 1; min-width: 0; color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.task-row > a:hover { text-decoration: underline; }
.task-row.is-done > a, .task-row.is-done > span:first-child { color: var(--text-muted); text-decoration: line-through; }
.category-empty { margin: 12px 0 0; color: var(--text-muted); font-size: 0.9rem; }

/* --- Reports ----------------------------------------------------------- */

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  display: flex; flex-direction: column; gap: 4px; padding: 16px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.stat-label { color: var(--text-muted); font-size: 0.85rem; font-weight: 500; }
.stat-value { font-size: 1.8rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-value.is-danger { color: var(--danger); }

.charts { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 18px; margin-bottom: 18px; }
.chart-box { position: relative; height: max(240px, calc(var(--rows, 6) * 34px)); }
.chart-box-fixed { height: 280px; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.925rem; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table td:first-child { white-space: normal; min-width: 160px; }
.table th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr:hover { background: var(--surface-2); }

.empty-state { text-align: center; padding: 48px 20px; }
.empty-state p { margin: 0; }

/* --- Responsive -------------------------------------------------------- */

@media (max-width: 1100px) {
  .charts { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  /* Board becomes swipeable columns with tabs on tablets & phones. */
  .column-tabs {
    display: flex; gap: 6px; margin: 0 0 12px; padding: 4px;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  }
  .column-tabs button {
    flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 40px; border: 0; border-radius: 999px; background: transparent;
    color: var(--text-muted); font: inherit; font-weight: 600; font-size: 0.82rem; white-space: nowrap; cursor: pointer;
  }
  .column-tabs button[aria-current] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
  .column-tabs .count { background: var(--surface-2); }

  .board {
    display: flex; gap: 12px; overflow-x: auto;
    scroll-snap-type: x mandatory; scrollbar-width: none;
    margin: 0 -16px; padding: 0 16px 8px; scroll-padding: 0 16px;
  }
  .board::-webkit-scrollbar { display: none; }
  .column { flex: 0 0 88%; scroll-snap-align: start; min-height: 55vh; }
}

@media (max-width: 720px) {
  .container { padding: 16px 16px calc(var(--bottomnav-h) + 24px + env(safe-area-inset-bottom)); }
  .auth-page .container { padding-bottom: 16px; }

  /* No backdrop-filter here: it would trap the fixed bottom nav inside the top bar. */
  .topbar { gap: 12px; padding: 0 16px; backdrop-filter: none; background: var(--surface); }
  .username { display: none; }

  /* Navigation moves to a thumb-friendly bottom bar. */
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    justify-content: space-around; gap: 0;
    height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
    padding: 6px 8px env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .nav a { flex: 1; flex-direction: column; justify-content: center; gap: 2px; padding: 6px; border-radius: 12px; font-size: 0.72rem; }
  .nav a[aria-current="page"] { background: transparent; }
  .nav svg { width: 22px; height: 22px; }

  h1 { font-size: 1.35rem; }
  .page-head { align-items: stretch; flex-direction: column; margin-bottom: 14px; }
  .page-actions { width: 100%; }
  .page-actions .btn-primary { flex: 1; }
  .filter-select { flex: 1 1 200px; }  /* wraps rather than truncating long labels */
  .filter-select select { width: 100%; max-width: none; min-width: 0; }
  .segmented { width: 100%; overflow-x: auto; }
  .segmented a { flex: 1; text-align: center; padding: 6px 8px; }

  .fields { grid-template-columns: minmax(0, 1fr); }
  .category-grid { grid-template-columns: minmax(0, 1fr); }
  .category-create .btn { flex: 1; }
  .dialog { width: 100vw; max-width: 100vw; max-height: 92dvh; margin: auto 0 0; border-radius: 20px 20px 0 0; }
  .dialog form#task-form { padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }

  .toasts { left: 16px; right: 16px; bottom: calc(var(--bottomnav-h) + 12px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }

  .stat-value { font-size: 1.45rem; }
  .table th, .table td { padding: 8px 6px; white-space: normal; }
  .table td:first-child { min-width: 0; }
  #calendar .fc-header-toolbar { flex-wrap: wrap; gap: 8px; }
  #calendar .fc-toolbar-title { font-size: 1.05rem; }
  .calendar-panel { padding: 10px; }
}

@media (max-width: 420px) {
  .topbar .brand-name { display: none; }
  .topbar .role-badge { display: none; }  /* keeps the bar on one line */
  .user-menu { gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
