/* ── PDAQR design system ─────────────────────────────────────────────────── */
:root {
  --bg: #080b12;
  --bg-soft: #0d1119;
  --surface: #121824;
  --surface-2: #182031;
  --surface-3: #1e293c;
  --border: #212c40;
  --border-soft: #18212f;
  --text: #e9eff9;
  --muted: #8a9ab4;
  --faint: #5d6f8c;
  --accent: #5b8cff;
  --accent-2: #a06bff;
  --accent-soft: rgba(91, 140, 255, .14);
  --ok: #2ecc71;
  --ok-soft: rgba(46, 204, 113, .14);
  --warn: #f5a623;
  --warn-soft: rgba(245, 166, 35, .14);
  --danger: #ff4d6a;
  --danger-soft: rgba(255, 77, 106, .14);
  --info: #38bdf8;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .38);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .5);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Fira Code", Menlo, monospace;
  --sidebar-w: 244px;
}

html[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-soft: #eef1f8;
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --surface-3: #eef2f9;
  --border: #dfe5f0;
  --border-soft: #e9edf5;
  --text: #101828;
  --muted: #5b6b85;
  --faint: #8494ab;
  --accent-soft: rgba(91, 140, 255, .12);
  --shadow: 0 6px 24px rgba(16, 24, 40, .07);
  --shadow-lg: 0 20px 50px rgba(16, 24, 40, .12);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 620; letter-spacing: -.02em; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ── Shell ─────────────────────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-soft);
  border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  z-index: 40;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 20px 18px 18px;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: #fff; flex: 0 0 auto;
  box-shadow: 0 4px 14px rgba(91, 140, 255, .35);
}
.brand-name { font-weight: 650; font-size: 15px; letter-spacing: -.02em; }
.brand-sub { font-size: 11px; color: var(--faint); letter-spacing: .04em; text-transform: uppercase; }

.nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--faint); padding: 14px 10px 6px; font-weight: 600; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: 10px; color: var(--muted);
  font-weight: 500; font-size: 13.5px; transition: background .13s, color .13s;
}
.nav a:hover { background: var(--surface); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav a svg { width: 17px; height: 17px; flex: 0 0 auto; }
.nav-badge { margin-left: auto; font-size: 11px; background: var(--surface-3); color: var(--muted); padding: 1px 7px; border-radius: 20px; font-weight: 600; }

.sidebar-foot { padding: 12px; border-top: 1px solid var(--border-soft); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; }
.user-chip:hover { background: var(--surface); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 24px; border-bottom: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
}
.topbar h1 { font-size: 18px; }
.topbar .spacer { flex: 1; }
.page { padding: 22px 24px 60px; max-width: 1500px; width: 100%; }

.btn.burger { display: none; }

@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after {
    content: ''; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 35;
  }
  .btn.burger { display: inline-flex; }
  .page { padding: 16px 14px 60px; }
  .topbar { padding: 12px 14px; }
}

/* ── Primitives ────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h3 { font-size: 14.5px; }
.card-head .spacer { flex: 1; }
.card-sub { font-size: 12.5px; color: var(--muted); font-weight: 400; }

.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: 2fr 1fr; }
.g-1-2 { grid-template-columns: 1fr 2fr; }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g-2-1, .g-1-2 { grid-template-columns: 1fr; } }
@media (max-width: 720px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 550; font-size: 13px; cursor: pointer;
  transition: background .13s, border-color .13s, transform .08s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: linear-gradient(135deg, var(--accent), #4a7bf0); border-color: transparent; color: #fff; box-shadow: 0 3px 12px rgba(91,140,255,.28); }
.btn-primary:hover { filter: brightness(1.08); background: linear-gradient(135deg, var(--accent), #4a7bf0); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 32%, transparent); background: var(--danger-soft); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 22%, transparent); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn-icon { padding: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.lang-toggle { min-width: 38px; padding-inline: 9px; font-weight: 750; letter-spacing: .04em; }

.input, select, textarea {
  width: 100%; padding: 9px 11px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font: inherit; font-size: 13.5px; outline: none;
  transition: border-color .13s, box-shadow .13s;
}
.input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: var(--faint); }
select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a9ab4' stroke-width='3'><path d='M6 9l6 6 6-6'/></svg>"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
label.field { display: block; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 550; }

.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--faint); pointer-events: none; }
.search .input { padding-left: 32px; }

.toolbar { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .grow { flex: 1; min-width: 180px; }

/* ── KPI ───────────────────────────────────────────────────────────────── */
.kpi { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 15px 16px; position: relative; overflow: hidden; }
.kpi::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--accent); opacity: .8; }
.kpi.ok::before { background: var(--ok); }
.kpi.warn::before { background: var(--warn); }
.kpi.danger::before { background: var(--danger); }
.kpi.info::before { background: var(--info); }
.kpi-label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.kpi-value { font-size: 27px; font-weight: 680; letter-spacing: -.03em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: 14px; font-weight: 550; color: var(--muted); margin-left: 3px; }
.kpi-foot { font-size: 12px; color: var(--faint); margin-top: 3px; }

