:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1b2430;
  --muted: #6a7686;
  --line: #dde3ea;
  --line2: #edf0f4;
  --brand: #1f4e79;
  --brand2: #2f6fa8;
  --accent: #eaf3fb;
  --sel: #d6e8f8;
  --head: #f7f9fb;
  --warn: #8a5a00;
  --warnbg: #fff7e6;
  --err: #a1261d;
  --errbg: #fdeeec;
  --rowh: 32px;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 35, 55, .06), 0 4px 16px rgba(20, 35, 55, .06);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg);
  display: flex; flex-direction: column; overflow: hidden; -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- header */
.topbar {
  display: flex; align-items: center; gap: 14px; background: var(--panel);
  padding: 0 16px; min-height: 56px; border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.logo { height: 32px; width: 32px; flex: none; }
.menubar { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.menubar::-webkit-scrollbar { display: none; }
.menubar button {
  background: none; border: 0; padding: 8px 12px; border-radius: 8px; white-space: nowrap; color: var(--ink); font-weight: 500;
}
.menubar button:hover, .menubar button.open { background: var(--accent); color: var(--brand); }
.topright { display: flex; align-items: center; gap: 12px; }
.engine { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.engine .dot { width: 8px; height: 8px; border-radius: 50%; background: #3cb371; }
.engine.busy .dot { background: #f0b429; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.userchip { display: flex; align-items: center; gap: 6px; background: var(--head); border: 1px solid var(--line); border-radius: 20px; padding: 4px 12px 4px 6px; font-size: 13px; max-width: 180px; }
.userchip #userName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userchip .av { font-size: 14px; }

.menu-pop {
  position: fixed; z-index: 50; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 40px rgba(20,30,50,.16); min-width: 270px; max-width: calc(100vw - 16px);
  max-height: calc(100vh - 80px); overflow: auto; padding: 6px;
}
.menu-pop .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); padding: 10px 10px 4px; font-weight: 600; }
.menu-pop button {
  display: flex; width: 100%; text-align: left; background: none; border: 0; padding: 9px 10px; gap: 12px; border-radius: 8px; align-items: baseline;
}
.menu-pop button:hover { background: var(--accent); }
.menu-pop button small { margin-left: auto; color: var(--muted); font-size: 11.5px; }
.menu-pop .menusearch { position: sticky; top: -6px; z-index: 1; margin: 0 0 4px; box-shadow: 0 2px 0 var(--panel); }
.menu-pop hr { border: 0; border-top: 1px solid var(--line2); margin: 5px 4px; }

/* ---------- sub bar */
.subbar { display: flex; align-items: center; gap: 14px; padding: 10px 16px; background: var(--bg); }
.dsname {
  border: 1px solid transparent; background: transparent; font-size: 16px; font-weight: 600; padding: 5px 8px; border-radius: 8px;
  min-width: 120px; max-width: 320px; flex: 0 1 auto;
}
.dsname:hover { border-color: var(--line); background: var(--panel); }
.dsname:focus { outline: none; border-color: var(--brand2); background: var(--panel); }
.seg { display: inline-flex; background: #e6ebf1; border-radius: 10px; padding: 3px; gap: 2px; }
.tab { border: 0; background: transparent; padding: 6px 16px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.tab.active { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); font-weight: 600; }
.badge { background: var(--brand2); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: 4px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; margin-left: auto; font-size: 13px; color: var(--muted); }

main { flex: 1; min-height: 0; position: relative; margin: 0 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; overflow: hidden; }
.view { display: none; position: absolute; inset: 0; }
.view.active { display: block; }

/* ---------- grid */
.grid { position: absolute; inset: 0; overflow: auto; outline: none; }
.grid table { border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; }
.grid th, .grid td {
  height: var(--rowh); padding: 0 10px; border-right: 1px solid var(--line2); border-bottom: 1px solid var(--line2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px;
}
.grid thead th {
  position: sticky; top: 0; z-index: 2; background: var(--head); font-weight: 600; text-align: left; border-bottom: 1px solid var(--line); cursor: pointer;
}
.grid thead th.newcol { color: var(--muted); font-weight: 400; font-style: italic; }
.grid tbody th {
  position: sticky; left: 0; z-index: 1; background: var(--head); color: var(--muted); font-weight: 500;
  text-align: right; min-width: 52px; border-right: 1px solid var(--line); cursor: pointer;
}
.grid tbody th.rsel { background: var(--sel); color: var(--brand); }
.grid thead th.corner { left: 0; z-index: 3; }
.grid td { min-width: 90px; cursor: cell; }
.grid td.num { text-align: right; }
.grid td.blank { background: #fcfdfe; }
.grid td.sel { box-shadow: inset 0 0 0 2px var(--brand2); background: var(--accent); }
.grid tr.filtered th { text-decoration: line-through; color: #b34; }
.grid tr.filtered td { color: #9aa3ad; }
.grid td input, .grid td select {
  width: 100%; height: calc(var(--rowh) - 6px); border: 0; outline: none; background: #fff; padding: 0; text-align: inherit;
}
.grid thead th .vt { margin-left: 5px; vertical-align: -2px; }
.mi { width: 13px; height: 13px; display: inline-block; vertical-align: middle; }
.vargrid thead th { cursor: default; }
.vargrid td { min-width: 80px; padding: 0 4px; }
.vargrid td input, .vargrid td select { padding: 0 6px; border-radius: 6px; }
.vargrid td input:focus, .vargrid td select:focus { box-shadow: inset 0 0 0 2px var(--brand2); }
.vargrid td.wide { min-width: 220px; }
.vargrid td.btncell { cursor: pointer; color: var(--brand2); padding: 0 10px; max-width: 240px; }
.vargrid td.btncell:hover { background: var(--accent); }
.spacer-row td { border: 0 !important; }

/* ---------- layar sambutan */
.welcome { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(244,246,249,.92); padding: 16px; overflow: auto; }
.wcard { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 32px; max-width: 720px; width: 100%; text-align: center; }
.wlogo { height: 48px; }
.wcard h2 { margin: 16px 0 4px; font-size: 22px; }
.wcard > p { color: var(--muted); margin: 0 0 20px; }
.wbtns { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.wbtn { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 20px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); transition: .15s; }
.wbtn:hover { border-color: var(--brand2); background: var(--accent); transform: translateY(-1px); }
.wbtn span { font-size: 26px; }
.wbtn small { color: var(--muted); }

/* ---------- login */
.login { position: fixed; inset: 0; z-index: 80; background: linear-gradient(160deg, #eef4fb 0%, #f7f9fb 60%); display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
.lcard { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 32px 28px; width: min(400px, 100%); }
.llogo { height: 52px; display: block; margin: 0 auto; }
.lsub { text-align: center; color: var(--muted); margin: 8px 0 20px; }
.ltabs { display: flex; background: #e9eef4; border-radius: 10px; padding: 3px; margin-bottom: 18px; }
.ltab { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.ltab.active { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
#loginForm label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
#loginForm .inp { margin-top: 4px; padding: 10px 12px; font-size: 15px; }
.lerr { color: var(--err); font-size: 13px; min-height: 18px; margin-bottom: 6px; }
.btn.wide { width: 100%; padding: 11px; font-size: 15px; }
.center { text-align: center; }

/* ---------- output */
.outwrap { position: absolute; inset: 0; display: flex; }
.outline { width: 250px; flex: none; overflow: auto; border-right: 1px solid var(--line2); background: var(--head); padding: 10px 0; font-size: 13px; }
.outline .grp a { font-weight: 600; color: var(--brand); padding-left: 14px; margin-top: 6px; }
.outline a { display: block; padding: 4px 12px 4px 28px; color: var(--ink); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 6px; margin: 0 6px; }
.outline a:hover { background: var(--accent); }
.outdoc { flex: 1; overflow: auto; padding: 20px 28px 90px; }
.empty { color: var(--muted); padding: 60px 20px; text-align: center; }
.empty-ic { font-size: 40px; }
.run { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 26px; }
.run:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.run-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.run-head h2 { margin: 0; font-size: 19px; color: var(--brand); }
.run-head .time { color: var(--muted); font-size: 12px; }
.run-head .acts { margin-left: auto; display: flex; gap: 6px; }
.blk { margin: 16px 0; position: relative; }
.blk .acts { display: flex; gap: 6px; margin-bottom: 4px; opacity: 0; transition: opacity .15s; }
.blk:hover .acts { opacity: 1; }
.smallbtn { border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 4px 10px; font-size: 12px; color: var(--muted); }
.smallbtn:hover { color: var(--ink); border-color: var(--brand2); }
.smallbtn.danger:hover { color: var(--err); border-color: var(--err); }

/* tabel output gaya laporan */
.ptable { border-collapse: collapse; font: 13px/1.35 Arial, "Helvetica Neue", sans-serif; color: #111; background: #fff; }
.ptable caption { caption-side: top; text-align: center; font-weight: 700; font-size: 14px; padding: 4px 0 8px; }
.ptable caption .sub { display: block; font-weight: 400; font-size: 12.5px; color: #333; }
.ptable th, .ptable td { padding: 4px 9px; border: 1px solid #cfd5dc; vertical-align: top; }
.ptable thead th { background: #f3f6f9; font-weight: 600; text-align: center; vertical-align: bottom; }
.ptable tbody th { background: #fafbfc; font-weight: 400; text-align: left; }
.ptable td { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ptable td.txt { text-align: left; white-space: normal; }
.ptable sup { font-size: 9px; margin-left: 1px; }
.ptable tfoot td { border: 0; text-align: left; font-size: 12px; white-space: normal; padding: 2px 4px; color: #333; }
.tblwrap { overflow-x: auto; max-width: 100%; }
.msg { padding: 12px 14px; border-radius: 10px; white-space: pre-wrap; max-width: 900px; }
.msg.warning { background: var(--warnbg); color: var(--warn); border: 1px solid #f2d79a; }
.msg.error { background: var(--errbg); color: var(--err); border: 1px solid #f3bdb6; }
.msg.text { background: var(--head); border: 1px solid var(--line2); font-size: 13px; color: #334; }
.msg .t { font-weight: 700; display: block; margin-bottom: 2px; }
.interp { background: #f2f8ff; border: 1px solid #cfe2f6; border-left: 4px solid var(--brand2); border-radius: 10px; padding: 12px 16px; max-width: 900px; }
.interp .it { font-weight: 700; color: var(--brand); margin-bottom: 4px; }
.interp .ib { margin-right: 6px; }
.interp ul { margin: 4px 0 6px; padding-left: 20px; }
.interp li { margin: 3px 0; }
.chart { background: #fff; border: 1px solid var(--line2); border-radius: 10px; display: inline-block; max-width: 100%; overflow: hidden; }
.chart svg { display: block; max-width: 100%; height: auto; }

/* ---------- dialog */
.modal-back { position: fixed; inset: 0; background: rgba(15,25,40,.35); backdrop-filter: blur(2px); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.dlg { background: var(--panel); border-radius: 16px; box-shadow: 0 24px 70px rgba(0,0,0,.25); width: min(880px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.dlg.small { width: min(520px, 100%); }
.dlg.wide { width: min(1100px, 100%); }
textarea.syn { min-height: 340px; font-size: 13.5px; line-height: 1.5; white-space: pre; tab-size: 2; }
.dlg header { padding: 16px 20px 12px; border-bottom: 1px solid var(--line2); display: flex; align-items: flex-start; gap: 8px; }
.dlg header h3 { margin: 0; font-size: 17px; }
.dhelp { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.dlg header .x { margin-left: auto; border: 0; background: none; font-size: 24px; line-height: 1; color: var(--muted); padding: 0 4px; }
.dlg .body { padding: 16px 20px; overflow: auto; flex: 1; }
.dlg footer { padding: 12px 20px; border-top: 1px solid var(--line2); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dlg footer .grow { flex: 1; }
.dlg footer:not(:has(.grow)) { justify-content: flex-end; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 9px; padding: 8px 18px; font-weight: 500; }
.btn:hover { border-color: var(--brand2); }
.btn.primary { background: var(--brand2); border-color: var(--brand2); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand); }
.btn:disabled { opacity: .5; cursor: default; }
.dl-cols { display: grid; grid-template-columns: minmax(200px, 1fr) minmax(260px, 1.3fr); gap: 18px; }
.cap { font-size: 13px; color: var(--muted); display: block; margin-bottom: 5px; font-weight: 500; }
.srclist, .tgtlist { border: 1px solid var(--line); border-radius: 9px; overflow: auto; background: #fff; user-select: none; }
.srclist { height: 330px; }
.tgtlist { min-height: 44px; max-height: 170px; }
.tgtlist.one { min-height: 40px; max-height: 40px; overflow: hidden; }
.ph { color: #a9b2bd; font-size: 12.5px; padding: 10px; }
.vitem { padding: 7px 10px; display: flex; gap: 8px; align-items: center; cursor: pointer; border-bottom: 1px solid #f2f4f7; }
.vitem:hover { background: #f5f9fd; }
.vitem.on { background: var(--sel); }
.vitem .ic { width: 20px; text-align: center; font-size: 12px; flex: none; color: var(--muted); }
.vitem .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tgt { display: grid; grid-template-columns: 46px 1fr; gap: 6px 8px; align-items: start; margin-bottom: 12px; }
.tgt .lbl { grid-column: 2; font-size: 13px; color: var(--muted); font-weight: 500; }
.mv { grid-column: 1; border: 1px solid var(--line); background: #fff; border-radius: 9px; height: 40px; font-size: 16px; color: var(--brand2); }
.mv:hover { border-color: var(--brand2); background: var(--accent); }
.fld { margin: 10px 0; }
.fs { border: 1px solid var(--line2); border-radius: 12px; padding: 8px 14px 6px; margin: 14px 0 0; }
.fs legend { padding: 0 6px; font-size: 13px; font-weight: 600; color: var(--brand); }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 2px 14px; }
.checks label, .chk, .radios label { display: flex; gap: 8px; align-items: center; padding: 4px 0; cursor: pointer; }
.radios { display: flex; flex-wrap: wrap; gap: 4px 18px; }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--brand2); }
.inp { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; background: #fff; }
.inp:focus { outline: none; border-color: var(--brand2); box-shadow: 0 0 0 3px rgba(47,111,168,.15); }
.inp.short { width: 130px; }
textarea.inp { resize: vertical; font-family: ui-monospace, Consolas, monospace; }
.row2 { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row2 .inp { flex: 1; min-width: 120px; }
.row2 .inp.short { flex: none; }
.hint { font-size: 12px; color: var(--muted); }
.fnbtns { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.fnbtns button { border: 1px solid var(--line); background: var(--head); border-radius: 6px; padding: 4px 8px; font-size: 12px; font-family: ui-monospace, Consolas, monospace; }
.fnbtns button:hover { border-color: var(--brand2); }
.ruletbl, .dstbl { width: 100%; border-collapse: collapse; font-size: 13.5px; margin-top: 8px; }
.ruletbl td, .dstbl td { border-bottom: 1px solid var(--line2); padding: 8px 6px; vertical-align: middle; }
.dstbl tr.cur { background: var(--accent); }
.dstbl .acts2 { text-align: right; white-space: nowrap; }
.dstbl .acts2 > * { margin-left: 6px; }
.linkbtn { border: 0; background: none; color: var(--brand2); font-weight: 600; padding: 0; text-align: left; }
.linkbtn:hover { text-decoration: underline; }
.toast {
  position: fixed; left: 50%; bottom: 48px; transform: translateX(-50%); background: #1f2b38; color: #fff;
  padding: 11px 18px; border-radius: 10px; z-index: 90; max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: 13.5px;
}

/* ---------- status bar */
.statusbar {
  display: flex; gap: 18px; align-items: center; padding: 6px 28px; font-size: 12px; color: var(--muted);
  background: var(--bg); padding-bottom: calc(6px + env(safe-area-inset-bottom));
}
.statusbar .spacer { flex: 1; }
#stFilter { color: #b34; font-weight: 600; }
.stflag { color: var(--brand2); font-weight: 600; }

/* ---------- layar sempit (ponsel / tablet tegak) */
@media (max-width: 820px) {
  .outline { display: none; }
  .outdoc { padding: 14px 14px 80px; }
  .dl-cols { grid-template-columns: 1fr; }
  .srclist { height: 190px; }
  .modal-back { padding: 0; }
  .dlg, .dlg.small { max-height: 100vh; height: 100%; border-radius: 0; width: 100%; }
  .engine .txt, .userchip #userName { display: none; }
  .userchip { padding: 4px 8px; }
  main { margin: 0 8px; }
  .subbar { padding: 8px; gap: 8px; flex-wrap: wrap; }
  .dsname { font-size: 15px; max-width: 46vw; }
  .statusbar { padding: 6px 12px; }
  .blk .acts { opacity: 1; }
}
@media (hover: none) { .blk .acts { opacity: 1; } }

@media print {
  body { overflow: visible; display: block; background: #fff; }
  .topbar, .subbar, .statusbar, .outline, .acts, #view-data, #view-vars, .login { display: none !important; }
  main, .view, .outwrap, .outdoc { position: static !important; display: block !important; overflow: visible !important; padding: 0; border: 0; margin: 0; }
  .blk { break-inside: avoid; }
}
