/* ==========================================================================
   MCP Monitoring Dashboard - design tokens + layout
   Colors are defined as tokens; dark mode is a selected set of steps,
   not an automatic inversion.
   ========================================================================== */
:root {
  color-scheme: light;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --page: #f5f6f8;
  --surface-1: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e4e6eb;
  --border-strong: #d3d6dd;
  --text-primary: #0f1115;
  --text-secondary: #4b5060;
  --text-muted: #6f7482;
  --accent: #2a78d6;
  --accent-soft: #e8f1fc;

  --sidebar-bg: #0f1724;
  --sidebar-text: #aab4c5;
  --sidebar-text-active: #ffffff;
  --sidebar-active: #1d2a3d;

  --grid: #eceef2;

  /* categorical (fixed order) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --neutral: #9a9893;

  /* sequential (heatmap) */
  --seq-0: #f1f3f6;
  --seq-1: #cde2fb;
  --seq-2: #9ec5f4;
  --seq-3: #6da7ec;
  --seq-4: #3987e5;
  --seq-5: #256abf;
  --seq-6: #104281;

  /* status (reserved) */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #111110;
    --surface-1: #1a1a19;
    --surface-2: #212120;
    --border: #2e2e2c;
    --border-strong: #3a3a37;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #949389;
    --accent: #3987e5;
    --accent-soft: #1b2a3d;
    --sidebar-bg: #0c0c0b;
    --sidebar-text: #a3a29a;
    --sidebar-active: #22221f;
    --grid: #2a2a28;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #0ca30c; --series-7: #9085e9; --series-8: #e66767;
    --neutral: #75746f;
    --seq-0: #232322; --seq-1: #0d366b; --seq-2: #184f95; --seq-3: #256abf;
    --seq-4: #3987e5; --seq-5: #6da7ec; --seq-6: #9ec5f4;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #111110;
  --surface-1: #1a1a19;
  --surface-2: #212120;
  --border: #2e2e2c;
  --border-strong: #3a3a37;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #949389;
  --accent: #3987e5;
  --accent-soft: #1b2a3d;
  --sidebar-bg: #0c0c0b;
  --sidebar-text: #a3a29a;
  --sidebar-active: #22221f;
  --grid: #2a2a28;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #0ca30c; --series-7: #9085e9; --series-8: #e66767;
  --neutral: #75746f;
  --seq-0: #232322; --seq-1: #0d366b; --seq-2: #184f95; --seq-3: #256abf;
  --seq-4: #3987e5; --seq-5: #6da7ec; --seq-6: #9ec5f4;
}

/* ---------- base ---------- */
html, body { background: var(--page); }
body {
  font-family: var(--font);
  color: var(--text-primary);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted, .text-muted { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.tabular { font-variant-numeric: tabular-nums; }

/* ---------- shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex-shrink: 0; background: var(--sidebar-bg); color: var(--sidebar-text);
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px 20px; color: #fff; }
.brand:hover { text-decoration: none; color: #fff; }
/* The logo has dark text on a transparent background, so it always sits on a white tile. */
.brand-logo {
  background: #ffffff; border-radius: 10px; padding: 5px 7px; display: inline-flex;
  align-items: center; justify-content: center; flex-shrink: 0;
}
.brand-logo img { height: 38px; width: auto; display: block; }
.brand-logo-lg { padding: 10px 16px; border: 1px solid var(--border); }
.brand-logo-lg img { height: 72px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 650; font-size: 15px; line-height: 1.15; }
.brand-sub { font-size: 11px; color: var(--sidebar-text); }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding: 14px 12px 6px; opacity: .7; }
.side-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px;
  color: var(--sidebar-text); font-weight: 500; margin-bottom: 2px;
}
.side-link i { font-size: 16px; width: 18px; text-align: center; }
.side-link:hover { background: var(--sidebar-active); color: var(--sidebar-text-active); text-decoration: none; }
.side-link.active { background: var(--sidebar-active); color: var(--sidebar-text-active); box-shadow: inset 3px 0 0 var(--series-1); }
.side-link .count { margin-left: auto; font-size: 11px; background: var(--critical); color: #fff; border-radius: 10px; padding: 0 7px; }
.sidebar-foot { margin-top: auto; padding: 12px; font-size: 12px; border-top: 1px solid rgba(255,255,255,.08); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface-1); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 10px 24px; flex-wrap: wrap;
}
.topbar .page-title { font-size: 18px; font-weight: 650; margin: 0; }
.topbar .spacer { flex: 1; }
.content { padding: 24px; max-width: 1480px; width: 100%; }

