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

:root {
  --bg-deep: #0f1114;
  --bg-surface: #181b20;
  --bg-elevated: #1e2228;
  --bg-hover: #252a31;
  --border: #2a2f38;
  --border-light: #353b45;
  --text-primary: #e8e4dd;
  --text-secondary: #9a958d;
  --text-muted: #615d57;
  --accent-gold: #d4a857;
  --accent-gold-dim: #b8912e;
  --accent-gold-glow: rgba(212, 168, 87, 0.15);
  --cat-government: #e05555;
  --cat-road: #4a9eda;
  --cat-bridge: #e0943a;
  --cat-residential: #5bb868;
  --cat-commercial: #a07ad4;
  --cat-utility: #7a8899;
  --status-completed: #5bb868;
  --status-construction: #e0943a;
  --status-planned: #4a9eda;
  --status-stalled: #e05555;
  --sidebar-width: 380px;
  --topbar-height: 56px;
  --radius: 8px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

/* ── Light / Day Mode ── */
body.day-mode {
  --bg-deep: #f0ede8;
  --bg-surface: #ffffff;
  --bg-elevated: #f5f3ef;
  --bg-hover: #eae7e1;
  --border: #ddd8d0;
  --border-light: #ccc7be;
  --text-primary: #1a1a1a;
  --text-secondary: #5a564f;
  --text-muted: #9a958d;
  --accent-gold: #a07820;
  --accent-gold-dim: #8a6818;
  --accent-gold-glow: rgba(160, 120, 32, 0.12);
}

body.day-mode .leaflet-control-zoom a {
  background: #fff !important;
  color: #333 !important;
  border-color: #ccc !important;
}

body.day-mode .leaflet-control-zoom a:hover {
  background: #f0f0f0 !important;
  color: #000 !important;
}

body.day-mode .home-btn {
  background: #fff;
  border-color: rgba(0,0,0,0.15);
  color: #555;
}

body.day-mode .home-btn:hover {
  background: #f0f0f0;
  color: #222;
}

body.day-mode .news-article:hover .news-article-title {
  color: #1a5fb4;
}

/* ── Top Bar ── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 1000;
  gap: 16px;
}

.topbar-brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-shrink: 0;
}

.topbar-title {
  font-family: 'DM Serif Display', serif;
  font-size: 1.2rem;
  color: var(--accent-gold);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.topbar-subtitle {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 600;
  white-space: nowrap;
}

.topbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  flex-shrink: 0;
}

.filters {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  flex: 1;
  min-width: 0;
}

.filters::-webkit-scrollbar { display: none; }

.filter-btn {
  padding: 5px 14px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
  letter-spacing: 0.02em;
}

.filter-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
  color: var(--text-primary);
}

.filter-btn.active {
  background: var(--accent-gold-glow);
  border-color: var(--accent-gold-dim);
  color: var(--accent-gold);
}

.filter-btn .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  position: relative;
  top: -0.5px;
}

/* ── Filter Dropdown (mobile only, hidden on desktop) ── */
.filter-dropdown {
  display: none;
  position: relative;
  flex-shrink: 0;
}

.filter-dropdown-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 100px;
  border: 1px solid var(--accent-gold-dim);
  background: var(--accent-gold-glow);
  color: var(--accent-gold);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.filter-dropdown-arrow {
  font-size: 0.6rem;
}

.filter-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 160px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 4px 0;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 2000;
}

.filter-dropdown-menu.open {
  display: block;
}

.filter-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}

.filter-dropdown-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.filter-dropdown-item.active {
  color: var(--accent-gold);
  font-weight: 700;
}

.filter-dropdown-item .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

/* ── Home Button ── */
.home-btn {
  position: absolute;
  top: 80px;
  left: 10px;
  z-index: 800;
  width: 30px;
  height: 30px;
  background: var(--bg-surface);
  border: 2px solid rgba(0,0,0,0.2);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  line-height: 1;
}

