/* Dark mode for the whole portal (management + branches). Activated by <html data-theme="dark">. */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141414;
  --card: #1f1f1f;
  --card-2: #262626;
  --border: #353535;
  --text: #ececea;
  --muted: #a3a3a0;
  --primary: #e6e6e3;
  --primary-600: #ffffff;
  --primary-50: #2c2c2c;
  --side-1: #0d0d0d;
  --side-2: #050505;
  --green: #4ade80;
  --green-50: #12301d;
  --red: #f87171;
  --red-50: #3a1615;
  --amber: #fbbf24;
  --amber-50: #3a2a0c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .35);
}
html[data-theme="dark"] body { background: var(--bg); color: var(--text); }
html[data-theme="dark"] a { color: var(--text); text-decoration-color: #6b6b68; }

/* Surfaces that were hard-coded white */
html[data-theme="dark"] .brand,
html[data-theme="dark"] .login form,
html[data-theme="dark"] input, html[data-theme="dark"] select, html[data-theme="dark"] textarea,
html[data-theme="dark"] .btn, html[data-theme="dark"] .pills button,
html[data-theme="dark"] .ms-box, html[data-theme="dark"] .pk-trigger, html[data-theme="dark"] .pk-check,
html[data-theme="dark"] .pk-add, html[data-theme="dark"] .search-box, html[data-theme="dark"] .composer,
html[data-theme="dark"] .msg.theirs, html[data-theme="dark"] .msg-day span, html[data-theme="dark"] .chat-pop,
html[data-theme="dark"] .msg-file:hover, html[data-theme="dark"] .bell {
  background: var(--card); color: var(--text); border-color: var(--border);
}
html[data-theme="dark"] [class*="-menu"], html[data-theme="dark"] .pk-panel, html[data-theme="dark"] .ms-list { background: var(--card); }
html[data-theme="dark"] .brand .logo { filter: invert(1) brightness(1.1); }
html[data-theme="dark"] .login .brand { background: transparent; }
html[data-theme="dark"] .field > span { color: var(--muted); }
html[data-theme="dark"] input::placeholder, html[data-theme="dark"] textarea::placeholder { color: #77777a; }
html[data-theme="dark"] input:focus, html[data-theme="dark"] select:focus, html[data-theme="dark"] textarea:focus,
html[data-theme="dark"] .ms-box:focus-within, html[data-theme="dark"] .search-box:focus-within, html[data-theme="dark"] .pk.open .pk-trigger {
  border-color: #9a9a96; box-shadow: 0 0 0 3px rgba(255, 255, 255, .1);
}

/* Buttons */
html[data-theme="dark"] .btn-primary, html[data-theme="dark"] .pills button.active { background: #ececea; border-color: #ececea; color: #111; }
html[data-theme="dark"] .btn-primary:hover { background: #fff; }
html[data-theme="dark"] .btn-success { background: #15803d; border-color: #15803d; color: #fff; }
html[data-theme="dark"] .btn-danger { background: #b42318; border-color: #b42318; color: #fff; }
html[data-theme="dark"] .btn-ghost { background: transparent; }

/* Sidebar */
html[data-theme="dark"] .nav a.active, html[data-theme="dark"] .side-foot a.active { background: #2a2a2a; color: #fff; }
html[data-theme="dark"] .stat.hero { background: linear-gradient(135deg, #2b2b2b, #1a1a1a); }

/* Tables, lists, chat */
html[data-theme="dark"] .tbl td { border-bottom-color: #2c2c2c; }
html[data-theme="dark"] .tbl tr:hover td { background: #242424; }
html[data-theme="dark"] .pk-opt { border-bottom-color: #2c2c2c; }
html[data-theme="dark"] .pk-opt.sel { background: #2a2a2a; }
html[data-theme="dark"] .chat-item { border-bottom-color: #2c2c2c; }
html[data-theme="dark"] .chat-msgs { background: #181818; }
html[data-theme="dark"] .msg.mine { background: #333331; }
html[data-theme="dark"] .msg-file { background: rgba(255, 255, 255, .05); }
html[data-theme="dark"] .msg-system { background: #2a2a2a; }
html[data-theme="dark"] .msg-day span { color: var(--muted); }
html[data-theme="dark"] .gallery figure, html[data-theme="dark"] .map, html[data-theme="dark"] .msg-imgs img { background: #2a2a2a; }

/* Badges & alerts */
html[data-theme="dark"] .badge-pending { border-color: #5c4513; }
html[data-theme="dark"] .badge-approved { border-color: #1f5132; }
html[data-theme="dark"] .badge-rejected { border-color: #5c2420; }
html[data-theme="dark"] .badge-cancelled, html[data-theme="dark"] .badge-muted { background: #2a2a2a; border-color: #3a3a3a; }
html[data-theme="dark"] .badge-blue { border-color: #3a3a3a; }
html[data-theme="dark"] .badge-deferred { background: #23264a; color: #b4b8f5; border-color: #33376a; }
html[data-theme="dark"] .alert-info { color: #d4d4d1; }
html[data-theme="dark"] .alert-warn { color: #fcd38a; }
html[data-theme="dark"] .locked-banner { border-color: #1f5132; }
html[data-theme="dark"] .locked-banner b { color: #86efac; }
html[data-theme="dark"] .locked-banner small { color: #9fd3b0; }
html[data-theme="dark"] .new-avreich { border-color: #3a3a3a; }
html[data-theme="dark"] .modal-backdrop { background: rgba(0, 0, 0, .6); }

/* Theme switch button */
.theme-toggle { display: flex; align-items: center; gap: 10px; }
.theme-fab {
  position: fixed; top: 14px; inset-inline-start: 14px; z-index: 50; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .25); background: rgba(255, 255, 255, .1); color: #fff; cursor: pointer;
  display: grid; place-items: center;
}
.theme-fab:hover { background: rgba(255, 255, 255, .2); }
@media print { .theme-fab { display: none; } }
