:root {
  /* Tells the browser/OS this site is designed for light mode and manages
     its own theming (via the in-app Light/Executive Midnight/Graphite Luxe
     picker) -- prevents Android Chrome/Samsung Internet's automatic
     dark-mode content adjustment from repainting pages and form controls
     dark when the device's system Dark Mode is on, independent of our
     own explicit CSS colors. */
  color-scheme: light;
  /* WesTrack Light -- the current approved default theme. */
  --navy: #0a2647;
  --navy-light: #12345f;
  --teal: #147a7a;
  --teal-light: #1a9494;
  --gold: #b9925a;
  --green: #1e8449;
  --green-bg: #e6f4ea;
  --amber: #b9770e;
  --amber-bg: #fcf3cf;
  --red: #c0392b;
  --red-bg: #fdedec;
  --bg: #f5f7f8;
  --card-bg: #ffffff;
  --text: #1c2733;
  --text-muted: #5b6b78;
  --border: #e1e6ea;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(10, 38, 71, 0.08);
  --shadow-md: 0 8px 24px rgba(10, 38, 71, 0.14);

  /* Semantic tokens (theme-aware). Defaults below = light theme. */
  --heading: var(--navy);
  --sidebar-bg: var(--navy);
  --accent-neutral: var(--navy);
  --surface-muted: #eef2f5;
  --chart-track-bg: #eef2f5;

  /* Fixed -- never themed. The logo panel always stays light so the full
     official logo stays crisp and legible in every theme. */
  --logo-panel-bg: #ffffff;
  --logo-panel-text: #0a2647;

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---------- Owner-only premium theme previews ----------
   Scoped to #app-shell so the shared login screen and Kai/Joyce's
   workspaces (which never receive a data-theme attribute) always render
   in WesTrack Light, regardless of Edwin's saved preference. */
#app-shell[data-theme="executive-midnight"] {
  --bg: #07111f;
  --sidebar-bg: #081b2f;
  --card-bg: #10233c;
  --border: #1e3a5f;
  --text: #f7fafc;
  --text-muted: #aab7c4;
  --heading: #f7fafc;
  --teal: #18a999;
  --teal-light: #2cc0af;
  --gold: #c8a96b;
  --green: #36c98f;
  --green-bg: rgba(54, 201, 143, 0.16);
  --amber: #f5c76b;
  --amber-bg: rgba(245, 199, 107, 0.16);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.16);
  --accent-neutral: #18a999;
  --surface-muted: #16304f;
  --chart-track-bg: #16304f;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.48);
}

#app-shell[data-theme="graphite-luxe"] {
  --bg: #111318;
  --sidebar-bg: #161a22;
  --card-bg: #20252f;
  --border: #343b49;
  --text: #f4f6f8;
  --text-muted: #aeb6c2;
  --heading: #f4f6f8;
  --teal: #1aa89c;
  --teal-light: #2bc2b4;
  --gold: #b9a77a;
  --green: #36c98f;
  --green-bg: rgba(54, 201, 143, 0.16);
  --amber: #f5c76b;
  --amber-bg: rgba(245, 199, 107, 0.16);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.16);
  --accent-neutral: #1aa89c;
  --surface-muted: #2a3038;
  --chart-track-bg: #2a3038;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.48);
}

/* Premium dark themes read better with a thin defining border on raised
   surfaces (shadows alone are less visible against a dark page). Scoped
   to dark themes only so WesTrack Light is never altered. */
#app-shell[data-theme="executive-midnight"] .kpi-card,
#app-shell[data-theme="executive-midnight"] .section-card,
#app-shell[data-theme="graphite-luxe"] .kpi-card,
#app-shell[data-theme="graphite-luxe"] .section-card {
  border: 1px solid var(--border);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.login-card {
  background: var(--card-bg); border-radius: 16px; box-shadow: var(--shadow-md);
  padding: 36px 32px; width: 100%; max-width: 380px; animation: fadeUp .35s ease;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px);} to { opacity: 1; transform: translateY(0);} }
