/* ===========================================================================
   TaskTracker design system  —  Apple-flavoured.
   Tokens live here; every other stylesheet and every template <style> block
   consumes them via var(). No raw hex outside this file (that's what makes
   dark mode flow everywhere).
   =========================================================================== */

:root {
  color-scheme: light;

  /* ── Surfaces & text ──────────────────────────────────────────────────── */
  --bg: #f5f5f7;
  --bg-secondary: #fafafa;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --stage-bg: #e8e8ed;

  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #86868b;

  --separator: rgba(0, 0, 0, 0.10);
  --separator-opaque: #d2d2d7;

  --fill-secondary: rgba(120, 120, 128, 0.12);
  --fill-tertiary: rgba(120, 120, 128, 0.08);

  /* ── Accent (single brand colour) ─────────────────────────────────────── */
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-pressed: #006edb;
  --accent-contrast: #ffffff;
  --accent-tint: rgba(0, 113, 227, 0.10);

  /* ── Semantic (tinted-pill) ───────────────────────────────────────────── */
  --success-fg: #1d7a3a;
  --success-bg: rgba(52, 199, 89, 0.14);
  --warning-fg: #9a5b00;
  --warning-bg: rgba(255, 149, 0, 0.16);
  --danger-fg: #c4291e;
  --danger-bg: rgba(255, 59, 48, 0.14);

  /* ── Effects ──────────────────────────────────────────────────────────── */
  --focus-ring: 0 0 0 4px rgba(0, 113, 227, 0.35);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.14);

  /* ── Radii ────────────────────────────────────────────────────────────── */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-pill: 980px;

  /* ── Type scale ───────────────────────────────────────────────────────── */
  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 15px;
  --text-md: 17px;
  --text-lg: 21px;
  --text-xl: 24px;
  --text-2xl: 28px;
  --text-3xl: clamp(26px, 3.4vw, 34px);

  /* ── Spacing (4px base) ───────────────────────────────────────────────── */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* ── Motion ───────────────────────────────────────────────────────────── */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast: 0.15s;
  --dur: 0.25s;

  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Segoe UI", system-ui, Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", ui-monospace, "Consolas", "Monaco", monospace;

  /* ── Legacy aliases (consumed by not-yet-migrated rules; do not remove) ── */
  --panel: var(--surface);
  --panel-strong: var(--surface);
  --line: var(--separator-opaque);
  --muted: var(--text-secondary);
  --accent-strong: var(--accent-pressed);
  --accent-soft: var(--accent-tint);
  --blue-soft: var(--accent-tint);
  --shadow: var(--shadow-md);
}

/* Dark palette — applied automatically when the OS prefers dark, OR when the
   user picks "Dark" on the theme toggle (which sets <html data-theme="dark">).
   An explicit "Light" choice (<html data-theme="light">) opts out of the
   automatic dark switch; "System" simply removes the attribute. The dark
   declarations are intentionally duplicated below: once for the explicit
   "dark" choice, once inside the media query for "follow system". */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { color-scheme: dark; }
}
:root[data-theme="dark"] { color-scheme: dark; }

