:root {
  --bg: #f4f6f3; --surface: #ffffff; --ink: #1b262c; --ink-2: #51606a; --line: #dfe5df;
  --accent: #0f766e; --accent-ink: #ffffff; --warn: #b45309; --danger: #c62828; --ok: #2e7d32;
  --radius: 12px; --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11181c; --surface: #1a2328; --ink: #e8eef0; --ink-2: #9db0b9; --line: #2b383e; --accent: #2dd4bf; --accent-ink: #062b27; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: none; }
#app { height: 100%; display: flex; flex-direction: column; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 18px; } h2 { font-size: 18px; } h3 { font-size: 15px; margin: 14px 0 8px; }
p { margin: 6px 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.topbar { display: flex; align-items: center; gap: 8px; padding: calc(var(--sat) + 8px) 12px 8px; background: var(--surface); border-bottom: 1px solid var(--line); min-height: 52px; }
.topbar h1 { flex: 1; }
.top-actions { display: flex; gap: 2px; }
.title-input { flex: 1; min-width: 0; border: 0; background: transparent; font-size: 17px; font-weight: 650; padding: 8px 4px; border-radius: 8px; }
.title-input:focus { background: var(--bg); outline: 2px solid var(--accent); }
.icon-btn { min-width: 44px; height: 44px; border: 0; background: transparent; border-radius: 10px; font-size: 20px; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover:not(:disabled) { background: var(--bg); }
.icon-btn.danger { color: var(--danger); }

.screen { flex: 1; overflow-y: auto; padding: 14px 14px calc(96px + var(--sab)); max-width: 880px; width: 100%; margin: 0 auto; -webkit-overflow-scrolling: touch; }
.footbar { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 14px calc(10px + var(--sab)); background: var(--surface); border-top: 1px solid var(--line); display: flex; gap: 8px; z-index: 5; }
.footbar.two .btn { flex: 1; }
.footbar .wide { flex: 1; }

.btn { min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.on { background: color-mix(in srgb, var(--accent) 16%, var(--surface)); border-color: var(--accent); }
.btn.alert { border-color: var(--danger); color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; }
.btn.round { width: 44px; padding: 0; border-radius: 50%; font-size: 20px; }
.btn.wide { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn-col { display: flex; flex-direction: column; gap: 8px; }

.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; font-size: 13px; }
.field > span { color: var(--ink-2); font-weight: 600; }
.field input, .field select { height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); width: 100%; min-width: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 420px) { .row4 { grid-template-columns: 1fr 1fr; } }
.hint { color: var(--ink-2); font-size: 13px; }
.hint.warn, .warn { color: var(--warn); }
.hint.center { text-align: center; }
.meta { color: var(--ink-2); font-size: 13px; margin: 2px 0; }
.meta.dim { opacity: .8; }
.callout { background: color-mix(in srgb, var(--warn) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 35%, var(--line)); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; font-size: 13px; }

.stepper { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.stepper .dot { width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; background: var(--line); color: var(--ink-2); }
.stepper .dot.on { background: var(--accent); color: var(--accent-ink); }
.stepper .dot.done { background: color-mix(in srgb, var(--accent) 30%, var(--line)); }
.steplabel { font-weight: 650; margin-left: 4px; }

.seg { display: flex; gap: 6px; }
.seg-btn { flex: 1; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; }
.seg-btn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.counter { display: flex; align-items: center; gap: 14px; }
.counter output { min-width: 28px; text-align: center; font-size: 20px; font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; }
.chip.on { background: color-mix(in srgb, var(--accent) 16%, var(--surface)); border-color: var(--accent); font-weight: 650; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: 14px; }
.check input { width: 20px; height: 20px; }
.lot-preview { margin-top: 12px; }
.lot-preview svg { width: 100%; max-height: 280px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }

.proj-list { display: grid; gap: 10px; }
.proj-card { display: flex; align-items: center; gap: 12px; padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; }
.proj-card:hover { border-color: var(--accent); }
.proj-info { flex: 1; min-width: 0; }
.proj-info h3 { margin: 0 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.thumb svg { display: block; width: 100%; height: auto; }
.thumb.sm { width: 76px; height: 96px; flex: none; display: flex; align-items: center; justify-content: center; }
.thumb.sm svg { width: 100%; height: 100%; }
.thumb.empty { font-size: 11px; color: var(--ink-2); text-align: center; padding: 6px; }
.empty { text-align: center; padding: 36px 8px 12px; }
.empty p { color: var(--ink-2); }
.home-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 16px; }

.opt-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.opt-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.opt-head { display: flex; justify-content: space-between; align-items: center; }
.opt-head h3 { margin: 0; }
.score { font-weight: 700; padding: 2px 10px; border-radius: 999px; font-size: 13px; }
.score.good { background: #dcfce7; color: #166534; } .score.mid { background: #fef3c7; color: #92400e; } .score.low { background: #fee2e2; color: #991b1b; }
.traits { color: var(--accent); font-weight: 600; font-size: 13px; margin: 0; }
.notes { margin: 4px 0; padding-left: 18px; font-size: 12.5px; color: var(--ink-2); }
.notes li.error { color: var(--danger); } .notes li.warn { color: var(--warn); }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--line); flex: none; }
.screen > .tabs { margin: 0 0 12px; padding: 0; background: transparent; border: 0; }
.tab { min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 13px; white-space: nowrap; }
.tab.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tab.fitbtn { margin-left: auto; }

/* Editor */
.stage { flex: 1; min-height: 0; position: relative; overflow: hidden; }
.canvas { position: absolute; inset: 0; background: var(--bg); touch-action: none; }
.plan { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; cursor: crosshair; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; box-shadow: 0 -4px 16px rgba(0,0,0,.08); max-height: 50%; overflow-y: auto; z-index: 2; }
@media (min-width: 900px) { .sheet { left: auto; right: 12px; bottom: 12px; width: 360px; border-radius: 16px; border: 1px solid var(--line); max-height: calc(100% - 24px); } }
.sheet.collapsed { max-height: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 12px; min-height: 48px; position: sticky; top: 0; background: var(--surface); cursor: pointer; }
.sheet-head .grip { position: absolute; left: 50%; top: 6px; width: 36px; height: 4px; border-radius: 2px; background: var(--line); transform: translateX(-50%); }
.sheet-body { padding: 0 12px 12px; }
.toolbar { display: flex; gap: 6px; padding: 8px 10px calc(8px + var(--sab)); background: var(--surface); border-top: 1px solid var(--line); align-items: center; flex: none; }
.toolbar .btn { flex: 1; min-width: 0; padding: 0 6px; white-space: nowrap; font-size: 13.5px; }
.sync { font-size: 11px; color: var(--ink-2); padding: 0 6px; white-space: nowrap; }
.sync.gagal { color: var(--danger); } .sync.tersimpan { color: var(--ok); }

.issues { list-style: none; padding: 0; margin: 0 0 8px; }
.issues li { padding: 4px 0; border-bottom: 1px solid var(--line); }
.issues li.error .link { color: var(--danger); } .issues li.warn .link { color: var(--warn); }
.link { background: none; border: 0; padding: 8px 0; text-align: left; font-size: 14px; text-decoration: underline; }
.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.type-btn { min-height: 52px; border: 1px solid var(--line); border-radius: 10px; font-weight: 600; color: #1b262c; padding: 6px; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 30; }
.modal { width: 100%; max-width: 520px; background: var(--surface); border-radius: 16px 16px 0 0; max-height: 86vh; display: flex; flex-direction: column; padding-bottom: var(--sab); }
@media (min-width: 640px) { .overlay { align-items: center; } .modal { border-radius: 16px; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 4px; }
.modal-body { padding: 4px 14px 12px; overflow-y: auto; }
.modal-actions { display: flex; gap: 8px; padding: 8px 14px 14px; justify-content: flex-end; flex-wrap: wrap; }
.modal-actions .btn { flex: 1; }

#toast { position: fixed; left: 50%; bottom: calc(110px + var(--sab)); transform: translateX(-50%) translateY(20px); background: #263238; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; z-index: 40; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.error { background: var(--danger); }

#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; color: #000; background: #fff; }
  .print-page { page-break-after: always; }
  .print-page svg { width: 100%; height: auto; max-height: 24cm; }
  html, body { background: #fff; height: auto; }
}