.login-brand { text-align: center; margin-bottom: 22px; }
.login-logo { width: 200px; max-width: 100%; height: auto; margin-bottom: 14px; }

.boot-loading-inner { text-align: center; color: var(--navy); animation: fadeUp .3s ease; }
.boot-logo-panel {
  background: var(--logo-panel-bg); border-radius: 16px; padding: 20px 24px; display: inline-block;
  box-shadow: var(--shadow-md); margin-bottom: 16px;
}
.boot-logo { width: 200px; max-width: 60vw; height: auto; display: block; }
.boot-text { font-size: 0.95rem; color: var(--text-muted); }
.login-brand h1 { font-size: 1.25rem; margin: 0 0 4px; color: var(--navy); }
.login-sub { font-size: 0.85rem; color: var(--text-muted); margin: 0; }
#login-form label, #change-password-form label { display: block; font-size: 0.82rem; font-weight: 600; margin: 14px 0 6px; color: var(--navy); }
#login-form input, #change-password-form input {
  width: 100%; padding: 11px 12px; border-radius: 8px; border: 1px solid var(--border); font-size: 0.95rem;
}
#login-form input:focus, #change-password-form input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(20,122,122,0.15); }
.btn-primary {
  width: 100%; margin-top: 20px; padding: 12px; border: none; border-radius: 8px;
  background: var(--teal); color: white; font-weight: 700; font-size: 0.95rem; transition: background .15s ease;
}
.btn-primary:hover { background: var(--teal-light); }
.error-text { color: var(--red); font-size: 0.85rem; margin-top: 12px; min-height: 1em; }
.app-footer { color: var(--text-muted); font-size: 0.78rem; margin-top: 18px; text-align: center; }
.app-footer-inline { color: var(--text-muted); background: transparent; padding: 14px 0; text-align: center; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; background: var(--bg); color: var(--text); }
.sidebar {
  width: 236px; background: var(--sidebar-bg); color: white; display: flex; flex-direction: column;
  flex-shrink: 0; transition: transform .2s ease; z-index: 50;
}
.sidebar-brand {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 16px 14px; background: var(--logo-panel-bg);
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.brand-logo { width: 180px; max-width: 100%; height: auto; display: block; }
.brand-sub { font-size: 0.74rem; color: var(--logo-panel-text); font-weight: 700; letter-spacing: .01em; }
.nav-links { flex: 1; padding: 14px 10px; overflow-y: auto; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: rgba(255,255,255,0.85);
  font-size: 0.88rem; font-weight: 600; margin-bottom: 2px; cursor: pointer; transition: background .12s ease;
  text-decoration: none;
}
.nav-link:hover { background: rgba(255,255,255,0.08); }
.nav-link.active { background: var(--teal); color: white; }
.nav-section-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .06em; color: rgba(255,255,255,0.45); padding: 14px 12px 4px; }
.sidebar-footer { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,0.12); }
.user-badge { font-size: 0.82rem; margin-bottom: 10px; }
.user-badge .role-pill { display: inline-block; margin-top: 4px; font-size: 0.68rem; padding: 2px 8px; border-radius: 999px; background: var(--teal); }
.sidebar-theme-picker { margin-bottom: 10px; }
.sidebar-theme-picker label { display: block; font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: rgba(255,255,255,0.55); margin-bottom: 5px; }
.sidebar-theme-picker select {
  width: 100%; padding: 8px 9px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.08); color: white; font-size: 0.8rem;
}
.sidebar-theme-picker select option { color: #1c2733; }
.btn-ghost { width: 100%; padding: 9px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.3); background: transparent; color: white; font-size: 0.82rem; font-weight: 600; }
.btn-ghost:hover { background: rgba(255,255,255,0.1); }

.main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 14px 24px; background: var(--card-bg);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.menu-toggle { display: none; background: none; border: none; font-size: 1.3rem; color: var(--heading); }
.topbar-logo { display: none; background: var(--logo-panel-bg); border-radius: 8px; padding: 4px 8px; }
.topbar-title { font-weight: 800; color: var(--heading); font-size: 1.05rem; flex: 1; }
.topbar-meta { font-size: 0.78rem; color: var(--text-muted); }
.view-root { flex: 1; padding: 22px 24px; overflow-x: hidden; }

