* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --emerald: #0f766e;
  --emerald-dark: #115e59;
  --emerald-light: #14b8a6;
  --gold: #c9a227;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --warning: #d97706;
  --success: #16a34a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 14px rgba(0, 0, 0, 0.05);
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--emerald); text-decoration: none; }

/* ====== AUTH PAGES ====== */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--emerald-dark) 0%, var(--emerald) 50%, #134e4a 100%);
  padding: 20px;
}
.auth-card {
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  width: 100%;
  max-width: 420px;
  padding: 40px 36px;
}
.auth-logo {
  text-align: center;
  margin-bottom: 24px;
}
.auth-logo .icon {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, var(--emerald), var(--emerald-light));
  color: #fff; font-size: 30px;
  border-radius: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
}
.auth-logo h1 { font-size: 22px; color: var(--emerald-dark); }
.auth-logo p { color: var(--muted); font-size: 13px; margin-top: 4px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border 0.2s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--emerald-light);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.15);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 22px;
  border: none; cursor: pointer;
  border-radius: 10px;
  font-size: 14px; font-weight: 600;
  transition: all 0.2s;
}
.btn-primary { background: var(--emerald); color: #fff; }
.btn-primary:hover { background: var(--emerald-dark); }
.btn-outline { background: transparent; color: var(--emerald); border: 1.5px solid var(--emerald); }
.btn-outline:hover { background: var(--emerald); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f1f5f9; }
.btn-gold { background: var(--gold); color: #1e293b; }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-block { width: 100%; }

.alert {
  padding: 12px 16px; border-radius: 10px; font-size: 13px; margin-bottom: 16px;
  display: none;
}
.alert.show { display: block; }
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }

.auth-foot { text-align: center; margin-top: 18px; font-size: 13px; color: var(--muted); }

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

.sidebar {
  width: 250px;
  background: linear-gradient(180deg, var(--emerald-dark), var(--emerald));
  color: #fff;
  flex-shrink: 0;
  position: fixed; top: 0; bottom: 0; left: 0;
  display: flex; flex-direction: column;
  z-index: 30;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 22px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}
.sidebar-brand .icon {
  width: 38px; height: 38px; background: rgba(255, 255, 255, 0.15);
  border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.sidebar-brand h1 { font-size: 16px; }
.sidebar-brand small { opacity: 0.75; font-size: 11px; display: block; }

.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 12px;
  color: rgba(255, 255, 255, 0.85);
  padding: 12px 14px; border-radius: 10px;
  font-size: 14px; margin-bottom: 4px;
  transition: background 0.15s;
}
.sidebar-nav a:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.sidebar-nav a.active { background: rgba(255, 255, 255, 0.2); color: #fff; font-weight: 600; }
.sidebar-nav a .badge { margin-left: auto; background: var(--gold); color: #1e293b; font-size: 11px; padding: 2px 8px; border-radius: 20px; }

.sidebar-footer { padding: 16px 12px; border-top: 1px solid rgba(255, 255, 255, 0.15); }
.sidebar-footer .user-chip {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: rgba(255,255,255,0.1); border-radius: 12px;
}
.sidebar-footer .footer-actions { display: flex; gap: 8px; margin-top: 10px; }
.sidebar-footer .footer-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 8px 6px; border-radius: 8px;
  background: rgba(255,255,255,0.1); color: #fff; text-decoration: none; cursor: pointer;
  border: none; font-family: inherit; white-space: nowrap;
  transition: background 0.15s;
}
.sidebar-footer .footer-btn:hover { background: rgba(255,255,255,0.25); }
.sidebar-footer .avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--gold); color: #1e293b; font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.sidebar-footer .uname { font-size: 13px; font-weight: 600; }
.sidebar-footer .urole { font-size: 11px; opacity: 0.85; }

.main { flex: 1; margin-left: 250px; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  background: var(--card);
  padding: 16px 28px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h2 { font-size: 20px; }
.topbar p { font-size: 13px; color: var(--muted); }
.topbar .menu-btn { display: none; }

.content { padding: 26px 28px; flex: 1; }

/* ====== CARDS ====== */
.grid { display: grid; gap: 18px; }
.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: 768px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 20px;
}
.stat-card { display: flex; align-items: center; gap: 16px; }
.stat-card .icon {
  width: 52px; height: 52px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center; font-size: 24px;
}
.stat-card .value { font-size: 26px; font-weight: 700; }
.stat-card .label { font-size: 13px; color: var(--muted); }
.icon-emerald { background: #ccfbf1; color: var(--emerald); }
.icon-gold { background: #fef3c7; color: #b45309; }
.icon-blue { background: #dbeafe; color: #1d4ed8; }
.icon-purple { background: #ede9fe; color: #6d28d9; }

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 12px; flex-wrap: wrap;
}
.card-header h3 { font-size: 16px; }
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }

/* ====== PROGRESS BAR ====== */
.progress-wrap { margin: 8px 0; }
.progress-track {
  background: #e2e8f0; border-radius: 20px; height: 10px; overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: 20px;
  background: linear-gradient(90deg, var(--emerald-light), var(--emerald));
  transition: width 0.5s;
}
.progress-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 5px; }

/* ====== TABLES ====== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); background: #f8fafc; }
tr:hover td { background: #f8fafc; }
.empty { text-align: center; color: var(--muted); padding: 30px !important; font-size: 14px; }

/* ====== BADGES ====== */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-purple { background: #ede9fe; color: #6d28d9; }
.badge-gray { background: #f1f5f9; color: var(--muted); }

.jenis-badge { text-transform: capitalize; }
.nilai-badge { text-transform: capitalize; }

/* ====== MODAL ====== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 25px 60px rgba(0,0,0,0.3);
  padding: 26px;
}
.modal h3 { margin-bottom: 18px; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ====== MISC ====== */
.flex { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.grow { flex: 1; }

.chart-box { position: relative; height: 300px; }

.role-pill {
  display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600;
}
.role-admin { background: #fee2e2; color: #b91c1c; }
.role-musyrif { background: #dcfce7; color: #15803d; }
.role-santri { background: #dbeafe; color: #1d4ed8; }
.role-wali { background: #fef3c7; color: #b45309; }

.card-grid-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.santri-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; transition: transform 0.15s;
}
.santri-card:hover { transform: translateY(-2px); }
.santri-card .top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.santri-card .avatar {
  width: 46px; height: 46px; border-radius: 12px; background: var(--emerald);
  color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.santri-card h4 { font-size: 15px; }
.santri-card .sub { font-size: 12px; color: var(--muted); }

.tab-bar { display: flex; gap: 6px; border-bottom: 2px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
.tab-bar button {
  background: none; border: none; padding: 10px 16px; font-size: 14px; font-weight: 500;
  color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.tab-bar button.active { color: var(--emerald); border-bottom-color: var(--emerald); }

.row-actions { display: flex; gap: 6px; }
.row-actions button { background: none; border: none; cursor: pointer; font-size: 15px; padding: 4px; border-radius: 6px; }
.row-actions button:hover { background: #f1f5f9; }

/* Responsive */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.25s; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .topbar .menu-btn { display: inline-flex; }
  .content { padding: 18px; }
  .stat-card .value { font-size: 22px; }
}

footer.app-footer {
  padding: 14px 28px; color: var(--muted); font-size: 12px;
  border-top: 1px solid var(--border); background: var(--card);
}

/* toast */
.notice {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px);
  padding: 12px 22px; border-radius: 10px; color: #fff; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all 0.3s; z-index: 200;
  max-width: 90vw;
}
.notice.show { opacity: 1; transform: translate(-50%, 0); }
.notice-ok { background: var(--success); }
.notice-err { background: var(--danger); }