:root {
  color-scheme: light;
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-2: #fbfbfa;
  --text: #16181b;
  --text-secondary: #5b6168;
  --muted: #8a9099;
  --border: #e4e7ea;

  --brand: #0e6e72;
  --brand-dark: #0a4f52;
  --brand-light: #e3f2f1;
  --accent: #c9972b;
  --accent-light: #faf1dc;

  --good: #0ca30c;
  --warning: #b8860b;
  --serious: #c9622f;
  --critical: #c9302c;

  --shadow-sm: 0 1px 2px rgba(16, 24, 20, 0.06);
  --shadow-md: 0 4px 16px rgba(16, 24, 20, 0.08);
  --radius: 10px;
  --radius-lg: 14px;

  --sidebar-w: 248px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #18191a;
    --surface-2: #1f2021;
    --text: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --border: #2c2c2a;

    --brand: #45bfc0;
    --brand-dark: #0a4f52;
    --brand-light: rgba(69, 191, 192, 0.16);
    --accent: #e0b450;
    --accent-light: rgba(224, 180, 80, 0.14);

    --good: #22c55e;
    --warning: #fab219;
    --serious: #ec835a;
    --critical: #e66767;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #18191a;
  --surface-2: #1f2021;
  --text: #ffffff;
  --text-secondary: #c3c2b7;
  --muted: #898781;
  --border: #2c2c2a;

  --brand: #34a67a;
  --brand-dark: #0b4f39;
  --brand-light: rgba(52, 166, 122, 0.16);
  --accent: #e0b450;
  --accent-light: rgba(224, 180, 80, 0.14);

  --good: #22c55e;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #e66767;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

/* Safety net: every icon here is a viewBox-only inline SVG with no
   width/height attribute, so anywhere a more specific rule below doesn't
   size it explicitly, it would otherwise render at the browser's ~300x150
   intrinsic default. This keeps it sane and scaling with text by default. */
svg { width: 1.1em; height: 1.1em; vertical-align: -0.15em; flex-shrink: 0; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--brand); }

/* ---------- App shell: sidebar + content ---------- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--brand-dark);
  color: #eef7f2;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.3rem 1.2rem 1.1rem;
  text-decoration: none;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.sidebar-brand .logo-mark {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}
.sidebar-brand .logo-mark img { width: 100%; height: 100%; object-fit: contain; }
.sidebar-brand .logo-mark svg { width: 20px; height: 20px; }
.sidebar-brand .brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.sidebar-brand .brand-text strong { font-size: 0.95rem; font-weight: 700; }
.sidebar-brand .brand-text span { font-size: 0.72rem; color: rgba(255, 255, 255, 0.6); letter-spacing: 0.03em; text-transform: uppercase; }

.sidebar-nav { flex: 1; padding: 0.9rem 0.7rem; display: flex; flex-direction: column; gap: 0.15rem; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.78);
  text-decoration: none;
  font-size: 0.89rem;
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}
.sidebar-nav a svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }
.sidebar-nav a:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.sidebar-nav a.active { background: rgba(255, 255, 255, 0.14); color: #fff; }
.sidebar-nav a.active svg { opacity: 1; color: var(--accent); }

.sidebar-nav .nav-section-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.4);
  padding: 0.9rem 0.7rem 0.25rem;
}

.sidebar-footer {
  padding: 0.9rem 0.7rem 1.1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.sidebar-user { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0.7rem 0.7rem; }
.sidebar-user .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: #241a03;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.8rem; flex-shrink: 0;
}
.sidebar-user .who { line-height: 1.2; overflow: hidden; }
.sidebar-user .who strong { display: block; font-size: 0.84rem; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .who span { font-size: 0.72rem; color: rgba(255, 255, 255, 0.55); }
.sidebar-footer a.logout {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.55rem 0.7rem; border-radius: 8px;
  color: rgba(255, 255, 255, 0.72); text-decoration: none; font-size: 0.86rem;
}
.sidebar-footer a.logout svg { width: 17px; height: 17px; }
.sidebar-footer a.logout:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

.content-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.breadcrumb-bar {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.85rem 2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.breadcrumb-trail {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  font-size: 0.88rem;
}
.breadcrumb-trail::-webkit-scrollbar { display: none; }
.breadcrumb-trail a { color: var(--text-secondary); text-decoration: none; white-space: nowrap; font-weight: 500; }
.breadcrumb-trail a:hover { color: var(--brand); }
.breadcrumb-trail .crumb-current { color: var(--text); font-weight: 650; white-space: nowrap; }
.breadcrumb-trail .crumb-sep { display: inline-flex; color: var(--muted); }
.breadcrumb-trail .crumb-sep svg { width: 13px; height: 13px; }

.breadcrumb-actions { display: flex; align-items: center; gap: 0.9rem; flex-shrink: 0; }
.icon-action {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px;
  color: var(--text-secondary); text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease;
}
.icon-action svg { width: 18px; height: 18px; }
.icon-action:hover { background: var(--surface-2); color: var(--brand); }

.topbar-user { display: flex; align-items: center; gap: 0.5rem; padding-left: 0.7rem; border-left: 1px solid var(--border); }
.topbar-user .avatar-sm {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--brand-light); color: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.72rem; flex-shrink: 0;
}
.topbar-user-name { font-size: 0.84rem; font-weight: 600; color: var(--text); }

.subnav {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0 2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.subnav::-webkit-scrollbar { display: none; }
.subnav a {
  display: inline-flex;
  align-items: center;
  padding: 0.75rem 0.2rem;
  margin-right: 1.4rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.86rem;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.subnav a:hover { color: var(--text); }
.subnav a.active { color: var(--brand); border-bottom-color: var(--brand); }

.mobile-nav-toggle { display: none; }

@media (min-width: 761px) {
  .mobile-nav-toggle { display: none !important; }
}

main.page { padding: 1.75rem 2rem 3rem; max-width: 1180px; width: 100%; }

/* ---------- Typography ---------- */

