/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* === Theme: Light (A - Clean Emerald) === */
:root, [data-theme="light"] {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --accent: #059669;
  --accent-light: rgba(5, 150, 105, 0.1);
  --border: #e5e7eb;
  --row-alt: #f9fafb;
  --green: #10b981;
  --orange: #f59e0b;
  --red: #ef4444;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);

  --header-bg: #fff;
  --header-border: #10b981;
  --header-shadow: 0 2px 4px rgba(0,0,0,0.06);
  --logo-wild: #059669;
  --logo-dot: #059669;
  --logo-flights: #6b7280;
  --updated-color: #6b7280;
  --tab-bg: #fff;
  --pill-hover: #059669;
  --pill-active-bg: #059669;
  --pill-active-text: #fff;
  --book-bg: #10b981;
  --book-text: #fff;
  --book-hover: #059669;
  --marker-text: var(--text);
  --marker-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff;
  --popup-code: #065f46;
  --chart-axis: #e5e7eb;
  --chart-label: #6b7280;
  --chart-line: #059669;
  --chart-fill: rgba(5, 150, 105, 0.08);
  --chart-dot: #059669;
  --route-color: #059669;
}

/* === Theme: Dark (B - Dark Adventure) === */
[data-theme="dark"] {
  --bg: #022c22;
  --surface: #0a3d2e;
  --text: #e2e8f0;
  --text-muted: #a7f3d0;
  --accent: #34d399;
  --accent-light: rgba(52, 211, 153, 0.15);
  --border: #065f46;
  --row-alt: #0d4a38;
  --green: #34d399;
  --orange: #fbbf24;
  --red: #f87171;
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);

  --header-bg: linear-gradient(135deg, #064e3b, #065f46);
  --header-border: #10b981;
  --header-shadow: 0 2px 8px rgba(0,0,0,0.3);
  --logo-wild: #fff;
  --logo-dot: #34d399;
  --logo-flights: #a7f3d0;
  --updated-color: #6ee7b7;
  --tab-bg: #064e3b;
  --pill-hover: #34d399;
  --pill-active-bg: #10b981;
  --pill-active-text: #fff;
  --book-bg: #34d399;
  --book-text: #022c22;
  --book-hover: #6ee7b7;
  --marker-text: #fff;
  --marker-shadow: 0 0 4px rgba(0,0,0,0.8), 0 0 2px rgba(0,0,0,0.6);
  --popup-code: #065f46;
  --chart-axis: #065f46;
  --chart-label: #a7f3d0;
  --chart-line: #34d399;
  --chart-fill: rgba(52, 211, 153, 0.12);
  --chart-dot: #34d399;
  --route-color: #34d399;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

/* === Header === */
header {
  background: var(--header-bg);
  border-bottom: 2px solid var(--header-border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--header-shadow);
  z-index: 100;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", "JetBrains Mono", "Consolas", monospace;
}

.logo-wild { font-weight: 700; color: var(--logo-wild); }
.logo-dot { font-weight: 700; color: var(--logo-dot); }
.logo-flights { font-weight: 400; color: var(--logo-flights); }

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

.updated-at {
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.7;
}

/* === Theme Toggle === */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 8px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: var(--text);
  transition: border-color 0.15s;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

/* === Mobile Tabs === */
.mobile-tabs {
  display: none;
  background: var(--tab-bg);
  border-bottom: 1px solid var(--border);
  padding: 0;
}

.mobile-tabs .tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.mobile-tabs .tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* === Main Layout === */
main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.panel {
  overflow: auto;
}

.map-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

#map {
  width: 100%;
  flex: 1;
  min-height: 300px;
}

.map-panel .trend-container {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  border-radius: 0;
}

.marker-label {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
}

.marker-label span {
  display: block;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--marker-text);
  line-height: 1.1;
  text-shadow: var(--marker-shadow);
  pointer-events: none;
}

.detail-panel {
  flex: 1;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg);
  border-left: 1px solid var(--border);
  overflow: hidden;
  min-height: 0;
}

/* === Controls === */
.controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.controls label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

#origin-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  max-width: 240px;
}

.controls #filter-dest {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
}

.controls #filter-dest:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.controls #filter-dest::placeholder {
  color: var(--text-muted);
}

