/* Reviewer UI: styles.css
   Assessment review dashboard for tax assessors.
   Layout: fixed-width sidebar (charts + summary) | flex-fill map area */

/* Reset and Base
   Normalizes box model and removes browser default spacing
   so layout behaves consistently across browsers. */

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

html, body {
  height: 100%; /* Required so the full-viewport flex layout works. */
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: #232323;
  background: #fff;
}

a {
  color: #F2541B; /* Orange. */
}

a:hover {
  color: #c23d0e; /* Darker shade for contrast on hover. */
}

strong, b {
  color: #F2541B; /* Brand orange for bold text. */
}

/* Layout
   Two-column flex row. Sidebar on left, map fills rest.
   100vh keeps the entire UI within one screen with no page scroll. */

.layout {
  display: flex;
  height: 100vh;
}

/* Sidebar
   Fixed-width panel containing title, summary stats, and charts.
   flex-shrink: 0 prevents sidebar from collapsing as map grows.
   overflow-y: auto lets chart content scroll if window is short. */

.sidebar {
  width: 360px;
  min-width: 300px;
  padding: 24px 28px;
  overflow-y: auto;
  border-right: 1px solid #ddd;
  background: #fff;
  flex-shrink: 0;
}

.sidebar h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #2C3968; /* Navy. */
  margin-bottom: 16px;
}

.summary {
  margin-bottom: 24px;
  line-height: 1.5;
  font-size: 0.95rem;
}

/* Chart Sections
   Placeholder layout used before a charting library replaces .chart-placeholder with a real chart canvas.
   y-label is rotated vertically to sit flush against chart edge. */

.chart-section {
  margin-bottom: 28px;
}

.chart-section h2 {
  font-size: 0.85rem;
  font-weight: 400; /* Light weight to read as a label, not a heading. */
  color: #555;
  margin-bottom: 8px;
}

.chart-container {
  width: 100%;
}

.chart-placeholder {
  position: relative; /* Needed to absolutely position y-axis label. */
  display: flex;
  flex-direction: column;
}

.chart-y-label {
  font-size: 0.7rem;
  color: #888;
  writing-mode: vertical-rl; /* Rotate text to run bottom-to-top. */
  transform: rotate(180deg);
  position: absolute;
  left: 0;
  top: 10px;
}

.chart-area {
  height: 100px;
  margin-left: 24px; /* Leaves space for rotated y-axis label. */
  background: #D8D7B1; /* Warm grey placeholder fill. */
  border-radius: 4px;
  border-bottom: 1px solid #ccc;
  border-left: 1px solid #ccc;
}

.chart-x-labels {
  display: flex;
  justify-content: space-between; /* Pin min label left, max label right. */
  margin-left: 24px;
  margin-top: 4px;
  font-size: 0.7rem;
  color: #888;
}

/* Map Area
   Fills all remaining horizontal space after sidebar.
   Position: relative creates a stacking context so that absolutely
   positioned children (controls, popup) layer correctly over the map.
   Background color shows briefly before MapLibre tiles load. */

.map-area {
  flex: 1;
  position: relative;
  background: #e8e0d8; /* Warm grey tile-loading fallback. */
}

/* MapLibre GL JS mounts its <canvas> inside this element.
   Must be 100% x 100% so the canvas fills the available area. */
#map {
  width: 100%;
  height: 100%;
}

/* Map Controls (Layer Toggles)
   Floating panel anchored to top-right corner of map.
   z-index 1000 keeps it above MapLibre GL canvas (z-index 0).
   Semi-transparent white background lets map context show through. */

.map-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1000;
  background: rgb(255 255 255 / 95%); /* Semi-transparent white. */
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 10px 14px;
  font-size: 0.82rem;
  box-shadow: 0 1px 4px rgb(0 0 0 / 15%);
}

.map-controls fieldset {
  border: none; /* <fieldset> has default border. Remove for clean styling */
}

.map-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  cursor: pointer; /* Entire label row is clickable, not just checkbox. */
}

.map-controls label:last-child {
  margin-bottom: 0; /* Remove trailing gap after last toggle. */
}

.map-controls input[type="checkbox"],
.map-controls input[type="radio"] {
  width: 14px;
  height: 14px;
  cursor: pointer;
}

/* Radio button label layout. Main label + descriptive subtitle. */
.layer-label-main {
  display: block;
  font-size: 0.82rem;
}

.layer-label-sub {
  display: block;
  font-size: 0.68rem;
  color: #888;
  margin-top: 1px;
  line-height: 1.2;
}

