/* ==========================================================================
   AZS MONITORING DASHBOARD - STYLESHEET
   Aesthetics: Dark Theme, Glassmorphism, Modern Typography & Vibrant Accents
   ========================================================================== */

:root {
  --bg-dark: #0f172a;
  --bg-card: rgba(30, 41, 59, 0.7);
  --bg-card-hover: rgba(30, 41, 59, 0.9);
  --border-color: rgba(255, 255, 255, 0.1);
  --border-color-glow: rgba(59, 130, 246, 0.3);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  /* Brand Theme Colors */
  --gazprom-color: #0072ce;
  --rosneft-color: #facc15;
  --teboil-color: #ef4444;
  --ltk-color: #10b981;
  --primary-blue: #3b82f6;
  --accent-purple: #8b5cf6;
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.15);
  
  --font-family: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: auto !important;
  -webkit-user-select: auto !important;
  -moz-user-select: auto !important;
}

body.dark-theme {
  background-color: var(--bg-dark);
  background-image: 
    radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.08) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.08) 0px, transparent 50%);
  color: var(--text-main);
  font-family: var(--font-family);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

th[data-sort], th[data-sort-modal] {
  cursor: pointer;
}

th[data-sort]:hover, th[data-sort-modal]:hover {
  background: var(--bg-card);
}

/* Glassmorphism Common Style */
.glass {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

/* Header */
.app-header {
  height: 65px;
  padding: 0 24px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 1000;
}

.header-left .logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-image {
  width: 42px;
  height: 42px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.4));
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.logo-text .title {
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, #60a5fa, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-text .subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Nav Tabs */
.nav-tabs {
  display: flex;
  gap: 6px;
  background: rgba(30, 41, 59, 0.6);
  padding: 4px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}

.nav-tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-weight: 500;
  font-size: 0.88rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.nav-tab:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.nav-tab.active {
  background: var(--primary-blue);
  color: #ffffff;
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.4);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.live-status {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.04);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
}

.status-dot {
  width: 8px;
  height: 8px;
  background-color: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 8px #10b981;
}

.btn {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

.btn-outline:hover {
  border-color: var(--primary-blue);
  color: var(--text-main);
  background: rgba(59, 130, 246, 0.1);
}

.btn-primary {
  background: var(--primary-blue);
  color: #fff;
}

.btn-primary:hover {
  background: #2563eb;
  box-shadow: 0 0 12px rgba(37, 99, 235, 0.4);
}

/* Filter Bar */
.filter-bar {
  padding: 14px 24px;
  background: rgba(15, 23, 42, 0.6);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 170px;
}

.filter-group.search-group {
  flex: 1.5;
  min-width: 220px;
}

.filter-group label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 5px;
}

.filter-control {
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: 0.85rem;
  outline: none;
  transition: all 0.2s ease;
}

.filter-control:focus {
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Custom Dropdown (Dates) */
.custom-dropdown {
  position: relative;
  width: 100%;
}

.dropdown-toggle {
  width: 100%;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 35px;
}

.dropdown-toggle span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 85%;
  text-align: left;
}

.dropdown-toggle:hover {
  border-color: var(--primary-blue);
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  width: 250px;
  background: #0f172a;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  z-index: 1000;
  display: none;
  flex-direction: column;
}

.custom-dropdown.open .dropdown-menu {
  display: flex;
}

.dropdown-content {
  max-height: 300px;
  overflow-y: auto;
  padding: 10px;
}

.dropdown-content::-webkit-scrollbar {
  width: 6px;
}

.dropdown-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.dropdown-group-header {
  font-weight: 600;
  color: var(--primary-blue);
  margin-top: 10px;
  margin-bottom: 5px;
  padding-bottom: 2px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  font-size: 0.8rem;
  cursor: pointer;
  transition: color 0.2s;
}

.dropdown-group-header:hover {
  color: #60a5fa;
}

.dropdown-group-header:first-child {
  margin-top: 0;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-main);
  transition: background 0.2s;
}

.dropdown-item:hover {
  background: rgba(255,255,255,0.05);
}

.dropdown-item input[type="checkbox"] {
  accent-color: var(--primary-blue);
  cursor: pointer;
}

.dropdown-footer {
  padding: 10px;
  background: #1e293b;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-bottom-left-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
}

.dropdown-footer .btn {
  padding: 5px 10px;
  font-size: 0.75rem;
}