h2 { font-size: 1.4rem; font-weight: 700; margin: 0 0 1.1rem; letter-spacing: -0.01em; }
h3 { font-size: 1.05rem; font-weight: 650; margin: 0 0 0.8rem; }

/* ---------- Cards & layout primitives ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}

.auth-card {
  max-width: 380px;
  margin: 4.5rem auto;
  padding: 2.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  text-align: center;
}
.auth-card .logo-mark {
  width: 84px; height: 84px; margin: 0 auto 1rem;
  color: var(--brand);
  display: flex; align-items: center; justify-content: center;
}
.auth-card .logo-mark img { width: 100%; height: 100%; object-fit: contain; }
.auth-card .logo-mark svg { width: 30px; height: 30px; }
.auth-card h1 { font-size: 1.3rem; margin: 0 0 1.4rem; }
.auth-card form { text-align: left; }

/* ---------- Stat tiles ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.2rem 1.3rem;
  box-shadow: var(--shadow-sm);
}
.stat-tile .stat-label {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.8rem; color: var(--text-secondary); font-weight: 600;
  margin-bottom: 0.55rem;
}
.stat-tile .stat-label svg { width: 16px; height: 16px; color: var(--brand); flex-shrink: 0; }
.stat-tile .stat-value {
  font-size: 1.7rem; font-weight: 700; letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.stat-tile .stat-sub { font-size: 0.78rem; color: var(--muted); margin-top: 0.2rem; }

/* ---------- Dashboard grid ---------- */

.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 860px) { .dash-grid { grid-template-columns: 1fr; } }

.widget-list { list-style: none; margin: 0; padding: 0; }
.widget-list li {
  display: flex; justify-content: space-between; gap: 0.75rem;
  padding: 0.65rem 0; border-bottom: 1px solid var(--border); font-size: 0.88rem;
}
.widget-list li:last-child { border-bottom: none; }
.widget-list .item-title { font-weight: 600; }
.widget-list .item-meta { color: var(--text-secondary); font-size: 0.8rem; }
.widget-list .item-amount { font-variant-numeric: tabular-nums; color: var(--brand); font-weight: 700; white-space: nowrap; }
.empty-note { color: var(--muted); font-size: 0.86rem; padding: 0.5rem 0; }

