/* ==========================================================================
   CodeMaster Design System
   Mission Control aesthetic — layered surfaces, monospace data, electric accents
   ========================================================================== */

/* --- 1. Design Tokens --------------------------------------------------- */
:root {
  /* ── Font families ── */
  --font-body: 'Sora', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

  /* ── Fluid type scale (mobile → desktop) ── */
  --text-xs:  clamp(0.6875rem, 0.65rem  + 0.19vw, 0.75rem);
  --text-sm:  clamp(0.8125rem, 0.775rem + 0.19vw, 0.875rem);
  --text-base: clamp(0.875rem, 0.83rem  + 0.23vw, 1rem);
  --text-lg:  clamp(1rem,      0.94rem  + 0.3vw,  1.125rem);
  --text-xl:  clamp(1.125rem,  1.03rem  + 0.47vw, 1.25rem);
  --text-2xl: clamp(1.25rem,   1.1rem   + 0.75vw, 1.5rem);
  --text-3xl: clamp(1.5rem,    1.25rem  + 1.25vw, 1.875rem);

  /* ── Spacing ── */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* ── Radii ── */
  --radius-sm:   0.375rem;
  --radius:      0.5rem;
  --radius-lg:   0.75rem;
  --radius-xl:   1rem;
  --radius-full: 9999px;

  /* ── Transitions ── */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --transition-fast: 120ms var(--ease-out);
  --transition:      200ms var(--ease-out);
  --transition-slow:  350ms var(--ease-out);

  /* ── Layout ── */
  --container-max:    1200px;
  --container-narrow: 640px;
  --container-auth:   440px;
  --touch-min:        44px;
  --header-height:    3.5rem;

  /* ── Light theme (default) ── */
  --bg:               #F4F5F7;
  --bg-surface:       #FFFFFF;
  --bg-surface-raised:#EEF0F4;
  --bg-surface-inset: #E8EBF0;
  --bg-overlay:       rgba(15, 23, 42, 0.4);

  --border:           #D5D9E2;
  --border-subtle:    #E8EBF0;
  --border-focus:     var(--accent);

  --text-primary:     #1A1D26;
  --text-secondary:   #525868;
  --text-muted:       #6B7280;
  --text-inverse:     #FFFFFF;

  /* ── Accent (teal) ── */
  --accent:           #0891B2;
  --accent-hover:     #0E7490;
  --accent-subtle:    rgba(8, 145, 178, 0.08);
  --accent-text:      #065F73;

  /* ── Semantic: status ── */
  --status-running:    #10B981;
  --status-running-bg: rgba(16, 185, 129, 0.1);
  --status-pending:    #F59E0B;
  --status-pending-bg: rgba(245, 158, 11, 0.1);
  --status-paused:     #F97316;
  --status-paused-bg:  rgba(249, 115, 22, 0.1);
  --status-completed:  #3B82F6;
  --status-completed-bg: rgba(59, 130, 246, 0.1);
  --status-failed:     #EF4444;
  --status-failed-bg:  rgba(239, 68, 68, 0.1);
  --status-awaiting:   #8B5CF6;
  --status-awaiting-bg: rgba(139, 92, 246, 0.1);
  --status-stopped:    #6B7280;
  --status-stopped-bg: rgba(107, 114, 128, 0.1);
  --status-archived:   #9CA3AF;
  --status-archived-bg: rgba(156, 163, 175, 0.1);

  /* ── Semantic: feedback ── */
  --success:    #10B981;
  --success-bg: rgba(16, 185, 129, 0.1);
  --success-text: #065F46;
  --danger:     #EF4444;
  --danger-bg:  rgba(239, 68, 68, 0.08);
  --danger-text: #991B1B;
  --warning:    #F59E0B;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --warning-text: #92400E;
  --info:       #3B82F6;
  --info-bg:    rgba(59, 130, 246, 0.08);
  --info-text:  #1E40AF;

  /* ── Shadows ── */
  --shadow-xs:  0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:     0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg:  0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px rgba(0,0,0,0.04);
  --shadow-xl:  0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);

  /* ── Result accent (purple) ── */
  --result:     #8B5CF6;

  /* ── Code block ── */
  --code-bg:    #1E293B;
  --code-text:  #E2E8F0;
}

/* ── Dark theme ── */
[data-theme="dark"] {
  --bg:               #0B0F19;
  --bg-surface:       #141922;
  --bg-surface-raised:#1C2333;
  --bg-surface-inset: #111621;
  --bg-overlay:       rgba(0, 0, 0, 0.6);

  --border:           #2A3241;
  --border-subtle:    #1E2736;
  --border-focus:     var(--accent);

  --text-primary:     #E8ECF4;
  --text-secondary:   #94A3B8;
  --text-muted:       #7C8AA0;
  --text-inverse:     #0B0F19;

  --accent:           #22D3EE;
  --accent-hover:     #67E8F9;
  --accent-subtle:    rgba(34, 211, 238, 0.08);
  --accent-text:      #22D3EE;

  --success-text: #6EE7B7;
  --success-bg: rgba(16, 185, 129, 0.15);
  --danger-text:  #FCA5A5;
  --danger-bg:  rgba(239, 68, 68, 0.15);
  --warning-text: #FCD34D;
  --warning-bg: rgba(245, 158, 11, 0.15);
  --info-text:    #93C5FD;
  --info-bg:    rgba(59, 130, 246, 0.15);

  --shadow-xs:  0 1px 2px rgba(0,0,0,0.2);
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow:     0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -1px rgba(0,0,0,0.2);
  --shadow-lg:  0 10px 15px -3px rgba(0,0,0,0.4), 0 4px 6px rgba(0,0,0,0.3);
  --shadow-xl:  0 20px 25px -5px rgba(0,0,0,0.5), 0 10px 10px -5px rgba(0,0,0,0.3);

  --status-stopped:    #9CA3AF;
  --status-stopped-bg: rgba(156, 163, 175, 0.12);
  --status-archived:   #D1D5DB;
  --status-archived-bg: rgba(209, 213, 219, 0.1);

  --result:     #A78BFA;

  --code-bg:    #0D1117;
  --code-text:  #C9D1D9;
}

/* System preference when no manual override */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:               #0B0F19;
    --bg-surface:       #141922;
    --bg-surface-raised:#1C2333;
    --bg-surface-inset: #111621;
    --bg-overlay:       rgba(0, 0, 0, 0.6);

    --border:           #2A3241;
    --border-subtle:    #1E2736;
    --border-focus:     var(--accent);

    --text-primary:     #E8ECF4;
    --text-secondary:   #94A3B8;
    --text-muted:       #7C8AA0;
    --text-inverse:     #0B0F19;

    --accent:           #22D3EE;
    --accent-hover:     #67E8F9;
    --accent-subtle:    rgba(34, 211, 238, 0.08);
    --accent-text:      #22D3EE;

    --success-text: #6EE7B7;
    --success-bg: rgba(16, 185, 129, 0.15);
    --danger-text:  #FCA5A5;
    --danger-bg:  rgba(239, 68, 68, 0.15);
    --warning-text: #FCD34D;
    --warning-bg: rgba(245, 158, 11, 0.15);
    --info-text:    #93C5FD;
    --info-bg:    rgba(59, 130, 246, 0.15);

    --shadow-xs:  0 1px 2px rgba(0,0,0,0.2);
    --shadow-sm:  0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow:     0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -1px rgba(0,0,0,0.2);
    --shadow-lg:  0 10px 15px -3px rgba(0,0,0,0.4), 0 4px 6px rgba(0,0,0,0.3);
    --shadow-xl:  0 20px 25px -5px rgba(0,0,0,0.5), 0 10px 10px -5px rgba(0,0,0,0.3);

    --status-stopped:    #9CA3AF;
    --status-stopped-bg: rgba(156, 163, 175, 0.12);
    --status-archived:   #D1D5DB;
    --status-archived-bg: rgba(209, 213, 219, 0.1);

    --result:     #A78BFA;

    --code-bg:    #0D1117;
    --code-text:  #C9D1D9;
  }
}

/* --- 2. Reset ----------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  line-height: 1.3;
  color: var(--text-primary);
  font-weight: 600;
}

p { margin: 0 0 var(--space-4); }
p:last-child { margin-bottom: 0; }

a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-surface-raised);
  padding: 0.125em 0.375em;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
}

pre {
  font-family: var(--font-mono);
  margin: 0;
}

img, svg { display: block; max-width: 100%; }

ol, ul { padding-left: var(--space-6); margin: 0 0 var(--space-4); }

/* Custom scrollbar for dark mode */
[data-theme="dark"] ::-webkit-scrollbar { width: 8px; height: 8px; }
[data-theme="dark"] ::-webkit-scrollbar-track { background: var(--bg-surface); }
[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
}
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) ::-webkit-scrollbar { width: 8px; height: 8px; }
  :root:not([data-theme="light"]) ::-webkit-scrollbar-track { background: var(--bg-surface); }
  :root:not([data-theme="light"]) ::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-full);
  }
}

/* --- 3. Layout ---------------------------------------------------------- */
.app-main {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
  min-height: calc(100vh - var(--header-height) - var(--space-12));
  position: relative;
  z-index: 0; /* Stacking context below mobile menu overlay (z-index: 200+) */
}

/* --- 4. Header & Navigation --------------------------------------------- */
.app-header {
  background: color-mix(in srgb, var(--bg-surface) 85%, transparent);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.header-container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: var(--header-height);
}

.app-logo {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--accent-text);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.app-logo:hover {
  color: var(--accent);
  text-decoration: none;
}

/* Header layout: icon actions always visible, desktop nav hidden on mobile */
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.header-nav--desktop {
  display: none;
  align-items: center;
  gap: var(--space-1);
}

@media (min-width: 640px) {
  .header-nav--desktop { display: flex; }
  .mobile-menu-toggle { display: none !important; }
  .header-actions { gap: var(--space-3); }
}

.header-desktop-only { display: none; }
@media (min-width: 640px) {
  .header-desktop-only { display: contents; }
}

.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background var(--transition-fast);
}

.nav-link:hover {
  color: var(--text-primary);
  background: var(--accent-subtle);
  text-decoration: none;
}

.nav-link--active {
  color: var(--accent-text, var(--accent));
  background: var(--accent-subtle);
  font-weight: 600;
}

/* Hamburger button — mobile only */
.mobile-menu-toggle {
  background: none;
  border: 1px solid var(--border);
  padding: var(--space-2);
  cursor: pointer;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  transition: all var(--transition-fast);
}

.mobile-menu-toggle:hover {
  color: var(--text-primary);
  background: var(--accent-subtle);
  border-color: var(--accent);
}

/* Mobile overlay */
.mobile-menu-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 200;
  animation: fadeInOverlay 0.2s var(--ease-out);
}

@keyframes fadeInOverlay {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Mobile slide-out panel */
.mobile-menu {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 280px;
  max-width: calc(100vw - 3rem);
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  z-index: 201;
  display: flex;
  flex-direction: column;
  animation: slideInRight 0.25s var(--ease-out);
  overflow-y: auto;
}

@keyframes slideInRight {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

.mobile-menu__user {
  padding: var(--space-5) var(--space-5) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}

.mobile-menu__email {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  word-break: break-all;
}

.mobile-menu__links {
  flex: 1;
  padding: var(--space-2) 0;
}

.mobile-menu__link {
  display: flex;
  align-items: center;
  padding: var(--space-3) var(--space-5);
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 500;
  font-size: var(--text-base);
  transition: background var(--transition-fast);
}

.mobile-menu__link:hover {
  background: var(--accent-subtle);
  text-decoration: none;
}

.mobile-menu__link--active {
  color: var(--accent-text);
  background: var(--accent-subtle);
  font-weight: 600;
}

.mobile-menu__footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-subtle);
}

.mobile-menu__signout { width: 100%; }

/* Theme toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  padding: var(--space-2);
  cursor: pointer;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  transition: all var(--transition-fast);
}

.theme-toggle:hover {
  color: var(--text-primary);
  background: var(--accent-subtle);
  border-color: var(--accent);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

.theme-toggle__light { display: block; }
.theme-toggle__dark  { display: none; }

[data-theme="dark"] .theme-toggle__light { display: none; }
[data-theme="dark"] .theme-toggle__dark  { display: block; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle__light { display: none; }
  :root:not([data-theme="light"]) .theme-toggle__dark  { display: block; }
}

/* --- 5. Buttons --------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  border: 1.5px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition-fast);
  min-height: var(--touch-min);
  line-height: 1.2;
  white-space: nowrap;
}

.btn:hover { text-decoration: none; }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-inverse);
}

.btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn--secondary {
  background: var(--bg-surface-raised);
  border-color: var(--border);
  color: var(--text-primary);
}

.btn--secondary:hover {
  background: var(--bg-surface-inset);
  border-color: var(--text-muted);
}

.btn--outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text-secondary);
}

.btn--outline:hover {
  background: var(--accent-subtle);
  border-color: var(--accent);
  color: var(--accent-text);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

.btn--ghost:hover {
  background: var(--bg-surface-raised);
  color: var(--text-primary);
}

.btn--danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger-text);
}

.btn--danger:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--text-inverse);
}

.btn--small {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  min-height: 34px;
}

.btn--icon {
  padding: var(--space-2);
  width: var(--touch-min);
}

/* --- 6. Forms ----------------------------------------------------------- */
.form { width: 100%; }