/* ── Table ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border-soft); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 10px 14px; font-size: 11px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .06em; color: var(--faint);
  background: var(--surface-2); border-bottom: 1px solid var(--border-soft);
  position: sticky; top: 0; white-space: nowrap;
}
tbody td { padding: 10px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12px; }

/* ── Bits ──────────────────────────────────────────────────────────────── */
.avatar {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto;
  display: grid; place-items: center; font-weight: 650; font-size: 12.5px;
  background: var(--surface-3); color: var(--muted); letter-spacing: .02em;
}
.avatar.lg { width: 56px; height: 56px; font-size: 19px; border-radius: 16px; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; border-radius: 8px; }
.person-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.person-cell .nm { font-weight: 560; }
.person-cell .sub { font-size: 11.5px; color: var(--faint); }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2.5px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 620;
  background: var(--surface-3); color: var(--muted); white-space: nowrap;
}
.chip.in, .chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.out { background: var(--surface-3); color: var(--muted); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.dot.pulse { animation: pulse 1.8s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button { border: none; background: transparent; color: var(--muted); font: inherit; font-size: 12.5px; font-weight: 570; padding: 6px 12px; border-radius: 7px; cursor: pointer; transition: .13s; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.2); }

.empty { text-align: center; padding: 44px 20px; color: var(--faint); }
.empty svg { width: 34px; height: 34px; margin-bottom: 10px; opacity: .5; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.right { text-align: right; }
.row { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.sep { height: 1px; background: var(--border-soft); margin: 14px 0; }
.tabular { font-variant-numeric: tabular-nums; }

/* ── Modal ─────────────────────────────────────────────────────────────── */
.modal-back {
  position: fixed; inset: 0; background: rgba(4, 7, 14, .68);
  backdrop-filter: blur(3px); z-index: 100;
  display: grid; place-items: center; padding: 18px;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow-lg);
  width: min(560px, 100%); max-height: 90vh; overflow-y: auto;
  animation: rise .19s cubic-bezier(.2,.8,.3,1);
}
.modal.wide { width: min(860px, 100%); }
@keyframes rise { from { transform: translateY(14px) scale(.985); opacity: 0; } }
.modal-head { display: flex; align-items: center; padding: 18px 20px 4px; }
.modal-head h3 { font-size: 16px; flex: 1; }
.modal-body { padding: 16px 20px; display: grid; gap: 13px; }
.modal-foot { display: flex; gap: 9px; justify-content: flex-end; padding: 4px 20px 20px; }

/* ── Toast ─────────────────────────────────────────────────────────────── */
#toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 9px; }
.toast {
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 11px 15px; border-radius: 10px; box-shadow: var(--shadow);
  font-size: 13px; font-weight: 520; max-width: 340px;
  animation: slidein .2s cubic-bezier(.2,.8,.3,1);
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }
@media (max-width: 600px) { #toasts { left: 12px; right: 12px; bottom: 12px; } .toast { max-width: none; } }

/* ── Charts ────────────────────────────────────────────────────────────── */
.chart { width: 100%; display: block; overflow: visible; }
.chart text { font-family: var(--sans); font-size: 10.5px; fill: var(--faint); }
.chart .grid-line { stroke: var(--border-soft); stroke-width: 1; }
.chart .bar { transition: opacity .12s; }
.chart .bar:hover { opacity: .78; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; margin-right: 5px; }
.heat-cell { rx: 2; }
.spark { height: 40px; }
.tip {
  position: fixed; z-index: 300; pointer-events: none;
  background: var(--surface-3); border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 8px; font-size: 12px; box-shadow: var(--shadow);
  white-space: nowrap; transform: translate(-50%, -130%);
}

/* ── Loading ───────────────────────────────────────────────────────────── */
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.bar-track { height: 6px; border-radius: 6px; background: var(--surface-3); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
