/* UX-001 — Dark/Light Theme (data-color-scheme on html)
   Light: WCAG 2.x AA — normal text ≥4.5:1, large text ≥3:1 */

html[data-color-scheme='light'] {
  --t9-theme-bg: #f3f5f8;
  --t9-theme-surface: #ffffff;
  --t9-theme-text: #1a2332;
  --t9-theme-muted: #475569;
  --t9-theme-border: #c8d0da;

  /* T9 tokens — remap dark defaults so t9-skin/dashboard inherit readable colors */
  --t9-bg-0: #f3f5f8;
  --t9-bg-1: #ffffff;
  --t9-bg-2: #eef1f5;
  --t9-bg-3: #e2e7ee;
  --t9-text: #1a2332;
  --t9-text-muted: #475569;
  --t9-text-dim: #5c6778;
  --t9-cyan: #006e8c;
  --t9-cyan-soft: #087ea4;
  --t9-cyan-deep: #005a70;
  --t9-line: rgba(0, 90, 112, 0.16);
  --t9-line-strong: rgba(0, 90, 112, 0.32);
  --t9-glow: 0 0 0 1px rgba(0, 110, 140, 0.22);
  --t9-glow-soft: 0 0 0 1px rgba(0, 110, 140, 0.14);
  --t9-alert: #c41e3a;
  --t9-warn: #9a5f00;
  --t9-ok: #0d7a52;

  /* Nautilus classic surfaces */
  --nautilus-surface: #ffffff;
  --nautilus-surface-2: #f3f5f8;
  --nautilus-border: #c8d0da;
  --nautilus-text: #1a2332;
  --nautilus-text-muted: #475569;
  --nautilus-accent: #005a70;
  --nautilus-accent-hover: #004555;

  /* Mobile bottom nav */
  --t9-bottom-nav-bg: #ffffff;
  --t9-bottom-nav-border: #c8d0da;
  --t9-bottom-nav-muted: #475569;
  --t9-bottom-nav-text: #1a2332;

  /* Cockpit / HV fallbacks */
  --text-primary: #1a2332;
  --text-muted: #475569;
  --bg-card: #ffffff;
  --border-card: #c8d0da;
  --accent-cyan: #006e8c;

  /* Legacy NBE-Surface-Aliase — Light-Override (Dark-Default in t9-tokens.css) */
  --s1: #f3f5f8;
  --s2: #ffffff;
  --s3: #e7ecf2;
  --bd: #c8d0da;
  --bdhi: #aab4c0;
}

html[data-color-scheme='dark'],
html:not([data-color-scheme]) {
  --t9-theme-bg: #0b1220;
  --t9-theme-surface: #111a2e;
  --t9-theme-text: #e6edf7;
  --t9-theme-muted: #94a3b8;
  --t9-theme-border: #1f2a44;
}

html[data-color-scheme='light'] body.theme-standard {
  background: var(--t9-theme-bg);
  color: var(--t9-theme-text);
}

html[data-color-scheme='light'] .nautilus-body {
  background: var(--t9-theme-bg);
  color: var(--t9-theme-text);
}

/* T9/Owner: flat light page — no dark neon wash */
html[data-color-scheme='light'][data-theme='t9'] body.theme-standard,
html[data-color-scheme='light'][data-theme='owner'] body.theme-standard {
  background: var(--t9-bg-0);
}

html[data-color-scheme='light'][data-theme='t9'] .nautilus-body,
html[data-color-scheme='light'][data-theme='owner'] .nautilus-body {
  color: var(--t9-text);
}

/* Dashboard header: text-shadow was for dark glass only */
html[data-color-scheme='light'][data-theme='t9'] .dashboard-nbe-header .logo,
html[data-color-scheme='light'][data-theme='owner'] .dashboard-nbe-header .logo {
  text-shadow: none;
}

/* Status / CTA: hardcoded neon pinks — replace with AA on light surfaces */
html[data-color-scheme='light'][data-theme='t9'] .nautilus-dashboard .dashboard-team-cta--wa,
html[data-color-scheme='light'][data-theme='owner'] .nautilus-dashboard .dashboard-team-cta--wa {
  background: rgba(22, 163, 74, 0.1) !important;
  border-color: rgba(22, 163, 74, 0.45) !important;
  color: #166534 !important;
}

html[data-color-scheme='light'][data-theme='t9'] .nautilus-dashboard .dashboard-com-radio-baustein__btn--com,
html[data-color-scheme='light'][data-theme='owner'] .nautilus-dashboard .dashboard-com-radio-baustein__btn--com {
  border-color: #0d7a6e !important;
  color: #0d7a6e !important;
}

