/* Theme tokens (light default) */
:root {
  --bg: oklch(97.5% 0.003 250);
  --surface: oklch(99.5% 0.002 250);
  --surface-2: oklch(95% 0.004 250);
  --surface-raised: oklch(100% 0 0);
  --border-color: oklch(89% 0.005 250);
  --border-strong-color: oklch(78% 0.006 250);
  --text-primary: oklch(22% 0.006 250);
  --text-secondary: oklch(46% 0.007 250);
  --text-tertiary: oklch(58% 0.007 250);
  --overlay: oklch(20% 0.01 250 / 0.45);
  --accent-color: oklch(54% 0.13 155);
  --accent-hover: oklch(48% 0.13 155);
  --accent-tint: oklch(93% 0.035 155);
  --accent-tint-text: oklch(34% 0.09 155);
  --on-accent: oklch(99% 0 0);
  --warning-color: oklch(62% 0.14 75);
  --warning-tint: oklch(93% 0.045 75);
  --warning-tint-text: oklch(38% 0.1 75);
  --danger-color: oklch(55% 0.16 25);
  --danger-tint: oklch(93% 0.04 25);
  --danger-tint-text: oklch(40% 0.13 25);

  /* Map onto Chota's own variables so existing .button/.badge/.card pick up the theme */
  --bg-color: var(--bg);
  --bg-secondary-color: var(--surface-2);
  --color-lightgray: var(--border-color);
  --color-primary: var(--accent-color);
  --color-gray: var(--text-tertiary);
  --font-color: var(--text-primary);
}

:root[data-theme="dark"] {
  --bg: oklch(19% 0.006 250);
  --surface: oklch(23% 0.007 250);
  --surface-2: oklch(27% 0.008 250);
  --surface-raised: oklch(29% 0.009 250);
  --border-color: oklch(33% 0.009 250);
  --border-strong-color: oklch(41% 0.01 250);
  --text-primary: oklch(95% 0.004 250);
  --text-secondary: oklch(74% 0.007 250);
  --text-tertiary: oklch(58% 0.007 250);
  --overlay: oklch(10% 0.01 250 / 0.6);
  --accent-color: oklch(70% 0.14 155);
  --accent-hover: oklch(76% 0.14 155);
  --accent-tint: oklch(30% 0.05 155);
  --accent-tint-text: oklch(85% 0.09 155);
  --on-accent: oklch(14% 0.01 155);
  --warning-color: oklch(75% 0.14 75);
  --warning-tint: oklch(32% 0.055 75);
  --warning-tint-text: oklch(87% 0.1 75);
  --danger-color: oklch(68% 0.17 25);
  --danger-tint: oklch(32% 0.06 25);
  --danger-tint-text: oklch(85% 0.11 25);
}

/* Establish flex layout with no scrolling */
html, body {
    height: 100vh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-color);
    color: var(--font-color);
    font-family: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
}

code, .mono {
  font-family: 'Roboto Mono', monospace;
}

/* 3-part header using Chota navbar classes */
header {
    flex-shrink: 0;
    border-bottom: 1px solid var(--color-lightgray);
    padding: 0.5rem 1rem;
    background-color: var(--surface);
}

/* Fluid layout wrapper */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 1rem;
    gap: 1rem;
}

.map-section,
.list-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    gap: 0.75rem;
}

#map {
    flex: 1;
    width: 100%;
    min-height: 0;
    border-radius: 10px;
    border: 1px solid var(--color-lightgray);
    z-index: 1;
}

/* Grouped buttons in the middle of the header */
.nav-center,
.nav-right {
  align-items: center !important;
  gap: 0.75rem;
}

.brand {
  color: var(--text-primary) !important;
}

/* Narrow viewports: drop the brand name and let the Map/List toggle sit left (main map/list header only) */
@media (max-width: 758px) {
  header .nav-left .brand {
    display: none;
  }

  header .nav-left:has(.brand) {
    flex: 0;
  }

  header .nav-left:has(.brand) + .nav-center {
    justify-content: flex-start !important;
  }
}

/* Narrow viewports: keep the Map/List toggle and theme toggle on one row
   (Chota's own 480px breakpoint stacks .nav into a column, which we don't want here). */
@media (max-width: 480px) {
  header .nav:has(.toggle-group) {
    flex-direction: row !important;
  }

  header .nav:has(.toggle-group) .nav-left,
  header .nav:has(.toggle-group) .nav-center,
  header .nav:has(.toggle-group) .nav-right {
    flex-wrap: nowrap !important;
  }

  header .nav:has(.toggle-group) .nav-right {
    flex: 0 0 auto;
    justify-content: flex-end;
  }
}

/* Narrow viewports: keep the back button, facility name, and theme toggle on one row
   (Chota's own 480px breakpoint stacks .nav into a column, which we don't want here). */
