/* StatLab — shell & komponen bersama. View boleh menambah CSS sendiri di css/<view>.css. */
:root {
  --vh: 100vh; --nav-h: 0px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  --view-h: calc(var(--vh) - var(--top-h) - var(--nav-h));
  /* skala tipografi & jarak (dipakai komponen baru; komponen lama menyusul bertahap) */
  --t-xs: .75rem; --t-sm: .85rem; --t-md: 1rem; --t-lg: 1.2rem; --t-xl: 1.5rem; --t-2xl: 1.9rem;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;
  --touch: 44px;
}
@supports (height: 100dvh) { :root { --vh: 100dvh; } }
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: var(--fs)/1.5 var(--font);
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 2.1rem; font-weight: 750; } h2 { font-size: 1.5rem; font-weight: 700; } h3 { font-size: 1.2rem; font-weight: 650; } h4 { font-size: 1.05rem; font-weight: 650; }
p { margin: 0 0 .75em; } a { color: var(--accent-text); text-underline-offset: 2px; }
code, kbd, .mono { font-family: var(--mono); font-size: .92em; }
kbd { background: var(--surface-3); border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; font-size: .8em; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }
svg.ic { width: 1.25em; height: 1.25em; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Shell ---------- */
#app { display: grid; grid-template-columns: var(--rail-w) 1fr; grid-template-rows: var(--top-h) 1fr; height: calc(var(--vh) - var(--nav-h)); }
#topbar {
  grid-column: 1 / 3; display: flex; align-items: center; gap: 18px; padding: 0 20px 0 0;
  background: var(--surface); border-bottom: 1px solid var(--border); z-index: 20;
}
#brand { width: var(--rail-w); display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; flex: none; cursor: pointer; user-select: none; }
#brand .logo { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, #0f62fe, #6929c4); color: #fff; display: grid; place-items: center; font-size: 17px; font-weight: 800; box-shadow: var(--shadow-1); }
#project { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; flex: 0 1 auto; }
#project b { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 24ch; }
#project small { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.topactions { display: flex; align-items: center; gap: 6px; margin-left: auto; flex: none; }
.topactions .btn.ghost { color: var(--text-2); }
.topactions .btn.ghost.on { color: var(--accent-text); background: var(--accent-soft); }
.tb-mode { margin-right: 6px; } .tb-mode .seg button { padding: 6px 12px; min-height: 34px; }

/* Bilah langkah: ① Data → ② Analisis → ③ Hasil */
#steps { display: flex; align-items: center; gap: 0; margin: 0 auto; padding-right: 12px; min-width: 0; }
.stp { display: inline-flex; align-items: center; gap: 9px; padding: 6px 14px 6px 7px; min-height: 40px; border: 1px solid transparent; border-radius: 999px; background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.stp:hover { background: var(--surface-3); color: var(--text); }
.stp-n { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .85rem; font-weight: 700; background: var(--surface-3); color: var(--text-2); flex: none; }
.stp-n svg.ic { width: 15px; height: 15px; stroke-width: 2.6; }
.stp.done .stp-n { background: var(--ok); color: #fff; } .stp.done { color: var(--text-2); }
.stp.next { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); } .stp.next .stp-n { background: var(--accent); color: var(--on-accent); }
.stp.now { background: var(--accent); color: var(--on-accent); border-color: var(--accent); } .stp.now .stp-n, .stp.now.done .stp-n { background: var(--on-accent); color: var(--accent); }
.stp-go { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; opacity: .85; }
.stp-line { width: 26px; height: 2px; background: var(--border-strong); border-radius: 1px; flex: none; } .stp-line.done { background: var(--ok); }

#rail { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; padding: 14px 0; gap: 6px; overflow-y: auto; }
.railbtn {
  width: 72px; padding: 11px 0 8px; border: 0; background: transparent; border-radius: 14px; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 5px; font: inherit; font-size: .78rem; font-weight: 600; position: relative;
}
.railbtn svg.ic { width: 24px; height: 24px; }
.railbtn:hover { background: var(--surface-3); color: var(--text); }
.railbtn[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); }
.railbtn[aria-current="page"]::before { content: ""; position: absolute; left: -8px; top: 12px; bottom: 12px; width: 4px; border-radius: 0 4px 4px 0; background: var(--accent); }