html[data-color-scheme='light'][data-theme='t9'] .nautilus-dashboard .com-feed-flag,
html[data-color-scheme='light'][data-theme='owner'] .nautilus-dashboard .com-feed-flag,
html[data-color-scheme='light'][data-theme='t9'] .nautilus-dashboard .com-detail-flag,
html[data-color-scheme='light'][data-theme='owner'] .nautilus-dashboard .com-detail-flag {
  background: rgba(196, 30, 58, 0.1) !important;
  color: #9f1239 !important;
  border-color: rgba(196, 30, 58, 0.35) !important;
}

html[data-color-scheme='light'][data-theme='t9'] .nautilus-dashboard .com-btn-red,
html[data-color-scheme='light'][data-theme='owner'] .nautilus-dashboard .com-btn-red,
html[data-color-scheme='light'][data-theme='t9'] .nautilus-dashboard .com-status-offen,
html[data-color-scheme='light'][data-theme='owner'] .nautilus-dashboard .com-status-offen,
html[data-color-scheme='light'][data-theme='t9'] .nautilus-dashboard .com-slot-status-abgelehnt,
html[data-color-scheme='light'][data-theme='owner'] .nautilus-dashboard .com-slot-status-abgelehnt {
  color: #9f1239 !important;
}

html[data-color-scheme='light'][data-theme='t9'] .nautilus-dashboard .com-status-eskaliert,
html[data-color-scheme='light'][data-theme='owner'] .nautilus-dashboard .com-status-eskaliert {
  color: #9a5f00 !important;
}

html[data-color-scheme='light'][data-theme='t9'] .nautilus-dashboard .com-status-abgenommen,
html[data-color-scheme='light'][data-theme='owner'] .nautilus-dashboard .com-status-abgenommen {
  color: var(--t9-cyan-deep) !important;
}

html[data-color-scheme='light'][data-theme='t9'] .nautilus-dashboard .com-panel,
html[data-color-scheme='light'][data-theme='owner'] .nautilus-dashboard .com-panel {
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.12) !important;
}

html[data-color-scheme='light'][data-theme='t9'] .nautilus-dashboard #com-detail-panel,
html[data-color-scheme='light'][data-theme='owner'] .nautilus-dashboard #com-detail-panel {
  box-shadow: -8px 0 24px rgba(15, 23, 42, 0.1) !important;
}

/* Dashboard: cockpit-default.ejs always has .nautilus-dashboard--dark (inline !important).
   In light color-scheme, remap to readable light surfaces (beats inline via html[...] specificity). */
html[data-color-scheme='light'] .nautilus-dashboard--dark {
  --nautilus-surface: #ffffff;
  --nautilus-surface-2: #eef1f5;
  --nautilus-text: #1a2332;
  --nautilus-text-muted: #475569;
  --nautilus-border: #c8d0da;
}

html[data-color-scheme='light'] .nautilus-dashboard--dark .tile.glass-effect,
html[data-color-scheme='light'] .nautilus-dashboard--dark .dashboard-tile,
html[data-color-scheme='light'] .nautilus-dashboard--dark .dashboard-widget,
html[data-color-scheme='light'] .nautilus-dashboard--dark .dashboard-report-bar,
html[data-color-scheme='light'] .nautilus-dashboard--dark .com-panel.nbl-card,
html[data-color-scheme='light'] .nautilus-dashboard--dark .nbl-tile--finance {
  background: var(--nautilus-surface) !important;
  color: var(--nautilus-text) !important;
  border-color: var(--nautilus-border) !important;
}

html[data-color-scheme='light'] .nautilus-dashboard--dark .dashboard-tile {
  color: var(--nautilus-text) !important;
}

html[data-color-scheme='light'] .nautilus-dashboard--dark .dashboard-tile:hover {
  box-shadow: 0 4px 12px rgba(0, 90, 112, 0.12) !important;
  border-color: var(--nautilus-accent, #005a70) !important;
}

html[data-color-scheme='light'] .nautilus-dashboard--dark .c-level-table th {
  background: var(--nautilus-surface-2) !important;
  color: var(--nautilus-text-muted) !important;
  border-color: var(--nautilus-border) !important;
}

html[data-color-scheme='light'] .nautilus-dashboard--dark .c-level-table td {
  border-color: var(--nautilus-border) !important;
  color: var(--nautilus-text) !important;
}

html[data-color-scheme='light'] .nautilus-dashboard--dark .c-level-table .cell-name {
  color: var(--nautilus-text) !important;
}

html[data-color-scheme='light'] .nautilus-dashboard--dark .c-level-table tr:hover td {
  background: var(--nautilus-surface-2) !important;
  color: var(--nautilus-text) !important;
}

html[data-color-scheme='light'] .nautilus-dashboard--dark .c-level-table tr:hover td.cell-name {
  color: var(--nautilus-text) !important;
}

html[data-color-scheme='light'] .nautilus-dashboard--dark .nautilus-data-warning {
  background: #fff4ce !important;
  color: #92400e !important;
  border-color: #d97706 !important;
}

html[data-color-scheme='light'] .nautilus-dashboard--dark .dashboard-note-item .note-item-content {
  color: var(--nautilus-text) !important;
}

html[data-color-scheme='light'] .nautilus-dashboard--dark .com-panel {
  --card-bg: #ffffff;
  background: var(--nautilus-surface) !important;
  border-color: var(--nautilus-border) !important;
}

html[data-color-scheme='light'] .nautilus-dashboard--dark .com-mangel-item {
  background: var(--nautilus-surface-2) !important;
  border-color: var(--nautilus-border) !important;
  color: var(--nautilus-text) !important;
}

html[data-color-scheme='light'] .nautilus-dashboard--dark .com-inbox-item {
  color: var(--nautilus-text) !important;
}

html[data-color-scheme='light'] .nautilus-dashboard--dark .tile.glass-effect {
  background: var(--nautilus-surface) !important;
  border-color: var(--nautilus-border) !important;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08) !important;
}

