:root {
  --bg-a: #f0f7f4;
  --bg-b: #fdf9ef;
  --ink: #1c2a2f;
  --muted: #586b73;
  --accent: #0f766e;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-border: rgba(28, 42, 47, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 12%, #c7f0da 0%, transparent 40%),
    radial-gradient(circle at 88% 88%, #ffe8bb 0%, transparent 42%),
    linear-gradient(135deg, var(--bg-a), var(--bg-b));
  min-height: 100vh;
}

.shell {
  display: grid;
  grid-template-columns: minmax(290px, 360px) 1fr;
  height: 100vh;
  min-height: 100vh;
}

.panel {
  padding: 1.2rem 1rem 1.4rem;
  border-right: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(10px);
  height: 100vh;
  overflow: auto;
}

.eyebrow {
  margin: 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

h1 {
  margin: 0.4rem 0 0.35rem;
  font-size: 1.45rem;
}

.intro {
  margin: 0 0 1rem;
  font-size: 0.92rem;
  line-height: 1.35;
  color: var(--muted);
}

.stats {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.68);
}

.label {
  font-size: 0.82rem;
  color: var(--muted);
}

.value {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.9rem;
  font-weight: 600;
}

.filters,
.legend {
  margin-top: 1rem;
}

.search-box {
  margin-top: 1rem;
}

.methodology {
  margin-top: 1rem;
}

.methodology details {
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
  padding: 0.5rem 0.6rem;
}

.methodology summary {
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink);
}

.methodology-body {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
  display: grid;
  gap: 0.3rem;
}

.methodology-body h3 {
  margin: 0.2rem 0 0;
  font-size: 0.76rem;
  color: var(--ink);
}

.methodology-body p {
  margin: 0;
  line-height: 1.35;
}

.methodology-body ul {
  margin: 0.1rem 0 0.2rem 1rem;
  padding: 0;
  display: grid;
  gap: 0.18rem;
}

.methodology-body code {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  color: var(--ink);
}

h2 {
  margin: 0 0 0.45rem;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
}

#comune-search {
  width: 100%;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.5rem 0.55rem;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.86rem;
  background: rgba(255, 255, 255, 0.86);
}

.suggestions {
  margin: 0.35rem 0 0;
  padding: 0.2rem;
  list-style: none;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  max-height: 190px;
  overflow: auto;
}

.suggestions li {
  padding: 0.36rem 0.45rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
}

.suggestions li:hover {
  background: rgba(15, 118, 110, 0.09);
}

.suggestions .meta {
  color: var(--muted);
  margin-left: 0.35rem;
}

.filter {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.2rem 0.5rem;
  margin-bottom: 0.7rem;
}

.filter span {
  font-size: 0.8rem;
  color: var(--muted);
}

.filter output {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
}

.filter > input[type="range"],
.filter > input[type="number"] {
  grid-column: 1 / -1;
  width: 100%;
}

.filter select {
  grid-column: 1 / -1;
  width: 100%;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.42rem 0.5rem;
  background: rgba(255, 255, 255, 0.85);
  font-family: "Space Grotesk", sans-serif;
}

.hint-inline {
  grid-column: 1 / -1;
  margin: 0.1rem 0 0;
  font-size: 0.73rem;
  color: var(--muted);
}

.ftth-control {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto 54px;
  gap: 0.35rem;
  align-items: center;
}

.step-btn {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  padding: 0.36rem 0.3rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
  cursor: pointer;
}

.step-btn:hover {
  background: rgba(255, 255, 255, 0.96);
}

#ftth-input,
#budget-input {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.38rem 0.45rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem;
}

#ftth-input {
  grid-column: auto;
  width: 100%;
}

.unit {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.76rem;
  color: var(--muted);
}

.checkline {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.76rem;
  color: var(--muted);
}

.checkline input {
  width: auto;
}

.toggle-row {
  display: grid;
  gap: 0.3rem;
  margin-bottom: 0.8rem;
}

.toggle-option {
  display: block;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--panel-border);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.7);
  font-size: 0.83rem;
}

.zone-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.3rem;
}

.zone-grid label {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  justify-content: center;
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  padding: 0.24rem 0.1rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  background: rgba(255, 255, 255, 0.7);
}

.bucket-grid {
  grid-column: 1 / -1;
  display: grid;
  gap: 0.25rem;
}

.bucket-grid label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  padding: 0.28rem 0.4rem;
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.75rem;
  color: var(--ink);
}

.bucket-grid input {
  width: auto;
}

.reset-btn {
  margin-top: 0.2rem;
  width: 100%;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.48rem 0.55rem;
  background: #eaf7ef;
  color: var(--ink);
  font-weight: 600;
  font-family: "Space Grotesk", sans-serif;
  cursor: pointer;
}

