/* Appearance controls stay available on desktop and mobile. */
:root { color-scheme: light; }
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; border-radius: 8px; }
.theme-toggle:hover { background: var(--line); }
.theme-toggle[hidden], .theme-toggle .theme-sun { display: none; }
.theme-toggle[aria-pressed="true"] .theme-sun { display: inline; }
.theme-toggle[aria-pressed="true"] .theme-moon { display: none; }

/* Keep print output on the existing light palette, including when the app is dark. */
@media screen {
  :root[data-theme="dark"] {
    color-scheme: dark;
    --paper: #111c17;
    --surface: #1a2922;
    --ink: #e3ebe5;
    --muted: #a8b7ac;
    --line: #35493c;
    --green: #97c4a8;
    --warm: #303125;
    --danger: #efa58f;
    --shadow: 0 3px 18px #00000040;
    --theme-accent: #b8d7c0;
    --theme-soft: #22352a;
    --theme-hover: #2c4234;
    --theme-input: #15241c;
    --theme-warning-bg: #3b3020;
    --theme-warning-ink: #ecd39a;
    --theme-danger-bg: #3c2823;
    --theme-success-bg: #243b2d;
    --theme-info-bg: #21343a;
  }

  /* Low specificity preserves the sidebar, badges and other intentional link colors. */
  :where(:root[data-theme="dark"]) a { color: var(--theme-accent); }
  :root[data-theme="dark"] .sidebar { background: #102b22; border-right: 1px solid var(--line); }
  :root[data-theme="dark"] .topbar { background: var(--surface); }
  :root[data-theme="dark"] :is(.breadcrumb, .global-search, .eyebrow, .stat>span, .stat small,
    .task-meta, .project-card p, .project-card-bottom, .entry-line>span:last-child,
    .entry-line small, .note-footer, .tags, td small, .cost-summary span,
    .field .help, .help, .required, .capture-note, .type-choice,
    .stream-list li:before, .kanban-column>h3 span) { color: var(--muted); }
  :root[data-theme="dark"] :is(.heading-dot, .context-intro .icon) { color: var(--green); }

  :root[data-theme="dark"] :is(.skip-link, .global-search kbd, .button) {
    background: var(--surface); color: var(--theme-accent); border-color: var(--line);
  }
  :root[data-theme="dark"] .button:hover { background: var(--theme-hover); border-color: #5c7862; }
  :root[data-theme="dark"] .button.primary {
    background: #264e3d; border-color: #507b5e; color: #f1f5e9;
  }
  :root[data-theme="dark"] .button.primary:hover { background: #34634b; }
  :root[data-theme="dark"] .button.light { background: var(--lime); color: #183d34; }
  :root[data-theme="dark"] .button.light:hover { background: #e5efbf; }
  :root[data-theme="dark"] .button.danger { background: #914c3a; border-color: #ba735b; color: #fff; }
  :root[data-theme="dark"] .button.danger:hover { background: #a45a46; }
  :root[data-theme="dark"] :is(.text-button, .tabs a.selected, .project-children summary) {
    color: var(--theme-accent);
  }
  :root[data-theme="dark"] .tabs a.selected { border-bottom-color: var(--green); }

  :root[data-theme="dark"] :is(.panel.tint, .welcome, .context-bar, .kanban-column,
    .cost-summary, .file-icon, .entry-icon, .prose pre, .prose code, th,
    .link-card-image, .file-linked-preview>img) { background: var(--theme-soft); border-color: var(--line); }
  :root[data-theme="dark"] :is(.entry-icon, th) { color: var(--green); }
  :root[data-theme="dark"] :is(.task-row, .project-card, .project-card-bottom,
    .entry-line, td, th, .type-choice) { border-color: var(--line); }
  :root[data-theme="dark"] :is(.project-card:hover, .note-card:hover) { border-color: #5c7862; }
  :root[data-theme="dark"] .task-check { border-color: #74917a; color: var(--green); }
  :root[data-theme="dark"] .task-check:hover { background: var(--theme-hover); }
  :root[data-theme="dark"] .prose blockquote { border-color: #74917a; }
  :root[data-theme="dark"] .task-meta span+span:before { color: var(--muted); }

  :root[data-theme="dark"] .project-glyph { background: var(--theme-success-bg); color: #aacb95; }
  :root[data-theme="dark"] .kind-software .project-glyph { background: var(--theme-info-bg); color: #accbda; }
  :root[data-theme="dark"] .kind-maker .project-glyph { background: var(--theme-warning-bg); color: #dfbd8e; }
  :root[data-theme="dark"] .kind-art .project-glyph { background: #382b37; color: #d7b0c8; }
  :root[data-theme="dark"] .kind-research .project-glyph { background: #2e2f42; color: #c1c0e5; }
  :root[data-theme="dark"] .badge { background: var(--theme-soft); border-color: var(--line); color: #bacab1; }
  :root[data-theme="dark"] :is(.status-active, .status-completed) { background: var(--theme-success-bg); color: #b1d2a6; }
  :root[data-theme="dark"] :is(.status-ready, .status-waiting, .type-idea) {
    background: var(--theme-warning-bg); color: var(--theme-warning-ink);
  }
  :root[data-theme="dark"] :is(.status-monitoring, .type-observation) { background: var(--theme-info-bg); color: #accbda; }
  :root[data-theme="dark"] .status-dormant { background: #332b3e; color: #d1bddc; }

  :root[data-theme="dark"] :is(input:not([type=checkbox]):not([type=hidden]), textarea, select, .context-bar select) {
    background: var(--theme-input); color: var(--ink); border-color: var(--line);
  }
  :root[data-theme="dark"] :is(input, textarea)::placeholder { color: #8ea294; }
  :root[data-theme="dark"] .global-search input { background: transparent; }
  :root[data-theme="dark"] input[type=checkbox] { accent-color: #97c4a8; }
  :root[data-theme="dark"] input[type=file]::file-selector-button {
    background: var(--theme-hover); color: var(--theme-accent);
  }
  :root[data-theme="dark"] .form-actions { background: #111c17f0; }
  :root[data-theme="dark"] .type-choice { background: var(--surface); }
  :root[data-theme="dark"] .type-choice.selected {
    background: var(--theme-hover); color: var(--theme-accent); border-color: #74917a;
  }
  :root[data-theme="dark"] :is(.message, .pwa-form-status) {
    background: var(--theme-success-bg); border-color: #506c49; color: var(--ink);
  }
  :root[data-theme="dark"] .message.error {
    background: var(--theme-danger-bg); border-color: #805a49; color: var(--danger);
  }
  :root[data-theme="dark"] .pwa-status {
    background: var(--theme-warning-bg); color: var(--theme-warning-ink); border-color: #78603b;
  }
  :root[data-theme="dark"] .pwa-status[data-state="online"] {
    background: var(--theme-success-bg); color: #b1d2a6; border-color: #506c49;
  }
  :root[data-theme="dark"] .mobile-nav { background: #1a2922f5; }
  :root[data-theme="dark"] .mobile-nav a { color: var(--muted); }
  :root[data-theme="dark"] .mobile-nav .capture-nav { color: var(--theme-accent); }
}
