/* ========================================
   Parking Forecaster - Main Stylesheet
   Light/dark mode, demand colors, responsive
   ======================================== */

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

:root {
  --bg: #f5f5f5;
  --bg-card: #ffffff;
  --bg-sidebar: #ffffff;
  --text: #1a1a1a;
  --text-muted: #666666;
  --border: #e0e0e0;
  --accent: #1e3a5f;
  --accent-light: #2a5a8f;
  --hover: #f0f0f0;
  --topbar-bg: #ffffff;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --demand-green: #2ecc71;
  --demand-amber: #f39c12;
  --demand-red: #e74c3c;
  --demand-purple: #9b59b6;
  --radius: 6px;
}

body.dark-mode {
  --bg: #1a1a1a;
  --bg-card: #2d2d2d;
  --bg-sidebar: #242424;
  --text: #e0e0e0;
  --text-muted: #999999;
  --border: #3d3d3d;
  --accent: #5b9bd5;
  --accent-light: #7ab3e8;
  --hover: #353535;
  --topbar-bg: #242424;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-light); }

/* ---- HOME / MARKET SELECTOR ---- */
.home-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 60px 20px;
}
.home-title {
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.home-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 32px;
}
.markets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.market-card {
  display: block;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
  color: var(--text);
}
.market-card:hover {
  border-color: var(--accent);
  color: var(--text);
}
.market-name { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.market-stats { font-size: 13px; color: var(--text-muted); display: flex; gap: 12px; flex-wrap: wrap; }
.loading-msg, .empty-msg { color: var(--text-muted); font-size: 14px; }

/* ---- TOP BAR ---- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 48px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
}
.topbar-left, .topbar-right { display: flex; align-items: center; }
.topbar-home {
  color: var(--text-muted);
  display: flex; align-items: center;
  padding: 4px;
  border-radius: 4px;
}
.topbar-home:hover { color: var(--text); background: var(--hover); }
.topbar-center { display: flex; flex-direction: column; align-items: center; }
.topbar-city { font-size: 15px; font-weight: 600; line-height: 1.2; }
.topbar-updated { font-size: 11px; color: var(--text-muted); }
.theme-toggle {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 6px; border-radius: 4px; display: flex;
}
.theme-toggle:hover { color: var(--text); background: var(--hover); }

/* ---- APP LAYOUT ---- */
.app-layout {
  display: flex;
  margin-top: 48px;
  min-height: calc(100vh - 48px);
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: 180px;
  min-width: 180px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: fixed;
  top: 48px;
  bottom: 0;
  left: 0;
  overflow-y: auto;
  z-index: 50;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.sidebar-link:hover { background: var(--hover); color: var(--text); }
.sidebar-link.active { background: var(--hover); color: var(--accent); font-weight: 600; }
.sidebar-link svg { flex-shrink: 0; }

/* ---- SIDEBAR COLLAPSE/EXPAND (default: collapsed, icons only) ---- */
.sidebar {
  width: 56px;
  min-width: 56px;
  transition: width 0.2s ease;
}
.sidebar .sidebar-link span {
  display: none;
}
.sidebar .sidebar-link {
  justify-content: center;
  padding: 10px;
}

/* Expanded state */
.sidebar.sidebar-expanded {
  width: 180px;
  min-width: 180px;
}
.sidebar.sidebar-expanded .sidebar-link span {
  display: inline;
}
.sidebar.sidebar-expanded .sidebar-link {
  justify-content: flex-start;
  gap: 10px;
  padding: 10px 16px;
}

/* Sidebar toggle button */
#sidebar-toggle {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 12px;
  color: var(--text-muted);
  width: 100%;
  display: flex;
  justify-content: center;
  border-radius: var(--radius);
  transition: background 0.15s, color 0.15s;
}
#sidebar-toggle:hover {
  background: var(--hover);
  color: var(--text);
}

/* ---- MAIN CONTENT ---- */
.main-content {
  flex: 1;
  margin-left: 56px;
  padding: 20px;
  min-width: 0;
  transition: margin-left 0.2s ease;
}
.sidebar.sidebar-expanded ~ .main-content {
  margin-left: 180px;
}

