:root {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-elev2: #1c2230;
  --border: #2a313c;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #388bfd;
  --accent-dim: #1f6feb;
  --green: #3fb950;
  --red: #f85149;
  --amber: #d29922;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
button {
  font-family: inherit; font-size: 13px; cursor: pointer;
  background: var(--bg-elev2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent-dim); border-color: var(--accent-dim); color: #fff; }
button.primary:hover { background: var(--accent); }
button.danger { color: var(--red); border-color: #4a2525; }
button.danger:hover { border-color: var(--red); }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select {
  font-family: inherit; font-size: 13px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
label { display: block; font-size: 12px; color: var(--text-dim); margin: 10px 0 4px; }

/* Layout */
.layout { display: grid; grid-template-columns: 250px 1fr; height: 100vh; }
.sidebar {
  background: var(--bg-elev); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.brand { padding: 16px; font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); }
.nav { flex: 1; overflow-y: auto; padding: 8px; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); padding: 12px 10px 6px; }
.nav-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 10px; border-radius: 6px; cursor: pointer; color: var(--text);
}
.nav-item:hover { background: var(--bg-elev2); }
.nav-item.active { background: var(--accent-dim); color: #fff; }
.nav-item .count { font-size: 11px; color: var(--text-dim); }
.nav-item.active .count { color: #cfe3ff; }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-dim); }

.main { overflow-y: auto; padding: 24px 28px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.topbar h1 { font-size: 20px; margin: 0; }
.row { display: flex; gap: 10px; align-items: center; }

/* Cards & tables */
.card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h2 { font-size: 14px; margin: 0 0 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); font-weight: 600; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--bg-elev2); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; }
.status.online .dot { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status.offline .dot { background: #484f58; }
.status.online { color: var(--green); }
.status.offline { color: var(--text-dim); }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--text-dim); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 10px; background: var(--bg-elev2); font-size: 11px; border: 1px solid var(--border); }

/* Metrics */
.metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.metric { background: var(--bg-elev2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.metric .m-label { font-size: 12px; color: var(--text-dim); }
.metric .m-value { font-size: 24px; font-weight: 700; margin: 4px 0; }
.bar { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; background: var(--accent); transition: width .4s ease; }
.bar.warn > span { background: var(--amber); }
.bar.crit > span { background: var(--red); }

/* Detail layout */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; word-break: break-word; }

/* Auth */
.auth-wrap { display: flex; align-items: center; justify-content: center; height: 100vh; }
.auth-card { width: 360px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; padding: 28px; }
.auth-card h1 { font-size: 22px; margin: 0 0 4px; display: flex; gap: 8px; align-items: center; }
.auth-card p.sub { color: var(--text-dim); margin: 0 0 18px; font-size: 13px; }
.auth-card button { width: 100%; margin-top: 18px; }
.err { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; padding: 24px; width: 480px; max-width: 92vw; }
.modal h2 { margin: 0 0 16px; font-size: 18px; text-transform: none; letter-spacing: 0; color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.codeblock { font-family: var(--mono); font-size: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 12px; white-space: pre-wrap; word-break: break-all; margin-top: 8px; }

.empty { text-align: center; color: var(--text-dim); padding: 48px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--bg-elev2); border: 1px solid var(--accent); border-radius: 8px; padding: 12px 16px; z-index: 100; animation: slideup .2s ease; }
@keyframes slideup { from { transform: translateY(10px); opacity: 0; } }
.spark { width: 100%; height: 40px; display: block; }
.oidc-btn { display: block; text-align: center; background: var(--accent-dim); color: #fff; border-radius: 6px; padding: 11px; font-weight: 600; margin-top: 4px; }
.oidc-btn:hover { background: var(--accent); }


/* Metrics history */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; color: var(--text-dim); padding: 5px 10px; font-variant-numeric: tabular-nums; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover { background: var(--bg-elev2); color: var(--text); }
.seg button.active { background: var(--bg-elev2); color: var(--text); font-weight: 600; }
.hist-body { transition: opacity .15s ease; }
.hist-chart { margin-bottom: 14px; outline: none; border-radius: 6px; }
.hist-chart:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.hist-title { display: flex; gap: 10px; align-items: baseline; font-size: 13px; margin-bottom: 2px; }
.hist-title span:first-child { font-weight: 600; }
.hist-title .muted { font-size: 12px; }
.hist-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-dim); margin: 2px 0 2px; }
.hist-legend span { display: inline-flex; align-items: center; gap: 6px; }
.hist-legend i, .hist-tip-row i { display: inline-block; width: 12px; height: 2px; border-radius: 1px; }
.hist-plot { position: relative; }
.hist-svg { display: block; overflow: visible; }
.hist-grid { stroke: #222a35; stroke-width: 1; shape-rendering: crispEdges; }
.hist-base { stroke: var(--border); stroke-width: 1; shape-rendering: crispEdges; }
.hist-tick { fill: var(--text-dim); font-size: 11px; font-variant-numeric: tabular-nums; }
.hist-endlabel { fill: var(--text-dim); font-size: 11px; }
.hist-cross { stroke: var(--text-dim); stroke-width: 1; stroke-opacity: .6; shape-rendering: crispEdges; }
.hist-tip { position: absolute; pointer-events: none; background: var(--bg-elev2); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; font-size: 12px; white-space: nowrap; box-shadow: 0 4px 16px rgba(0,0,0,.35); z-index: 5; }
.hist-tip-row { display: flex; align-items: center; gap: 8px; }
.hist-tip-row strong { color: var(--text); font-variant-numeric: tabular-nums; }
.hist-table summary { cursor: pointer; color: var(--text-dim); font-size: 12px; }
.hist-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.hist-table th, .hist-table td { padding: 6px 10px; font-size: 12px; }