.form-field { margin-bottom: var(--space-5); }

.form-label {
  display: block;
  margin-bottom: var(--space-2);
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text-primary);
}

.form-input {
  width: 100%;
  padding: var(--space-3);
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  min-height: var(--touch-min);
}

.form-input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.field-hint {
  display: block;
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.field-error {
  display: block;
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  color: var(--danger-text);
  font-weight: 500;
}

.form-actions {
  margin: var(--space-8) 0 var(--space-4);
}

.form-actions .btn {
  width: 100%;
}

.form-actions--aligned {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  margin-top: var(--space-8);
}

.form-actions--aligned .btn {
  width: auto;
  min-width: 120px;
}

.form-footer {
  text-align: center;
  margin-top: var(--space-4);
}

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

.form-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-5);
}

.form-section h2 {
  margin: 0 0 var(--space-1);
  font-size: var(--text-lg);
}

.form-section__description {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  margin: 0 0 var(--space-4);
}

.form-section--collapsible {
  padding: 0;
}

.form-section__toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: var(--space-4) var(--space-6);
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
  transition: background var(--transition-fast);
}

.form-section__toggle:hover {
  background: var(--bg-surface-raised);
}

.form-section__content {
  padding: 0 var(--space-6) var(--space-6);
}

.form-section--submit {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.form-section--submit .form-actions {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-subtle);
}

/* Checkbox */
.checkbox-label {
  display: flex;
  align-items: flex-start;
  cursor: pointer;
  padding: var(--space-3) var(--space-4);
  margin: 0 calc(var(--space-4) * -1);
  transition: background var(--transition-fast);
  border-radius: var(--radius);
}

.checkbox-label:hover {
  background: var(--bg-surface-raised);
}

.checkbox-label:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.checkbox-input {
  margin-right: var(--space-3);
  margin-top: var(--space-1);
  accent-color: var(--accent);
  cursor: pointer;
}

.checkbox-text { flex: 1; }

.checkbox-text strong {
  display: block;
  color: var(--text-primary);
  font-weight: 600;
  margin-bottom: var(--space-1);
}

.checkbox-description {
  display: block;
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: 1.4;
}

/* Password strength */
.password-strength { margin-top: var(--space-2); }

.password-strength__bar {
  width: 100%;
  height: 4px;
  background: var(--bg-surface-raised);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.password-strength__fill {
  height: 100%;
  width: 0;
  transition: all 0.3s ease;
  border-radius: var(--radius-full);
}

.password-strength__fill.weak   { width: 25%;  background: var(--danger); }
.password-strength__fill.fair   { width: 50%;  background: var(--status-paused); }
.password-strength__fill.good   { width: 75%;  background: var(--warning); }
.password-strength__fill.strong { width: 100%; background: var(--success); }

.password-strength__text {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
  display: block;
}

/* Misc form helpers */
.link { color: var(--accent-text); text-decoration: none; }
.link:hover { text-decoration: underline; }
.link--secondary { color: var(--text-muted); font-size: var(--text-sm); }

.terms-text {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin: 0;
  line-height: 1.4;
}

.inline-form { display: inline-block; margin: 0; }

.button-group {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-4);
  flex-wrap: wrap;
}

/* --- 7. Alerts & Flash -------------------------------------------------- */
body > .flash-container { margin: 0; padding: 0; }

.alert {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: 0;
  font-weight: 500;
  font-size: var(--text-sm);
}

.alert--notice {
  background: var(--info-bg);
  border-bottom: 1px solid color-mix(in srgb, var(--info) 20%, transparent);
  color: var(--info-text);
}

.alert--alert {
  background: var(--danger-bg);
  border-bottom: 1px solid color-mix(in srgb, var(--danger) 20%, transparent);
  color: var(--danger-text);
}

.alert--error {
  background: var(--danger-bg);
  border-bottom: 1px solid color-mix(in srgb, var(--danger) 20%, transparent);
  color: var(--danger-text);
}

.alert__icon {
  font-size: var(--text-lg);
  flex-shrink: 0;
}

.alert__message { flex: 1; }

.alert__message ul {
  margin: var(--space-2) 0 0;
  padding-left: var(--space-6);
}

/* --- 8. Authentication -------------------------------------------------- */
.auth-container {
  max-width: var(--container-auth);
  margin: var(--space-12) auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  overflow: hidden;
  padding: var(--space-10);
}

.auth-container h1 {
  text-align: center;
  padding: 0 0 var(--space-3);
  font-size: var(--text-2xl);
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}

.auth-description {
  margin: 0 0 var(--space-8);
  color: var(--text-secondary);
  text-align: center;
  font-size: var(--text-sm);
}

.auth-form { padding: var(--space-8); }

/* --- 9. Dashboard ------------------------------------------------------- */
.dashboard {
  max-width: 900px;
  margin: 0 auto;
}

.dashboard__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-6);
}

.dashboard__header h1 {
  margin: 0;
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}

/* Dashboard Stats Row */
.dashboard-stats {
  display: flex;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.dashboard-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-surface);
  padding: var(--space-4) var(--space-3);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
}

.dashboard-stat--running .dashboard-stat__number {
  color: var(--success);
}

.dashboard-stat--failed .dashboard-stat__number {
  color: var(--danger);
}

.dashboard-stat__number {
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.dashboard-stat__label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-top: var(--space-1);
}

/* Dashboard Sections */
.dashboard-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}

.dashboard-section__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
}

.dashboard-section__header h2 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-lg);
  margin: 0;
}

/* Running Tasks List */
.dashboard-running-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.dashboard-running-item {
  display: block;
  padding: var(--space-4);
  border: 1px solid var(--success);
  border-left: 3px solid var(--success);
  border-radius: var(--radius);
  background: var(--bg-surface-raised);
  text-decoration: none;
  color: inherit;
  transition: all var(--transition-fast);
}

.dashboard-running-item:hover {
  background: var(--accent-subtle);
  border-color: var(--accent);
  border-left-color: var(--accent);
  text-decoration: none;
}

.dashboard-running-item__main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-2);
}

.dashboard-running-item__worktree {
  font-weight: 700;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-primary);
}

.dashboard-running-item__agent {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-surface);
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
}

.dashboard-running-item__prompt {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin: 0 0 var(--space-2);
  line-height: 1.4;
}

.dashboard-running-item__meta {
  display: flex;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* Recent Tasks List */
.dashboard-recent-list {
  display: flex;
  flex-direction: column;
}

.dashboard-recent-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-2);
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid var(--border-subtle);
  transition: background var(--transition-fast);
}

.dashboard-recent-item:last-child {
  border-bottom: none;
}

.dashboard-recent-item:hover {
  background: var(--accent-subtle);
  text-decoration: none;
}

.dashboard-recent-item .status-dot {
  margin-top: 6px;
  flex-shrink: 0;
}

.dashboard-recent-item__info {
  flex: 1;
  min-width: 0;
}

.dashboard-recent-item__top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
}

.dashboard-recent-item__worktree {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.dashboard-recent-item__time {
  font-size: var(--text-xs);
  color: var(--text-muted);
  flex-shrink: 0;
}

.dashboard-recent-item__prompt {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin: 0 0 var(--space-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-recent-item__meta {
  display: flex;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.dashboard-recent-item__status {
  font-weight: 600;
}

.dashboard-recent-item--running .dashboard-recent-item__status {
  color: var(--success);
}

.dashboard-recent-item--completed .dashboard-recent-item__status {
  color: var(--text-muted);
}

.dashboard-recent-item--failed .dashboard-recent-item__status {
  color: var(--danger);
}

.dashboard-recent-item--stopped .dashboard-recent-item__status {
  color: var(--warning-text);
}

.dashboard-recent-item--archived .dashboard-recent-item__status {
  color: var(--status-archived);
}

/* Dashboard Empty State */
.dashboard-empty {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--text-muted);
}

.dashboard-empty p {
  margin-bottom: var(--space-4);
  font-size: var(--text-sm);
}

/* --- 10. Notification Permission Card ----------------------------------- */
.notification-permission-card {
  background: var(--bg-surface);
  padding: var(--space-6);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  margin-bottom: var(--space-8);
}

.notification-permission-card h2 {
  margin-top: 0;
  margin-bottom: var(--space-4);
  font-size: var(--text-lg);
}

.notification-status {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  margin-bottom: var(--space-4);
  font-size: var(--text-sm);
  text-align: center;
  font-weight: 500;
}

.notification-status--default {
  background: var(--bg-surface-raised);
  color: var(--text-secondary);
}

.notification-status--granted,
.notification-status--subscribed {
  background: var(--success-bg);
  color: var(--success-text);
}

.notification-status--denied {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.notification-status--error {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.notification-status--not-supported {
  background: var(--info-bg);
  color: var(--info-text);
}

.permission-ui {
  margin-top: var(--space-4);
}

.permission-ui[data-permission-state="granted"] {
  border-left: 3px solid var(--success);
  padding-left: var(--space-4);
}

.permission-ui[data-permission-state="denied"] {
  border-left: 3px solid var(--danger);
  padding-left: var(--space-4);
}

.browser-instructions {
  background: var(--bg-surface-raised);
  padding: var(--space-4);
  border-radius: var(--radius);
  margin: var(--space-4) 0;
}

.browser-instructions li {
  margin-bottom: var(--space-2);
  color: var(--text-secondary);
}

.revoke-help-panel {
  margin-top: var(--space-3);
}

/* --- 11. Notification Badge & Dropdown ---------------------------------- */
.notification-badge-container {
  position: relative;
}

.notification-badge-button {
  position: relative;
  background: none;
  border: none;
  padding: var(--space-2);
  cursor: pointer;
  font-size: 1.25rem;
  color: var(--text-secondary);
  transition: color var(--transition-fast);
  border-radius: var(--radius-sm);
}

.notification-badge-button:hover {
  color: var(--text-primary);
}

.notification-icon { display: block; }

.notification-badge {
  position: absolute;
  top: 0;
  right: -2px;
  background: var(--danger);
  color: #FFFFFF;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: var(--radius-full);
  min-width: 16px;
  text-align: center;
  line-height: 1.3;
}

.notification-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: var(--space-2);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  max-width: 360px;
  width: calc(100vw - var(--space-8));
  max-height: 480px;
  display: flex;
  flex-direction: column;
  z-index: 1000;
}

.notification-dropdown[hidden] { display: none !important; }

/* Overlay behind the mobile bottom-sheet notification dropdown.
   Hidden on desktop — only shown on mobile (<640px) via media query. */
.notification-dropdown__overlay {
  display: none;
}

.notification-dropdown__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.notification-dropdown__header h3 {
  margin: 0;
  font-size: var(--text-base);
}

.notification-dropdown__view-all {
  color: var(--accent-text);
  text-decoration: none;
  font-size: var(--text-sm);
}

.notification-dropdown__view-all:hover { text-decoration: underline; }

.notification-dropdown__content {
  flex: 1;
  overflow-y: auto;
  max-height: 360px;
}

.notification-dropdown__loading,
.notification-dropdown__empty {
  padding: var(--space-8);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.notification-dropdown__list { padding: 0; }

/* Drag handle — visible only on mobile bottom sheet */
.notification-dropdown__handle {
  display: none;
  justify-content: center;
  padding: var(--space-2) 0 0;
  cursor: grab;
}

.notification-dropdown__handle-bar {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: var(--radius-full);
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Notification items (dropdown) */
.notification-item {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.notification-item:hover { background: var(--bg-surface-raised); }
.notification-item:last-child { border-bottom: none; }

.notification-item--unread {
  background: var(--accent-subtle);
  position: relative;
}

.notification-item--unread:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.notification-item--unread::before {
  content: '';
  position: absolute;
  left: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
}

.notification-item--unread .notification-item__title { font-weight: 700; }

.notification-item__icon {
  flex-shrink: 0;
  font-size: 1.25rem;
  line-height: 1;
}

.notification-item__content {
  flex: 1;
  min-width: 0;
}

.notification-item__title {
  font-weight: 600;
  color: var(--text-primary);
  font-size: var(--text-sm);
  margin-bottom: var(--space-1);
}

.notification-item__body {
  color: var(--text-muted);
  font-size: var(--text-xs);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.notification-item__time {
  color: var(--text-muted);
  font-size: var(--text-xs);
  margin-top: var(--space-1);
}

.notification-error { padding: var(--space-8); text-align: center; }
.notification-error p { color: var(--danger-text); margin-bottom: var(--space-4); }

/* --- 12. Notifications Page --------------------------------------------- */
.notifications {
  max-width: 800px;
  margin: 0 auto;
}

.notifications__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-6);
}

.notifications__title {
  font-size: var(--text-2xl);
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}

.notifications__actions {
  display: flex;
  gap: var(--space-2);
}

.notifications__filters {
  background: var(--bg-surface);
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  margin-bottom: var(--space-6);
}

.filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
  align-items: end;
}

.filters__group {
  display: flex;
  flex-direction: column;
}

.filters__group--actions {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: row;
  gap: var(--space-2);
  justify-content: flex-end;
  margin-top: var(--space-2);
}

.filters__label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-2);
}

.filters__select,
.filters__input {
  padding: var(--space-2) var(--space-3);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  color: var(--text-primary);
  background: var(--bg-surface);
  transition: border-color var(--transition-fast);
}

.filters__select:focus,
.filters__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.filters__input--date { width: 100%; }

/* Notification list */
.notifications__list {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}

.notifications__day-group {
  border-bottom: 1px solid var(--border-subtle);
}

.notifications__day-group:last-child { border-bottom: none; }

.notifications__day-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  padding: var(--space-3) var(--space-5);
  margin: 0;
  background: var(--bg-surface-raised);
  border-bottom: 1px solid var(--border-subtle);
}

.notifications__day-items { padding: 0; }

/* Individual notification (full-page) */
.notification {
  display: flex;
  align-items: flex-start;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  transition: background var(--transition-fast);
  position: relative;
}

.notification:last-child { border-bottom: none; }
.notification:hover { background: var(--bg-surface-raised); }

.notification--unread {
  background: var(--accent-subtle);
}

.notification--unread:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.notification--unread::before {
  content: '';
  position: absolute;
  left: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
}

.notification__icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  margin-right: var(--space-4);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface-raised);
  border-radius: 50%;
}