@media (max-width: 480px) {
  #back-link .back-label {
    display: none;
  }

  header .nav:has(#facility-title) {
    flex-direction: row !important;
  }

  header .nav:has(#facility-title) .nav-left,
  header .nav:has(#facility-title) .nav-center,
  header .nav:has(#facility-title) .nav-right {
    flex-wrap: nowrap !important;
  }

  header .nav:has(#facility-title) .nav-left {
    flex: 0 0 auto;
    justify-content: flex-start;
  }

  header .nav:has(#facility-title) .nav-center {
    flex: 1 1 auto;
    min-width: 0;
  }

  header .nav:has(#facility-title) .nav-right {
    flex: 0 0 auto;
    justify-content: flex-end;
  }

  #facility-title {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  header .nav:has(#facility-title) .theme-toggle-label {
    display: none;
  }
}

/* Chota's default outline-button text color doesn't track the theme; keep it legible in dark mode */
.button.outline {
  color: var(--text-primary);
  border-color: var(--border-strong-color);
}

/* Connected Segmented Pill Toggle Group */
.toggle-group {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.toggle-group .button {
  margin: 0 !important;
  border: none !important;
  border-radius: 999px !important;
  font-weight: 600;
}

.toggle-group .button.outline {
  background: transparent !important;
  color: var(--text-secondary);
}

/* Theme toggle switch */
.theme-toggle-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle-label {
  font-size: 12.5px;
  color: var(--text-secondary);
}

.theme-switch {
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--color-lightgray);
  position: relative;
  cursor: pointer;
  flex: none;
  padding: 0;
  transition: background .18s ease, border-color .18s ease;
}

html[data-theme="dark"] .theme-switch {
  background: var(--accent-color);
  border-color: var(--accent-color);
}

.theme-switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface-raised);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: left .18s ease;
}

html[data-theme="dark"] .theme-switch-knob {
  left: 22px;
}

/* Filter button badge count */
.filter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent-color);
  color: var(--on-accent);
  font-size: 10.5px;
  font-weight: 700;
  margin-left: 6px;
}

/* Search row above map/list */
.toolbar-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  flex: none;
}

.search-input {
  flex: 1;
  max-width: 340px;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--color-lightgray);
  background: var(--surface);
  color: var(--font-color);
  font-size: 13.5px;
  font-family: inherit;
}

.result-count {
  font-size: 13px;
  color: var(--text-tertiary);
}

.toolbar-loading {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  color: var(--text-tertiary);
}

.filter-btn {
  margin-left: auto;
}

/* Active filter chip row */
.active-filters-row {
  display: none;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: none;
}

.active-filters-row.visible {
  display: flex;
}

.active-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px 5px 12px;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent-tint-text);
  font-size: 12.5px;
  font-weight: 500;
}

.active-chip button {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
  font-weight: 700;
}

.clear-filters-link {
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 12.5px;
  cursor: pointer;
  text-decoration: underline;
}

/* List View & Pagination */
.table-wrapper {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--color-lightgray);
    border-radius: 14px;
    background: var(--surface);
}

.table-wrapper table th,
.table-wrapper table td {
    padding: 12px 20px;
}

.table-row-clickable {
    cursor: pointer;
}

.table-row-clickable:hover {
    background-color: var(--bg-secondary-color);
}

.pagination-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0.5rem;
    flex-shrink: 0;
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pagination-nav-compact {
    display: none;
}

.pagination-controls select {
    display: inline-block;
    width: auto;
    min-width: 70px;
    padding-right: 1.75rem;
}

/* Narrow viewports: shrink Prev/Next pagination buttons to just arrows (list view) */
@media (max-width: 480px) {
  .pagination-nav-full {
    display: none;
  }

  .pagination-nav-compact {
    display: inline;
  }
}

/* Status / confidence pill badges */
.pill-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.pill-badge.status-operational { background: var(--accent-tint); color: var(--accent-tint-text); }
.pill-badge.status-construction,
.pill-badge.status-announced { background: var(--warning-tint); color: var(--warning-tint-text); }
.pill-badge.status-decommissioned { background: var(--danger-tint); color: var(--danger-tint-text); }

.pill-badge.confidence-verified { background: var(--accent-tint); color: var(--accent-tint-text); }
.pill-badge.confidence-sourced,
.pill-badge.confidence-estimated { background: var(--surface-2); color: var(--text-secondary); }

/* Correction / correction-field status pill badges */
.pill-badge.status-new,
.pill-badge.status-partial { background: var(--warning-tint); color: var(--warning-tint-text); }
.pill-badge.status-reviewed,
.pill-badge.status-actioned,
.pill-badge.status-approved { background: var(--accent-tint); color: var(--accent-tint-text); }
.pill-badge.status-dismissed { background: var(--danger-tint); color: var(--danger-tint-text); }
.pill-badge.status-pending { background: var(--surface-2); color: var(--text-secondary); }

