/* ─────────────────────────────────────────────────────────────────────────────
   Unscattered — app.css
   CSS custom properties + @layer architecture.
   No Tailwind. No preprocessor. Web Platform first.
   ───────────────────────────────────────────────────────────────────────────── */

/* ─── @layer order ───────────────────────────────────────────────────────────── */
@layer reset, tokens, base, layout, components, views, utilities;

/* ─── Design Tokens ─────────────────────────────────────────────────────────── */
@layer tokens {
  :root {
    /* Colors */
    --color-bg: #ffffff;
    --color-surface: #f8f9fa;
    --color-surface-2: #f1f5f9;
    --color-border: #e2e8f0;
    --color-text: #1a1a2e;
    --color-muted: #64748b;
    --color-primary: #3b82f6;
    --color-primary-hover: #2563eb;
    --color-danger: #ef4444;
    --color-danger-hover: #dc2626;
    --color-success: #22c55e;

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    /* Typography */
    --font-sans: "Inter", system-ui, -apple-system, sans-serif;
    --font-mono: "JetBrains Mono", "Fira Code", monospace;
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgb(0 0 0 / 0.08);
    --shadow-md: 0 4px 16px rgb(0 0 0 / 0.12);
    --shadow-lg: 0 8px 32px rgb(0 0 0 / 0.16);

    /* 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;

    /* Touch targets */
    --touch-target: 44px;

    /* Layout */
    --header-height: 56px;
    --max-list-width: 600px;

    /* Transitions */
    --transition-fast: 120ms ease;
    --transition-base: 200ms ease;
    --transition-slow: 300ms ease;
  }

  [data-theme="dark"] {
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-surface-2: #293548;
    --color-border: #334155;
    --color-text: #f1f5f9;
    --color-muted: #94a3b8;
    --color-primary: #60a5fa;
    --color-primary-hover: #3b82f6;
  }
}

/* ─── Reset ──────────────────────────────────────────────────────────────────── */
@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

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

  body {
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100dvh;
  }

  img,
  svg {
    display: block;
  }

  button,
  input,
  textarea,
  select {
    font: inherit;
    color: inherit;
  }

  a {
    color: inherit;
  }

  ul,
  ol {
    list-style: none;
  }

  dialog {
    border: none;
    background: none;
    padding: 0;
    max-width: 100%;
    max-height: 100%;
  }
}

/* ─── Base ───────────────────────────────────────────────────────────────────── */
@layer base {
  .icon {
    width: 1.25em;
    height: 1.25em;
    flex-shrink: 0;
  }

  :focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
  }

  /* Smooth color scheme transition */
  body,
  .app-header,
  .modal__content,
  .node-panel__content {
    transition:
      background-color var(--transition-base),
      color var(--transition-base),
      border-color var(--transition-base);
  }
}

/* ─── Layout ─────────────────────────────────────────────────────────────────── */
@layer layout {
  /* App shell — header takes fixed height; content fills remainder */
  .app-header + * {
    padding-top: var(--header-height);
  }
}