.notification__icon svg {
  width: 20px;
  height: 20px;
  stroke: var(--text-muted);
}

.notification--unread .notification__icon {
  background: var(--accent-subtle);
}

.notification--unread .notification__icon svg {
  stroke: var(--accent-text);
}

.notification__content {
  flex: 1;
  min-width: 0;
}

.notification__title {
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 var(--space-1);
  font-size: var(--text-sm);
}

.notification--unread .notification__title { font-weight: 700; }

.notification__body {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: 1.5;
  margin: 0 0 var(--space-2);
}

.notification__meta {
  display: flex;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.notification__actions {
  display: flex;
  gap: var(--space-1);
  align-items: center;
  margin-left: var(--space-3);
}

.notification__action {
  background: none;
  border: none;
  padding: var(--space-2);
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  border-radius: var(--radius-sm);
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  display: flex;
  align-items: center;
  justify-content: center;
}

.notification__action:hover {
  background: var(--bg-surface-raised);
  color: var(--text-primary);
}

.notification__action svg {
  width: 16px;
  height: 16px;
  display: block;
}

.notification__action--tmux {
  color: var(--text-muted);
  background: var(--success-bg);
}

.notification__action--tmux:hover {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 15%, transparent);
}

.notification__action--mark-read:hover { color: var(--success); }
.notification__action--view:hover { color: var(--accent-text); }
.notification__action--delete:hover { color: var(--danger); }

/* Empty state */
.notifications__empty { padding: var(--space-16) var(--space-8); text-align: center; }

.empty-state { max-width: 400px; margin: 0 auto; }

.empty-state__icon {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-5);
  color: var(--text-muted);
  opacity: 0.4;
}

.empty-state__title {
  font-size: var(--text-lg);
  font-weight: 600;
  margin: 0 0 var(--space-2);
}

.empty-state__text {
  color: var(--text-muted);
  margin: 0;
  font-size: var(--text-sm);
}

/* Pagination */
.notifications__pagination {
  padding: var(--space-5);
  text-align: center;
  border-top: 1px solid var(--border-subtle);
}

.load-more-button { margin-top: var(--space-3); }

/* --- 13. Modal ---------------------------------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-slow);
}

.modal--active { opacity: 1; visibility: visible; }

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: var(--bg-overlay);
  cursor: pointer;
  backdrop-filter: blur(4px);
}

.modal__content {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalSlideIn 0.35s var(--ease-out);
}

.modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}

.modal__title {
  font-size: var(--text-lg);
}

.modal__close {
  background: none;
  border: none;
  padding: var(--space-2);
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
}

.modal__close:hover {
  color: var(--text-primary);
  background: var(--bg-surface-raised);
}

.modal__close svg { width: 20px; height: 20px; display: block; }

.modal__body {
  padding: var(--space-5);
  overflow-y: auto;
  flex: 1;
}

/* Notification detail (inside modal) */
.notification-detail__header {
  display: flex;
  gap: var(--space-4);
  align-items: flex-start;
  margin-bottom: var(--space-5);
}

.notification-detail__icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface-raised);
  border-radius: 50%;
  flex-shrink: 0;
}

.notification-detail__icon svg {
  width: 24px;
  height: 24px;
  stroke: var(--text-muted);
}

.notification-detail__title {
  font-size: var(--text-xl);
  font-weight: 600;
  margin: 0 0 var(--space-1);
}

.notification-detail__type {
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin: 0;
}

.notification-detail__body {
  margin-bottom: var(--space-6);
  color: var(--text-secondary);
  line-height: 1.6;
}

.notification-detail__metadata {
  background: var(--bg-surface-raised);
  padding: var(--space-5);
  border-radius: var(--radius);
  margin-bottom: var(--space-5);
}

.notification-detail__metadata-title {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 var(--space-4);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.notification-detail__metadata-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-2) var(--space-4);
  margin: 0;
}

.notification-detail__metadata-list dt {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.notification-detail__metadata-list dd {
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin: 0;
  word-break: break-all;
}

.notification-detail__actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}

/* --- 14. Agent Tasks ---------------------------------------------------- */

/* Task list index */
.tasks-page {
  max-width: 900px;
  margin: 0 auto;
}

.tasks-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-5);
  gap: var(--space-4);
  flex-wrap: wrap;
}

.tasks-header__title h1 {
  margin: 0 0 var(--space-2);
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}

.tasks-header__stats {
  display: flex;
  gap: var(--space-2);
}

.stat-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
}

.stat-badge--running {
  background: var(--status-running-bg);
  color: var(--status-running);
}

.stat-badge--active {
  background: var(--info-bg);
  color: var(--info-text);
}

/* ── Filter system — chip rows with collapsible scope drawer ── */
.tasks-filters {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: var(--space-4);
}

/* Each filter dimension is a row: label + horizontally scrollable chips */
.filter-row {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: var(--space-1);
  overflow: visible;
}

/* Status row: top-rounded when scope drawer follows */
.filter-row--status {
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

/* Standalone status row (no scope drawer after it) */
.tasks-filters > .filter-row--status:last-child {
  border-radius: var(--radius-lg);
}

/* Row label — fixed left column */
.filter-row__label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  padding: 0 var(--space-2);
  flex-shrink: 0;
  min-width: 4.25rem;
  user-select: none;
}

.filter-row__label svg {
  opacity: 0.5;
  flex-shrink: 0;
}

/* Scrollable chip track */
.filter-row__chips {
  display: flex;
  gap: var(--space-1);
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  flex: 1;
  min-width: 0;
  padding-right: var(--space-2);
}

.filter-row__chips::-webkit-scrollbar {
  display: none;
}

/* ── Filter chip — shared base ── */
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  text-decoration: none;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 500;
  transition: all var(--transition-fast);
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 1.625rem;
  line-height: 1;
}

.filter-chip:hover {
  background: var(--bg-surface-raised);
  color: var(--text-primary);
  text-decoration: none;
}

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

/* Active chip */
.filter-chip--active {
  background: var(--accent);
  color: var(--text-inverse);
}

.filter-chip--active:hover {
  filter: brightness(0.9);
  text-decoration: none;
}

.filter-chip--active:focus-visible {
  outline-color: var(--text-primary);
}

/* Count badge */
.filter-chip__count {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  font-weight: 700;
  min-width: 1rem;
  text-align: center;
  padding: 0 3px;
  border-radius: var(--radius-full);
  background: var(--bg-surface-raised);
  color: var(--text-muted);
  line-height: 1.5;
}

.filter-chip--active .filter-chip__count {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text-inverse);
}

/* ── Status-colored chips ── */
.filter-chip--running.filter-chip--active  { background: var(--status-running-bg);  color: var(--status-running);  box-shadow: inset 0 -2px 0 var(--status-running); }
.filter-chip--awaiting.filter-chip--active { background: var(--status-awaiting-bg); color: var(--status-awaiting); box-shadow: inset 0 -2px 0 var(--status-awaiting); }
.filter-chip--paused.filter-chip--active   { background: var(--status-paused-bg);   color: var(--status-paused);   box-shadow: inset 0 -2px 0 var(--status-paused); }
.filter-chip--pending.filter-chip--active  { background: var(--status-pending-bg);  color: var(--status-pending);  box-shadow: inset 0 -2px 0 var(--status-pending); }
.filter-chip--completed.filter-chip--active { background: var(--status-completed-bg); color: var(--status-completed); box-shadow: inset 0 -2px 0 var(--status-completed); }
.filter-chip--failed.filter-chip--active   { background: var(--status-failed-bg);   color: var(--status-failed);   box-shadow: inset 0 -2px 0 var(--status-failed); }
.filter-chip--stopped.filter-chip--active  { background: var(--status-stopped-bg);  color: var(--status-stopped);  box-shadow: inset 0 -2px 0 var(--status-stopped); }
.filter-chip--archived.filter-chip--active { background: var(--status-archived-bg); color: var(--status-archived); box-shadow: inset 0 -2px 0 var(--status-archived); }

.filter-chip--running.filter-chip--active .filter-chip__count,
.filter-chip--awaiting.filter-chip--active .filter-chip__count,
.filter-chip--paused.filter-chip--active .filter-chip__count,
.filter-chip--pending.filter-chip--active .filter-chip__count,
.filter-chip--completed.filter-chip--active .filter-chip__count,
.filter-chip--failed.filter-chip--active .filter-chip__count,
.filter-chip--stopped.filter-chip--active .filter-chip__count,
.filter-chip--archived.filter-chip--active .filter-chip__count {
  background: currentColor;
  color: var(--bg-surface);
}

.filter-chip--running:not(.filter-chip--active) .filter-chip__count  { background: var(--status-running-bg); color: var(--status-running); }
.filter-chip--awaiting:not(.filter-chip--active) .filter-chip__count { background: var(--status-awaiting-bg); color: var(--status-awaiting); }
.filter-chip--paused:not(.filter-chip--active) .filter-chip__count   { background: var(--status-paused-bg); color: var(--status-paused); }
.filter-chip--pending:not(.filter-chip--active) .filter-chip__count  { background: var(--status-pending-bg); color: var(--status-pending); }
.filter-chip--completed:not(.filter-chip--active) .filter-chip__count { background: var(--status-completed-bg); color: var(--status-completed); }
.filter-chip--failed:not(.filter-chip--active) .filter-chip__count   { background: var(--status-failed-bg); color: var(--status-failed); }
.filter-chip--stopped:not(.filter-chip--active) .filter-chip__count  { background: var(--status-stopped-bg); color: var(--status-stopped); }
.filter-chip--archived:not(.filter-chip--active) .filter-chip__count { background: var(--status-archived-bg); color: var(--status-archived); }

/* ── Scope chips (project / worktree) — monospace ── */
.filter-chip--scope {
  font-family: var(--font-mono);
}

.filter-chip--scope.filter-chip--active {
  background: var(--accent-subtle);
  color: var(--accent-text);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.filter-chip--scope.filter-chip--active .filter-chip__count {
  background: var(--accent);
  color: var(--text-inverse);
}

/* ── Mobile filter bar: hidden on desktop ── */
.filter-bar-mobile { display: none; }

/* Desktop scope chip rows share borders with status row */
.filter-row--scope-desktop {
  border-top: none;
}

.filter-row--scope-desktop:last-of-type {
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Scope rows inside drawer — dashed separator */
.filter-row--scope-desktop + .filter-row--scope-desktop {
  border-top: 1px dashed var(--border-subtle);
}

/* Summary tags container */
.filter-summary__tags {
  display: flex;
  gap: var(--space-1);
  flex-wrap: wrap;
  align-items: center;
}

/* ── Removable filter tags ── */
.filter-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px var(--space-2);
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: all var(--transition-fast);
  background: var(--bg-surface-raised);
  color: var(--text-secondary);
  line-height: 1.5;
}

.filter-tag svg { flex-shrink: 0; opacity: 0.6; }
.filter-tag__x { font-size: 0.75rem; opacity: 0.4; margin-left: 1px; }
.filter-tag:hover { background: var(--danger-bg); color: var(--danger-text); text-decoration: none; }
.filter-tag:hover .filter-tag__x { opacity: 1; }
.filter-tag:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.filter-tag--running  { background: var(--status-running-bg);  color: var(--status-running); }
.filter-tag--awaiting { background: var(--status-awaiting-bg); color: var(--status-awaiting); }
.filter-tag--paused   { background: var(--status-paused-bg);   color: var(--status-paused); }
.filter-tag--pending  { background: var(--status-pending-bg);  color: var(--status-pending); }
.filter-tag--completed { background: var(--status-completed-bg); color: var(--status-completed); }
.filter-tag--failed   { background: var(--status-failed-bg);   color: var(--status-failed); }
.filter-tag--stopped  { background: var(--status-stopped-bg);  color: var(--status-stopped); }
.filter-tag--archived { background: var(--status-archived-bg); color: var(--status-archived); }
.filter-tag--scope { background: var(--accent-subtle); color: var(--accent-text); }

/* ── Filter summary row ── */
.filter-summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  flex-wrap: wrap;
}

