:root {
  color-scheme: dark;
  --bg: #0d1117;
  --surface: #151b23;
  --surface-2: #1c232d;
  --border: #262f3b;
  --text: #f0f3f6;
  --text-2: #c3c9d1;
  --muted: #8b95a3;
  --s1: #3987e5; /* blue */
  --s2: #d95926; /* orange */
  --s3: #199e70; /* aqua */
  --s4: #c98500; /* yellow */
  --ok: #2ea043;
  --warn: #d29922;
  --crit: #e5534b;
  --radius: 10px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; -webkit-font-smoothing: antialiased; }
h1, h2, p { margin: 0; }
.muted { color: var(--muted); }
button { font: inherit; color: inherit; }

/* ---------- Buttons ---------- */
.btn { border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
.btn:hover { border-color: #3a4656; }
.btn:focus-visible, .seg button:focus-visible, input:focus-visible, th.sortable:focus-visible { outline: 2px solid var(--s1); outline-offset: 2px; }
.btn-primary { background: var(--s1); border-color: var(--s1); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #2f79d4; }
.btn-primary:disabled { opacity: .6; cursor: wait; }
.btn-ghost { background: transparent; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; background: rgba(13, 17, 23, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.host { min-width: 0; }
.host h1 { font-size: 16px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.host p { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid var(--border); background: var(--surface); white-space: nowrap; }
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.badge-live { color: #7ee2a0; border-color: #1f4d2e; }
.badge-live .dot { background: var(--ok); animation: pulse 2s infinite; }
.badge-wait { color: #f0c96a; border-color: #5a4613; }
.badge-wait .dot { background: var(--warn); }
.badge-off { color: #ff9b95; border-color: #5c2320; }
.badge-off .dot { background: var(--crit); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .badge-live .dot { animation: none; } }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 6px 10px; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--surface-2); color: var(--text); font-weight: 600; }

.banner { margin: 12px 20px 0; padding: 10px 14px; border-radius: 8px; border: 1px solid #5c2320; background: #2a1413; color: #ffc9c5; font-size: 13px; }

/* ---------- Layout ---------- */
main { padding: 16px 20px 8px; display: grid; gap: 16px; max-width: 1600px; margin: 0 auto; }
.foot { text-align: center; font-size: 12px; padding: 12px 0 24px; }

/* ---------- Cards ---------- */
.cards { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.card h2 { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; display: flex; align-items: center; gap: 6px; }
.card .val { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .bar { height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.card .bar i { display: block; height: 100%; width: 0; border-radius: 2px; background: var(--ok); transition: width .4s ease; }
.card .lvl { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 999px; text-transform: none; letter-spacing: 0; }
.card[data-level="ok"] .bar i { background: var(--ok); }
.card[data-level="warn"] .bar i { background: var(--warn); }
.card[data-level="crit"] .bar i { background: var(--crit); }
.card[data-level="warn"] { border-color: #5a4613; }
.card[data-level="crit"] { border-color: #6b2522; }
.card[data-level="warn"] .lvl { background: #3a2e0c; color: #f0c96a; }
.card[data-level="crit"] .lvl { background: #3d1614; color: #ff9b95; }

/* ---------- Panels & charts ---------- */
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.panel > header { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.panel h2 { font-size: 14px; font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); }
.chart { width: 100%; min-height: 220px; }

.cores { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.core { background: var(--surface-2); border-radius: 8px; padding: 6px 8px 2px; min-width: 0; }
.core-head { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.core-head b { color: var(--text); font-weight: 600; }
.core-plot { width: 100%; height: 72px; }

/* uPlot dark tweaks */
.uplot { font-family: inherit; }
.uplot .u-legend { font-size: 12px; color: var(--text-2); text-align: left; padding-top: 4px; }
.uplot .u-legend .u-series th { font-weight: 500; }
.uplot .u-legend .u-series td { font-variant-numeric: tabular-nums; }
.uplot .u-legend .u-marker { width: 10px; height: 3px; border-radius: 2px; }
.uplot .u-cursor-x, .uplot .u-cursor-y { border-color: #56627180 !important; }
.uplot .u-select { background: rgba(57, 135, 229, .12); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface); position: sticky; top: 0; }
th.num, td.num { text-align: right; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sortable[aria-sort]::after { content: " ↓"; color: var(--s1); }
th.sortable[aria-sort="ascending"]::after { content: " ↑"; }
tbody tr:hover td { background: var(--surface-2); }
tr.empty td { text-align: center; color: var(--muted); padding: 20px; white-space: normal; }
td .name { font-weight: 600; color: var(--text); max-width: 280px; overflow: hidden; text-overflow: ellipsis; display: inline-block; vertical-align: bottom; }
td .dim { color: var(--muted); font-size: 12px; }
td .meter { display: inline-block; width: 48px; height: 4px; border-radius: 2px; background: var(--surface-2); margin-left: 8px; vertical-align: middle; overflow: hidden; }
td .meter i { display: block; height: 100%; background: var(--s1); border-radius: 2px; }
.state { display: inline-flex; align-items: center; gap: 6px; }
.state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.state.running::before { background: var(--ok); }
.state.exited::before, .state.dead::before { background: var(--crit); }
.state.restarting::before, .state.paused::before { background: var(--warn); }

.stale { opacity: .55; transition: opacity .3s; }

/* ---------- Login ---------- */
.login-body { display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px 24px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.brand h1 { font-size: 18px; }
.brand p { font-size: 12px; }
#login-form { display: grid; gap: 10px; }
#login-form label { font-size: 13px; color: var(--text-2); }
#login-form input { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 15px; }
#login-form .btn { padding: 10px 12px; margin-top: 6px; }
.form-error { color: #ff9b95; font-size: 13px; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .charts { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .topbar { padding: 10px 12px; }
  .topbar-right { width: 100%; justify-content: space-between; }
  main { padding: 12px 12px 8px; gap: 12px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .card { padding: 10px 12px; }
  .card .val { font-size: 20px; }
  .charts { gap: 12px; }
  .cores { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .banner { margin: 10px 12px 0; }
  th, td { padding: 7px 8px; }
  td .meter { display: none; }
}

/* Live: umur data terakhir di dalam badge */
.badge-age { font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 0; }
.badge-age:not(:empty)::before { content: "· "; }
.badge-lag { color: #f0c96a; border-color: #5a4613; }
.badge-lag .dot { background: var(--warn); animation: none; }
