/* Disiplin TC — tampilan dasar. Mengikuti tema terang/gelap perangkat,
   bisa dipaksa lewat atribut data-theme di <html>. */

:root {
  color-scheme: light dark;

  --bg:        #f4f5f7;
  --surface:   #ffffff;
  --surface-2: #f8f9fb;
  --line:      #e3e6ec;
  --line-soft: #eef0f4;

  --ink-1: #14181f;
  --ink-2: #4c5566;
  --ink-3: #7b8493;

  --accent:     #4f46e5;
  --accent-ink: #ffffff;
  --accent-soft:#ecebfd;

  --ok:   #12855b;
  --warn: #b26a00;
  --hard: #c2410c;
  --crit: #c81e3a;
  --fail: #7f1d1d;

  --ok-bg:   #e4f5ee;
  --warn-bg: #fdf2dd;
  --hard-bg: #fdeee4;
  --crit-bg: #fdeaee;
  --fail-bg: #f8e0e0;

  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --r:  12px;
  --r-s: 9px;
  --nav-w: 236px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0c0e12;
    --surface:   #161a20;
    --surface-2: #1c212a;
    --line:      #262d38;
    --line-soft: #1f242d;

    --ink-1: #e9edf3;
    --ink-2: #a3adbd;
    --ink-3: #7c8797;

    --accent:     #7c7bf0;
    --accent-ink: #0d0f14;
    --accent-soft:#232345;

    --ok:   #4ed3a0;
    --warn: #f0b649;
    --hard: #fb923c;
    --crit: #f87171;
    --fail: #ef4444;

    --ok-bg:   #12312a;
    --warn-bg: #33290f;
    --hard-bg: #35220f;
    --crit-bg: #3a1620;
    --fail-bg: #401717;

    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg:#f4f5f7; --surface:#fff; --surface-2:#f8f9fb; --line:#e3e6ec; --line-soft:#eef0f4;
  --ink-1:#14181f; --ink-2:#4c5566; --ink-3:#7b8493;
  --accent:#4f46e5; --accent-ink:#fff; --accent-soft:#ecebfd;
  --ok:#12855b; --warn:#b26a00; --hard:#c2410c; --crit:#c81e3a; --fail:#7f1d1d;
  --ok-bg:#e4f5ee; --warn-bg:#fdf2dd; --hard-bg:#fdeee4; --crit-bg:#fdeaee; --fail-bg:#f8e0e0;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:#0c0e12; --surface:#161a20; --surface-2:#1c212a; --line:#262d38; --line-soft:#1f242d;
  --ink-1:#e9edf3; --ink-2:#a3adbd; --ink-3:#7c8797;
  --accent:#7c7bf0; --accent-ink:#0d0f14; --accent-soft:#232345;
  --ok:#4ed3a0; --warn:#f0b649; --hard:#fb923c; --crit:#f87171; --fail:#ef4444;
  --ok-bg:#12312a; --warn-bg:#33290f; --hard-bg:#35220f; --crit-bg:#3a1620; --fail-bg:#401717;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink-1);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p  { margin: 0 0 8px; }
a  { color: var(--accent); }

.muted { color: var(--ink-2); }
.dim   { color: var(--ink-3); }
.small { font-size: 12.5px; }
.mono  { font-variant-numeric: tabular-nums; }
.nowrap{ white-space: nowrap; }
.right { text-align: right; }
.grow  { flex: 1; min-width: 0; }
.hide  { display: none !important; }

/* ---------- kerangka ---------- */
#app { min-height: 100%; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  height: 56px; padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -.02em; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  font-size: 12px; font-weight: 800;
}
.topbar .sp { flex: 1; }

.iconbtn {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--r-s);
  background: var(--surface); color: var(--ink-2);
  cursor: pointer; font-size: 16px; line-height: 1;
}
.iconbtn:hover { background: var(--surface-2); color: var(--ink-1); }

.layout { display: flex; align-items: flex-start; }

.nav {
  width: var(--nav-w); flex: none;
  position: sticky; top: 56px; height: calc(100vh - 56px);
  display: flex; flex-direction: column;
  padding: 12px 10px; gap: 2px;
  background: var(--surface); border-right: 1px solid var(--line);
  overflow-y: auto;
}
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: var(--r-s);
  color: var(--ink-2); text-decoration: none;
  font-size: 14.5px; font-weight: 550;
}
.nav a:hover { background: var(--surface-2); color: var(--ink-1); }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.nav a .ic { width: 20px; text-align: center; font-size: 15px; }
.nav .foot { margin-top: auto; padding: 10px 11px 2px; border-top: 1px solid var(--line-soft); }