.filter-summary__count {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
}

.filter-summary__clear {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius);
  transition: all var(--transition-fast);
  white-space: nowrap;
  margin-left: auto;
}

.filter-summary__clear:hover {
  color: var(--danger-text);
  background: var(--danger-bg);
  text-decoration: none;
}

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

.filter-summary__clear svg {
  opacity: 0.5;
}

.filter-summary__clear:hover svg {
  opacity: 1;
}

/* Scroll overflow affordance — fade on trailing edge */
.filter-row__chips {
  mask-image: linear-gradient(to right, black calc(100% - 1.5rem), transparent);
  -webkit-mask-image: linear-gradient(to right, black calc(100% - 1.5rem), transparent);
}

/* Touch devices above mobile (tablets, touch laptops) */
@media (pointer: coarse) and (min-width: 640px) {
  .filter-chip {
    min-height: var(--touch-min);
    padding: var(--space-1) var(--space-3);
  }
}

/* ── Mobile: single-bar filter with native selects ── */
@media (max-width: 639px) {
  /* ── Tighten header on mobile ── */
  .tasks-header {
    margin-bottom: var(--space-2);
    gap: var(--space-2);
    align-items: center;
  }

  .tasks-header__title h1 {
    font-size: var(--text-lg);
    margin-bottom: 0;
  }

  .tasks-header__title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
  }

  .tasks-header__stats { gap: var(--space-1); }

  .stat-badge {
    font-size: 0.5625rem;
    padding: 1px var(--space-1);
  }

  .tasks-filters { margin-bottom: var(--space-2); }

  /* ── Hide all desktop elements on mobile ── */
  .filter-row--desktop,
  .filter-row--scope-desktop,
  .filter-summary--desktop { display: none; }

  /* ── Mobile filter bar: single compact row ── */
  .filter-bar-mobile {
    display: flex;
    align-items: stretch;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    min-height: var(--touch-min);
  }

  .filter-bar-mobile__select {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    border: none;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--text-secondary);
    padding: 6px 20px 6px var(--space-2);
    cursor: pointer;
    min-width: 0;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    background-image: url("data:image/svg+xml,%3Csvg width='8' height='8' viewBox='0 0 24 24' fill='none' stroke='%237C8AA0' stroke-width='3' xmlns='http://www.w3.org/2000/svg'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 8px;
  }

  .filter-bar-mobile__select:focus { outline: none; }

  .filter-bar-mobile__select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    border-radius: var(--radius);
  }

  /* Status select: takes remaining space */
  .filter-bar-mobile__select--status {
    flex: 1;
    min-width: 0;
  }

  /* Scope selects: fixed-width, mono */
  .filter-bar-mobile__select--scope {
    border-left: 1px solid var(--border-subtle);
    max-width: 7rem;
  }

  /* Active state: highlight selected filter */
  .filter-bar-mobile__select--active {
    color: var(--accent-text);
    font-weight: 600;
  }

  /* Clear button */
  .filter-bar-mobile__clear {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 var(--space-2);
    border-left: 1px solid var(--border-subtle);
    color: var(--text-muted);
    text-decoration: none;
    transition: all var(--transition-fast);
    flex-shrink: 0;
  }

  .filter-bar-mobile__clear:hover {
    color: var(--danger-text);
    background: var(--danger-bg);
  }

  .filter-bar-mobile__clear:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
  }

  /* Loading state */
  .filter-bar-mobile--loading {
    opacity: 0.5;
    pointer-events: none;
  }

  /* ── Task cards: tighter on mobile ── */
  .tasks-list { gap: var(--space-2); }

  .task-card {
    padding: var(--space-3);
    border-left-width: 3px;
  }

  .task-card__header { margin-bottom: var(--space-1); }
  .task-card__body { margin-bottom: var(--space-2); }
  .task-card__title { font-size: var(--text-sm); }
  .task-card__description,
  .task-card__prompt { font-size: var(--text-xs); }
  .task-card__meta { gap: var(--space-3); font-size: 0.6875rem; }
}

/* Task tags */
.task-tag {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1;
}

.task-tag--project {
  background: var(--accent-subtle);
  color: var(--accent-text);
}

.task-tag--worktree {
  background: var(--bg-surface-raised);
  color: var(--text-muted);
}

.task-tag--sm {
  padding: 2px var(--space-1);
  font-size: 0.65rem;
}

.task-card__tags {
  display: flex;
  gap: var(--space-1);
  align-items: center;
  flex-wrap: nowrap;
  min-width: 0;
}

.task-card__tags .task-tag {
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 10rem;
  vertical-align: middle;
}

/* Desktop/mobile tag visibility */
.task-card__tags--mobile { display: none; }

@media (max-width: 639px) {
  .task-card__tags--desktop { display: none; }
  .task-card__tags--mobile {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-wrap: nowrap;
    margin-bottom: var(--space-1);
  }
  .task-card__tags--mobile .task-tag {
    font-size: 0.5625rem;
    padding: 1px 5px;
    max-width: 9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.5;
  }
}

/* Task card */
.tasks-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.task-card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--border);
  transition: all var(--transition-fast);
}

.task-card:hover {
  border-color: var(--border);
  box-shadow: var(--shadow);
  text-decoration: none;
  transform: translateY(-1px);
}

.task-card--running  { border-left-color: var(--status-running); }
.task-card--pending  { border-left-color: var(--status-pending); }
.task-card--paused   { border-left-color: var(--status-paused); }
.task-card--completed { border-left-color: var(--status-completed); }
.task-card--failed   { border-left-color: var(--status-failed); }
.task-card--stopped  { border-left-color: var(--status-stopped); }
.task-card--awaiting { border-left-color: var(--status-awaiting); }
.task-card--archived { border-left-color: var(--status-archived); }

.task-card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.task-card__status {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: var(--space-2);
}

.task-card__agent {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--bg-surface-raised);
  color: var(--text-muted);
}

.task-card__body { margin-bottom: var(--space-3); }

.task-card__title {
  margin: 0 0 var(--space-1);
  font-size: var(--text-base);
  font-weight: 600;
}

.task-card__worktree {
  margin: 0 0 var(--space-1);
  font-size: var(--text-base);
  font-weight: 600;
}

.task-card__description {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: 1.5;
  white-space: pre-line;
}

.task-card__prompt {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: 1.4;
}

.task-card__footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.task-card__meta {
  display: flex;
  gap: var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.meta-item { display: inline-flex; align-items: center; }

/* Tasks empty */
.tasks-empty {
  text-align: center;
  padding: var(--space-12);
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
}

.tasks-empty p {
  color: var(--text-muted);
  margin-bottom: var(--space-4);
}

/* --- 15. Task Detail (Show) --------------------------------------------- */
.task-detail {
  max-width: 900px;
  margin: 0 auto;
}

.task-detail__header { margin-bottom: var(--space-5); }
.task-detail__nav { margin-bottom: var(--space-4); }

.task-detail__title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.task-detail__title-row h1 {
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}

.task-detail__badges {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
}

.badge--agent {
  background: var(--bg-surface-raised);
  color: var(--text-muted);
}

.badge--session {
  background: var(--success-bg);
  color: var(--success-text);
}

.badge--cli {
  background: var(--bg-surface-raised);
  color: var(--text-muted);
}

.task-detail__actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
}

.task-detail__resume-cmd {
  background: var(--code-bg);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
}

.task-detail__resume-cmd code {
  background: none;
  font-size: var(--text-xs);
  color: var(--code-text);
  padding: 0;
}

/* Task info grid */
.task-detail__info {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  border: 1px solid var(--border-subtle);
  margin-bottom: var(--space-5);
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

.info-item { padding: 0; }

.info-item--error {
  grid-column: 1 / -1;
  background: var(--danger-bg);
  padding: var(--space-3);
  border-radius: var(--radius);
}

.info-label {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-1);
}

.info-value {
  color: var(--text-primary);
  font-size: var(--text-sm);
}

.info-value code {
  font-size: var(--text-xs);
}

.info-value--prompt {
  grid-column: 1 / -1;
  line-height: 1.5;
}

.info-value--prompt p { margin: 0; }

/* Message form */
.message-form-container {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  border: 1px solid var(--border-subtle);
  margin-bottom: var(--space-5);
}

.message-form-container h3 {
  margin: 0 0 var(--space-3);
  font-size: var(--text-base);
}

.message-form__input-row {
  display: flex;
  gap: var(--space-3);
  align-items: flex-end;
  flex-direction: column;
}

.message-form__textarea {
  flex: 1;
  resize: vertical;
  min-height: var(--touch-min);
  width: 100%;
}

/* Task status banners */
.task-status-banner {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  margin-bottom: var(--space-5);
  font-size: var(--text-sm);
  line-height: 1.5;
  border: 1px solid;
}

.task-status-banner strong { display: inline; }

.task-status-banner code {
  font-size: var(--text-xs);
}

.task-status-banner--pending {
  background: var(--status-pending-bg);
  border-color: color-mix(in srgb, var(--status-pending) 30%, transparent);
  color: var(--warning-text);
}

.task-status-banner--running {
  background: var(--status-running-bg);
  border-color: color-mix(in srgb, var(--status-running) 30%, transparent);
  color: var(--success-text);
}

.task-status-banner--paused {
  background: var(--status-paused-bg);
  border-color: color-mix(in srgb, var(--status-paused) 30%, transparent);
  color: var(--warning-text);
}

.task-status-banner--completed {
  background: var(--status-completed-bg);
  border-color: color-mix(in srgb, var(--status-completed) 30%, transparent);
  color: var(--info-text);
}

.task-status-banner--failed {
  background: var(--status-failed-bg);
  border-color: color-mix(in srgb, var(--status-failed) 30%, transparent);
  color: var(--danger-text);
}

.task-status-banner--stopped {
  background: var(--status-stopped-bg);
  border-color: color-mix(in srgb, var(--status-stopped) 30%, transparent);
  color: var(--text-secondary);
}

/* Event stream */
.task-detail__stream { margin-bottom: var(--space-8); }

.task-detail__stream h2 {
  margin: 0 0 var(--space-4);
  font-size: var(--text-lg);
}

.event-count {
  font-weight: normal;
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.event-stream {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-height: 600px;
  overflow-y: auto;
  padding-right: var(--space-2);
}

.event-stream-empty {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  padding: var(--space-8);
  font-size: var(--text-sm);
}

/* Event card */
.event-card {
  background: var(--bg-surface);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--border);
}

.event-card--system {
  border-left-color: var(--text-muted);
  background: var(--bg-surface-raised);
}

.event-card--assistant {
  border-left-color: var(--accent);
}

.event-card--user {
  border-left-color: var(--success);
}

.event-card--result {
  border-left-color: var(--result);
  background: color-mix(in srgb, var(--result) 5%, var(--bg-surface));
}

.event-card--rate_limit_event {
  border-left-color: var(--status-paused);
  background: color-mix(in srgb, var(--status-paused) 5%, var(--bg-surface));
}

.event-card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-2);
}

.event-card__type {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.event-card__time {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.event-card__body {
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text-primary);
}

/* Event types */
.event-text p { margin: 0 0 var(--space-2); }
.event-text p:last-child { margin-bottom: 0; }

.event-thinking { margin-bottom: var(--space-2); }

.thinking-label {
  font-style: italic;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.event-question {
  background: var(--warning-bg);
  padding: var(--space-3);
  border-radius: var(--radius);
  margin-top: var(--space-2);
  border: 1px solid color-mix(in srgb, var(--warning) 30%, transparent);
}

.event-question strong { color: var(--warning-text); }

/* Tool use */
.event-tool-use {
  margin-top: var(--space-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  overflow: hidden;
}

.tool-use__header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-surface-raised);
  cursor: pointer;
  border: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: inherit;
  transition: background var(--transition-fast);
}

.tool-use__header:hover { background: var(--bg-surface-inset); }

.tool-use__name {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--text-xs);
  color: var(--accent-text);
}