#origin-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* === Trend === */
.trend-container {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 12px;
}

.trend-container h3 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

#trend-canvas {
  width: 100%;
  height: 100px;
  display: block;
}

/* === Contact Form === */
.contact-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.form-field input,
.form-field textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg);
  font-family: inherit;
  resize: vertical;
}

.form-field input:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.cf-submit {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--book-text);
  background: var(--book-bg);
  cursor: pointer;
  transition: background 0.15s;
  align-self: flex-start;
}

.cf-submit:hover {
  background: var(--book-hover);
}

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

.cf-status {
  font-size: 0.85rem;
  min-height: 1.2em;
}

.cf-success {
  color: var(--green);
}

.cf-error {
  color: var(--red);
}

/* === Date Pills === */
.date-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 2px 0 4px;
}

.date-pill {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface);
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.date-pill:hover {
  border-color: var(--pill-hover);
  color: var(--pill-hover);
}

.date-pill.active {
  background: var(--pill-active-bg);
  border-color: var(--pill-active-bg);
  color: var(--pill-active-text);
}

/* === Flight Table === */
.table-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 0;
}

#flight-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

#flight-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

#flight-table thead th:hover {
  color: var(--accent);
}

.sort-arrow {
  font-size: 0.7rem;
  margin-left: 2px;
  opacity: 0.4;
}

th.sort-asc .sort-arrow::after { content: " \25B2"; opacity: 1; }
th.sort-desc .sort-arrow::after { content: " \25BC"; opacity: 1; }

#flight-table tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

#flight-table tbody tr:nth-child(even) {
  background: var(--row-alt);
}

#flight-table tbody tr:hover {
  background: var(--accent-light);
}

/* Fare styling */
td.fare-gw {
  font-weight: 700;
  color: var(--green);
}

td.fare-low {
  color: var(--text-muted);
}

.book-link {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--book-text);
  background: var(--book-bg);
  border-radius: 4px;
  text-decoration: none;
  white-space: nowrap;
}

.book-link:hover {
  background: var(--book-hover);
}

.no-flights {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* === Leaflet Overrides === */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.leaflet-popup-content {
  margin: 10px 14px;
  font-size: 0.85rem;
  line-height: 1.4;
}

.popup-code {
  font-weight: 700;
  font-size: 1rem;
  color: var(--popup-code);
}

.popup-count {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* === Footer === */
footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  flex-shrink: 0;
  z-index: 100;
}

.footer-left,
.footer-right {
  flex: 1;
}

.footer-right {
  text-align: right;
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 10px;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

.footer-links a:hover {
  color: var(--accent);
}

.footer-sep {
  color: var(--text-muted);
  opacity: 0.4;
}

.disclaimer,
.copyright {
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.5;
}

/* === Overlay === */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.overlay-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 32px;
  position: relative;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.overlay-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.overlay-close:hover {
  color: var(--text);
}

#overlay-body h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 16px;
}

#overlay-body h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 20px;
  margin-bottom: 8px;
}

#overlay-body p {
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 12px;
}

#overlay-body ul {
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 12px;
  padding-left: 20px;
}

#overlay-body li {
  margin-bottom: 6px;
}

#overlay-body .tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-right: 6px;
}

#overlay-body .tag-soon {
  background: var(--accent-light);
  color: var(--accent);
}

#overlay-body .tag-later {
  background: rgba(251, 191, 36, 0.15);
  color: var(--orange);
}

/* === Responsive === */
@media (max-width: 768px) {
  header {
    padding: 10px 16px;
  }

  header h1 {
    font-size: 1.05rem;
  }

  .mobile-tabs {
    display: flex;
  }

  main {
    flex-direction: column;
    height: calc(100vh - 96px);
  }

  .map-panel,
  .detail-panel {
    flex: none;
    height: 100%;
    width: 100%;
  }

  .detail-panel {
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .panel.hidden {
    display: none;
  }

  .controls {
    flex-wrap: wrap;
  }

  #origin-select,
  .controls #filter-dest {
    max-width: 100%;
    flex: 1 1 100%;
  }
}

@media (max-width: 480px) {
  #flight-table {
    font-size: 0.78rem;
  }

  #flight-table thead th,
  #flight-table tbody td {
    padding: 6px 8px;
  }
}