/* ─── Components ─────────────────────────────────────────────────────────────── */
@layer components {
  /* --- Buttons --- */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    min-height: var(--touch-target);
    transition:
      background-color var(--transition-fast),
      opacity var(--transition-fast);
    white-space: nowrap;
  }

  .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .btn--primary {
    background: var(--color-primary);
    color: #fff;
  }
  .btn--primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
  }

  .btn--ghost {
    background: transparent;
    color: var(--color-text);
    border: 1.5px solid var(--color-border);
  }
  .btn--ghost:hover:not(:disabled) {
    background: var(--color-surface);
  }

  .btn--danger-ghost {
    background: transparent;
    color: var(--color-danger);
    border: 1.5px solid transparent;
  }
  .btn--danger-ghost:hover:not(:disabled) {
    background: hsl(from var(--color-danger) h s l / 0.08);
  }

  .btn--full {
    width: 100%;
  }
  .btn--sm {
    min-height: 36px;
    padding: var(--space-1) var(--space-3);
  }

  .btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--touch-target);
    height: var(--touch-target);
    border: none;
    background: transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--color-muted);
    transition:
      background-color var(--transition-fast),
      color var(--transition-fast);
  }
  .btn-icon:hover {
    background: var(--color-surface);
    color: var(--color-text);
  }
  .btn-icon:disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }
  .btn-icon--danger {
    color: var(--color-danger);
  }
  .btn-icon--danger:hover {
    background: hsl(from var(--color-danger) h s l / 0.1);
  }

  .install-app-btn {
    color: #345995;
    background:
      linear-gradient(135deg, rgb(52 89 149 / 0.14), rgb(255 155 84 / 0.18)),
      var(--color-surface);
    border: 1px solid rgb(52 89 149 / 0.14);
  }

  /* --- Theme toggle --- */
  .theme-toggle .theme-toggle__moon {
    display: none;
  }
  [data-theme="dark"] .theme-toggle .theme-toggle__sun {
    display: none;
  }
  [data-theme="dark"] .theme-toggle .theme-toggle__moon {
    display: block;
  }

  /* --- Forms --- */
  .form-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
  }

  .form-label {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--color-text);
  }

  .form-label__optional {
    color: var(--color-muted);
    font-weight: 400;
  }

  .form-input {
    padding: var(--space-3);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: var(--text-base);
    transition: border-color var(--transition-fast);
    width: 100%;
    resize: vertical;
  }
  .form-input:focus {
    outline: none;
    border-color: var(--color-primary);
  }
  .form-input--large {
    font-size: var(--text-lg);
    min-height: var(--touch-target);
  }
  .form-input::placeholder {
    color: var(--color-muted);
  }

  textarea.form-input {
    min-height: 80px;
  }

  /* --- Header --- */
  .app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-3);
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    z-index: 100;
    gap: var(--space-2);
  }

  .app-header__left,
  .app-header__right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
  }

  .sync-status {
    position: fixed;
    top: calc(var(--header-height) + var(--space-2));
    right: var(--space-3);
    z-index: 90;
    padding: 0.55rem 0.85rem;
    border-radius: var(--radius-full);
    border: 1px solid var(--color-border);
    background: rgb(255 255 255 / 0.82);
    backdrop-filter: blur(18px);
    box-shadow: var(--shadow-sm);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }

  [data-theme="dark"] .sync-status {
    background: rgb(15 23 42 / 0.82);
  }

  .sync-status[data-tone="synced"] {
    color: #166534;
    border-color: rgb(34 197 94 / 0.28);
  }

  .sync-status[data-tone="pending"],
  .sync-status[data-tone="offline"] {
    color: #9a6700;
    border-color: rgb(245 158 11 / 0.28);
  }

  .sync-status[data-tone="syncing"] {
    color: #345995;
    border-color: rgb(52 89 149 / 0.24);
  }

  .sync-status[data-tone="conflict"] {
    color: #b42318;
    border-color: rgb(239 68 68 / 0.32);
  }

  .ios-install-tip {
    position: fixed;
    left: var(--space-3);
    right: var(--space-3);
    bottom: calc(env(safe-area-inset-bottom) + var(--space-3));
    z-index: 110;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border: 1px solid rgb(52 89 149 / 0.16);
    border-radius: calc(var(--radius-lg) + 6px);
    background:
      radial-gradient(circle at top left, rgb(255 155 84 / 0.18), transparent 36%),
      linear-gradient(135deg, rgb(247 241 231 / 0.94), rgb(255 255 255 / 0.96));
    box-shadow: var(--shadow-lg);
  }

  [data-theme="dark"] .ios-install-tip {
    background:
      radial-gradient(circle at top left, rgb(255 155 84 / 0.16), transparent 36%),
      linear-gradient(135deg, rgb(30 41 59 / 0.96), rgb(15 23 42 / 0.96));
  }

  .sync-conflict-modal__content {
    max-width: 28rem;
  }

  .sync-conflict-modal__body {
    margin-top: var(--space-2);
    color: var(--color-muted);
    line-height: 1.6;
  }

  /* --- Project switcher --- */
  .project-switcher {
    position: relative;
  }

  .project-switcher__trigger {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-2) var(--space-3);
    background: transparent;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 600;
    font-size: var(--text-sm);
    max-width: 200px;
    min-height: 36px;
  }
  .project-switcher__trigger:hover {
    background: var(--color-surface);
  }

  .project-switcher__name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .project-switcher__menu {
    position: absolute;
    top: calc(100% + var(--space-2));
    left: 0;
    min-width: 200px;
    background: var(--color-bg);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 200;
    padding: var(--space-1) 0;
  }

  .project-switcher__item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
  }
  .project-switcher__item:hover {
    background: var(--color-surface);
  }

  .project-switcher__sep {
    border-top: 1px solid var(--color-border);
    margin: var(--space-1) 0;
  }

  /* --- View toggle --- */
  .view-toggle {
    display: flex;
    background: var(--color-surface);
    border-radius: var(--radius-md);
    padding: 3px;
    gap: 2px;
  }

  .view-toggle__btn {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-3);
    border-radius: calc(var(--radius-md) - 3px);
    font-size: var(--text-sm);
    font-weight: 500;
    text-decoration: none;
    color: var(--color-muted);
    transition:
      background-color var(--transition-fast),
      color var(--transition-fast);
    min-height: 32px;
  }

  .view-toggle__btn:hover {
    color: var(--color-text);
  }

  .view-toggle__btn.is-active {
    background: var(--color-bg);
    color: var(--color-text);
    box-shadow: var(--shadow-sm);
  }

  @media (max-width: 400px) {
    .view-toggle__label {
      display: none;
    }
  }

  /* --- User menu --- */
  .user-menu {
    position: relative;
  }

  .user-menu__trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    font-weight: 700;
    cursor: pointer;
    text-transform: uppercase;
  }

  .user-menu__dropdown {
    position: absolute;
    top: calc(100% + var(--space-2));
    right: 0;
    min-width: 160px;
    background: var(--color-bg);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 200;
    padding: var(--space-1) 0;
  }

  .user-menu__name {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--color-muted);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-1);
  }

  .user-menu__item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    background: transparent;
    border: none;
    cursor: pointer;
    text-align: left;
  }
  .user-menu__item:hover {
    background: var(--color-surface);
  }
  .user-menu__item--danger {
    color: var(--color-danger);
  }
  .user-menu__logout-form {
    display: contents;
  }

  /* --- Project actions dropdown --- */
  .project-actions {
    position: relative;
  }

  .project-actions__menu {
    position: absolute;
    top: calc(100% + var(--space-2));
    right: 0;
    min-width: 200px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: var(--space-1) 0;
    list-style: none;
    z-index: 200;
  }

  .project-actions__item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    padding: var(--space-2) var(--space-3);
    background: none;
    border: none;
    cursor: pointer;
    font-size: var(--text-sm);
    color: var(--color-text);
    text-align: left;
    white-space: nowrap;
  }

  .project-actions__item:hover {
    background: var(--color-surface);
  }

  .project-actions__sep {
    height: 1px;
    background: var(--color-border);
    margin: var(--space-1) 0;
  }

  /* --- Modal --- */
  .modal::backdrop {
    background: rgb(0 0 0 / 0.5);
    backdrop-filter: blur(2px);
  }

  .modal[open] {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .modal--bottom[open] {
    align-items: flex-end;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .modal__content {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    width: min(480px, calc(100vw - var(--space-8)));
    max-height: 90dvh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
  }

  .modal--bottom .modal__content {
    width: 100%;
    max-width: 600px;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-lg);
  }

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

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

  .modal__form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding: var(--space-5);
  }

  .modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    padding-top: var(--space-2);
  }

  .modal__actions--spaced {
    justify-content: space-between;
  }

  /* --- Flash messages --- */
  .flash {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: 500;
  }
  .flash--success {
    background: hsl(from var(--color-success) h s l / 0.12);
    color: var(--color-success);
  }
  .flash--error {
    background: hsl(from var(--color-danger) h s l / 0.12);
    color: var(--color-danger);
  }

  /* --- FAB (floating action button) --- */
  .fab {
    position: fixed;
    bottom: calc(var(--space-6) + env(safe-area-inset-bottom));
    right: var(--space-5);
    width: 56px;
    height: 56px;
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition:
      transform var(--transition-fast),
      background-color var(--transition-fast);
    z-index: 50;
  }
  .fab:hover {
    background: var(--color-primary-hover);
    transform: scale(1.05);
  }
  .fab:active {
    transform: scale(0.95);
  }

  /* --- Color picker --- */
  .color-picker {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
  }

  .color-swatch {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    border: 2px solid transparent;
    cursor: pointer;
    transition:
      transform var(--transition-fast),
      border-color var(--transition-fast);
  }
  .color-swatch:hover {
    transform: scale(1.15);
  }
  .color-swatch.is-selected {
    border-color: var(--color-text);
  }
  .color-swatch--none {
    border: 2px dashed var(--color-border);
    position: relative;
  }
  .color-swatch--none::after {
    content: "×";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--color-muted);
  }
}

