/* ========================================================================
   0. THEME TOKENS (COLORS, RADIUS, SHADOWS)
   ------------------------------------------------------------------------ */

:root {
  /* Brand & Accent - Vibrant Indigo/Blue */
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: rgba(99, 102, 241, 0.1);
  --on-primary: #ffffff;

  /* Status Colors (Modern & Accessible) */
  --added: #10b981;
  /* Emerald-500 */
  --removed: #ef4444;
  /* Red-500 */
  --changed: #f59e0b;
  /* Amber-500 */

  --added-bg: rgba(16, 185, 129, 0.1);
  --removed-bg: rgba(239, 68, 68, 0.1);
  --changed-bg: rgba(245, 158, 11, 0.1);

  --added-border: rgba(16, 185, 129, 0.3);
  --removed-border: rgba(239, 68, 68, 0.3);
  --changed-border: rgba(245, 158, 11, 0.3);

  /* Light Theme Surfaces (Default) */
  --bg-body: #f3f4f6;
  /* Gray-100 */
  --bg-surface: #ffffff;
  /* White */
  --bg-surface-hover: #f9fafb;
  /* Gray-50 */
  --bg-panel: #ffffff;
  --bg-header: rgba(255, 255, 255, 0.85);

  /* Text Colors */
  --text-main: #111827;
  /* Gray-900 */
  --text-secondary: #4b5563;
  /* Gray-600 */
  --text-tertiary: #9ca3af;
  /* Gray-400 */
  --text-inverse: #ffffff;

  /* Borders & Dividers */
  --border-light: #e5e7eb;
  /* Gray-200 */
  --border-medium: #d1d5db;
  /* Gray-300 */

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

  /* Layout */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --header-height: 60px;
}

[data-theme="dark"] {
  /* Dark Theme Surfaces */
  --bg-body: #0f172a;
  /* Slate-900 */
  --bg-surface: #1e293b;
  /* Slate-800 */
  --bg-surface-hover: #334155;
  /* Slate-700 */
  --bg-panel: #1e293b;
  --bg-header: rgba(30, 41, 59, 0.85);

  /* Text Colors */
  --text-main: #f8fafc;
  /* Slate-50 */
  --text-secondary: #cbd5e1;
  /* Slate-300 */
  --text-tertiary: #94a3b8;
  /* Slate-400 */

  /* Borders */
  --border-light: #334155;
  /* Slate-700 */
  --border-medium: #475569;
  /* Slate-600 */

  /* Status Adjustments for Dark Mode */
  --added-bg: rgba(16, 185, 129, 0.15);
  --removed-bg: rgba(239, 68, 68, 0.15);
  --changed-bg: rgba(245, 158, 11, 0.15);
}

/* ========================================================================
   1. GLOBAL RESET & TYPOGRAPHY
   ======================================================================== */

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text-main);
  background: var(--bg-body);
  transition: background-color 0.2s ease, color 0.2s ease;
  overflow: hidden;
  /* App-like feel */
}

/* ========================================================================
   2. LAYOUT & GRID
   ======================================================================== */

#app-container {
  display: grid;
  grid-template-columns: 280px 1fr;
  /* Fixed Sidebar, Flexible Main */
  grid-template-rows: var(--header-height) 1fr;
  grid-template-areas:
    "header header"
    "sidebar main";
  height: 100vh;
  width: 100vw;
}

/* Header */
header {
  grid-area: header;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-light);
  backdrop-filter: blur(12px);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 1100;
  box-shadow: var(--shadow-sm);
}

/* Sidebar */
#sidebar {
  grid-area: sidebar;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 40;
}

/* Main Content (Table + Map) */
#main-content {
  grid-area: main;
  display: flex;
  flex-direction: column;
  /* Or grid if we split top/bottom or left/right */
  overflow: hidden;
  position: relative;
  background: var(--bg-body);
}

/* Drag Handles (Splitters) */
.gutter {
  background: var(--border-light);
  transition: background 0.2s;
  z-index: 100;
}

.gutter:hover,
.gutter:active {
  background: var(--primary);
}

.gutter.gutter-horizontal {
  cursor: col-resize;
}

.gutter.gutter-vertical {
  cursor: row-resize;
}

/* ========================================================================
   3. HELPER COMPONENTS (Buttons, Inputs, etc.)
   ======================================================================== */

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid var(--border-medium);
  background: var(--bg-surface);
  color: var(--text-main);
  transition: all 0.15s ease;
  gap: 6px;
}

button:hover {
  background: var(--bg-surface-hover);
  border-color: var(--text-tertiary);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button.primary {
  background: var(--primary);
  color: var(--on-primary);
  border-color: transparent;
  box-shadow: 0 2px 4px rgba(99, 102, 241, 0.3);
}

button.primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 6px rgba(99, 102, 241, 0.4);
}

button.icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1;
}

button.icon-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--primary);
}

/* Inputs & Selects */
input[type="text"],
input[type="number"],
select {
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-medium);
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s box-shadow 0.15s;
}