/* Slide-in Filter Drawer (uses existing .modal-overlay / .modal-card / .open hooks) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: var(--overlay);
  display: none;
  justify-content: flex-end;
  align-items: stretch;
  padding: 0;
  z-index: 2000;
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  width: 360px;
  max-width: 90vw;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--color-lightgray);
  box-shadow: -8px 0 30px rgba(0, 0, 0, .18);
  border-radius: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .18s ease;
}

.modal-overlay.open .modal-card {
  transform: translateX(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 22px;
  border-bottom: 1px solid var(--color-lightgray);
  background: transparent;
}

.modal-header h4 {
  margin: 0;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px;
  margin-bottom: 0;
}

.filter-group {
  margin-bottom: 24px;
}

.filter-group-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 12px;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--color-lightgray);
}

.chip.active {
  background: var(--accent-tint);
  color: var(--accent-tint-text);
  border-color: var(--accent-color);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 18px 22px;
  border-top: 1px solid var(--color-lightgray);
}

/* Active Filter Button Highlight */
#btn-filter.active-filter {
  background-color: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

/* Detail View Layout & Styling */
#detail-container {
  overflow-y: auto;
}

.facility-map-container {
  box-sizing: border-box;
  max-width: 880px;
  margin: 0 auto;
  padding: 0 0 1.5rem;
  width: 100%;
}

.facility-map-container #facility-map {
  height: 350px;
  width: 100%;
  border: 1px solid var(--color-lightgray);
  border-radius: 16px;
}

.detail-card {
  max-width: 880px;
  margin: 0 auto;
  width: 100%;
  padding: 2rem;
  background-color: var(--surface);
  border: 1px solid var(--color-lightgray);
  border-radius: 16px;
}

.detail-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.detail-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.pill-badge.flag {
  background: var(--surface-2);
  color: var(--text-secondary);
}

.detail-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.detail-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-gray);
  margin-bottom: 0.25rem;
}

.detail-value {
  font-size: 1.3rem;
}

.detail-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 0.5rem;
}

.detail-actions .button.outline {
  color: var(--accent-color);
  border-color: var(--accent-color);
}

.detail-actions .button.outline:hover {
  background: var(--accent-tint);
}

.gated-upsell {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--color-gray);
  font-size: 0.95rem;
  font-style: italic;
}

.gated-upsell::before {
  content: "";
  display: inline-block;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  background-color: currentColor;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23000' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M8 0a4 4 0 0 1 4 4v2.05a2.5 2.5 0 0 1 2 2.45v5a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 2 13.5v-5a2.5 2.5 0 0 1 2-2.45V4a4 4 0 0 1 4-4M4.5 7A1.5 1.5 0 0 0 3 8.5v5A1.5 1.5 0 0 0 4.5 15h7a1.5 1.5 0 0 0 1.5-1.5v-5A1.5 1.5 0 0 0 11.5 7zM8 1a3 3 0 0 0-3 3v2h6V4a3 3 0 0 0-3-3'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23000' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M8 0a4 4 0 0 1 4 4v2.05a2.5 2.5 0 0 1 2 2.45v5a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 2 13.5v-5a2.5 2.5 0 0 1 2-2.45V4a4 4 0 0 1 4-4M4.5 7A1.5 1.5 0 0 0 3 8.5v5A1.5 1.5 0 0 0 4.5 15h7a1.5 1.5 0 0 0 1.5-1.5v-5A1.5 1.5 0 0 0 11.5 7zM8 1a3 3 0 0 0-3 3v2h6V4a3 3 0 0 0-3-3'/%3E%3C/svg%3E");
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

.hidden {
  display: none !important;
}

.pad-20 {
  padding: 2rem;
}

.margin-0 {
  margin: 0;
}

.margin-top-10 {
  margin-top: 1rem;
}

/* Nav alignment rule matching index page */
header .nav-left,
header .nav-center,
header .nav-right {
  align-items: center !important;
}

/* Form layout shared by correction / admin edit pages */
.form-card {
  max-width: 880px;
  margin: 0 auto;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--color-lightgray);
  border-radius: 16px;
  overflow: hidden;
}

.form-section-label {
  padding: 22px 28px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.form-grid {
  padding: 8px 28px 22px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.form-grid label,
.field-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-tertiary);
}

.form-grid input,
.form-grid select,
.form-grid textarea {
  padding: 9px 12px;
  border-radius: 9px;
  border: 1px solid var(--color-lightgray);
  background: var(--bg);
  color: var(--font-color);
  font-size: 13.5px;
  font-family: inherit;
}

.form-divider {
  height: 1px;
  background: var(--color-lightgray);
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding: 20px 28px;
}

.form-note {
  margin: 0 28px 20px;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--accent-tint);
  color: var(--accent-tint-text);
  font-size: 13px;
  font-weight: 500;
}

/* Auth / login card */
.auth-card {
  width: 380px;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--color-lightgray);
  border-radius: 16px;
  padding: 32px;
  margin: auto;
}

.auth-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}
