/* DB Command Center — dark ops theme.
   Committed dark-only design; chart series colors validated for CVD
   separation and ≥3:1 contrast against the panel surface. */

:root {
  --bg: #0F172A;
  --bg-deep: #0B1220;
  --panel: #1E293B;
  --panel-2: #26344B;
  --line: rgba(148, 163, 184, 0.14);
  --line-strong: rgba(148, 163, 184, 0.28);
  --text: #F1F5F9;
  --text-2: #B9C5D6;
  --muted: #8B9BB4;
  --accent: #3987E5;
  --accent-soft: rgba(57, 135, 229, 0.14);
  --s1: #3987E5;  /* series: qps */
  --s2: #D95926;  /* series: threads */
  --s3: #199E70;  /* series: slow rate */
  --good: #0CA30C;
  --warn: #FAB219;
  --serious: #EC835A;
  --crit: #D03B3B;
  --crit-soft: rgba(208, 59, 59, 0.14);
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --r: 10px;
  --r-sm: 7px;
  --shadow: 0 10px 30px rgba(2, 6, 16, 0.45);
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  background:
    radial-gradient(1100px 500px at 75% -220px, rgba(57, 135, 229, 0.09), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 1600px; margin: 0 auto; padding: 0 22px 40px; }

.ic { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.hidden { display: none !important; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 4px 12px;
  background: linear-gradient(var(--bg) 82%, transparent);
}

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

.brand-mark {
  display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: var(--r-sm);
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid rgba(57, 135, 229, 0.35);
}
.brand-mark .ic { width: 19px; height: 19px; }

.brand h1 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }

.brand-sub { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot[data-state="ok"] { background: var(--good); box-shadow: 0 0 8px rgba(12, 163, 12, 0.7); }
.dot[data-state="down"] { background: var(--crit); box-shadow: 0 0 8px rgba(208, 59, 59, 0.7); }

.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 11px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel);
  font-size: 12.5px; color: var(--text-2); white-space: nowrap;
}
.chip[data-health="bad"] { color: var(--serious); border-color: rgba(236, 131, 90, 0.4); }

