/* ============================================
   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;
  z-index: 0;
}

.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;
  text-align: center;
  min-width: 80px;
}

.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 10px;
  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;
  text-align: center;
  white-space: nowrap;
}

.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;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.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 handle (hidden on desktop, visible on mobile) ── */
.sidebar-handle {
  display: none;
}

.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;
}

.recent-post-text {
  white-space: normal;
  font-weight: 400;
  font-size: 12.5px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.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;
  overflow-x: hidden;
  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;
  width: 100%;
  box-sizing: border-box;
}

.insight-card {
  background: var(--bg-card);
  border-radius: 14px;
  border: 0.5px solid rgba(0, 0, 0, 0.06);
  padding: 22px 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 0 0 0.5px rgba(0, 0, 0, 0.03);
  transition: box-shadow 0.2s ease;
  overflow: hidden;
  box-sizing: border-box;
  min-width: 0;
}

.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;
}

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

.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;
  min-width: 0;
}

.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;
}

/* ── Search Bar ── */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(118, 118, 128, 0.08);
  border: none;
  border-radius: 10px;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.search-bar:focus-within {
  background: rgba(118, 118, 128, 0.12);
  box-shadow: 0 0 0 3px rgba(179, 27, 27, 0.1);
}

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

.search-bar input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  min-width: 0;
}

.search-bar input::placeholder {
  color: var(--text-tertiary);
}

.search-clear {
  width: 22px;
  height: 22px;
  border: none;
  background: var(--bg-hover);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease;
  flex-shrink: 0;
  padding: 0;
}

.search-clear:hover {
  background: var(--border);
}

.search-clear-icon {
  width: 13px;
  height: 13px;
  color: var(--text-secondary);
}

/* ── Search Results ── */
.search-results {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 12px 12px;
}

.search-results-count {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  padding: 8px 4px 10px;
  letter-spacing: 0.2px;
}

.search-results-list {
  background: var(--bg-card);
  border-radius: 12px;
  overflow: hidden;
}

.search-result-item {
  padding: 12px 14px;
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.06);
  display: flex;
  gap: 10px;
  align-items: flex-start;
  cursor: pointer;
  transition: background 0.12s ease;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: rgba(0, 0, 0, 0.03);
}

.search-result-item:active {
  background: rgba(0, 0, 0, 0.06);
}

.search-result-badge {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--cornell-red);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 2px;
}

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

.search-result-text {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-primary);
  letter-spacing: -0.1px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
}

.search-result-text.expanded {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
}

.search-result-text mark {
  background: rgba(179, 27, 27, 0.12);
  color: var(--cornell-red);
  border-radius: 2px;
  padding: 0 1px;
}

.search-result-meta {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 0;
}

.search-result-location {
  font-weight: 500;
  color: var(--text-secondary);
}

.search-result-date::before {
  content: " · ";
  color: var(--text-tertiary);
  margin: 0 4px;
}

.search-result-pills {
  display: flex;
  gap: 5px;
  margin-top: 6px;
}

.search-result-pill {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
  line-height: 1.4;
  text-transform: capitalize;
}

.search-result-pill--crush {
  background: rgba(192, 57, 43, 0.1);
  color: #c0392b;
}

.search-result-pill--vent {
  background: rgba(230, 126, 34, 0.1);
  color: #e67e22;
}

.search-result-pill--funny {
  background: rgba(39, 174, 96, 0.1);
  color: #27ae60;
}

.search-result-pill--wholesome {
  background: rgba(142, 68, 173, 0.1);
  color: #8e44ad;
}

.search-result-pill--gender {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.search-no-results {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-tertiary);
  font-size: 14px;
}

.search-no-results-icon {
  width: 32px;
  height: 32px;
  color: var(--border);
  margin-bottom: 12px;
}

.search-show-more {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
  max-width: 220px;
  margin: 14px auto 0;
  padding: 9px 20px;
  background: var(--bg-card);
  border: none;
  border-radius: 20px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.search-show-more:hover {
  background: var(--bg-hover);
}

.search-show-more:active {
  transform: scale(0.97);
}

.search-show-more-count {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-tertiary);
}

