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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: #f5f5f5;
  color: #333;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Header === */
.app-header {
  background: #1a1a2e;
  color: #fff;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 24px;
}

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

.app-header h1 {
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
}

.header-subtitle {
  font-size: 13px;
  color: #8899bb;
  white-space: nowrap;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  justify-content: flex-end;
}

.nav-selectors {
  display: flex;
  gap: 12px;
}

.nav-selector {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-selector label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #667;
}

.nav-selector select {
  padding: 5px 8px;
  border: 1px solid #444;
  border-radius: 4px;
  background: #2a2a3e;
  color: #dde;
  font-size: 13px;
  min-width: 180px;
  cursor: pointer;
}

.nav-selector select:focus {
  outline: none;
  border-color: #4a9eff;
}

.nav-selector select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.header-chronicle-name {
  font-size: 13px;
  color: #8899bb;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}

/* === Tabs === */
.tab-bar {
  display: flex;
  background: #2a2a3e;
  flex-shrink: 0;
}

.tab-btn {
  padding: 10px 24px;
  background: none;
  border: none;
  color: #889;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

.tab-btn:hover {
  color: #ccd;
}

.tab-btn.active {
  color: #fff;
  border-bottom-color: #4a9eff;
}

/* === Tab Content === */
.tab-content {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.tab-panel {
  position: absolute;
  inset: 0;
  display: none;
}

.tab-panel.active {
  display: flex;
  flex-direction: column;
}

/* === Map === */
#map {
  flex: 1;
  min-height: 0;
}

/* === Timeline === */
#timeline-container {
  flex: 1;
  min-height: 0;
  padding: 16px;
  background: #fff;
  display: flex;
  flex-direction: column;
}

#timeline {
  flex: 1;
  min-height: 0;
}

/* === Map Popups === */
.event-popup {
  max-width: 320px;
  line-height: 1.5;
}

.event-popup h3 {
  font-size: 15px;
  margin-bottom: 6px;
  color: #1a1a2e;
}

.event-popup .popup-date {
  font-size: 13px;
  color: #666;
  margin-bottom: 4px;
}

.event-popup .popup-location {
  font-size: 12px;
  color: #888;
  margin-bottom: 8px;
}

.event-popup .popup-description {
  font-size: 13px;
  margin-bottom: 10px;
}

.event-popup .popup-tags {
  font-size: 11px;
  color: #666;
  margin-bottom: 4px;
}

.event-popup .popup-people {
  font-size: 11px;
  color: #666;
  margin-bottom: 10px;
}

.event-popup .popup-link {
  display: inline-block;
  font-size: 13px;
  color: #4a9eff;
  text-decoration: none;
  font-weight: 500;
}

.event-popup .popup-link:hover {
  text-decoration: underline;
}

.event-popup .popup-thumb {
  max-width: 300px;
  max-height: 200px;
  border-radius: 4px;
  margin-bottom: 8px;
  display: block;
  object-fit: cover;
}

.event-popup a .popup-thumb {
  cursor: pointer;
}

/* === Precision indicator for county/state markers === */
.marker-imprecise {
  filter: hue-rotate(180deg) saturate(0.7);
  opacity: 0.85;
}

/* === Map hover tooltip with thumbnail === */
.marker-thumb-tooltip {
  padding: 0;
  border: 2px solid #fff;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  background: #fff;
}

.marker-thumb-tooltip .marker-tooltip-thumb {
  display: block;
  max-width: 180px;
  max-height: 120px;
  border-radius: 4px 4px 0 0;
  object-fit: cover;
}

.marker-thumb-tooltip .marker-tooltip-title {
  padding: 4px 8px 6px;
  font-size: 12px;
  color: #333;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* === Timeline item tooltip === */
.timeline-tooltip {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 12px 16px;
  max-width: 340px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  font-size: 13px;
  line-height: 1.5;
  position: absolute;
  z-index: 1000;
  pointer-events: auto;
}

.timeline-tooltip h3 {
  font-size: 14px;
  margin-bottom: 4px;
  color: #1a1a2e;
}

.timeline-tooltip .tooltip-date {
  font-size: 12px;
  color: #666;
  margin-bottom: 6px;
}

.timeline-tooltip .tooltip-description {
  margin-bottom: 8px;
}

.timeline-tooltip .tooltip-link {
  color: #4a9eff;
  text-decoration: none;
  font-weight: 500;
}

.timeline-tooltip .tooltip-link:hover {
  text-decoration: underline;
}

.timeline-tooltip .tooltip-thumb {
  max-width: 300px;
  max-height: 200px;
  border-radius: 4px;
  margin-bottom: 8px;
  display: block;
  object-fit: cover;
}

/* === Event count badge === */
.event-count {
  font-size: 13px;
  color: #889;
  padding: 10px 16px;
  flex-shrink: 0;
}

/* === Loading === */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 16px;
  color: #888;
}

