:root {
  --ink: #14212E; --ink2: #4A5A6A; --ink3: #5A6876;
  --bg: #F4F6F8; --card: #FFFFFF; --line: #D5DDE5; --line2: #C9D2DB; --soft: #E3E8EE;
  --amber: #F2A900; --auto: #2E8B57; --imm: #F2C14E; --buy: #8796A5;
  --warnbg: #FFF4D6; --warn: #6B4A00;
  --r: 16px; --shadow: 0 1px 3px rgba(20,33,46,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: Manrope, system-ui, -apple-system, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 12px max(20px, env(safe-area-inset-left)); background: var(--ink); color: #fff; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-title { font-size: 20px; font-weight: 800; }
.brand-sub { font-size: 13px; color: #B8C4CF; }
.tabs { display: flex; gap: 6px; }
.tab { height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid #3A4A5A; background: transparent; color: #fff; font-weight: 700; font-size: 15px; }
.tab[aria-current="page"] { background: var(--amber); border-color: var(--amber); color: var(--ink); }

/* Barra cliente / posizione */
.locbar { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line); }
.field { display: flex; flex-direction: column; gap: 4px; position: relative; }
.field label, .lbl { font-size: 13px; font-weight: 700; color: var(--ink2); }
.grow { flex: 1 1 180px; } .grow2 { flex: 3 1 360px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }
input[type=text], input[type=number] { height: 44px; border-radius: 10px; border: 1px solid var(--line2); padding: 0 12px; font-size: 16px; background: #fff; width: 100%; }
input:focus-visible, button:focus-visible { outline: 3px solid #1F6FB2; outline-offset: 1px; }
.btn { height: 44px; padding: 0 14px; border-radius: 10px; border: 2px solid var(--ink); background: #fff; font-weight: 700; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.btn-accent { background: var(--amber); border-color: var(--amber); color: var(--ink); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-dashed { border: 2px dashed #8796A5; color: var(--ink2); }
.locstatus { font-size: 14px; color: var(--ink2); flex: 2 1 260px; min-height: 44px; display: flex; align-items: center; gap: 8px; }
.locstatus b { color: var(--ink); }
.geo-results { position: absolute; top: 100%; left: 0; right: 0; z-index: 20; background: #fff; border: 1px solid var(--line2); border-radius: 10px; box-shadow: 0 8px 24px rgba(20,33,46,.15); margin-top: 4px; overflow: hidden; }
.geo-results button { display: block; width: 100%; text-align: left; padding: 12px 14px; min-height: 44px; border: none; border-bottom: 1px solid var(--soft); background: #fff; font-size: 14px; }
.geo-results button:last-child { border-bottom: none; }

/* Layout */
main { padding: 16px 20px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 440px) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 1000px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
.card { background: var(--card); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; }
.card + .card { margin-top: 12px; }
.card-title { font-size: 15px; font-weight: 800; }
.muted { color: var(--ink3); font-size: 13px; }
.note { font-size: 13px; color: var(--ink2); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { min-height: 44px; padding: 0 14px; border-radius: 10px; border: 2px solid var(--line2); background: #fff; font-weight: 700; font-size: 14px; }
.pill.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.seg { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 6px; }
.seg .pill { padding: 0 6px; font-size: 13px; }

/* Bussola */
.falda-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.ftab { height: 44px; padding: 0 14px; border-radius: 10px; border: 2px solid; background: #fff; font-weight: 800; font-size: 14px; }
.compass-wrap { display: flex; justify-content: center; }
.compass { position: relative; width: 380px; height: 380px; flex: none; }
@media (max-width: 430px) { .compass { transform: scale(.82); transform-origin: top center; margin-bottom: -68px; } }
.compass svg { position: absolute; inset: 0; }
.dir { position: absolute; width: 46px; height: 46px; border-radius: 23px; border: 2px solid var(--line2); background: #fff; color: var(--ink); padding: 0; font-weight: 700; font-size: 11px; }
.dir.main { font-size: 14px; font-weight: 800; }
.needle { position: absolute; left: 187px; top: 86px; width: 6px; height: 104px; border-radius: 3px; transform-origin: 3px 104px; transition: transform .25s; }
.needle::before { content: ""; position: absolute; left: -6px; top: -9px; width: 18px; height: 18px; border-radius: 9px; background: inherit; }
.hub { position: absolute; left: 184px; top: 184px; width: 12px; height: 12px; border-radius: 6px; background: var(--ink); }
.fine { display: grid; grid-template-columns: auto minmax(0,1fr) auto; gap: 8px; align-items: center; }
.fine input { text-align: center; font-weight: 800; font-size: 18px; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }

.fcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.fcard { background: #fff; border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); border: 2px solid transparent; display: flex; flex-direction: column; gap: 10px; }
.fcard-head { display: flex; align-items: center; gap: 8px; }
.tag { font-size: 13px; font-weight: 800; padding: 5px 10px; border-radius: 999px; color: #fff; }
.fcard-dir { flex: 1; font-size: 14px; font-weight: 700; color: var(--ink2); }
.xbtn { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line2); background: #fff; display: flex; align-items: center; justify-content: center; padding: 0; }
.big2 { display: flex; gap: 20px; }
.kl { font-size: 12px; font-weight: 700; color: var(--ink3); text-transform: uppercase; letter-spacing: .6px; }
.kv { font-size: 36px; font-weight: 800; line-height: 1.05; }
.bar { height: 12px; border-radius: 6px; background: var(--soft); overflow: hidden; }
.bar > div { height: 100%; border-radius: 6px; }
.spread { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }

/* Grafici a barre */
.chart { display: flex; align-items: flex-end; gap: 6px; border-bottom: 2px solid var(--line); height: 200px; }
.chart .col { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 2px; height: 100%; min-width: 0; }
.chart .b { display: block; border-radius: 3px 3px 0 0; min-width: 4px; }
.mcol { position: relative; border: none; background: transparent; padding: 0; border-radius: 6px 6px 0 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.mcol:hover { background: rgba(20,33,46,.04); }
.mcol.on { background: rgba(31,111,178,.12); }
.stackbar > span { display: block; }
.bnum { position: absolute; left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 800; color: var(--ink); white-space: nowrap; pointer-events: none; }
@media (max-width: 600px) { .bnum { font-size: 9px; } }
.mdetail { border: 1px solid var(--line2); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; background: #FBFCFD; }
.mdetail.empty-detail { color: var(--ink2); font-size: 14px; font-weight: 600; border-style: dashed; }
.dhead { font-size: 15px; font-weight: 800; }
.dgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 14px; }
.dcell { display: flex; flex-direction: column; gap: 2px; }
.dcell b { font-size: 20px; line-height: 1.15; }
.eq { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; border-top: 1px solid var(--soft); }
.eqhead { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; color: var(--ink2); }
.eqtag { width: 24px; height: 24px; border-radius: 6px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; }
.eqbody { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; font-size: 15px; }
.eqtot { font-size: 22px; }
.op { font-size: 18px; font-weight: 800; color: var(--ink3); }
.part { display: inline-flex; align-items: center; gap: 6px; }
.part b { font-size: 17px; }
.dlbl { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; color: var(--ink2); }
.axis { display: flex; gap: 6px; }
.axis span { flex: 1; text-align: center; font-size: 12px; color: var(--ink3); font-weight: 600; min-width: 0; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; font-weight: 600; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.stackbar { display: flex; flex-direction: column; width: 16px; }
.pc { display: flex; justify-content: center; gap: 3px; font-size: 11px; font-weight: 800; color: var(--ink2); }
.pc span { width: 16px; text-align: center; }

/* Produzione */
.frow { display: grid; grid-template-columns: 32px minmax(0,1fr) 92px; gap: 10px; align-items: center; }
.fdot { width: 32px; height: 32px; border-radius: 16px; color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.frow input { font-weight: 800; font-size: 17px; border-width: 2px; }
.g3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; }
.g4 { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 6px; }
.g4 input, .g3 input { font-weight: 700; padding: 0 8px; }
.photo { width: 100%; max-height: 220px; object-fit: contain; border-radius: 10px; border: 1px solid var(--line2); background: #EEF1F4; cursor: zoom-in; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: 12px; }
.kpi { background: #fff; border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; }
.kpi .v { font-size: 22px; font-weight: 800; line-height: 1.1; white-space: nowrap; }
.kpi .pre { display: block; font-size: 13px; font-weight: 700; color: var(--ink2); line-height: 1.2; }
tbody tr.on td { background: rgba(31,111,178,.10); font-weight: 700; }
.battnote {background: var(--warnbg); color: var(--warn); border-radius: 10px; padding: 10px 14px; font-size: 13px; font-weight: 600; }
.dot { width: 12px; height: 12px; border-radius: 6px; display: inline-block; }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--soft); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: 12px; color: var(--ink2); text-transform: uppercase; letter-spacing: .5px; }
tfoot td { font-weight: 800; border-top: 2px solid var(--line); }

.empty { padding: 24px; text-align: center; color: var(--ink2); font-weight: 600; background: #fff; border-radius: var(--r); box-shadow: var(--shadow); }
.err { color: #A3341E; font-weight: 700; font-size: 14px; }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line2); border-top-color: var(--ink); border-radius: 50%; animation: sp 1s linear infinite; vertical-align: -3px; }
@keyframes sp { to { transform: rotate(360deg); } }

.foot { margin: 0 20px 24px; padding: 10px 14px; border-radius: 10px; background: var(--warnbg); color: var(--warn); font-size: 13px; font-weight: 600; }
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(10,16,22,.92); display: flex; align-items: center; justify-content: center; padding: 60px 16px 16px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.lb-close { position: absolute; top: 12px; right: 12px; }

/* Selettore stima PVGIS / prudente */
.stima { flex: 0 0 auto; }
.seg2 { display: flex; gap: 6px; }
.seg2 .pill { min-height: 44px; }
.seg2 .pill.prudon { background: #6B4A00; border-color: #6B4A00; }
.seg2 { flex-wrap: wrap; align-items: center; }
.prudrange { display: flex; align-items: center; gap: 6px; }
.prudrange input[type=range] { width: 120px; height: 44px; accent-color: #6B4A00; }