html[data-color-scheme='light'] .nautilus-dashboard--dark .dashboard-nbe-header,
html[data-color-scheme='light'] .nautilus-dashboard--dark .dashboard-title {
  color: var(--nautilus-text) !important;
}

html[data-color-scheme='light'] .nautilus-dashboard--dark .dashboard-intro,
html[data-color-scheme='light'] .nautilus-dashboard--dark .dashboard-section-title,
html[data-color-scheme='light'] .nautilus-dashboard--dark .dashboard-nbe-pilot {
  color: var(--nautilus-text-muted) !important;
}

html[data-color-scheme='light'] .nautilus-dashboard--dark .dashboard-nbe-time {
  color: var(--nautilus-accent, #005a70) !important;
}

html[data-color-scheme='light'] .nautilus-dashboard--dark .quickaccess-badge {
  background: rgba(154, 95, 0, 0.12);
  color: #9a5f00;
}

/* Forensik-Kachel: bewusst dunkel, aber mit AA-Text */
html[data-color-scheme='light'] .t9-forensik-cta a.dashboard-tile,
html[data-color-scheme='light'] .t9-forensik-cta .dashboard-tile {
  background: linear-gradient(145deg, #0a3d4a, #0f5668) !important;
  border: 1px solid #006e8c !important;
  color: #f0f9ff !important;
}

/* Focus ring: visible on light chrome (not color-only affordance) */
html[data-color-scheme='light'] button.t9-topbar-icon-btn:focus-visible,
html[data-color-scheme='light'] .t9-theme-toggle:focus-visible,
html[data-color-scheme='light'] .t9-bottom-nav__item:focus-visible,
html[data-color-scheme='light'] a:focus-visible,
html[data-color-scheme='light'] button:focus-visible {
  outline: 2px solid var(--nautilus-accent, #005a70);
  outline-offset: 2px;
}

/* Topbar: gemeinsamer Rahmen/Höhe (Theme-Umschalter, WA-Tacho, SYS Check, …) */
/* box model & radius live here — Modul-CSS nur noch Farbzustände / Typo, keine Konflikt-Overrides */
.t9-topbar-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-sizing: border-box;
  min-width: 40px;
  min-height: 40px;
  padding: 6px 10px;
  margin: 0;
  border: 1px solid var(--t9-theme-border, #1f2a44);
  border-radius: 8px;
  background: var(--t9-theme-surface, #111a2e);
  color: var(--t9-theme-text, #e6edf7);
  overflow: visible;
}

button.t9-topbar-icon-btn {
  /* Native <button>-Chrome (incl. Safari): appearance:none zurücksetzt teils Layout —
     volles Box-Model hier wiederholen wie bei .t9-topbar-icon-btn oben */
  font-family: inherit;
  cursor: pointer;
  margin: 0;
  padding: 6px 10px;
  border: 1px solid var(--t9-theme-border, #1f2a44);
  border-radius: 8px;
  background: var(--t9-theme-surface, #111a2e);
  color: var(--t9-theme-text, #e6edf7);
  overflow: visible;
  -webkit-appearance: none;
  appearance: none;
}

button.t9-topbar-icon-btn:hover,
button.t9-topbar-icon-btn:focus-visible {
  outline: 2px solid var(--nautilus-accent, #0078d4);
  outline-offset: 2px;
}

.t9-theme-toggle {
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

/* PWA-002 install banner (Nautilus) */
#nautilus-pwa-banner {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  z-index: 9998;
  max-width: 28rem;
  margin: 0 auto;
  background: var(--t9-theme-surface, #1e293b);
  color: var(--t9-theme-text, #e2e8f0);
  padding: 12px 14px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  border: 1px solid var(--t9-theme-border, #334155);
}

#nautilus-pwa-banner .nautilus-pwa-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

#nautilus-pwa-banner button {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
}

#nautilus-pwa-banner .nautilus-pwa-install {
  background: var(--nautilus-accent, #0078d4);
  color: #fff;
}

#nautilus-pwa-banner .nautilus-pwa-dismiss {
  background: transparent;
  color: inherit;
  border: 1px solid var(--t9-theme-border, #475569);
}

@media (min-width: 769px) {
  #nautilus-pwa-banner {
    bottom: 16px;
  }
}

/* ──────────────────────────────────────────────────────────────────────────
   Modul-Kacheln (Finanz / Settings / Stats / B2440 …) — Theme-Konsistenz
   Viele Modul-Views definieren .fin-card & Co. in eigenen <style>-Blöcken mit
   hellen Hardcodes (#fff, #eee, color:#666) und var(--nautilus-accent) als
   Textfarbe (auf dunklem Grund schlecht lesbar). Diese Regeln greifen über
   höhere Spezifität (html[data-theme] …) ohne !important und ohne pro-View-Edits.
   Light/Dark schalten automatisch über die --t9-Tokens. ────────────────────── */
html[data-theme='t9'] :is(.fin-card,.section-card,.kpi-card,.meine-daten-card,.pw-card,.notif-card,.b2440-card,.ki-fin-box),
html[data-theme='owner'] :is(.fin-card,.section-card,.kpi-card,.meine-daten-card,.pw-card,.notif-card,.b2440-card,.ki-fin-box) {
  background: var(--t9-bg-1);
  border: 1px solid var(--t9-line);
  color: var(--t9-text);
}
html[data-theme='t9'] :is(.fin-card,.section-card,.kpi-card,.b2440-card,.ki-fin-box) h3,
html[data-theme='owner'] :is(.fin-card,.section-card,.kpi-card,.b2440-card,.ki-fin-box) h3 {
  color: var(--t9-cyan);
}
html[data-theme='t9'] .kpi-val,
html[data-theme='owner'] .kpi-val { color: var(--t9-cyan); }
html[data-theme='t9'] .kpi-lbl,
html[data-theme='owner'] .kpi-lbl { color: var(--t9-text-muted); }
html[data-theme='t9'] :is(.fin-card,.section-card,.kpi-card,.meine-daten-card,.pw-card,.notif-card,.b2440-card,.ki-fin-box) label,
html[data-theme='owner'] :is(.fin-card,.section-card,.kpi-card,.meine-daten-card,.pw-card,.notif-card,.b2440-card,.ki-fin-box) label {
  color: var(--t9-text-muted);
}
html[data-theme='t9'] :is(.fin-card,.section-card,.meine-daten-card,.pw-card,.notif-card,.b2440-card) :is(input,select,textarea),
html[data-theme='owner'] :is(.fin-card,.section-card,.meine-daten-card,.pw-card,.notif-card,.b2440-card) :is(input,select,textarea) {
  background: var(--t9-bg-2);
  color: var(--t9-text);
  border-color: var(--t9-line-strong);
}
/* Finanz-Tabellen */
html[data-theme='t9'] .fin-table th,
html[data-theme='owner'] .fin-table th {
  background: var(--t9-bg-3);
  color: var(--t9-text-muted);
}
html[data-theme='t9'] .fin-table td,
html[data-theme='owner'] .fin-table td {
  border-bottom-color: var(--t9-line);
  color: var(--t9-text);
}
html[data-theme='t9'] .mini-table th,
html[data-theme='owner'] .mini-table th {
  background: rgba(92, 228, 255, 0.10);
  color: var(--t9-cyan);
}
html[data-theme='t9'] .mini-table td,
html[data-theme='owner'] .mini-table td {
  border-bottom-color: var(--t9-line);
  color: var(--t9-text);
}
/* In Light-Scheme bleiben die Finanz-Header-Zellen petrol mit hellem Text */
html[data-color-scheme='light'][data-theme='t9'] .mini-table th,
html[data-color-scheme='light'][data-theme='owner'] .mini-table th {
  background: rgba(0, 110, 140, 0.10);
  color: var(--t9-cyan-deep);
}

/* Modul-Seitentitel: viele Views setzen inline <h1 style="color:var(--nautilus-accent)">.
   --nautilus-accent ist #005a70 (für weiße Button-/Header-Schrift gedacht) und als
   Textfarbe auf dunklem Seitenhintergrund schlecht lesbar (~2.3:1). H1 nutzt die
   Variable hier ausschließlich als Textfarbe → gezielt auf den lesbaren Cyan-Token. */
html[data-theme='t9'] h1[style*='nautilus-accent'],
html[data-theme='owner'] h1[style*='nautilus-accent'] {
  color: var(--t9-cyan) !important;
}
