/* ==========================================================================
   panel.css - Dark theme profile panel stylesheet for PSF
   ========================================================================== */

/* --- Custom Properties added by panel.css --- */
:root {
  --surface: #161e29;
  --accent-strong: #7fd8f5;
  --accent-soft: rgba(76, 201, 240, 0.14);
  --prov: #2ec4b6;
  --reg: #b392f0;
  --c1: #2892c7;
  --c2: #a0c29b;
  --c3: #fafa64;
  --c4: #e88d34;
  --c5: #e81014;
  --fl1: #F9E154;
  --fl2: #F39C12;
  --fl3: #C0392B;
  --unexposed: #2a3646;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.45);
  --grid: #334155;
  --band: rgba(255, 255, 255, 0.03);
  --bar-edge: rgba(230, 237, 243, 0.25);
}

/* --- Panel Container Setup --- */
#panel {
  container-type: inline-size;
  container-name: panel;
}

#panel [hidden] {
  display: none !important;
}

/* --- Entrance & Rise Keyframes --- */
@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes pf-rise {
  from {
    height: var(--pf-from);
  }
  to {
    height: var(--pf-level);
  }
}

@keyframes pane-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes exp-fill {
  from {
    color: var(--unexposed);
    transform: translateY(5px);
  }
  to {
    color: var(--accent);
    transform: none;
  }
}

/* --- Place Header (Top Card) --- */
#panel #place-head {
  position: relative;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#panel #panel-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color 150ms ease;
}

#panel #panel-close:hover {
  color: var(--text);
}

#panel #place-name {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  letter-spacing: -0.01em;
  padding-right: 32px;
}

#panel #place-sub {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.4;
}

#panel #place-ranks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

#panel .rank-chip {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  padding: 3px 9px;
  border-radius: 999px;
  color: #0a0e14;
  white-space: nowrap;
}

#panel .rank-chip.c1 { background-color: var(--c1); }
#panel .rank-chip.c2 { background-color: var(--c2); }
#panel .rank-chip.c3 { background-color: var(--c3); }
#panel .rank-chip.c4 { background-color: var(--c4); }
#panel .rank-chip.c5 { background-color: var(--c5); }

#panel .rank-chip.na {
  background-color: var(--na);
  color: var(--text);
}

/* --- Flood Figure --- */
#panel #flood-figure {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
  padding: 14px 4px 2px;
  border-top: 1px solid var(--border);
  animation: panel-in 380ms cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

#panel .pf-stage {
  position: relative;
  flex: 0 0 auto;
  width: 96px;
  height: 150px;
  border-radius: 8px;
  overflow: hidden;
  background-color: var(--accent-soft);
}

#panel .pf-text {
  min-width: 0;
}

#panel .pf-person {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 6px;
}

#panel .pf-person svg {
  width: 48px;
  height: 122px;
  fill: var(--muted);
}

#panel .pf-water {
  --pf-level: 0%;
  --pf-from: 0%;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--pf-level);
  background-image:
    linear-gradient(180deg, rgba(46, 155, 214, 0.62) 0%, rgba(20, 96, 150, 0.78) 100%);
  border-top: 1px solid rgba(255, 255, 255, 0.55);
  animation: pf-rise 1400ms cubic-bezier(0.22, 0.61, 0.36, 1) 260ms both;
}

#panel .pf-scale {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#panel .pf-tick {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px dashed var(--bar-edge);
}

#panel .pf-tick span {
  position: absolute;
  right: 3px;
  top: -8px;
  padding: 0 3px;
  border-radius: 3px;
  background-color: var(--panel-2);
  font-size: 10px;
  font-weight: 600;
  line-height: 1.5;
  color: var(--muted);
}

#panel .pf-caption {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-strong);
  line-height: 1.25;
  margin-bottom: 2px;
}

#panel .pf-sub {
  font-size: 13px;
  color: var(--text);
  line-height: 1.35;
  margin-bottom: 6px;
}

#panel .pf-note {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
  max-width: 62ch;
}

/* --- Notes in Workspace and Main --- */
#panel .note,
#panel #footnote {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

/* --- Main Content Section (Chart & Data Card) --- */
#panel #main {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Tab Bar */
#panel #tabs {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

#panel #tablist {
  display: flex;
  align-items: center;
  gap: 8px;
}

#panel #tablist button {
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  transition: all 120ms ease;
}

#panel #tablist button:hover {
  color: var(--text);
}

#panel #tablist button[aria-selected="true"] {
  color: var(--accent);
  font-weight: 600;
  border-bottom: 3px solid var(--accent);
  background-color: transparent;
}

/* Vulnerability Menu */
#panel #vul-menu {
  position: absolute;
  z-index: 20;
  min-width: 190px;
  padding: 6px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 8px);
  box-shadow: var(--shadow-dropdown);
}