.scope-select { min-width: 210px; }
.range-group .btn { font-size: 12.5px; padding: 4px 10px; }
.btn-check:checked + .btn-range, .btn-range.active {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.btn-range { border: 1px solid var(--border-strong); color: var(--text-secondary); background: var(--surface-1); }
.icon-btn {
  border: 1px solid var(--border-strong); background: var(--surface-1); color: var(--text-secondary);
  border-radius: 8px; width: 34px; height: 34px; display: grid; place-items: center;
}
.icon-btn:hover { color: var(--text-primary); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 12px;
  background: var(--accent-soft); color: var(--accent); flex-shrink: 0;
}
.avatar.ai { background: color-mix(in srgb, var(--series-2) 16%, transparent); color: var(--series-2); }

/* ---------- cards ---------- */
.card-x {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); height: 100%;
}
.card-x .card-head {
  display: flex; align-items: center; gap: 8px; padding: 14px 18px 0;
}
.card-x .card-title { font-weight: 600; font-size: 14px; margin: 0; }
.card-x .card-sub { color: var(--text-muted); font-size: 12px; }
.card-x .card-body-x { padding: 14px 18px 18px; }
.card-x .card-head .ms-auto a { font-size: 12.5px; }

.kpi { padding: 16px 18px; }
.kpi-label { color: var(--text-secondary); font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi-label i { color: var(--text-muted); }
.kpi-value { font-size: 28px; font-weight: 650; line-height: 1.15; margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.kpi-delta { font-size: 12px; color: var(--text-secondary); display: inline-flex; gap: 4px; align-items: center; }

.meter { height: 8px; border-radius: 4px; background: var(--seq-0); display: flex; gap: 2px; overflow: hidden; }
.meter > span { display: block; height: 100%; }
.meter > span:first-child { border-radius: 4px 0 0 4px; }
.meter > span:last-child { border-radius: 0 4px 4px 0; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--text-secondary); }
.legend .item { display: inline-flex; align-items: center; gap: 6px; }

.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
.dot-series-1 { background: var(--series-1); } .dot-series-2 { background: var(--series-2); }
.dot-series-3 { background: var(--series-3); } .dot-series-4 { background: var(--series-4); }
.dot-neutral { background: var(--neutral); }
.bg-series-1 { background: var(--series-1); } .bg-series-2 { background: var(--series-2); }
.bg-series-3 { background: var(--series-3); } .bg-series-4 { background: var(--series-4); }
.bg-neutral { background: var(--neutral); }

.row > * { min-width: 0; }
.chart-box { position: relative; height: 280px; width: 100%; min-width: 0; overflow: hidden; }
.chart-box canvas { max-width: 100%; }
.chart-box.sm { height: 230px; }
.chart-box.lg { height: 320px; }

/* ---------- badges ---------- */
.src-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-secondary); white-space: nowrap; }
.act-badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500; padding: 2px 8px;
  border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-primary); white-space: nowrap;
}
.act-badge i { font-size: 12px; color: var(--text-muted); }
.act-delete i, .act-unpublish i { color: var(--critical); }
.act-publish i { color: var(--good); }
.act-admin_user_changed i, .act-role_changed i { color: var(--serious); }
.act-login_failed i { color: var(--critical); }
.tag {
  display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 5px; margin: 1px 2px 1px 0;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-secondary);
}
.tag-ai { border-color: color-mix(in srgb, var(--series-2) 45%, transparent); color: var(--text-primary); }
.tag-ai i { color: var(--series-2); }

