:root {
  --bg: #f4f5f7; --card: #fff; --text: #1d2433; --muted: #6b7280; --border: #d9dde3;
  --primary: #0b5cad; --green: #1f8a4c; --red: #c0392b; --amber: #b7791f; --purple: #5b3fa8;
  --sec: #ece9dc; --hold: #fdecea;
  --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
body.noscroll { overflow: hidden; }
#app { max-width: 820px; margin: 0 auto; min-height: 100vh; }
main { padding: 12px 14px calc(24px + var(--sb)); }
main.loading { padding: 40px; text-align: center; color: var(--muted); }
h2, h3, h4 { margin: 0 0 8px; }
h3 { font-size: 15.5px; }
h4 { font-size: 14px; margin-top: 14px; }
.m0 { margin: 0; }

/* header */
.hd { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; background: var(--primary); color: #fff;
  padding: calc(10px + var(--st)) 12px 10px; min-height: 56px; }
.hd .bk { background: none; border: 0; color: #fff; font-size: 32px; line-height: 1; padding: 0 6px 4px 0; cursor: pointer; }
.hd .ht { flex: 1; min-width: 0; }
.hd .t1 { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hd .t2 { font-size: 12.5px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hlogo { width: 36px; height: 36px; border-radius: 7px; background: #fff; }
.sheet .hd { position: sticky; border-radius: 0; }
.sheet .hd .btn.ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.6); }

/* tabs */
.tabs { position: sticky; top: calc(56px + var(--st)); z-index: 9; display: flex; background: #fff; border-bottom: 1px solid var(--border); }
.tabs button { flex: 1; background: none; border: 0; border-bottom: 3px solid transparent; padding: 11px 2px; font-weight: 700; font-size: 13px; color: var(--muted); cursor: pointer; }
.tabs button.on { color: var(--primary); border-color: var(--primary); }

/* card */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.card.tap { cursor: pointer; }
.card.tap:active { background: #f0f5fb; }
.card.dim { opacity: .5; }
.big { font-size: 16px; }
.ttl { font-weight: 600; margin-top: 2px; }
.pri { color: var(--primary); }
.red { color: var(--red); } .green { color: var(--green); } .amber { color: var(--amber); }
.muted { color: var(--muted); font-size: 13px; }
.muted.pri { color: var(--primary); }
.ell { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mt { margin-top: 8px; } .mb { margin-bottom: 8px; }
.blk { display: block; }
.right { text-align: right; }
.grp { font-weight: 700; color: var(--muted); margin: 12px 2px 6px; }
.foot { text-align: center; margin-top: 20px; }
.spacer { height: 110px; }

/* layout */
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.nw { flex-wrap: nowrap; }
.row.sb { justify-content: space-between; }
.row.top { align-items: flex-start; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.col .btn { width: 100%; }
.fx { flex: 1; min-width: 0; }

/* buttons */
.btn { border: 1px solid transparent; border-radius: 10px; padding: 12px 16px; font-weight: 700; font-size: 15px; cursor: pointer;
  background: var(--primary); color: #fff; font-family: inherit; }
.btn.sm { padding: 7px 11px; font-size: 13px; border-radius: 8px; }
.btn.ghost { background: #fff; color: var(--primary); border-color: var(--primary); }
.btn.green { background: var(--green); }
.btn.danger { background: var(--red); }
.btn.purple { background: var(--purple); }
.btn.link { background: none; color: var(--primary); padding: 4px 6px; font-weight: 600; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.block { display: block; width: 100%; }
.btn:active:not(:disabled) { filter: brightness(.92); }
.lnk { color: var(--primary); cursor: pointer; font-size: 13px; text-decoration: underline; }
.lnk.red { color: var(--red); }

.chip { --c: var(--primary); border: 1.5px solid var(--c); color: var(--c); background: #fff; border-radius: 999px; padding: 6px 12px;
  font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit; text-align: left; }
.chip.on { background: var(--c); color: #fff; }
.badge { color: #fff; font-size: 11px; font-weight: 800; padding: 3px 7px; border-radius: 6px; letter-spacing: .3px; white-space: nowrap; }
.bar { height: 6px; background: #e5e7eb; border-radius: 4px; margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--green); }

/* forms */
.fld { display: block; margin-bottom: 10px; }
.fld > span { display: block; font-weight: 600; color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.fld input, .fld textarea, .fld select, .search { width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px;
  font: inherit; font-size: 16px; background: #fff; color: var(--text); }
.fld textarea { resize: vertical; min-height: 80px; }
.fld input:disabled, .fld textarea:disabled { background: #f3f4f6; color: var(--muted); }
.fld.date { margin-bottom: 0; }
.fld.date input { padding: 8px 10px; min-height: 40px; }
.search { margin-bottom: 8px; }
.switch { display: flex; gap: 12px; align-items: center; margin-top: 6px; }
.switch input { width: 22px; height: 22px; }
.cbl { display: flex; gap: 10px; align-items: flex-start; margin: 8px 0; cursor: pointer; }
.cbl input { width: 20px; height: 20px; margin: 0; flex-shrink: 0; }

/* task list */
.task { display: flex; gap: 8px; align-items: flex-start; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-bottom: 6px; cursor: pointer; }
.task.done { background: #eaf6ee; } .task.na { background: #f1f1f1; } .task.hold { background: var(--hold); }
.tno { width: 36px; font-weight: 700; flex-shrink: 0; }
.tst { min-width: 82px; text-align: right; display: flex; flex-direction: column; }
.tst small { color: var(--muted); font-size: 11px; }
.codes { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.codes span { border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; font-size: 11px; }
.codes span.h { border-color: var(--red); color: var(--red); }
.sec { display: flex; align-items: center; background: var(--sec); padding: 8px 10px; border-radius: 8px; margin: 8px 0 4px; }
.sec.tap { cursor: pointer; }
.mv { display: flex; gap: 2px; }
.mv button { border: 0; background: none; color: var(--primary); font-size: 18px; padding: 2px 6px; cursor: pointer; }
.ctlrow { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.cbox { width: 36px; height: 30px; border: 1.5px solid var(--primary); border-radius: 7px; display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--primary); flex-shrink: 0; }
.cbox.on { background: #eef4fb; } .cbox.h { border-color: var(--red); color: var(--red); }

/* comments, attachments, sign */
.ctext { margin-top: 4px; white-space: normal; }
.thumb { width: 92px; height: 70px; object-fit: cover; border-radius: 7px; background: #ddd; flex-shrink: 0; }
.thumb.doc { display: flex; align-items: center; justify-content: center; background: #e8eef7; color: var(--primary); font-weight: 800; }
.prevs { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-bottom: 10px; }
.prevs img { width: 100%; height: 160px; object-fit: contain; background: #e5e7eb; border-radius: 8px; }
.rph { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.sorow { border-bottom: 1px solid var(--border); padding: 9px 0; }
.sorow:last-child { border-bottom: 0; }
img.sig { width: 130px; height: 52px; object-fit: contain; background: #fafafa; border: 1px solid var(--border); border-radius: 6px; }
img.sig.sm { width: 92px; height: 36px; }
.selrow { display: flex; gap: 10px; align-items: flex-start; }
.selrow.on { border-color: var(--primary); }
.selrow2 { display: flex; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.ck { font-size: 20px; width: 26px; color: var(--muted); flex-shrink: 0; line-height: 1.1; }
.selrow.on .ck, .ck.on { color: var(--primary); }
.ptw { border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 10px; }

/* footer aksi */
.ft { position: fixed; left: 0; right: 0; bottom: 0; z-index: 8; background: #fff; border-top: 1px solid var(--border);
  padding: 10px 14px calc(10px + var(--sb)); max-width: 820px; margin: 0 auto; }
.ft .btn { padding: 12px; }

/* modal */
#modal { display: none; }
#modal.on { display: flex; position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); align-items: center; justify-content: center; }
.sheet { background: var(--bg); width: 100%; height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: var(--sb); }
.sheet .pad { padding: 12px 14px 30px; }
.sheet.small { width: min(92vw, 420px); height: auto; max-height: 90vh; border-radius: 14px; padding: 18px; background: #fff; }
.sheet.bottom { align-self: flex-end; height: auto; max-height: 88vh; border-radius: 16px 16px 0 0; background: #fff; max-width: 820px; }
.fname { font-weight: 700; word-break: break-all; margin: 4px 0; }
@media (min-width: 821px) { .sheet:not(.small):not(.bottom) { width: 820px; height: 92vh; border-radius: 14px; } }

/* pad tanda tangan */
.sigwrap { position: fixed; inset: 0; background: #fff; display: flex; flex-direction: column; padding: calc(10px + var(--st)) 10px calc(10px + var(--sb)); }
.sighd { padding: 4px 4px 8px; }
.sigbox { position: relative; flex: 1; border: 1.5px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff; }
.sigbox canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.sigline { position: absolute; left: 8%; right: 8%; bottom: 22%; border-top: 1.5px dashed #b7bcc5; color: #9aa3af; font-size: 12px; padding-top: 4px; text-align: center; pointer-events: none; }
.sigbtns { display: flex; gap: 8px; padding-top: 10px; }
.sigbtns .btn { flex: 1; }

/* busy & toast */
#busy { display: none; }
#busy.on { display: flex; position: fixed; inset: 0; z-index: 90; background: rgba(255,255,255,.7); align-items: center; justify-content: center; }
#busy > div { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 16px 20px; display: flex; gap: 12px; align-items: center; box-shadow: 0 6px 24px rgba(0,0,0,.12); max-width: 80vw; }
#busy i { width: 22px; height: 22px; border: 3px solid #cfe0f3; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
#toast { position: fixed; left: 50%; bottom: calc(24px + var(--sb)); transform: translateX(-50%) translateY(30px); opacity: 0; z-index: 95;
  background: #1d2433; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: 90vw; transition: all .25s; pointer-events: none; }
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
