:root {
  --apms-theme-background: #15191f;
  --apms-theme-surface: #252b33;
  --apms-theme-surface-raised: #303740;
  --apms-theme-line: #414954;
  --apms-theme-text: #f4f6f8;
  --apms-theme-muted: #aeb5be;
}

:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="light"] {
  color-scheme: light;
  background: #f6f7f9;
}

.apms-theme-toggle {
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.apms-theme-toggle svg {
  width: 22px;
  height: 22px;
  fill: none !important;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.apms-theme-toggle .theme-icon-sun { display: none; }
:root[data-theme="dark"] .apms-theme-toggle .theme-icon-sun { display: block; }
:root[data-theme="dark"] .apms-theme-toggle .theme-icon-moon { display: none; }
.apms-theme-toggle:focus-visible { outline: 3px solid rgba(255, 90, 0, 0.46); outline-offset: 2px; }
.apms-theme-toggle:active { transform: scale(0.97); }

:root[data-theme="light"] .apms-global-nav {
  background: rgba(255, 255, 255, 0.98);
  border-color: #d9dee5;
  box-shadow: 0 -10px 28px rgba(10, 14, 20, 0.1);
}

:root[data-theme="light"] .apms-global-nav a { color: #626d7a; }
:root[data-theme="light"] .apms-global-nav a.active,
:root[data-theme="light"] .apms-global-nav a[aria-current="page"] { color: #d94d00; }

:root[data-theme="light"] .apms-global-nav::after { border-color: #1e232a; }

/* Operations */
:root[data-theme="light"] body[data-apms-module="operations"] {
  --ink: #171a1f;
  --muted: #606874;
  --line: #d9dde2;
  --soft: #e8ebee;
  --paper: #ffffff;
  --orange-dark: #c94700;
  --blue: #1d4e73;
  background: var(--soft);
}

:root[data-theme="light"] body[data-apms-module="operations"] .command-band {
  border-top-color: #d9dde2;
  background:
    linear-gradient(115deg, rgba(246, 247, 249, 0.99), rgba(232, 235, 238, 0.98)),
    repeating-linear-gradient(90deg, transparent 0 79px, rgba(21, 25, 31, 0.035) 80px);
  color: var(--ink);
}

:root[data-theme="light"] body[data-apms-module="operations"] .command-band small,
:root[data-theme="light"] body[data-apms-module="operations"] .command-band p,
:root[data-theme="light"] body[data-apms-module="operations"] .scope-controls label {
  color: var(--muted);
}

:root[data-theme="light"] body[data-apms-module="operations"] .scope-controls select {
  border-color: #c7cdd4;
  background: #ffffff;
  color: var(--ink);
}

:root[data-theme="light"] body[data-apms-module="operations"] .segmented {
  border-color: #c7cdd4;
  background: #dfe3e7;
}

:root[data-theme="light"] body[data-apms-module="operations"] .segmented button {
  color: var(--muted);
}

:root[data-theme="light"] body[data-apms-module="operations"] .segmented button.active {
  background: #ffffff;
  color: var(--ink);
}

:root[data-theme="dark"] body[data-apms-module="operations"] {
  --ink: var(--apms-theme-text);
  --muted: var(--apms-theme-muted);
  --line: var(--apms-theme-line);
  --soft: var(--apms-theme-background);
  --paper: var(--apms-theme-surface);
  --orange-dark: #ff7a33;
  --blue: #72a9d2;
  background: var(--apms-theme-background);
}

:root[data-theme="dark"] body[data-apms-module="operations"] .command-band {
  background: linear-gradient(115deg, #15191f, #20262d);
}

:root[data-theme="dark"] body[data-apms-module="operations"] .metric,
:root[data-theme="dark"] body[data-apms-module="operations"] .content-band,
:root[data-theme="dark"] body[data-apms-module="operations"] .status-band {
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.2);
}

:root[data-theme="dark"] body[data-apms-module="operations"] .metric small { color: var(--muted); }
:root[data-theme="dark"] body[data-apms-module="operations"] input,
:root[data-theme="dark"] body[data-apms-module="operations"] select,
:root[data-theme="dark"] body[data-apms-module="operations"] textarea { border-color: var(--line); }
:root[data-theme="dark"] body[data-apms-module="operations"] .chip.success { background: #183c30; color: #7fe0b6; }
:root[data-theme="dark"] body[data-apms-module="operations"] .chip.warning { background: #453a16; color: #f6d66a; }
:root[data-theme="dark"] body[data-apms-module="operations"] .chip.danger { background: #482322; color: #ffaaa5; }
:root[data-theme="dark"] body[data-apms-module="operations"] .temporary-password { background: #39271d; color: var(--ink); }
:root[data-theme="dark"] body[data-apms-module="operations"] dialog { background: var(--paper); color: var(--ink); }
:root[data-theme="dark"] body[data-apms-module="operations"] .empty { border-color: var(--line); }

/* Field Assistant */
:root[data-theme="dark"] body[data-apms-module="assistant"] {
  --ink: var(--apms-theme-text);
  --muted: var(--apms-theme-muted);
  --line: var(--apms-theme-line);
  --surface: var(--apms-theme-surface);
  --background: var(--apms-theme-background);
  --orange-dark: #ff7a33;
  --green: #55c992;
  --red: #ff8e88;
  --orange-soft: #492919;
  --green-soft: #183c30;
  --yellow-soft: #453a16;
  --red-soft: #482322;
  background: var(--apms-theme-background);
}

:root[data-theme="dark"] body[data-apms-module="assistant"] .operations-strip,
:root[data-theme="dark"] body[data-apms-module="assistant"] .prompt-button,
:root[data-theme="dark"] body[data-apms-module="assistant"] .assistant-message,
:root[data-theme="dark"] body[data-apms-module="assistant"] .typing,
:root[data-theme="dark"] body[data-apms-module="assistant"] .entity-dialog {
  background: var(--apms-theme-surface);
}

:root[data-theme="dark"] body[data-apms-module="assistant"] .claim-link,
:root[data-theme="dark"] body[data-apms-module="assistant"] .clarification-button,
:root[data-theme="dark"] body[data-apms-module="assistant"] .reference-link,
:root[data-theme="dark"] body[data-apms-module="assistant"] .entity-facts div {
  background: var(--apms-theme-surface-raised);
  color: var(--ink);
}

:root[data-theme="dark"] body[data-apms-module="assistant"] .answer-summary,
:root[data-theme="dark"] body[data-apms-module="assistant"] .reference-link { color: #dce1e6; }
:root[data-theme="dark"] body[data-apms-module="assistant"] .limitations { color: #e8d594; }
:root[data-theme="dark"] body[data-apms-module="assistant"] .composer-shell {
  border-color: var(--apms-theme-line);
  background: rgba(21, 25, 31, 0.97);
}
:root[data-theme="dark"] body[data-apms-module="assistant"] .composer textarea {
  border-color: var(--apms-theme-line);
  background: var(--apms-theme-surface);
  color: var(--ink);
}

/* Knowledge Review */
:root[data-theme="dark"] body[data-apms-module="knowledge"] {
  --white: var(--apms-theme-surface);
  --ink: var(--apms-theme-text);
  --industrial-050: #20262d;
  --industrial-100: var(--apms-theme-background);
  --industrial-200: var(--apms-theme-line);
  --industrial-300: #56606c;
  --industrial-500: #9ea7b2;
  --industrial-600: #b3bbc5;
  --industrial-700: #d0d5db;
  --industrial-800: #e3e7eb;
  --orange-dark: #ff7a33;
  --orange-soft: #492919;
  --yellow-soft: #453a16;
  --green: #55c992;
  --green-soft: #183c30;
  --red: #ff8e88;
  --red-soft: #482322;
  --blue: #72a9d2;
  --blue-soft: #1d3445;
  background: var(--apms-theme-background);
}

:root[data-theme="dark"] body[data-apms-module="knowledge"] .topbar,
:root[data-theme="dark"] body[data-apms-module="knowledge"] .topbar .brand,
:root[data-theme="dark"] body[data-apms-module="knowledge"] .review-action-bar,
:root[data-theme="dark"] body[data-apms-module="knowledge"] .toast { color: #ffffff; }
:root[data-theme="dark"] body[data-apms-module="knowledge"] .brand-mark i { border-color: #ffffff; }
:root[data-theme="dark"] body[data-apms-module="knowledge"] .primary-button { color: #ffffff; }
:root[data-theme="dark"] body[data-apms-module="knowledge"] .workspace-tabs button.active,
:root[data-theme="dark"] body[data-apms-module="knowledge"] .rail-heading h1,
:root[data-theme="dark"] body[data-apms-module="knowledge"] .global-heading h1,
:root[data-theme="dark"] body[data-apms-module="knowledge"] .capture-header h2,
:root[data-theme="dark"] body[data-apms-module="knowledge"] .section-heading h3,
:root[data-theme="dark"] body[data-apms-module="knowledge"] .dialog-heading h3,
:root[data-theme="dark"] body[data-apms-module="knowledge"] .confidence-block strong,
:root[data-theme="dark"] body[data-apms-module="knowledge"] .section-tabs button.active,
:root[data-theme="dark"] body[data-apms-module="knowledge"] .domain-summary strong,
:root[data-theme="dark"] body[data-apms-module="knowledge"] .capture-fact strong,
:root[data-theme="dark"] body[data-apms-module="knowledge"] .next-action strong,
:root[data-theme="dark"] body[data-apms-module="knowledge"] .metric strong { color: var(--ink); }
:root[data-theme="dark"] body[data-apms-module="knowledge"] .section-tabs { background: rgba(37, 43, 51, 0.97); }
:root[data-theme="dark"] body[data-apms-module="knowledge"] .status-chip.pending,
:root[data-theme="dark"] body[data-apms-module="knowledge"] .signal-chip.warning { color: #f6d66a; border-color: #796523; }
:root[data-theme="dark"] body[data-apms-module="knowledge"] .status-chip.approved,
:root[data-theme="dark"] body[data-apms-module="knowledge"] .signal-chip.success { color: #7fe0b6; border-color: #28634d; }
:root[data-theme="dark"] body[data-apms-module="knowledge"] .status-chip.rejected,
:root[data-theme="dark"] body[data-apms-module="knowledge"] .signal-chip.danger { color: #ffaaa5; border-color: #7a3936; }
:root[data-theme="dark"] body[data-apms-module="knowledge"] .domain-filters button.active { border-color: #96502a; }
:root[data-theme="dark"] body[data-apms-module="knowledge"] .danger-button { border-color: #7a3936; }

/* Capture */
:root[data-theme="light"] body[data-apms-module="capture"],
:root[data-theme="light"] body[data-apms-module="capture"].field-mode {
  --light-grey: #e8ebee;
  --light-grey-2: #f6f7f9;
  background: var(--light-grey);
}

:root[data-theme="light"] body[data-apms-module="capture"] .app-shell {
  background: var(--light-grey);
}

:root[data-theme="dark"] body[data-apms-module="capture"] {
  --ink: var(--apms-theme-text);
  --muted: var(--apms-theme-muted);
  --muted-strong: #d3d8de;
  --line: rgba(255, 255, 255, 0.13);
  --line-strong: rgba(255, 255, 255, 0.22);
  --light-grey: var(--apms-theme-background);
  --light-grey-2: #20262d;
  --orange-soft: #492919;
  --yellow-soft: #453a16;
  --green-soft: #183c30;
  --red-soft: #482322;
  --blue-soft: #1d3445;
  --shadow-card: 0 12px 28px rgba(0, 0, 0, 0.24);
  --shadow-tight: 0 2px 10px rgba(0, 0, 0, 0.22);
  background: var(--apms-theme-background);
}

:root[data-theme="dark"] body[data-apms-module="capture"].field-mode { background: var(--apms-theme-background); }
:root[data-theme="dark"] body[data-apms-module="capture"] .system-card,
:root[data-theme="dark"] body[data-apms-module="capture"] .panel-card,
:root[data-theme="dark"] body[data-apms-module="capture"] .detail-body,
:root[data-theme="dark"] body[data-apms-module="capture"] .record,
:root[data-theme="dark"] body[data-apms-module="capture"] .search-box,
:root[data-theme="dark"] body[data-apms-module="capture"] .filter-box,
:root[data-theme="dark"] body[data-apms-module="capture"] .modal-panel,
:root[data-theme="dark"] body[data-apms-module="capture"] .pipeline-card,
:root[data-theme="dark"] body[data-apms-module="capture"] .pipeline-stage {
  background: var(--apms-theme-surface);
  border-color: var(--line);
}

:root[data-theme="dark"] body[data-apms-module="capture"] .system-card,
:root[data-theme="dark"] body[data-apms-module="capture"] .quick-action,
:root[data-theme="dark"] body[data-apms-module="capture"] .quick-action.has-count {
  background: linear-gradient(180deg, var(--apms-theme-surface-raised), var(--apms-theme-surface));
  border-color: var(--line);
}

:root[data-theme="dark"] body[data-apms-module="capture"] .tabs { background: var(--apms-theme-surface); border-color: var(--line); }
:root[data-theme="dark"] body[data-apms-module="capture"] .tab { color: var(--muted); }
:root[data-theme="dark"] body[data-apms-module="capture"] .tab.active { color: #ff8b4d; }
:root[data-theme="dark"] body[data-apms-module="capture"] .ghost-button,
:root[data-theme="dark"] body[data-apms-module="capture"] .secondary-action,
:root[data-theme="dark"] body[data-apms-module="capture"] .remove-file {
  background: var(--apms-theme-surface-raised);
  color: var(--ink);
}
:root[data-theme="dark"] body[data-apms-module="capture"] .remove-file { color: #ff8e88; }
:root[data-theme="dark"] body[data-apms-module="capture"] .progress { background: var(--apms-theme-line); }
:root[data-theme="dark"] body[data-apms-module="capture"] .status-chip.uploaded,
:root[data-theme="dark"] body[data-apms-module="capture"] .status-chip.processing,
:root[data-theme="dark"] body[data-apms-module="capture"] .status-chip.uploading,
:root[data-theme="dark"] body[data-apms-module="capture"] .status-chip.waiting,
:root[data-theme="dark"] body[data-apms-module="capture"] .badge.uploaded,
:root[data-theme="dark"] body[data-apms-module="capture"] .badge.processing,
:root[data-theme="dark"] body[data-apms-module="capture"] .badge.uploading,
:root[data-theme="dark"] body[data-apms-module="capture"] .badge.waiting { color: #f6d66a; }
:root[data-theme="dark"] body[data-apms-module="capture"] .status-chip.completed,
:root[data-theme="dark"] body[data-apms-module="capture"] .status-chip.ok,
:root[data-theme="dark"] body[data-apms-module="capture"] .status-chip.ready,
:root[data-theme="dark"] body[data-apms-module="capture"] .badge.completed,
:root[data-theme="dark"] body[data-apms-module="capture"] .badge.ok,
:root[data-theme="dark"] body[data-apms-module="capture"] .badge.ready { color: #7fe0b6; }
:root[data-theme="dark"] body[data-apms-module="capture"] .status-chip.failed,
:root[data-theme="dark"] body[data-apms-module="capture"] .status-chip.offline,
:root[data-theme="dark"] body[data-apms-module="capture"] .badge.failed,
:root[data-theme="dark"] body[data-apms-module="capture"] .badge.offline { color: #ffaaa5; }
:root[data-theme="dark"] body[data-apms-module="capture"] .modal-panel .section-kicker { color: #ff8b4d; }
:root[data-theme="dark"] body[data-apms-module="capture"] .skeleton { background: var(--apms-theme-surface-raised); }

@media (max-width: 600px) {
  .apms-theme-toggle { width: 44px; height: 44px; }
}

@media (min-width: 900px) {
  :root[data-theme="light"] .apms-global-nav {
    box-shadow: 10px 0 28px rgba(10, 14, 20, 0.08);
  }
}

@media (prefers-reduced-motion: reduce) {
  .apms-theme-toggle { transition: none; }
}
