/* ===== Tokens ===== */
:root {
    --bg: #0d1117;
    --surface: #151b23;
    --surface-2: #1c2430;
    --border: #273141;
    --text: #e6edf3;
    --muted: #8b98a9;
    --accent: #3fb68b;
    --ok: #3fb68b;
    --warn: #e3a33b;
    --crit: #e5534b;
    --up: #f0883e;
    --down: #4c9aff;
    --cpu: #4c9aff;
    --mem: #b083f0;
    --load: #3fb68b;
    --grid: rgba(139, 152, 169, .14);
    --radius: 12px;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
}
@media (prefers-color-scheme: light) {
    :root {
        --bg: #f4f6f9;
        --surface: #ffffff;
        --surface-2: #f0f3f7;
        --border: #dde3ea;
        --text: #18212c;
        --muted: #627083;
        --grid: rgba(98, 112, 131, .14);
        --shadow: 0 1px 3px rgba(16, 24, 40, .06);
        --down: #2f7de1;
        --cpu: #2f7de1;
        --mem: #8a5cd6;
        --ok: #1f9d6f;
        --load: #1f9d6f;
        --accent: #1f9d6f;
        color-scheme: light;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 16px; }
h2 { font-size: 15px; }
h3 { font-size: 14px; }
code { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.inline { display: inline; margin: 0; }
b { font-variant-numeric: tabular-nums; }

/* ===== Buttons / inputs ===== */
.btn {
    font: inherit; cursor: pointer; border-radius: 8px; padding: 8px 14px;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; width: 100%; padding: 11px; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; padding: 6px 12px; font-size: 13px; }
input[type=text], input[type=password] {
    width: 100%; font: inherit; color: var(--text); background: var(--bg);
    border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin: 4px 0 14px;
}
input:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { font-size: 13px; color: var(--muted); }

.alert { border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; font-size: 13px; border: 1px solid; }
.alert.error { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 40%, transparent); background: color-mix(in srgb, var(--crit) 10%, transparent); }
.alert.warn  { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: color-mix(in srgb, var(--warn) 10%, transparent); }

/* ===== Brand ===== */
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo { width: 34px; height: 34px; flex: none; display: block; object-fit: contain; border-radius: 9px; }
@media (prefers-color-scheme: dark) {
    .brand-logo { background: #fff; padding: 3px; }
}

/* ===== Login ===== */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-wrap { width: 100%; max-width: 380px; }
.login-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 28px; box-shadow: var(--shadow);
}
.login-card .brand { margin-bottom: 22px; }
.login-card .small { margin: 14px 0 0; text-align: center; }

/* ===== Layout ===== */
.topbar {
    position: sticky; top: 0; z-index: 5;
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    padding: 12px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.topbar p { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.container { max-width: 1320px; margin: 0 auto; padding: 20px 24px 40px; }
.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.grid.gauges { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0;
}
.grid > .card { margin-bottom: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.sub { margin: 18px 0 10px; font-size: 13px; color: var(--muted); font-weight: 500; }

/* ===== Pills ===== */
.pill {
    display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500;
    padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.live .dot { background: var(--ok); box-shadow: 0 0 0 0 var(--ok); animation: pulse 2s infinite; }
.pill.err .dot { background: var(--crit); }
.pill.paused .dot { background: var(--warn); }
.pill.subtle { color: var(--muted); }
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); }
    70% { box-shadow: 0 0 0 6px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}
@media (prefers-reduced-motion: reduce) { .pill.live .dot { animation: none; } }

/* ===== Gauges ===== */
.gauge-card { display: flex; align-items: center; gap: 16px; }
.gauge { position: relative; width: 96px; height: 96px; flex: none; --c: var(--ok); }
.gauge[data-level=warn] { --c: var(--warn); }
.gauge[data-level=crit] { --c: var(--crit); }
.gauge svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.gauge circle { fill: none; stroke-width: 10; }
.gauge .track { stroke: var(--surface-2); }
.gauge .bar { stroke: var(--c); stroke-linecap: round; transition: stroke-dasharray .6s ease, stroke .3s; }
.gauge-value { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.gauge-value .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.gauge-value small { color: var(--muted); font-size: 11px; }
.gauge-info { min-width: 0; }
.gauge-info p { margin: 2px 0 0; }
.gauge-info .status { font-weight: 600; color: var(--c, var(--text)); }
.gauge-card:has(.gauge[data-level=ok]) .status { color: var(--ok); }
.gauge-card:has(.gauge[data-level=warn]) .status { color: var(--warn); }
.gauge-card:has(.gauge[data-level=crit]) .status { color: var(--crit); }

/* ===== Charts ===== */
.chart-box { position: relative; width: 100%; }
.chart-box canvas { display: block; width: 100%; height: 220px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend b { color: var(--text); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.sw.up { background: var(--up); } .sw.down { background: var(--down); }
.sw.cpu { background: var(--cpu); } .sw.mem { background: var(--mem); } .sw.load { background: var(--load); }
.stats-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.stats-row div { display: flex; flex-direction: column; }
.stats-row b { font-size: 15px; }

/* ===== Detail list ===== */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.cores { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px 14px; }
.core { font-size: 12px; }
.core .row { display: flex; justify-content: space-between; color: var(--muted); }

/* ===== Bars & tables ===== */
.meter { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--ok); border-radius: inherit; transition: width .5s; }
.meter > span.warn { background: var(--warn); } .meter > span.crit { background: var(--crit); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 0 8px 8px; border-bottom: 1px solid var(--border); }
td { padding: 9px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.w-bar { width: 34%; }
td .meter { margin-top: 4px; min-width: 80px; }

/* ===== Responsive ===== */
@media (max-width: 1100px) { .grid.gauges { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px)  { .grid.two { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 600px) {
    .topbar, .container { padding-left: 16px; padding-right: 16px; }
    .grid.gauges { grid-template-columns: minmax(0, 1fr); }
    .stats-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .gauge { width: 84px; height: 84px; }
}

/* ===== Navigasi, user & admin ===== */
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 8px; font-size: 13px; font-weight: 500; }
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--text); background: var(--surface-2); }
.user-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.badge.admin { color: var(--down); border-color: color-mix(in srgb, var(--down) 40%, transparent); background: color-mix(in srgb, var(--down) 10%, transparent); }
.badge.staff { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.state { font-size: 12px; font-weight: 500; }
.state.on { color: var(--ok); } .state.off { color: var(--crit); }
.alert.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn.danger { color: var(--crit); }
.btn.block { display: block; text-align: center; margin-top: 8px; text-decoration: none; }
a.btn { text-decoration: none; display: inline-block; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 4px; flex-wrap: wrap; }
td.wrap { white-space: normal; min-width: 180px; }
.users-grid { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
.form select, .search input {
    width: 100%; font: inherit; color: var(--text); background: var(--bg);
    border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin: 4px 0 14px;
}
.form .check { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; color: var(--text); }
.search { display: flex; gap: 8px; }
.search input { margin: 0; padding: 6px 10px; min-width: 220px; }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 14px; }
.otp-input { text-align: center; font-size: 24px; letter-spacing: .4em; font-variant-numeric: tabular-nums; }
.otp-actions { display: flex; justify-content: space-between; margin-top: 12px; }
@media (max-width: 1000px) { .users-grid { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 600px) { .search input { min-width: 0; } .nav { order: 3; width: 100%; } }