.tool-use__preview {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  background: none;
  padding: 0;
}

.tool-use__detail { border-top: 1px solid var(--border-subtle); }

.tool-use__input {
  margin: 0;
  padding: var(--space-3);
  background: var(--code-bg);
  color: var(--code-text);
  font-size: var(--text-xs);
  line-height: 1.5;
  overflow-x: auto;
  max-height: 300px;
}

/* Result event */
.event-result {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.result-item {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--result);
}

/* Rate limit event */
.event-rate-limit { margin-top: var(--space-1); }

.rate-limit-bar {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--status-paused);
  padding: var(--space-1) var(--space-3);
  background: linear-gradient(
    to right,
    color-mix(in srgb, var(--status-paused) 15%, transparent) var(--utilization),
    var(--bg-surface-raised) var(--utilization)
  );
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

/* --- 15b. Chat Interface — Full-Viewport Mobile-First Chat -------------- */

/*
 * The chat page takes over the entire viewport below the app header.
 * Layout: topbar (fixed) → scrollable timeline → pinned input.
 * On mobile, the app-main padding is stripped for the chat page.
 */

/* Full-viewport chat page wrapper */
.chat-page {
  position: relative;
  display: flex;
  flex-direction: column;
  /* CSS fallback — JS (setViewportHeight in agent_task_stream controller)
     overrides with the actual measured height on connect + resize.
     Use svh (smallest viewport) as the CSS fallback so the input is never
     clipped behind mobile browser chrome on initial load. */
  height: calc(100vh - var(--header-height));
  height: calc(100svh - var(--header-height));
  margin: calc(-1 * var(--space-6)) calc(-1 * var(--space-4)); /* bleed out of app-main padding */
  background: var(--bg);
  overflow: hidden;
}

/* ── Topbar ── */
.chat-topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  min-height: 3rem;
  flex-shrink: 0;
  gap: var(--space-2);
  z-index: 15;
}

.chat-topbar__left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0; /* allow truncation */
  flex: 1;
}

.chat-topbar__back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-min);
  height: var(--touch-min);
  flex-shrink: 0;
  color: var(--text-secondary);
  border-radius: var(--radius);
  transition: background var(--transition-fast), color var(--transition-fast);
}

.chat-topbar__back:hover {
  background: var(--bg-surface-raised);
  color: var(--text-primary);
}

.chat-topbar__details {
  min-width: 0;
}

.chat-topbar__details > summary {
  list-style: none;
  cursor: pointer;
}

.chat-topbar__details > summary::-webkit-details-marker {
  display: none;
}

.chat-topbar__info {
  display: flex;
  flex-direction: column;
  min-width: 0; /* truncation */
  gap: 2px;
  position: relative;
  padding-right: var(--space-4);
}

.chat-topbar__chevron {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  opacity: 0.5;
  transition: transform 0.2s, opacity 0.2s;
  flex-shrink: 0;
}

.chat-topbar__details[open] .chat-topbar__chevron {
  transform: translateY(-50%) rotate(180deg);
  opacity: 0.8;
}

.chat-topbar__drawer {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--bg-surface-raised);
  border-bottom: 1px solid var(--border-subtle);
  padding: var(--space-3) var(--space-4);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.chat-detail-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  margin: 0;
}

.chat-detail-grid dt {
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

.chat-detail-grid dd {
  margin: 0;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Allow title text to wrap so the full title is visible */
.chat-detail-grid__wrap {
  white-space: normal;
  word-break: break-word;
}

.chat-detail-mono {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  background: var(--bg-surface-inset);
  padding: 1px 4px;
  border-radius: 3px;
}

.chat-detail-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 3px;
  vertical-align: middle;
  margin-left: 2px;
  padding: 0;
  transition: color 0.15s, background 0.15s;
}
.chat-detail-copy:hover { color: var(--text-primary); background: var(--bg-surface-inset); }
.chat-detail-copy__check { display: none; }
.chat-detail-copy--done .chat-detail-copy__icon { display: none; }
.chat-detail-copy--done .chat-detail-copy__check { display: block; color: var(--status-completed); }

.chat-topbar__name {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-topbar__meta-row {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-wrap: nowrap;
  overflow: hidden;
}

.chat-topbar__sep {
  color: var(--text-muted);
  opacity: 0.4;
  font-size: var(--text-xs);
  flex-shrink: 0;
}

.chat-topbar__scope {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.chat-topbar__status {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
}

.chat-topbar__cost,
.chat-topbar__turns {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.chat-topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.chat-topbar__action-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.chat-topbar__action-btn svg { flex-shrink: 0; }

@media (max-width: 639px) {
  .chat-topbar__action-label { display: none; }
}

/* ── Status banners ── */
/* #chat_banner is a Turbo Stream target wrapper — direct child of the
   .chat-page flex container, so it also needs flex-shrink: 0. */
#chat_banner {
  flex-shrink: 0;
}

.chat-banner {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  text-align: center;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-subtle);
}

.chat-banner--pending  { background: var(--status-pending-bg);  color: var(--text-primary); }
.chat-banner--running  { background: var(--status-running-bg);  color: var(--text-primary); }
.chat-banner--awaiting { background: var(--status-awaiting-bg); color: var(--text-primary); }
.chat-banner--paused   { background: var(--status-paused-bg);   color: var(--text-primary); }
.chat-banner--failed   { background: var(--status-failed-bg);   color: var(--text-primary); }
.chat-banner--stopped  { background: var(--status-stopped-bg);  color: var(--text-primary); }
.chat-banner--archived { background: var(--status-archived-bg); color: var(--text-primary); }

.chat-banner code,
.chat-banner__code {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  background: var(--bg-surface-inset);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  display: inline-block;
  margin-top: var(--space-1);
  word-break: break-all;
}

/* ── History sentinel (infinite scroll trigger) ── */
.chat-history-sentinel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  min-height: 1px;
}

.chat-history-sentinel__spinner {
  display: none;
  animation: spin 0.8s linear infinite;
  color: var(--text-muted);
}

.chat-history-sentinel__text {
  display: none;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.chat-history-sentinel--loading .chat-history-sentinel__spinner,
.chat-history-sentinel--loading .chat-history-sentinel__text {
  display: block;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Scrollable chat timeline ── */
.chat-timeline {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: var(--space-3) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  font-family: var(--font-mono);
  /* Avoid scroll-behavior:smooth here — programmatic auto-scroll (scrollTo)
     races with rapid Turbo Stream appends, causing the timeline to fall behind.
     The JS controller handles scrolling; user scroll is already instant. */
}

/* ── Scroll-to-bottom button ── */
.chat-scroll-bottom {
  position: absolute;
  bottom: 5rem;
  right: var(--space-3);
  z-index: 10;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transform: translateY(0.5rem);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.chat-scroll-bottom--visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.chat-scroll-bottom:hover {
  color: var(--text-primary);
  border-color: var(--accent);
  background: var(--bg-raised);
}

.chat-empty {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  padding: var(--space-8);
  font-size: var(--text-sm);
}

/* ── Terminal-style message entries ── */
.chat-msg {
  width: 100%;
  padding: 0;
  position: relative;
}

/* Fade-in for dynamically appended entries (Turbo Stream / MutationObserver) */
.chat-msg--enter,
.chat-divider--enter,
.chat-turn-end--enter {
  animation: chatFadeIn 200ms var(--ease-out);
}

@keyframes chatFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Both agent and user messages left-aligned, full width */
.chat-msg--agent,
.chat-msg--user {
  align-self: flex-start;
}

/* User message — left accent border for visual distinction */
.chat-msg--user {
  border-left: 3px solid var(--accent-text);
  padding-left: var(--space-3);
}

/* Message header — role label + copy button */
.chat-msg__header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Copy button — appears on hover */
.chat-msg__copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px;
  border-radius: 3px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.chat-msg--user:hover .chat-msg__copy-btn { opacity: 1; }
.chat-msg__copy-btn:hover { color: var(--text-primary); }
.chat-msg__copy-btn .chat-detail-copy__check { display: none; }
.chat-msg__copy-btn .chat-detail-copy__icon { display: block; }
.chat-msg__copy-btn.chat-detail-copy--done .chat-detail-copy__icon { display: none; }
.chat-msg__copy-btn.chat-detail-copy--done .chat-detail-copy__check { display: block; color: var(--status-completed); }
.chat-msg__copy-btn.chat-detail-copy--done { opacity: 1; }

/* Role label — user messages only (agent is the default speaker) */
.chat-msg__role {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-1);
  color: var(--accent-text);
}
.chat-msg__role::before {
  content: '\276F ';
  opacity: 0.7;
}

/* Message content — flat, full-width, no background */
.chat-msg__content {
  font-size: var(--text-sm);
  line-height: 1.6;
  color: var(--text-primary);
  word-break: break-word;
  overflow-wrap: break-word;
}

.chat-msg__content p { margin: 0 0 var(--space-2); }
.chat-msg__content p:last-child { margin-bottom: 0; }

/* Initial prompt — subtle background only (outer border comes from .chat-msg--user) */
.chat-msg--prompt .chat-msg__content {
  padding: var(--space-2) var(--space-3);
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}

/* Attachments */
.chat-msg__attachments {
  margin: var(--space-2) 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.chat-msg__attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  background: var(--bg-surface-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  line-height: 1.3;
  max-width: 100%;
}

.chat-msg__attachment-icon {
  flex-shrink: 0;
  opacity: 0.7;
}

.chat-msg__attachment-name {
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.chat-msg__attachment-size {
  color: inherit;
  opacity: 0.6;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ── Inline images in chat ── */
.chat-inline-image {
  max-width: 100%;
  max-height: 400px;
  border-radius: var(--radius);
  border: 1px solid var(--border-subtle);
  margin: var(--space-2) 0;
  display: block;
  object-fit: contain;
  background: var(--bg-surface-inset);
  cursor: zoom-in;
}

.chat-msg__image-previews {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: var(--space-2) 0 0;
}

.chat-msg__image-link {
  display: block;
  max-width: 300px;
}

.chat-msg__image-link .chat-inline-image {
  margin: 0;
  cursor: zoom-in;
  transition: opacity var(--transition-fast);
}

.chat-msg__image-link:hover .chat-inline-image {
  opacity: 0.85;
}

.chat-tool-call__result-images {
  padding: var(--space-2);
}

.chat-tool-call__result-images .chat-inline-image {
  max-height: 300px;
}

/* ── Markdown rendering inside chat messages ── */
.chat-markdown > *:first-child { margin-top: 0; }
.chat-markdown > *:last-child  { margin-bottom: 0; }

.chat-markdown p {
  margin: 0 0 var(--space-2);
}
.chat-markdown p:last-child { margin-bottom: 0; }

.chat-markdown h1,
.chat-markdown h2,
.chat-markdown h3,
.chat-markdown h4,
.chat-markdown h5,
.chat-markdown h6 {
  font-weight: 600;
  color: var(--text-primary);
  margin: var(--space-3) 0 var(--space-1);
  line-height: 1.3;
}
.chat-markdown h1 { font-size: var(--text-lg); }
.chat-markdown h2 { font-size: var(--text-base); }
.chat-markdown h3,
.chat-markdown h4,
.chat-markdown h5,
.chat-markdown h6 { font-size: var(--text-sm); }

.chat-markdown strong { font-weight: 600; }
.chat-markdown em     { font-style: italic; }
.chat-markdown del    { text-decoration: line-through; opacity: 0.7; }
.chat-markdown mark   { background: var(--warning-bg); padding: 0 0.15em; border-radius: 2px; }

.chat-markdown a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.chat-markdown a:hover { color: var(--accent-hover); }

/* Inline code */
.chat-markdown code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-surface-inset);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
  word-break: break-word;
}

/* Fenced code blocks — override inline code styles */
.chat-markdown pre {
  margin: var(--space-2) 0;
  padding: var(--space-3);
  background: var(--code-bg);
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.chat-markdown pre code {
  display: block;
  background: none;
  padding: 0;
  border-radius: 0;
  color: var(--code-text);
  font-size: var(--text-xs);
  line-height: 1.55;
  white-space: pre;
  word-break: normal;
}

/* Lists */
.chat-markdown ul,
.chat-markdown ol {
  margin: var(--space-2) 0;
  padding-left: var(--space-5);
}

.chat-markdown li {
  margin-bottom: var(--space-1);
}

.chat-markdown li > ul,
.chat-markdown li > ol {
  margin: var(--space-1) 0 0;
}

/* Blockquote */
.chat-markdown blockquote {
  margin: var(--space-2) 0;
  padding: var(--space-1) var(--space-3);
  border-left: 3px solid var(--accent);
  color: var(--text-secondary);
  font-style: italic;
}

.chat-markdown blockquote p { margin-bottom: var(--space-1); }
.chat-markdown blockquote p:last-child { margin-bottom: 0; }

/* Horizontal rule */
.chat-markdown hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: var(--space-3) 0;
}

/* Tables */
.chat-markdown table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-2) 0;
  font-size: var(--text-xs);
}

.chat-markdown th,
.chat-markdown td {
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border-subtle);
  text-align: left;
}

.chat-markdown th {
  background: var(--bg-surface-raised);
  font-weight: 600;
  font-family: var(--font-mono);
}

/* Metadata — subtle, below message */
.chat-msg__meta {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
  opacity: 0.6;
}

.chat-msg__pending {
  color: var(--status-pending);
  font-weight: 600;
  opacity: 1;
}
.chat-msg__delivered {
  display: inline-flex;
  align-items: center;
  gap: 0.25em;
  color: var(--status-running);
  opacity: 1;
}

/* ── Typing indicator (pulsing dots) ── */
.chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: var(--space-1) 0;
}
.chat-typing__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: chat-typing-pulse 1.4s ease-in-out infinite;
}
.chat-typing__dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing__dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes chat-typing-pulse {
  0%, 60%, 100% { opacity: 0.25; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* Thinking — flat with left border */
.chat-msg__thinking {
  font-style: italic;
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
}

.chat-msg__thinking-block {
  margin-bottom: var(--space-2);
  border-left: 2px solid var(--border-subtle);
}

.chat-msg__thinking-label {
  display: block;
  padding: var(--space-1) var(--space-3);
  font-style: italic;
  font-size: var(--text-sm);
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-fast);
}

.chat-msg__thinking-label:hover {
  background: var(--bg-surface-inset);
}

.chat-msg__thinking-block[open] .chat-msg__thinking-label {
  border-bottom: 1px solid var(--border-subtle);
}

.chat-msg__thinking-content {
  padding: var(--space-2) var(--space-3);
  font-style: italic;
  font-size: var(--text-sm);
  color: var(--text-muted);
  max-height: 300px;
  overflow-y: auto;
  line-height: 1.5;
}

.chat-msg__thinking-content p {
  margin: 0 0 var(--space-2);
}

.chat-msg__thinking-content p:last-child {
  margin-bottom: 0;
}

/* Agent question highlight — flat with left border */
.chat-msg__question {
  background: var(--warning-bg);
  border: none;
  border-left: 2px solid var(--warning);
  padding: var(--space-2) var(--space-3);
  border-radius: 0;
  margin-top: var(--space-2);
  font-weight: 500;
  color: var(--warning-text);
  font-size: var(--text-sm);
}

/* ── Tool call cards — flat with left border ── */
.chat-tool-call {
  margin-top: var(--space-2);
  border: none;
  border-left: 2px solid var(--border-subtle);
  border-radius: 0;
}

.chat-tool-call__header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: none;
  cursor: pointer;
  border: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: inherit;
  transition: background var(--transition-fast);
}

