:root {
  --bg: #0f1319;
  --bg-soft: #151b24;
  --panel: #1a212c;
  --panel-2: #202836;
  --line: #2a3444;
  --text: #e6ecf5;
  --muted: #8d9aae;
  --accent: #ff6d5a;
  --accent-soft: rgba(255, 109, 90, .14);
  --ok: #35c88a;
  --bad: #f2555a;
  --warn: #f0a92b;
  --info: #4d9dff;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0, 0, 0, .28);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --bg-soft: #eef1f7;
    --panel: #ffffff;
    --panel-2: #f7f9fc;
    --line: #dfe5ee;
    --text: #172033;
    --muted: #66748c;
    --accent: #e8543f;
    --accent-soft: rgba(232, 84, 63, .12);
    --shadow: 0 6px 18px rgba(20, 30, 50, .08);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 "Segoe UI", Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 226px;
  flex: 0 0 226px;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft);
}
.brand strong { display: block; font-size: 15px; }
.brand small { color: var(--muted); font-size: 11.5px; letter-spacing: .12em; text-transform: uppercase; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  padding: 9px 12px; border-radius: 9px; color: var(--muted);
  font-weight: 500; transition: background .15s, color .15s;
}
.sidebar nav a:hover { background: var(--panel); color: var(--text); }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 6px; }
.who { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.version { font-size: 11px; color: var(--muted); opacity: .75; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 22px; border-bottom: 1px solid var(--line);
  background: var(--bg-soft); position: sticky; top: 0; z-index: 5;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title p { margin: 2px 0 0; font-size: 12.5px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.content { padding: 22px; display: flex; flex-direction: column; gap: 18px; }

/* ---------- komponen ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.kpi { padding: 15px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .07em; }
.kpi .value { font-size: 26px; font-weight: 680; margin-top: 6px; letter-spacing: -.02em; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.bad .value { color: var(--bad); }
.kpi.ok .value { color: var(--ok); }
.kpi.warn .value { color: var(--warn); }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  border: 1px solid transparent; white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-ok { color: var(--ok); background: rgba(53, 200, 138, .12); }
.pill-bad { color: var(--bad); background: rgba(242, 85, 90, .13); }
.pill-warn { color: var(--warn); background: rgba(240, 169, 43, .13); }
.pill-info { color: var(--info); background: rgba(77, 157, 255, .13); }
.pill-muted { color: var(--muted); background: var(--panel-2); }
.pill-plain::before { display: none; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  background: var(--panel-2); border: 1px solid var(--line);
  color: var(--muted); font-size: 11px; margin-right: 4px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--bad); border-color: rgba(242, 85, 90, .4); background: rgba(242, 85, 90, .08); }

.icon-btn {
  background: transparent; border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 16px;
}

input[type=text], input[type=search], input[type=password], select {
  padding: 8px 11px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font: inherit; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters .grow { flex: 1; min-width: 180px; }

/* ---------- tabel ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 10px 14px; color: var(--muted);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em;
  border-bottom: 1px solid var(--line); white-space: nowrap; font-weight: 600;
}
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }
td.nowrap, th.nowrap { white-space: nowrap; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.link { color: var(--info); font-weight: 600; }
.link:hover { text-decoration: underline; }

.empty { padding: 34px 16px; text-align: center; color: var(--muted); }

/* ---------- grafik batang ---------- */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 132px; padding: 4px 0; }
.chart .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; height: 100%; position: relative; }
.chart .seg-ok { background: var(--ok); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.chart .seg-bad { background: var(--bad); border-radius: 3px 3px 0 0; min-height: 2px; }
.chart .bar:hover::after {
  content: attr(data-tip); position: absolute; bottom: 100%; left: 50%;
  transform: translateX(-50%); white-space: nowrap; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 7px; padding: 5px 9px;
  font-size: 11.5px; z-index: 3; box-shadow: var(--shadow);
}
.chart-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }

.bar-line { height: 6px; border-radius: 999px; background: var(--panel-2); overflow: hidden; min-width: 60px; }
.bar-line > span { display: block; height: 100%; background: var(--bad); }

/* ---------- lain-lain ---------- */
.stack { display: flex; flex-direction: column; gap: 4px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.divide > * + * { border-top: 1px solid var(--line); }
.list-item { padding: 12px 16px; display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }

.msg-body {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 11px; white-space: pre-wrap; word-break: break-word; max-width: 620px;
}
pre.code {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
  padding: 12px; overflow-x: auto; font-size: 12px; margin: 0;
  white-space: pre-wrap; word-break: break-word; max-height: 340px;
}
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 8px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 16px; }

.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 50;
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 12px 16px; box-shadow: var(--shadow); max-width: 380px;
}
.toast.ok { border-left-color: var(--ok); }
.toast.bad { border-left-color: var(--bad); }

.only-mobile { display: none; }

@media (max-width: 900px) {
  .sidebar {
    position: fixed; z-index: 20; left: 0; top: 0; transform: translateX(-100%);
    transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .only-mobile { display: inline-flex; align-items: center; justify-content: center; }
  .content { padding: 16px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; }
}

/* ---------- chip topik pertanyaan ---------- */
.topic {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 11px; border-radius: 9px; border: 1px solid var(--line);
  font-size: 12.5px; line-height: 1.2; transition: border-color .15s, transform .15s;
  /* lebar isian = seberapa sering topik itu muncul */
  background: linear-gradient(
    to right,
    var(--accent-soft) var(--bobot, 0%),
    var(--panel-2) var(--bobot, 0%)
  );
}
.topic:hover { border-color: var(--accent); transform: translateY(-1px); }
.topic strong { color: var(--accent); font-variant-numeric: tabular-nums; }