/* ---------- KPI cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.kpi-card {
  background: var(--card-bg); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
  border-left: 4px solid var(--accent-neutral); animation: fadeUp .25s ease;
}
.kpi-card.tone-good { border-left-color: var(--green); background: var(--green-bg); }
.kpi-card.tone-warn { border-left-color: var(--amber); background: var(--amber-bg); }
.kpi-card.tone-bad { border-left-color: var(--red); background: var(--red-bg); }
.kpi-label { font-size: 0.78rem; font-weight: 700; color: var(--text-muted); margin-bottom: 6px; }
.kpi-value { font-size: 1.5rem; font-weight: 800; color: var(--heading); line-height: 1.2; }
.kpi-value.small { font-size: 1.05rem; }
.kpi-note { font-size: 0.72rem; color: var(--text-muted); margin-top: 4px; font-style: italic; }

/* ---------- Simplified home screens (Joyce / Kai) ---------- */
.home-intro { font-size: 1rem; color: var(--text-muted); margin-bottom: 18px; }
.home-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 24px; }
.home-action-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: var(--card-bg); border: 2px solid var(--border); border-radius: var(--radius);
  padding: 32px 16px; cursor: pointer; box-shadow: var(--shadow); transition: border-color .15s, transform .1s;
  text-align: center;
}
.home-action-btn:hover { border-color: var(--teal); transform: translateY(-2px); }
.home-action-icon { font-size: 2.2rem; color: var(--teal); }
.home-action-label { font-size: 1.05rem; font-weight: 800; color: var(--heading); }
.home-action-sub { font-size: 0.78rem; color: var(--text-muted); }

/* ---------- Operational info strip (kept visually separate from the 7 financial cards) ---------- */
.operational-strip {
  display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; padding: 12px 16px;
  background: var(--surface-muted); border-radius: var(--radius); border: 1px dashed var(--border);
}
.operational-item { display: flex; flex-direction: column; gap: 2px; min-width: 140px; }
.operational-label { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); }
.operational-value { font-size: 1rem; font-weight: 700; color: var(--heading); }

/* ---------- Alerts ---------- */
.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-item {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 8px;
  background: var(--amber-bg); border-left: 4px solid var(--amber); margin-bottom: 8px; font-size: 0.9rem;
}
.alert-item strong { color: var(--heading); }
.no-alerts { color: var(--text-muted); font-size: 0.9rem; padding: 8px 0; }

/* ---------- Details toggle ---------- */
.details-toggle {
  background: transparent; border: 1px solid var(--border); color: var(--text-muted);
  border-radius: 8px; padding: 8px 16px; font-size: 0.82rem; font-weight: 700; cursor: pointer; margin-bottom: 16px;
}
.details-toggle:hover { border-color: var(--teal); color: var(--teal); }

/* ---------- More Details (collapsible form section) ---------- */
details.more-details { margin: 10px 0 16px; }
details.more-details summary {
  cursor: pointer; font-size: 0.82rem; font-weight: 700; color: var(--teal); padding: 6px 0; list-style: none;
}
details.more-details summary::-webkit-details-marker { display: none; }
details.more-details summary::before { content: "▸ "; }
details.more-details[open] summary::before { content: "▾ "; }

@media (max-width: 640px) {
  .home-actions { grid-template-columns: 1fr; }
}

/* ---------- Section / cards / tables ---------- */
.section-card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 20px; }
.section-title { font-weight: 800; color: var(--heading); font-size: 1rem; margin: 0 0 14px; display: flex; align-items: center; justify-content: space-between; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-neutral { background: var(--surface-muted); color: var(--text-muted); }

table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th { text-align: left; padding: 9px 10px; background: var(--teal); color: white; font-size: 0.75rem; text-transform: uppercase; letter-spacing: .02em; }
th:first-child { border-radius: 8px 0 0 0; } th:last-child { border-radius: 0 8px 0 0; }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); color: var(--text); }
tr:hover td { background: var(--surface-muted); }
.table-wrap { overflow-x: auto; }