input[type="text"]:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* ========================================================================
   4. HEADER ELEMENTS
   ======================================================================== */

.app-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-brand img {
  height: 48px;
  width: 48px;
  border-radius: 6px;
}

.app-brand h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: var(--text-main);
}

.app-brand .tag {
  font-size: 10px;
  background: var(--primary-light);
  color: var(--primary);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

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

/* DROPDOWN MENUS */
.menu {
  position: relative;
  display: inline-block;
}

.menu-content {
  display: none;
  position: absolute;
  background-color: var(--bg-surface);
  min-width: 160px;
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  z-index: 3000;
  top: 100%;
  padding: 6px 0;
  margin-top: 6px;
  /* Right align default */
  right: 0;
}

.menu-content::before {
  content: '';
  position: absolute;
  top: -10px;
  left: 0;
  width: 100%;
  height: 10px;
  background-color: transparent;
}

.menu.open .menu-content {
  display: block;
}

.menu .btn {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-medium);
  color: var(--text-main);
  transition: border-color 0.15s box-shadow 0.15s;
}

/* Remove button hover transform/styles */
.menu .btn:hover {
  transform: none;
  background-color: var(--bg-surface);
  border-color: var(--border-medium);
}

/* Match select focus state when open */
.menu.open .btn {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.menu-item {
  width: 100%;
  text-align: left;
  padding: 8px 16px;
  border: none;
  background: none;
  font-size: 13px;
  color: var(--text-main);
  border-radius: 0;
  display: block;
}

.menu-item:hover {
  background-color: var(--bg-surface-hover);
  transform: none;
  /* Override btn transform */
}

hr {
  border: 0;
  border-top: 1px solid var(--border-light);
  margin: 4px 0;
}


/* ========================================================================
   5. SIDEBAR (SECTIONS)
   ======================================================================== */

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
  background: rgba(0, 0, 0, 0.02);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

/* Section Grouping */
.sec-group-header {
  user-select: none;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-surface-hover);
  margin-bottom: 4px;
}

.sec-group-content {
  margin-bottom: 12px;
}

/* Section Items */
.sec-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  margin-bottom: 4px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
  border: 1px solid transparent;
}

.sec-item:hover {
  background: var(--bg-surface-hover);
  color: var(--text-main);
}

.sec-item.active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: rgba(99, 102, 241, 0.2);
  font-weight: 600;
}

.sec-counts {
  font-size: 11px;
  opacity: 0.7;
  display: flex;
  gap: 6px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.dot.added {
  background: var(--added);
}

.dot.removed {
  background: var(--removed);
}

.dot.changed {
  background: var(--changed);
}

/* ========================================================================
   6. MAIN PANEL ELEMENTS (FILTER BAR, TABLE, MAP)
   ======================================================================== */

.toolbar {
  padding: 12px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 16px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  font-weight: 500;
}

.checkbox-label input {
  accent-color: var(--primary);
}

/* Table View */
#table-container {
  flex: 1;
  overflow: auto;
  background: var(--bg-surface);
  position: relative;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

table.data-table th {
  background: var(--bg-body);
  color: var(--text-secondary);
  font-weight: 600;
  text-align: left;
  padding: 10px 12px;
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 2px solid var(--border-light);
}

table.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-main);
}

table.data-table tr:hover td {
  background: var(--bg-surface-hover);
}

table.data-table tr.selected td {
  background: var(--primary-light);
}

/* Status Badges */
.badge {
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.badge.added {
  background: var(--added-bg);
  color: var(--added);
  border: 1px solid var(--added-border);
}

.badge.removed {
  background: var(--removed-bg);
  color: var(--removed);
  border: 1px solid var(--removed-border);
}

.badge.changed {
  background: var(--changed-bg);
  color: var(--changed);
  border: 1px solid var(--changed-border);
}

/* Map */
#map-container {
  flex: 1;
  position: relative;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
  background: #e5e7eb;
  /* Fallback */
}

/* Floating Map Legend */
.map-legend {
  position: absolute;
  bottom: 20px;
  left: 20px;
  background: var(--bg-surface);
  padding: 12px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 1000;
  font-size: 12px;
  border: 1px solid var(--border-light);
}

/* ========================================================================
   7. MODALS
   ======================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* Specific override for the Details modal to give it more room */
#modal {
  width: 95vw;
  max-width: 1200px;
}

.modal-content {
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 90vw;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  transform: scale(0.95);
  transition: transform 0.2s;
  border: 1px solid var(--border-light);
}

.modal-backdrop.open .modal-content {
  transform: scale(1);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  font-size: 18px;
  margin: 0;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background: var(--bg-surface-hover);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ========================================================================
   UTILITIES
   ======================================================================== */
.hidden {
  display: none !important;
}

.flex {
  display: flex;
}

.flex-col {
  display: flex;
  flex-direction: column;
}

.flex-1 {
  flex: 1;
}

.p-2 {
  padding: 0.5rem;
}

.gap-2 {
  gap: 0.5rem;
}