/* Map Legend
   Color-key shown below layer radio buttons.
   Renders a horizontal gradient bar with labeled endpoints. */

.map-legend {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #e0e0e0;
}

.map-legend-title {
  font-size: 0.7rem;
  color: #555;
  margin-bottom: 4px;
}

.map-legend-bar {
  height: 10px;
  border-radius: 3px;
  margin-bottom: 3px;
}

.map-legend-labels {
  display: flex;
  justify-content: space-between;
  gap: 2px;
  font-size: 0.65rem;
  color: #888;
}

.map-legend-labels span {
  text-align: center;
  flex: 1;
  min-width: 0;
  font-size: 0.6rem;
}

/* Address Search Bar
   Floating search input over map, top-left below nav controls.
   Positioned to avoid overlap with MapLibre zoom controls. */

.map-search {
  position: absolute;
  top: 12px;
  left: 56px;
  z-index: 1000;
  display: flex;
  gap: 0;
  box-shadow: 0 1px 4px rgb(0 0 0 / 15%);
  border-radius: 4px;
  overflow: hidden;
}

.map-search input {
  width: 240px;
  padding: 8px 12px;
  font-size: 0.85rem;
  font-family: inherit;
  border: 1px solid #ccc;
  border-right: none;
  border-radius: 4px 0 0 4px;
  outline: none;
  background: #fff;
}

.map-search input:focus {
  border-color: #2C3968;
}

.map-search button {
  padding: 8px 12px;
  font-size: 0.85rem;
  background: #2C3968;
  color: #fff;
  border: 1px solid #2C3968;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
  transition: background 0.15s;
}

.map-search button:hover {
  background: #1e2a4a;
}

/* PDF Export Button
   Floating button over map, positioned top-left below the search bar.
   Triggers client-side PDF generation of viewport properties. */

.map-export-btn {
  position: absolute;
  top: 52px;
  left: 56px;
  z-index: 1000;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 600;
  background: #fff;
  color: #2C3968;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 1px 4px rgb(0 0 0 / 15%);
  transition: background 0.15s, color 0.15s;
}

.map-export-btn:hover {
  background: #2C3968;
  color: #fff;
}

.map-export-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Property Popup
   Shown when user clicks a property on map.
   Absolutely positioned over the map. Toggled via hidden attribute in JS.
   Floated away from layer-toggle panel (bottom-right) to avoid overlap. */

.property-popup {
  position: absolute;
  bottom: 60px;
  right: 60px;
  z-index: 1000;
  background: #fff;
  border: 1px solid #ccc;
  padding: 12px 16px;
  min-width: 240px;
  max-width: 280px;
  font-size: 0.85rem;
  box-shadow: 0 2px 6px rgb(0 0 0 / 20%);
}

/* Close button for property popup. Positioned top-right corner. */
.popup-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  font-size: 1.1rem;
  color: #888;
  cursor: pointer;
  line-height: 1;
  padding: 2px 4px;
}

.popup-close:hover {
  color: #232323;
}

.popup-address {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.popup-details {
  border-collapse: collapse; /* Remove default cell spacing in details table. */
}

.popup-details td {
  padding: 1px 4px;
}

.popup-label {
  font-style: italic;
  color: #555;
  padding-right: 8px;
}

.popup-value {
  text-align: right; /* Align dollar values to right for easy scanning. */
}

/* Color-coded change indicators: navy = increase, orange = decrease. */
.popup-change-up {
  color: #2C3968;
}

.popup-change-down {
  color: #F2541B;
}

/* Margin of Error (MOE) section.
   Visualizes 80% prediction interval for popup property.
   Bar runs from lower bound to upper bound. Marker
   shows where point prediction sits within that range. */

.moe-section {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #eee;
}

.moe-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.moe-label {
  font-size: 0.75rem;
  color: #555;
  font-style: italic;
}

.moe-range {
  font-size: 0.78rem;
  font-weight: 700;
  color: #2C3968;
}

.moe-bar {
  position: relative;
  height: 6px;
  background: #eee;
  border-radius: 3px;
  overflow: visible;
}

.moe-bar-fill {
  position: absolute;
  top: 0;
  height: 100%;
  background: #c9d0e0; /* Light navy. */
  border-radius: 3px;
}

.moe-bar-marker {
  position: absolute;
  top: -2px;
  width: 2px;
  height: 10px;
  background: #2C3968;
  transform: translateX(-1px);
}

.moe-endpoints {
  display: flex;
  justify-content: space-between;
  margin-top: 3px;
  font-size: 0.7rem;
  color: #888;
}

/* Explainability section.
   Lists top features driving model along with this property's
   own value for each. Bars are scaled relative to most-important
   feature so reviewers can eyeball relative contributions. */

.drivers-section {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #eee;
}

.drivers-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: #2C3968;
  margin-bottom: 6px;
}