/* KPI Banner */
.kpi-banner {
  padding: 16px 24px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
}

.kpi-card {
  padding: 20px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  cursor: pointer;
}

.kpi-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
  background: rgba(30, 41, 59, 0.9);
}

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

.kpi-icon.blue { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.kpi-icon.yellow { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.kpi-icon.green { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.kpi-icon.purple { background: rgba(139, 92, 246, 0.15); color: #c084fc; }
.kpi-icon.red { background: rgba(239, 68, 68, 0.15); color: #f87171; }

.kpi-info {
  display: flex;
  flex-direction: column;
}

.kpi-title {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.kpi-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  margin: 2px 0;
}

.kpi-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.text-danger { color: #f87171 !important; }

/* Main Content */
.main-content {
  flex: 1;
  padding: 0 24px 24px 24px;
  display: flex;
  flex-direction: column;
}

.tab-pane {
  display: none;
  flex: 1;

}

.tab-pane.active {
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.3s ease-in-out;
}

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

/* Map Tab */
.map-wrapper {
  height: calc(100vh - 280px);
  min-height: 520px;
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-md);
}

/* Map Legend Overlay */
.map-legend {
  position: absolute;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(0, 0, 0, 0.15);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.82rem;
  color: #0f172a;
}

.legend-title {
  font-weight: 700;
  color: #334155;
  margin-bottom: 2px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.brand-badge {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.brand-badge.gazprom { background: var(--gazprom-color); }
.brand-badge.rosneft { background: var(--rosneft-color); }
.brand-badge.teboil { background: var(--teboil-color); }
.brand-badge.ltk { background: var(--ltk-color); }

/* Hide Leaflet Attribution & Flags */
.leaflet-control-attribution {
  display: none !important;
}

/* Modal Styles */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(4px);
  z-index: 10000;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
  animation: fadeIn 0.2s ease;
}

.modal-content {
  width: 100%;
  max-width: 1100px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #f8fafc;
}

.modal-close {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 4px;
  transition: color 0.2s;
}

.modal-close:hover {
  color: #f8fafc;
}

.modal-body {
  padding: 0 20px 20px 20px;
  overflow-y: auto;
  max-height: calc(90vh - 140px);
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(15, 23, 42, 0.3);
}

#kpi-modal-count {
  color: #94a3b8;
  font-size: 0.875rem;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

/* Custom Leaflet Pins */
.custom-map-pin {
  background: transparent !important;
  border: none !important;
}

/* Custom Leaflet Popup - Dark Glass Theme */
.leaflet-popup-content-wrapper {
  background: #1e293b !important;
  color: #f8fafc !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5) !important;
  font-family: var(--font-family) !important;
  padding: 0 !important;
}

.leaflet-popup-tip {
  background: #1e293b !important;
}

.azs-popup {
  padding: 16px 18px;
  min-width: 290px;
  max-width: 360px;
}

.azs-popup-header {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 4px;
  color: #60a5fa;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.azs-popup-brand {
  display: inline-block;
  padding: 4px 10px;
  margin-left: -10px;
  border-radius: 8px;
  font-size: 1.05rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.azs-popup-brand.gazprom { background: rgba(0, 114, 206, 0.25); color: #60a5fa; border: 1px solid rgba(0, 114, 206, 0.4); }
.azs-popup-brand.rosneft { background: rgba(250, 204, 21, 0.25); color: #facc15; border: 1px solid rgba(250, 204, 21, 0.4); }
.azs-popup-brand.teboil { background: rgba(239, 68, 68, 0.25); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.4); }
.azs-popup-brand.ltk { background: rgba(16, 185, 129, 0.25); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.4); }

.azs-popup-info {
  font-size: 0.82rem;
  line-height: 1.5;
  color: #cbd5e1;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 8px;
}

.azs-popup-info strong {
  color: #f8fafc;
}

.azs-popup-date-badge {
  font-size: 0.75rem;
  color: #94a3b8;
  background: rgba(255, 255, 255, 0.05);
  padding: 4px 8px;
  border-radius: 6px;
  margin-top: 8px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.azs-popup-fuel-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.azs-popup-fuel-card {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 8px 10px;
}

.azs-popup-fuel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 4px;
}

.azs-popup-fuel-badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
}

.azs-popup-fuel-metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px 10px;
  font-size: 0.76rem;
  color: #94a3b8;
}

.azs-popup-fuel-metrics span {
  color: #f8fafc;
  font-weight: 600;
}

.azs-popup-no-data {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 10px 12px;
  border-radius: 8px;
  margin-top: 10px;
  font-size: 0.82rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}


/* Charts Layout */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.charts-grid .span-2 {
  grid-column: span 2;
}

.chart-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
}

.chart-header {
  margin-bottom: 16px;
}

.chart-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chart-header h3 i {
  color: var(--primary-blue);
}

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

/* Inventory Layout */
.inventory-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.inventory-grid .span-2 {
  grid-column: span 2;
}

.risk-table-wrapper {
  max-height: 300px;
  overflow-y: auto;

}

/* Data Table */
.table-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.table-title {
  font-weight: 600;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.table-count-badge {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.78rem;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

/* Upload Tab */
.upload-card {
  padding: 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 400px;
}

.upload-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: 2px dashed rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-md);
  padding: 60px 20px;
  background: rgba(15, 23, 42, 0.4);
  transition: all 0.3s ease;
}

.upload-container:hover {
  border-color: var(--primary-blue);
  background: rgba(15, 23, 42, 0.6);
}

.upload-icon {
  font-size: 4rem;
  color: var(--primary-blue);
  margin-bottom: 20px;
  opacity: 0.8;
}

.upload-status {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--primary-blue);
  font-weight: 600;
}

.spinner {
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  border-top: 3px solid var(--primary-blue);
  width: 20px;
  height: 20px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
}

.data-table th,
.data-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.data-table thead {
  position: sticky;
  top: 0;
  z-index: 100;
}

.data-table th {
  background: rgba(15, 23, 42, 1);
  color: #94a3b8;
  font-weight: 500;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  position: sticky;
  top: -1px; /* Slight offset for perfect seal */
  z-index: 100;
  cursor: pointer;
  user-select: none;
  white-space: normal; /* Allowed to wrap */
  word-wrap: break-word;
}

.data-table th:hover {
  color: var(--text-main);
  background: rgba(30, 41, 59, 1);
}

.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  white-space: normal; /* Allowed to wrap */
  word-wrap: break-word;
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.table-pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.5);
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}


/* ============================================================
   RESPONSIVE — TABLET (≤1024px) landscape & portrait
   ============================================================ */
@media (max-width: 1024px) {
  .charts-grid,
  .inventory-grid {
    grid-template-columns: 1fr;
  }
  .charts-grid .span-2,
  .inventory-grid .span-2 {
    grid-column: span 1;
  }

  /* Header: stack nav below logo */
  .app-header {
    height: auto;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 1000;
  }

  body.dark-theme {
    padding-top: 0 !important;
  }

  .header-left {
    flex-shrink: 1;
  }

  .nav-tabs {
    width: 100%;
    order: 3;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    justify-content: flex-start;
    padding: 4px 2px;
  }
  .nav-tabs::-webkit-scrollbar { display: none; }

  .nav-tab {
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 0.8rem;
    padding: 7px 12px;
    gap: 6px;
  }

  .header-right {
    order: 2;
    gap: 8px;
  }

  .live-status { font-size: 0.75rem; padding: 5px 10px; }

  /* Filter bar wraps */
  .filter-bar {
    padding: 10px 16px;
    gap: 10px;
  }
  .filter-group {
    min-width: 140px;
  }

  /* KPI: 2 per row on tablet */
  .kpi-banner {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 12px 16px;
  }

  /* Main content padding */
  .main-content {
    padding: 0 16px 16px;
  }

  /* Map height */
  .map-wrapper {
    height: calc(100vh - 320px);
    min-height: 400px;
  }

  /* Table: compact */
  .table-card {
    padding: 14px;
  }

  /* Modal: full-width on tablet */
  .modal-content {
    max-width: 96vw;
  }

  /* Charts body height */
  .chart-body {
    height: 260px;
  }
}

/* ============================================================
   RESPONSIVE — MOBILE (≤640px) portrait
   ============================================================ */
@media (max-width: 640px) {
  /* Logo: hide subtitle */
  .logo-text .subtitle { display: none; }
  .logo-icon { font-size: 1.3rem; }
  .logo-text .title { font-size: 1rem; }

  /* Header compact */
  .app-header {
    padding: 8px 12px;
    gap: 8px;
  }

  /* Nav: icon only on very small, scroll */
  .nav-tab i { font-size: 0.95rem; }
  .nav-tab {
    padding: 7px 10px;
    font-size: 0;        /* hide text */
    gap: 0;
  }
  .nav-tab i { font-size: 1.05rem; }

  /* Filters: 2-column grid */
  .filter-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 8px 12px;
    gap: 8px;
  }
  .filter-group {
    min-width: 0;
    width: 100%;
  }
  /* Reset button full-width */
  .filter-group:last-child {
    grid-column: span 2;
  }

  /* KPI: 1 column */
  .kpi-banner {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px 12px;
  }

  .kpi-card {
    padding: 12px;
    gap: 10px;
  }
  .kpi-icon {
    width: 36px;
    height: 36px;
    font-size: 1rem;
    flex-shrink: 0;
  }
  .kpi-value { font-size: 1rem; }
  .kpi-title { font-size: 0.68rem; }
  .kpi-sub { font-size: 0.65rem; }

  /* Main content padding */
  .main-content {
    padding: 0 10px 10px;
  }

  /* Charts */
  .chart-body { height: 220px; }
  .chart-card { padding: 14px; }

  /* Map */
  .map-wrapper {
    height: calc(100svh - 280px);
    min-height: 300px;
  }
  .map-legend {
    bottom: 10px;
    right: 8px;
    padding: 8px 10px;
    font-size: 0.72rem;
    gap: 5px;
  }

  /* Modal */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-content {
    max-width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
  }
  .modal-header { padding: 14px 16px; }
  .modal-header h3 { font-size: 1rem; }
  .modal-body { padding: 0 12px 12px; }
  .modal-footer { padding: 12px 16px; flex-wrap: wrap; gap: 8px; }

  /* Table */
  .table-card { padding: 10px; gap: 10px; }
  .table-toolbar { flex-wrap: wrap; gap: 8px; }
  .table-title { font-size: 0.9rem; }
  .data-table { font-size: 0.76rem; }
  .data-table th, .data-table td { padding: 6px 7px; }

  /* Dropdown Mobile Fix */
  .custom-dropdown {
    position: relative;
  }
  .dropdown-menu {
    width: min(290px, calc(100vw - 32px)) !important;
    max-width: calc(100vw - 32px) !important;
    z-index: 2500 !important;
  }
  .filter-group:nth-child(odd) .dropdown-menu {
    left: 0 !important;
    right: auto !important;
  }
  .filter-group:nth-child(even) .dropdown-menu {
    left: auto !important;
    right: 0 !important;
  }
  .dropdown-footer {
    padding: 8px 10px;
    gap: 8px;
    justify-content: space-between;
  }
  .dropdown-footer .btn {
    flex: 1;
    text-align: center;
    padding: 6px 8px;
    font-size: 0.8rem;
  }

  /* Upload */
  .upload-card { padding: 20px; }
  .upload-container { padding: 30px 16px; }
  .upload-icon { font-size: 3rem; }

  /* Pagination */
  .table-pagination { justify-content: center; flex-wrap: wrap; gap: 8px; }
}

