:root {
  --brand: #4f7cff;
  --brand-2: #7b3fe4;
  --brand-soft: #eaefff;
  --sidebar-bg: #121829;
  --sidebar-bg-2: #0d1220;
  --sidebar-text: #aab4cc;
  --sidebar-active: #1d2742;
  --bg: #f3f5fb;
  --card: #ffffff;
  --border: #e4e9f2;
  --border-strong: #d3dae8;
  --text: #1d2740;
  --muted: #78839b;
  --green: #16a34a;
  --green-soft: #e7f7ed;
  --amber: #d97706;
  --amber-soft: #fdf3e3;
  --red: #dc2626;
  --red-soft: #fdeaea;
  --blue-soft: #e8f0ff;
  --shadow-sm: 0 1px 2px rgba(19, 30, 60, .06), 0 1px 3px rgba(19, 30, 60, .04);
  --shadow-md: 0 8px 24px rgba(19, 30, 60, .10);
  --shadow-lg: 0 18px 48px rgba(19, 30, 60, .18);
  --radius: 12px;
  --radius-sm: 8px;
  --header-h: 62px;
  --sidebar-w: 250px;
  --sidebar-w-collapsed: 70px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;

  /* Permukaan & teks tambahan — nilainya ditimpa oleh tema gelap di bawah. */
  --brand-hover: #3f6cf0;
  --surface: #ffffff;
  --surface-2: #f7f9fd;
  --surface-3: #f8fafd;
  --surface-4: #f4f7ff;
  --ink-2: #46536e;
  --ink-3: #66708a;
  --ink-soft: #8a94a8;
  --accent-ink: #2f56c9;
  --border-soft: #dde6fb;
  --row-hover: #f7f9ff;
  --red-hover: #c81e1e;
  --red-border: #f6c9c9;
  --glow-1: #e9efff;
  --glow-2: #f0e9ff;

  /* Skala permukaan: garis pemisah, garis atas tabel, ring fokus */
  --hairline: #eef1f7;
  --head-line: #cfd8ea;
  --ring: rgba(79, 124, 255, .45);
  --ring-soft: rgba(79, 124, 255, .16);
  --radius-lg: 16px;
  /* Bayangan: kartu diam rendah, kartu terangkat sedikit naik saat disentuh */
  --shadow-card: 0 1px 2px rgba(19, 30, 60, .04), 0 1px 3px rgba(19, 30, 60, .03);
  --shadow-lift: 0 6px 18px rgba(19, 30, 60, .10), 0 2px 6px rgba(19, 30, 60, .06);
  color-scheme: light;
}

/* =====================================================================
   TEMA GELAP  (diaktifkan lewat atribut data-theme pada <html>)
   Hanya variabel di bawah yang berubah — seluruh halaman ikut otomatis.
   ===================================================================== */
:root[data-theme="dark"] {
  color-scheme: dark;

  --brand: #5b86ff;
  --brand-2: #9a6bff;
  --brand-soft: #1e2a4d;
  --brand-hover: #7098ff;

  --bg: #0e1424;
  --card: #161e33;
  --surface: #161e33;
  --surface-2: #1b2338;
  --surface-3: #1a2338;
  --surface-4: #1b2745;

  --border: #26314c;
  --border-strong: #36435f;
  --border-soft: #2b3550;

  --text: #e6ebf7;
  --muted: #949eb8;
  --ink-2: #bcc6dd;
  --ink-3: #9aa4bd;
  --ink-soft: #7f8aa5;
  --accent-ink: #9db9ff;

  --green: #4ade80;
  --green-soft: #14281f;
  --amber: #fbbf24;
  --amber-soft: #2a2115;
  --red: #f87171;
  --red-soft: #2c1a1c;
  --blue-soft: #1b2745;

  /* hover baris tabel: harus lebih terang dari latar, tapi teksnya tetap terbaca */
  --row-hover: #1e2942;

  /* Tema gelap butuh nilai garis & ring sendiri, bukan hasil membalik tema terang */
  --hairline: #202a41;
  --head-line: #33405e;
  --ring: rgba(120, 160, 255, .55);
  --ring-soft: rgba(120, 160, 255, .18);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lift: 0 8px 22px rgba(0, 0, 0, .45);
  --red-hover: #ef4444;
  --red-border: #5a2a2a;
  --glow-1: rgba(91, 134, 255, .10);
  --glow-2: rgba(154, 107, 255, .10);

  --sidebar-bg: #0b1020;
  --sidebar-bg-2: #070c17;
  --sidebar-active: #1e2a4d;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .45);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, .5);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, .6);
}

