.theme-toggle-global {
  width: 42px;
  min-width: 42px;
  height: 42px;
  padding: 0 !important;
  display: inline-grid;
  place-items: center;
  font-size: 23px;
  line-height: 1;
}

.theme-toggle-floating {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  border: 1px solid var(--line, #d8dfdb);
  border-radius: 8px;
  background: var(--panel, #fff);
  color: var(--text, #18201d);
  box-shadow: 0 8px 24px rgba(23, 38, 31, .14);
}

html[data-theme="dark"] {
  --bg: #121513;
  --panel: #1b201d;
  --panel-soft: #222824;
  --text: #e7ece9;
  --muted: #9da9a2;
  --line: #3a443e;
  --line-strong: #4c5851;
  --green: #218365;
  --green-soft: #20372e;
  --olive-soft: #342f1e;
  --olive-line: #6d6031;
  --red: #e1877d;
  --red-soft: #38201e;
  --shadow: 0 18px 44px rgba(0, 0, 0, .28);
  color-scheme: dark;
  background: #121513;
}
html[data-theme="dark"] body,
html[data-theme="dark"] #root,
html[data-theme="dark"] .app-shell,
html[data-theme="dark"] .workspace,
html[data-theme="dark"] .monitor-main {
  background: #121513;
  color: var(--text);
}
html[data-theme="dark"] .crm-header,
html[data-theme="dark"] .admin-tabs,
html[data-theme="dark"] .metric,
html[data-theme="dark"] .requests-panel,
html[data-theme="dark"] .details-panel,
html[data-theme="dark"] .directory-panel,
html[data-theme="dark"] .toolbar-card,
html[data-theme="dark"] .login-card,
html[data-theme="dark"] .modal-shell,
html[data-theme="dark"] .monitor-header,
html[data-theme="dark"] .status-panel,
html[data-theme="dark"] .metrics-section,
html[data-theme="dark"] .delivery-section {
  background: var(--panel);
  border-color: var(--line);
  color: var(--text);
}
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] .field-stack input,
html[data-theme="dark"] .field-stack select,
html[data-theme="dark"] .field-stack textarea,
html[data-theme="dark"] .field-inline select,
html[data-theme="dark"] .quick-select {
  background: #171b19 !important;
  border-color: var(--line) !important;
  color: var(--text) !important;
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: #75827b; }
html[data-theme="dark"] .ghost-button,
html[data-theme="dark"] .nav-item,
html[data-theme="dark"] .button,
html[data-theme="dark"] .period,
html[data-theme="dark"] .page-button {
  background: #222824;
  border-color: var(--line);
  color: var(--text);
}
html[data-theme="dark"] .ghost-button:hover,
html[data-theme="dark"] .button:hover,
html[data-theme="dark"] .period:hover,
html[data-theme="dark"] .page-button:hover { background: #2a312d; }
html[data-theme="dark"] .nav-item:hover,
html[data-theme="dark"] .nav-item.active,
html[data-theme="dark"] .primary-button,
html[data-theme="dark"] .page-button.active { background: var(--green); color: #fff; }
html[data-theme="dark"] .order-form-section,
html[data-theme="dark"] .detail-card,
html[data-theme="dark"] .notes-panel,
html[data-theme="dark"] .permission-card,
html[data-theme="dark"] .permission-group-card,
html[data-theme="dark"] .vin-lookup-hint {
  background: var(--panel-soft);
  border-color: var(--line);
}
html[data-theme="dark"] table,
html[data-theme="dark"] .autocomplete-dropdown { background: #191e1b; color: var(--text); }
html[data-theme="dark"] th { background: #242a27; color: var(--muted); }
html[data-theme="dark"] th,
html[data-theme="dark"] td,
html[data-theme="dark"] .table-wrap { border-color: #343c37; }
html[data-theme="dark"] tbody tr:hover { background: #222a26; }
html[data-theme="dark"] tbody tr.selected { background: #263b33; }
html[data-theme="dark"] .autocomplete-option { color: var(--text); }
html[data-theme="dark"] .autocomplete-option:hover { background: #29312d; }
html[data-theme="dark"] .segmented-control { background: #252c28; }
html[data-theme="dark"] .segment { color: var(--muted); }
html[data-theme="dark"] .segment.active { background: #35403a; color: #9de0c6; }
html[data-theme="dark"] .metric.accent { background: #342f1e; border-color: #6d6031; }
html[data-theme="dark"] .mini-tag,
html[data-theme="dark"] .status-neutral { background: #303733; color: #d0d8d3; }
html[data-theme="dark"] .status-payment { background: #493b1e; color: #f0cf7b; }
html[data-theme="dark"] .status-work,
html[data-theme="dark"] .alert.success { background: #20372e; color: #9bd8bd; border-color: #3f725f; }
html[data-theme="dark"] .status-danger,
html[data-theme="dark"] .alert.error { background: #38201e; color: #f1b5ae; border-color: #77443e; }
html[data-theme="dark"] .modal-overlay { background: rgba(5, 8, 6, .78); }
html[data-theme="dark"] .loading-overlay { background: rgba(12, 15, 13, .78); }
html[data-theme="dark"] .monitor-header { border-bottom-color: var(--line); }
html[data-theme="dark"] .status-details div,
html[data-theme="dark"] .delivery-row>div { background: var(--panel-soft); border-color: var(--line); }
html[data-theme="dark"] .checked-at,
html[data-theme="dark"] .eyebrow,
html[data-theme="dark"] .metric span,
html[data-theme="dark"] .field-stack span,
html[data-theme="dark"] .detail-card span { color: var(--muted); }

@media (max-width: 920px) {
  .theme-toggle-global { width: 40px; min-width: 40px; height: 40px; }
  .theme-toggle-floating { top: 12px; right: 12px; }
}

/* Unified header for CRM and monitoring. */
.crm-header.global-site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "brand navigation theme logout";
  gap: 16px;
  min-height: 68px;
  margin: -24px -24px 22px;
  padding: 10px 24px;
  border-width: 0 0 1px;
  border-radius: 0;
  box-shadow: 0 5px 18px rgba(23, 38, 31, .07);
}
.crm-header.global-site-header>.brand { grid-area: brand; min-width: max-content; }
.crm-header.global-site-header>.header-tabs {
  grid-area: navigation;
  min-width: 0;
  flex-wrap: nowrap;
  overflow-x: auto;
  justify-content: center;
  scrollbar-width: none;
}
.crm-header.global-site-header>.header-tabs::-webkit-scrollbar { display: none; }
.crm-header.global-site-header>.theme-toggle-global { grid-area: theme; align-self: center; }
.crm-header.global-site-header>.ghost-button:last-child { grid-area: logout; align-self: center; white-space: nowrap; }

.monitor-header.global-site-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "brand navigation tools";
  gap: 18px;
  min-height: 68px;
  padding: 10px clamp(16px, 3vw, 40px);
}
.monitor-header.global-site-header>.brand { grid-area: brand; min-width: max-content; }
.monitor-header.global-site-header>.global-header-nav { grid-area: navigation; }
.monitor-header.global-site-header>.header-actions { grid-area: tools; flex-wrap: nowrap; }
.global-header-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.global-header-nav::-webkit-scrollbar { display: none; }
.global-header-nav a,.global-header-nav span {
  min-height: 40px;
  padding: 9px 13px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.global-header-nav a:hover,.global-header-nav .active { background: var(--green); border-color: var(--green); color: #fff; }

@media (max-width: 1240px) {
  .crm-header.global-site-header {
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas: "brand theme logout" "navigation navigation navigation";
    gap: 8px 10px;
  }
  .crm-header.global-site-header>.header-tabs { justify-content: flex-start; border-top: 1px solid var(--line); padding-top: 8px; }
  .monitor-header.global-site-header {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "brand tools" "navigation navigation";
    gap: 8px 12px;
  }
  .monitor-header.global-site-header>.global-header-nav { justify-content: flex-start; border-top: 1px solid var(--line); padding-top: 8px; }
}
@media (max-width: 920px) {
  .crm-header.global-site-header { margin: -18px -18px 18px; padding: 9px 18px; }
  .crm-header.global-site-header>.brand .brand-mark { width: 40px; height: 40px; }
  .crm-header.global-site-header>.header-tabs .nav-item.compact { min-width: auto; padding: 9px 11px; }
  .monitor-header.global-site-header>.header-actions .checked-at { display: none; }
  .monitor-header.global-site-header>.header-actions .button:not(.theme-toggle-global) { padding: 9px 11px; }
}
@media (max-width: 560px) {
  .crm-header.global-site-header { padding: 9px 12px; margin-left: -18px; margin-right: -18px; }
  .crm-header.global-site-header>.brand span { display: none; }
  .crm-header.global-site-header>.ghost-button:last-child { padding: 9px 10px; }
  .monitor-header.global-site-header>.brand small { display: none; }
  .monitor-header.global-site-header>.header-actions #refresh-button { display: none; }
  .global-header-nav a,.global-header-nav span { padding: 8px 10px; min-height: 38px; }
}
