:root {
  --navy: #14264A;
  --navy-2: #1F3864;
  --accent: #2F5DA8;
  --ok: #3ddc97;
  --bg: #F4F6F9;
  --card: #ffffff;
  --text: #13202e;
  --muted: #5f6f80;
  --danger: #e5484d;
  --radius: 14px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { display: block; }
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; display: none; flex-direction: column; }
.screen.active { display: flex; }

/* ---------- bar ---------- */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + var(--safe-t)) 14px 10px; background: var(--navy); color: #fff; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; letter-spacing: .2px; }
.bar-actions { display: flex; gap: 4px; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: rgba(255,255,255,.12); }

/* menu Scan: ikon + tulisan (bukan simbol saja) */
#home .bar { justify-content: flex-start; padding-bottom: 6px; }
.toolstrip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 0 10px 10px; background: var(--navy); }
.tool { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 58px; padding: 6px 2px;
  border-radius: 12px; background: rgba(255,255,255,.08); color: #fff; font: inherit; font-size: 12px; font-weight: 600; line-height: 1.15; text-align: center; }
.tool svg { width: 22px; height: 22px; flex: none; }
.tool:active { background: rgba(255,255,255,.18); }
.tool { box-shadow: 0 3px 10px rgba(0,0,0,.22), inset 0 1px 0 rgba(255,255,255,.18); text-shadow: 0 1px 1px rgba(0,0,0,.18); }
.tool svg { filter: drop-shadow(0 1px 1px rgba(0,0,0,.18)); }
#home .toolstrip .tool, #home .toolstrip .tool span { color: #fff; opacity: 1; }
/* warna per menu (selaras ikon Beranda Marsup) */
#btnConv { background: linear-gradient(145deg, #F2A54A, #C9611F); }
#btnMerge { background: linear-gradient(145deg, #4A9BE0, #2263A6); }
#btnNew { background: linear-gradient(145deg, #26B3A2, #0E7569); }
#btnSettings { background: linear-gradient(145deg, #8D6CD6, #533A9C); }
.tool:active { filter: brightness(.92); transform: scale(.97); }
.docname { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--navy-2); color: #cfe0f0; }
.docname label { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; white-space: nowrap; }
.docname input { flex: 1; min-width: 0; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15);
  color: #fff; border-radius: 9px; padding: 8px 10px; font: inherit; }

/* ---------- grid halaman ---------- */
.pages-wrap { flex: 1; overflow-y: auto; padding: 14px 14px 120px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
.page-card { position: relative; background: var(--card); border-radius: 10px; padding: 6px; box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 14px rgba(11,29,46,.06); text-align: left; }
.page-card .ph { aspect-ratio: 1 / 1.414; background: #f4f6f8; border-radius: 6px; display: grid; place-items: center; overflow: hidden; }
.page-card img { width: 100%; height: 100%; object-fit: contain; }
.page-card .meta { display: flex; justify-content: space-between; align-items: center; padding: 6px 2px 2px; font-size: 12px; color: var(--muted); }
.page-card .no { position: absolute; top: 10px; left: 10px; background: var(--navy); color: #fff; font-size: 12px; font-weight: 700; border-radius: 6px; padding: 1px 7px; }
.empty { text-align: center; color: var(--muted); padding: 48px 24px; max-width: 360px; margin: 0 auto; }
.empty svg { margin: 0 auto 10px; color: #9fb0c2; }
.empty p { margin: 6px 0; }

/* ---------- dock bawah ---------- */
.dock { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; align-items: center;
  padding: 10px 16px calc(12px + var(--safe-b)); background: rgba(255,255,255,.96); backdrop-filter: blur(8px);
  box-shadow: 0 -1px 0 rgba(0,0,0,.06), 0 -8px 24px rgba(11,29,46,.06); }
.dock-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: var(--navy); width: 72px; padding: 6px 0; border-radius: 10px; }
.dock-btn svg { width: 26px; height: 26px; }
.dock-btn:active { background: #e8eef4; }
.scan-btn { display: flex; align-items: center; gap: 8px; background: var(--accent); color: #fff; font-weight: 700; font-size: 17px;
  padding: 14px 28px; border-radius: 999px; box-shadow: 0 6px 18px rgba(31,143,255,.4); }
.scan-btn svg { width: 24px; height: 24px; }
.scan-btn:active { transform: scale(.97); }

/* ---------- kamera ---------- */
#cam { background: #000; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s; }
#flash.on { opacity: .85; transition: none; }
.cam-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 10px;
  padding: calc(12px + var(--safe-t)) 14px 12px; background: linear-gradient(rgba(0,0,0,.55), transparent); color: #fff; }
.round-btn { width: 42px; height: 42px; border-radius: 50%; background: rgba(0,0,0,.35); display: grid; place-items: center; color: #fff; }
.round-btn svg { width: 22px; height: 22px; }
.round-btn.on { background: #ffd23f; color: #000; }
.res-badge { flex: 1; text-align: center; font-size: 12px; opacity: .85; font-variant-numeric: tabular-nums; }
.pill-btn { padding: 8px 14px; border-radius: 999px; font-weight: 800; font-size: 13px; letter-spacing: .5px; background: rgba(0,0,0,.35); color: #fff; border: 2px solid rgba(255,255,255,.5); }
.pill-btn.on { background: var(--ok); color: #05281a; border-color: var(--ok); }
.cam-hint { position: absolute; left: 50%; top: calc(70px + var(--safe-t)); transform: translateX(-50%); background: rgba(0,0,0,.55);
  color: #fff; padding: 8px 16px; border-radius: 999px; font-size: 14px; white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis; }
.cam-hint.ok { background: rgba(61,220,151,.92); color: #05281a; font-weight: 600; }
.cam-bottom { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 20px 26px calc(26px + var(--safe-b)); background: linear-gradient(transparent, rgba(0,0,0,.65)); }
.shutter { width: 80px; height: 80px; }
.shutter svg { width: 80px; height: 80px; }
.shutter:active svg circle:last-child { r: 25; }
.thumb-btn { position: relative; width: 56px; height: 56px; border-radius: 10px; background: rgba(255,255,255,.15); border: 2px solid #fff; overflow: visible; }
.thumb-btn img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.thumb-btn img:not([src]) { visibility: hidden; }
.count { position: absolute; top: -8px; right: -8px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; min-width: 22px; height: 22px; border-radius: 11px; display: grid; place-items: center; padding: 0 5px; }
.done-btn { min-width: 56px; color: #fff; font-weight: 700; font-size: 16px; padding: 10px 6px; }

/* ---------- editor ---------- */
.screen.dark { background: #0d141b; color: #fff; }
.bar.dark { background: #0d141b; }
.text-btn { padding: 8px 6px; color: #b9c8d6; font-size: 16px; }
.text-btn.strong { color: var(--ok); font-weight: 700; }
.seg { display: flex; background: rgba(255,255,255,.08); border-radius: 10px; padding: 3px; }
.seg-btn { padding: 6px 16px; border-radius: 8px; font-size: 14px; color: #b9c8d6; }
.seg-btn.active { background: #fff; color: var(--navy); font-weight: 600; }
.stage { position: relative; flex: 1; min-height: 0; margin: 6px 10px; }
#cropCanvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#resultImg:not([src]) { visibility: hidden; }
#resultImg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #0d141b; }
#loupe { position: absolute; top: 8px; left: 8px; width: 130px; height: 130px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 4px 16px rgba(0,0,0,.5); display: none; pointer-events: none; background: #000; }
#loupe.right { left: auto; right: 8px; }
.stage-busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(13,20,27,.55); }
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px; scrollbar-width: none; }
.chip { flex: none; padding: 8px 14px; border-radius: 999px; border: 1.5px solid rgba(255,255,255,.25); color: #dbe6f0; font-size: 14px; }
.chip.active { background: #fff; color: var(--navy); border-color: #fff; font-weight: 600; }
.tools { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; padding: 4px 6px calc(10px + var(--safe-b)); }
.tool { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 0; font-size: 10.5px; white-space: nowrap; color: #c8d5e2; border-radius: 10px; }
.tool svg { width: 22px; height: 22px; }
.tool:active { background: rgba(255,255,255,.08); }
.tool.danger { color: #ff8a8d; }

/* ---------- sheet & dialog ---------- */
.scrim { position: fixed; inset: 0; background: rgba(5,12,20,.45); z-index: 20; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: #fff; color: var(--text); border-radius: 18px 18px 0 0;
  padding: 8px 18px calc(18px + var(--safe-b)); max-width: 560px; margin: 0 auto; box-shadow: 0 -10px 40px rgba(0,0,0,.2); animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: #d3dbe3; margin: 4px auto 10px; }
.sheet h3 { margin: 4px 0 6px; font-size: 18px; }
.muted { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.field { display: block; font-size: 13px; color: var(--muted); margin: 10px 0; }
.field select { display: block; width: 100%; margin-top: 5px; padding: 11px 10px; border-radius: 10px; border: 1px solid #cfd8e1; font: inherit; color: var(--text); background: #f8fafc; }
.switch { display: flex; align-items: center; gap: 10px; margin: 12px 0; font-size: 14px; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
.wide { display: block; width: 100%; margin-top: 10px; }
.primary { background: var(--accent); color: #fff; font-weight: 700; padding: 13px; border-radius: 12px; }
.secondary { background: #e6eef7; color: var(--navy); font-weight: 600; padding: 13px; border-radius: 12px; }
.ghost { color: var(--muted); padding: 12px; border-radius: 12px; }
.danger-btn { background: var(--danger); color: #fff; font-weight: 700; padding: 10px 18px; border-radius: 10px; }
.dialog { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(5,12,20,.5); padding: 24px; }
.dialog-box { background: #fff; color: var(--text); border-radius: 16px; padding: 20px; max-width: 340px; width: 100%; }
.dialog-box p { margin: 0 0 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.busy { position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; background: rgba(5,12,20,.6); color: #fff; }
.busy p { margin: 12px 0 0; }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 4px solid rgba(255,255,255,.25); border-top-color: #fff; animation: spin .8s linear infinite; }
.page-card .spinner { border-color: #dbe3ea; border-top-color: var(--accent); width: 28px; height: 28px; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translateX(-50%); z-index: 60; background: #13202e; color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,.25); }

@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

/* ---------- gabung PDF ---------- */
.mg-list { display: flex; flex-direction: column; gap: 10px; }
.mg-item { background: var(--card); border-radius: 12px; padding: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 14px rgba(11,29,46,.06); display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center; }
.mg-ico { width: 40px; height: 48px; border-radius: 6px; background: #fdecec; color: #c62828; display: grid; place-items: center; font-size: 10px; font-weight: 800; position: relative; }
.mg-ico.scan { background: #e6f1ff; color: var(--accent); }
.mg-ico b { position: absolute; top: -6px; left: -6px; background: var(--navy); color: #fff; font-size: 11px; border-radius: 6px; padding: 0 6px; line-height: 18px; }
.mg-info { min-width: 0; }
.mg-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mg-sub { font-size: 12px; color: var(--muted); }
.mg-range { margin-top: 6px; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.mg-range input { flex: 1; min-width: 0; border: 1px solid #cfd8e1; border-radius: 8px; padding: 6px 8px; font: inherit; font-size: 13px; color: var(--text); background: #f8fafc; }
.mg-range input.bad { border-color: var(--danger); background: #fff3f3; }
.mg-btns { display: flex; flex-direction: column; gap: 2px; }
.mg-btns button { width: 34px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: var(--navy); }
.mg-btns button:active { background: #e8eef4; }
.mg-btns button.del { color: var(--danger); }
.mg-btns svg { width: 18px; height: 18px; }
.mg-add { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.mg-add button:disabled { opacity: .45; }
.mg-dock { justify-content: space-between; }
.mg-total { font-size: 13px; color: var(--muted); min-width: 80px; }
.mg-dock .scan-btn:disabled { background: #9db8d6; box-shadow: none; }

/* ---------- konversi PDF ---------- */
.cv-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 10px 12px 0; }
.cv-tab { border-radius: 10px; background: #e8eef4; color: var(--navy); font-size: 11.5px; line-height: 1.25; padding: 8px 2px; }
.cv-tab b { font-size: 12.5px; }
.cv-tab.on { background: var(--navy); color: #fff; }
.cv-wrap { display: flex; flex-direction: column; gap: 10px; }
.cv-hint { font-size: 13px; color: var(--muted); margin: 0; line-height: 1.45; }
.cv-add { width: 100%; }
.cv-thumb { width: 40px; height: 48px; object-fit: cover; border-radius: 6px; background: #eee; }
.cv-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cv-opts label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.cv-opts select, .cv-opts input:not([type=checkbox]) { border: 1px solid #cfd8e1; border-radius: 8px; padding: 8px; font: inherit; font-size: 14px; color: var(--text); background: #fff; min-width: 0; }
.cv-opts .cv-check { flex-direction: row; align-items: center; gap: 8px; align-self: end; padding-bottom: 8px; }
.cv-prev { background: #dfe5ec; border-radius: 12px; padding: 8px; overflow: auto; max-height: 60vh; }
.cv-prev .docx-wrapper { padding: 0 !important; background: transparent !important; }
.cv-prev .docx-wrapper > section.docx { margin: 0 auto 8px !important; }
.cv-prev .xlsheet { margin-bottom: 8px; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.cvsheetname { font-size: 12px; font-weight: 700; color: var(--navy); margin: 4px 0; }
.cv-result { background: #e9f7ef; border: 1px solid #b9e3c9; border-radius: 12px; padding: 12px; font-size: 14px; }
.cv-resbtn { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.cv-resbtn button:only-child { grid-column: 1 / -1; }

/* pratinjau Word = sama dengan hasil cetak (tanpa line-height halaman Scan) */
#cvPrevIn { line-height: normal; }

/* tekan lama halaman → menu Hapus */
.page-card { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; touch-action: manipulation; }
.page-card img { pointer-events: none; }
.page-card.held { outline: 3px solid var(--accent); transform: scale(.97); transition: transform .12s; }
.pg-menu { position: fixed; inset: 0; z-index: 60; background: rgba(11,29,46,.45); display: flex; align-items: flex-end; justify-content: center; }
.pg-menu-in { width: 100%; max-width: 520px; background: #fff; border-radius: 18px 18px 0 0; padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; animation: pgUp .16s ease-out; }
.pg-menu-in b { font-size: 15px; color: var(--navy); padding: 2px 6px 6px; }
.pg-menu-in button { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 50px; border-radius: 12px; border: 1px solid #dbe3ea; background: #fff; font: inherit; font-size: 16px; font-weight: 600; color: var(--navy); }
.pg-menu-in button svg { width: 20px; height: 20px; }
.pg-menu-in button.danger { background: #fdecec; border-color: #f5c2c2; color: #c62828; }
.pg-menu-in button.ghost { color: var(--muted); }
@keyframes pgUp { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }

/* Gabung PDF: urutan halaman (geser) */
.mg-pw { margin-top: 16px; }
.mg-ph { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.mg-ph > div { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.mg-ph b { color: var(--navy); font-size: 15px; }
.mg-ph span { color: var(--muted); font-size: 12px; line-height: 1.35; }
.mg-reset { flex: none; font-size: 12px; font-weight: 600; color: var(--accent); padding: 6px 10px; border-radius: 8px; background: #e6eef7; }
.mg-pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.mg-pg { position: relative; background: var(--card); border-radius: 10px; padding: 6px 6px 4px; box-shadow: 0 1px 3px rgba(0,0,0,.1); cursor: pointer; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.mg-th { aspect-ratio: 0.72; background: #eef2f6; border-radius: 4px; overflow: hidden; display: grid; place-items: center; }
.mg-th img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.mg-th img:not([src]) { visibility: hidden; }
.mg-no { position: absolute; top: 2px; left: 2px; background: var(--navy); color: #fff; font-size: 12px; font-weight: 800; border-radius: 6px; padding: 1px 7px; }
.mg-grip { position: absolute; top: 2px; right: 2px; width: 34px; height: 34px; border-radius: 8px; background: rgba(20,38,74,.85); color: #fff; font-size: 18px; line-height: 1; display: grid; place-items: center; touch-action: none; cursor: grab; }
.mg-src { font-size: 11px; color: var(--muted); text-align: center; padding-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mg-hole { opacity: .25; outline: 2px dashed var(--accent); }
.mg-ghost { position: fixed; left: 0; top: 0; z-index: 80; pointer-events: none; box-shadow: 0 10px 28px rgba(0,0,0,.35); opacity: .95; transition: none; }
.mg-to { display: flex; align-items: center; gap: 8px; padding: 4px 2px; }
.mg-to span { flex: 1; color: var(--navy); font-weight: 600; font-size: 15px; }
.mg-to input { width: 72px; min-height: 46px; border: 1px solid #cdd7e1; border-radius: 10px; text-align: center; font: inherit; font-size: 17px; font-weight: 700; }
.mg-to button { min-height: 46px; padding: 0 16px; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 700; border: 0; }