.main { flex: 1; min-width: 0; padding: 18px; max-width: 1240px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { flex: 1; min-width: 160px; }

.scrim { position: fixed; inset: 0; background: rgba(8,10,14,.45); z-index: 45; }

/* Di HP kartu KPI tetap 2 kolom supaya tidak jadi daftar panjang. */
@media (max-width: 719px) {
  .grid { gap: 10px; }
  .grid.kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.kpi .card { padding: 11px; }
  .kpicard .val { font-size: 25px; }
  .kpicard .lbl { font-size: 12px; }
  .kpicard .sub { font-size: 11.5px; }
  button.kpicard::after { top: 9px; right: 10px; }
}

@media (max-width: 899px) {
  .nav {
    position: fixed; top: 0; left: 0; height: 100vh; z-index: 50;
    transform: translateX(-100%); transition: transform .18s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.25);
  }
  body.nav-open .nav { transform: none; }
  .main { padding: 14px 12px 80px; }
}
@media (min-width: 900px) {
  .navtoggle, .scrim { display: none !important; }
}

/* ---------- kartu ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 14px;
}
.card + .card { margin-top: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2 { flex: 1; min-width: 120px; }

.grid { display: grid; gap: 14px; }
.grid.kpi  { grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); }
.grid.two  { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.form { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.span-all  { grid-column: 1 / -1; }

.kpicard { position: relative; }
.kpicard .lbl { font-size: 12.5px; font-weight: 600; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
button.kpicard .lbl { padding-right: 18px; }
.kpicard .val { font-size: 30px; font-weight: 700; letter-spacing: -.03em; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.kpicard .sub { font-size: 12.5px; color: var(--ink-3); }
button.kpicard { text-align: left; width: 100%; cursor: pointer; font: inherit; color: inherit; }
button.kpicard:hover { border-color: var(--accent); }
button.kpicard::after { content: "›"; position: absolute; top: 12px; right: 14px; color: var(--ink-3); font-size: 20px; line-height: 1; }

/* ---------- tombol ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 38px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--r-s);
  background: var(--surface); color: var(--ink-1);
  font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--crit); border-color: var(--line); }
.btn.danger:hover { background: var(--crit-bg); }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
/* Tombol "mati" tetap bisa diklik agar bisa menjelaskan apa yang kurang. */
.btn.off { opacity: .6; cursor: not-allowed; }
.btn:disabled { opacity: .6; cursor: progress; }

