:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --line: #e2e7ec;
  --line-strong: #cfd6dd;
  --text: #1c2630;
  --muted: #5f6b77;
  --primary: #0f5c6e;
  --primary-2: #137a91;
  --primary-soft: #e3f1f4;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --ok: #1a7f37;
  --ok-soft: #e6f4ea;
  --r1: #2e7d32; --r2: #7cb342; --r3: #f2b632; --r4: #ef7d32; --r5: #c62828;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--primary-2); }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* App bar */
.appbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 10px 20px; background: var(--primary); color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand small { display: block; font-size: 11px; opacity: .8; font-weight: 400; }
.logo { width: 34px; height: 34px; border-radius: 8px; background: #fff; color: var(--primary); display: grid;
  place-items: center; font-weight: 800; letter-spacing: -.5px; }
.appbar-right { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.save-state { opacity: .9; }

/* Layout */
main { max-width: 1400px; margin: 0 auto; padding: 20px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* Editor layout */
.editor { display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 1000px) { .editor { grid-template-columns: 1fr; } }
.sidenav { position: sticky; top: 74px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; max-height: calc(100vh - 94px); overflow: auto; }
.sidenav .grp { margin: 10px 8px 4px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); display: flex; align-items: center; gap: 6px; }
.sidenav a { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 6px; color: var(--text);
  text-decoration: none; font-size: 13px; }
.sidenav a:hover { background: var(--surface-2); }
.sidenav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sidenav a.disabled { color: #9aa5b1; }
.sidenav a .code { font-family: ui-monospace, Menlo, monospace; font-size: 11px; color: var(--muted); min-width: 32px; }
.sidenav a .cnt { margin-left: auto; }

/* Form controls */
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); border: 1px solid var(--line-strong); border-radius: 6px;
  padding: 7px 9px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(19,122,145,.25); border-color: var(--primary-2); }
