/* Osservatorio dell'energia — styles */

:root {
  /* surface */
  --bg: #050506;
  --bg-panel: rgba(12, 12, 14, 0.94);
  --fg: #e9e6df;
  --muted: #8f8b83;
  --faint: #4a4844;
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.28);
  --focus: #ffffff;

  /* one colour per source (keys = dataset ids) */
  --c-bioenergy: #c98a4b;
  --c-coal: #8d97a6;
  --c-hydro: #3db8de;
  --c-geothermal: #ee6842;
  --c-natural_gas: #a3c4ff;
  --c-oil: #c04a63;
  --c-electricity_imports: #ab92f7;
  --c-nuclear: #c3f2bd;
  --c-wind: #5ed8b4;
  --c-solar: #f5d24b;
  --c-other: #727272;
  --c-default: #cfcfcf;

  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --font-sans: "Helvetica Neue", Helvetica, "Inter", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;

  --gutter: clamp(16px, 2.2vw, 32px);
  --panel-w: min(420px, 92vw);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { overflow: hidden; }

button { font: inherit; color: inherit; }

a { color: inherit; text-decoration-color: var(--faint); text-underline-offset: 2px; }
a:hover { text-decoration-color: var(--fg); }

:focus-visible { outline: 1px solid var(--focus); outline-offset: 2px; }

.app {
  position: relative;
  height: 100%;
  min-height: 420px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  isolation: isolate;
}

/* ---------- header ---------- */
.bar {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px 20px;
  padding: var(--gutter) var(--gutter) 0;
  flex-wrap: wrap;
}

.brand { min-width: 0; flex: 1 1 260px; }

.title {
  margin: 0;
  font-weight: 300;
  font-size: clamp(15px, 1.35vw, 22px);
  letter-spacing: 0.01em;
}

.sub,
.readout {
  margin: 4px 0 0;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.readout { max-width: 62ch; line-height: 1.5; }
.readout b { color: var(--fg); font-weight: 400; }

.controls { display: flex; gap: 8px; flex-wrap: wrap; }

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px;
}

.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  transition: background-color 0.2s, color 0.2s;
}

.seg button:hover { color: var(--fg); }
.seg button[aria-pressed="true"] { background: var(--fg); color: var(--bg); }

/* ---------- stage ---------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 300px;
}

.layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.overlay { overflow: visible; }
.overlay text { font-family: var(--font-mono); fill: var(--muted); pointer-events: none; }
.overlay .lbl-name { font-size: 9.5px; letter-spacing: 0.09em; fill: var(--fg); }
.overlay .lbl-share { font-size: 11px; fill: var(--fg); }
.overlay .lbl-year { font-size: 9px; letter-spacing: 0.06em; fill: var(--muted); }
.overlay .core-val,
.overlay .core-cap,
.overlay .other-lbl {
  paint-order: stroke;
  stroke: rgba(5, 5, 6, 0.85);
  stroke-width: 3px;
  stroke-linejoin: round;
}
.overlay .core-val { font-size: 13px; fill: var(--fg); }
.overlay .core-cap { font-size: 8.5px; letter-spacing: 0.1em; fill: var(--muted); }
.overlay .other-lbl { font-size: 9px; letter-spacing: 0.08em; fill: var(--c-other); }
.overlay.narrow .lbl-name { font-size: 8px; letter-spacing: 0.02em; }
.overlay.narrow .lbl-share { font-size: 10px; }

.overlay .label { transition: opacity 0.6s ease; }
.overlay .label.pre { opacity: 0; }
.overlay .label.dim { opacity: 0.3; }
.overlay .label.ghost .lbl-name,
.overlay .label.ghost .lbl-share { fill: var(--muted); }

.overlay .hit { cursor: pointer; outline: none; }
.overlay .hit-area { fill: transparent; stroke: none; }
.overlay .ring {
  fill: none;
  stroke: var(--focus);
  stroke-width: 1;
  stroke-dasharray: 2 3;
  opacity: 0;
  transition: opacity 0.15s;
}
.overlay .hit:focus-visible .ring { opacity: 0.9; }
.overlay .other-hit { fill: none; stroke: transparent; stroke-width: 18; cursor: pointer; }

.tooltip {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  max-width: 240px;
  padding: 8px 10px;
  background: rgba(10, 10, 12, 0.92);
  border: 1px solid var(--line);
  border-left: 2px solid var(--c, var(--fg));
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.45;
}
.tooltip b { display: block; font-weight: 400; letter-spacing: 0.08em; text-transform: uppercase; font-size: 10px; }
.tooltip span { color: var(--muted); }

.status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  pointer-events: none;
}
.status:empty { display: none; }

/* ---------- footer ---------- */
.foot {
  position: relative;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 0 var(--gutter) var(--gutter);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.foot button.link {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: inherit;
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--faint);
  text-underline-offset: 2px;
}

/* ---------- markers ---------- */
.mk {
  font-family: var(--font-mono);
  font-size: 0.75em;
  margin-left: 2px;
  color: var(--muted);
  cursor: help;
  vertical-align: super;
  line-height: 0;
}

