/* ===== DARK THEME (Default) ===== */
:root {
  --primary: #d4af37;
  --secondary: #a38221;
  --accent-red: #ce1126;
  --glass-bg: rgba(255, 255, 255, 0.04);
  --glass-border: rgba(212, 175, 55, 0.15);
  --text-main: #ffffff;
  --text-muted: #bdc3c7;
  --success: #2ecc71;
  --danger: #ce1126;
  --body-bg-start: #4a4a4a;
  --body-bg-end: #1a1a1a;
  --sidebar-bg: rgba(255,255,255,0.04);
  --select-bg: rgba(0,0,0,0.5);
  --select-color: #fff;
}

/* ===== LIGHT THEME ===== */
body.theme-light {
  --glass-bg: rgba(255, 255, 255, 0.75);
  --glass-border: rgba(180, 140, 20, 0.25);
  --text-main: #1a1a1a;
  --text-muted: #555;
  --body-bg-start: #e8e0d0;
  --body-bg-end: #f5f0e8;
  --sidebar-bg: rgba(255,255,255,0.8);
  --select-bg: #fff;
  --select-color: #1a1a1a;
}

body.theme-light {
  background: radial-gradient(circle at top left, var(--body-bg-start), var(--body-bg-end)) !important;
  color: var(--text-main) !important;
}

body.theme-light .glass {
  background: var(--glass-bg) !important;
  border-color: var(--glass-border) !important;
  color: var(--text-main) !important;
}

body.theme-light .logo h2 {
  background: linear-gradient(135deg, var(--primary), var(--accent-red));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

body.theme-light .kpi-value { color: var(--primary) !important; }
body.theme-light h1, body.theme-light h2, body.theme-light h3 { color: var(--text-main) !important; }
body.theme-light .nav-btn { color: #555; }
body.theme-light .nav-btn.active { color: var(--primary); }
body.theme-light select { background: var(--select-bg) !important; color: var(--select-color) !important; }
body.theme-light .challenges-panel li { color: var(--text-muted) !important; }
body.theme-light .sidebar { background: var(--sidebar-bg) !important; }


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

body {
  font-family: 'Cairo', sans-serif;
  background: radial-gradient(circle at top left, #4a4a4a, #1a1a1a); /* Luxurious dark/medium grey gradient */
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
}

/* Glassmorphism utility */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
  border-radius: 20px;
}

/* Layout */
.app-container {
  display: flex;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 240px;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  border-right: none;
  border-left: 1px solid var(--glass-border);
  z-index: 10;
  border-radius: 0;
}

.logo h2 {
  font-size: 1.8rem;
  background: linear-gradient(135deg, var(--primary), var(--accent-red));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 800;
  text-align: center;
  margin-bottom: 2rem;
}

nav { display: flex; flex-direction: column; gap: 1rem; }

.nav-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: 'Cairo', sans-serif;
  font-size: 1.1rem;
  text-align: right;
  padding: 1.2rem;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  width: 100%;
  font-weight: 600;
}

.nav-btn:hover {
  background: rgba(212, 175, 55, 0.05); /* Gold hover */
  color: #fff;
  transform: translateX(-5px);
}

.nav-btn.active {
  background: rgba(212, 175, 55, 0.15); /* Gold active bg */
  color: var(--primary);
  border-right: 4px solid var(--accent-red); /* Bahrain Red accent */
}

.sidebar-footer {
  margin-top: auto;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  position: relative;
}

.main-content::before {
  content: "";
  position: absolute;
  top: -20%; left: -10%;
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(0,210,255,0.15) 0%, transparent 70%);
  z-index: -1;
}

.tab-content {
  animation: fadeIn 0.4s ease forwards;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(15px); }
  to { opacity: 1; transform: translateY(0); }
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  margin-bottom: 1.5rem;
}

.dashboard-header h1 {
  font-size: 1.4rem;
  font-weight: 800;
}

.filters select, .compare-select {
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 0.8rem 1.2rem;
  border-radius: 12px;
  font-family: 'Cairo';
  margin-right: 1rem;
  outline: none;
  font-size: 1rem;
  cursor: pointer;
  transition: border-color 0.3s;
}

.filters select:hover, .compare-select:hover {
  border-color: var(--primary);
}

/* KPIs */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  padding: 1.2rem;
  text-align: center;
  transition: transform 0.3s, box-shadow 0.3s;
}