.btnrow { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- isian ---------- */
label.f { display: block; }
label.f > .t { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
label.f > .t .req { color: var(--crit); }
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=month], input[type=search], input[type=datetime-local],
select, textarea {
  width: 100%; min-height: 38px; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: var(--r-s);
  background: var(--surface); color: var(--ink-1);
  font: inherit; font-size: 14.5px;
}
textarea { min-height: 72px; resize: vertical; }
select[multiple] { min-height: 120px; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
input::placeholder, textarea::placeholder { color: var(--ink-3); }
.hint { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.err  { font-size: 12.5px; color: var(--crit); margin-top: 4px; }

.filebtn input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.filebtn { position: relative; display: inline-flex; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-s); overflow: hidden; }
.seg button {
  border: 0; background: var(--surface); color: var(--ink-2);
  font: inherit; font-size: 13.5px; font-weight: 600;
  padding: 7px 12px; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); }

/* ---------- lencana ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 650; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2);
}
.badge.ok   { background: var(--ok-bg);   color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.hard { background: var(--hard-bg); color: var(--hard); }
.badge.crit { background: var(--crit-bg); color: var(--crit); }
.badge.fail { background: var(--fail-bg); color: var(--fail); }

/* ---------- tabel ---------- */
.tablewrap { overflow-x: auto; margin: 0 -14px; padding: 0 14px; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { padding: 9px 10px; text-align: left; vertical-align: middle; }
table.t th {
  font-size: 12px; font-weight: 650; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.t td { border-bottom: 1px solid var(--line-soft); }
table.t tbody tr:last-child td { border-bottom: 0; }
table.t tbody tr:hover { background: var(--surface-2); }
table.t .num { text-align: right; font-variant-numeric: tabular-nums; }

.linkish {
  background: none; border: 0; padding: 0; font: inherit; font-weight: 600;
  color: var(--accent); cursor: pointer; text-align: left;
}

.empty { padding: 26px 10px; text-align: center; color: var(--ink-3); font-size: 14px; }

/* Kartu-per-baris di layar kecil */
@media (max-width: 719px) {
  table.t.stack thead { display: none; }
  table.t.stack tbody tr {
    display: block; padding: 10px 2px;
    border-bottom: 1px solid var(--line);
  }
  table.t.stack tbody tr:hover { background: none; }
  table.t.stack td {
    display: flex; gap: 12px; align-items: baseline;
    padding: 3px 0; border: 0;
  }
  table.t.stack td::before {
    content: attr(data-l);
    flex: none; width: 96px;
    font-size: 12px; font-weight: 650; color: var(--ink-3);
    text-transform: uppercase; letter-spacing: .04em;
  }
  table.t.stack td.num { text-align: left; }
  table.t.stack td.wide { display: block; }
  table.t.stack td.wide::before { display: block; margin-bottom: 3px; }
}

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(8,10,14,.5);
}
.modal .box {
  width: 100%; max-width: 560px; max-height: calc(100vh - 32px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 12px 40px rgba(8,10,14,.28);
}
.modal .box.wide { max-width: 940px; }
.modal .box > header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.modal .box > header h2 { flex: 1; min-width: 0; }
.modal .box > .body { padding: 16px; overflow-y: auto; }
.modal .box > footer {
  display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap;
  padding: 12px 16px; border-top: 1px solid var(--line);
}
@media (max-width: 560px) {
  .modal { padding: 0; align-items: flex-end; }
  .modal .box { max-width: none; max-height: 92vh; border-radius: 16px 16px 0 0; }
}

/* ---------- toast ---------- */
#toasts {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  z-index: 90; display: flex; flex-direction: column; gap: 8px;
  width: min(420px, calc(100vw - 24px)); pointer-events: none;
}
.toast {
  padding: 11px 14px; border-radius: var(--r-s);
  background: var(--ink-1); color: var(--surface);
  font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(8,10,14,.3);
  animation: pop .18s ease;
}
.toast.bad { background: var(--crit); color: #fff; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 22px;
}
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { justify-content: center; margin-bottom: 4px; }
.login-card .brand .mark { width: 40px; height: 40px; border-radius: 11px; font-size: 15px; }

/* ---------- pemuat ---------- */
.loading { display: flex; align-items: center; gap: 9px; color: var(--ink-3); padding: 22px 4px; font-size: 14px; }
.spin {
  width: 15px; height: 15px; flex: none;
  border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media print {
  .topbar, .nav, .no-print { display: none !important; }
  .main { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; padding: 0; }
}

/* ---------- grafik ---------- */
:root {
  --g-grid: #eceef2;
  --g-axis: #d7dbe3;
  --g-ink:  #7b8493;
  --c1:#4f46e5; --c2:#0d9488; --c3:#d97706; --c4:#db2777;
  --c5:#7c3aed; --c6:#0284c7; --c7:#65a30d; --c8:#ea580c;
}
@media (prefers-color-scheme: dark) {
  :root { --g-grid:#232a35; --g-axis:#323b49; --g-ink:#7c8797;
    --c1:#818cf8; --c2:#2dd4bf; --c3:#fbbf24; --c4:#f472b6;
    --c5:#a78bfa; --c6:#38bdf8; --c7:#a3e635; --c8:#fb923c; }
}
:root[data-theme="light"] { --g-grid:#eceef2; --g-axis:#d7dbe3; --g-ink:#7b8493;
  --c1:#4f46e5; --c2:#0d9488; --c3:#d97706; --c4:#db2777;
  --c5:#7c3aed; --c6:#0284c7; --c7:#65a30d; --c8:#ea580c; }
:root[data-theme="dark"] { --g-grid:#232a35; --g-axis:#323b49; --g-ink:#7c8797;
  --c1:#818cf8; --c2:#2dd4bf; --c3:#fbbf24; --c4:#f472b6;
  --c5:#a78bfa; --c6:#38bdf8; --c7:#a3e635; --c8:#fb923c; }

.plot { width: 100%; overflow-x: auto; }
.plot svg { width: 100%; height: auto; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 10px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; flex: none; }

.tip {
  position: fixed; z-index: 95; pointer-events: none;
  padding: 7px 10px; border-radius: 8px; font-size: 12.5px; line-height: 1.45;
  background: var(--ink-1); color: var(--surface);
  box-shadow: 0 6px 18px rgba(8,10,14,.3);
  opacity: 0; transition: opacity .1s;
}
.tip.on { opacity: 1; }
.tip .k { color: rgba(255,255,255,.65); }
:root[data-theme="dark"] .tip, .tip { }

/* Ukuran teks grafik TIDAK diatur di sini. Di HP grafik memakai viewBox yang
   lebih sempit (lihat chart.js) sehingga seluruh teks ikut membesar proporsional
   — memperbesarnya lewat CSS membuat nama seri di talang kiri meluber keluar kartu. */