input[readonly] { background: var(--surface-2); }
textarea { resize: vertical; min-height: 38px; line-height: 1.4; }
input.invalid, select.invalid, textarea.invalid { border-color: var(--danger); background: #fffafa; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.counter { font-size: 11px; color: var(--muted); text-align: right; }
.counter.over { color: var(--danger); font-weight: 700; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.check input { width: auto; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: #fff; color: var(--text);
  padding: 7px 13px; border-radius: 6px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.appbar .btn { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.3); }
.appbar .btn:hover { background: rgba(255,255,255,.22); }

/* Badges */
.badge { display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.err { background: var(--danger-soft); color: var(--danger); border-color: #f5c2bd; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: #f0dca0; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: #b7dfc2; }
.badge.info { background: var(--primary-soft); color: var(--primary); border-color: #bfe0e7; }
.lvl { display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 6px; font-weight: 800;
  color: #fff; font-size: 13px; }
.lvl.l0 { background: #c3cbd3; } .lvl.l1 { background: var(--r1); } .lvl.l2 { background: var(--r2); }
.lvl.l3 { background: var(--r3); color: #3d2c00; } .lvl.l4 { background: var(--r4); } .lvl.l5 { background: var(--r5); }
.lvl.empty { background: transparent; color: #9aa5b1; border: 1px dashed var(--line-strong); }

/* Tables */
table.t { width: 100%; border-collapse: collapse; }
table.t th, table.t td { border-bottom: 1px solid var(--line); padding: 8px; text-align: left; vertical-align: top; }
table.t th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
table.t tr:hover td { background: #fbfcfd; }
table.t td.c, table.t th.c { text-align: center; }
table.t td.r, table.t th.r { text-align: right; }

table.kk td { padding: 6px 8px; }
table.kk tr.pilar td { background: var(--surface-2); font-weight: 600; }
table.kk tr.item td.nm { padding-left: 26px; }
table.kk tr.total td { background: var(--primary-soft); font-weight: 700; border-top: 2px solid #bfe0e7; }
table.kk tr.has-error td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
table.kk tr.flash td { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: #fff2b3; } to { } }
table.kk td.sandi { font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--muted); width: 54px; }
table.kk td.nm { width: 34%; line-height: 1.4; }
table.kk td.rasio { width: 110px; }
table.kk td.nilai { width: 170px; }
.saran { font-size: 11px; color: var(--primary); margin-top: 4px; font-weight: 500; }
.saran button { border: 0; background: none; color: var(--primary-2); text-decoration: underline; cursor: pointer; font-size: 11px; padding: 0; }
.input-unit { position: relative; }
.input-unit input { padding-right: 24px; }
.input-unit span { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; }

/* Matrix */
.matrix { display: grid; grid-template-columns: 110px repeat(5, 1fr); gap: 3px; font-size: 12px; max-width: 560px; }
.matrix div { padding: 6px 4px; text-align: center; border-radius: 4px; }
.matrix .h { background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: 11px; }
.matrix .cell { color: #fff; font-weight: 700; opacity: .35; }
.matrix .cell.on { opacity: 1; outline: 3px solid var(--text); outline-offset: -1px; }
.matrix .cell.c3 { color: #3d2c00; }

/* Stats */
.stat { padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 22px; font-weight: 800; margin-top: 4px; display: flex; align-items: center; gap: 8px; }
.stat .v small { font-size: 13px; font-weight: 600; color: var(--muted); }

/* Heatmap */
.heat td.c { padding: 6px; }

/* Messages */
.alert { padding: 10px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface-2); font-size: 13px; margin-bottom: 12px; }
.alert.err { background: var(--danger-soft); border-color: #f5c2bd; color: #7a1a12; }
.alert.warn { background: var(--warn-soft); border-color: #f0dca0; color: #5c3d00; }
.alert.ok { background: var(--ok-soft); border-color: #b7dfc2; color: #10501f; }
.alert.info { background: var(--primary-soft); border-color: #bfe0e7; color: #0b4250; }
ul.vlist { list-style: none; margin: 0; padding: 0; }
ul.vlist li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 4px; border-bottom: 1px solid var(--line); }
ul.vlist li a { cursor: pointer; }
pre.preview { background: #0f1720; color: #d7e3ee; padding: 12px; border-radius: 6px; overflow: auto; max-height: 420px; font-size: 12px; white-space: pre; }

.dropzone { border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); cursor: pointer; }
.dropzone.over { border-color: var(--primary-2); background: var(--primary-soft); }

/* Modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,32,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 10px; width: min(620px, 100%); max-height: 90vh; overflow: auto; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
#toast-root { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #1c2630; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; font-size: 13px; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* Print */
.print-only { display: none; }
@media print {
  .no-print, .appbar, .sidenav { display: none !important; }
  .print-only { display: block; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; padding: 0; margin-bottom: 14px; }
  table.t th { position: static; }
  .page-break { page-break-before: always; }
  .lvl { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.report h1 { font-size: 20px; }
.report table.t td, .report table.t th { font-size: 12px; padding: 5px 6px; }
.report .sect { margin-top: 18px; }

/* Kuesioner KPMR */
.seg { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.seg button { font: inherit; font-size: 12px; padding: 4px 9px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: #fff; color: var(--text); cursor: pointer; font-weight: 500; }
.seg button:hover { background: var(--surface-2); }
.seg button.on { color: #fff; font-weight: 700; border-color: transparent; }
.seg button.on.l1 { background: var(--r1); } .seg button.on.l2 { background: var(--r2); }
.seg button.on.l3 { background: var(--r3); color: #3d2c00; } .seg button.on.l4 { background: var(--r4); } .seg button.on.l5 { background: var(--r5); }

/* ================= Halaman login ================= */
body.mode-login .appbar { display: none; }
body.mode-login main { max-width: none; padding: 0; }
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); background: var(--surface); }
.login-brand { position: relative; overflow: hidden; color: #fff; display: flex; align-items: center; padding: 56px;
  background: radial-gradient(1200px 600px at -10% -10%, #1d8aa3 0%, transparent 60%),
              radial-gradient(900px 500px at 110% 120%, #0a3d4a 0%, transparent 55%),
              linear-gradient(150deg, #0f5c6e 0%, #0b4757 55%, #082f3a 100%); }
.login-brand::before { content: ""; position: absolute; inset: 0; opacity: .12;
  background-image: linear-gradient(rgba(255,255,255,.6) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.6) 1px, transparent 1px);
  background-size: 44px 44px; mask-image: radial-gradient(ellipse at 30% 40%, #000 0%, transparent 70%); }
.login-brand::after { content: ""; position: absolute; width: 420px; height: 420px; right: -140px; top: -140px; border-radius: 50%;
  background: radial-gradient(circle, rgba(242,182,50,.28), transparent 65%); }
.lb-inner { position: relative; z-index: 1; max-width: 460px; }
.lb-logo { width: 54px; height: 54px; border-radius: 14px; background: #fff; color: var(--primary); display: grid; place-items: center;
  font-weight: 800; font-size: 20px; letter-spacing: -.5px; box-shadow: 0 10px 30px rgba(0,0,0,.25); margin-bottom: 28px; }
.lb-eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: 12px; font-weight: 700; opacity: .8; margin-bottom: 10px; }
.lb-title { font-size: 38px; line-height: 1.12; font-weight: 800; margin: 0 0 14px; letter-spacing: -.02em; }
.lb-sub { font-size: 15px; line-height: 1.6; opacity: .85; margin: 0 0 30px; }
.lb-list { list-style: none; padding: 0; margin: 0 0 34px; display: grid; gap: 12px; }
.lb-list li { display: flex; align-items: center; gap: 14px; font-size: 14px; background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12); border-radius: 12px; padding: 12px 14px; backdrop-filter: blur(4px); }
.lb-list li span { font-family: ui-monospace, Menlo, monospace; font-size: 12px; font-weight: 700; color: #f2b632;
  background: rgba(242,182,50,.12); border-radius: 8px; padding: 4px 7px; }
.lb-levels { display: flex; align-items: center; gap: 6px; }
.lb-levels i { width: 30px; height: 8px; border-radius: 99px; display: inline-block; }
.lb-levels i.l1 { background: var(--r1); } .lb-levels i.l2 { background: var(--r2); } .lb-levels i.l3 { background: var(--r3); }
.lb-levels i.l4 { background: var(--r4); } .lb-levels i.l5 { background: var(--r5); }
.lb-levels small { margin-left: 10px; opacity: .7; font-size: 12px; }

.login-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 24px;
  background: linear-gradient(180deg, #f7fafb 0%, #eef3f5 100%); }
.login-card { width: min(400px, 100%); background: #fff; border-radius: 18px; padding: 34px 32px 26px;
  box-shadow: 0 1px 2px rgba(16,24,40,.04), 0 18px 48px -12px rgba(15,92,110,.25); border: 1px solid #e6edf0; display: grid; gap: 16px; }
.lc-head h2 { font-size: 24px; margin: 10px 0 4px; letter-spacing: -.01em; }
.lc-head p { margin: 0; color: var(--muted); font-size: 13.5px; }
.lc-badge svg { width: 13px; height: 13px; fill: currentColor; }
.lc-badge { display: inline-flex; gap: 6px; align-items: center; font-size: 11px; font-weight: 700; color: var(--primary);
  background: var(--primary-soft); border-radius: 999px; padding: 4px 10px; }
.lc-field { display: grid; gap: 6px; font-size: 12.5px; font-weight: 600; color: #344250; }
.lc-input { position: relative; display: flex; align-items: center; }
.lc-input > svg { position: absolute; left: 13px; width: 18px; height: 18px; fill: #9aa7b2; pointer-events: none; transition: fill .15s; }
.lc-input input { height: 46px; padding: 0 44px 0 42px; border-radius: 11px; border: 1.5px solid #dbe3e8; background: #fbfcfd; font-size: 14.5px;
  transition: border-color .15s, box-shadow .15s, background .15s; }
.lc-input input:focus { outline: none; border-color: var(--primary-2); background: #fff; box-shadow: 0 0 0 4px rgba(19,122,145,.14); }
.lc-input:focus-within > svg { fill: var(--primary-2); }
.lc-eye { position: absolute; right: 6px; width: 34px; height: 34px; border: 0; background: transparent; border-radius: 8px; cursor: pointer;
  display: grid; place-items: center; }
.lc-eye svg { width: 19px; height: 19px; fill: #9aa7b2; }
.lc-eye:hover { background: #f0f4f6; } .lc-eye.on svg { fill: var(--primary-2); }
.lc-submit { height: 48px; border: 0; border-radius: 11px; color: #fff; font: inherit; font-weight: 700; font-size: 15px; cursor: pointer; margin-top: 4px;
  background: linear-gradient(135deg, #137a91 0%, #0f5c6e 100%); box-shadow: 0 8px 20px -6px rgba(15,92,110,.55); transition: transform .1s, box-shadow .15s, filter .15s; }
.lc-submit:hover { filter: brightness(1.06); box-shadow: 0 10px 24px -6px rgba(15,92,110,.6); }
.lc-submit:active { transform: translateY(1px); }
.lc-submit:disabled { cursor: progress; filter: saturate(.7); }
.lc-submit.loading span::before { content: ""; display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px;
  border: 2px solid rgba(255,255,255,.45); border-top-color: #fff; border-radius: 50%; animation: putar .7s linear infinite; }
@keyframes putar { to { transform: rotate(360deg); } }
.lc-error { background: #fff3f2; border: 1px solid #f6c9c4; color: #9b1c12; border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.lc-foot { margin: 2px 0 0; text-align: center; font-size: 11.5px; color: #8a97a3; }
.lc-copy { margin-top: 22px; font-size: 11.5px; color: #93a1ad; }
.login-card.shake { animation: goyang .35s ease; }
@keyframes goyang { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

@media (max-width: 860px) {
  .login-wrap { grid-template-columns: 1fr; }
  .login-brand { padding: 36px 24px 30px; }
  .lb-title { font-size: 28px; }
  .lb-list, .lb-levels { display: none; }
  .lb-sub { margin-bottom: 0; }
  .lb-logo { margin-bottom: 18px; }
  .login-panel { padding: 28px 16px 36px; }
}
@media (prefers-reduced-motion: reduce) { .login-card.shake, .lc-submit.loading span::before { animation: none; } }
