:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --s5: #e87ba4;
  --s6: #008300;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
}

/* ---------- sidebar ---------- */
.sidebar {
  width: 240px;
  flex: 0 0 240px;
  background: #10243c;
  color: #dbe4ee;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 20px 16px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand-mark {
  width: 40px; height: 40px; flex: 0 0 40px; border-radius: 8px;
  background: var(--s1); color: #fff; font-weight: 700; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.brand-title { font-weight: 600; font-size: 13px; line-height: 1.25; }
.brand-sub { font-size: 11px; color: #8ea3bd; margin-top: 2px; }
nav { padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }
nav a {
  color: #b9c7d8; text-decoration: none; padding: 9px 12px; border-radius: 6px;
  font-size: 13.5px;
  display: flex; align-items: center; gap: 10px;
}
nav a svg { flex: 0 0 16px; opacity: .75; }
nav a.active svg, nav a:hover svg { opacity: 1; }
nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
nav a.active { background: var(--s1); color: #fff; font-weight: 600; }
.sidebar-foot { margin-top: auto; padding: 16px; font-size: 11px; color: #7288a3; line-height: 1.5; }

/* ---------- main ---------- */
main { flex: 1; padding: 24px 28px 48px; min-width: 0; }
.page-head { margin-bottom: 20px; }
.page-head h1 { font-size: 20px; font-weight: 650; }
.page-head .sub { color: var(--ink-2); margin-top: 4px; font-size: 13px; }
.breadcrumb { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.breadcrumb a { color: var(--s1); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* ---------- grid & cards ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.grid-3-2 { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 980px) { .grid-2, .grid-3-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 18px;
}
.card h2 { font-size: 13.5px; font-weight: 600; color: var(--ink); margin-bottom: 2px; }
.card .card-sub { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.chart-wrap { position: relative; height: 260px; }
.chart-wrap.tall { height: 320px; }

/* ---------- stat tile ---------- */
a.tile { text-decoration: none; color: inherit; display: block; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; transition: box-shadow .12s, border-color .12s;
}
a.tile:hover { border-color: var(--s1); box-shadow: 0 2px 10px rgba(42,120,214,.12); }
.tile .label { font-size: 12.5px; color: var(--ink-2); }
.tile .value { font-size: 26px; font-weight: 650; margin-top: 4px; }
.tile .delta { font-size: 12px; margin-top: 4px; color: var(--ink-2); }
.tile .delta .up { color: var(--good-text); font-weight: 600; }
.tile .delta .down { color: var(--critical); font-weight: 600; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .03em;
  padding: 8px 10px; border-bottom: 1px solid var(--grid);
}
td { padding: 9px 10px; border-bottom: 1px solid var(--grid); }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f2f6fc; }
.table-scroll { overflow-x: auto; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 99px;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.b-good { color: var(--good-text); background: rgba(12,163,12,.10); }
.b-info { color: #1c5cab; background: rgba(42,120,214,.10); }
.b-warn { color: #8a5a00; background: rgba(250,178,25,.15); }
.b-serious { color: #a34a24; background: rgba(236,131,90,.15); }
.b-crit { color: var(--critical); background: rgba(208,59,59,.10); }
.b-muted { color: var(--ink-2); background: rgba(11,11,11,.06); }

/* ---------- meter ---------- */
.meter { height: 8px; border-radius: 4px; background: #dcE9f9; overflow: hidden; min-width: 80px; }
.meter > span { display: block; height: 100%; border-radius: 4px; background: var(--s1); }
.meter.warn { background: #fdeecd; } .meter.warn > span { background: var(--warning); }
.meter.crit { background: #f7dcdc; } .meter.crit > span { background: var(--critical); }

.kv { display: grid; grid-template-columns: 160px 1fr; row-gap: 8px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- topbar ---------- */
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.main-col main { flex: 1; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 10px 28px; position: sticky; top: 0; z-index: 50;
}
.topbar-left { font-size: 12.5px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.topbar-user { font-size: 12.5px; color: var(--ink-2); font-weight: 600; padding: 0 6px; }
.icon-link {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-2);
  text-decoration: none; padding: 7px 10px; border-radius: 7px;
  border: none; background: none; cursor: pointer; font-family: inherit;
}
.icon-link:hover { background: rgba(11,11,11,.05); color: var(--ink); }
.icon-link.active { color: var(--s1); background: rgba(42,120,214,.10); }

/* ---------- bell / alerts ---------- */
.bell-wrap { position: relative; }
.bell-btn { position: relative; }
.bell-badge {
  position: absolute; top: 0; right: 0;
  background: var(--critical); color: #fff; font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px; padding: 0 4px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--surface);
}
.bell-panel {
  display: none; position: absolute; right: 0; top: calc(100% + 8px);
  width: 340px; max-height: 420px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 30px rgba(11,11,11,.14); z-index: 100;
}
.bell-panel.open { display: block; }
.bell-panel-head {
  padding: 12px 14px; font-size: 12px; font-weight: 700; color: var(--ink-2);
  text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--grid);
}
.bell-item {
  display: flex; gap: 10px; padding: 11px 14px; text-decoration: none;
  color: inherit; border-bottom: 1px solid var(--grid);
}
.bell-item:last-child { border-bottom: none; }
.bell-item:hover { background: #f2f6fc; }
.bell-dot { flex: 0 0 8px; width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; }
.dot-crit { background: var(--critical); }
.dot-warn { background: var(--warning); }
.dot-info { background: var(--s1); }
.bell-title { display: block; font-size: 13px; font-weight: 600; }
.bell-text { display: block; font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.bell-empty { padding: 18px 14px; font-size: 13px; color: var(--muted); }

/* ---------- AI insights card ---------- */
.ai-card {
  margin-bottom: 16px;
  border: 1px solid rgba(42,120,214,.35);
  background: linear-gradient(135deg, rgba(42,120,214,.045), rgba(232,123,164,.045)), var(--surface);
}
.ai-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; color: var(--s1); }
.ai-head h2 { font-size: 13.5px; margin: 0; color: var(--ink); }
.ai-tag {
  font-size: 10.5px; font-weight: 600; color: var(--s1);
  background: rgba(42,120,214,.10); padding: 2px 8px; border-radius: 99px;
}
.ai-list { list-style: none; display: flex; flex-direction: column; gap: 7px; }
.ai-list li { position: relative; padding-left: 18px; font-size: 13px; line-height: 1.5; color: var(--ink-2); }
.ai-list li::before {
  content: ""; position: absolute; left: 2px; top: 6px;
  width: 8px; height: 8px; border-radius: 50%;
}
.ai-good::before { background: var(--good); }
.ai-info::before { background: var(--s1); }
.ai-warn::before { background: var(--warning); }
.ai-crit::before { background: var(--critical); }
.ai-pred { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--baseline); }
.ai-pred-title {
  font-size: 11px; font-weight: 700; color: var(--s1);
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px;
}
.ai-pred-item::before { background: var(--s1); outline: 2px dashed rgba(42,120,214,.4); outline-offset: 1px; }
.ai-rec {
  margin-top: 12px; padding: 10px 12px; border-radius: 8px;
  background: rgba(42,120,214,.07); font-size: 13px; line-height: 1.5; color: var(--ink);
}

/* ---------- chat ---------- */
.chat-card { display: flex; flex-direction: column; height: calc(100vh - 210px); min-height: 420px; padding: 0; overflow: hidden; }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 10px; max-width: 78%; }
.msg.user { align-self: flex-end; }
.msg .avatar {
  flex: 0 0 30px; width: 30px; height: 30px; border-radius: 50%;
  background: var(--s1); color: #fff; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}
.msg .bubble {
  padding: 10px 14px; border-radius: 12px; font-size: 13.5px; line-height: 1.55;
  background: #f1f0ec; color: var(--ink); white-space: pre-wrap;
}
.msg.user .bubble { background: var(--s1); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot .bubble { border-top-left-radius: 4px; }
.chat-suggestions { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 20px; border-top: 1px solid var(--grid); }
.chip {
  font-size: 12px; font-weight: 600; color: var(--s1);
  background: rgba(42,120,214,.08); border: 1px solid rgba(42,120,214,.25);
  padding: 6px 12px; border-radius: 99px; cursor: pointer; font-family: inherit;
}
.chip:hover { background: rgba(42,120,214,.15); }
.chat-input { display: flex; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--grid); }
.chat-input input {
  flex: 1; padding: 10px 14px; border: 1px solid var(--baseline); border-radius: 8px;
  font-size: 13.5px; font-family: inherit; background: var(--surface); color: var(--ink);
}
.chat-input input:focus { outline: 2px solid rgba(42,120,214,.35); border-color: var(--s1); }
.chat-input button, .btn-primary {
  background: var(--s1); color: #fff; border: none; border-radius: 8px;
  padding: 10px 20px; font-size: 13.5px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.chat-input button:hover, .btn-primary:hover { background: #1c5cab; }

/* ---------- login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; background: #10243c; }
.login-box {
  background: var(--surface); border-radius: 14px; padding: 32px 34px;
  width: 380px; max-width: calc(100vw - 32px);
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-box form { display: flex; flex-direction: column; gap: 14px; }
.login-box label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); display: flex; flex-direction: column; gap: 6px; }
.login-box input {
  padding: 10px 12px; border: 1px solid var(--baseline); border-radius: 8px;
  font-size: 14px; font-family: inherit;
}
.login-box input:focus { outline: 2px solid rgba(42,120,214,.35); border-color: var(--s1); }
.login-box button {
  margin-top: 6px; background: var(--s1); color: #fff; border: none; border-radius: 8px;
  padding: 11px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.login-box button:hover { background: #1c5cab; }
.login-error {
  background: rgba(208,59,59,.10); color: var(--critical); font-size: 13px;
  padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; font-weight: 600;
}
.login-hint { text-align: center; font-size: 12px; color: var(--muted); margin-top: 16px; }

/* ---------- settings ---------- */
.form-rows { display: flex; flex-direction: column; gap: 12px; }
.form-rows label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); display: flex; flex-direction: column; gap: 5px; }
.form-rows input[type="text"], .form-rows input[type="number"], .form-rows input[type="email"], .form-rows select {
  padding: 9px 12px; border: 1px solid var(--baseline); border-radius: 8px;
  font-size: 13.5px; font-family: inherit; background: var(--surface); color: var(--ink);
}
.form-rows input:focus, .form-rows select:focus { outline: 2px solid rgba(42,120,214,.35); border-color: var(--s1); }
.form-rows label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); }
.form-rows input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--s1); }
.flash-ok {
  background: rgba(12,163,12,.10); color: var(--good-text); font-weight: 600;
  font-size: 13px; padding: 10px 14px; border-radius: 8px; margin-bottom: 16px;
}
