* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
:root {
  --ink: #1f2a44;
  --text: #222;
  --muted: #667085;
  --line: #e1e5ec;
  --panel: #f7f8fa;
  --accent: #2b6cb0;
  --accent-soft: #e8f0fa;
}
html, body {
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 13px;
  color: var(--text);
  background: #fff;
}
button { font: inherit; color: inherit; }
.hidden { display: none !important; }

#container {
  height: 100%;
  width: 100%;
  display: grid;
  grid-template-columns: clamp(240px, 24vw, 300pt) 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "header header"
    "selectionPanel main"
    "footer footer";
}

/* ---- header: view tabs (top left) + title ---- */
#header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
#viewTabs { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.view-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted);
}
/* segmented control: one rounded box, the active view is an inner highlighted box */
.segmented {
  display: flex; gap: 2px; padding: 3px;
  background: #eef1f5; border: 1px solid var(--line); border-radius: 10px;
}
.view-tab {
  display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15;
  padding: 5px 14px; border: none; border-radius: 7px;
  background: transparent; color: var(--muted); cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.view-tab:hover:not(.active) { color: var(--text); background: rgba(255, 255, 255, 0.55); }
.view-tab.active {
  background: var(--ink); color: #fff;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.25);
}
.view-tab-name { font-weight: 600; font-size: 13px; }
.view-tab-task { font-size: 10.5px; opacity: 0.75; }
#title { display: flex; flex-direction: column; min-width: 0; }
.title-main { font-weight: 700; font-size: 15px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title-sub { font-size: 11.5px; color: var(--muted); }

#selectionPanel {
  grid-area: selectionPanel; overflow-y: auto; padding: 10px 12px;
  background: var(--panel); border-right: 1px solid var(--line); min-height: 0;
}
.view { grid-area: main; min-height: 0; min-width: 0; overflow: hidden; }
#footer {
  grid-area: footer; padding: 4px 12px; font-size: 11px; color: var(--muted);
  border-top: 1px solid var(--line);
}