:root[data-theme="dark"] {
  /* Surface ladder lightens with depth: page < panel < nested card. */
  --bg: #000000;
  --surface: #1c1c1e;
  --bg-secondary: #2c2c2e;
  --surface-raised: #3a3a3c;
  --stage-bg: #000000;

  --text: #f5f5f7;
  --text-secondary: #a1a1a6;
  --text-tertiary: #8e8e93;

  --separator: rgba(255, 255, 255, 0.12);
  --separator-opaque: #38383a;

  --fill-secondary: rgba(120, 120, 128, 0.24);
  --fill-tertiary: rgba(120, 120, 128, 0.16);

  --accent: #0a84ff;
  --accent-hover: #3393ff;
  --accent-pressed: #0a7aef;
  --accent-contrast: #ffffff;
  --accent-tint: rgba(10, 132, 255, 0.18);

  --success-fg: #30d158;
  --success-bg: rgba(48, 209, 88, 0.18);
  --warning-fg: #ffb340;
  --warning-bg: rgba(255, 159, 10, 0.20);
  --danger-fg: #ff453a;
  --danger-bg: rgba(255, 69, 58, 0.18);

  --focus-ring: 0 0 0 4px rgba(10, 132, 255, 0.45);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.65);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* Surface ladder lightens with depth: page < panel < nested card. */
    --bg: #000000;
    --surface: #1c1c1e;
    --bg-secondary: #2c2c2e;
    --surface-raised: #3a3a3c;
    --stage-bg: #000000;

    --text: #f5f5f7;
    --text-secondary: #a1a1a6;
    --text-tertiary: #8e8e93;

    --separator: rgba(255, 255, 255, 0.12);
    --separator-opaque: #38383a;

    --fill-secondary: rgba(120, 120, 128, 0.24);
    --fill-tertiary: rgba(120, 120, 128, 0.16);

    --accent: #0a84ff;
    --accent-hover: #3393ff;
    --accent-pressed: #0a7aef;
    --accent-contrast: #ffffff;
    --accent-tint: rgba(10, 132, 255, 0.18);

    --success-fg: #30d158;
    --success-bg: rgba(48, 209, 88, 0.18);
    --warning-fg: #ffb340;
    --warning-bg: rgba(255, 159, 10, 0.20);
    --danger-fg: #ff453a;
    --danger-bg: rgba(255, 69, 58, 0.18);

    --focus-ring: 0 0 0 4px rgba(10, 132, 255, 0.45);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.65);
  }
}

/* ===========================================================================
   Base elements
   =========================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4 {
  margin: 0 0 var(--space-2);
  font-weight: 600;
  line-height: 1.18;
  letter-spacing: -0.02em;
  color: var(--text);
}
h1 { font-size: var(--text-2xl); letter-spacing: -0.022em; }
h2 { font-size: var(--text-xl); letter-spacing: -0.022em; }
h3 { font-size: var(--text-md); }
h4 { font-size: var(--text-base); }
p { margin: 0 0 var(--space-3); }
a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }
code, kbd, samp { font-family: var(--font-mono); font-size: 0.92em; }
hr {
  border: 0;
  border-top: 1px solid var(--separator);
  margin: var(--space-5) 0;
}
::selection { background: var(--accent-tint); }

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-xs);
}

/* ── Form controls ────────────────────────────────────────────────────────── */
label {
  display: block;
  margin-bottom: var(--space-1);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
}
input[type="text"],
input[type="password"],
input[type="email"],
input[type="search"],
input[type="url"],
input[type="number"],
textarea,
select {
  width: 100%;
  font: inherit;
  font-size: var(--text-base);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  appearance: none;
}
select {
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2386868b' d='M6 8 0 1.5 1.4 0 6 5 10.6 0 12 1.5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
}
input[type="file"] {
  width: 100%;
  font: inherit;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  padding: 0.4rem 0;
}
input::placeholder,
textarea::placeholder { color: var(--text-tertiary); }
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
input[type="checkbox"],
input[type="radio"] { accent-color: var(--accent); }
form p { margin: 0 0 var(--space-4); }

/* ===========================================================================
   Layout shells
   =========================================================================== */
.shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-8);
}
.shell-wide {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-8);
}
.shell-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}

/* ===========================================================================
   Top navigation bar
   =========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0.6rem clamp(var(--space-4), 4vw, var(--space-8));
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--separator);
}
.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--text-base);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.topbar-brand:hover { text-decoration: none; }
.topbar-brand img { width: 20px; height: 20px; display: block; border-radius: 4px; }
.topbar-nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-wrap: wrap;
  flex: 1;
}
.topbar-spacer { flex: 1; }
.topbar-user {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}
.topbar-user-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

/* ── Legacy header (still rendered by partials/logout_form.html) ───────────── */
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  justify-content: space-between;
  width: 100%;
}
.header-nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.logout-form { margin: 0; }
.logout-user-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.logout-btn-separator {
  display: none;
}
.logout-btn-copy { white-space: nowrap; }
.header-actions .logout-btn { margin-left: auto; gap: 0.45rem; white-space: nowrap; }
@media (max-width: 860px) {
  .shell-header { align-items: stretch; }
  .header-actions { justify-content: flex-start; }
  .header-nav { width: 100%; }
  .header-actions .logout-btn { margin-left: 0; }
}

