/* ============ Design tokens ============ */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --accent: #06b6d4;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --muted-light: #f1f5f9;

  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
  --radius: 14px;
  --sidebar-w: 250px;
  --select-arrow: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220;
    --surface: #131b2c;
    --surface-2: #0f1728;
    --text: #e6ebf5;
    --text-muted: #93a1b8;
    --border: #223049;
    --primary-light: #16223f;
    --success-light: #0d2818;
    --danger-light: #341316;
    --warning-light: #332409;
    --muted-light: #182338;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    --select-arrow: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2393a1b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #131b2c;
  --surface-2: #0f1728;
  --text: #e6ebf5;
  --text-muted: #93a1b8;
  --border: #223049;
  --primary-light: #16223f;
  --success-light: #0d2818;
  --danger-light: #341316;
  --warning-light: #332409;
  --muted-light: #182338;
  --select-arrow: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2393a1b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  position: relative;
}
/* Watermark logo AnterNet di belakang seluruh halaman - tipis, tidak mengganggu keterbacaan. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("../img/brand-wordmark.png");
  background-repeat: no-repeat;
  background-position: center 42%;
  background-size: min(46vw, 480px);
  opacity: .05;
  pointer-events: none;
  z-index: 0;
}
#app, #splash { position: relative; z-index: 1; }
a { color: inherit; }
button { font-family: inherit; }
img { max-width: 100%; }

/* ============ Login ============ */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  background:
    radial-gradient(circle at 15% 20%, rgba(37, 99, 235, .18), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(6, 182, 212, .18), transparent 40%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.login-logo {
  display: flex; align-items: center; gap: 10px; margin-bottom: 6px;
}
.login-logo .logo-badge {
  width: 40px; height: 40px; border-radius: 12px;
  object-fit: cover; flex-shrink: 0;
}
.login-card h1 { font-size: 1.15rem; margin: 0; }
.login-card p.sub { color: var(--text-muted); margin: 4px 0 24px; font-size: .88rem; }

/* ============ Forms ============ */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }

/* Berlaku global (bukan cuma di dalam .field) supaya kontrol form yang berdiri sendiri,
   mis. kotak pencarian & filter di toolbar, ikut konsisten & tidak tampil polos bawaan browser.
   Dikecualikan (bukan didaftar satu-satu) supaya input tanpa atribut type="..." eksplisit
   (default-nya "text") tetap ikut ter-custom, bukan cuma jenis yang disebut namanya. */
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]),
select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: .92rem; outline: none;
  font-family: inherit; transition: border-color .15s, box-shadow .15s;
}
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]):focus,
select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
/* Input file (dipakai di wizard Impor SQL) - tombol native tak bisa dibentuk ulang penuh,
   tapi disamakan warna/bingkainya lewat ::file-selector-button supaya tidak terlalu njomplang. */
input[type="file"] {
  width: 100%; padding: 8px; border-radius: 10px; border: 1px dashed var(--border);
  background: var(--surface-2); color: var(--text-muted); font-size: .85rem;
}
input[type="file"]::file-selector-button {
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: .82rem; font-weight: 600;
  margin-right: 10px; cursor: pointer;
}
select {
  appearance: none; -webkit-appearance: none;
  padding-right: 34px; cursor: pointer;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
}
select:disabled { opacity: .6; cursor: not-allowed; }
textarea { resize: vertical; min-height: 60px; }
input[type="radio"], input[type="checkbox"] { accent-color: var(--primary); }
.field .hint { font-size: .76rem; color: var(--text-muted); margin-top: 4px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .field-row { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid transparent;
  font-size: .88rem; font-weight: 600; cursor: pointer; transition: filter .15s, transform .05s;
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 10px; font-size: .78rem; }
.btn-icon { padding: 8px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .6; cursor: not-allowed; }

.spinner {
  width: 15px; height: 15px; border-radius: 50%; display: inline-block;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Indikator kecil di navbar: muncul selama halaman masih mengambil data dari server
   (termasuk saat menyegarkan data di belakang layar setelah tampilan awal dari cache). */
.topbar-loading {
  width: 16px; height: 16px; border-radius: 50%; display: inline-block; flex-shrink: 0;
  border: 2px solid var(--danger-light); border-top-color: var(--danger); animation: spin .7s linear infinite;
}
.topbar-loading[hidden] { display: none; } /* aturan class di atas sengaja "display: inline-block"
  tanpa syarat, jadi harus ditimpa lagi di sini biar atribut hidden beneran menyembunyikannya */

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

.sidebar {
  width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border);
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 40; display: flex; flex-direction: column;
  transition: transform .2s ease;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; }
.sidebar-brand .logo-badge {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0; object-fit: cover;
}
.sidebar-brand strong { font-size: .95rem; display: block; }
.sidebar-brand span { font-size: .72rem; color: var(--text-muted); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 6px 10px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--text-muted); font-size: .87rem; font-weight: 500; margin-bottom: 2px; cursor: pointer;
  text-decoration: none;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 700; }

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary-light); color: var(--primary);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; flex-shrink: 0;
}
.user-meta { flex: 1; min-width: 0; }
.user-meta strong { display: block; font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta span { font-size: .72rem; color: var(--text-muted); }

.main-col { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 62px; display: flex; align-items: center; gap: 14px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30;
}
.hamburger { display: none; background: none; border: none; color: var(--text); cursor: pointer; padding: 6px; }
.hamburger svg { width: 22px; height: 22px; }
.topbar h2 { font-size: 1.05rem; margin: 0; flex: 1; }
.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text);
}
.icon-btn svg { width: 17px; height: 17px; }