/* ---- selection panel ---- */
.panel-section {
  margin-bottom: 12px; padding: 8px 10px; background: #fff;
  border: 1px solid var(--line); border-radius: 8px;
}
.panel-section h3 { font-size: 12.5px; margin: 2px 0 4px; color: var(--ink); }
.section-header { display: flex; justify-content: space-between; align-items: center; }
.clear-btn {
  font-size: 11px; padding: 1px 8px; border: 1px solid var(--line); border-radius: 4px;
  background: #fff; cursor: pointer; color: var(--muted);
}
.clear-btn:hover { color: var(--text); border-color: #b8c4d6; }
.section-note { font-size: 11px; color: var(--muted); margin: -2px 0 4px; }
.section-note:empty { display: none; }
#referenceSelect, .panel-section input[type="search"] {
  width: 100%; padding: 4px 6px; margin: 2px 0 6px;
  border: 1px solid #ccd3de; border-radius: 4px; background: #fff; font: inherit;
}
.check-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: 4px; padding: 2px 4px; }
.check-group-title { font-weight: 600; color: var(--muted); margin-top: 4px; font-size: 11.5px; }
.check-item { display: flex; gap: 4px; align-items: baseline; padding: 1px 0 1px 6px; cursor: pointer; border-radius: 3px; }
.check-item:hover { background: var(--panel); }
.check-item input:disabled + span { color: #aaa; }
.missing-note { color: #999; font-size: 11px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0 6px; }
.chips:empty { display: none; }
.chip {
  font-size: 11px; padding: 2px 8px; border: 1px solid #c9d6ea; border-radius: 10px;
  background: var(--accent-soft); color: var(--ink); cursor: pointer;
}
.chip:hover { background: #d6e3f5; }

/* ---- geospatial view (Task 2): one card per selected indicator ----
   number of columns and card size are set in geoVis.ts (layout) to give the largest maps;
   container queries keep the map area at the proportions of Italy inside each card. */
/* contain: size -> the height of the view never depends on the cards inside it (Safari) */
#geoVis { padding: 10px; overflow: hidden; position: relative; contain: size layout; }
.geo-grid {
  height: 100%;
  display: flex; flex-wrap: wrap; gap: 10px;
  justify-content: center; align-content: flex-start;
}
.geo-hint {
  position: absolute; inset: 10px; display: flex; align-items: center; justify-content: center;
  border: 1px dashed #ccd3de; border-radius: 10px; color: var(--muted); font-size: 13px; text-align: center; padding: 24px;
}
.geo-panel {
  flex: none; display: flex; flex-direction: column; min-width: 0; min-height: 0;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; overflow: hidden;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}
.geo-panel-header { height: 58px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); flex: none; }
.geo-slot { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.geo-title {
  font-weight: 600; color: var(--ink); line-height: 1.25; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.geo-meta { font-size: 11px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* card body: the map (proportions of Italy, as large as possible) + its legend */
.geo-map-body {
  flex: 1; min-height: 0; padding: 8px;
  display: flex; justify-content: center; align-items: center; gap: 0;
  container-type: size;
}
.geo-map {
  flex: none;
  width: min(100cqw - 64px, 100cqh * var(--map-ratio));
  aspect-ratio: var(--map-ratio);
  position: relative;
}
.geo-legend { flex: none; width: 64px; align-self: flex-start; margin-top: 24px; }
/* absolute: the svg never changes the size of its box (that comes from the card) */
.geo-svg { display: block; overflow: visible; position: absolute; top: 0; left: 0; }
.geo-square { stroke: rgba(31, 42, 68, 0.35); stroke-width: 0.6; cursor: pointer; }
.geo-square.na { stroke: none; }
.geo-square.na.hovered { stroke: #111; stroke-width: 1; stroke-dasharray: 2 2; }
.geo-na-cross { fill: none; stroke-width: 1.6; stroke-linecap: round; pointer-events: none; opacity: 0.9; }
.geo-label.na { font-weight: 500; }
.geo-square.hovered { stroke: #111; stroke-width: 2; }
.geo-label { text-anchor: middle; dominant-baseline: central; font-weight: 600; pointer-events: none; }
.geo-selected { fill: none; stroke-width: 2.5; pointer-events: none; }
.geo-legend-value { font-size: 10.5px; font-weight: 600; fill: #344054; dominant-baseline: middle; }
.geo-legend-word { font-size: 10px; font-weight: 700; fill: #344054; text-anchor: start; text-transform: uppercase; letter-spacing: 0.04em; }
.geo-legend-label { font-size: 9.5px; fill: var(--muted); dominant-baseline: middle; }

/* ---- clustering view (Task 3) ---- */
#clusterPanel {
  grid-area: selectionPanel; overflow-y: auto; padding: 10px 12px;
  background: var(--panel); border-right: 1px solid var(--line); min-height: 0;
}
.cl-blocks { display: flex; flex-direction: column; }
.cl-blocks.indicators-first .cl-ind-section { order: -1; }
.cl-mode { padding-left: 0; font-weight: 600; color: var(--ink); }
.cl-k-list { display: flex; flex-direction: column; gap: 2px; }
.cl-k-row {
  display: flex; align-items: center; gap: 8px; padding: 3px 6px;
  border: 1px solid transparent; border-radius: 6px; cursor: pointer;
}
.cl-k-row:hover { background: var(--panel); }
.cl-k-row.active { background: var(--accent-soft); border-color: #9db4d4; }
.cl-k-label { width: 38px; font-weight: 600; color: var(--ink); font-size: 12px; }
.cl-tri-frame { fill: none; stroke: #c9ced6; stroke-width: 1; }
.cl-tri { fill: #4e79a7; fill-opacity: 0.55; stroke: #2f4f75; stroke-width: 1; }
.cl-ind-list { max-height: 46vh; }
.cl-ind-row { align-items: center; }
/* placeholder card shown in the clustering view while no indicator is selected (as .geo-hint) */
.cl-panel.cl-hint-card {
  border: 1px dashed #ccd3de; background: transparent; box-shadow: none;
  display: flex; align-items: center; justify-content: center;
}
.cl-hint-text { color: var(--muted); font-size: 13px; text-align: center; padding: 24px; max-width: 360px; line-height: 1.5; }
.cl-hint-link { color: var(--accent); font-weight: 600; text-decoration: underline dotted; cursor: help; }
.cl-ind-section { transition: box-shadow 0.15s, border-color 0.15s; }
.cl-ind-section.flash { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cl-ind-row.disabled { cursor: default; }
.cl-ind-row.disabled .cl-ind-name, .cl-ind-row.disabled .cl-rank { color: #aab0ba; }
.cl-ind-row.disabled .cl-score-fill { background: #d5d9e0; }
.cl-rank { color: var(--muted); font-size: 10.5px; width: 20px; flex: none; text-align: right; }
.cl-ind-name { flex: 1; min-width: 0; }
.cl-score { flex: none; width: 44px; height: 6px; background: #eef1f5; border-radius: 3px; overflow: hidden; }
.cl-score-fill { display: block; height: 100%; background: #8aa4c8; }

#clusterVis { padding: 10px; overflow: hidden; position: relative; contain: size layout; }
.cl-grid { height: 100%; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-content: flex-start; }
.cl-panel-header { height: 84px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); flex: none; }
.cl-controls { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; align-items: center; }
.cl-control-hint { font-size: 11px; color: var(--muted); font-style: italic; }
.cl-seg { display: flex; align-items: center; gap: 0; }
.cl-seg-btn + .cl-seg-btn { margin-left: -1px; } /* attached buttons, one shared border */
.cl-mean-switch { display: flex; flex-direction: column; gap: 2px; margin-top: 2px; }
.cl-mean-switch .cl-seg-label { display: flex; align-items: center; gap: 4px; color: #344054; font-size: 10px; }
.cl-mean-icon { width: 8px; height: 8px; border: 2px solid #1f2a44; border-radius: 50%; background: #fff; flex: none; }
.cl-seg-label { font-size: 10.5px; color: var(--muted); margin-right: 3px; }
.cl-seg-btn {
  font-size: 10.5px; padding: 1px 7px; border: 1px solid var(--line); background: #fff;
  cursor: pointer; color: var(--muted);
}
.cl-seg-btn:first-of-type { border-radius: 4px 0 0 4px; }
.cl-seg-btn:last-of-type { border-radius: 0 4px 4px 0; }
.cl-seg-btn.active { background: var(--ink); color: #fff; border-color: var(--ink); }
/* as in the geospatial view: map centred in the card, legend / dot chart column at the top right */
.cl-body { flex: 1; min-height: 0; padding: 8px; display: flex; justify-content: center; align-items: center; }
/* the map is centred in the space left of the side column, which stays at the right edge of the card */
.cl-map { flex: none; position: relative; margin: 0 auto; }
.cl-side { flex: none; width: 128px; align-self: flex-start; margin-top: 8px; }
/* the cluster overview card stands apart from the cartograms: light blue background */
.cl-panel.cl-overview { background: #eef5fc; border-color: #c9dcf0; }
.cl-panel.cl-overview .cl-panel-header { border-bottom-color: #c9dcf0; }
.cl-overview .cl-legend-row:hover { background: #dde9f6; }
.cl-province { stroke: #fff; stroke-width: 0.4; cursor: pointer; }
/* hovering a cluster in the cluster map: its squares get a thicker outline in the cartograms */
/* colour = value with a cluster selected: provinces outside the cluster are empty grey squares */
.cl-panel .geo-square.outside { fill: none; stroke: #c3c9d2; stroke-width: 0.8; pointer-events: all; } /* still clickable inside */
.cl-panel .geo-square.outside.hovered { stroke: #111; stroke-width: 2; }
.cl-panel .geo-square.cluster-hovered { stroke: #1f2a44; stroke-width: 1.8; }
/* brushing box over a cartogram */
.cl-brush { fill: rgba(43, 108, 176, 0.08); stroke: #2b6cb0; stroke-width: 1; stroke-dasharray: 4 3; pointer-events: none; }
.cl-province.hovered { stroke: #111; stroke-width: 1.5; }
.cl-province-selected { fill: none; stroke-width: 2.5; pointer-events: none; }
.cl-legend { display: flex; flex-direction: column; gap: 2px; padding-left: 6px; }
/* same horizontal padding as the rows below (4px + 1px border), so "Size" sits above the numbers */
.cl-legend-title {
  display: flex; justify-content: space-between; padding: 0 5px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: #344054; margin-bottom: 2px;
}
.cl-legend-row {
  display: flex; align-items: center; gap: 6px; padding: 2px 4px; border: 1px solid transparent;
  border-radius: 4px; background: none; cursor: pointer; font-size: 11.5px; text-align: left;
}
.cl-legend-row:hover { background: var(--panel); }
.cl-legend-row.active { border-color: #1f2a44; font-weight: 700; }
.cl-legend-row.dim { opacity: 0.4; }
.cl-swatch { width: 14px; height: 14px; border-radius: 2px; flex: none; }
.geo-label.on-texture { paint-order: stroke; stroke: #fff; stroke-width: 2.5px; stroke-linejoin: round; }
.cl-legend-size { margin-left: auto; color: var(--muted); }
.cl-legend-note { font-size: 9.5px; color: var(--muted); margin-top: 2px; }
.cl-axis { stroke: #98a2b3; stroke-width: 2; }
.cl-mean { fill: #fff; stroke: #1f2a44; stroke-width: 2.2; }
.cl-ref { fill: #1f2a44; }
.cl-dot-value { font-size: 10.5px; fill: #1f2a44; dominant-baseline: middle; }
.cl-dot-value.ref { font-weight: 700; }
.cl-dot-name { font-size: 9.5px; fill: #667085; dominant-baseline: middle; }
.cl-dot-key text { font-size: 10px; fill: #344054; dominant-baseline: middle; }

/* ---- vista multivariata (Task 1): dot chart ---- */
#multivariateVis { overflow-y: auto; }
.mv-svg { display: block; font-size: 12px; }
.legend text { font-size: 12px; }
.legend-hint { fill: #666; font-style: italic; font-size: 11px; }
.row-label { font-size: 12.5px; font-weight: 600; fill: #222; cursor: help; }
.row-unit { font-size: 11px; fill: #666; }
.dot-axis text { fill: #555; font-size: 10.5px; }
.dot-axis path, .dot-axis line { stroke: #999; }
.dot-axis .max-tick text { font-weight: 700; fill: #333; }
.dot-segment { stroke-width: 5; stroke-linecap: round; opacity: 0.85; }
.ref-mark { cursor: help; }
.mean-mark { fill: white; stroke: #1f2a44; stroke-width: 2.5; cursor: pointer; }
.mean-mark:hover { stroke-width: 3.5; }
.ref-label { font-size: 11px; font-weight: 700; fill: #1f2a44; pointer-events: none; }
.mean-label { font-size: 11px; fill: #1f2a44; pointer-events: none; }
.lane { stroke: #e2e2e2; }
.lane-label { font-size: 10.5px; fill: #555; }
.province-mark { cursor: help; }
.row-bg { fill: #f4f6fa; }
.row-bg.hover { fill: #f4f6fa; stroke: #c9d3e3; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.15)); }
.hover-overlay { pointer-events: none; }
.row-bg.pinned { fill: #eaf0f8; stroke: #9db4d4; stroke-dasharray: 4,3; }
.na-label { font-size: 11px; font-weight: 700; }
.hint { color: #666; padding: 12px; }

#tooltip {
  display: none;
  position: absolute;
  z-index: 1070;
  background-color: white;
  border: 1px solid #888;
  border-radius: 4px;
  padding: 5px;
  pointer-events: none;
  white-space: pre-line;
  font-size: 12px;
}
