/* Home page — current snapshot on top, historical chart below */

.home-app {
  min-height: calc(100vh - var(--chrome-h));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.home-hero {
  background: var(--fao-blue-light);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  flex-shrink: 0;
}

.home-hero-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.home-hero h1 { font-size: 1.05rem; font-weight: 700; color: var(--fao-blue-dark); }
.home-hero p { font-size: 0.78rem; color: var(--text-secondary); }

.home-alert-badges { display: flex; gap: 8px; flex-wrap: wrap; }

.alert-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
}
.alert-pill.severe { background: rgba(200,64,64,0.1); color: var(--prelim-red); border: 1px solid rgba(200,64,64,0.3); }

.home-layout {
  flex: 0 0 auto;
  min-height: 420px;
  height: min(58vh, 620px);
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 12px 24px 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(460px, 38%);
  gap: 16px;
  overflow: hidden;
}

.home-map-card {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.home-map-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--panel-bg);
  z-index: 2;
}

.home-map-header h2 { font-size: 0.9rem; font-weight: 700; color: var(--text-primary); margin-bottom: 2px; }
.home-map-header .period { font-size: 0.76rem; color: var(--text-secondary); }

.home-map-body {
  flex: 1;
  position: relative;
  min-height: 0;
}

#home-map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.home-map-legend {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 400;
  background: rgba(255,255,255,0.96);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 0.7rem;
  box-shadow: var(--shadow-sm);
}

.home-map-legend strong {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.home-map-legend .legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}

.home-map-legend .legend-swatch {
  display: inline-block;
  width: 14px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(0,0,0,0.12);
  flex-shrink: 0;
}

.home-map-cta {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: 400;
}

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

.assessment-card {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.assessment-card h3 { font-size: 0.82rem; font-weight: 700; color: var(--fao-blue-dark); margin-bottom: 6px; }
.assessment-card p { font-size: 0.74rem; color: var(--text-secondary); margin-bottom: 10px; line-height: 1.5; max-width: none; }

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

.stat-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.stat-pill .sp-label { font-size: 0.72rem; font-weight: 600; }
.stat-pill .sp-value { font-size: 1.15rem; font-weight: 700; }
.stat-pill.extreme { background: rgba(123,0,0,0.06); border-color: var(--cdi-extreme); }
.stat-pill.extreme .sp-value { color: var(--cdi-extreme); }
.stat-pill.severe-total { background: rgba(200,64,64,0.06); }
.stat-pill.severe-total .sp-value { color: var(--cdi-severe); }
.stat-pill.improving { background: rgba(0,160,0,0.06); }
.stat-pill.improving .sp-value { color: var(--cdi-normal); }

button.stat-pill {
  width: 100%; font: inherit; color: inherit; text-align: left; cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
button.stat-pill:hover { box-shadow: 0 2px 6px rgba(0,0,0,0.12); }
button.stat-pill:focus-visible { outline: 2px solid var(--fao-blue); outline-offset: 1px; }
button.stat-pill[aria-expanded="true"] { box-shadow: inset 0 0 0 1px var(--fao-blue); }

.stat-pill .sp-text { display: flex; flex-direction: column; gap: 2px; }
.stat-pill .sp-action {
  font-size: 0.66rem; font-weight: 600; color: var(--fao-blue);
  text-decoration: underline; text-decoration-color: rgba(46,139,199,0.35); text-underline-offset: 2px;
}
button.stat-pill:hover .sp-action { text-decoration-color: currentColor; }
.stat-pill .sp-right { display: flex; align-items: center; gap: 8px; }
.stat-pill .sp-chevron {
  width: 20px; height: 20px; flex: none; border-radius: 50%;
  background: rgba(46,139,199,0.12); position: relative;
  transition: background 0.15s ease, transform 0.2s ease;
}
.stat-pill .sp-chevron::before {
  content: ''; position: absolute; left: 50%; top: 45%;
  width: 6px; height: 6px; border-right: 2px solid var(--fao-blue); border-bottom: 2px solid var(--fao-blue);
  transform: translate(-50%, -50%) rotate(45deg);
}
button.stat-pill:hover .sp-chevron { background: rgba(46,139,199,0.22); }
button.stat-pill[aria-expanded="true"] .sp-chevron { transform: rotate(180deg); }

.assessment-list-panel {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel-bg); padding: 8px 10px; font-size: 0.72rem;
}
.assessment-list-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.assessment-list-head .text-muted { font-size: 0.68rem; }
.assessment-list-search {
  width: 100%; padding: 4px 8px; margin-bottom: 6px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.72rem;
}
.assessment-list-scroll { max-height: 220px; overflow-y: auto; }
.assessment-list-table { width: 100%; border-collapse: collapse; }
.assessment-list-table th, .assessment-list-table td { padding: 4px 4px; border-bottom: 1px solid var(--border); text-align: left; }
.assessment-list-table th { position: sticky; top: 0; background: var(--panel-bg); font-size: 0.62rem; text-transform: uppercase; color: var(--text-muted); }
.assessment-list-table td.num, .assessment-list-table th.num { text-align: right; white-space: nowrap; }
.assessment-list-table a { color: var(--fao-blue-dark); text-decoration: none; }
.assessment-list-table a:hover { text-decoration: underline; }
.assessment-list-empty { color: var(--text-muted); padding: 4px 0; }

.district-stress-card {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.district-stress-card h3 {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--fao-blue-dark);
  margin-bottom: 8px;
  flex-shrink: 0;
}

.stress-list {
  list-style: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.stress-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.stress-item.is-open { background: var(--fao-blue-light); margin: 0 -6px; padding: 8px 6px; border-radius: 4px; }
.stress-item:last-child { border-bottom: none; }

.stress-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 0.65rem;
}
.stress-map-link {
  color: var(--fao-blue);
  font-weight: 600;
  text-decoration: none;
}
.stress-map-link:hover { text-decoration: underline; }
.stress-detail-panel { margin-top: 6px; }

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

.stress-name-row { display: flex; align-items: center; gap: 8px; }

.stress-rank {
  width: 18px; height: 18px;
  background: var(--fao-blue-light);
  color: var(--fao-blue-dark);
  border-radius: 50%;
  font-size: 0.62rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.stress-name { font-size: 0.76rem; font-weight: 600; }
.stress-value { font-size: 0.76rem; font-weight: 700; }

.stress-bar {
  height: 8px;
  background: #e8e8e8;
  border-radius: 5px;
  overflow: hidden;
  display: flex;
  margin-bottom: 2px;
}
.stress-bar-seg { height: 100%; }

.stress-meta { font-size: 0.65rem; color: var(--text-muted); }

/* Historical drought chart */
.home-history-section {
  flex-shrink: 0;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px 20px;
}

.home-history-card {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.home-history-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--border);
}

.home-history-header h2 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--fao-blue-dark);
  margin-bottom: 2px;
}

