/* ============ Nailnate Back Office ============ */
:root {
  /* Brand nailnatté (Color Story) */
  --maroon: #490101;
  --terra: #a0544b;
  --pink: #ff8bb5;
  --primary: #490101;
  --primary-600: #2f0000;
  --primary-50: #FFEEF4;
  --primary-100: #FFD3E3;
  --bg: #F8F0EB;
  --surface: #FFFFFF;
  --text: #2E1515;
  --muted: #7D6461;
  --border: #EFE1DA;
  --ok: #1F7A50;   --ok-bg: #E4F3EA;
  --warn: #A35A00; --warn-bg: #FDF0DC;
  --bad: #B3261E;  --bad-bg: #FBE6E3;
  --info: #7A3F38; --info-bg: #F6E9E5;
  --c-bahan: #a0544b;
  --c-perusahaan: #490101;
  --c-jasa: #ff8bb5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(73,1,1,.05), 0 6px 18px rgba(73,1,1,.05);
  --font: "Jua", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-brand: "Jua", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: var(--terra); text-decoration: none; }
a:hover { color: var(--maroon); }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-family: var(--font-brand); font-weight: 400; color: var(--maroon); letter-spacing: .2px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Buttons ---------- */
.btn { font-family: var(--font-brand) !important; font-weight: 400 !important; letter-spacing: .2px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 9px 14px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #d9c3ba; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.danger { color: var(--bad); border-color: #efc8c2; }
.btn.ok { color: var(--ok); border-color: #bfe3cf; }
.btn:not(.primary):not(.danger):not(.ok) { color: var(--maroon); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 11px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border: 0; background: transparent; border-radius: 10px; cursor: pointer; color: var(--text); }
.icon-btn:hover { background: var(--primary-50); color: var(--maroon); }

/* ---------- Login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 20% 10%, #FFE1EC 0, transparent 45%), radial-gradient(circle at 85% 90%, #F3DDD5 0, transparent 40%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 22px; padding: 24px 24px 28px; border: 1px solid var(--border); box-shadow: var(--shadow); display: grid; gap: 12px; text-align: center; }
.login-card label { text-align: left; }
.login-logo { width: 230px; max-width: 80%; height: auto; margin: 0 auto; display: block; }
.login-sub { margin: -2px 0 6px; color: var(--muted); font-family: var(--font-brand); font-size: 15px; }
.brand-mark { width: 56px; height: 56px; margin: 0 auto 4px; border-radius: 16px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 22px; letter-spacing: .5px; }
.brand-mark.sm { width: 34px; height: 34px; font-size: 14px; border-radius: 10px; margin: 0; }

/* ---------- Layout ---------- */
.sidebar { position: fixed; inset: 0 auto 0 0; width: 236px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 14px 10px; z-index: 30; transition: transform .2s; }
.sidebar-brand { padding: 2px 6px 14px; border-bottom: 1px dashed var(--border); margin-bottom: 10px; }
.sidebar-brand img.sidebar-logo { width: 100%; max-width: 200px; height: auto; display: block; }
.sidebar-icon { display: none; }
#nav { display: grid; gap: 2px; flex: 1; align-content: start; overflow-y: auto; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; color: var(--text); border: 0; background: none; font: inherit; font-family: var(--font-brand); font-size: 15.5px; letter-spacing: .2px; cursor: pointer; text-align: left; width: 100%; }
.nav-link:hover { background: var(--bg); }
.nav-link svg { color: var(--terra); }
.nav-link.active { background: var(--primary-50); color: var(--maroon); box-shadow: inset 3px 0 0 var(--pink); }
.nav-link.active svg { color: var(--maroon); }
.nav-link.logout { color: var(--muted); margin-top: 8px; }
.main { margin-left: 236px; min-height: 100vh; min-height: 100dvh; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 12px 24px; background: rgba(248,240,235,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topbar h2 { font-size: 21px; flex: 1; }
.menu-btn { display: none; }
.view { padding: 20px 24px 80px; max-width: 1180px; }
.scrim { display: none; }

@media (max-width: 767px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 25; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .view { padding: 16px 16px 80px; }
}

/* ---------- Cards / grids ---------- */
.grid { display: grid; gap: 12px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 720px) { .grid.c3, .grid.c4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 600px) { .grid.c2.stack, .grid.c3.stack { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card.tight { padding: 0; overflow: hidden; }
.card h3 { font-size: 15px; margin-bottom: 10px; }
.section { margin-top: 22px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.section-head h3 { font-size: 16px; }
.stat { display: grid; gap: 4px; position: relative; }
.stat .label { font-size: 13px; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.stat .value { font-family: var(--font-brand); color: var(--maroon); font-size: 24px; font-weight: 400; font-variant-numeric: tabular-nums; letter-spacing: -.2px; overflow-wrap: anywhere; }
.stat .sub { font-size: 12.5px; color: var(--muted); }
.stat.neg .value { color: var(--bad); }
.section-head h3, .card h3 { color: var(--maroon); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.bahan { background: var(--c-bahan); } .dot.perusahaan { background: var(--c-perusahaan); } .dot.jasa { background: var(--c-jasa); }
.pos-bar { height: 4px; position: absolute; top: 0; left: 0; right: 0; border-radius: var(--radius) var(--radius) 0 0; }
.pos-bar.bahan { background: var(--c-bahan); } .pos-bar.perusahaan { background: var(--c-perusahaan); } .pos-bar.jasa { background: var(--c-jasa); }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; min-width: 0; }
.toolbar .grow { flex: 1; min-width: 160px; }

/* ---------- Lists ---------- */
.list { display: grid; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); color: inherit; }
.row:last-child { border-bottom: 0; }
a.row:hover, .row.click:hover { background: #FFF7FA; cursor: pointer; }
.row .main-col { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .end { text-align: right; flex: none; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12.5px; color: var(--muted); font-weight: 600; background: #FCF6F3; white-space: nowrap; }
td.num, th.num { text-align: right; }
tfoot td { font-weight: 700; background: #FCF6F3; color: var(--maroon); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.badge.lunas { background: var(--ok-bg); color: var(--ok); }
.badge.belum_lunas { background: var(--warn-bg); color: var(--warn); }
.badge.batal { background: #EFE7E4; color: var(--muted); }
.badge.cash { background: var(--ok-bg); color: var(--ok); }
.badge.rekening, .badge.transfer, .badge.qris { background: var(--info-bg); color: var(--info); }
.badge.bahan { background: #F6E6E2; color: #8A4239; }
.badge.perusahaan { background: #F1E1E1; color: var(--maroon); }
.badge.jasa { background: #FFE6F0; color: #B23A6B; }
.badge.soft { background: var(--bg); color: var(--muted); }

/* ---------- Forms ---------- */
label { display: grid; gap: 5px; font-size: 13.5px; font-weight: 600; color: var(--text); }
label .hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
input, select, textarea { width: 100%; font: inherit; font-size: 16px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--primary-100); border-color: var(--pink); }
textarea { min-height: 70px; resize: vertical; }
input.money { font-variant-numeric: tabular-nums; font-weight: 600; }
.form-grid { display: grid; gap: 12px; }
.form-grid.c2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 480px) { .form-grid.c2 { grid-template-columns: 1fr; } }
.fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: grid; gap: 12px; background: #FFF9F7; }
.fieldset-title { font-family: var(--font-brand); font-size: 14px; color: var(--terra); letter-spacing: .3px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; font-weight: 500; }
.chip input { position: absolute; opacity: 0; pointer-events: none; width: 1px; }
.chip span { padding: 8px 13px; border: 1px solid var(--border); border-radius: 999px; background: #fff; cursor: pointer; font-size: 14px; }
.chip input:checked + span { background: var(--primary-50); border-color: var(--pink); color: var(--maroon); font-weight: 600; box-shadow: 0 0 0 1px var(--pink) inset; }
.chip input:focus-visible + span { outline: 2px solid var(--primary-100); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; }
.summary-line { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; font-size: 14px; }
.summary-line.total { font-family: var(--font-brand); font-weight: 400; color: var(--maroon); font-size: 17px; border-top: 1px dashed var(--border); padding-top: 8px; margin-top: 4px; }
.alert { padding: 10px 12px; border-radius: 10px; font-size: 13.5px; }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.info { background: var(--primary-50); color: var(--maroon); }
.combo { position: relative; }
.combo-list { position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); max-height: 240px; overflow-y: auto; }
.combo-item { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.combo-item:last-child { border-bottom: 0; }
.combo-item:hover, .combo-item.hl { background: var(--primary-50); }
.combo-item small { color: var(--muted); display: block; }

/* ---------- Modal ---------- */
dialog.modal { border: 0; padding: 0; background: transparent; max-width: 520px; width: calc(100% - 24px); max-height: calc(100vh - 24px); }
dialog.modal.wide { max-width: 680px; }
dialog.modal::backdrop { background: rgba(73,1,1,.35); }
.modal-card { background: var(--surface); border-radius: 16px; display: flex; flex-direction: column; max-height: calc(100vh - 24px); }
.modal-card header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; border-bottom: 1px solid var(--border); }
.modal-card header h3 { font-size: 19px; }
.modal-body { padding: 16px; overflow-y: auto; display: grid; gap: 12px; }
.modal-card footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }

/* ---------- Detail ---------- */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.detail-head h3 { font-size: 22px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 14.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) { .kv { grid-template-columns: 110px 1fr; } }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 500; margin-bottom: 12px; }

/* ---------- Toast ---------- */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; width: min(92vw, 420px); }
.toast { background: var(--maroon); color: #fff; padding: 11px 14px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); animation: tin .18s ease-out; }
.toast.error { background: var(--bad); }
.toast.ok { background: var(--ok); }
@keyframes tin { from { opacity: 0; transform: translateY(6px); } }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Print ---------- */
@media print {
  .sidebar, .topbar, .no-print, .toasts { display: none !important; }
  .main { margin: 0; }
  .view { padding: 0; max-width: none; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* ============ iPad / tablet ============ */
/* Portrait iPad (768–1099px): sidebar ramping berisi ikon + label kecil */
@media (min-width: 768px) and (max-width: 1099px) {
  .sidebar { width: 92px; padding: 12px 8px; }
  .sidebar-brand { padding: 0 0 10px; display: flex; justify-content: center; }
  .sidebar-brand img.sidebar-logo { display: none; }
  .sidebar-icon { display: block; width: 52px; height: 52px; border-radius: 16px; border: 2px solid var(--primary-100); }
  #nav { gap: 4px; }
  .nav-link { flex-direction: column; justify-content: center; gap: 5px; padding: 10px 4px; font-size: 12px; line-height: 1.15; text-align: center; }
  .nav-link svg { width: 22px; height: 22px; }
  .nav-link.active { box-shadow: inset 0 0 0 2px var(--pink); }
  .nav-link.logout { justify-content: center; }
  .main { margin-left: 92px; }
  .topbar { padding: 12px 20px; }
  .view { padding: 18px 20px 80px; }
  .grid.c4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
/* Layar sentuh: tombol & area klik lebih besar */
@media (pointer: coarse) {
  .btn { min-height: 44px; padding: 10px 16px; }
  .btn.sm { min-height: 38px; padding: 7px 12px; }
  .icon-btn { width: 44px; height: 44px; }
  .nav-link { min-height: 46px; }
  .chip span { padding: 10px 15px; font-size: 15px; }
  .row { padding: 14px 16px; }
  .check input { width: 20px; height: 20px; }
  .combo-item { padding: 12px 14px; }
}
dialog.modal, .modal-card { max-height: calc(100dvh - 24px); }
td:first-child { white-space: nowrap; }
.form-grid.c2 > label { align-content: end; }

/* ============ iPhone / HP ============ */
@media (max-width: 767px) {
  /* area aman: notch / Dynamic Island / home indicator */
  .topbar { padding-top: max(10px, env(safe-area-inset-top)); padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .view { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  .sidebar { padding-top: max(14px, env(safe-area-inset-top)); padding-bottom: max(14px, env(safe-area-inset-bottom)); width: min(280px, 82vw); }
  .toasts { bottom: calc(16px + env(safe-area-inset-bottom)); }
  .topbar h2 { font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* tabel: geser ke samping, teks tidak patah-patah */
  th, td { white-space: nowrap; padding: 10px 10px; }
  /* kartu saldo pos lebih ringkas */
  .stat .value { font-size: 23px; }
  /* modal jadi lembar dari bawah */
  dialog.modal, dialog.modal.wide { width: 100%; max-width: 100%; margin: auto 0 0; max-height: calc(100dvh - max(12px, env(safe-area-inset-top))); }
  .modal-card { border-radius: 20px 20px 0 0; max-height: calc(100dvh - max(12px, env(safe-area-inset-top))); }
  .modal-card footer { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .modal-card footer .btn { flex: 1; }
  .detail-head .actions .btn { flex: 1 1 auto; }
  .toolbar input[type=month], .toolbar select { flex: 1 1 140px; }
}
.login { padding-top: max(16px, env(safe-area-inset-top)); padding-bottom: max(16px, env(safe-area-inset-bottom)); }

/* Semua teks pakai Jua (font hanya 1 ketebalan → jangan dipaksa tebal) */
body, input, select, textarea, button, table { font-family: var(--font); font-synthesis: none; }
strong, b, th, .row .title, label { font-weight: 400; }
strong, b { color: var(--maroon); }

/* Nota */
.nota-preview { background: var(--bg); border-radius: 14px; padding: 10px; max-height: 58vh; overflow-y: auto; }
.nota-preview img { width: 100%; height: auto; display: block; border-radius: 10px; }
.nota-actions .btn { flex: 1 1 auto; }