/* ---------- Buttons ---------- */

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.15rem;
  border: none;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease, transform 0.05s ease, box-shadow 0.12s ease;
  box-shadow: var(--shadow-sm);
}
button:hover, .button:hover { background: var(--brand-dark); }
button:active, .button:active { transform: translateY(1px); }
button:focus-visible, .button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
button.secondary, .button.secondary {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
button.secondary:hover, .button.secondary:hover { background: var(--surface-2); }
button.danger, .button.danger { background: var(--critical); }
button.danger:hover { background: #a02622; }
button.ghost {
  background: none; color: var(--critical); box-shadow: none; padding: 0.2rem 0.4rem; font-weight: 500;
}
button.ghost:hover { background: rgba(201, 48, 44, 0.08); }

/* ---------- Forms ---------- */

.field { margin-bottom: 1.05rem; }
label { display: block; font-weight: 600; font-size: 0.86rem; margin-bottom: 0.35rem; color: var(--text); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="datetime-local"], textarea, select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.12s ease;
}
input:focus, textarea:focus, select:focus { border-color: var(--brand); outline: none; }
input:disabled, textarea:disabled { background: var(--surface-2); color: var(--muted); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1.5rem; padding: 1.1rem 1.2rem; }
legend { padding: 0 0.5rem; font-weight: 650; font-size: 0.92rem; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); }
thead th {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-secondary); font-weight: 650; background: var(--surface-2);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

/* ---------- Misc ---------- */

.hint { color: var(--text-secondary); font-size: 0.86rem; }
.error { color: var(--critical); font-size: 0.88rem; }
.success { color: var(--good); font-size: 0.88rem; }
.warning, .warning-banner {
  color: #6b4a10; background: var(--accent-light); border: 1px solid rgba(201, 151, 43, 0.35);
  padding: 0.75rem 1rem; border-radius: var(--radius); font-size: 0.88rem; margin-bottom: 1.25rem;
  display: block;
}
:root:not([data-theme="light"]) .warning, :root:not([data-theme="light"]) .warning-banner,
:root[data-theme="dark"] .warning, :root[data-theme="dark"] .warning-banner { color: var(--accent); }

.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.15rem 0.55rem; border-radius: 999px;
  font-size: 0.74rem; font-weight: 650;
}
.badge svg { width: 12px; height: 12px; }
.badge.good { background: rgba(12, 163, 12, 0.12); color: var(--good); }
.badge.critical { background: rgba(201, 48, 44, 0.12); color: var(--critical); }
.badge.muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; margin-top: 1.5rem; }
.module-grid a {
  display: flex; flex-direction: column; align-items: center; gap: 0.6rem;
  padding: 1.4rem 1rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); text-decoration: none; color: var(--text);
  font-weight: 650; text-align: center; box-shadow: var(--shadow-sm);
  transition: box-shadow 0.12s ease, transform 0.08s ease;
}
.module-grid a:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.module-grid a svg { width: 26px; height: 26px; color: var(--brand); }

#log { list-style: none; padding: 0; font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 0.84rem; }
#log li { padding: 0.4rem 0; border-bottom: 1px solid var(--border); }

.chart-card canvas { max-width: 100%; }

@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40;
    transform: translateX(-100%); transition: transform 0.18s ease;
    box-shadow: var(--shadow-md);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .content-area { width: 100%; }
  .breadcrumb-bar { padding: 0.75rem 1.1rem; }
  .subnav { padding: 0 1.1rem; }
  .topbar-user-name { display: none; }
  .topbar-user { border-left: none; padding-left: 0; }
  main.page { padding: 1.25rem 1.1rem 2.5rem; }
  .mobile-nav-toggle {
    display: inline-flex !important; align-items: center; justify-content: center;
    width: 36px; height: 36px; flex-shrink: 0; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); cursor: pointer;
  }
  body.nav-open::after {
    content: ""; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 30;
  }
}
