/* v4: listino condiviso; storici e confronto; medie mensili a piena larghezza.
   A 1440px: 1376px utili = 3 x 448px + 2 x 16px negli storici.
   A 390px: 358px utili, una colonna. Nessun dato nascosto. */
/* I colori stanno in palette.css (una per variante: site/variants/<nome>/palette.css). */
:root {
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --display: "Montserrat", "IBM Plex Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 24px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3, p, dl { margin: 0; }
h1 { font-family: var(--display); font-size: 26px; font-weight: 600; letter-spacing: -.02em; line-height: 1.2; text-wrap: balance; }
h2 { font-family: var(--display); font-size: 19px; font-weight: 600; letter-spacing: -.01em; line-height: 1.3; }
h3 { font-family: var(--display); font-size: 15px; font-weight: 600; line-height: 1.4; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
button, input, select { font: inherit; color: inherit; }
button, select { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip { position: absolute; top: -80px; left: 16px; background: var(--surface); padding: 10px 14px; border-radius: 8px; z-index: 10; }
.skip:focus { top: 10px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.price, .deltas, .chart, table, .ratio { font-variant-numeric: tabular-nums; }

/* ---------- logo ---------- */
.logo { display: inline-flex; align-items: center; }
.logo img { display: block; height: 30px; width: auto; }
.logo .logo-dark { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .logo .logo-light { display: none; } :root:not([data-theme="light"]) .logo .logo-dark { display: block; } }
:root[data-theme="dark"] .logo .logo-light { display: none; }
:root[data-theme="dark"] .logo .logo-dark { display: block; }
/* ---------- frame: piena larghezza, solo margini laterali ---------- */
.header, main, footer { width: 100%; margin: 0 auto; padding-left: max(32px, env(safe-area-inset-left, 0px)); padding-right: max(32px, env(safe-area-inset-right, 0px)); }
.header { display: flex; align-items: center; gap: 28px; min-height: 56px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.brand::before { content: ""; width: 12px; height: 12px; border-radius: 3px; background: var(--ink); }
.brand:hover { text-decoration: none; }
.header nav { display: flex; flex-wrap: wrap; gap: 4px; margin-left: -12px; }
.header nav a { padding: 10px 12px; min-height: 44px; display: inline-flex; align-items: center; border-radius: 6px; color: var(--muted); font-size: 14px; white-space: nowrap; }
.header nav a:hover { background: var(--chip); color: var(--ink); text-decoration: none; }
.preferences { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.preferences select, .preferences button { border: 0; background: transparent; color: var(--muted); font-size: 13px; padding: 8px 10px; border-radius: 8px; min-height: 44px; }
.preferences select:hover, .preferences button:hover { background: var(--chip); color: var(--ink); }
main { padding-top: 8px; padding-bottom: 24px; }
footer { border-top: 1px solid var(--rule); margin-top: 24px; padding-top: 22px; padding-bottom: 40px; font-size: 12.5px; color: var(--muted); display: grid; gap: 12px; }
footer > p { max-width: 110ch; line-height: 1.55; }
.footer-row { display: flex; justify-content: space-between; gap: 24px; }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 22px 24px; min-width: 0; }
.section { margin-top: 32px; }
.title-row, .section-top { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.title-row { margin: 8px 0 18px; align-items: flex-start; flex-direction: column; gap: 6px; }
.section-top { margin-bottom: 16px; align-items: center; }

/* ---------- quotes ---------- */
#load-status { color: var(--muted); font-size: 13px; padding: 12px 0; }
.quotes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; }
.quote { padding: 20px 24px; min-width: 0; display: grid; gap: 4px; align-content: start; }
.quote + .quote { border-left: 1px solid var(--rule); }
.quote[data-series="apt_eu"] { --series: var(--eu); }
.quote[data-series="apt_cn"] { --series: var(--cn); }
.quote[data-series="wc"] { --series: var(--wc); }
.quote h2 { font-size: 16px; }
.quote .description { font-size: 13px; color: var(--muted); }
.price-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.price { font-size: 40px; line-height: 1.05; font-weight: 600; letter-spacing: -.03em; }
.price:hover { text-decoration: none; color: var(--series); }
.price-unit { font-size: 14px; color: var(--muted); }
.price-range, .source-row { font-size: 13px; color: var(--muted); }
.source-row a { color: var(--ink); border-bottom: 1px solid var(--rule); }
.source-row a:hover { text-decoration: none; border-color: var(--ink); }
.deltas { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--rule-soft); }
.deltas div { display: grid; gap: 2px; min-width: 0; }
.deltas dt { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deltas dd { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.2; }
/* Il segno comunica la direzione: un rialzo non è un vantaggio per chi compra. */
.deltas dd.up, .deltas dd.down { color: var(--ink); }
.deltas small { display: block; font-size: 12px; font-weight: 400; color: var(--faint); margin-top: 2px; }

/* ---------- controls ---------- */
.periods, .segmented { display: inline-flex; background: var(--chip); border-radius: 6px; padding: 3px; gap: 2px; }
.periods button { border: 0; background: transparent; color: var(--muted); font-size: 13px; font-weight: 500; padding: 8px 12px; min-height: 44px; min-width: 44px; border-radius: 4px; }
.periods button:hover { color: var(--ink); }
.periods button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
select.compact, .currency select { border: 1px solid var(--control-border); background: var(--control); border-radius: 8px; padding: 6px 10px; font-size: 13px; min-height: 44px; }
.currency { display: flex; gap: 10px; align-items: center; font-size: 13px; color: var(--muted); }

/* ---------- charts ---------- */
.histories { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.histories article { background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 18px 20px 14px; min-width: 0; }
.histories h3 { margin-bottom: 10px; }
.comparison { margin-top: 16px; }
.comparison .section-top { margin-bottom: 4px; }
.chart { width: 100%; min-width: 0; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { font: 12px var(--font); fill: var(--faint); }
.gridline { stroke: var(--rule-soft); stroke-width: 1; }
.series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.series-area { stroke: none; opacity: .045; }
.end-dot { stroke: var(--surface); stroke-width: 2; }
.cursor-line { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 20px; font-size: 13px; color: var(--muted); margin: 8px 0 6px; }
.legend-line { display: inline-block; width: 18px; border-top: 2px solid; vertical-align: middle; margin-right: 8px; }
.chart input[type="range"] { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 44px; margin: 0; padding: 0; background: transparent; border: 0; }
.chart input[type="range"]::-webkit-slider-runnable-track { height: 3px; background: var(--rule); border-radius: 2px; }
.chart input[type="range"]::-moz-range-track { height: 3px; background: var(--rule); border-radius: 2px; }
.chart input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--ink); margin-top: -6.5px; border: 2px solid var(--surface); }
.chart input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--ink); border: 2px solid var(--surface); }
.chart-readout { font-size: 13px; color: var(--muted); min-height: 24px; margin-top: 0; display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: baseline; }
.chart-readout time { color: var(--faint); }
.chart-readout strong { color: var(--ink); font-weight: 600; }
.point-row { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.point-row a { color: var(--muted); border-bottom: 1px solid var(--rule); }
.point-row a:hover { text-decoration: none; color: var(--ink); }
.point-meta { color: var(--faint); }
.chart-help { margin-top: 12px; font-size: 12.5px; }
.notice { color: var(--muted); font-size: 13px; margin-block: 8px; }

/* ---------- table + form ---------- */
.supporting { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; }
.supporting section { background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 22px 24px; min-width: 0; }
.supporting h2 { margin-bottom: 4px; }
.supporting .muted { margin-bottom: 14px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; table-layout: fixed; font-size: 14px; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--rule-soft); text-align: right; font-weight: 400; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
thead th { color: var(--muted); font-size: 12px; vertical-align: bottom; border-bottom-color: var(--rule); }
th small { display: block; font-size: 12px; color: var(--faint); }
tbody th { font-weight: 500; }
td small { display: inline-block; min-width: 4ch; color: var(--faint); font-size: 12px; }
td a { border-bottom: 1px solid transparent; }
td a:hover { text-decoration: none; border-color: var(--ink); }
#monthly-more { border: 0; background: transparent; color: var(--ink); padding: 10px 0; min-height: 44px; font-size: 14px; }
#monthly-more:hover { color: var(--ink); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 12.5px; color: var(--muted); }
.field input, .field select { width: 100%; min-height: 40px; border: 1px solid var(--control-border); background: var(--control); border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.field input:focus-visible, .field select:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.consent { display: flex; align-items: flex-start; gap: 10px; margin: 14px 0; font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.consent input { width: 16px; height: 16px; margin: 2px 0 0; flex-shrink: 0; accent-color: var(--accent); }
.primary { background: var(--ink); color: var(--bg); border: 0; border-radius: 8px; padding: 10px 18px; min-height: 40px; font-weight: 500; }
.primary:hover { opacity: .88; }
.primary:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- method ---------- */
.method { font-size: 13.5px; color: var(--muted); max-width: 90ch; display: grid; gap: 8px; }
.method h2 { color: var(--ink); margin-bottom: 4px; }
.method p { line-height: 1.55; }
details { margin-top: 2px; }
summary { cursor: pointer; color: var(--ink); font-weight: 500; padding: 10px 0; min-height: 44px; }
details p { margin-top: 6px; }

/* ---------- widget ---------- */
.widget main { padding-top: 8px; padding-bottom: 20px; }
.widget .title-row { margin-bottom: 14px; }
.widget-legal { font-size: 12px; color: var(--muted); margin: 18px 0 10px; line-height: 1.5; }
.widget main > a { font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--rule); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  /* Tre oggetti: nessuna terza scheda isolata in una griglia a due colonne. */
  .quotes, .histories { grid-template-columns: 1fr; }
  .quote + .quote { border-left: 0; border-top: 1px solid var(--rule); }
  .quote { grid-template-columns: 1fr 1fr; column-gap: 24px; }
  .quote h2, .quote .description, .quote .price-row, .quote .price-range, .quote .source-row { grid-column: 1; }
  .quote .deltas { grid-column: 2; grid-row: 1 / 6; grid-template-columns: 1fr 1fr; border-top: 0; padding-top: 0; margin-top: 0; align-self: center; gap: 16px; }
}
@media (max-width: 700px) {
  .header, main, footer { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .header { flex-wrap: wrap; gap: 0 12px; padding-top: 4px; padding-bottom: 0; min-height: 0; }
  .header nav { order: 3; flex-basis: 100%; margin-left: -12px; }
  .preferences { margin-left: auto; }
  main { padding-top: 8px; }
  h1 { font-size: 24px; }
  .title-row { margin: 6px 0 16px; gap: 8px; }
  .histories { gap: 12px; }
  .quote, .panel, .histories article, .supporting section { padding: 16px; }
  .quote { display: grid; grid-template-columns: 1fr; }
  .quote .deltas { grid-column: 1; grid-row: auto; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--rule-soft); }
  .price { font-size: 36px; }
  .price-row { margin-top: 6px; }
  .section { margin-top: 28px; }
  .section-top { margin-bottom: 12px; gap: 8px; }
  .periods button { padding-inline: 10px; }
  .form-row { grid-template-columns: 1fr; }
  .footer-row { flex-wrap: wrap; }
  th, td { padding: 10px 4px; }
  thead th { white-space: normal; }
  td small { display: block; }
}
@media (max-width: 370px) {
  .quote .deltas { grid-template-columns: 1fr 1fr; }
  #history > .section-top { align-items: flex-start; flex-direction: column; }
}
@media (prefers-reduced-motion: no-preference) {
  .header nav a, .preferences select, .preferences button, .periods button, .primary { transition: background-color .15s, color .15s, opacity .15s; }
}