.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; font-size: 13px; color: var(--text-primary); }
.status-good i { color: var(--good); } .status-critical i { color: var(--critical); }
.status-warning i { color: var(--warning); } .status-muted i { color: var(--text-muted); }

/* ---------- tables ---------- */
.table-x { width: 100%; margin: 0; font-size: 13px; }
.table-x th {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 600;
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
.table-x td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text-primary); }
.table-x tbody tr:hover td { background: var(--surface-2); }
.table-x tbody tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.cell-user { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.cell-user .nm { font-weight: 550; line-height: 1.2; }
.cell-user .em { font-size: 12px; color: var(--text-muted); }
.cell-entry { max-width: 340px; }
.cell-entry .ttl { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.when { white-space: nowrap; color: var(--text-secondary); }
.bar-inline { height: 6px; border-radius: 3px; background: var(--series-1); min-width: 2px; }

/* ---------- activity feed ---------- */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.feed li:last-child { border-bottom: 0; }
.feed .what { font-size: 13px; line-height: 1.35; }
.feed .meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- heatmap ---------- */
.heatmap { display: grid; grid-template-columns: 38px repeat(24, minmax(10px, 1fr)); gap: 2px; font-size: 11px; }
.heatmap .hl { color: var(--text-muted); text-align: center; }
.heatmap .dl { color: var(--text-secondary); display: flex; align-items: center; }
.heatmap .c { aspect-ratio: 1 / 1; border-radius: 3px; background: var(--seq-0); }
.heatmap .l1 { background: var(--seq-1); } .heatmap .l2 { background: var(--seq-2); }
.heatmap .l3 { background: var(--seq-3); } .heatmap .l4 { background: var(--seq-4); }
.heatmap .l5 { background: var(--seq-5); } .heatmap .l6 { background: var(--seq-6); }
.heat-scale { display: flex; align-items: center; gap: 2px; font-size: 11px; color: var(--text-muted); }
.heat-scale .c { width: 12px; height: 12px; border-radius: 3px; }

/* ---------- filters ---------- */
.filter-bar { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.filter-bar .search { grid-column: span 2; }
@media (max-width: 575px) { .filter-bar .search { grid-column: span 1; } }

/* ---------- misc ---------- */
.empty {
  text-align: center; padding: 40px 20px; color: var(--text-muted);
}
.empty i { font-size: 32px; display: block; margin-bottom: 8px; }
.alert-banner {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--critical) 40%, transparent);
  background: color-mix(in srgb, var(--critical) 8%, var(--surface-1)); margin-bottom: 18px; font-size: 13px;
}
.alert-banner i { color: var(--critical); font-size: 18px; }
pre.json {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 14px;
  font-size: 12.5px; color: var(--text-primary); max-height: 420px; overflow: auto;
}
dl.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--text-muted); font-weight: 500; }
dl.kv dd { margin: 0; word-break: break-word; }
code { color: var(--text-secondary); font-size: .92em; }
.htmx-request .loading-veil { opacity: .5; transition: opacity .15s; }

.form-control, .form-select { background-color: var(--surface-1); border-color: var(--border-strong); color: var(--text-primary); }
.form-control:focus, .form-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background-color: var(--surface-1); color: var(--text-primary); }
.pagination .page-link { color: var(--text-secondary); background: var(--surface-1); border-color: var(--border); }
.pagination .active .page-link { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- responsive ---------- */
.menu-toggle { display: none; }
@media (max-width: 991px) {
  .sidebar { position: fixed; left: -260px; z-index: 50; transition: left .2s; }
  .sidebar.open { left: 0; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .menu-toggle { display: grid; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .scope-select { min-width: 0; flex: 1; }
}
