.theme-toggle {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0;
  color: #353943;
  background: #fff;
  border: 1px solid #daddE3;
  border-radius: 9px;
  cursor: pointer;
}
.theme-toggle:hover { background: #f3f4f6; }
.theme-toggle:focus-visible { outline: 2px solid #b91622; outline-offset: 2px; }
.theme-toggle svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .theme-sun,
[data-theme="dark"] .theme-toggle .theme-moon { display: none; }
[data-theme="dark"] .theme-toggle .theme-sun { display: block; }
.theme-anchor { position: relative; }
.theme-anchor > .theme-toggle { position: absolute; top: 12px; right: 12px; }
body[data-page="login"] #recover + .theme-toggle { position: static; display: grid; margin: 12px auto 0; }
@media print { body[data-page="login"] #recover + .theme-toggle { display: none; } }
@media (max-width: 400px) {
  .theme-anchor .logo { max-width: calc(100% - 64px); }
  .topbar > .row { flex-wrap: wrap; justify-content: flex-end; }
  .topbar .theme-toggle { width: 36px; height: 36px; }
}
@media print { .theme-toggle { display: none; } }

@media screen {
  html[data-theme="dark"] {
    color-scheme: dark;
    --ink: #f0f1f5;
    --muted: #b8bcc7;
    --line: #3b3e48;
    --bg: #15161b;
    --theme-surface: #202228;
    --theme-raised: #2b2e36;
    --theme-accent: #ff9ba2;
    --theme-red: #3c242b;
    --theme-green: #1b382e;
    --theme-blue: #24344e;
    --theme-amber: #3c301f;
  }
  [data-theme="dark"] body { color: var(--ink); background: var(--bg); }
  [data-theme="dark"] .theme-anchor,
  [data-theme="dark"] :is(.topbar,.metric,.panel,.stage-tabs,.stage-tab,.media-card,.global-sector-nav,.section-buttons,dialog) {
    background: var(--theme-surface);
    border-color: var(--line);
  }
  [data-theme="dark"] .theme-toggle,
  [data-theme="dark"] .btn:not(.primary,.dark,.ghost),
  [data-theme="dark"] .icon-btn,
  [data-theme="dark"] :is(input,select,textarea) {
    background: var(--theme-raised);
    color: var(--ink);
    border-color: #626775;
  }
  [data-theme="dark"] :is(.theme-toggle,.btn:not(.primary,.dark,.ghost),.icon-btn):hover { background: #383c46; }
  [data-theme="dark"] .theme-toggle:focus-visible { outline-color: var(--theme-accent); }
  [data-theme="dark"] .theme-anchor .logo { background: #fff; border-radius: 6px; }
  [data-theme="dark"] :is(.theme-anchor p,.theme-anchor small,.theme-anchor label,.muted,.hint,.panel-head p,.page-head p,.cell-sub,.metric-head,.metric small,.stage-tab,.summary-line,.summary-total small,.timeline-item span,.execute-row small,.footer-note,.workflow-item p,.help-card p,.help-card li,.finance-muted,.finance-section p,.finance-table small,.sector-client small) {
    color: var(--muted);
  }
  [data-theme="dark"] :is(.topbar .path b,.dashboard-title,.client-title,.summary-line b,.summary-total strong,.timeline-item b,.execute-row b,.workflow-highlight .panel-head h2,.workflow-highlight .workflow-item b,.financial-box .summary-line b, label) { color: var(--ink); }
  [data-theme="dark"] :is(.dashboard-head p,.workflow-highlight .panel-head p,.workflow-highlight .workflow-item p,.financial-box .summary-line,input::placeholder,textarea::placeholder) { color: var(--muted); }
  [data-theme="dark"] :is(.theme-anchor a,.theme-anchor .link,.theme-anchor .message,.eyebrow,.linkbtn,.client-name,.order-number,.required,.btn.danger,.finance-negative,.finance-editor-error,.financial-box .total-line) { color: var(--theme-accent); }
  [data-theme="dark"] :is(.theme-anchor .message.ok,.save-status,.finance-positive) { color: #8ad7b5; }
  [data-theme="dark"] :is(.save-status,.panel-head,.execute-row,.finance-audit p) { border-color: var(--line); }
  [data-theme="dark"] :is(th,td):not(.paper *) { border-color: var(--line); }
  [data-theme="dark"] th:not(.paper *, .items-table *) { background: var(--theme-raised); color: var(--muted); }
  [data-theme="dark"] :is(.orders-table tbody tr:hover,.items-table tbody tr:nth-child(odd),.items-table tbody tr:nth-child(even),.media-preview,.paper-view,.theme-anchor .notice) { background: var(--theme-raised); color: var(--ink); }
  [data-theme="dark"] :is(.tag,.tag.dark,.metric .icon-box) { background: var(--theme-raised); color: var(--muted); }
  [data-theme="dark"] :is(.tag.red,.stage-tab.active,.save-status.error,.empty .empty-icon,.step-circle,.file-drop:focus,.file-drop.dragging,.callout.red,.approval-card.red,.fixed-error,.items-table .line-total,.metric:nth-child(3) .icon-box) { background: var(--theme-red); color: var(--theme-accent); border-color: #674049; }
  [data-theme="dark"] :is(.tag.green,.callout.green,.approval-card.green,.metric:nth-child(4) .icon-box) { background: var(--theme-green); color: #a4dfc3; border-color: #3a6655; }
  [data-theme="dark"] :is(.tag.amber,.callout:not(.red,.green,.blue),.approval-card:not(.red,.green),.role-notice,.metric:nth-child(2) .icon-box) { background: var(--theme-amber); color: #f5cd89; border-color: #695638; }
  [data-theme="dark"] :is(.tag.blue,.callout.blue,.chip,.items-table .subselect,.financial-box,.workflow-highlight .panel-head,.sector-client) { background: var(--theme-blue); color: #bed3ff; border-color: #4a6083; }
  [data-theme="dark"] :is(.chip:hover,.sector-client:hover) { background: #30466a; }
  [data-theme="dark"] .file-drop { background: var(--theme-surface); border-color: #626775; }
  [data-theme="dark"] .finance-bar:not(.income) { background: #83a1d0; }
  [data-theme="dark"] .paper { color-scheme: light; }
}
