/* ============================================
   SISTEM INFORMASI WARGA - STYLES
   ============================================ */

/* === RESET & BASE === */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #059669;
  --success-light: #d1fae5;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --dark: #1e293b;
  --text: #334155;
  --text-light: #64748b;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* === PAGES === */
.page { display: none; min-height: 100vh; }
.page.active { display: block; }

/* === LOADING OVERLAY === */
.loading-overlay {
  position: fixed; inset: 0; background: rgba(255,255,255,0.85);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 9999;
}
.spinner {
  width: 44px; height: 44px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay p { margin-top: 12px; color: var(--text-light); font-weight: 500; }

/* === TOAST === */
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
  padding: 12px 24px; border-radius: 10px; color: white;
  font-weight: 600; font-size: 0.9em; z-index: 10000;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(20px); } }

.hide { display: none !important; }

/* ============================================
   LOGIN PAGE
   ============================================ */
.login-wrapper {
  max-width: 420px;
  margin: 0 auto;
  padding: 40px 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-header {
  text-align: center;
  margin-bottom: 30px;
}
.login-header .logo-img {
  width: 100px;
  height: 100px;
  object-fit: contain;
  margin-bottom: 12px;
  border-radius: 50%;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
.login-header h1 { font-size: 1.4em; color: var(--dark); }
.login-header p { color: var(--text-light); font-size: 0.9em; margin-top: 4px; }

.login-tabs {
  display: flex; gap: 4px;
  background: var(--border);
  border-radius: 10px; padding: 4px;
  margin-bottom: 24px;
}
.login-tab {
  flex: 1; padding: 10px; border: none; background: none;
  border-radius: 8px; cursor: pointer; font-weight: 600;
  font-size: 0.9em; color: var(--text-light);
  transition: all 0.3s;
}
.login-tab.active {
  background: white; color: var(--primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.login-form {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.login-footer {
  text-align: center; margin-top: 24px;
  font-size: 0.8em; color: var(--text-light);
}

/* ============================================
   FORMS
   ============================================ */
.form-group {
  margin-bottom: 14px;
}
.form-group label {
  display: block; font-weight: 600;
  margin-bottom: 5px; font-size: 0.82em;
  color: var(--text-light);
}
.form-group label .req { color: var(--danger); }

.form-group input,
.form-group select {
  width: 100%; padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 8px; font-size: 0.95em;
  transition: border-color 0.3s;
  outline: none; background: white;
}
.form-group input:focus,
.form-group select:focus {
  border-color: var(--primary);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-grid .full { grid-column: 1 / -1; }

.form-section-title {
  font-weight: 700; color: var(--primary);
  font-size: 0.88em; margin: 20px 0 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--primary-light);
  display: flex; align-items: center; gap: 8px;
}

.form-actions {
  display: flex; gap: 10px;
  margin-top: 24px; justify-content: flex-end;
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
  padding: 10px 20px; border: none; border-radius: 8px;
  font-weight: 600; cursor: pointer; font-size: 0.9em;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all 0.2s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #047857; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 6px 14px; font-size: 0.82em; }

.btn-icon {
  background: none; border: none; color: white;
  font-size: 1.1em; cursor: pointer; padding: 8px;
  border-radius: 8px; transition: background 0.2s;
}
.btn-icon:hover { background: rgba(255,255,255,0.15); }

/* ============================================
   TOPBAR
   ============================================ */
.topbar {
  padding: 12px 20px; display: flex;
  justify-content: space-between; align-items: center;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}
.topbar-warga { background: linear-gradient(135deg, var(--success), #047857); color: white; }
.topbar-admin { background: linear-gradient(135deg, var(--dark), #0f172a); color: white; }
.topbar-left { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.admin-name { font-size: 0.85em; opacity: 0.9; }

/* ============================================
   ADMIN TABS
   ============================================ */
.admin-tabs {
  display: flex; background: white;
  border-bottom: 2px solid var(--border);
  overflow-x: auto; padding: 0 12px;
}
.admin-tab {
  padding: 12px 16px; border: none; background: none;
  cursor: pointer; font-size: 0.82em; font-weight: 600;
  color: var(--text-light); white-space: nowrap;
  border-bottom: 3px solid transparent;
  display: flex; align-items: center; gap: 6px;
  transition: all 0.3s;
}
.admin-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.admin-tab:hover { color: var(--primary); }

.admin-content { display: none; }
.admin-content.active { display: block; }

.container { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* ============================================
   CARDS & STATS
   ============================================ */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.stat-card {
  background: white; border-radius: var(--radius);
  padding: 16px; text-align: center;
  box-shadow: var(--shadow); border: 1px solid var(--border);
  transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-card .stat-icon { font-size: 1.6em; margin-bottom: 4px; }
.stat-card .stat-num { font-size: 1.8em; font-weight: 800; color: var(--primary); }
.stat-card .stat-label { font-size: 0.75em; color: var(--text-light); margin-top: 2px; }

.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.chart-row .card h3 {
  font-size: 0.9em; margin-bottom: 12px;
  display: flex; align-items: center; gap: 6px;
}

/* ============================================
   SECTION HEADER
   ============================================ */
.section-header {
  display: flex; justify-content: space-between;
  align-items: center; margin-bottom: 16px;
  flex-wrap: wrap; gap: 10px;
}
.section-header h2 {
  font-size: 1.1em; display: flex;
  align-items: center; gap: 8px;
}
.header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.search-box { display: flex; gap: 4px; }
.search-box input {
  padding: 8px 12px; border: 2px solid var(--border);
  border-radius: 8px; font-size: 0.85em; outline: none; width: 200px;
}
.search-box input:focus { border-color: var(--primary); }
.search-box button {
  padding: 8px 12px; background: var(--primary);
  color: white; border: none; border-radius: 8px; cursor: pointer;
}

/* ============================================
   WARGA CARD LIST (for PIN users)
   ============================================ */
.card-list { display: flex; flex-direction: column; gap: 10px; }

.warga-card {
  background: white; border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
  border: 1px solid var(--border);
  cursor: pointer; transition: all 0.2s;
  display: flex; align-items: center; gap: 14px;
}
.warga-card:hover { border-color: var(--primary); transform: translateX(4px); }

.warga-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4em; flex-shrink: 0;
}
.warga-avatar.male { background: var(--primary-light); }
.warga-avatar.female { background: #fce7f3; }

.warga-info { flex: 1; }
.warga-info .name { font-weight: 700; font-size: 1em; }
.warga-info .meta { font-size: 0.8em; color: var(--text-light); margin-top: 2px; }

.badge {
  display: inline-block; padding: 2px 10px;
  border-radius: 20px; font-size: 0.72em; font-weight: 700;
}
.badge-tetap { background: var(--primary-light); color: var(--primary); }
.badge-pendatang { background: var(--warning-light); color: var(--warning); }
.badge-aktif { background: var(--success-light); color: var(--success); }
.badge-l { background: var(--primary-light); color: var(--primary); }
.badge-p { background: #fce7f3; color: #db2777; }

/* ============================================
   TABLE
   ============================================ */
.table-wrapper { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 0.85em; background: white; }
th {
  background: #f8fafc; padding: 10px 14px; text-align: left;
  font-weight: 700; color: var(--text-light);
  font-size: 0.78em; text-transform: uppercase;
  letter-spacing: 0.5px; white-space: nowrap;
  border-bottom: 2px solid var(--border);
}
td { padding: 10px 14px; border-bottom: 1px solid var(--border); }
tr:hover { background: #f8fafc; }
td .name-cell { font-weight: 600; }

.btn-table {
  padding: 4px 10px; border: none; border-radius: 6px;
  cursor: pointer; font-size: 0.82em; font-weight: 600;
  margin: 0 2px; transition: all 0.2s;
}
.btn-view { background: var(--success-light); color: var(--success); }
.btn-view:hover { background: #a7f3d0; }
.btn-edit { background: var(--primary-light); color: var(--primary); }
.btn-edit:hover { background: #bfdbfe; }
.btn-delete { background: var(--danger-light); color: var(--danger); }
.btn-delete:hover { background: #fecaca; }

/* ============================================
   MODAL
   ============================================ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: none; justify-content: center; align-items: flex-start;
  padding: 20px; overflow-y: auto; z-index: 500;
}
.modal-overlay.active { display: flex; }

.modal {
  background: white; border-radius: 16px;
  width: 100%; max-width: 600px;
  max-height: 90vh; overflow-y: auto;
  margin-top: 30px; box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s ease;
}
.modal-lg { max-width: 750px; }
.modal-sm { max-width: 450px; }

@keyframes modalIn { from { opacity: 0; transform: translateY(-20px); } }

.modal-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; background: white;
  border-radius: 16px 16px 0 0;
}
.modal-header h3 {
  font-size: 1em; display: flex;
  align-items: center; gap: 8px;
}
.modal-close {
  background: none; border: none; font-size: 1.6em;
  cursor: pointer; color: var(--text-light);
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--bg); }

.modal-body { padding: 20px; }

/* Detail view */
.detail-section { margin-bottom: 16px; }
.detail-section-title {
  font-size: 0.82em; font-weight: 700; color: var(--primary);
  text-transform: uppercase; margin-bottom: 8px;
  padding-bottom: 4px; border-bottom: 2px solid var(--primary-light);
  display: flex; align-items: center; gap: 6px;
}
.detail-row {
  display: flex; padding: 7px 0;
  border-bottom: 1px solid #f1f5f9;
}
.detail-label {
  width: 40%; font-size: 0.82em;
  color: var(--text-light); font-weight: 600;
}
.detail-value { width: 60%; font-size: 0.9em; }

/* PIN Result */
.pin-result {
  background: var(--warning-light);
  border: 2px dashed var(--warning);
  border-radius: var(--radius);
  padding: 20px; text-align: center;
  margin: 16px 0;
}
.pin-code {
  font-size: 2.2em; font-weight: 900;
  color: var(--warning); letter-spacing: 6px;
  margin: 8px 0;
}
.pin-result .pin-note {
  font-size: 0.8em; color: #92400e; margin-top: 6px;
}

/* Skeleton */
.skeleton-card {
  height: 72px; background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  border-radius: var(--radius);
  animation: shimmer 1.5s infinite;
  margin-bottom: 10px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* Empty state */
.empty-state {
  text-align: center; padding: 40px 20px; color: var(--text-light);
}
.empty-state .empty-icon { font-size: 3em; margin-bottom: 10px; opacity: 0.5; }
.empty-state p { font-size: 0.9em; }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  .form-grid { grid-template-columns: 1fr; }
  .chart-row { grid-template-columns: 1fr; }
  .detail-row { flex-direction: column; }
  .detail-label, .detail-value { width: 100%; }
  .search-box input { width: 140px; }
  .admin-tab span { display: none; }
  .admin-tab { padding: 12px; font-size: 1.1em; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .section-header { flex-direction: column; align-items: flex-start; }
  .header-actions { width: 100%; }
  .search-box { flex: 1; }
  .search-box input { width: 100%; }
}

@media (max-width: 480px) {
  .login-wrapper { padding: 20px 12px; }
  .container { padding: 10px; }
  .topbar { padding: 10px 14px; }
  .modal { margin-top: 10px; border-radius: 12px; }
  .modal-body { padding: 14px; }
}

/* ============================================
   FORM PAGE (Full Page)
   ============================================ */
.topbar-form {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
}

.btn-back {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1em;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.btn-back:hover {
  background: rgba(255,255,255,0.3);
}

.form-card {
  margin-bottom: 16px;
}

.form-bottom-actions {
  display: flex;
  gap: 12px;
  padding: 20px 0 40px;
  position: sticky;
  bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 16px;
}

.form-bottom-actions .btn {
  flex: 1;
  justify-content: center;
}

.btn-lg {
  padding: 14px 24px;
  font-size: 1em;
}

@media (max-width: 480px) {
  .form-bottom-actions {
    flex-direction: column;
  }
}