.home-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.layer-toggle {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.layer-btn {
  padding: 5px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.layer-btn:hover { color: var(--text-secondary); border-color: var(--border-light); }
.layer-btn.active { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-light); }

/* ── Day/Night Toggle ── */
.theme-toggle {
  position: relative;
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-size: 1rem;
}

.theme-icon {
  position: absolute;
  transition: transform 0.4s ease, opacity 0.4s ease;
}

/* Night mode (default): moon visible, sun hidden */
.theme-icon.moon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

.theme-icon.sun {
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

/* Day mode: sun visible, moon hidden */
.theme-toggle.day .theme-icon.moon {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

.theme-toggle.day .theme-icon.sun {
  opacity: 1;
  transform: rotate(0deg) scale(1);
  color: var(--accent-gold);
}

/* ── Layout: Map + Sidebar ── */
.main-layout {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: stretch;
}

.map-container {
  flex: 1;
  min-width: 0;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
}

.leaflet-control-attribution { font-size: 9px !important; opacity: 0.5; }
.leaflet-control-zoom a {
  background: var(--bg-surface) !important;
  color: var(--text-secondary) !important;
  border-color: var(--border) !important;
}
.leaflet-control-zoom a:hover { background: var(--bg-elevated) !important; color: var(--text-primary) !important; }

/* ── Custom Markers ── */
.marker-icon {
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,0.9);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4), 0 0 0 1px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.marker-icon:hover {
  transform: scale(1.3);
  box-shadow: 0 4px 16px rgba(0,0,0,0.5), 0 0 0 1px rgba(0,0,0,0.15);
}

/* ── Map Tooltip (matches popup styling) ── */
.marker-tooltip {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  max-width: 260px;
  white-space: normal;
}
.marker-tooltip::before {
  border-top-color: var(--border);
}

/* ── Map Popup ── */
.custom-popup .leaflet-popup-content-wrapper {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  padding: 0;
}

.custom-popup .leaflet-popup-content {
  margin: 0;
}

.custom-popup .leaflet-popup-tip {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-top: none;
  border-left: none;
}

.map-popup {
  padding: 12px 14px;
}

.map-popup-name {
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 2px;
}

.map-popup-local {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.map-popup-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.map-popup-sep {
  color: var(--text-muted);
}

.map-popup-desc {
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--text-secondary);
}

/* ── Sidebar Drag Zone (mobile only) ── */
.sidebar-drag-zone {
  flex-shrink: 0;
  background: var(--bg-surface);
}

.sidebar-drag-handle {
  display: none;
  justify-content: center;
  padding: 8px 0 0;
}

.drag-bar {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border-light);
}

/* ── Sidebar Horizontal Resize (desktop) ── */
.sidebar-resize-handle {
  width: 8px;
  cursor: col-resize;
  background: var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-resize-handle::after {
  content: '';
  width: 3px;
  height: 32px;
  border-radius: 2px;
  background: var(--border-light);
  transition: background 0.2s;
}

.sidebar-resize-handle:hover,
.sidebar-resize-handle.dragging {
  background: var(--accent-gold-glow);
}

.sidebar-resize-handle:hover::after,
.sidebar-resize-handle.dragging::after {
  background: var(--accent-gold);
}

/* ── Sidebar (always visible) ── */
.sidebar {
  width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  min-width: 320px;
  max-width: 70vw;
}

.sidebar-header {
  padding: 12px 20px 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.sidebar-header h2 {
  font-family: 'DM Serif Display', serif;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.sidebar-header .view-info {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.sidebar-header .view-info .count {
  color: var(--accent-gold);
  font-weight: 700;
}

/* ── Sidebar Tabs ── */
.sidebar-tabs {
  display: flex;
  gap: 0;
}

.sidebar-tab {
  flex: 1;
  padding: 8px 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  position: relative;
  transition: color var(--transition);
}

.sidebar-tab:hover {
  color: var(--text-secondary);
}

.sidebar-tab.active {
  color: var(--accent-gold);
}

.sidebar-tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 20%;
  right: 20%;
  height: 2px;
  background: var(--accent-gold);
  border-radius: 1px;
}

.sidebar-body {
  flex: 1 1 0;
  overflow-y: auto;
  padding: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  background: var(--bg-surface);
  min-height: 0;
}

.sidebar-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.6;
}

/* ── Time Group Header ── */
.time-group-header {
  padding: 12px 16px 8px;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-primary);
  border-bottom: 2px solid var(--border);
  border-top: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  z-index: 1;
}

/* ── News Article ── */
.news-article {
  display: flex;
  gap: 12px;
  padding: 10px 16px;
  text-decoration: none;
  color: inherit;
  transition: background var(--transition);
}

.news-article:hover {
  background: var(--bg-elevated);
}

.news-article-body {
  flex: 1;
  min-width: 0;
}

.news-article-source {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.news-article-source-name {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.news-article-source .news-article-time {
  margin: 0;
}

.news-article-source .news-article-time::before {
  content: '\00b7';
  margin-right: 6px;
}

.news-article-title {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text-primary);
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.news-article:hover .news-article-title {
  color: #8ab4f8;
}

.news-article-time {
  font-size: 0.65rem;
  color: var(--text-muted);
}

/* ── Location Tag on Article ── */
.news-article-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 0.62rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.news-article-tag-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

.news-article-thumb {
  width: 100px;
  height: 68px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-elevated);
}

/* ── Loading / Error ── */
.news-loading {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.news-loading-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-light);
  border-top-color: var(--accent-gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.news-error {
  padding: 8px 16px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ── Article border ── */
.news-article {
  border-bottom: 1px solid var(--border);
}

.news-article:last-child {
  border-bottom: none;
}

/* ── YouTube Video Feed ── */
.video-feed {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.video-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 16px;
}

.video-card {
  width: 220px;
  flex-shrink: 0;
  display: block;
  text-decoration: none;
  color: inherit;
  border-radius: var(--radius);
  transition: background var(--transition);
  padding: 8px;
}

.video-feed::after {
  content: '';
  flex: 1;
  min-height: 0;
  display: block;
  background: linear-gradient(to bottom, var(--bg-surface) 0%, var(--bg-deep) 100%);
}

.video-card:hover {
  background: var(--bg-elevated);
}

.video-card-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 8px;
  background: var(--bg-elevated);
}

.video-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-card-duration {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0,0,0,0.8);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
}

.video-card-title {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text-primary);
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.video-card:hover .video-card-title {
  color: #e05555;
}

.video-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.video-card-channel {
  color: var(--text-secondary);
  font-weight: 600;
}

.video-card-meta .sep::before {
  content: '\00b7';
}

/* ── Mobile ── */
@media (max-width: 768px) {
  .topbar-subtitle { display: none; }
  .topbar-divider:first-of-type { display: none; }
  .topbar-divider:nth-of-type(2) { display: none; }

  .layer-toggle {
    margin-left: auto;
  }

  /* Hide pill filters, show dropdown */
  .filters { display: none; }
  .filter-dropdown { display: block; }

  .main-layout {
    flex-direction: column;
  }

  .map-container {
    flex: 1;
  }

  .sidebar {
    width: 100%;
    height: 40vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    transition: height 0.3s ease;
  }

  .sidebar-drag-zone {
    cursor: grab;
    touch-action: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-drag-zone:active { cursor: grabbing; }

  .sidebar-drag-zone .sidebar-header {
    border-bottom: none;
  }

  .sidebar-drag-handle {
    display: flex;
  }

  .sidebar-resize-handle {
    display: none;
  }

  .sidebar {
    max-width: 100%;
    min-width: 100%;
  }

  .video-grid {
    gap: 8px;
    padding: 8px 12px;
  }

  .video-card {
    width: 100%;
  }
}
