/* ============================================
   Big Red Mapped Connections
   Apple-native aesthetic, Riley Walz layout
   ============================================ */

:root {
  --cornell-red: #B31B1B;
  --cornell-red-hover: #8C1515;
  --cornell-red-light: rgba(179, 27, 27, 0.08);
  --cornell-red-badge: #B31B1B;

  --bg-window: #f5f5f7;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --bg-titlebar: #f0f0f2;
  --bg-hover: #f5f5f7;

  --text-primary: #1d1d1f;
  --text-secondary: #86868b;
  --text-tertiary: #aeaeb2;

  --border: #d2d2d7;
  --border-light: #e8e8ed;

  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-sheet: 0 -4px 32px rgba(0, 0, 0, 0.12);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-badge: 50%;

  --sidebar-width: 280px;
  --titlebar-height: 52px;
  --stats-height: 36px;
}

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

html,
body {
  height: 100%;
  font-family: var(--font);
  background: #000;
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── Window Chrome ── */
.window {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-window);
  overflow: hidden;
}

/* ── Titlebar ── */
.titlebar {
  height: var(--titlebar-height);
  background: var(--bg-titlebar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  flex-shrink: 0;
  -webkit-app-region: drag;
  position: relative;
}

.titlebar-url {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  font-weight: 400;
  color: var(--text-tertiary);
  letter-spacing: 0.1px;
  pointer-events: none;
}

.traffic-lights {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

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

.light.red {
  background: #ff5f57;
}

.light.yellow {
  background: #febc2e;
}

.light.green {
  background: #28c840;
}

.tabs {
  display: flex;
  background: var(--bg-sidebar);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
}

.tab {
  padding: 6px 20px;
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-app-region: no-drag;
}

.tab.active {
  background: var(--bg-window);
  color: var(--text-primary);
}

.tab:hover:not(.active) {
  color: var(--text-primary);
}

.date-filter {
  margin-left: auto;
  display: flex;
  align-items: center;
  background: var(--bg-sidebar);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: visible;
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 0;
}

.custom-range {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-left: 1px solid var(--border);
}

.custom-range input[type="date"] {
  font-family: var(--font);
  font-size: 11px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-window);
  color: var(--text-primary);
  cursor: pointer;
  -webkit-app-region: no-drag;
}

.custom-range-sep {
  font-size: 11px;
  color: var(--text-tertiary);
}

.date-btn {
  padding: 5px 14px;
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-app-region: no-drag;
}

.date-btn.active {
  background: var(--bg-window);
  color: var(--text-primary);
}

.date-btn:hover:not(.active) {
  color: var(--text-primary);
}

/* ── Content Area ── */
.content {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

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

.filter-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: transparent;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-btn.active {
  background: var(--cornell-red);
  border-color: var(--cornell-red);
  color: #fff;
}

.filter-btn:hover:not(.active) {
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sidebar-list::-webkit-scrollbar {
  width: 6px;
}

.sidebar-list::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ── Sidebar Entry ── */
.sidebar-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.12s ease;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-entry:hover {
  background: var(--bg-hover);
}

.sidebar-entry.active {
  background: var(--cornell-red-light);
}

.badge {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-badge);
  background: var(--cornell-red-badge);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.entry-info {
  flex: 1;
  min-width: 0;
}

.entry-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-meta {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.entry-count {
  font-size: 11px;
  color: var(--text-tertiary);
  flex-shrink: 0;
  font-weight: 500;
}

/* ── Resize Handle ── */
.resize-handle {
  width: 6px;
  cursor: col-resize;
  background: transparent;
  position: relative;
  flex-shrink: 0;
  z-index: 10;
  transition: background 0.15s ease;
}

.resize-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 32px;
  border-radius: 2px;
  background: var(--border);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.resize-handle:hover,
.resize-handle.active {
  background: rgba(0, 0, 0, 0.04);
}

.resize-handle:hover::after,
.resize-handle.active::after {
  opacity: 1;
}

body.resizing {
  cursor: col-resize !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}

body.resizing * {
  cursor: col-resize !important;
}

/* ── Map Wrapper ── */
.map-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
}

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

/* ── Leaflet Overrides ── */
.leaflet-container {
  font-family: var(--font) !important;
  background: var(--bg-window);
}

.leaflet-control-zoom {
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-card) !important;
  overflow: hidden;
}

.leaflet-control-zoom a {
  background: var(--bg-sidebar) !important;
  color: var(--text-primary) !important;
  border-bottom: 1px solid var(--border-light) !important;
  width: 32px !important;
  height: 32px !important;
  line-height: 32px !important;
  font-size: 16px !important;
}

.leaflet-control-zoom a:hover {
  background: var(--bg-hover) !important;
}

.leaflet-control-attribution {
  font-size: 10px !important;
  background: rgba(255, 255, 255, 0.7) !important;
  padding: 2px 6px !important;
}

/* ── Map Badge Markers ── */
.map-badge-container {
  background: transparent !important;
  border: none !important;
}

.map-badge {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--cornell-red);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  border: 2px solid #fff;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.map-badge:hover {
  transform: scale(1.15);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.map-badge.selected {
  transform: scale(1.2);
  box-shadow: 0 4px 16px rgba(179, 27, 27, 0.4);
  border-color: var(--cornell-red);
  background: #fff;
  color: var(--cornell-red);
}

/* ── Place Card (Bottom Sheet) ── */
.place-card {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-sheet);
  overflow: hidden;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.place-card.open {
  max-height: 55%;
}

.place-card-handle {
  width: 36px;
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  margin: 8px auto 4px;
  flex-shrink: 0;
}

.place-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 20px 12px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.place-card-badge {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-badge);
  background: var(--cornell-red);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  flex-shrink: 0;
}

.place-card-info {
  flex: 1;
}

.place-card-info h2 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
}

