@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700;800&display=swap');

:root {
  /* Color Palette - Premium Light Theme (High Contrast & Senior Friendly) */
  --bg-app: #f1f5f9; /* Slate 100 - soft on the eyes */
  --bg-card: #ffffff; /* Crisp white cards */
  --text-primary: #0f172a; /* Slate 900 - high contrast deep navy */
  --text-secondary: #334155; /* Slate 700 - very readable gray */
  --text-muted: #64748b; /* Slate 500 - for secondary notes */
  
  --primary: #2563eb; /* Royal Blue - clear and standard */
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  
  --success: #059669; /* Emerald 600 - positive clear green */
  --success-light: #ecfdf5;
  
  --warning: #d97706; /* Amber 600 - attention-grabbing yellow */
  --warning-light: #fef3c7;
  
  --danger: #dc2626; /* Crimson Red - high visibility emergency red */
  --danger-hover: #b91c1c;
  --danger-light: #fef2f2;
  
  --border-color: #cbd5e1; /* Slate 300 - clear grid lines */
  --border-focus: #3b82f6;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.6;
  font-size: 16px; /* Senior Friendly minimum size */
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Outfit', sans-serif;
  color: var(--text-primary);
  font-weight: 700;
}

/* App Containers */
.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  background-color: var(--bg-card);
  border-bottom: 2px solid var(--border-color);
  padding: 1rem 2rem;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  background: linear-gradient(135deg, var(--primary), #4f46e5);
  color: white;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 800;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

.logo-text h1 {
  font-size: 1.6rem;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--primary), #1e3a8a);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-text p {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background-color: var(--primary-light);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-full);
  border: 1px solid rgba(37, 99, 235, 0.2);
}

.user-badge-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background-color: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.user-badge-name {
  font-weight: 600;
  color: var(--primary);
  font-size: 0.95rem;
}

/* Button & Controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: 'Outfit', sans-serif;
  font-size: 1.05rem; /* Senior friendly size */
  font-weight: 600;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: var(--transition);
  min-height: 48px; /* Large clickable target */
}

.btn-primary {
  background-color: var(--primary);
  color: white;
  box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 12px -2px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
  background-color: var(--bg-app);
  color: var(--text-primary);
  border: 2px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: #e2e8f0;
  border-color: var(--text-muted);
}

.btn-danger {
  background-color: var(--danger);
  color: white;
  box-shadow: 0 4px 6px -1px rgba(220, 38, 38, 0.2);
}

.btn-danger:hover {
  background-color: var(--danger-hover);
  transform: translateY(-1px);
}

.btn-icon-only {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: var(--radius-md);
}

/* Login Page Styling */
.login-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
}