/* ---------- panel ---------- */
.panel {
  position: absolute;
  z-index: 10;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--panel-w);
  background: var(--bg-panel);
  border-left: 1px solid var(--line);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transform: translateX(102%);
  transition: transform 0.35s cubic-bezier(0.2, 0.7, 0.2, 1), visibility 0s linear 0.35s;
  visibility: hidden;
  display: flex;
  flex-direction: column;
}
.panel.open {
  transform: none;
  visibility: visible;
  transition: transform 0.35s cubic-bezier(0.2, 0.7, 0.2, 1), visibility 0s;
}

.panel .close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.panel .close:hover { border-color: var(--line-strong); }

.panel-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 22px 32px;
  font-size: 13.5px;
  line-height: 1.55;
}

.p-head { padding-right: 40px; margin-bottom: 18px; }
.p-head .eyebrow {
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.swatch { width: 8px; height: 18px; background: var(--c); display: inline-block; }
.swatch.dashed { background: transparent; border: 1px dashed var(--c); }
.swatch.ghost { background: transparent; border: 1px solid var(--c); opacity: 0.6; }
.p-head h2 { margin: 0; font-weight: 300; font-size: 24px; line-height: 1.15; outline: none; }
.p-head .intro { margin: 8px 0 0; color: var(--muted); font-size: 12.5px; }
.p-head .intro-year { font-family: var(--font-mono); color: var(--fg); margin-right: 6px; }

.p-sec { border-top: 1px solid var(--line); padding: 14px 0 6px; }
.p-sec h3 {
  margin: 0 0 10px;
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.p-sec p { margin: 0 0 10px; }
.p-sec .note { font-size: 12px; color: var(--muted); }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.card { border: 1px solid var(--line); padding: 10px; }
.card.active { border-color: var(--line-strong); }
.card .k {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.card .v { font-size: 22px; font-weight: 300; line-height: 1.2; margin-top: 4px; }
.card .s { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }

dl.rows { margin: 0; }
dl.rows .row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  border-bottom: 1px dotted var(--line);
}
dl.rows .row:last-child { border-bottom: 0; }
dl.rows dt { color: var(--muted); font-size: 12.5px; }
dl.rows dd { margin: 0; font-family: var(--font-mono); font-size: 12px; text-align: right; white-space: nowrap; }
dl.rows .row.total dt, dl.rows .row.total dd { color: var(--fg); }

ul.bars, ul.tags, ul.plain { list-style: none; margin: 0; padding: 0; }
ul.bars li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  padding: 4px 0;
  font-size: 12.5px;
}
ul.bars .b-val { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); }
ul.bars .b-track { grid-column: 1 / -1; height: 3px; background: rgba(255, 255, 255, 0.06); }
ul.bars .b-fill { display: block; height: 100%; background: var(--c, var(--fg)); opacity: 0.85; }

ul.tags { display: flex; flex-wrap: wrap; gap: 6px; }
ul.tags li {
  border: 1px solid var(--line);
  padding: 3px 8px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
}

ul.plain li { padding: 6px 0; border-bottom: 1px dotted var(--line); font-size: 12.5px; }
ul.plain li:last-child { border-bottom: 0; }
ul.plain .meta { display: block; color: var(--muted); font-size: 11.5px; }
ul.plain .yr { font-family: var(--font-mono); margin-right: 8px; color: var(--fg); }

table.mix { width: 100%; border-collapse: collapse; font-size: 12px; }
table.mix th, table.mix td { padding: 4px 0; border-bottom: 1px dotted var(--line); text-align: right; font-weight: 400; }
table.mix th:first-child, table.mix td:first-child { text-align: left; }
table.mix thead th { font-family: var(--font-mono); font-size: 9.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
table.mix td { font-family: var(--font-mono); }
table.mix td:first-child { font-family: var(--font-sans); }
table.mix td.on, table.mix th.on { color: var(--fg); }
table.mix td.off { color: var(--muted); }
table.mix tfoot td { border-bottom: 0; border-top: 1px solid var(--line-strong); }
table.mix .dot { display: inline-block; width: 6px; height: 6px; margin-right: 8px; background: var(--c); vertical-align: middle; }

.refs li { font-size: 12px; }

/* ---------- mobile: bottom sheet ---------- */
@media (max-width: 640px) {
  :root { --gutter: 16px; }
  .bar { gap: 10px; }
  .brand { flex-basis: 100%; }
  .readout { font-size: 9.5px; }
  .seg button { padding: 6px 10px; font-size: 10px; }
  .foot { font-size: 9px; gap: 2px 12px; }

  .panel {
    top: auto;
    left: 0;
    width: auto;
    max-height: 78%;
    border-left: 0;
    border-top: 1px solid var(--line-strong);
    border-radius: 14px 14px 0 0;
    transform: translateY(102%);
  }
  .panel::before {
    content: "";
    display: block;
    width: 36px;
    height: 3px;
    margin: 8px auto 0;
    border-radius: 2px;
    background: var(--faint);
  }
  .panel-body { padding: 14px 16px 28px; }
  .p-head h2 { font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .panel.open, .overlay .label, .seg button { transition: none; }
}