/* ===========================================================================
   Buttons   (.btn* is canonical; legacy aliases map onto it)
   =========================================================================== */
.btn,
.submit-btn,
.open-link,
.nav-link,
.tool-btn,
.logout-btn,
.delete-btn,
.toolbar-submit,
button.btn {
  --btn-bg: var(--fill-secondary);
  --btn-fg: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  padding: 0.5rem 0.95rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--btn-bg);
  color: var(--btn-fg);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}
.btn:hover,
.submit-btn:hover,
.open-link:hover,
.nav-link:hover,
.tool-btn:hover,
.logout-btn:hover,
.delete-btn:hover,
.toolbar-submit:hover {
  background: color-mix(in srgb, var(--btn-bg) 70%, var(--text) 8%);
  text-decoration: none;
}
.btn:active,
.submit-btn:active,
.open-link:active,
.nav-link:active,
.tool-btn:active,
.toolbar-submit:active { transform: translateY(0.5px); }
.btn:disabled,
.btn[aria-disabled="true"],
.submit-btn:disabled,
.tool-btn:disabled,
.nav-link:disabled,
.delete-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* Primary — filled accent */
.btn-primary,
.submit-btn,
.tool-btn.primary-btn,
.primary-btn {
  --btn-bg: var(--accent);
  --btn-fg: var(--accent-contrast);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover,
.submit-btn:hover,
.tool-btn.primary-btn:hover,
.primary-btn:hover {
  background: var(--accent-hover);
  color: var(--accent-contrast);
}
.btn-primary:active,
.submit-btn:active,
.tool-btn.primary-btn:active,
.primary-btn:active { background: var(--accent-pressed); }

/* Secondary — tinted (the default look of .btn / legacy .nav-link / .open-link / .tool-btn) */
.btn-secondary { --btn-bg: var(--fill-secondary); --btn-fg: var(--text); }

/* Plain — text-only accent */
.btn-plain {
  --btn-bg: transparent;
  --btn-fg: var(--accent);
  padding-left: 0.45rem;
  padding-right: 0.45rem;
}
.btn-plain:hover { background: var(--accent-tint); color: var(--accent); }

/* Destructive */
.btn-destructive,
.delete-btn {
  --btn-bg: var(--danger-bg);
  --btn-fg: var(--danger-fg);
}
.btn-destructive:hover,
.delete-btn:hover { background: color-mix(in srgb, var(--danger-bg) 65%, var(--danger-fg) 12%); color: var(--danger-fg); }

/* Big standalone call-to-action */
.btn-pill { border-radius: var(--radius-pill); padding: 0.7rem 1.4rem; font-size: var(--text-base); }
.submit-btn { width: 100%; }

/* Active / current nav item */
.nav-link-current,
.nav-link-current:hover,
.topbar-nav .is-current {
  background: var(--accent-tint);
  color: var(--accent);
  cursor: default;
  transform: none;
}

/* Muted, non-interactive pseudo-button (disabled prev/next etc.) */
.muted-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.95rem;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.2;
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.back-link {
  color: var(--accent);
  font-size: var(--text-base);
  font-weight: 600;
  text-decoration: none;
}
.back-link:hover { text-decoration: underline; }

/* ===========================================================================
   Search field  (iOS style)
   =========================================================================== */
.search-field {
  position: relative;
  display: flex;
  align-items: center;
}
.search-field::before {
  content: "";
  position: absolute;
  left: 0.6rem;
  width: 15px;
  height: 15px;
  pointer-events: none;
  background: var(--text-tertiary);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M11.74 10.34a6 6 0 1 0-1.4 1.4l3.2 3.2 1.4-1.4zM2.5 6.5a4 4 0 1 1 8 0 4 4 0 0 1-8 0z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M11.74 10.34a6 6 0 1 0-1.4 1.4l3.2 3.2 1.4-1.4zM2.5 6.5a4 4 0 1 1 8 0 4 4 0 0 1-8 0z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.search-field input[type="text"],
.search-field input[type="search"] {
  flex: 1;
  min-width: 0;
  background: var(--fill-secondary);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding-left: 2rem;
  font-size: var(--text-base);
}
.search-field input:focus-visible {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

/* ===========================================================================
   Cards / panels
   =========================================================================== */
.panel,
.card {
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: var(--space-5); }

.eyebrow {
  margin: 0;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-secondary);
}
.panel-header,
.section-header { display: grid; gap: 0.4rem; }
.panel-title {
  margin: 0;
  font-size: var(--text-3xl);
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -0.022em;
  color: var(--text);
}
.section-title {
  margin: 0;
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.18;
  letter-spacing: -0.022em;
  color: var(--text);
}
.card-title {
  margin: 0;
  font-size: var(--text-md);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--text);
}
.header-description {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-base);
  line-height: 1.45;
}