.kpi-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 30px rgba(0, 210, 255, 0.15);
}

.kpi-card h3 {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.kpi-value {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 0.2rem;
}
.kpi-text { font-size: 1.3rem; }

.trend { font-size: 0.85rem; font-weight: 600; }
.trend.positive { color: var(--success); }
.trend.negative { color: var(--danger); }

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
}

.full-width {
  grid-column: 1 / -1;
  margin-top: 1rem;
}

.chart-card {
  padding: 1rem 1.5rem;
}

.chart-card h3 {
  margin-bottom: 1rem;
  font-size: 1.1rem;
  font-weight: 600;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 0.5rem;
}

.chart-wrapper {
  position: relative;
  height: 250px;
  width: 100%;
}

.doughnut-wrapper { height: 250px; }
.bar-h-wrapper { height: 250px; }

.mt-4 { margin-top: 1.5rem; }
.challenges-panel {
  padding: 1.5rem;
}

.challenges-panel h3 {
  font-size: 1.2rem;
  margin-bottom: 0.8rem;
  color: #fff;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 0.4rem;
}

.challenges-panel ul {
  list-style-type: none;
}

.challenges-panel li {
  padding: 0.8rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  position: relative;
  padding-right: 1.5rem;
  line-height: 1.4;
  font-size: 0.95rem;
}
.challenges-panel li::before {
  content: "🔹";
  position: absolute;
  right: 0;
  top: 0.9rem;
  font-size: 0.8rem;
}

/* Upload UI */
.upload-manager-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    height: 60vh;
}

.month-status-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1rem;
    background: rgba(255,255,255,0.03);
    margin-bottom: 0.5rem;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.05);
}
.month-status-item.missing {
    border-color: rgba(255, 23, 68, 0.4);
    background: rgba(255, 23, 68, 0.05);
}
.month-status-item.uploaded {
    border-color: rgba(0, 230, 118, 0.4);
    background: rgba(0, 230, 118, 0.05);
}
.btn-delete {
    background: rgba(255, 23, 68, 0.8);
    color: #fff; border: none; padding: 0.5rem 1rem;
    border-radius: 8px; cursor: pointer; font-family: 'Cairo'; font-weight: bold;
    transition: 0.3s;
}
.btn-delete:hover { background: rgba(255, 23, 68, 1); }

.btn-upload-missing {
    background: var(--primary);
    color: #000; border: none; padding: 0.5rem 1rem;
    border-radius: 8px; cursor: pointer; font-family: 'Cairo'; font-weight: bold;
    transition: 0.3s;
}
.btn-upload-missing:hover { opacity: 0.8; }

.upload-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60vh;
  border: 2px dashed rgba(212, 175, 55, 0.4);
  border-radius: 24px;
  background: rgba(212, 175, 55, 0.02);
  cursor: pointer;
  transition: all 0.3s;
  text-align: center;
}

.upload-container:hover {
  background: rgba(212, 175, 55, 0.05);
  border-color: var(--primary);
  transform: scale(1.02);
}

.upload-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.upload-container h2 {
  font-size: 1.8rem;
  margin-bottom: 0.8rem;
  line-height: 1.4;
}

.upload-container p {
  color: var(--text-muted);
  font-size: 1.1rem;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ===== SETTINGS PANEL ===== */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 0.5rem;
}

.settings-card-wide {
  grid-column: 1 / -1;
}

.settings-card {
  padding: 1.5rem;
  border-radius: 20px;
  transition: transform 0.3s;
}

.settings-card:hover { transform: translateY(-3px); }

.settings-card h3 {
  font-size: 1.1rem;
  color: var(--primary);
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 0.5rem;
}

.settings-option-group {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.settings-lang-btn,
.settings-theme-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--glass-border);
  color: var(--text-muted);
  font-family: 'Cairo', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.7rem 1.4rem;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s;
}

.settings-lang-btn:hover,
.settings-theme-btn:hover {
  border-color: var(--primary);
  color: #fff;
}

.settings-lang-btn.active,
.settings-theme-btn.active {
  background: rgba(212,175,55,0.2);
  border-color: var(--primary);
  color: var(--primary);
}

.settings-fields-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.settings-field label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

.settings-field input {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--glass-border);
  color: var(--text-main);
  font-family: 'Cairo', sans-serif;
  font-size: 0.95rem;
  padding: 0.55rem 0.9rem;
  border-radius: 8px;
  outline: none;
  transition: border-color 0.3s;
}