#panel #vul-menu button {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 13.5px;
  color: var(--text);
  text-align: left;
}

#panel #vul-menu button:hover,
#panel #vul-menu button:focus-visible {
  background-color: var(--accent-soft);
  color: var(--accent-strong);
}

/* Back to Risk */
#panel #back-to-risk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  margin-bottom: 4px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  background-color: var(--surface);
}

#panel #back-to-risk:hover {
  color: var(--accent-strong);
  border-color: var(--accent);
}

/* Chart Row Layouts */
/* row-fig is the Hazard tab: the water level figure, then the histogram. row-2 is a spider or the exposure figure beside a histogram. */
#panel #chart-row {
  display: block;
}

#panel #main.row-fig #chart-row,
#panel #main.row-2 #chart-row {
  display: grid;
  align-items: center;
  gap: 18px;
}

#panel #main.row-fig #chart-row {
  grid-template-columns: 232px minmax(0, 1fr);
}

#panel #main.row-2 #chart-row {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
}

#panel #main.row-2 #chart {
  max-width: none;
  margin: 0;
  height: clamp(300px, 38vh, 430px);
}

#panel #main.row-2 #exposure {
  align-self: start;
}

/* Exposure reads people figure, histogram, table. #exposure dissolves into the grid so its two
   children and the histogram can be placed apart: the figure across the top, then the histogram
   beside the table, stacked when the panel is narrow. */
#panel #main.tab-exp #exposure:not([hidden]) {
  display: contents;
}

#panel #main.tab-exp #chart-row {
  align-items: start;
  grid-template-areas: "people people" "hist table";
}

#panel #main.tab-exp #exp-people {
  grid-area: people;
}

#panel #main.tab-exp #side-hist {
  grid-area: hist;
}

#panel #main.tab-exp .exp-table {
  grid-area: table;
}

#panel #main.row-fig #flood-figure {
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  max-width: 230px;
  padding: 0;
  border-top: none;
}

/* Side Histogram */
#panel #side-hist {
  min-width: 0;
}

#panel #hist-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

#panel #hist-chart {
  width: 100%;
  height: clamp(320px, 44vh, 470px);
}

#panel #hist-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
}

#panel .hist-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

#panel .hist-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  border: 1px solid var(--bar-edge);
}

#panel #hist-note {
  margin-top: 4px;
}

/* --- Axis Tip (Body-Level Floating Tooltip) --- */
#axis-tip {
  position: fixed;
  z-index: 60;
  max-width: 320px;
  padding: 10px 12px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 8px);
  box-shadow: var(--shadow-dropdown);
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
}

#axis-tip strong {
  display: block;
  margin-bottom: 3px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
}

/* --- Pane & Content Transition --- */
#panel #pane {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#panel .pane-in {
  animation: pane-in 560ms cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

/* --- Ten People Figure --- */
#panel .exp-people-row {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  margin-bottom: 10px;
}

#panel .exp-person {
  display: inline-flex;
  width: 23px;
  height: 54px;
  color: var(--unexposed);
}

#panel .exp-person svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

#panel .exp-person-on {
  animation: exp-fill 380ms ease both;
  animation-delay: calc(var(--i) * 110ms);
}

#panel .exp-people-caption {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--accent-strong);
  margin-bottom: 2px;
}

#panel .exp-people-sub {
  margin-bottom: 12px;
}

#panel #chart-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

/* Series Toggle */
#panel #series-toggle {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

#panel label.series-item {
  display: inline-grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  column-gap: 8px;
  row-gap: 1px;
  cursor: pointer;
  padding: 6px 14px;
  border-radius: 9999px;
  background-color: var(--border);
  color: var(--text);
  user-select: none;
  transition: background-color 120ms ease;
}

#panel label.series-item:has(input[type="checkbox"]:checked) {
  background-color: var(--accent-soft);
}

#panel label.series-item input[type="checkbox"] {
  grid-column: 1;
  grid-row: 1 / span 2;
  margin: 0;
  cursor: pointer;
}

#panel label.series-item .series-swatch {
  grid-column: 2;
  grid-row: 1 / span 2;
  width: 26px;
  height: 10px;
  flex: none;
  display: inline-block;
  vertical-align: middle;
}

#panel .series-name {
  grid-column: 3;
  grid-row: 1;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
}

#panel .series-scope {
  grid-column: 3;
  grid-row: 2;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.2;
  color: var(--muted);
}

/* --- Radar Chart Dimensions --- */
#panel #chart {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  height: clamp(380px, 52vh, 560px);
}

/* --- Axis Key --- */
#panel #axis-key {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px 16px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

#panel .axis-key-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  column-gap: 10px;
  row-gap: 1px;
  align-items: start;
  font-size: 12px;
  line-height: 1.4;
}

#panel .axis-key-row > span {
  grid-column: 2;
}

