/* =============================================
   EVM Management System - Main Styles
   ============================================= */

:root {
  --primary: #1a3a5c;
  --primary-dark: #0f2440;
  --primary-light: #2a5a8c;
  --accent: #e8b84b;
  --accent-dark: #c99a30;
  --success: #2e7d32;
  --danger: #c62828;
  --warning: #f57f17;
  --info: #0277bd;
  --bg: #f0f4f8;
  --sidebar-width: 260px;
  --card-shadow: 0 2px 12px rgba(0,0,0,0.1);
  --border-radius: 10px;
}

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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: #2d3748;
  min-height: 100vh;
}

a { text-decoration: none; color: inherit; }

/* ─── LOGIN PAGE ─────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
  padding: 20px;
}

.login-card {
  background: white;
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo .logo-icon {
  width: 70px;
  height: 70px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  font-size: 32px;
}

.login-logo h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}

.login-logo p {
  font-size: 13px;
  color: #718096;
  margin-top: 4px;
}

.login-card h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 24px;
  text-align: center;
}

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

.sidebar {
  width: var(--sidebar-width);
  background: var(--primary);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-brand {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-brand .brand-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.sidebar-brand h2 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
  line-height: 1.3;
}

.sidebar-brand p {
  font-size: 11px;
  opacity: 0.7;
  margin-top: 4px;
}

.sidebar-user {
  padding: 16px 20px;
  background: rgba(255,255,255,0.05);
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-user .user-name { font-size: 13px; font-weight: 600; }
.sidebar-user .user-role {
  font-size: 11px;
  opacity: 0.7;
  background: var(--accent);
  color: var(--primary-dark);
  padding: 2px 8px;
  border-radius: 10px;
  display: inline-block;
  margin-top: 4px;
  font-weight: 600;
}

.sidebar-nav { padding: 16px 0; flex: 1; }

.nav-section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  opacity: 0.5;
  padding: 8px 20px 4px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 20px;
  font-size: 14px;
  color: rgba(255,255,255,0.85);
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: rgba(255,255,255,0.1);
  color: white;
  border-left-color: var(--accent);
}

.sidebar-nav a .nav-icon { font-size: 18px; width: 22px; text-align: center; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-footer a {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: rgba(255,255,255,0.7);
  transition: color 0.2s;
}
.sidebar-footer a:hover { color: white; }

/* ─── MAIN CONTENT ───────────────────────── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: white;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--primary);
}

.topbar-actions { display: flex; gap: 12px; align-items: center; }

.page-body { padding: 28px; flex: 1; }

/* ─── FLASH MESSAGES ─────────────────────── */
.flash-messages { margin-bottom: 20px; }

.alert {
  padding: 14px 18px;
  border-radius: var(--border-radius);
  margin-bottom: 12px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
}

.alert-success { background: #e8f5e9; color: #1b5e20; border-left: 4px solid #2e7d32; }
.alert-error { background: #ffebee; color: #7f0000; border-left: 4px solid #c62828; }
.alert-info { background: #e3f2fd; color: #01579b; border-left: 4px solid #0277bd; }

/* ─── CARDS ──────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 18px;
  margin-bottom: 28px;
}

.stat-card {
  background: white;
  border-radius: var(--border-radius);
  padding: 22px 20px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 4px solid var(--primary);
  transition: transform 0.2s;
}

.stat-card:hover { transform: translateY(-2px); }
.stat-card.accent { border-top-color: var(--accent); }
.stat-card.success { border-top-color: var(--success); }
.stat-card.danger { border-top-color: var(--danger); }
.stat-card.info { border-top-color: var(--info); }

.stat-icon { font-size: 28px; }
.stat-value { font-size: 30px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: #718096; text-transform: uppercase; letter-spacing: 0.5px; }

/* ─── CARD ───────────────────────────────── */
.card {
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  margin-bottom: 24px;
}

.card-header {
  padding: 18px 24px;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: white;
}

.card-header h2, .card-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--primary);
}

.card-body { padding: 24px; }

/* ─── TABLES ─────────────────────────────── */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  background: var(--primary);
  color: white;
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}