.filters-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; align-items: flex-end; }
.theme-picker-spacer { flex: 1 1 auto; min-width: 8px; }
.theme-picker select { min-width: 220px; }
@media (max-width: 720px) {
  .theme-picker-spacer { flex-basis: 100%; height: 0; }
  .theme-picker { width: 100%; }
  .theme-picker select { width: 100%; }
}
.month-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.month-nav-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--card-bg); color: var(--heading); font-size: 0.9rem; cursor: pointer;
}
.month-nav-btn:hover { background: var(--accent-soft, var(--border)); }
.month-nav-label { font-size: 1.05rem; font-weight: 800; color: var(--heading); letter-spacing: 0.03em; min-width: 160px; text-align: center; }
.month-nav-today { margin-left: 6px; }
.summary-strip { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.summary-pill {
  flex: 1 1 160px; background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px;
}
.summary-pill-label { font-size: 0.72rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.summary-pill-value { font-size: 1.35rem; font-weight: 800; color: var(--heading); margin-top: 4px; }
.summary-pill-sub { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
.empty-state { padding: 28px 16px; text-align: center; color: var(--text-muted); }
.empty-state strong { display: block; color: var(--heading); font-size: 1rem; margin-bottom: 6px; }
.alert-item.clickable { cursor: pointer; }
.alert-item.clickable:hover { text-decoration: underline; }
.filter-field label { display: block; font-size: 0.72rem; font-weight: 700; color: var(--text-muted); margin-bottom: 4px; }
.filter-field input, .filter-field select {
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 0.85rem;
  background: var(--card-bg); color: var(--text);
}

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 16px; margin-bottom: 12px; }
.form-field.wide { grid-column: 1 / -1; }
.form-field label { display: block; font-size: 0.78rem; font-weight: 700; color: var(--heading); margin-bottom: 5px; }
.form-field input, .form-field select, .form-field textarea {
  width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 0.88rem;
  background: var(--card-bg); color: var(--text);
}
.btn-small { padding: 8px 16px; border-radius: 8px; border: none; background: var(--teal); color: white; font-weight: 700; font-size: 0.82rem; }
.btn-small:hover { background: var(--teal-light); }
.btn-small.outline { background: transparent; border: 1px solid var(--teal); color: var(--teal); }
.btn-small.danger { background: var(--red); }
.btn-small.approve { background: var(--green); }

.action-list { list-style: none; margin: 0; padding: 0; }
.action-list li { padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 0.88rem; display: flex; gap: 8px; align-items: flex-start; }
.action-list li:last-child { border-bottom: none; }
.action-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); margin-top: 6px; flex-shrink: 0; }

.chart-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.chart-bar-label { width: 120px; font-size: 0.8rem; color: var(--text-muted); flex-shrink: 0; }
.chart-bar-track { flex: 1; background: var(--chart-track-bg); border-radius: 6px; height: 20px; overflow: hidden; position: relative; }
.chart-bar-fill { height: 100%; background: var(--teal); border-radius: 6px; transition: width .4s ease; }
.chart-bar-value { font-size: 0.78rem; font-weight: 700; color: var(--heading); width: 100px; text-align: right; flex-shrink: 0; }

.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--navy); color: white; padding: 12px 18px;
  border-radius: 8px; box-shadow: var(--shadow-md); font-size: 0.85rem; z-index: 200; animation: fadeUp .2s ease;
}
.toast.error { background: var(--red); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); box-shadow: var(--shadow-md); }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: block; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .view-root { padding: 16px; }
  .topbar { padding: 10px 14px; }
  .topbar-meta { display: none; }
  .topbar-logo { display: block; width: 140px; max-width: 40vw; height: auto; flex-shrink: 0; }
  .topbar-title { display: none; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
}