.chat-tool-call__header:hover { background: var(--bg-surface-inset); }
.chat-tool-call__header:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); outline: none; }

.chat-tool-call__name {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--text-xs);
  color: var(--accent-text);
  flex-shrink: 0;
}

.chat-tool-call__preview {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  background: none;
  padding: 0;
}

.chat-tool-call__detail { border-top: 1px solid var(--border-subtle); }

.chat-tool-call__input {
  margin: 0;
  padding: var(--space-3);
  background: var(--code-bg);
  color: var(--code-text);
  font-size: var(--text-xs);
  line-height: 1.5;
  overflow-x: auto;
  max-height: 200px;
}

/* ── Chat dividers (system events, rate limits) ── */
.chat-divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  align-self: center;
  margin: var(--space-1) 0;
  max-width: 100%;
}

.chat-divider::before,
.chat-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
  min-width: 1rem;
}

.chat-divider__label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
}

.chat-divider--rate-limit .chat-divider__label {
  color: var(--status-paused);
}

.chat-divider--compact::before,
.chat-divider--compact::after {
  border-top: 1px dashed var(--border-subtle);
  background: none;
  height: 0;
}

/* ── Subagent activity group (collapsed) ── */
.chat-subagent-group {
  align-self: flex-start;
  margin: var(--space-1) 0;
  max-width: 100%;
}

.chat-subagent-group > details > summary {
  list-style: none;
  cursor: pointer;
}

.chat-subagent-group > details > summary::-webkit-details-marker { display: none; }

.chat-subagent-group__header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.chat-subagent-group__header:hover {
  background: var(--bg-surface-inset);
}

.chat-subagent-group__icon {
  color: var(--text-muted);
  flex-shrink: 0;
  opacity: 0.7;
}

.chat-subagent-group__summary {
  font-size: var(--text-xs);
  color: var(--accent-text);
  font-weight: 600;
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.chat-subagent-group__detail {
  padding: var(--space-1) var(--space-3) var(--space-1) calc(var(--space-3) + 14px + var(--space-2));
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.chat-subagent-group__step {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 2px 0;
}

.chat-subagent-group__step-desc {
  font-size: var(--text-xs);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.chat-subagent__tag--done {
  color: var(--green-text, #22c55e);
  border-color: var(--green-text, #22c55e);
}

.chat-subagent__tag--error {
  color: var(--red-text, #ef4444);
  border-color: var(--red-text, #ef4444);
}

.chat-subagent__tag--running {
  color: var(--accent-text);
  border-color: var(--accent-text);
}

/* ── Subagent activity indicators (legacy single) ── */
.chat-subagent {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  align-self: flex-start;
  margin: var(--space-1) 0;
  padding: var(--space-1) var(--space-3);
  max-width: 100%;
}

.chat-subagent__icon {
  color: var(--text-muted);
  flex-shrink: 0;
  opacity: 0.7;
}

.chat-subagent__label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--accent-text);
  font-weight: 600;
  white-space: nowrap;
}

.chat-subagent__description {
  font-size: var(--text-xs);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.chat-subagent__meta {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  opacity: 0.6;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Turn-end stats — subtle inline annotation ── */
.chat-turn-end {
  align-self: flex-start;
  padding: var(--space-1) 0;
}

.chat-turn-end__stats {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* ── Tool activity groups (collapsed consecutive tool-only events) ── */
.chat-tool-activity {
  align-self: flex-start;
  width: 100%;
  border: none;
  border-left: 2px solid var(--border-subtle);
  border-radius: 0;
  background: none;
  font-size: var(--text-sm);
  animation: chatFadeIn 200ms var(--ease-out);
}

.chat-tool-activity--enter {
  animation: chatFadeIn 200ms var(--ease-out);
}

.chat-tool-activity details > summary {
  list-style: none;
}
.chat-tool-activity details > summary::-webkit-details-marker {
  display: none;
}

.chat-tool-activity__header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  transition: background var(--transition-fast);
  border-radius: 0;
}

.chat-tool-activity__header:hover {
  background: var(--bg-surface-inset);
}

.chat-tool-activity__icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-tool-activity__summary {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  font-weight: 500;
}

.chat-tool-activity__tools {
  color: var(--text-muted);
  font-weight: 400;
}

.chat-tool-activity__meta {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
}

.chat-tool-activity__detail {
  border-top: 1px solid var(--border-subtle);
  padding: var(--space-1) 0;
  max-height: 300px;
  overflow-y: auto;
}

.chat-tool-activity__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
}

.chat-tool-activity__item:hover {
  background: var(--bg-surface-inset);
}

/* Hidden: raw streamed items absorbed by Stimulus controller */
.chat-tool-activity-item { display: none; }
.chat-tool-activity-close { display: none; }

/* ── Todo list cards (Claude's task tracking) ── */
.chat-todo-list {
  align-self: flex-start;
  width: 100%;
  max-width: 600px;
}

.chat-todo-list details > summary { list-style: none; }
.chat-todo-list details > summary::-webkit-details-marker { display: none; }

.chat-todo-list__header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
}

.chat-todo-list__header:hover {
  background: var(--bg-surface-inset);
}

.chat-todo-list__icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-todo-list__summary {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  font-weight: 500;
}

.chat-todo-list__meta {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.chat-todo-list__items {
  list-style: none;
  margin: 0;
  padding: var(--space-1) 0 var(--space-1) var(--space-2);
  border-top: 1px solid var(--border-subtle);
}

.chat-todo-list__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 2px var(--space-2);
  font-size: var(--text-xs);
  line-height: 1.5;
}

.chat-todo-list__status {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
}

.chat-todo-list__item--completed .chat-todo-list__status {
  color: var(--success-text, #22c55e);
}

.chat-todo-list__item--completed .chat-todo-list__text {
  text-decoration: line-through;
  color: var(--text-muted);
}

.chat-todo-list__item--in_progress .chat-todo-list__status {
  color: var(--primary, #3b82f6);
}

.chat-todo-list__item--in_progress .chat-todo-list__text {
  font-weight: 500;
  color: var(--text-primary);
}

.chat-todo-list__item--pending .chat-todo-list__status {
  color: var(--text-muted);
}

.chat-todo-list__item--pending .chat-todo-list__text {
  color: var(--text-secondary);
}

.chat-todo-list__dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary, #3b82f6);
  animation: todoPulse 1.5s ease-in-out infinite;
}

@keyframes todoPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* History section (nested expandable) */
.chat-todo-list__history {
  border-top: 1px solid var(--border-subtle);
  margin-top: var(--space-1);
}

.chat-todo-list__history > summary { list-style: none; }
.chat-todo-list__history > summary::-webkit-details-marker { display: none; }

.chat-todo-list__history-header {
  display: block;
  padding: var(--space-1) var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  cursor: pointer;
}

.chat-todo-list__history-header:hover {
  color: var(--text-secondary);
}

.chat-todo-list__history-list {
  padding: 0 var(--space-2) var(--space-1);
}

.chat-todo-list__snapshot {
  border-left: 2px solid var(--border-subtle);
  padding-left: var(--space-2);
  margin-bottom: var(--space-2);
}

.chat-todo-list__snapshot:last-child {
  margin-bottom: 0;
}

.chat-todo-list__snapshot-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: 2px;
}

.chat-todo-list__snapshot-time {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 500;
}

.chat-todo-list__snapshot-summary {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
}

.chat-todo-list__snapshot-items {
  list-style: none;
  margin: 0;
  padding: 0;
}

.chat-todo-list__snapshot-item {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 1px 0;
  font-size: 0.65rem;
  line-height: 1.4;
}

.chat-todo-list__dot--small {
  width: 6px;
  height: 6px;
}

/* ── Tool activity item detail (expandable in grouped view) ── */
.chat-tool-activity__item-detail > summary {
  list-style: none;
}
.chat-tool-activity__item-detail > summary::-webkit-details-marker {
  display: none;
}

/* ── Tool call results (inline below tool input) ── */
.chat-tool-call__result {
  border-top: 1px solid var(--border-subtle);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-surface-inset);
}

.chat-tool-call__result--error {
  background: var(--danger-bg);
}

.chat-tool-call__result-label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chat-tool-call__result--error .chat-tool-call__result-label {
  color: var(--danger-text);
}

.chat-tool-call__result-output {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.5;
  color: var(--code-text);
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Inline diff for Edit tool calls ── */
.diff {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.6;
  overflow-x: auto;
}

.diff__file-header {
  padding: var(--space-1) var(--space-2);
  background: var(--bg-surface);
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.diff__lines {
  max-height: 300px;
  overflow-y: auto;
}

.diff__line {
  padding: 0 var(--space-2);
  white-space: pre-wrap;
  word-break: break-all;
}

.diff__line--removed {
  background: color-mix(in srgb, var(--danger-text) 12%, transparent);
  color: var(--danger-text);
}

.diff__line--removed::before {
  content: "- ";
  opacity: 0.5;
}

.diff__line--added {
  background: color-mix(in srgb, var(--success-text) 12%, transparent);
  color: var(--success-text);
}

.diff__line--added::before {
  content: "+ ";
  opacity: 0.5;
}

/* ── Init divider (collapsible details) ── */
.chat-divider--init {
  flex-wrap: wrap;
}

.chat-divider__init-details {
  width: 100%;
}

.chat-divider__init-details > summary {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  text-align: center;
  list-style: none;
}
.chat-divider__init-details > summary::-webkit-details-marker {
  display: none;
}

.chat-divider__init-detail {
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-surface-inset);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.chat-divider__init-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-2);
  padding: var(--space-1) 0;
}

.chat-divider__init-key {
  font-weight: 600;
  color: var(--text-muted);
  min-width: 10ch;
}

.chat-divider__init-mcp {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.chat-divider__init-mcp-status {
  font-size: 0.65rem;
  padding: 0 var(--space-1);
  border-radius: var(--radius-full);
  background: var(--bg-surface-inset);
}
.chat-divider__init-mcp-status--connected { color: var(--status-running); }
.chat-divider__init-mcp-status--error { color: var(--danger-text); }

/* ── Turn-end details (collapsible result/token breakdown) ── */
.chat-turn-end__details {
  width: 100%;
}

.chat-turn-end__details > summary {
  cursor: pointer;
  list-style: none;
}
.chat-turn-end__details > summary::-webkit-details-marker {
  display: none;
}

.chat-turn-end__detail {
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-surface-inset);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.chat-turn-end__detail-label {
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.65rem;
}

.chat-turn-end__result-text {
  margin: var(--space-1) 0 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.5;
  color: var(--code-text);
  max-height: 150px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.chat-turn-end__tokens,
.chat-turn-end__timing,
.chat-turn-end__models,
.chat-turn-end__stop-reason {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-2);
  align-items: baseline;
}

.chat-turn-end__model-entry {
  background: var(--bg-surface);
  padding: 0 var(--space-1);
  border-radius: var(--radius-sm);
}

/* ── Status transition divider ── */
.chat-divider--status .chat-divider__label {
  font-style: italic;
  color: var(--text-muted);
  opacity: 0.8;
}

/* ── Subagent tags ── */
.chat-subagent__tag {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  background: var(--bg-surface-inset);
  padding: 0 var(--space-1);
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

/* ── Rate limit overage badge ── */
.chat-divider__overage-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0 var(--space-1);
  border-radius: var(--radius-full);
  background: var(--status-paused-bg);
  color: var(--status-paused);
  margin-left: var(--space-1);
}


/* ── Chat input — pinned at bottom ── */
/* The #chat_input_area wrapper is a direct child of .chat-page (the flex
   container). Without flex-shrink: 0, the flex algorithm can squeeze it to
   zero height on tight mobile viewports, making the input disappear. */
#chat_input_area {
  flex-shrink: 0;
}

.chat-input {
  border-top: 1px solid var(--border-subtle);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.chat-input__hint {
  font-size: var(--text-xs);
  color: var(--warning-text);
  background: var(--warning-bg);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-2);
  text-align: center;
}

.chat-input__form {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* File preview chips above the input row */
.chat-input__file-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-2) var(--space-1);
}

.chat-input__file-list[hidden] { display: none; }

.chat-input__file-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  background: var(--bg-surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  line-height: 1.3;
  color: var(--text-secondary);
  max-width: 260px;
  animation: chip-in 150ms var(--ease-out);
}

@keyframes chip-in {
  from { opacity: 0; transform: scale(0.9) translateY(4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.chat-input__file-chip-icon {
  flex-shrink: 0;
  color: var(--accent);
}

.chat-input__file-chip-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
  color: var(--text-primary);
  font-weight: 500;
}

.chat-input__file-chip-size {
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.chat-input__file-chip-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  margin: -3px -2px -3px 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  flex-shrink: 0;
}

.chat-input__file-chip-remove:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

.chat-input__file-chip-remove:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  background: var(--accent-subtle);
}

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

/* Main input row: attach + textarea + send */
.chat-input__row {
  display: flex;
  gap: var(--space-2);
  align-items: flex-end;
}

.chat-input__attach {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-min);
  height: var(--touch-min);
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition-fast), background var(--transition-fast);
}

.chat-input__attach:hover {
  color: var(--accent);
  background: var(--accent-subtle);
}

.chat-input__file-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.chat-input__textarea {
  flex: 1;
  resize: none;
  min-height: var(--touch-min);
  max-height: 120px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 16px; /* prevent iOS zoom */
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg);
  transition: border-color var(--transition-fast);
}

.chat-input__textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.chat-input__textarea::placeholder {
  color: var(--text-muted);
}

.chat-input__send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-min);
  height: var(--touch-min);
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--text-inverse);
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.chat-input__send:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.chat-input__send:active {
  transform: scale(0.95);
}