#panel .axis-key-row-button {
  margin: -6px -8px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  background: none;
  font: inherit;
  text-align: left;
  color: inherit;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease;
}

#panel .axis-key-row-button:hover {
  background-color: var(--accent-soft);
  border-color: var(--accent);
}

#panel .axis-key-row-button:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#panel .axis-key-hint {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
}

#panel .axis-key-row-button[aria-expanded="true"] .axis-key-hint {
  color: var(--muted);
}

#panel .axis-key-row img,
#panel .axis-key-icon {
  grid-column: 1;
  grid-row: 1 / span 3;
  width: 20px;
  height: 20px;
  object-fit: contain;
  margin-top: 1px;
}

#panel .axis-key-text,
#panel .axis-key-body,
#panel .axis-key-content,
#panel .axis-key-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

#panel .axis-key-short,
#panel .axis-key-name,
#panel .axis-key-title,
#panel .axis-key-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

#panel .axis-key-label,
#panel .axis-key-full,
#panel .axis-key-indicator,
#panel .axis-key-desc {
  font-size: 12px;
  color: var(--muted);
}

#panel .axis-key-meaning,
#panel .axis-key-sense,
#panel .axis-key-far-out {
  font-size: 12px;
  color: var(--muted);
}

/* --- Exposure Tab Layout --- */
#panel #exposure {
  width: 100%;
}

/* --- Data Tables (Indicator & Exposure) --- */
#panel .ind-table,
#panel .exp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.4;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

#panel .exp-table {
  font-size: 17px;
}

#panel .ind-table thead,
#panel .exp-table thead {
  background-color: var(--panel-2);
  border-bottom: 1px solid var(--border);
}

#panel .ind-table th,
#panel .exp-table th {
  padding: 9px 12px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-align: left;
}

#panel .ind-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

#panel .exp-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

/* Zebra striping for table rows */
#panel .ind-table tbody tr:nth-child(even),
#panel .exp-table tbody tr:nth-child(even) {
  background-color: var(--band);
}

#panel .ind-table tbody tr:hover,
#panel .exp-table tbody tr:hover {
  background-color: var(--accent-soft);
}

#panel .ind-table tbody tr:last-child td,
#panel .exp-table tbody tr:last-child td {
  border-bottom: none;
}

/* Right-align numbers in tables */
#panel td.num,
#panel th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Spanning note row inside tables */
#panel .exp-table td.note {
  font-size: 12.5px;
  color: var(--muted);
  padding: 10px 12px;
  background-color: var(--panel-2);
}

/* ==========================================================================
   Container Query Breakpoints (scoped to #panel)
   ========================================================================== */

/* Below 1100px: 2-col axis key */
@container panel (max-width: 1100px) {
  #panel #axis-key {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Below 900px: Stack chart row and compact chart */
@container panel (max-width: 900px) {
  #panel #main.row-fig #chart-row,
  #panel #main.row-2 #chart-row {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
  }

  #panel #main.row-fig #side-hist,
  #panel #main.row-2 #side-hist,
  #panel #main.row-2 #exposure {
    width: 100%;
  }

  #panel #main.tab-exp #chart-row {
    grid-template-areas: "people" "hist" "table";
  }

  #panel #main.tab-exp #exp-people {
    width: 100%;
  }

  #panel #chart {
    height: 420px;
    min-height: 380px;
  }
}

/* Below 700px: 1-col axis key and table horizontal scroll */
@container panel (max-width: 700px) {
  #panel #axis-key {
    grid-template-columns: 1fr;
  }

  #panel .ind-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

/* Below 480px: Wrapping tabs */
@container panel (max-width: 480px) {
  #panel #tabs {
    flex-wrap: wrap;
    row-gap: 4px;
  }

  #panel #tablist button {
    padding: 8px 12px;
    font-size: 12.5px;
  }
}

/* Colour buildings by hazard (Hazard tab) */
#panel #bld-haz {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  margin-bottom: 14px;
}

#panel #bld-haz-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 8px;
}

#panel .bld-haz-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#panel .bld-haz-pick {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 8px;
  row-gap: 2px;
  align-items: center;
  padding: 6px 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
}

#panel .bld-haz-pick:hover {
  background-color: var(--accent-soft);
}

#panel .bld-haz-pick input {
  accent-color: var(--accent);
  margin: 0;
  width: 16px;
  height: 16px;
  grid-row: span 2;
}

#panel .bld-haz-name {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
}

#panel .bld-haz-levels {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 12px;
  color: var(--muted);
}

#panel .bld-haz-lv {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

#panel .bld-haz-lv i,
#panel .bld-haz-note i.bld-haz-none {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
  flex: 0 0 auto;
}

#panel .bld-haz-note {
  margin: 10px 0 0;
  font-size: 12px;
}

#panel .bld-haz-note i.bld-haz-none {
  vertical-align: -1px;
  margin: 0 4px 0 2px;
}