/* ── Shoutout Card ── */
.shoutout-card {
  text-align: center;
  padding: 20px 24px;
  background: rgba(179, 27, 27, 0.03);
  border: 1px solid rgba(179, 27, 27, 0.08);
}

.shoutout-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.shoutout-text a {
  color: var(--cornell-red);
  font-weight: 600;
  text-decoration: none;
  transition: opacity 0.15s ease;
}

.shoutout-text a:hover {
  opacity: 0.75;
  text-decoration: underline;
}

/* ── Activity Heatmap ── */
.heatmap-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.heatmap-months {
  display: flex;
  gap: 0;
  margin-bottom: 4px;
  padding-left: 0;
}

.heatmap-month-label {
  font-size: 10px;
  color: var(--text-tertiary);
  text-align: left;
  font-weight: 500;
}

.heatmap-grid {
  display: grid;
  grid-template-rows: repeat(7, 1fr);
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
}

.heatmap-cell {
  aspect-ratio: 1;
  min-width: 10px;
  max-width: 14px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.03);
  transition: transform 0.15s ease;
  position: relative;
}

.heatmap-cell:hover {
  transform: scale(1.4);
  z-index: 2;
}

.heatmap-cell[data-level="1"] {
  background: rgba(179, 27, 27, 0.15);
}

.heatmap-cell[data-level="2"] {
  background: rgba(179, 27, 27, 0.35);
}

.heatmap-cell[data-level="3"] {
  background: rgba(179, 27, 27, 0.55);
}

.heatmap-cell[data-level="4"] {
  background: rgba(179, 27, 27, 0.85);
}

.heatmap-cell[title]:hover::after {
  content: attr(title);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: #fff;
  font-size: 10px;
  padding: 3px 7px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
}

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  justify-content: flex-end;
  font-size: 10px;
  color: var(--text-tertiary);
}

.heatmap-legend-cell {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* ── Word Cloud ── */
.wordcloud-container {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 4px;
  justify-content: center;
  align-items: baseline;
  align-content: center;
  padding: 16px 8px;
  min-height: 120px;
  text-align: center;
  line-height: 1.1;
}

.wordcloud-word {
  display: inline-block;
  cursor: default;
  transition: transform 0.25s ease, opacity 0.2s ease;
  line-height: 1.2;
  letter-spacing: -0.02em;
  user-select: none;
}

.wordcloud-word:hover {
  transform: scale(1.2) rotate(0deg) !important;
  opacity: 1 !important;
}

/* ── Gender / Orientation Donut ── */
.donut-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.donut-chart {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  position: relative;
}

.donut-chart::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 72px;
  height: 72px;
  background: var(--bg-card);
  border-radius: 50%;
}

.donut-center-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  text-align: center;
}

.donut-center-number {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  letter-spacing: -0.5px;
}

.donut-center-text {
  font-size: 9px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
  font-weight: 500;
}

.donut-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  justify-content: center;
}

.donut-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

.donut-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.donut-legend-pct {
  color: var(--text-tertiary);
  font-weight: 400;
}

/* ── Keyword Explorer ── */

/* Trending word chips */
.keyword-top-words {
  margin-bottom: 12px;
}

.keyword-chips-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}

.keyword-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.keyword-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border: 1px solid rgba(179, 27, 27, 0.15);
  border-radius: 20px;
  background: rgba(179, 27, 27, 0.04);
  color: var(--cornell-red);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.keyword-chip:hover {
  background: rgba(179, 27, 27, 0.1);
  border-color: rgba(179, 27, 27, 0.3);
}

.keyword-chip-count {
  font-size: 10px;
  color: var(--text-tertiary);
  font-weight: 400;
}

/* Keyword highlight */
.keyword-highlight {
  background: rgba(179, 27, 27, 0.12);
  color: var(--cornell-red);
  font-weight: 600;
  border-radius: 2px;
  padding: 0 2px;
}