.drivers-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.driver-item {
  margin-bottom: 8px;
}

.driver-item:last-child {
  margin-bottom: 0;
}

.driver-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  margin-bottom: 2px;
}

.driver-label {
  color: #333;
}

.driver-value {
  color: #555;
  font-weight: 600;
}

.driver-bar {
  height: 4px;
  background: #f1f1f1;
  border-radius: 2px;
  overflow: hidden;
}

.driver-bar-fill {
  height: 100%;
  background: #F2541B; /* Brand orange to differentiate from MOE bar. */
}

.driver-importance {
  font-size: 0.65rem;
  color: #999;
  margin-top: 2px;
}

.drivers-empty {
  font-size: 0.75rem;
  color: #888;
  font-style: italic;
}

.drivers-footnote {
  margin-top: 6px;
  font-size: 0.65rem;
  color: #aaa;
  line-height: 1.3;
}

/* Deep link from popup to widget valuation history page. */
.popup-widget-link {
  display: block;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #eee;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
}

/* Utility
   Visually hides element while keeping accessible to screen readers.
   Used on <legend> inside layer toggle fieldset. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Mobile Responsive
   
   Two breakpoints used:
   - 768px for tablets in portrait and large phones in landscape.
   - 480px for small phones (iPhone SE, Galaxy S series, Pixel, etc.).

   Stack sidebar above map, shrink padding/font sizes, and reposition
   floating panels so they don't obscure the map. MapLibre GL JS handles
   touch/pinch-zoom natively apprently, so no JS changes needed. */

/* Tablet / Small Laptop (≤ 768px)
   Stack sidebar above map instead of side-by-side.
   Sidebar becomes scrollable top panel capped at 40 vh. */
@media (width <= 768px) {
  .layout {
    flex-direction: column; /* Sidebar on top, map below. */
  }

  .sidebar {
    width: 100%;
    min-width: unset; /* Remove desktop min. */
    max-height: 40vh; /* Cap sidebar height so map stays visible. */
    border-right: none;
    border-bottom: 1px solid #ddd; /* Horizontal divider replaces vertical. */
    padding: 16px 20px;
  }

  .sidebar h1 {
    font-size: 1.25rem;
  }

  /* Map fills remaining viewport below sidebar. */
  .map-area {
    min-height: 50vh;
  }

  /* Shrink layer-toggle panel so it doesn't cover too much of map. */
  .map-controls {
    font-size: 0.75rem;
    padding: 8px 10px;
    max-width: 70vw; /* Prevent overflow on narrow screens. */
  }

  /* Move property popup to bottom-center for thumb reach. */
  .property-popup {
    right: 50%;
    transform: translateX(50%);
    bottom: 16px;
    max-width: 85vw;
  }

  .map-search {
    left: 12px;
    top: auto;
    bottom: 12px;
  }

  .map-search input {
    width: 180px;
    font-size: 0.8rem;
  }

  .map-export-btn {
    top: auto;
    bottom: 52px;
    left: 12px;
  }
}

/* Small Phone (≤ 480px)
   Tighten spacing. Reduce chart heights. */
@media (width <= 480px) {
  .sidebar {
    padding: 12px 14px;
    max-height: 35vh; /* Slightly less room for sidebar on small screens. */
  }

  .sidebar h1 {
    font-size: 1.1rem;
    margin-bottom: 10px;
  }

  .summary {
    font-size: 0.85rem;
    margin-bottom: 16px;
  }

  .chart-section {
    margin-bottom: 18px;
  }

  .chart-section h2 {
    font-size: 0.78rem;
  }

  /* Reduce chart placeholder height for small viewport. */
  .chart-area {
    height: 70px;
  }

  /* Stack labels vertically with smaller text. */
  .map-controls {
    font-size: 0.7rem;
    padding: 6px 8px;
    top: 8px;
    right: 8px;
    max-width: 80vw;
  }

  .map-controls label {
    gap: 4px;
    margin-bottom: 4px;
  }

  /* Popup fills most of screen width on small phones. */
  .property-popup {
    max-width: 92vw;
    font-size: 0.8rem;
    padding: 10px 12px;
  }

  .map-search input {
    width: 150px;
  }
}