/* ─── Views ──────────────────────────────────────────────────────────────────── */
@layer views {
  /* === Auth page === */
  .auth-page {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    background: var(--color-surface);
  }

  .auth-card {
    width: min(420px, 100%);
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    padding: var(--space-8) var(--space-6);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
  }

  .auth-card__logo {
    display: flex;
    justify-content: center;
  }

  .auth-logo {
    width: 48px;
    height: 48px;
    color: var(--color-primary);
  }

  .auth-card__title {
    font-size: var(--text-2xl);
    font-weight: 700;
    text-align: center;
    margin-top: calc(-1 * var(--space-2));
  }

  .auth-card__subtitle {
    font-size: var(--text-sm);
    color: var(--color-muted);
    text-align: center;
    margin-top: calc(-1 * var(--space-3));
  }

  .auth-error {
    background: hsl(from var(--color-danger) h s l / 0.1);
    color: var(--color-danger);
    border: 1px solid hsl(from var(--color-danger) h s l / 0.3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
  }

  .auth-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
  }

  .auth-card__switch {
    font-size: var(--text-sm);
    color: var(--color-muted);
    text-align: center;
  }

  .auth-card__switch a {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
  }
  .auth-card__switch a:hover {
    text-decoration: underline;
  }

  /* === Projects page === */
  .projects-page {
    max-width: 720px;
    margin: 0 auto;
    padding: calc(var(--header-height) + var(--space-6)) var(--space-4)
      calc(var(--space-6) + env(safe-area-inset-bottom));
  }

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

  .projects-page__title {
    font-size: var(--text-2xl);
    font-weight: 700;
  }

  .project-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }

  .project-card {
    background: var(--color-bg);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    align-items: stretch;
    transition:
      box-shadow var(--transition-fast),
      border-color var(--transition-fast);
  }
  .project-card:hover {
    box-shadow: var(--shadow-sm);
    border-color: var(--color-primary);
  }

  .project-card__link {
    flex: 1;
    display: flex;
    align-items: center;
    padding: var(--space-4) var(--space-5);
    text-decoration: none;
    gap: var(--space-3);
    min-width: 0;
  }

  .project-card__body {
    flex: 1;
    min-width: 0;
  }

  .project-card__name {
    font-size: var(--text-base);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .project-card__desc {
    font-size: var(--text-sm);
    color: var(--color-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .project-card__arrow {
    color: var(--color-muted);
    flex-shrink: 0;
  }

  .project-card__actions {
    display: flex;
    align-items: center;
    padding: 0 var(--space-2);
    border-left: 1px solid var(--color-border);
  }

  .projects-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-8);
    text-align: center;
  }

  .projects-empty__icon {
    width: 64px;
    height: 64px;
    color: var(--color-border);
  }
  .projects-empty__text {
    color: var(--color-muted);
    font-size: var(--text-lg);
  }

  /* === List view === */
  .list-page {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .breadcrumb {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    min-height: 44px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    padding: var(--space-1) var(--space-3);
    gap: var(--space-2);
    z-index: 90;
    font-size: var(--text-lg);
  }

  .breadcrumb__back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--color-muted);
    border-radius: var(--radius-md);
    flex-shrink: 0;
  }
  .breadcrumb__back:hover {
    background: var(--color-surface-2);
    color: var(--color-text);
  }

  .breadcrumb__path {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex-wrap: wrap;
    flex: 1;
    list-style: none;
    margin: 0;
    padding: 0;
  }
  .breadcrumb__path li {
    display: flex;
    align-items: center;
    gap: var(--space-1);
  }

  .breadcrumb__item {
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--color-muted);
    font-weight: 500;
  }
  .breadcrumb__item:last-child {
    color: var(--color-text);
  }
  .breadcrumb__item:hover {
    text-decoration: underline;
  }

  .breadcrumb__sep {
    color: var(--color-border);
    flex-shrink: 0;
  }

  .list-main {
    flex: 1;
    overflow-y: auto;
    padding: calc(var(--header-height) + 44px + var(--space-3)) var(--space-3)
      calc(80px + env(safe-area-inset-bottom)) var(--space-3);
    max-width: var(--max-list-width);
    margin: 0 auto;
    width: 100%;
  }

  /* --- Task list --- */
  .task-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .task-list-empty {
    padding: var(--space-8);
    text-align: center;
    color: var(--color-muted);
  }

  .task-row {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-md);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    touch-action: pan-y;
    user-select: none;
    transition: opacity var(--transition-fast);
  }
  .task-row.is-dragging {
    opacity: 0.5;
  }
  .task-row.drag-over {
    border-color: var(--color-primary);
  }

  .task-row__inner {
    display: flex;
    align-items: center;
    min-height: var(--touch-target);
    padding: var(--space-2) var(--space-3);
    gap: var(--space-2);
    position: relative;
    z-index: 1;
    background: var(--color-bg);
    transition:
      transform var(--transition-fast),
      background-color var(--transition-fast);
  }

  /* Status icon button */
  .task-row__status {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    border-radius: var(--radius-full);
    transition: background-color var(--transition-fast);
  }
  .task-row__status:hover {
    background: var(--color-surface);
  }
  .task-row__status:active {
    transform: scale(0.9);
  }

  /* Color bar (replaces color dot) */
  .task-row__color-bar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    border-radius: 3px 0 0 3px;
  }

  /* Status picker in edit modal */
  .status-picker {
    display: flex;
    gap: var(--space-2);
  }
  .status-picker__btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: var(--space-2) var(--space-3);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    background: transparent;
    cursor: pointer;
    font-size: var(--text-sm);
    color: var(--color-text);
    transition: all var(--transition-fast);
  }
  .status-picker__btn:hover {
    border-color: var(--color-muted);
  }
  .status-picker__btn.is-active {
    border-color: var(--color-primary);
    background: var(--color-surface);
  }

  .task-row__drag {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    cursor: grab;
    color: var(--color-border);
    flex-shrink: 0;
    padding: 0;
  }
  .task-row__drag:active {
    cursor: grabbing;
  }

  .task-row.is-selected {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
  }
  .task-row.is-completed .task-row__content {
    opacity: 0.5;
    text-decoration: line-through;
  }

  .task-row__content {
    flex: 1;
    min-width: 0;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-2) 0;
  }

  .task-row__title {
    font-size: var(--text-base);
    word-break: break-word;
  }

  .task-row__desc {
    font-size: var(--text-sm);
    color: var(--color-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .task-row__drill {
    display: flex;
    align-items: center;
    gap: 4px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--color-muted);
    padding: var(--space-2);
    min-width: var(--touch-target);
    height: var(--touch-target);
    border-radius: var(--radius-md);
    flex-shrink: 0;
    font-size: var(--text-xs);
    font-weight: 600;
  }
  .task-row__drill:hover {
    background: var(--color-surface);
    color: var(--color-text);
  }

  .task-row__count {
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--color-muted);
  }

  /* === Mindmap view === */
  .mindmap-page {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .mindmap-toolbar {
    position: fixed;
    top: calc(var(--header-height) + var(--space-3));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: var(--space-1);
    background: var(--color-bg);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-1);
    box-shadow: var(--shadow-md);
    z-index: 80;
  }

  .mindmap-toolbar__sep {
    width: 1px;
    height: 24px;
    background: var(--color-border);
    margin: 0 var(--space-1);
  }

  .mindmap-canvas {
    flex: 1;
    width: 100%;
    display: block;
    cursor: grab;
    touch-action: none; /* Required for Pointer Events to work on touch */
  }
  .mindmap-canvas:active {
    cursor: grabbing;
  }

  /* --- Notes tooltip (description preview on hover / touch) --- */
  .mindmap-notes-tooltip {
    position: fixed;
    z-index: 60;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    background: var(--color-bg);
    color: var(--color-text);
    border: 1.5px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    font-size: var(--text-sm);
    line-height: 1.45;
    max-width: 320px;
    pointer-events: none;
    white-space: pre-wrap;
    word-break: break-word;
  }

  /* --- Inline node title editor (overlay input on canvas) --- */
  .mindmap-inline-edit {
    position: fixed;
    z-index: 50;
    padding: 0 8px;
    border: 2px solid var(--color-primary);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    color: var(--color-text);
    font:
      14px system-ui,
      sans-serif;
    outline: none;
    box-shadow: var(--shadow-md);
  }

  /* --- Node edit panel (aside, slides in from right) --- */
  .node-panel {
    position: fixed;
    top: var(--header-height);
    right: 0;
    bottom: 0;
    width: min(320px, 100vw);
    background: var(--color-bg);
    border-left: 1.5px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    z-index: 90;
    transform: translateX(100%);
    transition: transform var(--transition-base);
    overflow-y: auto;
  }
  .node-panel[hidden] {
    display: none !important;
  }
  .node-panel.is-open {
    transform: translateX(0);
  }

  .node-panel__content {
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
  }

  .node-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .node-panel__title {
    font-size: var(--text-base);
    font-weight: 600;
  }

  .node-panel__actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    justify-content: flex-end;
  }
}

/* ─── Utilities ──────────────────────────────────────────────────────────────── */
@layer 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-width: 0;
  }

  [hidden] {
    display: none !important;
  }

  /* === Settings page === */
  .settings-page {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .settings-main {
    flex: 1;
    overflow-y: auto;
    padding: calc(var(--header-height) + var(--space-6)) var(--space-4)
      var(--space-8);
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
  }

  .settings-title {
    font-size: var(--text-xl);
    font-weight: 700;
    margin-bottom: var(--space-6);
  }

  .settings-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
  }

  .settings-api-key {
    display: flex;
    gap: var(--space-2);
  }
  .settings-api-key .form-input {
    flex: 1;
    font-family: monospace;
    font-size: var(--text-sm);
  }

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

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

  /* --- Date field row (side-by-side date pickers) --- */
  .form-field-row {
    display: flex;
    gap: var(--space-3);
  }
  .form-field-row .form-field {
    flex: 1;
    min-width: 0;
  }
  .form-field-row .form-input {
    width: 100%;
    min-width: 0;
  }
}
