:root {
  --bg: #f4f5f8; --surface: #ffffff; --surface-2: #f0f2f6; --border: #e1e4ea; --text: #161a22; --muted: #6b7280;
  --accent: #e5484d; --primary: #6d4aff; --primary-2: #5a37f0; --ok: #16a34a; --warn: #d97706; --busy: #0891b2;
  --radius: 14px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --surface: #171a21; --surface-2: #1f232c; --border: #2a2f3a; --text: #eceef3; --muted: #9aa1ad;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #171a21; --surface-2: #1f232c; --border: #2a2f3a; --text: #eceef3; --muted: #9aa1ad;
  --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.app { max-width: 540px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 6px; }
.brand { display: flex; gap: 10px; align-items: center; }
.brand .logo { font-size: 26px; }
.brand b { display: block; font-size: 16px; }
.brand small { color: var(--muted); font-size: 12px; }
.top-btns { display: flex; gap: 6px; }

.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 6px 16px 4px; padding: 4px;
  background: var(--surface-2); border-radius: 12px; position: sticky; top: 0; z-index: 5; }
.tabs button { border: 0; background: none; padding: 8px 4px; border-radius: 9px; cursor: pointer; font-weight: 600;
  color: var(--muted); display: flex; gap: 6px; justify-content: center; align-items: center; }
.tabs button i { font-style: normal; font-size: 11px; width: 18px; height: 18px; border-radius: 50%; display: grid;
  place-items: center; background: var(--border); }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tabs button.active i { background: var(--primary); color: #fff; }
.tabs button.done i { background: var(--ok); color: #fff; }

main { flex: 1; padding: 6px 16px 120px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px;
  margin: 8px 0; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 10px; font-size: 14px; display: flex; align-items: center; gap: 8px; min-height: 28px; }
.card h3 > i { font-style: normal; font-size: 11px; width: 20px; height: 20px; border-radius: 50%; display: grid;
  place-items: center; background: var(--primary); color: #fff; flex: none; }
.card h3 small { color: var(--muted); font-weight: 400; }
.head-btns { margin-left: auto; display: flex; gap: 4px; }
.row { display: flex; gap: 12px; align-items: center; }
.row.top { align-items: flex-start; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.note { margin: 8px 2px; color: var(--muted); font-size: 13px; }

.fld { display: flex; flex-direction: column; gap: 4px; margin: 0 0 8px; }
.fld > span { font-size: 12px; color: var(--muted); }
input, select, textarea { width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px;
  padding: 8px 10px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 44px; }
textarea.is-default { color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

button { cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }
.icon { border: 1px solid var(--border); background: var(--surface); border-radius: 9px; padding: 6px 9px; }
.ghost { border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 5px 10px;
  font-size: 12.5px; white-space: nowrap; }
.ghost:hover, .icon:hover { border-color: var(--primary); }
.ghost.done { border-color: var(--ok); color: var(--ok); }
.primary { border: 0; background: var(--primary); color: #fff; border-radius: 10px; padding: 11px 16px; font-weight: 700;
  font-size: 14.5px; }
.primary:hover:not(:disabled) { background: var(--primary-2); }

.seg { display: flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 3px; margin-bottom: 10px; }
.seg button { flex: 1; border: 0; background: none; padding: 6px; border-radius: 7px; font-size: 12.5px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* Slot gambar: klik = pilih, seret = letak, 📋 = tampal */
.slot { position: relative; flex: none; border: 1.5px dashed var(--border); border-radius: 12px; background: var(--surface-2);
  display: grid; place-items: center; text-align: center; cursor: pointer; overflow: hidden; color: var(--muted);
  font-size: 11.5px; padding: 4px; }
.slot.sm { width: 92px; height: 122px; }
.slot.big { width: 132px; height: 234px; }
.slot.flow { width: 100px; height: 178px; }
.slot.over { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, var(--surface-2)); }
.slot.has { border-style: solid; padding: 0; }
.slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.slot .tools { position: absolute; right: 4px; bottom: 4px; display: flex; gap: 3px; }
.slot .tools button { border: 0; border-radius: 6px; padding: 2px 6px; font-size: 12px; background: rgba(0, 0, 0, .55); color: #fff; }
.slot .ph b { display: block; font-size: 20px; }

.analysis { flex: 1; font-size: 13px; white-space: pre-line; }
.analysis b { font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 4px 10px; font-size: 12.5px; }
.chip.on { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 14%, var(--surface)); }

.steps { margin: 8px 0 4px; padding-left: 20px; font-size: 13px; }
.steps li { margin: 6px 0; }
.watch { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.check { font-size: 13px; white-space: pre-line; }
.badge { display: inline-block; color: #fff; border-radius: 7px; padding: 3px 9px; font-weight: 700; font-size: 12.5px; margin-bottom: 6px; }
.badge.lulus { background: var(--ok); } .badge.sederhana { background: var(--warn); } .badge.gagal { background: var(--accent); }
.frames { align-items: flex-start; flex-wrap: wrap; }
.frames .side { min-width: 150px; }
#flowSrc { white-space: pre-line; margin: 0; }
.frame b { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.side { display: flex; flex-direction: column; gap: 6px; }
.out textarea { background: var(--surface); }

.bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; }
.bar > * { max-width: 540px; margin: 0 auto; }
.bar { background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border); padding: 8px 16px calc(10px + env(safe-area-inset-bottom)); }
.status { display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--muted); min-height: 20px; margin-bottom: 6px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.status.busy .dot { background: var(--busy); animation: pulse 1s infinite; }
.status.ok .dot { background: var(--ok); } .status.error .dot { background: var(--accent); }
.status.error { color: var(--accent); }
@keyframes pulse { 50% { opacity: .3; } }
.bar-btns { display: flex; gap: 8px; }
.bar-btns .primary { flex: 1; }
.toast { position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 8px 14px; border-radius: 10px; font-size: 13px; z-index: 20; max-width: 90vw; }

@media (max-width: 420px) {
  .slot.big { width: 112px; height: 199px; }
  .slot.flow { width: 86px; height: 153px; }
  .tabs button { font-size: 13px; gap: 4px; }
}