.chat-input__send svg {
  width: 18px;
  height: 18px;
}

/* Read-only footer for ended sessions */
.chat-input--readonly {
  text-align: center;
}

.chat-input__ended {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Task detail info as collapsible */
.task-detail__info-toggle {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  padding: var(--space-2) 0;
}

.task-detail__info-toggle:hover { color: var(--text-secondary); }

details.task-detail__info {
  margin-bottom: var(--space-4);
}

details.task-detail__info[open] .info-grid {
  margin-top: var(--space-3);
}

/* --- 16. New Task Form -------------------------------------------------- */
.task-new {
  max-width: 680px;
  margin: 0 auto;
}

.task-new__header {
  margin-bottom: var(--space-8);
}

.task-new__back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-3);
  transition: color var(--transition-fast);
}

.task-new__back:hover {
  color: var(--accent-text);
  text-decoration: none;
}

.task-new__header h1 {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  letter-spacing: -0.03em;
}

.task-new__description {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  margin: var(--space-2) 0 0;
  line-height: 1.6;
  max-width: 520px;
}

/* Step indicator on form sections */
.form-section__step {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #FFFFFF;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 700;
  margin-bottom: var(--space-3);
  flex-shrink: 0;
}

/* Prompt textarea — taller, more inviting */
.form-input--prompt {
  min-height: 140px;
  line-height: 1.7;
  resize: vertical;
}

/* Mono-spaced inputs (paths, tool lists) */
.form-input--mono {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

/* Manual path link */
.task-new__manual-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  transition: color var(--transition-fast);
}

.task-new__manual-link:hover { color: var(--accent-text); }

/* Advanced toggle styling */
.form-section__toggle-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-secondary);
}

.form-section__toggle-label svg {
  color: var(--text-muted);
}

.form-section__toggle-icon {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  color: var(--text-muted);
  width: 24px;
  text-align: center;
  transition: transform var(--transition-fast);
}

/* Footer: auto-start + submit */
.task-new__footer {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  margin-top: var(--space-2);
}

.task-new__autostart {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  cursor: pointer;
  margin-bottom: var(--space-5);
}

.task-new__autostart-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: var(--text-sm);
  line-height: 1.4;
}

.task-new__autostart-text strong {
  color: var(--text-primary);
}

.task-new__autostart-text span {
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.task-new__actions {
  display: flex;
  gap: var(--space-3);
}

.btn--lg {
  padding: var(--space-3) var(--space-8);
  font-size: var(--text-base);
  min-height: 48px;
}

/* Project picker (step 1a) */
.project-picker { margin-bottom: var(--space-5); }

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

.project-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-full);
  background: var(--bg);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.project-pill svg {
  color: var(--text-muted);
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.project-pill:hover {
  border-color: var(--accent);
  color: var(--text-primary);
  background: var(--accent-subtle);
}

.project-pill:hover svg {
  color: var(--accent);
}

.project-pill--active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.project-pill--active svg {
  color: #fff;
}

.project-pill--active:hover {
  background: var(--accent);
  color: #fff;
}

.project-pill__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 var(--space-1);
  border-radius: var(--radius-full);
  background: var(--bg-inset);
  font-size: 0.625rem;
  font-weight: 700;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.project-pill--active .project-pill__count {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

/* Worktree selector (step 1b — shown after project selected) */
.worktree-group {
  margin-top: var(--space-3);
  animation: fadeSlideIn 0.2s ease-out;
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.worktree-group__list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.worktree-option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition-fast);
  background: var(--bg);
}

.worktree-option:hover {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

/* Selected worktree — accent border + subtle glow */
.worktree-option:has(input[type="radio"]:checked) {
  border-color: var(--accent);
  background: var(--accent-subtle);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}

.worktree-option input[type="radio"] {
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.worktree-option__info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.worktree-option__name {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text-primary);
}

.worktree-option__branch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.worktree-option__branch svg {
  flex-shrink: 0;
  color: var(--text-muted);
}

.worktree-option__agent {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--status-running);
  background: var(--status-running-bg);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  width: fit-content;
}

/* --- 17. Status Indicators ---------------------------------------------- */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}

.status-dot--running {
  background: var(--status-running);
  box-shadow: 0 0 6px color-mix(in srgb, var(--status-running) 50%, transparent);
  animation: pulse 2s infinite;
}

.status-dot--pending  { background: var(--status-pending); }
.status-dot--paused   { background: var(--status-paused); }
.status-dot--completed { background: var(--status-completed); }
.status-dot--failed   { background: var(--status-failed); }
.status-dot--stopped  { background: var(--status-stopped); }
.status-dot--awaiting { background: var(--status-awaiting); }
.status-dot--archived { background: var(--status-archived); }
.status-dot--loading  {
  background: var(--text-muted);
  animation: status-pulse 1.2s ease-in-out infinite;
}

@keyframes status-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

.status-text {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
}

/* --- 18. Settings ------------------------------------------------------- */
.settings-container { max-width: var(--container-narrow); }

.settings-section {
  margin-bottom: var(--space-10);
  padding-bottom: var(--space-10);
  border-bottom: 1px solid var(--border-subtle);
}

.settings-section:last-child { border-bottom: none; }

.settings-section h2 {
  font-size: var(--text-xl);
  margin-bottom: var(--space-2);
}

.settings-description {
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
  font-size: var(--text-sm);
}

/* Notification settings */
.notification-settings h1 {
  font-size: var(--text-2xl);
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
  margin-bottom: var(--space-6);
}

.notification-settings__section {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-5);
}

.notification-settings__section h2 {
  font-size: var(--text-lg);
  margin-bottom: var(--space-4);
}

.notification-settings__channel,
.notification-settings__category {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-subtle);
}

.notification-settings__channel:last-child,
.notification-settings__category:last-child {
  border-bottom: none;
}

.notification-settings__label {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text-primary);
}

.notification-settings__checkbox {
  accent-color: var(--accent);
}

.notification-settings__description {
  color: var(--text-muted);
  font-size: var(--text-xs);
  margin: var(--space-1) 0 0 calc(var(--space-3) + 18px);
}

.notification-settings__actions {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  flex-wrap: wrap;
  margin-top: var(--space-6);
}

.notification-settings__quick-actions {
  display: flex;
  gap: var(--space-2);
  margin-left: auto;
}

/* --- 19. Settings Page ------------------------------------------------- */
.settings {
  max-width: 700px;
  margin: 0 auto;
}

.settings h1 {
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
  margin-bottom: var(--space-6);
}

.settings-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-5);
}

.settings-card h2 {
  font-size: var(--text-lg);
  margin-top: 0;
  margin-bottom: var(--space-4);
}

.settings-subsection {
  margin-bottom: var(--space-5);
}

.settings-subsection h3 {
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: var(--text-xs);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-subtle);
}

.notification-status:empty {
  display: none;
}

/* --- 20. Service Worker Banner ------------------------------------------ */
.service-worker-update-banner {
  position: fixed;
  bottom: var(--space-5);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-xl);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  animation: slideUp 0.35s var(--ease-out);
}

.service-worker-update-banner p {
  margin: 0;
  font-weight: 500;
  font-size: var(--text-sm);
}

/* --- 20. Dev Servers ---------------------------------------------------- */
.dev-servers {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
}

.dev-servers__header {
  margin-bottom: var(--space-8);
}

.dev-servers__header h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
  margin-bottom: var(--space-2);
}

.dev-servers__subtitle {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.dev-servers__tree {
  margin-bottom: var(--space-8);
}

.dev-servers__tree-name {
  font-size: var(--text-lg);
  font-weight: 600;
  font-family: var(--font-mono);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}

.dev-servers__list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.dev-server {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: border-color var(--transition);
}

.dev-server:hover {
  border-color: var(--border-hover, var(--border));
}

.dev-server--healthy {
  border-left: 3px solid var(--color-success, #22c55e);
}

.dev-server--running {
  border-left: 3px solid var(--color-success, #22c55e);
}

.dev-server--unresponsive {
  border-left: 3px solid var(--color-warning, #f59e0b);
}

.dev-server--stopped {
  border-left: 3px solid var(--border);
}

.dev-server__info {
  flex: 1;
  min-width: 0;
}

.dev-server__name-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-1);
}

.dev-server__name {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--text-base);
}

.dev-server__status-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  background: var(--surface-2, var(--surface-1));
}