/* Keyword posts */
.keyword-posts {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.keyword-posts .recent-entry {
  padding: 10px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

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

.keyword-show-all {
  display: block;
  width: 100%;
  padding: 10px;
  margin-top: 8px;
  border: 1px solid rgba(179, 27, 27, 0.15);
  border-radius: 8px;
  background: rgba(179, 27, 27, 0.04);
  color: var(--cornell-red);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.keyword-show-all:hover {
  background: rgba(179, 27, 27, 0.1);
  border-color: rgba(179, 27, 27, 0.3);
}

@media (max-width: 600px) {
  .keyword-chips-row {
    flex-wrap: wrap;
    gap: 6px;
  }
}

.keyword-search-wrap {
  margin-bottom: 16px;
}

.keyword-input {
  width: 100%;
  padding: 10px 14px;
  border: 0.5px solid rgba(0, 0, 0, 0.1);
  border-radius: 10px;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background: rgba(118, 118, 128, 0.04);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.keyword-input:focus {
  border-color: rgba(179, 27, 27, 0.4);
  box-shadow: 0 0 0 3.5px rgba(179, 27, 27, 0.08);
  background: rgba(118, 118, 128, 0.02);
}

.keyword-input::placeholder {
  color: var(--text-tertiary);
}

.keyword-results {
  min-height: 40px;
}

.keyword-empty {
  font-size: 13px;
  color: var(--text-tertiary);
  text-align: center;
  padding: 16px 0;
}

.keyword-stats {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 16px;
}

.keyword-count {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  letter-spacing: -1px;
}

.keyword-count-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.keyword-sparkline {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 60px;
  margin-bottom: 16px;
}

.keyword-spark-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
}

.keyword-spark-bar {
  width: 100%;
  background: var(--cornell-red);
  border-radius: 2px 2px 0 0;
  min-height: 2px;
  opacity: 0.7;
  transition: opacity 0.15s ease;
  margin-top: auto;
}

.keyword-spark-bar:hover {
  opacity: 1;
}

.keyword-spark-label {
  font-size: 8px;
  color: var(--text-tertiary);
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
}

.keyword-top-locs {
  border-top: 1px solid var(--border-light);
  padding-top: 12px;
}

.keyword-top-locs-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 8px;
}

.keyword-loc-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.keyword-loc-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
}

.keyword-loc-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

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

  /* ── Titlebar: frosted glass, compact ── */
  .titlebar {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 16px 6px;
    gap: 6px;
    justify-content: center;
    background: rgba(240, 240, 242, 0.72);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.12);
    position: relative;
    z-index: 100;
  }

  .traffic-lights {
    display: none !important;
  }

  .titlebar-url {
    position: static;
    transform: none;
    order: 0;
    width: 100%;
    text-align: center;
    font-size: 11px;
    color: var(--text-tertiary);
    pointer-events: none;
  }

  /* ── Tabs: iOS segmented control ── */
  .tabs {
    order: 1;
    width: auto;
    background: rgba(118, 118, 128, 0.12);
    border: none;
    border-radius: 8px;
    padding: 2px;
  }

  .tab {
    font-size: 13px;
    font-weight: 600;
    padding: 6px 24px;
    border-radius: 7px;
    color: var(--text-primary);
    transition: all 0.2s ease;
    position: relative;
    z-index: 1;
  }

  .tab.active {
    background: #fff;
    color: var(--text-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08),
      0 1px 2px rgba(0, 0, 0, 0.06);
  }

  .tab:not(.active) {
    background: transparent;
    color: var(--text-secondary);
  }

  /* ── Date filter: compact row ── */
  .date-filter {
    order: 2;
    margin-left: 0;
    width: auto;
    background: rgba(118, 118, 128, 0.12);
    border: none;
    border-radius: 8px;
    padding: 2px;
    justify-content: center;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0;
  }

  .date-btn {
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    border-radius: 6px;
    color: var(--text-secondary);
    transition: all 0.2s ease;
  }

  .date-btn.active {
    background: #fff;
    color: var(--text-primary);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08),
      0 1px 2px rgba(0, 0, 0, 0.06);
  }

  .custom-range {
    border-left: none;
    border-top: 0.5px solid rgba(0, 0, 0, 0.08);
    width: 100%;
    justify-content: center;
    padding: 6px 8px;
  }

  /* ── Content: full-height map with bottom sheet overlay ── */
  .content {
    position: relative;
    flex-direction: column;
  }

  /* ── Map: full area ── */
  .map-wrapper {
    flex: 1;
    order: 1;
    min-height: 0;
  }

  /* ── Sidebar: Apple Maps bottom sheet ── */
  .sidebar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 35vh;
    max-height: none;
    border-right: none;
    border-top-left-radius: 14px;
    border-top-right-radius: 14px;
    background: var(--bg-sidebar);
    box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.10),
      0 -1px 6px rgba(0, 0, 0, 0.05);
    z-index: 50;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: height 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    border-bottom: none;
    will-change: height;
  }

  .sidebar.sheet-expanded {
    height: 75vh;
  }

  .sidebar.sheet-dragging {
    transition: none;
  }

  /* ── Sidebar drag handle ── */
  .sidebar-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 0 6px;
    flex-shrink: 0;
    cursor: grab;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
  }

  .sidebar-handle-bar {
    width: 36px;
    height: 5px;
    border-radius: 2.5px;
    background: rgba(0, 0, 0, 0.15);
  }

  .sidebar-header {
    padding: 6px 16px 8px;
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg-sidebar);
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
  }

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

  .filter-tabs {
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }

  .filter-btn {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 5px 14px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 100px;
    border: none;
    background: rgba(118, 118, 128, 0.08);
    color: var(--text-secondary);
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
  }

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

  .sidebar-entry {
    padding: 10px 16px;
    gap: 12px;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.06);
  }

  .sidebar-entry:active {
    background: rgba(0, 0, 0, 0.04);
    transition: background 0.05s ease;
  }

  .badge {
    width: 30px;
    height: 30px;
    font-size: 10px;
  }

  .entry-name {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.01em;
  }

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

  .entry-count {
    font-size: 12px;
    color: var(--text-tertiary);
    font-weight: 400;
  }

  /* ── Hide resize handle ── */
  .resize-handle {
    display: none !important;
  }

  /* ── Map badges ── */
  .map-badge {
    width: 24px;
    height: 24px;
    font-size: 8px;
    border-width: 1.5px;
  }

  .map-badge.selected {
    transform: scale(1.2);
  }

  /* ── Place Card: stacks above sidebar sheet ── */
  .place-card {
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.12),
      0 -1px 6px rgba(0, 0, 0, 0.06);
    z-index: 1000;
  }

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

  .place-card-header {
    padding: 12px 16px;
    gap: 12px;
  }

  .place-card-badge {
    width: 36px;
    height: 36px;
    font-size: 12px;
  }

  .place-card-info h2 {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.02em;
  }

  .place-card-info p {
    font-size: 12px;
  }

  .place-card-entries {
    padding: 0 16px;
  }

  .crush-text {
    font-size: 14px;
    line-height: 1.45;
  }

  /* ── Insights ── */
  .insights-view {
    padding: 16px;
    overflow-x: hidden;
  }

  .insights-grid {
    grid-template-columns: 1fr;
    gap: 12px;
    max-width: 100%;
    overflow: hidden;
  }

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

  .insight-card {
    padding: 16px;
    border-radius: 14px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    border: 0.5px solid rgba(0, 0, 0, 0.06);
    overflow: hidden;
    max-width: 100%;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
    contain: inline-size;
  }

  .insight-body {
    overflow: hidden;
    min-width: 0;
    width: 100%;
  }

  .insight-banner {
    padding: 18px 12px;
    border-radius: 14px;
  }

  .banner-stats {
    gap: 0;
  }

  .banner-stat {
    padding: 0 16px;
  }

  .banner-number {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -1.5px;
  }

  .banner-label {
    font-size: 9px;
    letter-spacing: 1px;
    font-weight: 600;
    color: var(--text-tertiary);
  }

  .insight-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
  }

  /* Bar charts — constrain within card */
  .bar-row {
    max-width: 100%;
    overflow: hidden;
  }

  .bar-label {
    width: 80px;
    min-width: 80px;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: -0.01em;
  }

  .bar-track {
    min-width: 0;
  }

  .bar-fill {
    border-radius: 4px;
  }

  .bar-value {
    font-size: 11px;
    min-width: 22px;
    width: auto;
    font-weight: 500;
  }

  /* Heatmap — scroll within card on small screens */
  .heatmap-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  .heatmap-grid {
    min-width: 300px;
  }

  .heatmap-cell {
    min-width: 6px;
    max-width: 10px;
  }

  .heatmap-legend {
    font-size: 9px;
  }

  /* Keyword chips — wrap and fit */
  .keyword-chips-row {
    flex-wrap: wrap;
  }

  .keyword-chip {
    font-size: 11px;
    padding: 4px 10px;
  }

  .keyword-sparkline {
    height: 48px;
  }

  .keyword-search-wrap {
    max-width: 100%;
  }

  .keyword-input {
    max-width: 100%;
    box-sizing: border-box;
  }

  .recent-entry {
    gap: 10px;
    padding: 12px 0;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.06);
  }

  .recent-badge {
    width: 28px;
    height: 28px;
    font-size: 9px;
  }

  .recent-text {
    font-size: 13px;
    line-height: 1.4;
    letter-spacing: -0.01em;
  }

  .recent-meta {
    font-size: 11px;
  }

  /* ── Stats Bar ── */
  .stats-bar {
    font-size: 11px;
    padding: 0 16px;
    color: var(--text-tertiary);
    background: rgba(240, 240, 242, 0.72);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }

  /* ── Search ── */
  .search-bar {
    padding: 9px 14px;
    border-radius: 10px;
  }

  .search-bar:focus-within {
    background: rgba(118, 118, 128, 0.12);
    box-shadow: 0 0 0 3px rgba(179, 27, 27, 0.15);
  }

  .search-bar input {
    font-size: 15px;
    font-weight: 400;
    letter-spacing: -0.01em;
  }

  .search-bar input::placeholder {
    color: var(--text-tertiary);
    font-weight: 400;
  }

  .search-clear {
    width: 28px;
    height: 28px;
    min-width: 28px;
  }

  .search-results-count {
    font-size: 13px;
    margin-bottom: 10px;
    font-weight: 500;
    color: var(--text-secondary);
  }

  .search-results-list {
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    border: 0.5px solid rgba(0, 0, 0, 0.06);
  }

  .search-result-item {
    padding: 14px 16px;
    gap: 12px;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.06);
    -webkit-tap-highlight-color: transparent;
  }

  .search-result-item:active {
    background: rgba(0, 0, 0, 0.04);
    transition: background 0.05s ease;
  }

  .search-result-item:last-child {
    border-bottom: none;
  }

  .search-result-badge {
    width: 30px;
    height: 30px;
    font-size: 9px;
  }

  .search-result-text {
    font-size: 14px;
    line-height: 1.4;
    letter-spacing: -0.01em;
  }

  .search-result-meta {
    font-size: 11px;
    flex-wrap: wrap;
    gap: 6px;
    color: var(--text-secondary);
  }

  .sentiment-pill {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 6px;
  }

  .search-show-more {
    padding: 14px 28px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin: 16px auto 4px;
    border-radius: 14px;
    background: rgba(118, 118, 128, 0.08);
    border: none;
    color: var(--cornell-red);
    -webkit-tap-highlight-color: transparent;
    transition: background 0.2s ease;
  }

  .search-show-more:active {
    background: rgba(118, 118, 128, 0.16);
    transform: scale(0.98);
  }

  .search-show-more-count {
    color: var(--text-tertiary);
    font-weight: 400;
  }
}