/* TintServer dashboard */
:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100; --series-5: #e87ba4; --series-6: #008300; --series-other: #a9a8a1;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-ink: #006300;
  --critical-ink: #b02828;
  --grid: #e8e7e3;
  --axis: #c9c8c2;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121211; --surface-1: #1a1a19; --surface-2: #242422; --border: #31312e;
    --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8f8e86;
    --accent: #3987e5; --accent-ink: #86b6ef;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181; --series-6: #008300; --series-other: #6f6e68;
    --good-ink: #5fd35f; --critical-ink: #f08a8a;
    --grid: #2a2a28; --axis: #45453f; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface-1: #1a1a19; --surface-2: #242422; --border: #31312e;
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8f8e86;
  --accent: #3987e5; --accent-ink: #86b6ef;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181; --series-6: #008300; --series-other: #6f6e68;
  --good-ink: #5fd35f; --critical-ink: #f08a8a;
  --grid: #2a2a28; --axis: #45453f; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent-ink); }
.num, td.n, th.n { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
small, .muted { color: var(--text-muted); }

/* ---------- tombol & input */
.btn {
  border: 1px solid var(--border); background: var(--surface-1); border-radius: 8px;
  padding: 7px 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--critical-ink); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.icon { width: 32px; padding: 4px 0; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: default; }
input, select {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; min-width: 0;
}
input:focus-visible, select:focus-visible, .btn:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* ---------- login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 18px; margin: 4px 0 6px; }
.login-card label { display: grid; gap: 4px; font-size: 13px; color: var(--text-secondary); }
.login-card input { padding: 9px 11px; }
.login-foot { display: flex; justify-content: flex-end; }
.form-error { color: var(--critical-ink); min-height: 1.2em; margin: 0; font-size: 13px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; flex: none;
  background: linear-gradient(135deg, var(--series-1) 0 50%, var(--series-2) 50% 100%);
}