.home-history-header p {
  font-size: 0.74rem;
  color: var(--text-secondary);
}

.home-history-keys {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: 7px 14px;
  background: rgba(95, 130, 195, 0.08);
  border-bottom: 1px solid rgba(65, 95, 160, 0.15);
}

.history-keys-modal {
  margin-bottom: 10px;
  border: 1px solid rgba(65, 95, 160, 0.15);
  border-radius: var(--radius);
  background: rgba(95, 130, 195, 0.08);
}

.history-key-item {
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.35;
}

.history-key-swatch {
  flex-shrink: 0;
  width: 28px;
  height: 14px;
  border-radius: 3px;
  background: rgba(95, 130, 195, 0.24);
  border: 2px solid rgba(65, 95, 160, 0.7);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
}

.history-key-cdi-line {
  flex-shrink: 0;
  width: 28px;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, #930905, #d03a27, #e6987b, #FFFF80, #00A000);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.history-key-line {
  flex-shrink: 0;
  width: 28px;
  height: 0;
  border-top: 2px dashed rgba(90, 90, 90, 0.65);
}

.history-key-threshold .history-key-label {
  color: #555;
  font-weight: 500;
}

#home-map .district-label-icon { background: transparent !important; border: none !important; }
#home-map .district-label-text {
  font-size: 9px;
  font-weight: 700;
  color: #222;
  text-shadow:
    -1px -1px 0 #fff, 1px -1px 0 #fff,
    -1px 1px 0 #fff, 1px 1px 0 #fff,
    0 0 4px #fff, 0 0 4px #fff;
  white-space: nowrap;
  pointer-events: none;
}

.history-key-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: #2A4070;
  line-height: 1.35;
}

.home-history-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.history-action-btn {
  padding: 4px 8px;
  font-size: 0.68rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  color: var(--fao-blue-dark);
  cursor: pointer;
  font-family: var(--font);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.history-action-btn:hover { background: var(--fao-blue-light); }

.home-history-chart-wrap {
  height: 320px;
  padding: 6px 12px 2px;
  background: #FAFBFC;
}

.home-history-source {
  font-size: 0.65rem;
  color: var(--text-muted);
  padding: 4px 14px 10px;
}

.history-expand-box { max-width: 1100px; width: 100%; }
.history-expand-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}
.history-expand-header h3 { font-size: 1rem; color: var(--fao-blue-dark); }
.history-expand-header p { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; }
.history-expand-chart-wrap { height: 500px; margin-bottom: 14px; }
.history-expand-actions { display: flex; gap: 8px; justify-content: flex-end; }

@media (max-width: 1000px) {
  .home-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 380px;
    overflow: visible;
  }
  .home-map-card { min-height: 380px; height: auto; }
  .district-stress-card { max-height: 360px; }
  .home-history-chart-wrap { height: 260px; }
}

@media (max-width: 600px) {
  .home-layout { padding: 10px 12px; }
  .home-map-card { min-height: 320px; }
}