.range { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); padding: 3px; }
.range button {
  border: 0; background: transparent; color: var(--muted);
  font: 600 12.5px var(--sans); padding: 5px 12px; border-radius: 999px; cursor: pointer;
  transition: color 150ms, background 150ms;
}
.range button:hover { color: var(--text); }
.range button.active { background: var(--accent-soft); color: #9CC5F5; }

/* ---------- buttons & inputs ---------- */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--panel); color: var(--text-2);
  font: 600 13px var(--sans); padding: 8px 13px; min-height: 36px;
  cursor: pointer; transition: background 150ms, color 150ms, border-color 150ms;
}
.btn:hover { background: var(--panel-2); color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06101F; }
.btn.primary:hover { background: #5598E7; }
.btn.danger { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn.danger:hover { background: #DE5B5B; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel); }
.btn.icon { padding: 8px; }
.btn.mini { min-height: 30px; padding: 4px 10px; font-size: 12px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.input {
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--bg-deep); color: var(--text);
  font: 500 13px var(--sans); padding: 8px 11px; min-height: 36px;
}
.input::placeholder { color: var(--muted); }
select.input { cursor: pointer; }

:is(a, button, input, select, [tabindex]):focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm);
}

/* ---------- banner / kpis ---------- */

.banner {
  display: flex; gap: 10px; align-items: center;
  margin: 10px 0 0; padding: 11px 14px;
  border: 1px solid rgba(236, 131, 90, 0.45); border-radius: var(--r);
  background: rgba(236, 131, 90, 0.1); color: #F4B49B; font-size: 13.5px;
}

.kpis {
  display: grid; gap: 12px; margin-top: 14px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 13px 15px 11px;
}
.tile-label {
  display: flex; align-items: center; gap: 7px;
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted);
}
.tile-label .ic { width: 14px; height: 14px; }
.tile-value {
  font-size: 27px; font-weight: 700; line-height: 1.25; margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.tile-value small { font-size: 14px; font-weight: 600; color: var(--text-2); }
.tile-value.crit { color: #F08A8A; }
.tile-sub { font-size: 12px; color: var(--muted); margin-top: 1px; min-height: 18px; }

/* ---------- panels & layout ---------- */

.grid-main { display: grid; gap: 14px; grid-template-columns: 2fr 1fr; margin-top: 14px; }
.grid-main .span2 { min-width: 0; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 15px 17px 17px; margin-top: 14px; min-width: 0;
}
.grid-main .panel { margin-top: 0; }

.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-bottom: 8px;
}
.panel-head h2 { margin: 0; font-size: 14.5px; font-weight: 700; letter-spacing: 0.02em; }
.panel-note { font-size: 12px; color: var(--muted); }

.controls { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.search { position: relative; }
.search .ic { position: absolute; left: 10px; top: 50%; translate: 0 -50%; color: var(--muted); width: 14px; height: 14px; }
.search input { padding-left: 31px; width: 210px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.seg button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font: 600 12px var(--sans); padding: 5px 10px; transition: background 150ms, color 150ms;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--accent-soft); color: #9CC5F5; }

.empty { padding: 26px 10px; text-align: center; color: var(--muted); font-size: 13.5px; }

.foot { margin-top: 22px; font-size: 12px; color: var(--muted); text-align: center; }

/* ---------- charts ---------- */

.charts { display: grid; gap: 14px; }

.chart-title {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 3px;
}
.swatch { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

.chart { position: relative; height: 108px; }
.chart svg { display: block; width: 100%; height: 100%; }
.chart .gridline { stroke: rgba(148, 163, 184, 0.12); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font: 10.5px var(--sans); }
.chart .crosshair { stroke: var(--line-strong); stroke-width: 1; stroke-dasharray: 3 3; }

.tooltip {
  position: fixed; z-index: 70; pointer-events: none;
  background: var(--bg-deep); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  padding: 6px 10px; font-size: 12px; color: var(--text);
  box-shadow: var(--shadow); white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tooltip .t-time { color: var(--muted); }

/* ---------- traffic bars ---------- */

.bars { display: grid; gap: 9px; margin-top: 10px; }

.bar-row {
  display: grid; grid-template-columns: minmax(90px, 150px) 1fr auto;
  gap: 10px; align-items: center;
  border: 0; background: none; padding: 2px 4px; border-radius: var(--r-sm);
  color: inherit; font: inherit; text-align: left; cursor: pointer;
  transition: background 150ms;
}
.bar-row:hover { background: rgba(148, 163, 184, 0.08); }
.bar-row .bar-name { font-family: var(--mono); font-size: 12.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-track { display: block; height: 14px; border-radius: 4px; background: rgba(148, 163, 184, 0.1); overflow: hidden; }
.bar-row .bar-fill { display: block; height: 100%; border-radius: 4px 0 0 4px; min-width: 2px; }
.bar-row .bar-val { font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- tables ---------- */

.tbl-wrap { overflow-x: auto; }

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line-strong); white-space: nowrap;
}
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tbody tr { transition: background 120ms; }
.tbl tbody tr:hover { background: rgba(148, 163, 184, 0.06); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl th.num { text-align: right; }
.tbl .w-rank { width: 34px; color: var(--muted); }
.tbl .w-dur, .tbl .w-when { width: 92px; white-space: nowrap; }
.tbl .w-schema { width: 150px; }
.tbl .w-state { width: 150px; }
.tbl .w-act { width: 120px; white-space: nowrap; }
.tbl .w-total { width: 130px; }

tr.row-click { cursor: pointer; }

.sql {
  font-family: var(--mono); font-size: 12px; color: var(--text-2);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-all; max-width: 640px; line-height: 1.5;
}

.schema-tag {
  display: inline-block; font-family: var(--mono); font-size: 12px;
  background: rgba(57, 135, 229, 0.12); color: #9CC5F5;
  border: 1px solid rgba(57, 135, 229, 0.28); border-radius: 5px; padding: 1px 7px;
  max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle;
}

.cell-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* duration badges */
.dur { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.dur .ic { width: 13px; height: 13px; }
.dur.ok { color: var(--text-2); }
.dur.warn { color: var(--warn); }
.dur.crit { color: #F08A8A; }
tr.is-crit { background: var(--crit-soft); }
tr.is-crit:hover { background: rgba(208, 59, 59, 0.2); }

/* severity badges — icon + label always together (never color alone) */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  border-radius: 999px; padding: 2px 9px 2px 7px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  border: 1px solid; background: rgba(148, 163, 184, 0.07); cursor: default;
}
.badge .ic { width: 12px; height: 12px; }
.badge.good { color: #57C957; border-color: rgba(12, 163, 12, 0.5); }
.badge.warning { color: var(--warn); border-color: rgba(250, 178, 25, 0.45); }
.badge.serious { color: var(--serious); border-color: rgba(236, 131, 90, 0.5); }
.badge.critical { color: #F08A8A; border-color: rgba(208, 59, 59, 0.55); }
.badges { display: flex; flex-wrap: wrap; gap: 5px; max-width: 340px; }

.load-track { height: 5px; border-radius: 3px; background: rgba(148, 163, 184, 0.12); margin-top: 5px; overflow: hidden; }
.load-fill { height: 100%; border-radius: 3px; background: var(--s1); }

.killed-tag { color: #F08A8A; font-weight: 700; font-size: 11px; letter-spacing: 0.05em; }

/* ---------- drawer ---------- */

.drawer-veil, .modal-veil {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(4, 8, 18, 0.6); backdrop-filter: blur(2px);
}

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 60;
  width: min(660px, 94vw);
  background: var(--bg); border-left: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  animation: slide-in 200ms ease;
}
@keyframes slide-in { from { translate: 40px 0; opacity: 0; } to { translate: 0 0; opacity: 1; } }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.drawer-head h3 { margin: 0; font-size: 15px; }

.drawer-body { padding: 16px 18px 28px; overflow-y: auto; }

.d-section { margin-bottom: 18px; }
.d-section h4 {
  margin: 0 0 8px; font-size: 11.5px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 8px 11px;
}
.stat .s-label { font-size: 11px; color: var(--muted); }
.stat .s-value { font-size: 15.5px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 1px; }

.codeblock {
  position: relative;
  background: var(--bg-deep); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 12px 13px; font-family: var(--mono); font-size: 12.5px; line-height: 1.6;
  color: var(--text-2); white-space: pre-wrap; word-break: break-word;
  max-height: 300px; overflow-y: auto;
}
.codeblock .copy-btn { position: absolute; top: 7px; right: 7px; }

.notes { display: grid; gap: 7px; }
.note { display: flex; gap: 9px; align-items: flex-start; font-size: 13px; color: var(--text-2); }
.note .ic { margin-top: 2px; }
.note.good .ic { color: var(--good); }
.note.warning .ic { color: var(--warn); }
.note.critical .ic { color: var(--crit); }

/* fix guidance */
.fix-item { border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--panel); padding: 10px 12px; }
.fix-item + .fix-item { margin-top: 8px; }
.fix-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 13px; }
.fix-title .ic { color: var(--warn); }
.fix-detail { color: var(--text-2); font-size: 12.5px; margin-top: 4px; }
.fix-item .codeblock { margin-top: 8px; max-height: 140px; font-size: 12px; padding: 9px 11px; }

.prompt-box { border: 1px solid rgba(57, 135, 229, 0.4); border-radius: var(--r-sm); background: var(--accent-soft); }
.prompt-box summary {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 11px 13px; font-weight: 700; font-size: 13px; color: #9CC5F5;
  border-radius: var(--r-sm); list-style: none;
}
.prompt-box summary::-webkit-details-marker { display: none; }
.prompt-box summary .ic { color: #9CC5F5; }
.prompt-box[open] summary { border-bottom: 1px solid rgba(57, 135, 229, 0.3); }
.prompt-box .prompt-body { padding: 10px 13px 13px; }
.prompt-box .prompt-hint { font-size: 12px; color: var(--muted); margin: 0 0 8px; }
.prompt-box .codeblock { max-height: 260px; }

.explain-tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-sm); }
.explain-tbl { border-collapse: collapse; font-size: 12px; min-width: 100%; }
.explain-tbl th, .explain-tbl td { padding: 6px 9px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; font-family: var(--mono); }
.explain-tbl th { color: var(--muted); font-family: var(--sans); text-transform: uppercase; font-size: 10.5px; letter-spacing: 0.05em; }
.explain-tbl tr:last-child td { border-bottom: 0; }
.explain-tbl td.is-all { color: #F08A8A; font-weight: 700; }

/* ---------- modal & toasts ---------- */

.modal-veil { display: grid; place-items: center; z-index: 65; }
.modal {
  width: min(440px, 92vw);
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: var(--r);
  box-shadow: var(--shadow); padding: 20px;
}
.modal h3 { margin: 0 0 8px; font-size: 15.5px; }
.modal p { margin: 0 0 16px; color: var(--text-2); font-size: 13.5px; word-break: break-word; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; }

.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 80; display: grid; gap: 8px; }
.toast {
  background: var(--bg-deep); border: 1px solid var(--line-strong); border-left: 3px solid var(--accent);
  border-radius: var(--r-sm); box-shadow: var(--shadow);
  padding: 10px 14px; font-size: 13px; max-width: 360px;
  animation: toast-in 200ms ease;
}
.toast.err { border-left-color: var(--crit); }
.toast.ok { border-left-color: var(--good); }
@keyframes toast-in { from { translate: 0 8px; opacity: 0; } to { translate: 0 0; opacity: 1; } }

/* ---------- login ---------- */

.logout-form { display: inline; }

.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: min(380px, 92vw); display: grid; gap: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 28px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0; font-size: 17px; letter-spacing: 0.03em; }
.login-sub { margin: -6px 0 0; color: var(--muted); font-size: 13px; }
.login-error {
  margin: 0; color: #F08A8A; font-size: 13px;
  background: var(--crit-soft); border: 1px solid rgba(208, 59, 59, 0.4);
  border-radius: var(--r-sm); padding: 9px 11px;
}
.login-card .field { display: grid; gap: 5px; }
.login-card .f-label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.login-card .input { width: 100%; }
.login-card .remember {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--text-2); cursor: pointer;
}
.login-card .remember input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.login-card .btn { justify-content: center; }
.login-hint {
  margin: 2px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.6;
  border-top: 1px solid var(--line); padding-top: 12px;
}
.login-hint code { font-family: var(--mono); color: var(--text-2); font-size: 11px; }

/* ---------- responsive ---------- */

@media (max-width: 1100px) {
  .grid-main { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  body { font-size: 14px; }
  .app { padding: 0 12px 30px; }
  /* wrapped multi-row header can't be sticky without occluding content */
  .topbar { position: static; background: none; flex-direction: column; align-items: stretch; }
  .topbar-right { justify-content: flex-start; }
  .tile-value { font-size: 22px; }
  .search input { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