.content { padding: 22px; flex: 1; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 39; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-col { margin-left: 0; }
  .hamburger { display: flex; }
  .sidebar-backdrop.show { display: block; }
}

/* ============ Cards / grid / stats ============ */
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr);} }
@media (max-width: 620px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }
.card-header h3 { margin: 0; font-size: 1rem; }
.card-header .sub { color: var(--text-muted); font-size: .8rem; }

.stat-card { display: flex; align-items: center; gap: 14px; }
.stat-icon {
  width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; }
.stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-icon.red { background: var(--danger-light); color: var(--danger); }
.stat-icon.amber { background: var(--warning-light); color: var(--warning); }
.stat-icon.muted { background: var(--muted-light); color: var(--text-muted); }
.stat-value { font-size: 1.35rem; font-weight: 800; line-height: 1.1; }
.stat-label { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }

/* ============ Branch cards ============ */
.branch-card { cursor: pointer; transition: transform .12s, box-shadow .12s, border-color .12s; }
.branch-card:hover, .branch-card:focus-visible { transform: translateY(-2px); border-color: var(--primary); box-shadow: 0 4px 20px rgba(37, 99, 235, .12); outline: none; }
.branch-card-stats { display: flex; gap: 18px; padding: 10px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.branch-card-stats > div { flex: 1; text-align: center; }
.branch-card-stats strong { display: block; font-size: 1.05rem; font-weight: 800; }
.branch-card-stats span { font-size: .72rem; color: var(--text-muted); }
.branch-card-address { font-size: .82rem; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============ Table ============ */
.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; min-width: 640px; background: var(--surface); }
thead th {
  text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .03em;
  color: var(--text-muted); background: var(--surface-2); padding: 11px 14px; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: .87rem; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state svg { width: 40px; height: 40px; margin-bottom: 10px; opacity: .5; }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: .72rem; font-weight: 700;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-muted { background: var(--muted-light); color: var(--text-muted); }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.search-box { position: relative; flex: 1; min-width: 180px; max-width: 320px; }
.search-box svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-muted); }
.search-box input { padding-left: 34px; }
.spacer { flex: 1; }

.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; background: var(--border); border-radius: 999px; cursor: pointer; transition: .15s;
}
.switch .track::before {
  content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff;
  border-radius: 50%; transition: .15s; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.switch input:checked + .track { background: var(--success); }
.switch input:checked + .track::before { transform: translateX(18px); }
.switch input:disabled + .track { opacity: .5; cursor: not-allowed; }

/* ============ Modal ============ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 15, 30, .5); display: flex; align-items: center; justify-content: center;
  z-index: 100; opacity: 0; transition: opacity .15s; padding: 16px;
}
.modal-overlay.open { opacity: 1; }
.modal-box {
  background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 440px; max-height: 90vh;
  overflow-y: auto; box-shadow: var(--shadow); border: 1px solid var(--border);
}
.modal-wide { max-width: 640px; }
.modal-header { padding: 18px 20px 0; }
.modal-header h3 { margin: 0 0 12px; font-size: 1.02rem; }
.modal-body { padding: 4px 20px 6px; }
.modal-footer { padding: 14px 20px 20px; display: flex; justify-content: flex-end; gap: 10px; }

/* ============ Toast ============ */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 10px; font-size: .85rem;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 200; max-width: 90vw; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }

/* ============ Misc ============ */
.key-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .78rem; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
.section-title { font-size: .95rem; font-weight: 700; margin: 26px 0 12px; }
.section-title:first-child { margin-top: 0; }
.text-muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; }
.hidden { display: none !important; }
#splash { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); z-index: 999; }