/* ---- SIDE PANEL (event detail) ---- */
.side-panel {
  position: fixed;
  top: 48px; right: -400px; bottom: 0;
  width: 380px;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  box-shadow: -2px 0 8px rgba(0,0,0,0.1);
  z-index: 90;
  overflow-y: auto;
  padding: 20px;
  transition: right 0.25s ease;
}
.side-panel.open { right: 0; }
.side-panel-close {
  position: absolute; top: 12px; right: 12px;
  background: none; border: none; font-size: 24px; color: var(--text-muted);
  cursor: pointer; padding: 4px 8px; border-radius: 4px;
}
.side-panel-close:hover { background: var(--hover); color: var(--text); }

/* ---- DEMAND COLORS ---- */
.demand-green { color: var(--demand-green); }
.demand-amber { color: var(--demand-amber); }
.demand-red { color: var(--demand-red); }
.demand-purple { color: var(--demand-purple); }
.demand-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px;
}
.demand-dot-green { background: var(--demand-green); }
.demand-dot-amber { background: var(--demand-amber); }
.demand-dot-red { background: var(--demand-red); }
.demand-dot-purple { background: var(--demand-purple); }
.demand-bg-green { background: rgba(46,204,113,0.15); border-left: 3px solid var(--demand-green); }
.demand-bg-amber { background: rgba(243,156,18,0.15); border-left: 3px solid var(--demand-amber); }
.demand-bg-red { background: rgba(231,76,60,0.15); border-left: 3px solid var(--demand-red); }
.demand-bg-purple { background: rgba(155,89,182,0.15); border-left: 3px solid var(--demand-purple); }

/* ---- CALENDAR ---- */
.cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.cal-nav { display: flex; align-items: center; gap: 8px; }
.cal-nav button {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
  padding: 6px 12px; border-radius: var(--radius); cursor: pointer; font-size: 13px;
}
.cal-nav button:hover { background: var(--hover); }
.cal-title { font-size: 18px; font-weight: 600; }
.cal-view-toggle { display: flex; gap: 4px; }
.cal-view-toggle button {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text-muted);
  padding: 5px 12px; border-radius: var(--radius); cursor: pointer; font-size: 12px;
}
.cal-view-toggle button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.cal-grid-wrapper {
  width: 100%;
  display: block;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  width: 100%;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.cal-day-header {
  background: var(--bg-card); padding: 6px 4px; text-align: center;
  font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;
  overflow: hidden; min-width: 0;
}
.cal-day {
  background: var(--bg-card); min-height: 90px; padding: 4px 6px;
  vertical-align: top; position: relative; min-width: 0; overflow: hidden;
}
.cal-day.other-month { opacity: 0.4; }
.cal-day.today { background: rgba(30,58,95,0.06); }
body.dark-mode .cal-day.today { background: rgba(91,155,213,0.1); }
.cal-day-num { font-size: 12px; font-weight: 500; margin-bottom: 2px; }
.cal-event {
  display: block; max-width: 100%; width: 100%; box-sizing: border-box;
  font-size: 11px; padding: 2px 4px; margin-bottom: 2px; border-radius: 3px;
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text);
}
.cal-event:hover { opacity: 0.8; }
.cal-more { display: block; font-size: 10px; color: var(--text-muted); cursor: pointer; padding: 2px 4px; overflow: hidden; white-space: nowrap; max-width: 100%; }
.cal-more:hover { text-decoration: underline; }

/* ---- CARD GRID (lots, venues, events list) ---- */
.card-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  cursor: pointer; transition: border-color 0.15s;
}
.card:hover { border-color: var(--accent); }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.card-subtitle { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.card-meta { font-size: 12px; color: var(--text-muted); display: flex; gap: 12px; flex-wrap: wrap; }

/* ---- MAP ---- */
#map-container { width: 100%; height: calc(100vh - 88px); border-radius: var(--radius); overflow: hidden; }

/* ---- FORECAST ---- */
.forecast-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.forecast-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; text-align: center;
}
.forecast-day { font-size: 13px; font-weight: 600; }
.forecast-date { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.forecast-score { font-size: 24px; font-weight: 700; }
.forecast-label { font-size: 11px; text-transform: uppercase; font-weight: 600; }

/* ---- EVENT DETAIL (side panel) ---- */
.event-detail-title { font-size: 18px; font-weight: 600; margin-bottom: 4px; margin-right: 30px; }
.event-detail-venue { font-size: 14px; color: var(--text-muted); margin-bottom: 12px; }
.event-detail-row { font-size: 13px; margin-bottom: 8px; display: flex; gap: 8px; }
.event-detail-label { font-weight: 600; min-width: 70px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius); font-size: 13px; font-weight: 500;
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  cursor: pointer; transition: background 0.15s;
}
.btn:hover { background: var(--hover); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-light); }