.login-card {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border-color);
  width: 100%;
  max-width: 500px;
  padding: 2.5rem;
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-header .app-logo-large {
  display: inline-flex;
  background: linear-gradient(135deg, var(--primary), #4f46e5);
  color: white;
  width: 64px;
  height: 64px;
  border-radius: 16px;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  font-weight: 800;
  box-shadow: 0 6px 15px rgba(37, 99, 235, 0.4);
  margin-bottom: 1rem;
}

.login-header h2 {
  font-size: 1.8rem;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.login-header p {
  color: var(--text-secondary);
  font-size: 1.05rem;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
  font-size: 1.05rem;
}

.form-input {
  width: 100%;
  padding: 0.8rem 1rem;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 1.05rem;
  color: var(--text-primary);
  background-color: #f8fafc;
  transition: var(--transition);
  min-height: 48px;
}

.form-input:focus {
  outline: none;
  border-color: var(--border-focus);
  background-color: white;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
}

.demo-credentials-box {
  background-color: var(--primary-light);
  border: 1px dashed var(--primary);
  padding: 1.25rem;
  border-radius: var(--radius-md);
  margin-top: 1.5rem;
  font-size: 0.95rem;
}

.demo-credentials-title {
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.demo-credentials-box ul {
  list-style-type: none;
  padding-left: 0;
}

.demo-credentials-box li {
  margin-bottom: 0.4rem;
  color: var(--text-secondary);
  font-family: monospace;
}

.demo-credentials-box li strong {
  font-family: sans-serif;
  color: var(--text-primary);
}

/* Main Dashboard SPA Layout */
.dashboard-wrapper {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
  width: 100%;
  flex: 1;
}

/* Emergency Alert Bar */
.emergency-alert-bar {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  color: white;
  padding: 1.25rem 2rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  margin-bottom: 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  border: 2px solid #fecaca;
  animation: pulse-red 2s infinite;
}

.emergency-alert-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.emergency-alert-icon {
  background-color: rgba(255, 255, 255, 0.2);
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  animation: ring-alarm 0.5s infinite alternate;
}

.emergency-alert-text h3 {
  color: white;
  font-size: 1.25rem;
  font-weight: 800;
}

.emergency-alert-text p {
  color: #fee2e2;
  font-size: 1.05rem;
  font-weight: 500;
}

/* Grid Layout for Warga Hub */
.warga-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}

@media(min-width: 1024px) {
  .warga-grid {
    grid-template-columns: 350px 1fr;
  }
}

/* Cards & Sections */
.card {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 2px solid var(--border-color);
  box-shadow: var(--shadow-md);
  padding: 2rem;
  margin-bottom: 2rem;
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-lg);
  border-color: #cbd5e1;
}

.card-title {
  font-size: 1.35rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 0.75rem;
  color: var(--text-primary);
}

.card-title svg {
  color: var(--primary);
}

/* Profile Section Warga */
.warga-profile-card {
  text-align: center;
}

.warga-avatar-container {
  position: relative;
  display: inline-block;
  margin: 1rem auto 1.5rem;
}

.warga-avatar {
  width: 100px;
  height: 100px;
  border-radius: var(--radius-full);
  background-color: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  font-weight: bold;
  border: 4px solid var(--primary);
  box-shadow: var(--shadow-md);
}

.warga-profile-name {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.warga-profile-nik {
  font-family: monospace;
  font-size: 1.05rem;
  color: var(--text-muted);
  background-color: #f1f5f9;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
  display: inline-block;
  margin-bottom: 1.5rem;
}

.warga-meta-info {
  text-align: left;
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
}

.warga-meta-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  font-size: 1rem;
}

.warga-meta-row strong {
  color: var(--text-primary);
}

.warga-meta-row span {
  color: var(--text-secondary);
}

/* Panic Button Panel */
.panic-button-card {
  background: linear-gradient(135deg, #fff5f5 0%, #fee2e2 100%);
  border: 2px solid #fca5a5;
  text-align: center;
}

.panic-button-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 1.5rem 0;
}

.panic-trigger {
  width: 150px;
  height: 150px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #dc2626, #991b1b);
  border: 10px solid #fee2e2;
  box-shadow: 0 10px 25px rgba(220, 38, 38, 0.4), var(--shadow-lg);
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s ease;
  position: relative;
}

.panic-trigger:active, .panic-trigger.pressing {
  transform: scale(0.95);
  box-shadow: 0 4px 10px rgba(220, 38, 38, 0.6);
  background: linear-gradient(135deg, #b91c1c, #7f1d1d);
}

.panic-trigger-icon {
  font-size: 3rem;
  margin-bottom: 0.25rem;
}

.panic-trigger-text {
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  font-size: 0.85rem;
  letter-spacing: 0.5px;
}

.panic-countdown {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-full);
  background-color: rgba(220, 38, 38, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
  font-weight: 800;
  color: white;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.panic-countdown.active {
  opacity: 1;
}

.panic-instruction {
  font-size: 1.05rem;
  font-weight: 600;
  color: #991b1b;
  margin-top: 1rem;
}

/* Tabs & Navigation */
.tabs-nav {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 2rem;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 0.5rem;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch; /* Smooth inertial scrolling on iOS devices */
  scrollbar-width: none; /* Hide scrollbar Firefox */
}

.tabs-nav::-webkit-scrollbar {
  display: none; /* Hide scrollbar Chrome/Safari/Opera */
}

.tab-btn {
  background: none;
  border: none;
  padding: 0.75rem 1.5rem;
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: var(--transition);
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tab-btn:hover {
  background-color: #e2e8f0;
  color: var(--text-primary);
}

.tab-btn.active {
  background-color: var(--primary-light);
  color: var(--primary);
  border: 1px solid rgba(37, 99, 235, 0.2);
}

/* Quick Statistics Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  background-color: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
}

.stat-icon.primary { background-color: var(--primary-light); color: var(--primary); }
.stat-icon.success { background-color: var(--success-light); color: var(--success); }
.stat-icon.warning { background-color: var(--warning-light); color: var(--warning); }
.stat-icon.danger { background-color: var(--danger-light); color: var(--danger); }

.stat-info h4 {
  font-size: 0.95rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text-primary);
}

/* General Modul & Form Design */
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media(min-width: 768px) {
  .form-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }
  .form-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-success { background-color: var(--success-light); color: var(--success); border: 1px solid rgba(5, 150, 105, 0.3); }
.badge-warning { background-color: var(--warning-light); color: var(--warning); border: 1px solid rgba(217, 119, 6, 0.3); }
.badge-danger { background-color: var(--danger-light); color: var(--danger); border: 1px solid rgba(220, 38, 38, 0.3); }
.badge-neutral { background-color: #f1f5f9; color: var(--text-secondary); border: 1px solid var(--border-color); }

/* Table styling for records */
.table-container {
  overflow-x: auto;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-top: 1rem;
  -webkit-overflow-scrolling: touch;
}

/* Custom scrollbar for accessible horizontal scrolling tables */
.table-container::-webkit-scrollbar {
  height: 6px;
}
.table-container::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 4px;
}
.table-container::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}
.table-container::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.custom-table {
  width: 100%;
  min-width: 800px; /* Crucial: Prevents table squishing on mobile screens */
  border-collapse: collapse;
  text-align: left;
}

.custom-table th {
  background-color: #f8fafc;
  color: var(--text-primary);
  font-weight: 700;
  padding: 1rem;
  border-bottom: 2px solid var(--border-color);
  font-size: 1rem;
}

.custom-table td {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.95rem;
  vertical-align: middle;
}

.custom-table tr:last-child td {
  border-bottom: none;
}

.custom-table tr:hover td {
  background-color: #f8fafc;
}

/* Modals */
body.modal-open {
  overflow: hidden;
  height: 100vh;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 2rem 1rem;
  box-sizing: border-box;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  border: 2px solid var(--border-color);
  width: 100%;
  max-width: 580px;
  padding: 1.5rem;
  transform: translateY(20px);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  margin: auto;
  max-height: 90vh;
}

.modal-overlay.active .modal-content {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
  flex-shrink: 0;
}

.modal-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1.5rem;
  transition: var(--transition);
}

.modal-close-btn:hover {
  color: var(--text-primary);
}

.modal-body {
  margin-bottom: 1rem;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  padding-right: 0.5rem; /* space for the custom scrollbar */
}

/* Custom scrollbar for accessible modal bodies */
.modal-body::-webkit-scrollbar {
  width: 6px;
}
.modal-body::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 4px;
}
.modal-body::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}
.modal-body::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
  flex-shrink: 0;
}