#main { overflow: auto; position: relative; min-width: 0; }
#view { min-height: 100%; }
.view-pad { padding: 40px 48px 72px; max-width: 1180px; margin: 0 auto; }
.view-full { height: var(--view-h); display: flex; flex-direction: column; min-height: 0; }

/* Menu "Lainnya" */
#moremenu { position: fixed; top: calc(var(--top-h) - 4px); right: 16px; z-index: 45; width: min(340px, calc(100vw - 24px)); padding: 8px; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-3); animation: pop .16s; }
#moremenu[hidden] { display: none; }
#moremenu > button { display: flex; align-items: center; gap: 14px; min-height: 56px; padding: 8px 12px; border: 0; background: transparent; border-radius: 12px; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
#moremenu > button:hover, #moremenu > button:focus-visible { background: var(--surface-3); }
#moremenu > button svg.ic { color: var(--accent-text); width: 22px; height: 22px; }
#moremenu > button span { display: flex; flex-direction: column; } #moremenu > button b { font-weight: 600; } #moremenu > button small { color: var(--muted); font-size: .82rem; }
.mn-sep { border: 0; border-top: 1px solid var(--border); margin: 6px 4px; }
.mn-mode { padding: 8px 12px 10px; display: flex; flex-direction: column; gap: 10px; } .mn-mode-t { display: flex; flex-direction: column; } .mn-mode-t small { color: var(--muted); font-size: .82rem; }
.mn-mode .seg { align-self: stretch; } .mn-mode .seg button { flex: 1; min-height: 40px; }

/* ---------- Komponen ---------- */
/* Gaya tombol: utama (isi) · sekunder (garis) · tersier (.ghost, teks) */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: var(--pad-btn); min-height: 44px; border-radius: var(--r-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: var(--surface-3); } .btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; } .btn.ghost:hover { background: var(--surface-3); }
.btn.danger { color: var(--danger); } .btn.sm { padding: 6px 14px; min-height: 36px; font-size: .9rem; } .btn.lg { padding: 14px 26px; min-height: 54px; font-size: 1.08rem; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.iconbtn { width: 40px; height: 40px; min-height: 0; padding: 0; justify-content: center; border-radius: 10px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-1); }
.card.pad { padding: var(--pad-card); } .card.hover { transition: transform .12s, box-shadow .12s, border-color .12s; cursor: pointer; }
.card.hover:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--border-strong); }
.grid { display: grid; gap: 20px; } .grid.c2 { grid-template-columns: repeat(2, 1fr); } .grid.c3 { grid-template-columns: repeat(3, 1fr); } .grid.c4 { grid-template-columns: repeat(4, 1fr); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.row { display: flex; align-items: center; gap: 12px; } .row.wrap { flex-wrap: wrap; } .col { display: flex; flex-direction: column; gap: 12px; }
.sp { flex: 1; } .muted { color: var(--muted); } .small { font-size: .9rem; } .center { text-align: center; }

.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 11px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border); }
.chip.accent { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; } .chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.scale { color: var(--scale); } .chip.ordinal { color: var(--ordinal); } .chip.nominal { color: var(--nominal); }

input[type=text], input[type=number], input[type=search], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 9px 12px; min-height: 42px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
label.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .95rem; }
.seg { display: inline-flex; background: var(--surface-3); border-radius: 11px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 8px 16px; min-height: 38px; border-radius: 8px; font: inherit; font-weight: 600; font-size: .92rem; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"], .seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tabs button { border: 0; background: transparent; padding: 12px 18px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--accent-text); border-color: var(--accent); }

i.info, .tipi { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--surface-3); color: var(--muted); font-size: .75rem; font-weight: 700; cursor: help; border: 1px solid var(--border); vertical-align: middle; flex: none; font-style: normal; }
i.info:hover, .tipi:hover { background: var(--accent-soft); color: var(--accent-text); }

/* Tooltip global: elemen apa pun dengan data-tip="teks" (opsional data-tip-title) */
#tip { position: fixed; z-index: 1000; max-width: 320px; padding: 9px 12px; border-radius: 9px; background: #161a20; color: #f2f4f8; font-size: .82rem; line-height: 1.45; box-shadow: var(--shadow-2); pointer-events: none; opacity: 0; transform: translateY(2px); transition: opacity .12s, transform .12s; }
#tip.show { opacity: 1; transform: none; } #tip b { display: block; margin-bottom: 2px; color: #fff; }
:root[data-theme="dark"] #tip { background: #e8ebf1; color: #14171c; } :root[data-theme="dark"] #tip b { color: #000; }

