/* Lacupedas — bear-sighting tracker for Latvia. Forest-brand chrome + a
   validated data palette for anything that encodes actual data. */

/* The [hidden] UA rule loses to any author rule of equal specificity
   (e.g. `.modal-overlay { display: flex }`) — force it to win. */
[hidden] {
  display: none !important;
}

:root {
  color-scheme: light;
  --brand-forest-dark: #1f3b2c;
  --brand-forest: #2f5d3f;
  --brand-accent: #d97b29;
  --brand-accent-hover: #c26a1f;

  --page-plane: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --danger: #d03b3b;
  --danger-hover: #b52f2f;
  --success: #0ca30c;

  --series-1: #2a78d6; /* sequential blue */
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --brand-forest-dark: #0f1f17;
    --brand-forest: #234a30;
    --page-plane: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page-plane);
  color: var(--text-primary);
  /* Single-viewport app shell: header + main + footer fill the screen with
     no page-level scroll — each scrollable list scrolls within its own
     card instead. Reverted on small screens (see the 900px query) where
     stacking everything into one viewport isn't realistic. */
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

h1, h2 {
  margin: 0;
}

button {
  font-family: inherit;
}

/* Header */

.app-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: var(--brand-forest-dark);
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  font-size: 2rem;
}

.app-header h1 {
  font-size: 1.15rem;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.7);
}

.lang-switch {
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 3px;
}

.lang-switch button {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
}

.lang-switch button.active {
  background: var(--brand-accent);
  color: #fff;
}

/* Layout */

.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
  grid-template-rows: 1fr;
  gap: 16px;
  padding: 16px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
}

@media (max-width: 900px) {
  body {
    height: auto;
    overflow: visible;
  }

  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    overflow: visible;
  }
}

.map-pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.heatmap-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  margin-left: 4px;
}

.map-hint {
  flex: 0 0 auto;
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.picking-banner {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--brand-accent);
  color: #fff;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
}

#map {
  flex: 1 1 auto;
  min-height: 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: default;
}

@media (max-width: 900px) {
  #map {
    flex: none;
    height: 50vh;
    min-height: 340px;
  }
}

#map.picking {
  cursor: crosshair;
}

.bear-marker-dot {
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

/* Sidebar */

.sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

@media (max-width: 900px) {
  .sidebar {
    overflow: visible;
  }
}

.card {
  flex: 0 0 auto;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

/* list-card and news-card share whatever vertical space is left after the
   stats/chart cards take their natural height, and each scrolls its own
   list internally instead of growing the page. News gets a bigger share —
   it's typically the one with real content (auto-collected), while
   community reports start empty. */
.list-card {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.news-card {
  flex: 1.6 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

@media (max-width: 900px) {
  .list-card,
  .news-card {
    flex: none;
  }
}

.card h2 {
  flex: 0 0 auto;
  font-size: 0.95rem;
  margin-bottom: 10px;
  color: var(--text-primary);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

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

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-value-small {
  font-size: 0.95rem;
  font-weight: 600;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.chart-container svg {
  width: 100%;
  height: auto;
  display: block;
}

.viz-grid {
  stroke: var(--gridline);
  stroke-width: 1;
}

.viz-axis-label {
  fill: var(--text-muted);
  font-size: 9px;
}

.viz-bar {
  fill: var(--series-1);
}

.viz-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin: 4px 0 0;
}

/* Sightings list */

.sightings-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

@media (max-width: 900px) {
  .sightings-list {
    flex: none;
    max-height: 320px;
  }
}

.list-empty {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 8px 0;
}

.sighting-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  transition: background 0.2s;
}

.sighting-item:hover {
  background: rgba(217, 123, 41, 0.08);
}

.sighting-item.highlight {
  background: rgba(217, 123, 41, 0.2);
}

.type-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}

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

.sighting-top {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: 0.82rem;
}

.sighting-date {
  font-weight: 600;
}

.sighting-type {
  color: var(--text-secondary);
}

.sighting-desc {
  margin: 4px 0 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
  word-break: break-word;
}

.sighting-reporter {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.vote-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.vote-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.vote-btn:hover:not(:disabled) {
  border-color: var(--text-muted);
}

.vote-btn:disabled {
  cursor: default;
  opacity: 0.6;
}

.vote-confirm.active {
  border-color: var(--success);
  color: var(--success);
  background: rgba(12, 163, 12, 0.1);
}

.vote-dispute.active {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(208, 59, 59, 0.1);
}

/* Filters */

.list-card-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.list-card-header h2 {
  margin-bottom: 0;
}

.filter-group {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.filter-select {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--page-plane);
  color: var(--text-secondary);
  font-size: 0.75rem;
  padding: 3px 6px;
  font-family: inherit;
  max-width: 50%;
}

/* News mentions */

.news-card-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.news-card-header h2 {
  margin-bottom: 0;
}

.news-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
}

.news-link {
  display: block;
  margin-top: 4px;
  font-size: 0.82rem;
  color: var(--text-primary);
  text-decoration: none;
}

.news-link:hover {
  text-decoration: underline;
}

.news-disclaimer {
  flex: 0 0 auto;
  margin: 10px 0 0;
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.4;
  max-height: 4.5em;
  overflow-y: auto;
}

.news-marker-diamond {
  display: block;
  width: 12px;
  height: 12px;
  transform: rotate(45deg);
  background: #4a3aa7;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  margin: 2px;
}

.popup-meta {
  font-size: 0.75rem;
  color: #666;
}

.news-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--brand-forest-dark);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  z-index: 900;
}

/* Buttons */

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--brand-accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-accent-hover);
}

.btn-secondary {
  background: var(--brand-forest);
  color: #fff;
}

.btn-secondary:hover {
  filter: brightness(1.1);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-primary);
}

.btn-ghost:hover {
  background: rgba(11, 11, 11, 0.05);
}

/* Footer */

.app-footer {
  flex: 0 0 auto;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 6px 20px;
  max-width: 800px;
  margin: 0 auto;
}

@media (max-width: 900px) {
  .app-footer {
    padding: 12px 20px 24px;
  }
}

/* Modal */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal {
  background: var(--surface-1);
  color: var(--text-primary);
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal h2 {
  margin-bottom: 14px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.form-row label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-location {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.form-row input,
.form-row select,
.form-row textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.9rem;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: inherit;
}

.form-error {
  color: var(--danger);
  font-size: 0.8rem;
}

.photo-preview {
  margin-top: 8px;
  max-width: 100%;
  max-height: 160px;
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: cover;
}

.sighting-thumb {
  display: block;
  margin-top: 6px;
  max-width: 100%;
  max-height: 140px;
  border-radius: 8px;
  cursor: zoom-in;
  object-fit: cover;
}

.popup-photo {
  display: block;
  width: 100%;
  max-width: 220px;
  max-height: 160px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 6px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}