.place-card-info p {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.place-card-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--bg-hover);
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease;
  flex-shrink: 0;
}

.place-card-close:hover {
  background: var(--border);
}

.place-card-entries {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px;
  -webkit-overflow-scrolling: touch;
}

.place-card-entries::-webkit-scrollbar {
  width: 6px;
}

.place-card-entries::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.crush-entry {
  padding: 16px 0;
  border-bottom: 1px solid var(--border-light);
}

.crush-entry:last-child {
  border-bottom: none;
}

.crush-text {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-primary);
}

.crush-date {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 8px;
  text-align: right;
}

/* ── Stats Bar ── */
.stats-bar {
  height: var(--stats-height);
  background: var(--bg-titlebar);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

/* ── Insights View ── */
.insights-view {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 28px 36px;
  background: var(--bg-window);
}

.insights-view.active {
  display: block;
}

.insights-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  max-width: 980px;
  margin: 0 auto;
}

.insight-card {
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  padding: 20px 22px;
  box-shadow: 0 0.5px 1px rgba(0, 0, 0, 0.04);
}

.insight-banner {
  grid-column: 1 / -1;
  background: var(--bg-card);
  border: 1px solid rgba(0, 0, 0, 0.08);
  color: var(--text-primary);
  padding: 24px 32px;
  box-shadow: 0 0.5px 1px rgba(0, 0, 0, 0.04);
}

.banner-stats {
  display: flex;
  justify-content: center;
  gap: 0;
}

.banner-stat {
  text-align: center;
  padding: 0 48px;
  border-right: 1px solid rgba(0, 0, 0, 0.08);
}

.banner-stat:last-child {
  border-right: none;
}

.banner-number {
  font-size: 38px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -1.5px;
  color: var(--text-primary);
}

.banner-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  margin-top: 6px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.insight-header {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.insight-icon {
  width: 15px;
  height: 15px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.insight-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.insight-body {
  /* populated by JS */
}

.insight-wide {
  grid-column: 1 / -1;
}

/* ── Insight: Bar Chart ── */
.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.bar-row:last-child {
  margin-bottom: 0;
}

.bar-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  width: 104px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-track {
  flex: 1;
  height: 8px;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--cornell-red);
  border-radius: 4px;
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
  min-width: 3px;
}

.bar-value {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  width: 24px;
  flex-shrink: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ── Insight: Recent entry ── */
.recent-entry {
  padding: 14px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.recent-entry:last-child {
  border-bottom: none;
}

.recent-badge {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--cornell-red);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(180, 43, 30, 0.2);
}

.recent-content {
  flex: 1;
  min-width: 0;
}

.recent-text {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text-primary);
  letter-spacing: -0.1px;
}

.recent-meta {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.sentiment-pill {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
  text-transform: capitalize;
  letter-spacing: 0.1px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 100%;
  }

  .content {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    max-height: 35vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .traffic-lights {
    display: none;
  }

  .date-filter {
    margin-left: 0;
  }

  .titlebar {
    gap: 8px;
    flex-wrap: wrap;
    height: auto;
    padding: 8px 12px;
  }

  .insights-grid {
    grid-template-columns: 1fr;
  }
}