/* Callout (laporan & panduan) */
.callout { border-radius: var(--r); padding: 16px 20px; border-left: 4px solid var(--info); background: var(--info-soft); }
.callout b.t { display: block; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 3px; }
.callout.warn { background: var(--warn-soft); border-color: var(--warn-line); } .callout.warn b.t { color: var(--warn); }
.callout.ok { background: var(--ok-soft); border-color: var(--ok); } .callout.ok b.t { color: var(--ok); }
.callout.tip { background: var(--tip-soft); border-color: var(--tip); } .callout.tip b.t { color: var(--tip); }
.callout.interpret { background: var(--accent-soft); border-color: var(--accent); } .callout.interpret b.t { color: var(--accent-text); }
.callout.report { background: var(--surface-2); border-color: var(--border-strong); font-family: var(--font); } .callout.report b.t { color: var(--muted); }
.callout.info b.t { color: var(--info); }

/* Modal & toast */
#modals { position: fixed; inset: 0; z-index: 500; pointer-events: none; }
.scrim { position: fixed; inset: 0; background: rgba(8, 12, 20, .5); backdrop-filter: blur(3px); display: grid; place-items: center; pointer-events: auto; animation: fade .15s; padding: 20px; }
.modal { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-3); width: min(640px, 100%); max-height: calc(var(--vh) - 40px); display: flex; flex-direction: column; border: 1px solid var(--border); animation: pop .18s; }
.modal.wide { width: min(980px, 100%); } .modal.xl { width: min(1180px, 100%); }
.modal > header { display: flex; align-items: center; gap: 10px; padding: 20px 24px; border-bottom: 1px solid var(--border); } .modal > header h3 { flex: 1; }
.modal > .body { padding: 22px 24px; overflow: auto; } .modal > footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 600; }
.toast { background: #161a20; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow-2); display: flex; gap: 10px; align-items: center; animation: pop .2s; max-width: 380px; font-size: .9rem; }
.toast.err { background: #a2191f; } .toast.ok { background: #0e6027; }
@keyframes fade { from { opacity: 0; } } @keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

.empty { text-align: center; padding: 48px 24px; color: var(--muted); } .empty svg.ic { width: 44px; height: 44px; opacity: .5; margin-bottom: 8px; }
.kbd-hint { font-size: .75rem; color: var(--faint); }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 28px 0; }

/* ---------- Kerapian umum ---------- */
::placeholder { color: var(--muted); opacity: .8; }
.kbd-hint { color: var(--muted); }
#tip { max-width: min(320px, calc(100vw - 16px)); overflow-wrap: anywhere; }
.skel { position: relative; overflow: hidden; background: var(--surface-3); border-radius: var(--r-sm); min-height: 14px; }
.skel::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 70%, transparent), transparent); animation: skel 1.3s infinite; }
@keyframes skel { to { transform: translateX(100%); } }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; } }

/* ---------- Responsif ---------- */
@media (max-width: 1180px) { .tb-mode { display: none; } }
@media (max-width: 1040px) { #project { display: none; } .stp-go { display: none; } }
@media (max-width: 900px) {
  :root { --rail-w: 72px; } .view-pad { padding: 28px 24px 56px; } .grid.c3, .grid.c4 { grid-template-columns: repeat(2, 1fr); }
  .railbtn { width: 62px; } .topactions .tb-t { display: none; } #topbar { gap: 10px; }
}
@media (max-width: 620px) { .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; } }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); }