/* ===========================================================================
   Grouped list  ("inset grouped table")
   =========================================================================== */
.list {
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.list-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--separator);
  background: transparent;
  transition: background var(--dur-fast) var(--ease);
}
.list-row:first-child { border-top: 0; }
.list-row:hover { background: var(--fill-tertiary); }

/* ===========================================================================
   Badges  (tinted pills)
   =========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.5rem;
  border-radius: var(--radius-xs);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  background: var(--fill-secondary);
  color: var(--text-secondary);
}
.badge-neutral { background: var(--fill-secondary); color: var(--text-secondary); }
.badge-success { background: var(--success-bg); color: var(--success-fg); }
.badge-warning { background: var(--warning-bg); color: var(--warning-fg); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger-fg); }
.badge-accent  { background: var(--accent-tint); color: var(--accent); }

.doc-reference {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 0.12rem 0.4rem;
  border-radius: var(--radius-xs);
  background: var(--fill-secondary);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.01em;
  font-family: var(--font-mono);
}
/* A task-code reference that links to its task (partials/task_ref.html). */
a.doc-reference {
  text-decoration: none;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease);
}
a.doc-reference:hover {
  background: var(--accent-tint);
  color: var(--accent);
  text-decoration: none;
}
a.doc-reference:focus-visible { box-shadow: var(--focus-ring); }

/* ===========================================================================
   Segmented control
   =========================================================================== */
.segmented {
  display: inline-flex;
  align-items: stretch;
  padding: 2px;
  gap: 2px;
  background: var(--fill-secondary);
  border-radius: var(--radius-sm);
}
.segmented label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  margin: 0;
  padding: 0.32rem 0.7rem;
  border-radius: calc(var(--radius-sm) - 2px);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.segmented label > input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.segmented label:hover { background: var(--fill-tertiary); }
.segmented label:has(input:checked) {
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}
.segmented label:has(input:focus-visible) { box-shadow: var(--shadow-sm), var(--focus-ring); }
.segmented.is-block { display: flex; width: 100%; }
.segmented.is-vertical {
  flex-direction: column;
  align-items: stretch;
  width: 100%;
}
.segmented.is-vertical label {
  justify-content: flex-start;
  text-align: left;
  flex: none;
  padding: 0.4rem 0.6rem;
}

/* ===========================================================================
   Toggle switch  (Apple style)
   =========================================================================== */