.dev-server--healthy .dev-server__status-label {
  color: var(--color-success, #22c55e);
  background: color-mix(in srgb, var(--color-success, #22c55e) 10%, transparent);
}

.dev-server--running .dev-server__status-label {
  color: var(--color-success, #22c55e);
  background: color-mix(in srgb, var(--color-success, #22c55e) 10%, transparent);
}

.dev-server--unresponsive .dev-server__status-label {
  color: var(--color-warning, #f59e0b);
  background: color-mix(in srgb, var(--color-warning, #f59e0b) 10%, transparent);
}

.dev-server--stopped .dev-server__status-label {
  color: var(--text-muted);
}

.dev-server__meta {
  display: flex;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.dev-server__actions {
  flex-shrink: 0;
  margin-left: var(--space-4);
}

.dev-server__stopped-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* --- 20b. Worktrees ----------------------------------------------------- */
.worktrees {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
}

.worktrees__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-8);
}

.worktrees__header h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
  margin-bottom: var(--space-2);
}

.worktrees__subtitle {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.worktrees__actions {
  flex-shrink: 0;
}

.worktrees__view-toggle {
  display: flex;
  gap: 2px;
  margin-bottom: var(--space-6);
  background: var(--bg-surface-raised);
  border-radius: var(--radius);
  padding: 2px;
  width: fit-content;
}

.worktrees__view-btn {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: calc(var(--radius) - 2px);
  transition: color 0.15s ease, background 0.15s ease;
}

.worktrees__view-btn:hover {
  color: var(--text-primary);
}

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

.worktrees__view-btn--active {
  background: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.04);
}

@media (pointer: coarse) {
  .worktrees__view-btn {
    min-height: var(--touch-min);
    padding: var(--space-2) var(--space-3);
    display: flex;
    align-items: center;
  }
}

.worktrees__project {
  margin-bottom: var(--space-8);
}

.worktrees__project-name {
  font-size: var(--text-lg);
  font-weight: 600;
  font-family: var(--font-mono);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}

.worktrees__list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: var(--space-4);
}

@media (max-width: 600px) {
  .worktrees__list {
    grid-template-columns: 1fr;
  }
}

/* ── Worktree Card ────────────────────────────────────────────────────── */
.wt-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.wt-card:hover {
  border-color: color-mix(in srgb, var(--accent) 30%, var(--border));
  box-shadow: 0 1px 4px color-mix(in srgb, var(--accent) 6%, transparent);
}

/* Top row: name + status badge */
.wt-card__top {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.wt-card__name {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--text-base);
  color: var(--text-primary);
  text-decoration: none;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.15s ease;
}

.wt-card__name:hover {
  color: var(--accent);
}

/* turbo-frame participates in flex layout */
.wt-card__top turbo-frame {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
  flex-shrink: 0;
}

/* ── Status Badge ──────────────────────────────────────────────────── */
.wt-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  line-height: 1;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--text-muted) 8%, transparent);
}

.wt-badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.wt-badge__dot--pulse {
  animation: wt-dot-pulse 1.2s ease-in-out infinite;
}

@keyframes wt-dot-pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.85); }
  50%      { opacity: 1;   transform: scale(1); }
}

.wt-badge--loading {
  color: var(--text-muted);
  background: color-mix(in srgb, var(--text-muted) 6%, transparent);
}

.wt-badge--running {
  color: var(--color-success, #22c55e);
  background: color-mix(in srgb, var(--color-success, #22c55e) 10%, transparent);
}
.wt-badge--running .wt-badge__dot {
  animation: wt-dot-pulse 1.2s ease-in-out infinite;
}

.wt-badge--failed {
  color: var(--color-warning, #f59e0b);
  background: color-mix(in srgb, var(--color-warning, #f59e0b) 10%, transparent);
}

.wt-badge--stopped {
  color: var(--text-muted);
  background: color-mix(in srgb, var(--text-muted) 8%, transparent);
}

/* Restart icon button (inside turbo-frame next to badge) */
.wt-card__restart {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.wt-card__restart:hover {
  color: var(--text-primary);
  background: color-mix(in srgb, var(--text-muted) 10%, transparent);
  border-color: var(--border);
}

/* ── Card Details (branch, port, agent) ─────────────────────────────── */
.wt-card__details {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.wt-card__detail {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.wt-card__detail svg {
  opacity: 0.5;
  flex-shrink: 0;
}

.wt-card__detail--agent {
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--accent);
  font-weight: 500;
}

/* ── Card Bottom (tasks + actions) ──────────────────────────────────── */
.wt-card__bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: var(--space-3);
  border-top: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
}

.wt-card__tasks {
  display: flex;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.wt-card__task-count--active {
  color: var(--color-success, #22c55e);
  font-weight: 600;
}

.wt-card__actions {
  display: flex;
  gap: var(--space-2);
}

.wt-card__open-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.wt-card__open-link:hover {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.wt-card__open-link svg {
  opacity: 0.6;
  transition: opacity 0.15s ease;
}

.wt-card__open-link:hover svg {
  opacity: 1;
}

/* Worktree Detail */
.worktree-detail {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
}

.worktree-detail__header {
  margin-bottom: var(--space-6);
}

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

.worktree-detail__title-row h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
  font-family: var(--font-mono);
}

.worktree-detail__separator {
  color: var(--text-muted);
}

.worktree-detail__status-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
}

.worktree-detail__full-name {
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: var(--space-1);
}

.worktree-detail__info {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-6);
}

.worktree-detail__info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.worktree-detail__info-label {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-1);
}

.worktree-detail__info-value {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.worktree-detail__info-value a {
  color: var(--accent);
  text-decoration: none;
}

.worktree-detail__info-value a:hover {
  text-decoration: underline;
}

.worktree-detail__alias-form {
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

.inline-form__group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.inline-form__label {
  font-size: var(--text-sm);
  font-weight: 500;
}

.inline-form__row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.inline-form__row .form-input--small {
  max-width: 200px;
}

.inline-form__hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.worktree-detail__server-actions {
  margin-bottom: var(--space-6);
}

.worktree-detail__not-running {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.worktree-detail__not-running code {
  font-family: var(--font-mono);
  background: var(--surface-2, var(--surface-1));
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
}

.worktree-detail__section {
  margin-bottom: var(--space-8);
}

.worktree-detail__section h2 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--space-4);
}

/* Dashboard worktree cards section */
.dashboard-worktrees {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--space-3);
}

/* --- 21. Utilities ------------------------------------------------------ */
.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;
}

.text-muted { color: var(--text-muted); }

/* Turbo loading states — only for large content frames, not inline status badges.
   Frames that already show their own loading placeholder (e.g. "Checking..." badge)
   opt out via data-turbo-busy="false" or by being inside .wt-card. */
turbo-frame[busy].turbo-frame--loading { position: relative; }

turbo-frame[busy].turbo-frame--loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  z-index: 1;
}

turbo-frame[busy].turbo-frame--loading::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2rem;
  height: 2rem;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  z-index: 2;
}

/* --- 21. Focus & Accessibility ------------------------------------------ */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Skip-to-content link */
.skip-to-content {
  position: fixed;
  top: -100px;
  left: var(--space-4);
  z-index: 9999;
  padding: var(--space-2) var(--space-4);
  background: var(--bg-surface);
  color: var(--accent-text);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: var(--text-sm);
  transition: top 0.15s var(--ease-out);
}

.skip-to-content:focus {
  top: var(--space-4);
}

.btn--danger:focus-visible {
  outline-color: var(--danger);
}

/* --- 22. Animations ----------------------------------------------------- */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes slideUp {
  from { transform: translateX(-50%) translateY(100%); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0);    opacity: 1; }
}

@keyframes slideUpMobile {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes modalSlideIn {
  from { transform: translateY(-16px); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}

/* Permission UI fade */
.permission-ui { animation: fadeIn 0.3s var(--ease-out); }

/* --- 23. Responsive (mobile-first → larger screens) --------------------- */

/* < 640px: Mobile notification bottom-sheet */
@media (max-width: 639px) {
  .notification-dropdown__overlay:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    z-index: 999;
    animation: fadeInOverlay 0.2s var(--ease-out);
  }

  .notification-dropdown {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: none;
    max-height: 70vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border-bottom: none;
    margin: 0;
    animation: slideUpMobile 0.3s var(--ease-out);
  }

  .notification-dropdown__handle {
    display: flex;
  }

  .notification-dropdown__content {
    max-height: calc(70vh - 6rem);
  }

  /* Lock body scroll when notification dropdown is open */
  body.notification-dropdown-open {
    overflow: hidden;
  }
}

/* ≥ 480px: Small tablets / large phones */
@media (min-width: 480px) {
  .message-form__input-row {
    flex-direction: row;
  }

  .message-form__textarea {
    width: auto;
  }
}

/* ≥ 640px: Tablets */
@media (min-width: 640px) {
  .filters {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-row {
    grid-template-columns: 1fr 1fr;
  }

  .info-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
}

/* ≥ 768px: Desktop */
@media (min-width: 768px) {
  .filters {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }

  .button-group {
    flex-direction: row;
  }

  /* On desktop, give the chat timeline a comfortable reading width */
  .chat-timeline {
    padding: var(--space-4) var(--space-6);
    gap: var(--space-3);
  }

  .chat-input {
    padding: var(--space-3) var(--space-6);
  }

  .chat-topbar {
    padding: var(--space-2) var(--space-6);
  }
}

/* < 480px: Mobile overrides */
@media (max-width: 479px) {
  .form-input {
    font-size: 16px; /* Prevent iOS zoom */
  }

  .header-container {
    padding: var(--space-2) var(--space-3);
  }

  /* Tasks page: compact header — everything on one row */
  .tasks-header {
    flex-direction: row;
    align-items: center;
    margin-bottom: var(--space-2);
    gap: var(--space-2);
  }
  .tasks-header__title h1 { font-size: 1.125rem; margin: 0; }
  .tasks-header__stats { gap: var(--space-1); }
  .stat-badge { padding: 1px var(--space-2); font-size: 0.5625rem; }
  .tasks-header .btn--primary {
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
    white-space: nowrap;
    flex-shrink: 0;
  }

  .task-detail__title-row { flex-direction: column; }

  /* On small screens, let the chat page bleed fully — strip all margin */
  .chat-page {
    margin: calc(-1 * var(--space-6)) calc(-1 * var(--space-4));
  }

  .chat-topbar {
    padding: var(--space-1) var(--space-2);
    min-height: 2.5rem;
  }

  .chat-topbar__left { gap: var(--space-1); }

  .chat-topbar__info { gap: 1px; }

  .chat-topbar__name {
    max-width: 13rem;
    font-size: var(--text-xs);
  }

  /* Meta row: compact on mobile */
  .chat-topbar__meta-row {
    gap: 3px;
  }

  .chat-topbar__scope {
    font-size: 0.5625rem;
    max-width: 9rem;
  }

  .chat-topbar__status {
    font-size: 0.5625rem;
    gap: 3px;
  }

  /* Hide cost/turns on mobile — banner provides status context */
  .chat-topbar__cost,
  .chat-topbar__turns { display: none; }

  .chat-topbar__sep { font-size: 0.5rem; }

  /* Action buttons: icon-only on mobile */
  .chat-topbar__action-label { display: none; }
  .chat-topbar__action-btn { padding: var(--space-1) var(--space-2); }

  /* Banner: tighter on mobile */
  .chat-banner {
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
  }

  .chat-timeline {
    padding: var(--space-2);
    gap: var(--space-2);
  }

  .chat-input {
    padding: var(--space-2);
    /* account for mobile safe-area on phones with home indicator */
    padding-bottom: max(var(--space-2), env(safe-area-inset-bottom));
  }

  .chat-input__file-chip {
    max-width: calc(100% - var(--space-2));
  }

  .chat-input__file-chip-name {
    max-width: 120px;
  }

  .notifications__header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-4);
  }

  .dashboard-stats {
    flex-wrap: wrap;
  }

  .dashboard-stat {
    flex: 1 1 calc(50% - var(--space-2));
    min-width: 0;
  }

  .dashboard__header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
  }

  .settings-card {
    padding: var(--space-4);
  }

  .notification-settings__actions {
    flex-direction: column;
  }

  .notification-settings__quick-actions {
    margin-left: 0;
  }

  .form-actions--aligned {
    flex-direction: column-reverse;
  }

  .form-actions--aligned .btn {
    width: 100%;
  }

  .notification__actions {
    flex-direction: column;
    margin-left: var(--space-2);
  }

  .modal__content {
    margin: var(--space-4);
    max-height: calc(100vh - var(--space-8));
  }

  .dashboard-tasks-card__stats { gap: var(--space-4); }

  .auth-container {
    margin: var(--space-4);
    padding: var(--space-6);
  }
}

/* --- 24. Reduced Motion ------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- 25. Image Lightbox ------------------------------------------------- */
.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0);
  backdrop-filter: blur(0);
  transition: background 0.2s ease, backdrop-filter 0.2s ease;
  padding: var(--space-4);
}

.image-lightbox--visible {
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
}

.image-lightbox__img {
  max-width: 95vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: var(--radius-lg, 8px);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: scale(0.92);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.image-lightbox--visible .image-lightbox__img {
  opacity: 1;
  transform: scale(1);
}

.image-lightbox__close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  z-index: 1;
}

.image-lightbox__close:hover {
  background: rgba(255, 255, 255, 0.3);
}

@media (max-width: 640px) {
  .image-lightbox { padding: var(--space-2); }
  .image-lightbox__img { max-width: 100vw; max-height: 90vh; border-radius: var(--radius); }
  .image-lightbox__close { top: var(--space-2); right: var(--space-2); }
}

/* --- 26. High Contrast -------------------------------------------------- */
@media (prefers-contrast: high) {
  :focus-visible { outline-width: 3px; }
  .form-input { border-width: 3px; }
  .btn { border-width: 3px; }
  .alert { border-width: 2px; }
  .task-card { border-left-width: 6px; }
  .event-card { border-left-width: 5px; }
}