/* ---- SECTION HEADERS ---- */
.section-header { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.section-subheader { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }

/* ---- TABLE ---- */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; padding: 8px 12px; border-bottom: 2px solid var(--border);
  font-weight: 600; font-size: 12px; color: var(--text-muted); text-transform: uppercase;
}
.data-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: var(--hover); }

/* ---- WEATHER ---- */
.weather-current {
  display: flex; align-items: center; gap: 20px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 24px; margin-bottom: 8px; box-shadow: var(--shadow);
}
.weather-icon-lg { font-size: 56px; line-height: 1; }
.weather-temp-lg { font-size: 40px; font-weight: 700; line-height: 1; margin-bottom: 4px; }
.weather-desc { font-size: 16px; color: var(--text-muted); margin-bottom: 6px; }
.weather-meta { font-size: 13px; color: var(--text-muted); }
.weather-forecast-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; margin-bottom: 20px;
}
.weather-day-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; text-align: center;
}
.weather-day-label { font-size: 13px; font-weight: 600; }
.weather-day-date { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.weather-day-icon { font-size: 28px; line-height: 1; margin-bottom: 4px; }
.weather-day-desc { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.weather-day-temps { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.weather-hi { color: var(--demand-red); }
.weather-lo { color: var(--accent); }
.weather-day-precip { font-size: 11px; color: var(--text-muted); margin-bottom: 8px; }
.weather-impact {
  font-size: 11px; text-align: left; padding: 5px 6px; border-radius: 4px;
  background: rgba(0,0,0,0.04); line-height: 1.4;
}
body.dark-mode .weather-impact { background: rgba(255,255,255,0.05); }
.weather-impact-note {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; font-size: 13px; margin-top: 8px;
}
.weather-impact-row { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 8px; line-height: 1.4; }
.weather-impact-row:last-child { margin-bottom: 0; }

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  .sidebar {
    width: 52px; min-width: 52px;
    padding: 8px 4px;
  }
  .sidebar-link span { display: none; }
  .sidebar-link { justify-content: center; padding: 10px; }
  .main-content { margin-left: 52px; padding: 12px; }
  /* Bottom sheet: slides up from bottom, full-width, above Leaflet map (panes reach z-index 700) */
  .side-panel {
    top: auto !important;
    right: 0 !important;
    left: 0 !important;
    bottom: -70vh;
    width: 100% !important;
    height: 70vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.15);
    transition: bottom 0.25s ease;
    padding-top: 36px;
    z-index: 1000 !important;
  }
  .side-panel.open { bottom: 0; }
  /* Drag handle indicator */
  .side-panel::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
  }
  /* Leaflet popup must stay below the bottom sheet when it is open */
  .leaflet-popup-pane { z-index: 700; }
  .cal-day { min-height: 60px; }
  .cal-event { font-size: 10px; }
  .card-grid { grid-template-columns: 1fr; }
  .topbar-city { font-size: 13px; }
  .home-container { padding: 30px 16px; }
}

@media (max-width: 600px) {
  /* Compact calendar cells on mobile — fits 7 columns in viewport width */
  .cal-grid { gap: 1px; }
  .cal-day { min-height: 52px; padding: 2px 1px; }
  .cal-day-num { font-size: 11px; font-weight: 600; }
  .cal-day-header { font-size: 10px; padding: 4px 1px; }
  .cal-event {
    display: block; max-width: 100%; width: 100%; box-sizing: border-box;
    font-size: 9px; padding: 1px 2px;
    border-left-width: 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .cal-more { display: block; font-size: 9px; padding: 1px 2px; overflow: hidden; max-width: 100%; white-space: nowrap; }
}

@media (max-width: 400px) {
  /* Extra narrow phones */
  .cal-day { min-height: 44px; padding: 1px; }
  .cal-day-num { font-size: 10px; }
  .cal-day-header { font-size: 9px; padding: 3px 1px; }
  .cal-event { font-size: 8px; padding: 1px; border-left-width: 2px; }
  .cal-more { font-size: 8px; }
}