/* Area dokumen (kop surat & pratinjau) selalu putih seperti hasil cetak,
   supaya tampilan di layar tetap sama dengan PDF/print meski tema gelap. */
.kop-preview, .doc {
  color-scheme: light;
  --surface: #ffffff;
  --surface-2: #f7f9fd;
  --surface-3: #f8fafd;
  --surface-4: #f2f6ff;
  --text: #1d2740;
  --muted: #78839b;
  --ink-2: #46536e;
  --ink-3: #66708a;
  --ink-soft: #8a94a8;
  --accent-ink: #2f56c9;
  --border: #e4e9f2;
  --border-strong: #d3dae8;
  --border-soft: #dde6fb;
  --brand-soft: #eaefff;
  --blue-soft: #e8f0ff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
.is-hidden { display: none !important; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- Login ---------- */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 15% 10%, var(--glow-1) 0%, transparent 60%),
    radial-gradient(900px 600px at 90% 90%, var(--glow-2) 0%, transparent 55%),
    var(--bg);
}
.login-card {
  width: 380px;
  max-width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 30px;
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.login-logo { width: 46px; height: 46px; }
.login-title { font-size: 20px; font-weight: 700; }
.login-sub { font-size: 12.5px; color: var(--muted); }
.login-error {
  background: var(--red-soft);
  color: var(--red);
  border: 1px solid var(--red-border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}
.login-hint { margin-top: 16px; text-align: center; font-size: 12.5px; color: var(--muted); }

/* ---------- App shell ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }

.app-header {
  height: var(--header-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 40;
}
.header-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.header-right { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

.brand { display: flex; align-items: center; gap: 9px; padding: 4px 6px; border-radius: 10px; }
.brand:hover { background: var(--bg); }
.brand-logo { width: 90px; height: 30px; }
.brand-mark { display: none; }

/* Logo header mengikuti tema: versi teks gelap (terang) atau teks putih (gelap).
   Keduanya tetap ikut aturan .brand-wide, jadi di layar kecil tetap pakai .brand-mark. */
.brand-wide.brand-on-dark { display: none; }
@media (min-width: 821px) {
  :root[data-theme="dark"] .brand-wide.brand-on-light { display: none; }
  :root[data-theme="dark"] .brand-wide.brand-on-dark { display: block; mix-blend-mode: screen; }
}
.brand-name { font-weight: 750; font-size: 17px; letter-spacing: -.3px;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  -webkit-background-clip: text; background-clip: text; color: transparent; }

.search-wrap { position: relative; flex: 1; max-width: 460px; margin-left: 8px; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-input {
  width: 100%;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 0 14px 0 38px;
  font-size: 13.5px;
  color: var(--text);
  outline: none;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.search-input:focus { border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 3px var(--brand-soft); }
.search-input.has-clear { padding-right: 36px; }
.search-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 26px; height: 26px; padding: 0; border: 0; border-radius: 50%;
  background: var(--surface-3); color: var(--ink-3); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.search-clear:hover { background: var(--border-strong); color: var(--text); }
.search-clear:active { transform: translateY(-50%) scale(.94); }

/* Profile */
.profile { position: relative; }
.profile-btn {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: 1px solid transparent;
  padding: 4px 8px 4px 4px; border-radius: 999px; cursor: pointer;
}
.profile-btn:hover { background: var(--bg); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  overflow: hidden; flex: 0 0 auto; letter-spacing: .5px;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 44px; height: 44px; font-size: 15px; }
.profile-meta { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.profile-name { font-weight: 600; font-size: 13px; }
.profile-role { font-size: 11.5px; color: var(--muted); }

.dropdown {
  position: absolute; right: 0; top: calc(100% + 8px);
  width: 250px; background: var(--card);
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-md); padding: 6px;
  display: none; z-index: 60;
}
.dropdown.open { display: block; animation: pop .14s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.dropdown-head { display: flex; gap: 12px; align-items: center; padding: 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.dropdown-name { font-weight: 650; font-size: 13.5px; }
.dropdown-email { font-size: 12px; color: var(--muted); }
.dropdown-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; border: 0; background: transparent;
  border-radius: 8px; cursor: pointer; font-size: 13.5px; color: var(--text);
  text-align: left;
}
.dropdown-item:hover { background: var(--bg); }
.dropdown-item.danger { color: var(--red); }
.dropdown-item.danger:hover { background: var(--red-soft); }

/* Body + sidebar */
.app-body { flex: 1; display: flex; min-height: 0; }
.app-sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--sidebar-bg), var(--sidebar-bg-2));
  display: flex; flex-direction: column;
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  transition: width .18s ease;
  overflow: hidden;
}
.app-sidebar.collapsed { width: var(--sidebar-w-collapsed); }

.side-nav { padding: 14px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.side-group-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em;
  color: #5b6787; padding: 12px 12px 6px; font-weight: 700;
}
.side-link {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 10px;
  color: var(--sidebar-text); cursor: pointer; font-size: 13.5px; font-weight: 550;
  border: 0; background: transparent; width: 100%; text-align: left;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.side-link:hover { background: rgba(255,255,255,.05); color: #fff; }
.side-link.active { background: var(--sidebar-active); color: #fff; }
.side-link.active .side-ico { color: var(--brand); }
.side-ico { width: 20px; height: 20px; flex: 0 0 auto; color: #6b7699; }
.side-link .badge-count {
  margin-left: auto; background: rgba(255,255,255,.08); color: #c7d0e6;
  font-size: 11px; padding: 1px 8px; border-radius: 999px; font-weight: 600;
}
.app-sidebar.collapsed .side-link { justify-content: center; padding: 11px; }
.app-sidebar.collapsed .side-label,
.app-sidebar.collapsed .side-group-label,
.app-sidebar.collapsed .side-link .badge-count,
.app-sidebar.collapsed .side-foot-text { display: none; }

.side-foot { padding: 14px 12px; border-top: 1px solid rgba(255,255,255,.06); }
.side-foot-text { color: #5b6787; font-size: 11px; }

.app-content { flex: 1; min-width: 0; padding: 22px 24px 48px; }

/* ---------- Page bits ---------- */
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.page-title { font-size: 22px; font-weight: 750; letter-spacing: -.45px; margin: 0; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.page-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-card);
}
.card-pad { padding: 18px; }
.section-title { font-size: 14px; font-weight: 700; margin: 0 0 14px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  height: 40px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 4px 12px rgba(79,124,255,.25); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); box-shadow: 0 6px 16px rgba(79,124,255,.3); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: var(--red-hover); }
.btn-sm { height: 33px; padding: 0 11px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-icon { padding: 0; width: 36px; }

/* Tombol garis dengan aksen: dipakai untuk aksi per baris (mis. Download PDF) */
.btn-line {
  background: var(--surface); border-color: var(--border-strong); color: var(--accent-ink);
}
.btn-line:hover { background: var(--brand-soft); border-color: var(--brand); color: var(--accent-ink); }

/* Ring fokus keyboard — wajib terlihat, tidak dipakai saat klik mouse */
.btn:focus-visible, .btn-sm:focus-visible, .icon-btn:focus-visible,
.mcard-go:focus-visible, .mcard:focus-visible, .tab:focus-visible,
.side-link:focus-visible, .theme-opt:focus-visible, .btn-ghost:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
.select:focus-visible, .input:focus-visible, .textarea:focus-visible {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring-soft);
}

.dropdown-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 190px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-md); padding: 6px; display: none; z-index: 30;
}
.menu.open { display: block; animation: pop .12s ease; }
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 11px; border: 0; background: transparent; border-radius: 7px;
  cursor: pointer; font-size: 13px; color: var(--text); text-align: left;
}
.menu button:hover { background: var(--bg); }

/* Filters — toolbar ringkas: satu permukaan, kontrol sejajar */
.filters {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
  padding: 14px 16px 16px; margin-bottom: 16px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter { display: flex; flex-direction: column; gap: 5px; min-width: 150px; }
.filter > span {
  font-size: 10.5px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted);
}
.filter .select, .filter .input { height: 38px; background: var(--surface); }
.filters .btn { height: 38px; }
/* Pemisah sebelum tombol Reset supaya aksi tidak menyatu dengan filter */
.filters .filter-divider {
  width: 1px; align-self: stretch; margin: 0 4px;
  background: var(--border); min-height: 38px;
}
.select, .input, .textarea {
  height: 40px; border: 1px solid var(--border-strong); border-radius: 10px;
  padding: 0 12px; font-size: 13.5px; color: var(--text); background: var(--surface);
  outline: none; width: 100%; transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
.textarea { height: auto; min-height: 76px; padding: 10px 12px; resize: vertical; }
.select:focus, .input:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.input[readonly] { background: var(--surface-2); color: var(--muted); }
.input[data-loading] { background: var(--brand-soft); color: var(--ink-soft); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field-hint { font-size: 11.5px; color: var(--muted); }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* Table — pola "Compare": kolom tetap, baris mudah dipindai */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.data {
  width: 100%; border-collapse: collapse; font-size: 13.2px; background: var(--surface);
}
table.data thead th {
  text-align: left; font-weight: 700; font-size: 11px; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted);
  background: var(--surface-3); border-bottom: 1.5px solid var(--head-line);
  padding: 11px 14px; white-space: nowrap;
}
table.data tbody td { padding: 14px; border-bottom: 1px solid var(--hairline); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr.clickable { cursor: pointer; transition: background .12s; }
table.data tbody tr.clickable:hover { background: var(--row-hover); }
table.data tbody tr.clickable:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
table.data tbody tr.expanded { background: var(--brand-soft); }
table.data tbody tr.detail-row > td { background: var(--surface-2); padding: 0; }
.table-empty { padding: 52px 16px; text-align: center; color: var(--muted); }
.table-empty svg { opacity: .45; margin-bottom: 12px; }
.table-empty b { display: block; color: var(--text); font-size: 14px; margin-bottom: 3px; }

/* Objek utama tiap baris: nomor dokumen tebal + angka rata (tabular) */
.doc-no { font-size: 13.5px; font-weight: 750; letter-spacing: .01em; font-variant-numeric: tabular-nums; }
.cell-main { font-weight: 650; color: var(--text); }
.cell-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.num { font-variant-numeric: tabular-nums; }

/* Pil status: teks + bentuk, jadi tidak bergantung warna saja */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; white-space: nowrap;
  background: var(--surface-3); color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.pill svg { width: 13px; height: 13px; }
.pill.blue { background: var(--blue-soft); color: var(--accent-ink); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.muted { background: transparent; color: var(--ink-soft); font-weight: 600; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
table.data thead th.sortable:hover { background: var(--brand-soft); }
th.sortable.sorted { color: var(--brand); }
.sort-arrow { display: inline-block; margin-left: 5px; font-size: 9px; opacity: .45; }
th.sortable:hover .sort-arrow { opacity: .8; }
th.sortable.sorted .sort-arrow { opacity: 1; }

.caret { display: inline-flex; transition: transform .15s; color: var(--muted); }
tr.expanded .caret { transform: rotate(90deg); color: var(--brand); }

.sub-table { width: 100%; border-collapse: collapse; font-size: 12.8px; }
.sub-table th { text-align: left; padding: 10px 14px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-3); border-bottom: 1px solid var(--border); }
.sub-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.sub-table tr:last-child td { border-bottom: 0; }
.sub-table tr.child-link { cursor: pointer; }
.sub-table tr.child-link:hover td { background: var(--surface-3); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 650;
  background: var(--blue-soft); color: var(--accent-ink);
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.gray { background: var(--surface-3); color: var(--ink-3); }
.badge.red { background: var(--red-soft); color: var(--red); }

.row-actions { display: flex; gap: 4px; justify-content: flex-end; }

/* Items editor */
.items-editor { border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
.items-editor table { width: 100%; border-collapse: collapse; font-size: 13px; }
.items-editor thead th {
  background: var(--surface-3); font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border);
  font-weight: 650; white-space: nowrap;
}
.items-editor tbody td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.items-editor tbody tr:last-child td { border-bottom: 0; }
.items-editor .input, .items-editor .select { height: 36px; border-radius: 8px; font-size: 13px; }

/* Link gambar item + pratinjaunya (di bawah kolom Keterangan) */
.img-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.img-row .img-url { flex: 1 1 auto; min-width: 0; height: 30px; font-size: 12px; }
.img-prev {
  flex: 0 0 auto; width: 30px; height: 30px; object-fit: contain;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); padding: 2px;
}
.items-editor .cell-num { width: 108px; }
.items-editor .cell-qty { width: 86px; }
.items-editor .cell-sm { width: 92px; }
.items-editor .row-total { font-weight: 650; white-space: nowrap; padding-top: 16px; }

.totals { margin-left: auto; width: 340px; max-width: 100%; }
.totals .trow { display: flex; justify-content: space-between; padding: 8px 0; font-size: 13.5px; }
.totals .trow.sep { border-top: 1px dashed var(--border-strong); }
.totals .trow.grand { font-size: 17px; font-weight: 750; color: var(--brand); border-top: 2px solid var(--border); margin-top: 4px; padding-top: 12px; }
.totals .trow input { text-align: right; width: 130px; }

/* Detail / document preview */
.doc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 34px 38px; box-shadow: var(--shadow-sm); }
.doc-head { display: flex; justify-content: space-between; gap: 24px; border-bottom: 2px solid var(--text); padding-bottom: 18px; }
.doc-co { display: flex; gap: 14px; align-items: flex-start; }
.doc-co img { width: 54px; height: 54px; }
.doc-co-name { font-size: 19px; font-weight: 750; }
.doc-co-line { font-size: 12.5px; color: var(--ink-2); }
.doc-title { text-align: right; }
.doc-title h2 { margin: 0; font-size: 26px; letter-spacing: 2px; color: var(--text); }
.doc-title .doc-no { font-size: 13px; color: var(--muted); margin-top: 4px; }
.doc-meta { display: flex; justify-content: space-between; gap: 24px; margin: 22px 0; }
.doc-meta .box h4 { margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.doc-meta .box div { font-size: 13px; }
.doc-meta .box .strong { font-weight: 700; font-size: 14px; }
table.doc-items { width: 100%; border-collapse: collapse; font-size: 13px; }
table.doc-items th { background: var(--surface-3); border: 1px solid var(--border-strong); padding: 9px 10px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-2); }
table.doc-items td { border: 1px solid var(--border-strong); padding: 9px 10px; }
.doc-note { margin-top: 18px; font-size: 12.5px; color: var(--ink-2); }
.doc-sign { display: flex; justify-content: space-between; margin-top: 46px; gap: 24px; }
.doc-sign .sig { text-align: center; width: 220px; font-size: 13px; }
.doc-sign .sig .line { border-top: 1px solid var(--text); margin-top: 62px; padding-top: 6px; }

/* Settings / misc */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab { padding: 10px 14px; border: 0; background: transparent; cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

.theme-picker { display: flex; gap: 10px; flex-wrap: wrap; }
.theme-opt {
  flex: 1 1 130px; min-width: 110px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 14px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  font-size: 12.5px; font-weight: 600; transition: border-color .15s, background .15s, color .15s;
}
.theme-opt:hover { border-color: var(--border-strong); color: var(--text); }
.theme-opt.active {
  border-color: var(--brand); background: var(--brand-soft); color: var(--accent-ink);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.div-scope {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface-4); border: 1px solid var(--border-soft); border-radius: 10px;
  padding: 10px 14px; margin-bottom: 14px; font-size: 13px;
}
.div-scope-label { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.div-scope .select { height: 34px; min-width: 190px; max-width: 280px; background: var(--surface); }
@media (max-width: 620px) {
  .div-scope { align-items: stretch; }
  .div-scope .select { max-width: none; width: 100%; }
}

.toast-root { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  min-width: 250px; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--brand); border-radius: 10px; box-shadow: var(--shadow-md);
  padding: 12px 14px; font-size: 13.5px; animation: slideIn .18s ease;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

.modal-root { position: fixed; inset: 0; z-index: 300; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(16,24,44,.45); }
.modal {
  background: var(--surface); border-radius: 16px; width: 460px; max-width: 100%;
  max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); overflow: hidden; animation: pop .16s ease;
}
.modal-body { overflow-y: auto; }
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 15.5px; }
.modal-body { padding: 20px; font-size: 13.5px; color: var(--ink-2); }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; background: var(--surface-2); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state h3 { color: var(--text); margin: 14px 0 6px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 900px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.stat .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 22px; font-weight: 750; margin-top: 6px; letter-spacing: -.5px; }
.stat .value.sm { font-size: 17px; }
.stat .ico { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; background: var(--brand-soft); color: var(--brand); float: right; }

.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px;
  border-radius: 999px; background: var(--brand-soft); color: var(--accent-ink); font-size: 12.5px; font-weight: 600;
}
.chip button { border: 0; background: transparent; cursor: pointer; color: inherit; font-size: 15px; line-height: 1; padding: 0; }

.text-danger { color: var(--red); }
.text-success { color: var(--green); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mb-14 { margin-bottom: 14px; }
.mt-14 { margin-top: 14px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-10 { gap: 10px; }
.grow { flex: 1; }

.intro-text { white-space: pre-line; font-size: 13.5px; line-height: 1.7; color: var(--ink-2); }

.ac-menu {
  position: fixed; z-index: 400; display: none;
  max-height: 288px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 10px; box-shadow: var(--shadow-md); padding: 4px;
}
.ac-menu.open { display: block; }
.ac-row {
  display: flex; align-items: baseline; gap: 10px;
  padding: 7px 9px; border-radius: 7px; cursor: pointer;
}
.ac-row.active, .ac-row:hover { background: var(--brand-soft); }
.ac-name {
  flex: 0 0 auto; font-size: 12.5px; font-weight: 650;
  color: var(--text); white-space: nowrap;
}
.ac-ket {
  font-size: 12px; color: var(--muted); min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ac-price {
  margin-left: auto; flex: 0 0 auto; font-size: 11.5px;
  font-variant-numeric: tabular-nums; color: var(--ink-2);
}
.ac-empty { padding: 9px; font-size: 12.5px; color: var(--muted); }

.check-inline {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 14px; border: 1px solid var(--border-strong);
  border-radius: 10px; background: var(--surface); cursor: pointer;
  font-size: 13.5px; font-weight: 600; color: var(--text);
  user-select: none; transition: background .15s, border-color .15s, color .15s;
}
.check-inline:hover { background: var(--surface-2); }
.check-inline input { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; margin: 0; }
.check-inline:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); color: var(--accent-ink); }

.kop-preview {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 18px; background: var(--surface); overflow-x: auto;
}
.subpanel {
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); padding: 14px 14px 0;
}
.subpanel-title {
  font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); margin-bottom: 12px;
}

/* ---------- Category groups in items editor ---------- */
.items-editor .group-head > td {
  padding: 7px 12px;
  background: var(--surface-3);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.items-editor tbody.item-group + tbody.item-group .group-head > td { border-top: 0; }
.group-head-inner { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; row-gap: 6px; }
.group-caret {
  border: 0; background: transparent; cursor: pointer; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 7px; padding: 0; flex: 0 0 auto;
  transition: background .15s, color .15s, transform .15s;
}
.group-caret:hover { background: rgba(79, 124, 255, .12); color: var(--brand); }
.item-group.collapsed .group-caret { transform: rotate(-90deg); }
.item-group.collapsed .item-row { display: none; }
.group-name {
  flex: 0 1 340px; min-width: 130px; height: 32px;
  border: 1px solid transparent; background: transparent; border-radius: 8px;
  padding: 0 9px; font-family: inherit; font-size: 13.5px; font-weight: 700;
  color: var(--text); outline: none;
}
.group-name::placeholder { font-weight: 600; color: var(--muted); }
.group-name:hover { border-color: var(--border-strong); background: var(--surface); }
.group-name:focus { border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 3px var(--brand-soft); }
.group-name:disabled { opacity: 1; color: var(--text); -webkit-text-fill-color: var(--text); }
.group-subtotal { margin-left: auto; font-size: 12.5px; font-weight: 650; color: var(--accent-ink); white-space: nowrap; }
.group-actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.group-actions .btn { height: 30px; padding: 0 10px; font-size: 12px; gap: 5px; }
.group-actions .btn svg { width: 15px; height: 15px; }
.group-actions .icon-btn { width: 30px; height: 30px; }

/* ---------- Mobile card view ---------- */
.mcards { display: flex; flex-direction: column; gap: 12px; }
.mcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-card); overflow: hidden; cursor: pointer;
  transition: box-shadow .16s, border-color .16s, transform .16s;
}
.mcard:active { background: var(--surface-2); }
@media (hover: hover) {
  .mcard:hover { box-shadow: var(--shadow-lift); border-color: var(--border-strong); transform: translateY(-1px); }
}
.mcard-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 15px 15px 0; }
.mcard-head-l { min-width: 0; }
.mcard-top {
  font-size: 12.5px; font-weight: 750; color: var(--muted);
  font-variant-numeric: tabular-nums; letter-spacing: .01em;
}
.mcard-title { font-size: 15.5px; font-weight: 750; color: var(--text); line-height: 1.3; margin-top: 3px; }
.mcard-sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.mcard-head .badge { flex: 0 0 auto; margin-top: 2px; }
.mcard-fields {
  display: flex; flex-wrap: wrap; gap: 9px 16px;
  padding: 13px 15px 0;
  border-top: 1px solid var(--hairline); margin-top: 13px;
}
.mfield { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-2); min-width: 0; }
.mfield svg { color: var(--ink-soft); flex: 0 0 auto; }
.mcard-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 15px 14px;
}
.mcard-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.mcard-actions .btn {
  background: var(--surface); border-color: var(--border-strong); color: var(--accent-ink);
}
.mcard-actions .btn:hover { background: var(--brand-soft); border-color: var(--brand); }
.mcard-go {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--muted);
  width: 42px; height: 38px; border-radius: 10px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.mcard-go:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }

/* Hormati preferensi pengguna: kurangi gerakan */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  .mcard:hover { transform: none; }
}
.mcard-go svg { transition: transform .15s; }
.mcard.expanded .mcard-go svg { transform: rotate(90deg); }
.mcard-sub-list { display: flex; flex-direction: column; gap: 8px; padding: 12px 12px 0; }
.mmini {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
}
.mmini-l { min-width: 0; }
.mmini-title { font-size: 13px; font-weight: 700; color: var(--text); }
.mmini-sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.mmini-right { text-align: right; flex: 0 0 auto; }
.mmini-value { font-size: 13px; font-weight: 750; color: var(--text); }

/* ---------- Responsive ---------- */
.nav-backdrop {
  position: fixed; inset: 0; z-index: 45;
  background: rgba(16, 24, 44, .45);
  opacity: 0; visibility: hidden;
  transition: opacity .18s, visibility .18s;
}
.nav-backdrop.show { opacity: 1; visibility: visible; }
body.nav-open { overflow: hidden; }

@media (max-width: 820px) {
  .app-header { padding: 0 10px; }
  .header-left { gap: 6px; }
  .search-wrap { margin-left: 4px; }
  .search-input { height: 38px; padding: 0 12px 0 34px; font-size: 13px; }
  .brand-name { display: none; }
  .brand-wide { display: none; }
  .brand-mark { display: block; width: 38px; height: 38px; }
  .profile-btn { padding: 4px; }
  .profile-meta { display: none; }

  .app-sidebar {
    position: fixed; left: 0; top: var(--header-h); z-index: 46;
    width: var(--sidebar-w);
    height: calc(100vh - var(--header-h));
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .app-sidebar.collapsed { width: var(--sidebar-w); }
  .app-sidebar.mobile-open { transform: none; box-shadow: var(--shadow-lg); }
  .app-sidebar.mobile-open .side-label,
  .app-sidebar.mobile-open .side-group-label,
  .app-sidebar.mobile-open .side-link .badge-count,
  .app-sidebar.mobile-open .side-foot-text { display: block; }
  .app-sidebar.mobile-open .side-link { justify-content: flex-start; padding: 11px 12px; }

  .app-content { padding: 14px 14px 44px; }
  .page-title { font-size: 19px; }
  .page-head { gap: 12px; }
  .page-actions { width: 100%; gap: 8px; }
  .page-actions > .btn,
  .page-actions > .check-inline { flex: 1 1 auto; justify-content: center; }

  .items-editor table { min-width: 950px; }
  .table-wrap table.data { min-width: 760px; }
  .detail-row > td { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .sub-table { min-width: 640px; }

  .kop-preview { padding: 12px; }
  .kop-preview > div { flex-direction: column !important; align-items: flex-start !important; gap: 10px !important; }

  .toast-root { left: 12px; right: 12px; bottom: 12px; }
  .toast { min-width: 0; max-width: none; }

  .modal { width: 100%; }
  .modal-foot { flex-wrap: wrap; }
  .modal-foot .btn { flex: 1 1 auto; justify-content: center; }

  .card-pad { padding: 14px; }
}

@media (max-width: 620px) {
  .filter { flex: 1 1 100%; min-width: 0; }
  .filters > .btn { width: 100%; }
  .totals { width: 100%; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-actions .btn { padding: 0 12px; font-size: 13px; }
  .check-inline { padding: 0 12px; font-size: 13px; }
  .group-name { flex: 1 1 100%; }
  .group-subtotal { margin-left: 0; }
  .ac-menu { max-height: 220px; }
  .section-title, .page-sub { font-size: 12.5px; }
}

@media (max-width: 400px) {
  .app-content { padding: 12px 10px 40px; }
  .search-input { font-size: 12.5px; }
  .page-actions .btn span,
  .check-inline span { font-size: 12.5px; }
  .stat-grid { grid-template-columns: 1fr; }
}