/* === Timeline toolbar === */
.timeline-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  flex-shrink: 0;
}

.timeline-nav {
  display: flex;
  gap: 4px;
}

.tl-nav-btn {
  width: 34px;
  height: 34px;
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 4px;
  font-size: 18px;
  line-height: 1;
  color: #444;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}

.tl-nav-btn:hover {
  background: #e8f0fe;
  border-color: #4a9eff;
}

.tl-nav-btn:active {
  background: #d0e2fc;
}

.tl-fit-btn {
  width: auto;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  margin-left: 4px;
}

/* === vis-timeline overrides === */
.vis-timeline {
  border: 1px solid #ddd;
  border-radius: 4px;
}

.vis-item {
  border-color: #4a9eff;
  background-color: #4a9eff;
  color: #fff;
  border-radius: 4px;
  font-size: 12px;
  padding: 2px 6px;
}

.vis-item.vis-selected {
  border-color: #ff6b35;
  background-color: #ff6b35;
}

.vis-item.imprecise-event {
  border-color: #9b59b6;
  background-color: #9b59b6;
}

.vis-item.imprecise-event.vis-selected {
  border-color: #ff6b35;
  background-color: #ff6b35;
}

/* === Coordinate Picker === */
.picker-layout {
  display: flex;
  height: 100%;
}

.picker-sidebar {
  width: 320px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid #ddd;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.picker-map {
  flex: 1;
  min-height: 0;
}

.picker-instructions {
  font-size: 13px;
  color: #666;
  padding: 8px 12px;
  background: #f0f4ff;
  border-radius: 4px;
  border-left: 3px solid #4a9eff;
}

/* Search */
.picker-search label {
  font-size: 12px;
  font-weight: 600;
  color: #555;
  display: block;
  margin-bottom: 4px;
}

.picker-search-row {
  display: flex;
  gap: 6px;
}

.picker-search-row input {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
}

.picker-search-row input:focus {
  outline: none;
  border-color: #4a9eff;
}

.picker-search-row button {
  padding: 7px 14px;
  background: #4a9eff;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}

.picker-search-row button:hover {
  background: #3580d4;
}

#picker-search-results {
  margin-top: 6px;
}

.picker-result-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  background: #f9f9f9;
  border: 1px solid #eee;
  border-radius: 3px;
  font-size: 12px;
  color: #333;
  cursor: pointer;
  margin-bottom: 4px;
}

.picker-result-item:hover {
  background: #e8f0fe;
  border-color: #4a9eff;
}

.picker-searching,
.picker-no-results {
  font-size: 12px;
  color: #888;
  padding: 6px 0;
}

/* Coordinate display */
.picker-result label {
  font-size: 11px;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: block;
  margin-top: 10px;
  margin-bottom: 2px;
}

.picker-result label:first-child {
  margin-top: 0;
}

.picker-value {
  font-size: 18px;
  font-weight: 600;
  color: #1a1a2e;
  font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
  padding: 2px 0;
}

.picker-hint {
  font-weight: 400;
  color: #aaa;
  text-transform: none;
  letter-spacing: 0;
}

/* JSON section */
.picker-json-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #eee;
}

.picker-json-section input,
.picker-json-section select {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  margin-bottom: 4px;
}

.picker-json-section input:focus,
.picker-json-section select:focus {
  outline: none;
  border-color: #4a9eff;
}

.picker-json {
  background: #1a1a2e;
  color: #a8e6cf;
  padding: 12px;
  border-radius: 4px;
  font-size: 12px;
  font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
  white-space: pre;
  overflow-x: auto;
  margin: 8px 0;
}

.picker-copy-btn {
  padding: 6px 16px;
  background: #4a9eff;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}

.picker-copy-btn:hover {
  background: #3580d4;
}

.picker-copy-msg {
  font-size: 12px;
  color: #27ae60;
  margin-left: 8px;
}