.switch {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.switch > input {
  position: absolute;
  width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.switch-track {
  position: relative;
  flex: 0 0 auto;
  width: 51px;
  height: 31px;
  border-radius: var(--radius-pill);
  background: var(--fill-secondary);
  transition: background var(--dur) var(--ease);
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform var(--dur) var(--ease);
}
.switch > input:checked + .switch-track { background: var(--accent); }
.switch > input:checked + .switch-track::after { transform: translateX(20px); }
.switch > input:focus-visible + .switch-track { box-shadow: var(--focus-ring); }

/* ===========================================================================
   Flash messages
   =========================================================================== */
.message-stack { display: grid; gap: var(--space-2); }
.flash-message {
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  background: var(--fill-secondary);
  color: var(--text);
}
.flash-success { background: var(--success-bg); color: var(--success-fg); }
.flash-error { background: var(--danger-bg); color: var(--danger-fg); }
.flash-warning { background: var(--warning-bg); color: var(--warning-fg); }
.flash-info { background: var(--accent-tint); color: var(--accent); }

/* Form / field errors */
.field-errors,
.errorlist,
.login-error {
  margin: 0.35rem 0 0;
  padding: 0;
  list-style: none;
  color: var(--danger-fg);
  font-size: var(--text-sm);
}
.login-error {
  margin: 0 0 var(--space-4);
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--danger-bg);
}

/* ===========================================================================
   Empty state
   =========================================================================== */
.empty-state {
  padding: var(--space-10) var(--space-5);
  text-align: center;
  color: var(--text-secondary);
}
.empty-state-glyph {
  width: 44px;
  height: 44px;
  margin: 0 auto var(--space-3);
  color: var(--text-tertiary);
}
.empty-state h3 {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--text);
}
.empty-state p { font-size: var(--text-base); }

/* ===========================================================================
   Cards & forms  (shared structure: head / body / footer + sections)
   Used by the task form, task detail, and list toolbar so every page
   reads as one product.
   =========================================================================== */
.form-shell { max-width: 760px; }

/* A panel whose own padding is removed so head/body/foot own the spacing. */
.card-flush { padding: 0; overflow: hidden; }

.card-head {
  display: grid;
  gap: 2px;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--separator);
}
.card-head .card-title { font-size: var(--text-lg); }

.card-body {
  display: grid;
  gap: var(--space-6);
  padding: var(--space-6);
}

.card-foot {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--separator);
  background: var(--bg-secondary);
}
.card-foot .btn { min-width: 120px; }

/* Small uppercase section header (the signature of the task form look). */
.section-eyebrow {
  margin: 0 0 2px;
  padding: 0;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.form-section {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  gap: var(--space-4);
}

.field-group { display: grid; gap: var(--space-2); }
.field-group > label { margin-bottom: 0; }
.field-help {
  margin: 0;
  font-size: var(--text-sm);
  line-height: 1.4;
  color: var(--text-secondary);
}
.req { color: var(--danger-fg); font-weight: 700; }

.form-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4);
}

.form-banner { margin: var(--space-4) var(--space-6) 0; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

/* ===========================================================================
   List header + pagination  (shared: home task list & task-detail updates)
   =========================================================================== */
.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-3);
}
.list-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
}
.list-count {
  margin: 0;
  font-size: var(--text-sm);
}
.per-page-select {
  width: auto;
  min-width: 6.5rem;
  padding-top: 0.3rem;
  padding-bottom: 0.3rem;
  font-size: var(--text-sm);
}
.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3) var(--space-4);
  margin: 0;
}
.pagination-pages {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
}
.pagination-pages .nav-link {
  min-width: 2rem;
  padding: 0.4rem 0.6rem;
  justify-content: center;
}
.pagination-ellipsis {
  padding: 0 var(--space-1);
  color: var(--text-tertiary);
  user-select: none;
}
.pagination-jump {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: var(--text-sm);
}
.pagination-jump input[type="number"] {
  width: 4.5rem;
  text-align: center;
}
@media (max-width: 860px) {
  .pagination { justify-content: center; }
}

@media (max-width: 720px) {
  .form-row { grid-template-columns: 1fr; }
  .card-head,
  .card-body { padding-left: var(--space-4); padding-right: var(--space-4); }
  .card-foot {
    flex-direction: column-reverse;
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }
  .card-foot .btn { width: 100%; }
}

/* ===========================================================================
   Misc utilities
   =========================================================================== */
.muted { color: var(--text-secondary); }
.hidden { display: none !important; }
/* The HTML `hidden` attribute must win over component display rules
   (e.g. .field-group/.upload-progress use display:grid, which would
   otherwise override the UA [hidden]{display:none}). */
[hidden] { display: none !important; }

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