tbody tr { border-bottom: 1px solid #e2e8f0; }
tbody tr:hover { background: #f7fafc; }
tbody tr:last-child { border-bottom: none; }

tbody td { padding: 12px 14px; vertical-align: middle; }

/* ─── BADGES ─────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-success { background: #e8f5e9; color: #2e7d32; }
.badge-danger { background: #ffebee; color: #c62828; }
.badge-warning { background: #fff3e0; color: #e65100; }
.badge-info { background: #e3f2fd; color: #01579b; }
.badge-primary { background: #e8edf5; color: var(--primary); }
.badge-secondary { background: #f1f3f5; color: #555; }

/* ─── FORMS ──────────────────────────────── */
.form-group { margin-bottom: 20px; }

.form-label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 500;
  color: #4a5568;
}

.form-label .required { color: var(--danger); margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid #cbd5e0;
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: white;
  color: #2d3748;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(42, 90, 140, 0.15);
}

.form-control:disabled, .form-control[readonly] {
  background: #f7fafc;
  color: #718096;
  cursor: not-allowed;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

/* ─── BUTTONS ────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-accent { background: var(--accent); color: var(--primary-dark); }
.btn-accent:hover { background: var(--accent-dark); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #1b5e20; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #7f0000; }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--primary);
  color: var(--primary);
}
.btn-outline:hover { background: var(--primary); color: white; }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon { padding: 6px; border-radius: 6px; }

/* ─── SEARCH/FILTER BAR ──────────────────── */
.filter-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 20px;
}

.filter-bar .form-control { max-width: 200px; }

.search-input { max-width: 280px !important; }

/* ─── PAGINATION ─────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  margin-top: 20px;
}

.pagination a, .pagination span {
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 13px;
  border: 1.5px solid #e2e8f0;
  background: white;
}

.pagination a:hover { background: var(--primary); color: white; border-color: var(--primary); }
.pagination .active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination .disabled { opacity: 0.4; pointer-events: none; }

/* ─── EMPTY STATE ────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: #718096;
}

.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-state h3 { font-size: 16px; margin-bottom: 8px; color: #4a5568; }
.empty-state p { font-size: 14px; }

/* ─── MODAL ──────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: white;
  border-radius: 16px;
  padding: 32px;
  width: 90%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.modal-header h3 { font-size: 18px; color: var(--primary); }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: #718096; }
.modal-close:hover { color: var(--danger); }

/* ─── UTILITIES ──────────────────────────── */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: #718096; font-size: 13px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.fw-bold { font-weight: 600; }
.d-none { display: none; }

/* Dzongkhag table clickable rows */
.clickable-row { cursor: pointer; }
.clickable-row:hover td { background: #eef2f8; }

/* Report buttons */
.report-options { display: flex; gap: 12px; flex-wrap: wrap; }
.report-card {
  background: white;
  border: 2px solid #e2e8f0;
  border-radius: var(--border-radius);
  padding: 20px;
  width: 220px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}
.report-card:hover { border-color: var(--primary); background: #f0f4f8; }
.report-card .report-icon { font-size: 32px; margin-bottom: 10px; }
.report-card h4 { font-size: 14px; color: var(--primary); font-weight: 600; }


/* ==========================================================================
   ─── RESPONSIVE MEDIA QUERIES (APPENDED AT THE BOTTOM) ─────────────────────
   ========================================================================== */

/* 💻 TABLETS & SMALL LAPTOPS (Under 1024px) */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 220px; /* Shrink sidebar slightly on smaller desktop screens */
  }
  .page-body {
    padding: 20px; /* Bring the spacing down to give more data breathing room */
  }
  .topbar {
    padding: 16px 20px;
  }
}

/* 📱 MOBILE PHONES & TABLETS (Under 768px) */
@media (max-width: 768px) {
  /* 1. Reset the layout structure */
  .app-layout {
    flex-direction: column; /* Stack top-to-bottom */
  }

  /* 2. Reposition the Sidebar */
  .sidebar {
    position: relative; /* Unlock from screen edge */
    width: 100%;
    height: auto;
    bottom: auto;
  }

  .sidebar-brand {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .sidebar-brand .brand-icon {
    margin-bottom: 0;
    font-size: 24px;
  }

  /* Make nav items sit side-by-side or stack neatly */
  .sidebar-nav {
    display: flex;
    flex-wrap: wrap;
    padding: 8px;
  }

  .nav-section-title {
    width: 100%; /* Keep titles on their own row */
    padding: 8px 12px 4px;
  }

  .sidebar-nav a {
    padding: 8px 12px;
    font-size: 13px;
    border-left: none;
    border-bottom: 2px solid transparent; /* Move the accent indicator to the bottom */
    border-radius: 4px;
  }

  .sidebar-nav a:hover,
  .sidebar-nav a.active {
    border-left-color: transparent;
    border-bottom-color: var(--accent);
  }

  /* 3. Adjust main workspace */
  .main-content {
    margin-left: 0; /* Remove space previously reserved for the side panel */
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  /* 4. Dashboard Stats adjustments */
  .stat-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); /* Pack stats closer */
    gap: 14px;
  }
  
  .stat-card {
    padding: 16px;
  }

  .stat-value {
    font-size: 24px;
  }

  /* 5. Utility Layout Elements */
  .filter-bar {
    flex-direction: column;
    align-items: stretch; /* Stretch input fields full width */
    gap: 10px;
  }

  .filter-bar .form-control, 
  .search-input {
    max-width: 100% !important; /* Overwrite fixed inline widths */
    width: 100%;
  }

  .report-options {
    justify-content: center;
  }

  .report-card {
    width: 100%; /* Stretch out report option cards */