/* ===== Sistem Kas & Jimpitan RT — tema Biru Tua, tata letak melayang ===== */
:root {
  --brand: #1d4ed8;          /* blue-700 */
  --brand-dark: #1e3a8a;     /* blue-900 */
  --navy: #0f1f4d;           /* deep navy */
  --navy2: #1e40af;          /* blue-800 */
  --brand-soft: #dbeafe;     /* blue-100 */
  --ink: #0f172a;            /* slate-900 */
  --muted: #64748b;          /* slate-500 */
  --line: #e6eaf2;
  --bg1: #eef2fb;
  --bg2: #dde6f7;
  --card: #ffffff;
  --masuk: #059669;
  --keluar: #e11d48;
  --warn: #b45309;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .05);
  --shadow: 0 8px 24px rgba(15, 33, 77, .08), 0 2px 6px rgba(15, 33, 77, .06);
  --shadow-lg: 0 18px 45px rgba(15, 33, 77, .16);
  --radius: 16px;
  --radius-lg: 20px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(135deg, var(--bg1), var(--bg2)) fixed;
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.sidebar {
  width: 244px;
  position: fixed; top: 18px; left: 18px; bottom: 18px;
  background: linear-gradient(180deg, var(--navy), var(--navy2));
  color: #eef2ff;
  display: flex; flex-direction: column;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 30; overflow: hidden;
}
.sidebar .brand { padding: 20px 18px; display: flex; align-items: center; gap: 11px; border-bottom: 1px solid rgba(255,255,255,.12); }
.sidebar .brand .logo { width: 40px; height: 40px; border-radius: 12px; background: #fff; color: var(--brand-dark); display: grid; place-items: center; font-weight: 800; font-size: 17px; box-shadow: 0 3px 8px rgba(0,0,0,.2); }
.sidebar .brand b { font-size: 15px; line-height: 1.15; }
.sidebar .brand small { display: block; opacity: .75; font-weight: 400; font-size: 11px; }
.nav { padding: 12px 10px; overflow-y: auto; flex: 1; }
.nav .group { font-size: 10px; text-transform: uppercase; letter-spacing: .09em; opacity: .55; margin: 15px 12px 6px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 10px 12px; color: #c7d3f2; border-radius: 11px; font-weight: 500; margin-bottom: 3px; transition: background .15s, color .15s; }
.nav a:hover { background: rgba(255,255,255,.10); color: #fff; text-decoration: none; }
.nav a.active { background: linear-gradient(90deg, #fff, #eaf1ff); color: var(--brand-dark); font-weight: 600; box-shadow: 0 4px 12px rgba(0,0,0,.18); }
.nav a .ic { width: 18px; text-align: center; }

.main { flex: 1; min-width: 0; margin-left: 280px; padding: 18px 22px 22px; display: flex; flex-direction: column; }

.topbar {
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,.6);
  border-radius: var(--radius);
  padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 18px; z-index: 20;
  box-shadow: var(--shadow);
}
.topbar h1 { font-size: 18px; margin: 0; color: var(--brand-dark); }
.topbar .user { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.topbar .avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; box-shadow: var(--shadow-sm); }
.content { padding: 20px 2px 0; max-width: 1240px; width: 100%; min-width: 0; }

/* ---------- Cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .card-head { padding: 15px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card .card-head h2 { font-size: 15px; margin: 0; color: var(--brand-dark); }
.card .card-body { padding: 18px; }
.card + .card { margin-top: 18px; }

.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }

/* ---------- Stat tiles ---------- */
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 17px 18px; box-shadow: var(--shadow); transition: transform .15s; }
.stat:hover { transform: translateY(-2px); }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 24px; font-weight: 800; margin-top: 4px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.masuk .value { color: var(--masuk); }
.stat.keluar .value { color: var(--keluar); }
.stat.saldo { background: linear-gradient(135deg, var(--navy), var(--navy2)); color: #fff; border: none; }
.stat.saldo .label, .stat.saldo .sub { color: #c7d3f2; }
.stat.saldo .value { color: #fff; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 10px 13px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.data thead th { background: #f4f7fd; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; position: sticky; top: 0; }
table.data tbody tr:hover { background: #f7f9fe; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.center, table.data th.center { text-align: center; }
.text-masuk { color: var(--masuk); font-weight: 600; }
.text-keluar { color: var(--keluar); font-weight: 600; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.masuk { background: #d1fae5; color: #065f46; }
.badge.keluar { background: #ffe4e6; color: #9f1239; }
.badge.aktif { background: #dcfce7; color: #166534; }
.badge.nonaktif { background: #eef2f7; color: #64748b; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.info { background: var(--brand-soft); color: var(--brand-dark); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 15px; border-radius: 11px; border: 1px solid transparent; font-weight: 600; font-size: 13px; cursor: pointer; background: #fff; color: var(--ink); text-decoration: none; transition: filter .15s, transform .05s; }
.btn:hover { text-decoration: none; filter: brightness(.98); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-dark)); color: #fff; box-shadow: 0 4px 12px rgba(29,78,216,.28); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-outline { border-color: var(--line); background: #fff; color: var(--ink); }
.btn-danger { background: #ffe4e6; color: #9f1239; }
.btn-danger:hover { background: #fecdd3; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 9px; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Forms ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 11px; font-size: 14px; font-family: inherit; background: #fbfcfe; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px var(--brand-soft); }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.form-row > * { flex: 1; min-width: 140px; }
.help { font-size: 12px; color: var(--muted); }
.err { color: var(--keluar); font-size: 12px; margin-top: 4px; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-size: 13px; font-weight: 500; }
.alert.sukses { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert.gagal { background: #ffe4e6; color: #9f1239; border: 1px solid #fecdd3; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; background: rgba(255,255,255,.7); padding: 14px 16px; border-radius: var(--radius); border: 1px solid rgba(255,255,255,.6); box-shadow: var(--shadow-sm); }
.toolbar .spacer { flex: 1; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Matrix jimpitan ---------- */
.matrix { font-size: 12px; }
.matrix th, .matrix td { padding: 6px 6px; border: 1px solid var(--line); text-align: center; }
.matrix thead th { background: var(--brand-soft); color: var(--brand-dark); }
.matrix td.nama { text-align: left; white-space: nowrap; position: sticky; left: 0; background: #fff; font-weight: 600; }
.matrix input { width: 62px; padding: 4px 5px; text-align: right; font-size: 12px; border: 1px solid transparent; border-radius: 7px; background: transparent; }
.matrix input:hover { border-color: var(--line); background: #fff; }
.matrix input:focus { border-color: var(--brand); background: #fff; }
.matrix tfoot td { background: #eef3fd; font-weight: 700; color: var(--brand-dark); }
.matrix .lunas { background: #f0fdf4; }

/* ---------- Freeze panes (matriks jimpitan): header bulan + kolom Nama membeku ---------- */
.table-wrap.freeze { max-height: 72vh; overflow: auto; }
/* header bulan membeku saat scroll ke bawah */
.table-wrap.freeze table.matrix thead th { position: sticky; top: 0; z-index: 3; }
/* kolom No & Nama membeku saat scroll ke samping */
.table-wrap.freeze table.matrix th:nth-child(1),
.table-wrap.freeze table.matrix td:nth-child(1) { position: sticky; left: 0; width: 40px; background: #fff; z-index: 2; }
.table-wrap.freeze table.matrix th:nth-child(2),
.table-wrap.freeze table.matrix td.nama { position: sticky; left: 40px; background: #fff; z-index: 2; }
/* sudut kiri-atas (No & Nama pada header) di atas semuanya */
.table-wrap.freeze table.matrix thead th:nth-child(1),
.table-wrap.freeze table.matrix thead th:nth-child(2) { background: var(--brand-soft); z-index: 5; }
/* baris TOTAL membeku di bawah */
.table-wrap.freeze table.matrix tfoot td { position: sticky; bottom: 0; z-index: 3; }
.table-wrap.freeze table.matrix tfoot td:first-child { left: 0; z-index: 4; }

/* ---------- Modal ---------- */
dialog { border: none; border-radius: var(--radius-lg); padding: 0; box-shadow: var(--shadow-lg); width: min(560px, 92vw); }
dialog::backdrop { background: rgba(15,23,42,.55); backdrop-filter: blur(3px); }
dialog .card-head { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
dialog form.body { padding: 18px; }
dialog .foot { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: 5px; list-style: none; padding: 0; margin: 16px 0 0; flex-wrap: wrap; font-size: 13px; }
.pagination a, .pagination span { padding: 7px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }
.pagination .active span { background: var(--brand); color: #fff; border-color: var(--brand); }
.pagination [aria-disabled] span { opacity: .4; }

.muted { color: var(--muted); }
.mb0 { margin-bottom: 0; }
.mt0 { margin-top: 0; }
.right { text-align: right; }
.flex { display: flex; gap: 10px; align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--navy), var(--navy2)); padding: 20px; }
.login-card { background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: min(400px, 94vw); overflow: hidden; }
.login-card .head { text-align: center; padding: 30px 24px 12px; }
.login-card .head .logo { width: 58px; height: 58px; border-radius: 16px; background: linear-gradient(135deg, var(--brand), var(--brand-dark)); color: #fff; display: grid; place-items: center; font-size: 24px; font-weight: 800; margin: 0 auto 14px; box-shadow: var(--shadow); }
.login-card .head h1 { font-size: 19px; margin: 0; color: var(--brand-dark); }
.login-card .head p { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.login-card form { padding: 18px 24px 28px; }

/* ---------- Responsive ---------- */
.sidebar-backdrop { display: none; }

@media (max-width: 860px) {
  .sidebar { transform: translateX(-115%); transition: transform .2s; top: 0; left: 0; bottom: 0; border-radius: 0 var(--radius-lg) var(--radius-lg) 0; }
  .sidebar.open { transform: none; }
  .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 29; }
  .main { margin-left: 0; padding: 12px; }
  .topbar { top: 12px; padding: 10px 14px; }
  .topbar h1 { font-size: 16px; }
  .menu-toggle { display: inline-flex !important; }
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .content { padding: 16px 0 0; }
  /* Cegah zoom otomatis iOS Safari saat fokus input (butuh >=16px) */
  input[type=text], input[type=email], input[type=password],
  input[type=number], input[type=date], select, textarea { font-size: 16px; }
  /* Rapikan topbar: sembunyikan nama/peran, sisakan avatar + tombol keluar */
  .topbar .user .right { display: none; }
  .topbar .user { gap: 8px; }
}

@media (max-width: 480px) {
  .grid.cols-4, .grid.cols-3 { grid-template-columns: 1fr; }
  .toolbar { padding: 12px; }
  .toolbar .btn, .page-actions .btn { flex: 1; justify-content: center; }
}

.menu-toggle { display: none; background: none; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; cursor: pointer; font-size: 18px; }

/* ---------- Print / PDF ---------- */
@media print {
  body { background: #fff; }
  .sidebar, .topbar, .no-print { display: none !important; }
  .main { margin-left: 0; padding: 0; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; border: none; }
  a { color: #000; }
}