/* File Upload Premium Style */
.file-upload-wrapper {
  border: 2px dashed var(--border-color);
  background-color: #f8fafc;
  padding: 1rem;
  border-radius: var(--radius-md);
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.file-upload-wrapper:hover {
  border-color: var(--primary);
  background-color: var(--primary-light);
}

.file-upload-icon {
  font-size: 1.5rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.file-upload-text {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.file-upload-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.file-upload-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.receipt-preview {
  margin-top: 0.75rem;
  max-width: 100%;
  max-height: 100px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-color);
  display: none;
}

/* pay-qris flex-container for side-by-side layout (compact visual flow) */
.pay-qris-flex-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}

@media(min-width: 480px) {
  .pay-qris-flex-container {
    flex-direction: row;
    align-items: flex-start;
    gap: 1.25rem;
  }
  .qris-card-wrapper {
    flex: 0 0 200px;
  }
  .uploader-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
}

/* QRIS static illustration design (Optimized and scaled down) */
.qris-card {
  background-color: #ffffff;
  border: 2px solid var(--border-color);
  padding: 0.75rem;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  box-shadow: var(--shadow-sm);
}

.qris-header {
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #1e3a8a;
  font-size: 1.15rem;
  margin-bottom: 0.25rem;
}

.qris-qr-frame {
  padding: 0.4rem;
  border: 2px solid var(--text-primary);
  border-radius: var(--radius-md);
  background-color: white;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qris-qr-image {
  width: 160px;
  height: 160px;
  object-fit: contain;
}

.qris-nm {
  font-weight: 700;
  color: var(--text-primary);
  font-size: 0.85rem;
  text-transform: uppercase;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

.qris-id {
  font-family: monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 400px;
}

.toast {
  background-color: var(--bg-card);
  color: var(--text-primary);
  padding: 1rem 1.5rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border-left: 6px solid var(--primary);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 600;
  font-size: 1rem;
  transform: translateY(100px);
  opacity: 0;
  animation: slide-in-toast 0.3s forwards;
  pointer-events: auto;
}

.toast.toast-success { border-left-color: var(--success); }
.toast.toast-warning { border-left-color: var(--warning); }
.toast.toast-danger { border-left-color: var(--danger); }

/* Animation Keyframes */
@keyframes slide-in-toast {
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes pulse-red {
  0% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.4);
  }
  70% {
    box-shadow: 0 0 0 15px rgba(220, 38, 38, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0);
  }
}

@keyframes ring-alarm {
  0% {
    transform: rotate(-10deg) scale(1.1);
  }
  100% {
    transform: rotate(10deg) scale(1.1);
  }
}

/* Utility search bar */
.search-bar-container {
  position: relative;
  margin-bottom: 1.5rem;
}

.search-input {
  width: 100%;
  padding: 0.8rem 1rem 0.8rem 2.75rem;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 1.05rem;
  min-height: 48px;
}

.search-icon-inside {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

/* Custom Letter Request Form & Details */
.letter-type-selector {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.letter-type-btn {
  background-color: var(--bg-app);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.5rem;
  text-align: center;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  font-family: 'Outfit', sans-serif;
  font-size: 0.95rem;
}

.letter-type-btn:hover {
  background-color: #e2e8f0;
}

.letter-type-btn.active {
  background-color: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Cash balance visualization and logs */
.cashflow-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  margin-top: 1rem;
}

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

.chart-card-container {
  position: relative;
  height: 300px;
  width: 100%;
}

.cash-logs-list {
  max-height: 300px;
  overflow-y: auto;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.5rem;
}

.cash-log-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
}

.cash-log-item:last-child {
  border-bottom: none;
}

.cash-log-details h5 {
  font-size: 1rem;
  color: var(--text-primary);
  font-weight: 600;
}

.cash-log-details p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.cash-log-amount {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
}

.cash-log-amount.in { color: var(--success); }
.cash-log-amount.out { color: var(--danger); }

/* ==================== MEDIA QUERIES FOR SEAMLESS MOBILE RESPONSIVENESS ==================== */

@media (max-width: 1023px) {
  /* Stacks sidebar (profile, panic button) UNDER the main dashboard content on tablets/phones.
     This ensures citizens see their billing tabs and active content first without scrolling 900px! */
  .warga-grid {
    display: flex;
    flex-direction: column-reverse;
    gap: 1.5rem;
  }
  .sidebar-area {
    margin-top: 1rem;
  }
}

@media (max-width: 768px) {
  /* Reduce outer padding of the dashboard on tablets/phones to maximize screen space */
  .dashboard-wrapper {
    padding: 0.85rem;
  }
  
  /* Make cards more compact and sleek on smaller screens */
  .card {
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    border-radius: var(--radius-md);
  }
  .card-title {
    font-size: 1.15rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    gap: 0.5rem;
  }
  .card-title svg {
    width: 20px;
    height: 20px;
  }
}

@media (max-width: 576px) {
  /* Streamline header layout on mobile screens, centering content beautifully when wrapped */
  header {
    padding: 0.75rem 1rem;
  }
  .header-content {
    justify-content: center;
    text-align: center;
    gap: 0.75rem;
  }
  .logo-area {
    justify-content: center;
    width: 100%;
  }
  .header-actions {
    justify-content: center;
    width: 100%;
    gap: 0.75rem;
  }
  
  .logo-text h1 {
    font-size: 1.3rem;
  }
  .logo-text p {
    font-size: 0.7rem;
    letter-spacing: 0.5px;
  }
  
  /* Compact User Badge styling for clean visual flow */
  .user-badge {
    padding: 0.35rem 0.6rem;
    gap: 0.4rem;
  }
  .user-badge-name {
    display: none; /* Hide user name on extremely small screens (the colored avatar is enough and keeps header clean) */
  }
  .user-badge-avatar {
    width: 28px;
    height: 28px;
    font-size: 0.9rem;
  }
  
  /* Stats Grid: Transition to an extremely premium 2-column grid layout */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.25rem;
  }
  
  /* Smart CSS: If there's an odd number of stat cards (like the 3 cards in warga iuran), 
     make the first card span 2 columns fully for absolute symmetry! */
  .stats-grid > *:nth-last-child(odd):first-child {
    grid-column: span 2;
  }
  
  .stat-card {
    padding: 0.85rem;
    gap: 0.75rem;
    border-radius: var(--radius-md);
  }
  .stat-icon {
    width: 44px;
    height: 44px;
    font-size: 1.25rem;
  }
  .stat-icon svg {
    width: 20px;
    height: 20px;
  }
  .stat-info h4 {
    font-size: 0.75rem;
    margin-bottom: 0.15rem;
  }
  
  /* Responsive Stats Nominal Sizing: Prevents text overflow / messy layout in mobile cards */
  .stat-value {
    font-size: 1.15rem;
    white-space: nowrap;
  }
  
  /* The first card spans 2 columns, so it has more horizontal space to display a larger nominal */
  .stats-grid > *:nth-last-child(odd):first-child .stat-value {
    font-size: 1.45rem;
  }
  
  /* Make horizontal tab buttons compact and neat on mobile screens */
  .tab-btn {
    padding: 0.5rem 1rem;
    font-size: 0.95rem;
    min-height: 40px;
    gap: 0.35rem;
  }
  .tab-btn svg {
    width: 16px;
    height: 16px;
  }
  
  /* Enable direct horizontal swiping on the announcement carousel track */
  .carousel-track {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .carousel-track::-webkit-scrollbar {
    display: none;
  }
  .carousel-btn {
    display: none !important; /* Hide overlay arrow buttons on mobile since swipe touch is active */
  }
  
  /* Make emergency alarm bar neat on mobile */
  .emergency-alert-bar {
    padding: 1rem;
    margin-bottom: 1.5rem;
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }
  .emergency-alert-info {
    flex-direction: column;
    gap: 0.5rem;
  }
  .emergency-alert-text h3 {
    font-size: 1.1rem;
  }
  .emergency-alert-text p {
    font-size: 0.95rem;
  }
  
  /* Reduce modal margins & maximize width on tiny devices */
  .modal-overlay {
    padding: 0.75rem 0.5rem;
  }
  .modal-content {
    padding: 1rem;
    max-height: 95vh;
  }
}

@media (max-width: 480px) {
  /* Ensure login box fits beautifully on small viewports */
  .login-card {
    padding: 1.75rem 1.25rem;
  }
  .login-header {
    margin-bottom: 1.5rem;
  }
  .login-header .app-logo-large {
    width: 56px;
    height: 56px;
    font-size: 1.8rem;
    margin-bottom: 0.75rem;
  }
  .login-header h2 {
    font-size: 1.5rem;
  }
  .login-header p {
    font-size: 0.95rem;
  }
  
  /* Form sizer adjustments */
  .form-group {
    margin-bottom: 1.25rem;
  }
  .form-label {
    font-size: 0.95rem;
  }
  .form-input {
    font-size: 0.95rem;
    padding: 0.7rem 0.85rem;
  }
  
  /* QRIS Static Illustration Frame Sizer: Centered and constrained, 
     preventing enormous stretched QR codes on mobile */
  .qris-card-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
  }
  .qris-card {
    max-width: 230px;
    width: 100%;
    margin: 0 auto;
  }
}

@media (max-width: 390px) {
  /* Extra tiny screens optimization to ensure absolutely no overflowing currency text */
  .stat-value {
    font-size: 1rem !important;
  }
  .stats-grid > *:nth-last-child(odd):first-child .stat-value {
    font-size: 1.25rem !important;
  }
  .stat-card {
    padding: 0.65rem;
    gap: 0.5rem;
  }
  .stat-icon {
    width: 36px;
    height: 36px;
  }
}

/* Premium Agency Branding Footer Style */
.agency-branding {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: 'Outfit', sans-serif;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 1rem;
  padding: 0.35rem 0.85rem;
  border-radius: 50px;
  background-color: rgba(15, 23, 42, 0.03);
  border: 1px solid rgba(15, 23, 42, 0.05);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  text-decoration: none;
}

.agency-branding:hover {
  color: var(--primary);
  background-color: var(--primary-light);
  border-color: rgba(37, 99, 235, 0.15);
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.08);
}

.agency-branding .powered-by {
  font-family: 'Inter', sans-serif;
  text-transform: none;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--text-muted);
  margin-right: 0.1rem;
}

.agency-branding .brand-text {
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary) 0%, #1d4ed8 50%, #4f46e5 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-block;
}
