:root {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #1c2230; --muted: #667085; --line: #e4e7ec; --soft: #f2f4f7;
  --brand: #1f5eff; --brand-ink: #ffffff; --brand-soft: #e8eeff;
  --good: #12805c; --good-soft: #e3f5ee; --warn: #b54708; --warn-soft: #fff1e0; --bad: #c0362c; --bad-soft: #fde8e7; --info: #475467; --info-soft: #eef0f3;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--ink); line-height: 1.45; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* layout */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: #111827; color: #d0d5dd; padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { color: #fff; font-weight: 700; font-size: 16px; padding: 4px 10px 16px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--brand); display: inline-block; }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: 8px; color: #d0d5dd; margin-bottom: 2px; }
.nav a:hover { background: #1f2937; text-decoration: none; color: #fff; }
.nav a.active { background: #1f2937; color: #fff; font-weight: 600; }
.nav .sep { border-top: 1px solid #1f2937; margin: 10px 4px; }
.nav .badge { background: #374151; color: #fff; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar .grow { flex: 1; }
.content { padding: 20px 24px 60px; max-width: 1400px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.menu-btn { display: none; }

/* components */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .v { font-size: 22px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: 7px 12px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.link { border: none; background: none; color: var(--brand); padding: 0; }

input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; color: var(--ink); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea { width: 100%; min-height: 70px; resize: vertical; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { font-size: 14px; color: var(--ink); }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form .full { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--info-soft); color: var(--info); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }

.alert { padding: 10px 12px; border-radius: 8px; background: var(--info-soft); margin-bottom: 12px; font-size: 13px; }
.alert.warn { background: var(--warn-soft); color: #7a2e0e; }
.alert.bad { background: var(--bad-soft); color: #7a1f17; }
.alert.good { background: var(--good-soft); color: #0b5a40; }

/* tabel */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 13px; }
th { background: var(--soft); font-weight: 600; color: #344054; position: sticky; top: 0; white-space: nowrap; }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--brand); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fafbff; }
tr.sel td { background: var(--brand-soft); }
td.cb, th.cb { width: 32px; }
td .trunc { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 8px 0; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar .sel-info { color: var(--muted); font-size: 12px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 12px; background: #fff; cursor: pointer; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.progress { height: 8px; background: var(--soft); border-radius: 999px; overflow: hidden; min-width: 80px; }
.progress > span { display: block; height: 100%; background: var(--brand); }
.progress.good > span { background: var(--good); }

/* modal & drawer */
.overlay { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 20px 40px rgba(0,0,0,.2); }
.modal.wide { max-width: 980px; }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 16px 18px; max-height: 70vh; overflow-y: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.x { border: none; background: none; font-size: 20px; cursor: pointer; color: var(--muted); }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(720px, 100vw); background: var(--panel); box-shadow: -8px 0 30px rgba(0,0,0,.15); z-index: 40; display: flex; flex-direction: column; }
.drawer .modal-body { max-height: none; flex: 1; }

.toast-box { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #111827; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 420px; font-size: 13px; }
.toast.bad { background: var(--bad); }
.toast.good { background: var(--good); }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 13px; }
.kv .k { color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.bar-compare { display: grid; grid-template-columns: 80px 1fr 1fr; gap: 4px 10px; align-items: center; font-size: 12px; }
.bar { height: 10px; background: var(--soft); border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: #98a2b3; }
.bar.actual > span { background: var(--brand); }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
.login .brand { color: var(--ink); padding: 0 0 12px; font-size: 20px; }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 40px; text-align: center; color: var(--muted); }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -240px; width: 220px; z-index: 60; transition: left .2s; }
  .sidebar.open { left: 0; }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .grid.cols-2, .grid.cols-3, .form { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
}