/* Ponsel & tablet potret: rail menjadi bilah navigasi bawah (6 tombol) */
@media (max-width: 800px) {
  :root { --top-h: 56px; --nav-h: calc(62px + var(--safe-b)); }
  html, body { overscroll-behavior: none; }
  #app { grid-template-columns: minmax(0, 1fr); padding-top: var(--safe-t); }
  #app { height: calc(var(--vh) - var(--nav-h)); }
  #topbar { grid-column: 1; gap: 6px; padding: 0 8px 0 10px; }
  #brand { width: auto; } #brand .logo { width: 32px; height: 32px; }
  #steps { margin: 0 auto 0 4px; }
  .stp { padding: 4px 10px 4px 4px; gap: 6px; min-height: 38px; font-size: .9rem; } .stp:not(.now):not(.next) .stp-t { display: none; } .stp:not(.now):not(.next) { padding: 4px; }
  .stp-line { width: 12px; }
  .view-pad { padding: 20px 16px 36px; }
  h1 { font-size: 1.7rem; }

  #rail {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; height: var(--nav-h); padding: 4px 4px var(--safe-b); gap: 0;
    flex-direction: row; justify-content: space-around; align-items: stretch; border-right: 0; border-top: 1px solid var(--border);
    overflow: visible; box-shadow: 0 -4px 14px rgba(16, 24, 40, .06);
  }
  .railbtn { display: flex; flex: 1 1 0; width: auto; max-width: 96px; min-width: 0; padding: 7px 2px 5px; border-radius: 10px; justify-content: center; font-size: .72rem; gap: 3px; }
  .railbtn span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .railbtn[aria-current="page"]::before { left: 22%; right: 22%; top: 0; bottom: auto; width: auto; height: 3px; border-radius: 0 0 3px 3px; }
  #moremenu { right: 8px; top: calc(var(--top-h) + var(--safe-t) - 2px); }

  #main { overscroll-behavior: contain; }
  /* tinggi tampilan penuh memperhitungkan bilah bawah */
  #view .dv-host { height: var(--view-h); }
  .out, .az { height: var(--view-h); }

  /* target sentuh >= 44px, huruf 16px agar iOS tidak memperbesar saat fokus */
  .btn { min-height: var(--touch); } .btn.sm { min-height: 38px; padding: 4px 14px; } .iconbtn { width: var(--touch); height: var(--touch); }
  .seg button, .tabs button { min-height: 40px; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; } .tabs::-webkit-scrollbar { display: none; } .tabs button { flex: none; white-space: nowrap; }
  input[type=text], input[type=number], input[type=search], select, textarea { font-size: 16px; min-height: var(--touch); }
  i.info, .tipi { width: 24px; height: 24px; }
  .callout { padding: 14px 16px; }

  /* toast di atas bilah bawah */
  #toasts { left: 12px; right: 12px; bottom: calc(var(--nav-h) + 10px); align-items: stretch; } .toast { max-width: none; }
}
@media (max-width: 430px) { .topactions { gap: 0; } .topactions .btn.iconbtn, .topactions .btn.ghost { padding: 0 8px; min-width: 40px; } #brand .logo { width: 30px; height: 30px; } }

/* Modal: lembar bawah di ponsel, layar penuh untuk .wide/.xl */
@media (max-width: 640px) {
  .scrim { place-items: end stretch; padding: 0; }
  .modal, .modal.wide, .modal.xl { width: 100%; max-height: calc(var(--vh) - 28px); border-radius: var(--r-lg) var(--r-lg) 0 0; border-bottom: 0; animation: sheet .22s cubic-bezier(.2, .8, .2, 1); }
  .modal.wide, .modal.xl { height: var(--vh); max-height: var(--vh); border-radius: 0; border: 0; }
  .modal > header { padding: 12px 14px 12px 16px; position: sticky; top: 0; background: var(--surface); border-radius: inherit; }
  .modal > .body { padding: 14px 16px; -webkit-overflow-scrolling: touch; }
  .modal > footer { padding: 10px 14px calc(10px + var(--safe-b)); flex-wrap: wrap; } .modal > footer .btn { flex: 1 1 auto; justify-content: center; }
}
@keyframes sheet { from { transform: translateY(40px); opacity: 0; } }
@media (hover: none) { .btn:hover { background: var(--surface); } .btn.primary:hover { background: var(--accent); } .btn.ghost:hover { background: transparent; } .card.hover:hover { transform: none; } }
@media print { #rail, #topbar, #tip, #toasts { display: none !important; } #app { display: block; height: auto; } body { overflow: visible; } #main { overflow: visible; } }

/* Rujukan buku (Field/Bower) tersembunyi kecuali setting showBookRefs */
html:not([data-refs="1"]) .bookref { display: none !important; }

/* Gulir halaman: pastikan area utama selalu menjadi satu-satunya kontainer gulir (WebView desktop). */
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
#app { min-height: 0; }
#main { min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; outline: none; }
.shr { display: flex; flex-direction: column; gap: 10px; }
.shr-row { display: flex; align-items: center; gap: 14px; text-align: left; width: 100%; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.shr-row:hover { border-color: var(--accent); background: var(--accent-soft); }
.shr-row span { display: flex; flex-direction: column; min-width: 0; }
.shr-row small { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