.settings-field input:focus { border-color: var(--primary); }
.settings-field input::placeholder { color: var(--text-muted); opacity: 0.6; }

.settings-save-btn {
  background: var(--primary);
  color: #000;
  border: none;
  font-family: 'Cairo', sans-serif;
  font-size: 1rem;
  font-weight: 800;
  padding: 0.8rem 2rem;
  border-radius: 12px;
  cursor: pointer;
  transition: 0.3s;
  box-shadow: 0 4px 15px rgba(212,175,55,0.4);
}

.settings-save-btn:hover { opacity: 0.85; transform: translateY(-2px); }

.settings-reset-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--glass-border);
  font-family: 'Cairo', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.8rem 1.5rem;
  border-radius: 12px;
  cursor: pointer;
  transition: 0.3s;
}

.settings-reset-btn:hover {
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.settings-hint {
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-bottom: 1rem;
  opacity: 0.8;
}

/* Suggestion chips */
.suggestions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 5px;
}
.suggestion-chip {
  background: rgba(212,175,55,0.1);
  border: 1px solid rgba(212,175,55,0.25);
  color: var(--primary);
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Cairo', sans-serif;
  user-select: none;
}
.suggestion-chip:hover {
  background: rgba(212,175,55,0.25);
  transform: scale(1.05);
}