/* ---------- tata letak */
.app { display: grid; grid-template-columns: 216px minmax(0, 1fr); min-height: 100%; }
.side {
  background: var(--surface-1); border-right: 1px solid var(--border); padding: 16px 10px;
  display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh;
}
.side .brand { padding: 0 8px; }
.nav { display: grid; gap: 2px; overflow: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--text-secondary); text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--text-primary); }
.nav a.active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--text-primary); font-weight: 600; }
.nav a .badge { margin-left: auto; }
.nav svg { width: 17px; height: 17px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.side-foot { margin-top: auto; display: grid; gap: 6px; padding: 0 6px; }
.who { display: grid; padding: 0 4px 6px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.who small { font-size: 12px; }
.side-foot .btn { text-align: left; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px); border-bottom: 1px solid var(--border);
  padding: 10px 20px; display: flex; gap: 12px; align-items: flex-start; justify-content: space-between;
}
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters select { max-width: 190px; }
.f-date { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-muted); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-1); }
.seg button { border: 0; background: transparent; padding: 5px 10px; cursor: pointer; font-size: 13px; color: var(--text-secondary); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent); color: #fff; }
.top-right { display: flex; align-items: center; gap: 8px; }
.updated { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.view { padding: 20px; display: grid; gap: 16px; outline: none; max-width: 1500px; width: 100%; }
.view h1 { font-size: 20px; margin: 0; }
.page-head { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

/* ---------- kartu & grid */
.grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; box-shadow: var(--shadow); }
.card > h2, .card-head h2 { font-size: 14px; margin: 0; font-weight: 600; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card > h2 { margin-bottom: 12px; }
.card-head .sub, .card .sub { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.card.flush { padding: 0; }
.card.flush .card-head { padding: 14px 16px 0; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.kpi .k-label { font-size: 12px; color: var(--text-secondary); }
.kpi .k-val { font-size: 24px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; line-height: 1.2; }
.kpi .k-val.sm { font-size: 16px; }
.kpi .k-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.delta { font-weight: 600; }
.delta.up { color: var(--good-ink); }
.delta.down { color: var(--critical-ink); }

/* ---------- tabel */
.table-wrap { overflow: auto; max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--text-secondary); font-size: 12px; white-space: nowrap; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th { position: sticky; top: 0; background: var(--surface-1); z-index: 1; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover, tbody tr:focus-visible { background: var(--surface-2); }
td .ellipsis { display: inline-block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 16px; font-size: 13px; color: var(--text-secondary); }

.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.sw.lg { width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: none; }
.badge.good, .badge.bad, .badge.warn, .badge.off { color: var(--text-primary); }
.badge.good::before { display: block; background: var(--good); }
.badge.bad::before { display: block; background: var(--critical); }
.badge.warn::before { display: block; background: var(--warning); }
.badge.off::before { display: block; background: var(--text-muted); }
.badge.count { background: var(--critical); color: #fff; font-weight: 600; padding: 0 7px; }

/* level canister */
.level { display: flex; align-items: center; gap: 8px; min-width: 150px; }
.level-track { flex: 1; height: 8px; border-radius: 4px; background: var(--surface-2); position: relative; overflow: hidden; }
.level-fill { position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: var(--series-1); }
.level-fill.low { background: var(--critical); }
.level-warn { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text-muted); }

/* ---------- grafik */
.viz { display: block; overflow: visible; }
.viz-grid { stroke: var(--grid); stroke-width: 1; }
.viz-axis { stroke: var(--axis); stroke-width: 1; }
.viz-tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz-cross { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.viz-col.hover path { filter: brightness(1.12); }
.viz-col.clickable { cursor: pointer; }
.viz-empty { color: var(--text-muted); font-size: 13px; padding: 28px 0; text-align: center; }
.viz-tip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 12px; line-height: 1.5;
  box-shadow: 0 6px 24px rgba(0,0,0,.14); max-width: 280px; display: none;
}
.viz-tip b { font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-secondary); }
.hbars { display: grid; gap: 6px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 38%) minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: 13px; padding: 2px 4px; border-radius: 6px; }
.hbar.clickable { cursor: pointer; }
.hbar.clickable:hover { background: var(--surface-2); }
.hbar-label { display: flex; align-items: center; min-width: 0; gap: 0; }
.hbar-label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-label small { margin-left: 6px; white-space: nowrap; }
.hbar-track { height: 10px; }
.hbar-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar-val { font-variant-numeric: tabular-nums; text-align: right; color: var(--text-secondary); white-space: nowrap; }

/* ---------- peta */
.map-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; }
/* isolation: lapisan Leaflet (z-index 400-1000) tetap di dalam peta, tidak menutupi jendela detail. */
#map { height: 560px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); overflow: hidden; position: relative; z-index: 0; isolation: isolate; }
.map-list { max-height: 560px; overflow: auto; display: grid; gap: 8px; align-content: start; }
.map-item { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; background: var(--surface-1); cursor: pointer; }
.map-item:hover, .map-item.on { border-color: var(--accent); }
.map-item h3 { font-size: 13px; margin: 0 0 2px; display: flex; justify-content: space-between; gap: 8px; }
.map-item p { margin: 0; font-size: 12px; color: var(--text-secondary); }
.pin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.pin.ok { background: var(--series-1); }
.pin.warn { background: var(--warning); }
.pin.bad { background: var(--critical); }
.pin.off { background: #8f8e86; }
.map-legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-secondary); flex-wrap: wrap; }
.map-legend .pin { display: inline-block; width: 11px; height: 11px; border-width: 1px; vertical-align: -1px; margin-right: 5px; }
.svgmap .pt { cursor: pointer; }
.leaflet-popup-content { font: 13px/1.45 system-ui, sans-serif; }
/* Donat: bagian dari satu keseluruhan (paling banyak 6 bagian + Lainnya), dengan legenda nama, nilai dan persen. */
.donut { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.donut svg { flex: 0 0 auto; display: block; }
.donut .d-center-v { font-size: 20px; font-weight: 650; fill: var(--text-primary); font-variant-numeric: tabular-nums; }
.donut .d-center-l { font-size: 11px; fill: var(--text-muted); }
.donut .d-pct { font-size: 11px; font-weight: 600; pointer-events: none; }
.donut path.slice { cursor: default; transition: opacity .12s; }
.donut.clickable path.slice, .donut.clickable .d-row { cursor: pointer; }
.donut svg:hover path.slice:not(:hover) { opacity: .55; }
.d-legend { flex: 1 1 170px; min-width: 0; display: grid; gap: 4px; font-size: 13px; }
.d-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 8px; align-items: center; padding: 2px 4px; border-radius: 6px; }
.d-row:hover { background: var(--surface-2); }
.d-row span.n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-row span.v { color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.d-row span.p { color: var(--text-muted); font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; }
.d-row .sw { margin: 0; }
.viz-val { font-size: 11px; fill: var(--text-secondary); font-variant-numeric: tabular-nums; }
.viz-vbar.clickable { cursor: pointer; }
.viz-vbar:hover rect.b, .viz-vbar:hover path.b { opacity: .8; }
/* Sorotan: kalimat ringkas dari angka di halaman. */
.insights { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.insight { border: 1px solid var(--border); border-left: 4px solid var(--series-1); border-radius: var(--radius); background: var(--surface-1); padding: 10px 14px; font-size: 13px; line-height: 1.5; }
.insight.warn { border-left-color: var(--warning); }
.insight.bad { border-left-color: var(--critical); }
.insight.good { border-left-color: var(--good); }
.insight b.t { display: block; font-size: 12px; color: var(--text-secondary); font-weight: 600; margin-bottom: 2px; }
.insight ul { margin: 0; padding-left: 18px; }
/* Linimasa tugas mesin. */
.gantt { overflow-x: auto; }
.gantt svg { display: block; width: 100%; min-width: 520px; }
.gantt text { font-size: 11px; fill: var(--text-secondary); }
.gantt .lane { fill: var(--surface-2); }
.gantt rect.bar { cursor: pointer; }
.leaflet-bar a.map-home { display: flex; align-items: center; justify-content: center; color: #222; }

/* ---------- log */
.log { font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace; background: var(--surface-2); border-radius: 8px; padding: 10px 12px; max-height: 420px; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 0; }

/* ---------- modal, toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.42); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal-box { background: var(--surface-1); border-radius: 14px; width: min(860px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; border: 1px solid var(--border); }
.modal-box header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); gap: 12px; }
.modal-box h2 { font-size: 16px; margin: 0; }
.modal-body { padding: 16px 18px; overflow: auto; display: grid; gap: 14px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; font-size: 13px; margin: 0; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; align-items: end; }
.form-grid label { display: grid; gap: 4px; font-size: 12px; color: var(--text-secondary); }
.form-grid .btn { justify-self: start; min-width: 120px; }
.check { display: flex !important; align-items: center; gap: 6px; }
.keybox { font: 600 15px ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 10px 12px; border-radius: 8px; user-select: all; overflow-wrap: anywhere; }
.note { font-size: 12px; color: var(--text-secondary); background: var(--surface-2); border-radius: 8px; padding: 8px 12px; margin: 0; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text-primary); color: var(--surface-1); padding: 9px 16px; border-radius: 8px; z-index: 60; font-size: 13px; max-width: calc(100% - 32px); }
.toast.err { background: var(--critical); color: #fff; }
.loading { opacity: .55; transition: opacity .15s; }
.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface-2), var(--surface-1), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }
.err-box { border: 1px solid var(--critical); color: var(--critical-ink); border-radius: var(--radius); padding: 14px 16px; background: var(--surface-1); }
.tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- layar kecil */
@media (max-width: 1100px) {
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .map-wrap { grid-template-columns: 1fr; }
  #map { height: 420px; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { min-width: 0; position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; gap: 10px; border-right: 0; border-bottom: 1px solid var(--border); }
  .nav { display: flex; overflow-x: auto; order: 3; width: 100%; gap: 4px; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .side-foot { margin: 0 0 0 auto; display: flex; padding: 0; }
  .who { display: none; }
  .topbar { position: static; padding: 10px 16px; flex-direction: column; }
  .view { padding: 16px; }
  .g2, .g3, .g-2-1 { grid-template-columns: minmax(0, 1fr); }
  .filters select { max-width: 100%; flex: 1 1 140px; }
  .hbar { grid-template-columns: minmax(80px, 42%) minmax(0, 1fr) auto; }
}

/* Tabel besar: keterangan jumlah baris dan tombol tambah */
.table-more { display: flex; align-items: center; gap: 12px; margin: 0; padding: 8px 16px 12px; font-size: 12px; color: var(--text-secondary); }
