/* Kastral — gaya dasar. Flat, tanpa gradasi. Biru gelap utama, merah gelap untuk aksi penting. */
:root {
  --bg: #F4F6F9; --card: #FFFFFF; --card-2: #F8FAFC; --ink: #1A2433; --ink-2: #3A4656; --muted: #5B6575;
  --line: #DDE2EA; --line-2: #EEF1F5;
  --brand: #1E3A5F; --brand-hover: #172D4A; --brand-ink: #FFFFFF; --brand-soft: #E6ECF4; --link: #1E3A5F;
  --danger: #8B1E2D; --danger-hover: #721826; --danger-text: #8B1E2D; --danger-soft: #F7E8EA;
  --focus: #1E3A5F;
  --radius: 10px; --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B1220; --card: #121B2D; --card-2: #1A2540; --ink: #E6EAF2; --ink-2: #C3CBD8; --muted: #9AA6BA;
    --line: #26324A; --line-2: #1A2540;
    --brand: #3F6FB0; --brand-hover: #4A7BC0; --brand-soft: #1A2A44; --link: #5B8BD0;
    --danger: #B42A38; --danger-hover: #C33443; --danger-text: #F08A8A; --danger-soft: #2E1620;
    --focus: #5B8BD0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0B1220; --card: #121B2D; --card-2: #1A2540; --ink: #E6EAF2; --ink-2: #C3CBD8; --muted: #9AA6BA;
  --line: #26324A; --line-2: #1A2540;
  --brand: #3F6FB0; --brand-hover: #4A7BC0; --brand-soft: #1A2A44; --link: #5B8BD0;
  --danger: #B42A38; --danger-hover: #C33443; --danger-text: #F08A8A; --danger-soft: #2E1620;
  --focus: #5B8BD0;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 16px; line-height: 1.45; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.2; }
h1 { font-size: 1.55rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
a { color: var(--link); }
img { max-width: 100%; display: block; }
.muted { color: var(--muted); } .small { font-size: .875rem; } .tiny { font-size: .78rem; }
.mono { font-family: var(--mono); }
.danger-text { color: var(--danger-text); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; } .row.nowrap { flex-wrap: nowrap; } .row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.center { text-align: center; }

/* tombol: area sentuh minimal 44 px */
.btn { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; padding: 10px 16px; border-radius: var(--radius-sm);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; text-decoration: none; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { background: var(--danger-hover); }
.btn.danger-line { color: var(--danger-text); border-color: var(--danger-text); background: transparent; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--line-2); }
.btn.soft { background: var(--brand-soft); border-color: var(--brand-soft); color: var(--link); }
.btn.sm { padding: 6px 12px; min-height: 36px; font-size: .9rem; }
.btn.lg { padding: 14px 22px; min-height: 54px; font-size: 1.05rem; }
.btn.xl { padding: 16px 24px; min-height: 64px; font-size: 1.15rem; }
.btn.block { width: 100%; }
.btn.loading { position: relative; color: transparent !important; }
.btn.loading::after { content: ""; position: absolute; width: 18px; height: 18px; border: 2px solid var(--muted); border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { appearance: none; border: 0; background: transparent; color: inherit; width: 44px; height: 44px; border-radius: var(--radius-sm); cursor: pointer; font-size: 1.1rem; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--line-2); }

/* form */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-label { font-weight: 600; font-size: .92rem; }
.hint { color: var(--muted); font-size: .82rem; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 12px; width: 100%; min-height: 46px; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .icon-btn:focus-visible, a:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
input[type="color"] { padding: 4px; height: 46px; width: 70px; }
input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); margin: 0; }
input[type="time"] { min-width: 0; }
.check { display: flex; gap: 10px; align-items: center; cursor: pointer; min-height: 44px; }
.seg { display: inline-flex; background: var(--line-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { appearance: none; border: 0; background: transparent; font: inherit; font-weight: 600; color: var(--ink-2); padding: 8px 14px; border-radius: 6px; cursor: pointer; min-height: 40px; }
.seg button.on { background: var(--brand); color: var(--brand-ink); }

/* kartu & tata letak */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 14px; }
.grid > .card + .card, .kpis > * + * { margin-top: 0; }
.card h3 { margin-bottom: 10px; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.kpi .v { font-size: 1.45rem; font-weight: 700; margin-top: 2px; }
.kpi .l { color: var(--muted); font-size: .85rem; }
.divider { height: 1px; background: var(--line); margin: 14px 0; border: 0; }

/* lencana */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 6px; font-size: .78rem; font-weight: 700; background: var(--line-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.badge.brand { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.badge.soft { background: var(--brand-soft); color: var(--link); border-color: var(--brand-soft); }
.badge.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.badge.danger-line { background: transparent; color: var(--danger-text); border-color: var(--danger-text); }
.badge.line { background: transparent; }

/* tabel */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
table.tbl { border-collapse: collapse; width: 100%; font-size: .92rem; }
.tbl th, .tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { font-size: .8rem; color: var(--muted); font-weight: 700; background: var(--card-2); white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.num, .tbl th.num { text-align: right; white-space: nowrap; }

/* tab */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; margin-bottom: 16px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { appearance: none; border: 0; background: transparent; font: inherit; font-weight: 600; color: var(--muted); padding: 12px 14px; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; min-height: 46px; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--brand); }

/* toast & modal */
.toasts { position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 1000; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: var(--radius-sm); font-weight: 600; transition: opacity .3s, transform .3s; pointer-events: auto; }
.toast.err { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }
.modal-wrap { position: fixed; inset: 0; background: rgba(5, 10, 20, .55); display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; align-items: center; z-index: 900; padding: 16px; animation: fade .15s; }
.modal-wrap.out { opacity: 0; transition: opacity .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); width: min(100%, 480px); min-width: 0; max-width: 100%; max-height: calc(100dvh - 32px); display: flex; flex-direction: column; }
.modal-wrap.big .modal { width: min(100%, 760px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 16px; overflow: auto; min-width: 0; overflow-wrap: anywhere; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
@media (max-width: 560px) {
  .modal-wrap { align-items: end; padding: 0; }
  .modal { width: 100%; border-radius: var(--radius) var(--radius) 0 0; max-height: 92dvh; }
  .modal-foot .btn { flex: 1; }
}

.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.boot { min-height: 70vh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
.banner { padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--brand-soft); color: var(--ink); margin-bottom: 14px; }
.banner.danger { background: var(--danger-soft); border-color: var(--danger-text); }
.qr-box svg { width: 100%; height: auto; max-width: 260px; }
kbd { font-family: var(--mono); background: var(--line-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font-size: .85em; }

[hidden] { display: none !important; }
.ic { display: inline-flex; width: 1.15em; height: 1.15em; vertical-align: -0.2em; flex: none; }
.ic svg { width: 100%; height: 100%; display: block; }
.ic.g { margin-right: .4em; }
.btn .ic.g:last-child, .icon-btn .ic { margin-right: 0; }
.ic.flame { color: var(--danger-text); }
.sdot { display: inline-block; width: .6em; height: .6em; border-radius: 50%; background: var(--line); margin-right: .45em; vertical-align: .05em; border: 1px solid var(--muted); }
.sdot.on { background: #1E8E4E; border-color: #1E8E4E; }
.info-note { margin: 2px 0 12px; font-size: .88rem; color: var(--muted); }
.info-note > summary { display: inline-flex; align-items: center; cursor: pointer; list-style: none; color: var(--muted); font-weight: 600; font-size: .82rem; padding: 4px 8px 4px 6px; border-radius: 999px; border: 1px solid var(--line); user-select: none; }
.info-note > summary::-webkit-details-marker { display: none; }
.info-note > summary:hover { color: var(--ink); border-color: var(--muted); }
.info-note[open] > summary { color: var(--ink); background: var(--line-2); }
.info-note .info-body { margin-top: 8px; padding: 10px 12px; background: var(--card-2); border: 1px solid var(--line); border-radius: var(--radius-sm); line-height: 1.5; color: var(--ink-2); }
.card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---- ruang napas: jarak antarelemen lebih lega ---- */
.card { padding: 20px; }
.card + .card { margin-top: 18px; }
.card h3 { margin-bottom: 14px; }
.card h4 { margin: 20px 0 8px; }
.field { margin-bottom: 18px; gap: 8px; }
.row { gap: 12px; }
.stack > * + * { margin-top: 14px; }
.grid { gap: 18px; }
.kpis { gap: 14px; }
.kpi { padding: 16px; }
.divider { margin: 18px 0; }
.banner { margin-bottom: 14px; }
.check { gap: 12px; }
.tbl th, .tbl td { padding: 12px 14px; }
.btn .ic.g { margin-right: 0; }
@media (max-width: 480px) { .card { padding: 16px; } .card + .card { margin-top: 14px; } }
/* urutkan dengan seret */
.drag-h { appearance: none; border: 0; background: transparent; color: var(--muted); width: 32px; min-height: 40px; display: grid; place-items: center; cursor: grab; touch-action: none; border-radius: 6px; flex: none; padding: 0; }
.drag-h:hover { color: var(--ink); background: var(--line-2); }
.drag-h:active { cursor: grabbing; }
.drag-h .ic { width: 18px; height: 18px; }
.sort-drag { position: fixed; z-index: 1000; pointer-events: none; box-shadow: 0 12px 28px -8px rgba(16, 32, 64, .35); background: var(--card); border-radius: var(--radius-sm); opacity: .97; }
.sort-ph { border: 2px dashed var(--line); border-radius: var(--radius-sm); background: var(--line-2); list-style: none; }
/* potong foto persegi */
.crop-frame { position: relative; width: min(320px, 100%); aspect-ratio: 1 / 1; margin: 0 auto; overflow: hidden; border-radius: 12px; background: var(--line-2); touch-action: none; cursor: grab; }
.crop-frame:active { cursor: grabbing; }
.crop-img { position: absolute; left: 0; top: 0; max-width: none; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.crop-wrap input[type=range] { flex: 1; }