/* ===== Location Ranking Panel ===== */
.locations-ranking-grid {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}
.location-rank-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.location-rank-badge {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.rank-1 { background: rgba(255,215,0,0.3); color: #ffd700; border: 1px solid #ffd700; }
.rank-2 { background: rgba(192,192,192,0.2); color: #c0c0c0; border: 1px solid #c0c0c0; }
.rank-3 { background: rgba(205,127,50,0.2); color: #cd7f32; border: 1px solid #cd7f32; }
.rank-other { background: rgba(255,255,255,0.05); color: var(--text-muted); border: 1px solid var(--glass-border); }

.location-rank-name {
  min-width: 130px;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-main);
}
.location-rank-bar-wrap {
  flex: 1;
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  height: 10px;
  overflow: hidden;
}
.location-rank-bar {
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--primary), #a38221);
  transition: width 1s ease;
}
.location-rank-count {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--primary);
  min-width: 55px;
  text-align: left;
}

/* --- 🖨️ PRINT STYLES --- */
@media print {
  /* Default page size - overridden by JS @page injection */
  @page {
    size: A3 landscape;
    margin: 0.8cm;
  }

  /* Hide everything that shouldn't print */
  .sidebar,
  #export-options,
  .btn-print,
  .filters,
  #year-select,
  #month-select,
  .nav-btn,
  .upload-container,
  #upload-tab,
  #compare-tab {
    display: none !important;
  }

  /* Page body */
  html, body {
    background: #1a1a1a !important;
    color: #ffffff !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* App layout for print */
  .app-container {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
    background: #1a1a1a !important;
  }

  .main-content {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
  }

  .main-content::before { display: none !important; }

  /* Dashboard tab */
  #dashboard-tab {
    display: block !important;
    width: 100% !important;
    overflow: visible !important;
    background: #1a1a1a !important;
  }

  /* CRITICAL: Override glass/backdrop-filter with solid backgrounds */
  .glass,
  .kpi-card,
  .chart-card,
  .dashboard-header,
  .challenges-panel {
    background: #23272f !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border: 1px solid rgba(212, 175, 55, 0.35) !important;
    box-shadow: none !important;
  }

  /* Header */
  .dashboard-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 8px 12px !important;
    margin-bottom: 12px !important;
  }
  .dashboard-header h1 {
    color: #ffffff !important;
    font-size: 18pt !important;
  }

  /* KPI Grid: 5 per row to fit landscape */
  .kpi-grid {
    display: grid !important;
    grid-template-columns: repeat(5, 1fr) !important;
    gap: 8px !important;
    margin-bottom: 12px !important;
  }

  .kpi-card {
    padding: 10px !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    text-align: center !important;
  }

  .kpi-card h3 {
    color: #bdc3c7 !important;
    font-size: 8pt !important;
    margin-bottom: 4px !important;
  }

  .kpi-value {
    color: #d4af37 !important;
    font-size: 18pt !important;
    font-weight: 800 !important;
  }
  .kpi-text { font-size: 11pt !important; }

  /* Trends */
  .trend { font-size: 7pt !important; }
  .trend.positive { color: #2ecc71 !important; }
  .trend.negative { color: #e74c3c !important; }
  .trend.neutral { color: #bdc3c7 !important; }

  /* Charts grid */
  .charts-grid {
    display: grid !important;
    grid-template-columns: 2fr 1fr !important;
    gap: 8px !important;
    margin-bottom: 8px !important;
  }

  .chart-card {
    padding: 10px 12px !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .chart-card h3 {
    color: #ffffff !important;
    font-size: 9pt !important;
    margin-bottom: 6px !important;
    border-bottom: 1px solid rgba(212,175,55,0.3) !important;
    padding-bottom: 3px !important;
  }

  .chart-wrapper {
    height: 180px !important;
    position: relative !important;
  }
  .doughnut-wrapper { height: 160px !important; }
  .bar-h-wrapper { height: 160px !important; }

  canvas {
    max-width: 100% !important;
    height: auto !important;
  }

  .full-width {
    grid-column: 1 / -1 !important;
  }

  /* AI Summary & Challenges */
  .challenges-panel {
    padding: 10px 14px !important;
    margin-top: 8px !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .challenges-panel h3 {
    color: #ffffff !important;
    font-size: 10pt !important;
    border-bottom: 1px solid rgba(212,175,55,0.3) !important;
    padding-bottom: 4px !important;
    margin-bottom: 6px !important;
  }

  .challenges-panel li {
    color: #e0e0e0 !important;
    font-size: 8pt !important;
    padding: 3px 16px 3px 0 !important;
    border-bottom: 1px solid rgba(255,255,255,0.05) !important;
  }

h2, h3, h4, p, span, b, strong {
    color: #ffffff !important;
    text-shadow: none !important;
  }

  .mt-4 { margin-top: 8px !important; }
}

/* ========================================================= */
/* 📱 RESPONSIVE DESIGN (Tablet & Mobile)                      */
/* ========================================================= */

/* Tablet (Max 992px) */
@media (max-width: 992px) {
  .charts-grid {
    grid-template-columns: 1fr; /* Stack graphs */
  }
  .chart-card {
    min-height: 350px;
  }
  .full-width {
    grid-column: 1 / -1;
  }
}

/* Mobile (Max 768px) */
@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
    overflow-y: auto;
    height: auto;
  }

  /* Compact Sidebar for Mobile */
  .sidebar {
    width: 100%;
    border-left: none;
    border-bottom: 1px solid var(--glass-border);
    padding: 1rem;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    position: sticky;
    top: 0;
    z-index: 1000;
  }

  .logo { margin-bottom: 0; width: 100%; text-align: center; }
  .logo h2 { margin-bottom: 0.5rem; font-size: 1.4rem; }

  nav {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
    gap: 0.5rem;
  }

  .nav-btn {
    width: auto;
    flex: 1 1 calc(33% - 0.5rem);
    padding: 0.8rem;
    font-size: 0.9rem;
    text-align: center;
    border-right: none;
    border-bottom: 2px solid transparent;
  }

  .nav-btn.active {
    border-bottom: 2px solid var(--accent-red);
    border-right: none;
  }

  .sidebar-footer { width: 100%; margin-top: 0.5rem; }
  #user-badge { flex-direction: column; gap: 0.2rem; }

  /* Main Content Adjustments */
  .main-content {
    overflow-y: visible;
    padding: 1rem 0.5rem;
  }

  .dashboard-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.5rem;
  }

  .filters {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 0.5rem;
  }
  .filters select, .upload-btn, .compare-btn {
    width: 100%;
    margin: 0;
  }

  /* KPIs Adjustments */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .kpi-value { font-size: 1.8rem; }
  .kpi-text { font-size: 0.8rem; }
  .kpi-card { padding: 1rem; }

  /* Login Gates */
  #app-login-gate > div {
    padding: 2rem 1.5rem;
  }
  #settings-login-overlay > div {
    padding: 2rem 1.5rem;
  }
}

/* Small Mobile (< 480px) */
@media (max-width: 480px) {
  .kpi-grid {
    grid-template-columns: 1fr; /* 1 KPI per row on very small screens */
  }
  .nav-btn {
    flex: 1 1 100%;
  }
}


/* --- PDF Export glass class (no longer needed) --- */
