:root {
  --bg: #f4f2f1;
  --surface: #ffffff;
  --surface-2: #e8e6e3;
  --ink: #1c1a17;
  --muted: #8e8071;
  --line: #e8e6e3;
  --border: #d2ccc6;
  --brand: #5d8ca2;
  --brand-2: #385461;
  --brand-subtle: #eff4f6;
  --brand-border: #dfe8ec;
  --warn-bg: #f5f2f0;
  --warn-border: #d6ccc2;
  --warn: #5c4c3d;
  --danger-bg: #f5f3f0;
  --danger-border: #d6cdc2;
  --danger: #5c4e3d;
  --ok-bg: #f1f3f2;
  --ok-border: #c8d0cc;
  --ok: #46534d;
  --shadow: 0 18px 52px rgba(20, 18, 16, 0.08);
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-pill: 999px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141210;
    --surface: #1c1a17;
    --surface-2: #232019;
    --ink: #f4f2f1;
    --muted: #a4998e;
    --line: #232019;
    --border: #39332d;
    --brand: #7da3b5;
    --brand-2: #bed1da;
    --brand-subtle: #1b2a30;
    --brand-border: #253841;
    --warn-bg: #2a2521;
    --warn-border: #5c4c3d;
    --warn: #d6ccc2;
    --danger-bg: #2a2521;
    --danger-border: #5c4e3d;
    --danger: #d6cdc2;
    --ok-bg: #20241f;
    --ok-border: #46534d;
    --ok: #c8d0cc;
    --shadow: 0 18px 52px rgba(0, 0, 0, 0.45);
  }
}

:root[data-theme="dark"] {
  --bg: #141210;
  --surface: #1c1a17;
  --surface-2: #232019;
  --ink: #f4f2f1;
  --muted: #a4998e;
  --line: #232019;
  --border: #39332d;
  --brand: #7da3b5;
  --brand-2: #bed1da;
  --brand-subtle: #1b2a30;
  --brand-border: #253841;
  --warn-bg: #2a2521;
  --warn-border: #5c4c3d;
  --warn: #d6ccc2;
  --danger-bg: #2a2521;
  --danger-border: #5c4e3d;
  --danger: #d6cdc2;
  --ok-bg: #20241f;
  --ok-border: #46534d;
  --ok: #c8d0cc;
  --shadow: 0 18px 52px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--ink);
  display: grid;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  grid-template-columns: 280px minmax(0, 1fr);
  margin: 0;
  min-height: 100vh;
  transition: background-color 0.15s ease, color 0.15s ease;
}

a { color: inherit; text-decoration: none; }

.sidebar {
  background: #141210;
  color: #f4f2f1;
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-height: 100vh;
  padding: 22px;
  position: sticky;
  top: 0;
}

.brand {
  align-items: center;
  display: flex;
  gap: 12px;
}

.brand-mark {
  align-items: center;
  background: linear-gradient(145deg, var(--brand), var(--brand-2));
  border-radius: var(--radius-sm);
  display: inline-flex;
  font-size: 22px;
  font-weight: 900;
  height: 42px;
  justify-content: center;
  width: 42px;
  color: #fff;
}

.brand small {
  color: #a4998e;
  display: block;
  font-size: 12px;
  margin-top: 2px;
}

nav {
  display: grid;
  gap: 6px;
}

nav a {
  border-radius: 8px;
  color: #bbb3aa;
  font-size: 14px;
  font-weight: 800;
  padding: 11px 12px;
}

nav a.active,
nav a:hover {
  background: rgba(244, 242, 241, 0.08);
  color: #fff;
}

.theme-toggle {
  align-items: center;
  background: rgba(244, 242, 241, 0.08);
  border: 0;
  border-radius: var(--radius-sm);
  color: #d2ccc6;
  cursor: pointer;
  display: flex;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  gap: 8px;
  justify-content: center;
  min-height: 38px;
  padding: 0 12px;
}

.auth-panel {
  border-top: 1px solid rgba(244, 242, 241, 0.12);
  display: grid;
  gap: 9px;
  margin-top: auto;
  padding-top: 18px;
}

label {
  color: #a4998e;
  font-size: 12px;
  font-weight: 800;
}

input,
textarea {
  background: #0d0b0a;
  border: 1px solid rgba(244, 242, 241, 0.14);
  border-radius: var(--radius-sm);
  color: #fff;
  font: inherit;
  padding: 10px;
  width: 100%;
}

textarea {
  min-height: 88px;
  resize: vertical;
}

button {
  background: var(--brand);
  border: 0;
  border-radius: var(--radius-sm);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 900;
  min-height: 40px;
  padding: 0 14px;
}

main {
  min-width: 0;
  padding: 26px;
}

.topbar,
.section-head,
.panel-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 24px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 { font-size: 27px; font-weight: 800; letter-spacing: -0.6px; }
h2 { font-size: 20px; font-weight: 800; letter-spacing: -0.4px; }
h3 { font-size: 16px; font-weight: 800; letter-spacing: -0.3px; }

.eyebrow {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.status {
  align-items: center;
  display: flex;
  gap: 10px;
}

.status span,
.timestamp,
.threshold,
.panel-head span {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
}

.section {
  margin-bottom: 30px;
}

.section-head {
  margin-bottom: 14px;
}

.kpi-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 14px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 16px;
}

.kpi span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 900;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.kpi strong {
  display: block;
  font-size: 30px;
}

.kpi.danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.panel-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.8fr);
}

.panel,
.table-card,
.report-list,
.rule-grid article {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.bar-chart {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(14, 1fr);
  height: 220px;
  margin-top: 16px;
}

.bar {
  background: linear-gradient(180deg, var(--brand), var(--brand-2));
  border-radius: 6px 6px 0 0;
  min-height: 8px;
  position: relative;
}

.bar span {
  bottom: -22px;
  color: var(--muted);
  font-size: 10px;
  left: 50%;
  position: absolute;
  transform: translateX(-50%);
}

.severity-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.severity-row,
.report-item {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.severity-row {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.severity-row strong {
  font-size: 22px;
}

.table-card {
  overflow: auto;
}

table {
  border-collapse: collapse;
  min-width: 900px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 13px 14px;
  text-align: left;
}

th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

.badge {
  border-radius: var(--radius-pill);
  display: inline-flex;
  font-size: 12px;
  font-weight: 900;
  padding: 5px 9px;
}

.badge.active { background: var(--ok-bg); color: var(--ok); }
.badge.candidate { background: var(--warn-bg); color: var(--warn); }
.badge.observed { background: var(--surface-2); color: var(--muted); }
.badge.critical { background: var(--danger-bg); color: var(--danger); }

.report-list {
  display: grid;
  gap: 0;
  overflow: hidden;
}

.report-item {
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
}

.report-item:last-child {
  border-bottom: 0;
}

.report-item p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.rule-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.rule-grid article {
  display: grid;
  gap: 8px;
  padding: 16px;
}

.rule-grid span {
  color: var(--muted);
  line-height: 1.45;
}

@media (max-width: 980px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    position: static;
  }

  .kpi-grid,
  .panel-grid,
  .rule-grid {
    grid-template-columns: 1fr;
  }
}