.reset-btn:hover {
  background: #def2e6;
}

.filters-progress {
  margin-top: 0.45rem;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.42rem 0.5rem 0.48rem;
  background: rgba(255, 255, 255, 0.74);
}

.filters-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
  margin-bottom: 0.3rem;
  font-size: 0.72rem;
  color: var(--muted);
}

#filters-progress-value {
  font-family: "IBM Plex Mono", monospace;
  color: var(--ink);
}

.filters-progress-track {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: rgba(28, 42, 47, 0.12);
  overflow: hidden;
}

.filters-progress-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #0d9488, #16a34a);
  transition: width 120ms linear;
}

.best-match {
  margin-top: 1rem;
}

.ws-weights-grid {
  display: grid;
  gap: 0.35rem;
}

.ws-weights-grid label {
  display: grid;
  gap: 0.2rem;
}

.ws-weights-grid span {
  font-size: 0.8rem;
  color: var(--muted);
}

.ws-weights-grid input {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.36rem 0.45rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem;
}

.ws-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.ws-reset {
  background: #f5f5f5;
}

.ws-reset:hover {
  background: #ececec;
}

.bestmatch-list {
  margin: 0.3rem 0 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 0.28rem;
}

.bestmatch-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.77rem;
}

.bm-name {
  color: var(--ink);
}

.bm-score {
  font-family: "IBM Plex Mono", monospace;
  color: var(--accent);
}

.zone-legend {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.25rem;
}

.zone-legend span {
  display: flex;
  align-items: center;
  gap: 0.22rem;
  justify-content: center;
  padding: 0.25rem 0.05rem;
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  background: rgba(255, 255, 255, 0.7);
}

.zone-legend i {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  display: inline-block;
}

.zone-legend i[data-zone="A"] { background: #0f172a; }
.zone-legend i[data-zone="B"] { background: #0d9488; }
.zone-legend i[data-zone="C"] { background: #16a34a; }
.zone-legend i[data-zone="D"] { background: #f59e0b; }
.zone-legend i[data-zone="E"] { background: #f97316; }
.zone-legend i[data-zone="F"] { background: #b91c1c; }

.bucket-legend {
  display: grid;
  gap: 0.2rem;
}

.degree-sublevels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.25rem;
  margin-bottom: 0.35rem;
}

.degree-sublevels span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.2rem 0.1rem;
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  font-size: 0.72rem;
  background: rgba(255, 255, 255, 0.7);
}

.degree-sublevels i {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
}

.degree-sublevels i[data-level="low"] { background: #74c69d; }
.degree-sublevels i[data-level="mid"] { background: #f9b04b; }
.degree-sublevels i[data-level="high"] { background: #c1121f; }

.bucket-legend span {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.74rem;
  color: var(--ink);
}

.bucket-legend i {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
}

.bucket-legend i[data-bucket="A"] { background: #2f9e44; }
.bucket-legend i[data-bucket="B"] { background: #74c69d; }
.bucket-legend i[data-bucket="C"] { background: #ffd166; }
.bucket-legend i[data-bucket="D"] { background: #f8961e; }
.bucket-legend i[data-bucket="E"] { background: #f3722c; }
.bucket-legend i[data-bucket="F"] { background: #c1121f; }

.ftth-scale {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: linear-gradient(
    90deg,
    #ffffff 0%,
    #ffffff 1%,
    #c1121f 1.1%,
    #ffd166 75%,
    #ffd166 76%,
    #2f9e44 100%
  );
}

.ws-scale {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: linear-gradient(90deg, #c1121f 0%, #ffd166 50%, #2f9e44 100%);
}

.ftth-scale-labels {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.22rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  color: var(--muted);
}

.cost-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.45rem;
  margin-top: 0.35rem;
  font-size: 0.75rem;
}

.cost-grid span {
  color: var(--muted);
}

.cost-grid strong {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
}

.step-btn:disabled,
#ftth-input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.hidden {
  display: none;
}

.legend-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 0.3rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
}

.hint {
  margin: 0.4rem 0 0;
  font-size: 0.76rem;
  color: var(--muted);
}

.legend-note {
  margin: 0.32rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
}

.map-wrap {
  position: relative;
  height: 100vh;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
}

.status {
  position: absolute;
  left: 1rem;
  bottom: 1rem;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(16, 24, 32, 0.72);
  color: #f4f7f9;
  font-size: 0.8rem;
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .panel {
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--panel-border);
    max-height: 42vh;
  }

  .map-wrap {
    height: 58vh;
  }

  #map {
    height: 100%;
  }

  .zone-grid,
  .zone-legend {
    grid-template-columns: repeat(3, 1fr);
  }
}
