:root {
  --primary: #0f766e;
  --primary-600: #0d6560;
  --primary-50: #e8f5f3;
  --sidebar: #0b3b37;
  --accent: #d97706;
  --accent-50: #fef6e7;
  --bg: #f3f5f4;
  --surface: #ffffff;
  --text: #16211f;
  --muted: #5f6f6b;
  --border: #dfe5e3;
  --danger: #dc2626;
  --danger-50: #fef2f2;
  --success: #15803d;
  --success-50: #f0fdf4;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--text); background: var(--bg); }
body.no-scroll { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
.nowrap { white-space: nowrap; }
.center { text-align: center; display: block; }
.req { color: var(--danger); }
.icon { width: 18px; height: 18px; flex-shrink: 0; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40; width: 264px;
  display: flex; flex-direction: column; gap: 8px;
  background: var(--sidebar); color: #d7ebe8; padding: 20px 14px;
  transform: translateX(-100%); transition: transform .25s ease;
  overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }
.overlay { position: fixed; inset: 0; z-index: 30; background: rgba(5, 20, 18, .5); }
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand strong { display: block; color: #fff; font-size: 1rem; }
.brand small { color: #9cc9c3; font-size: .78rem; }
.brand-logo { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 10px; background: var(--accent); color: #fff; }
.brand-logo .icon { width: 22px; height: 22px; }
.brand-logo-lg { width: 64px; height: 64px; border-radius: 16px; }
.brand-logo-lg .icon { width: 34px; height: 34px; }
.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; flex: 1; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; color: #cfe5e1; font-weight: 500; font-size: .92rem; }
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-link.active { background: var(--primary); color: #fff; }
.sidebar-foot { border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 4px 8px; }
.sidebar-user strong { display: block; color: #fff; font-size: .88rem; }
.sidebar-user small { color: #9cc9c3; font-size: .78rem; }
.nav-logout:hover { background: rgba(220, 38, 38, .2); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: rgba(255,255,255,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 1.05rem; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-toggle { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); cursor: pointer; }
.content { padding: 16px; display: flex; flex-direction: column; gap: 16px; flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; }
.app-footer { padding: 16px; text-align: center; color: var(--muted); font-size: .8rem; }

@media (min-width: 1024px) {
  .sidebar { transform: none; }
  .main { margin-left: 264px; }
  .menu-toggle { display: none; }
  .overlay { display: none !important; }
  .topbar { padding: 14px 28px; }
  .content { padding: 24px 28px; gap: 20px; }
}

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-body { padding: 18px; border: 0; margin: 0; min-width: 0; }
fieldset.card-body { display: flex; flex-direction: column; gap: 14px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head p { margin-top: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px; border-radius: 9px; border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-600); }
.btn-secondary { background: var(--primary-50); color: var(--primary); border-color: #c7e5e0; }
.btn-secondary:hover:not(:disabled) { background: #d8eeea; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: #eef1f0; }
.btn-danger-outline { background: transparent; color: var(--danger); border-color: #f5c2c2; }
.btn-danger-outline:hover { background: var(--danger-50); }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: .82rem; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); cursor: pointer; padding: 0;
}
.btn-icon:hover { color: var(--primary); border-color: #c7e5e0; background: var(--primary-50); }
.btn-icon-danger:hover { color: var(--danger); border-color: #f5c2c2; background: var(--danger-50); }
.btn-icon .icon { width: 16px; height: 16px; }
.actions { display: flex; gap: 6px; align-items: center; }
.actions form { display: inline; margin: 0; }

.alert { padding: 12px 14px; border-radius: 10px; border: 1px solid; font-size: .9rem; }
.alert-success { background: var(--success-50); border-color: #bbe5c8; color: #14532d; }
.alert-error { background: var(--danger-50); border-color: #f5c2c2; color: #7f1d1d; }
.alert-info { background: var(--accent-50); border-color: #f6d9a8; color: #78350f; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--primary-50); color: var(--primary); font-size: .75rem; font-weight: 600; white-space: nowrap; }
.mode-badge { padding: 4px 10px; border-radius: 999px; background: var(--accent-50); color: #92400e; font-size: .78rem; font-weight: 600; }
.role-badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.role-super_admin { background: #fde9e9; color: #991b1b; }
.role-admin_desa { background: var(--primary-50); color: var(--primary); }
.role-guest { background: #eef1f0; color: var(--muted); }
.chip { display: inline-flex; gap: 6px; align-items: center; margin: 2px 4px 2px 0; padding: 2px 8px; border-radius: 6px; background: #eef1f0; font-size: .78rem; }
.chip b { color: var(--primary); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: .85rem; font-weight: 600; }
.field small { font-size: .78rem; }
.field-label { font-size: .85rem; font-weight: 600; }
.field-label small { font-weight: 400; }
.check-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.check-pill { position: relative; display: inline-flex; cursor: pointer; }
.check-pill input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.check-pill span { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-size: .85rem; font-weight: 500; transition: background .15s, border-color .15s, color .15s; }
.check-pill span::before { content: ""; width: 14px; height: 14px; border: 1.5px solid #9aa9a5; border-radius: 4px; flex-shrink: 0; }
.check-pill:hover span { border-color: var(--primary); }
.check-pill input:checked + span { background: var(--primary-50); border-color: var(--primary); color: var(--primary); font-weight: 600; }
.check-pill input:checked + span::before { border-color: var(--primary); background: var(--primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") center / 10px no-repeat; }
.check-pill input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
fieldset:disabled .check-pill { cursor: default; }
fieldset:disabled .check-pill:has(input:not(:checked)) { display: none; }
fieldset:disabled .check-pill span::before { display: none; }
.empty-hint { padding: 10px 12px; border: 1px dashed var(--border); border-radius: 8px; font-size: .85rem; color: var(--muted); }
.dapukan-text { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); font-size: .78rem; font-weight: 600; }
.dapukan-text .icon { width: 12px; height: 12px; }
.chip .icon { width: 13px; height: 13px; color: var(--primary); }
.quick-add-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 720px) { .quick-add-grid { grid-template-columns: 1.2fr 1fr auto; align-items: end; } }
input[type=text], input[type=password], input[type=date], input[type=tel], input[type=search], select, textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; font: inherit; font-size: .92rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, .15); }
input[readonly] { background: #f6f8f7; color: var(--muted); }
fieldset:disabled input, fieldset:disabled select, fieldset:disabled textarea { background: #f8faf9; color: var(--text); border-style: dashed; }
fieldset:disabled .btn-add, fieldset:disabled [data-remove-row], fieldset:disabled .btn-file { display: none; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.field-full { grid-column: 1 / -1; }
.section-title { margin-top: 8px; padding-top: 14px; border-top: 1px dashed var(--border); font-size: .95rem; color: var(--primary); }
.multi-list { display: flex; flex-direction: column; gap: 6px; }
.multi-row { display: flex; gap: 6px; }
.btn-add { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border: 0; background: none; color: var(--primary); font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer; border-radius: 6px; }
.btn-add:hover { background: var(--primary-50); }
.btn-add .icon { width: 14px; height: 14px; }
.form-actions { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 14px 18px; border-top: 1px solid var(--border); background: #fafbfb; border-radius: 0 0 var(--radius) var(--radius); }
.form-actions-main { display: flex; gap: 8px; flex-wrap: wrap; }
.form-actions-main .btn { min-width: 96px; }

.jamaah-form { display: flex; flex-direction: column; gap: 18px; }
.photo-col { display: flex; flex-direction: column; gap: 8px; align-items: stretch; width: 100%; max-width: 220px; margin: 0 auto; }
.photo-box { aspect-ratio: 3 / 4; border-radius: 12px; overflow: hidden; border: 2px dashed var(--border); background: #f6f8f7; display: flex; align-items: center; justify-content: center; }
.photo-box img { width: 100%; height: 100%; object-fit: cover; }
.photo-placeholder { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--muted); }
.photo-placeholder .icon { width: 32px; height: 32px; }

@media (min-width: 640px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 900px) {
  .jamaah-form { flex-direction: row; align-items: flex-start; }
  .jamaah-form .form-grid { flex: 1; }
  .photo-col { margin: 0; flex-shrink: 0; }
  .form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #f8faf9; font-weight: 600; white-space: nowrap; }
.table th, .table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:hover { background: #fafcfb; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 28px 14px !important; list-style: none; }
.link-strong { color: var(--text); font-weight: 600; }
.link-strong:hover { color: var(--primary); }

.pagination { display: flex; gap: 4px; justify-content: center; padding: 14px; flex-wrap: wrap; }
.pagination a, .pagination span { min-width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; border: 1px solid var(--border); font-size: .85rem; color: var(--text); }
.pagination .active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- Dashboard ---------- */
.welcome { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 20px; border-radius: var(--radius); background: linear-gradient(135deg, var(--sidebar), var(--primary)); color: #fff; }
.welcome .muted { color: #c6e3df; }
.welcome .btn-primary { background: var(--accent); }
.welcome .btn-primary:hover { background: #b45309; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.stat { display: flex; align-items: center; gap: 12px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.stat small { display: block; color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat strong { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
a.stat { color: inherit; text-decoration: none; transition: border-color .15s; }
a.stat:hover, a.stat:focus-visible { border-color: var(--primary); }
.stat-icon { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 10px; background: var(--primary-50); color: var(--primary); font-weight: 700; flex-shrink: 0; }
.stat-icon-blue { background: #e7f0fd; color: #1d4ed8; }
.stat-icon-rose { background: #fde9ef; color: #be185d; }
.stat-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.stat-primary small { color: #c6e3df; }
.stat-primary .stat-icon { background: rgba(255,255,255,.15); color: #fff; }
.stats-compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stats-compact .stat { padding: 10px 14px; }
.stats-compact .stat strong { font-size: 1.15rem; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } .stats-compact { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .stats { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 1024px) { .grid-2 { grid-template-columns: 3fr 2fr; } }

.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.bar-label { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: 4px; }
.bar-track { height: 8px; border-radius: 999px; background: #eef1f0; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 999px; background: var(--primary); }

.pengurus-list { margin: 0 0 6px; display: grid; grid-template-columns: 1fr; gap: 0; }
.pengurus-list > div { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.pengurus-list dt { width: 150px; flex-shrink: 0; color: var(--muted); font-size: .85rem; }
.pengurus-list dd { margin: 0; font-weight: 500; }

.recent-list, .jamaah-list { list-style: none; margin: 0; padding: 0; }
.recent-list li, .jamaah-list li { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.recent-list li:last-child, .jamaah-list li:last-child { border-bottom: 0; }
.recent-info, .jamaah-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.jamaah-info small, .recent-info small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.jamaah-meta { display: none; flex-direction: column; align-items: flex-end; gap: 2px; }
@media (min-width: 720px) { .jamaah-meta { display: flex; } }
@media (max-width: 480px) { .jamaah-list .actions .btn-icon:not(:first-child), .jamaah-list .actions form { display: none; } }

.avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.avatar-sm { width: 34px; height: 34px; font-size: .75rem; }
.avatar-initials { display: inline-flex; align-items: center; justify-content: center; background: var(--primary-50); color: var(--primary); font-weight: 700; }
.sidebar .avatar-initials { background: rgba(255,255,255,.12); color: #fff; }

.filter-card { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.filter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 900px) { .filter-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.inline-filter { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-filter input, .inline-filter select { flex: 1 1 200px; width: auto; }
.role-info { display: grid; grid-template-columns: 1fr; gap: 12px; }
.role-info p { margin-top: 8px; }
@media (min-width: 720px) { .role-info { grid-template-columns: repeat(3, 1fr); } }

/* ---------- Login ---------- */
.login-page { background: var(--sidebar); }
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; padding: 24px 16px; }
.login-hero { color: #fff; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; max-width: 380px; }
.login-hero h2 { font-size: 1.6rem; }
.login-hero p { color: #b8dbd6; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 16px; padding: 28px 24px; box-shadow: 0 20px 50px rgba(0,0,0,.25); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 1.4rem; }
.stack { display: flex; flex-direction: column; gap: 14px; }
@media (min-width: 900px) {
  .login-wrap { flex-direction: row; gap: 64px; }
  .login-hero { text-align: left; align-items: flex-start; }
  .login-hero h2 { font-size: 2.2rem; }
}

/* ---------- Print ---------- */
@media print {
  .sidebar, .topbar, .overlay, .no-print, .app-footer, .alert { display: none !important; }
  .main { margin: 0 !important; }
  .content { padding: 0; max-width: none; }
  body { background: #fff; font-size: 11px; }
  .card, .stat { box-shadow: none; }
  .table th, .table td { padding: 4px 6px; }
  .table-wrap { overflow: visible; }
}

.dapukan-groups { display: grid; gap: 14px; }
.dapukan-scope { padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: #fafcfb; }
.dapukan-scope > strong { display: block; margin-bottom: 9px; font-size: .88rem; }