/* ============================================================
   RESPONSIVE — MOBILE LANDSCAPE (≤900px, short height)
   ============================================================ */
@media (max-height: 500px) and (orientation: landscape) {
  .app-header { height: auto; padding: 6px 12px; flex-wrap: wrap; }
  .nav-tabs { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }

  .kpi-banner {
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    padding: 8px 12px;
  }
  .kpi-card { padding: 8px 10px; gap: 8px; }
  .kpi-icon { width: 30px; height: 30px; font-size: 0.9rem; }
  .kpi-value { font-size: 0.9rem; }

  .map-wrapper {
    height: calc(100svh - 180px);
    min-height: 200px;
  }

  .chart-body { height: 180px; }

  .filter-bar {
    gap: 6px;
    padding: 6px 12px;
  }
  .filter-group { min-width: 120px; }
}

/* ============================================================
   TOUCH IMPROVEMENTS
   ============================================================ */
@media (pointer: coarse) {
  /* Bigger tap targets */
  .nav-tab { min-height: 44px; }
  .btn { min-height: 40px; }
  .dropdown-item { min-height: 40px; padding: 8px 10px; }
  .dropdown-toggle { min-height: 42px; }
  .dropdown-group-header { min-height: 40px; display: flex; align-items: center; }
  .data-table td, .data-table th { padding: 10px 8px; }
  .modal-close { padding: 10px; }
}
