/* Thinknx · Glass Dark — valori presi dal file Figma "UX-UI App ThinKnx Fenice" */
:root {
  --bg: #0a0a0b;
  --rail-bg: #101011;
  --rail-border: rgba(255,255,255,.08);
  --text: #fff;
  --text-86: rgba(255,255,255,.86);
  --text-75: rgba(255,255,255,.75);
  --text-68: rgba(255,255,255,.68);
  --text-60: rgba(255,255,255,.6);
  --text-55: rgba(255,255,255,.55);
  --text-50: rgba(255,255,255,.5);
  --text-40: rgba(255,255,255,.4);
  --glass: linear-gradient(165deg, rgba(255,255,255,.11) 0%, rgba(255,255,255,.04) 80%);
  --glass-border: rgba(255,255,255,.12);
  --ok: #7ee2a8;
  --warn: #ffb547;
  --warn-text: #ffd08a;
  --accent: #db3700;
  --rail-closed: 64px;
  --rail-open: 233px;
  --font: "Google Sans Flex", "Google Sans", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html { height: 100%; background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px; line-height: normal;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
h1, h2, p { margin: 0; font-weight: inherit; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:focus-visible { outline: 2px solid rgba(255,255,255,.7); outline-offset: 2px; }
img { display: block; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; min-height: 100dvh; }

.rail {
  position: sticky; top: 0; flex: none;
  height: 100vh; height: 100dvh;
  width: calc(var(--rail-closed) + var(--safe-l));
  padding: calc(24px + var(--safe-t)) 10px calc(24px + var(--safe-b)) calc(10px + var(--safe-l));
  background: var(--rail-bg); border-right: 1px solid var(--rail-border);
  display: flex; flex-direction: column; gap: 8px;
  overflow: hidden; z-index: 30;
  transition: width .22s ease;
}
.app[data-menu="open"] .rail { width: calc(var(--rail-open) + var(--safe-l)); }

.brand { display: flex; align-items: center; gap: 12px; height: 40px; margin-bottom: 14px; padding-left: 2px; }
.brand-logo { flex: none; }
.brand-name { font-family: Inter, var(--font); font-weight: 700; font-size: 20px; white-space: nowrap; }

.nav { display: flex; flex-direction: column; gap: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  height: 42px; padding: 0 12px; border-radius: 12px;
  border: 1px solid transparent; white-space: nowrap;
  color: var(--text-75); font-size: 14px; text-align: left;
}
.nav-item img { flex: none; opacity: .65; }
.nav-item span { overflow: hidden; }
.nav-item[aria-current="page"] {
  background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.14);
  color: #fff; font-weight: 600;
}
.nav-item[aria-current="page"] img { opacity: 1; }
.nav-dot { margin-left: auto; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
.rail-settings { margin-top: auto; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; }
.rail-settings img { opacity: .6; }

/* rail chiuso: solo icone */
.app[data-menu="closed"] .brand { padding-left: 2px; }
.app[data-menu="closed"] .brand-name,
.app[data-menu="closed"] .nav-item span,
.app[data-menu="closed"] .nav-dot { opacity: 0; pointer-events: none; }
.app[data-menu="closed"] .nav-item { width: 44px; padding: 0 11px; }
.brand-name, .nav-item span, .nav-dot { transition: opacity .15s ease; }

.scrim { display: none; }

.main {
  flex: 1; min-width: 0;
  padding: calc(20px + var(--safe-t)) calc(24px + var(--safe-r)) calc(32px + var(--safe-b)) 20px;
  display: flex; flex-direction: column; gap: 20px;
}

/* ---------- Header ---------- */
.header { display: flex; align-items: center; gap: 20px; min-height: 52px; }
.icon-btn {
  width: 44px; height: 44px; flex: none; display: grid; place-items: center;
  border-radius: 12px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12);
}
.divider { width: 1px; height: 28px; background: rgba(255,255,255,.2); flex: none; }
.title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.title h1 { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title p { font-size: 13px; color: var(--text-68); white-space: nowrap; }
.spacer { flex: 1; }
.alert-pill {
  display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 20px 0 16px; flex: none;
  border-radius: 100px; background: rgba(255,181,71,.12); border: 1px solid rgba(255,181,71,.45);
  color: var(--warn-text); font-size: 14px; font-weight: 600; white-space: nowrap;
}
.alert-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 10px var(--warn); flex: none; }
.alert-count { display: none; }
.profile {
  width: 48px; height: 48px; flex: none; display: grid; place-items: center;
  border-radius: 24px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16);
}

/* ---------- Viste ---------- */
.view { display: none; flex-direction: column; gap: 20px; }
.app[data-view="home"] .view-home { display: flex; }
.app[data-view="empty"] .view-empty { display: flex; flex: 1; }

/* ---------- Card glass ---------- */
.glass {
  background: var(--glass); border: 1px solid var(--glass-border);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-radius: 32px; overflow: hidden;
}

.row-main { display: grid; grid-template-columns: minmax(0, 633fr) minmax(0, 354fr); gap: 16px; }

.card-power { padding: 28px 30px 22px; display: flex; flex-direction: column; gap: 14px; min-height: 424px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.card-labels { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.eyebrow { font-size: 13px; font-weight: 600; color: var(--text-55); letter-spacing: .78px; text-transform: uppercase; }
.card-labels h2 { font-size: 18px; font-weight: 500; color: var(--text-86); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.segmented {
  display: flex; gap: 4px; padding: 4px; flex: none;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14); border-radius: 999px;
}
.seg {
  display: flex; align-items: center; gap: 8px; padding: 9px 14px; border-radius: 999px;
  border: 1px solid transparent; font-size: 13px; font-weight: 500; color: var(--text-50);
}
.seg img { opacity: .5; }
.seg[aria-selected="true"] { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.seg[aria-selected="true"] img { opacity: 1; }

.card-body { flex: 1; display: flex; align-items: center; gap: 28px; min-height: 0; }
.kpis { display: flex; flex-direction: column; gap: 22px; flex: none; min-width: 0; }
.kpi p { font-size: 13px; color: var(--text-55); margin-bottom: 4px; }
.kpi strong { font-size: 20px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- Tachimetri ---------- */
.gauge { position: relative; flex: none; }
.gauge svg { display: block; width: 100%; height: auto; overflow: visible; }
.gauge .tick { fill: var(--text-40); font-family: var(--font); font-size: 11px; }
.gauge-value {
  position: absolute; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; white-space: nowrap; pointer-events: none;
}
.gauge-num { display: flex; align-items: baseline; gap: 4px; font-variant-numeric: tabular-nums; }

.big-gauge .gauge { width: 250px; }
.big-gauge .gauge-value { top: 37.2%; }
.big-gauge .gauge-num b { font-size: 54px; font-weight: 400; letter-spacing: -.5px; }
.big-gauge .gauge-num small { font-size: 19px; font-weight: 500; color: var(--text-60); }
.big-gauge .gauge-sub { font-size: 12px; color: var(--text-50); }

/* ---------- Grafico 24 h ---------- */
.card-body[data-mode="chart"] .big-gauge { display: none; }
.card-body[data-mode="chart"] .chart { display: block; }
.chart { flex: 1; min-width: 0; align-self: stretch; }
.chart svg { display: block; width: 100%; height: 100%; }
.chart text { fill: var(--text-40); font-family: var(--font); font-size: 11px; }
.chart .peak-label { fill: #fff; font-size: 12px; font-weight: 600; }

/* ---------- Ripartizione carichi ---------- */
.card-loads { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.card-loads h2 { font-size: 17px; font-weight: 600; }
.loads { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.load {
  flex: 1; display: flex; flex-direction: column; justify-content: space-between; gap: 10px;
  padding: 14px; border-radius: 16px; background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.08);
}
.load-label { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.load-value { display: flex; align-items: baseline; justify-content: space-between; }
.load-value b { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.load-value b small { font-size: 14px; color: var(--text-60); font-weight: 600; }
.load-value span { font-size: 12px; color: var(--text-60); font-variant-numeric: tabular-nums; }
.track { height: 8px; border-radius: 4px; background: rgba(255,255,255,.08); overflow: hidden; }
.fill { height: 100%; border-radius: 4px; transition: width .6s ease; }
.fill.clima { background: linear-gradient(90deg, #0284c7, #38bdf8); }
.fill.luci { background: linear-gradient(90deg, #f59e0b, #fcd34d); }
.fill.altro { background: linear-gradient(90deg, #7c3aed, #c4b5fd); }

/* ---------- Quadri ---------- */
.quadri { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.tile {
  border-radius: 28px; padding: 20px 22px; min-height: 232px;
  display: flex; flex-direction: column; justify-content: space-between; gap: 24px; text-align: left;
  transition: border-color .2s ease, background .2s ease;
}
.tile[aria-pressed="true"] { border-color: rgba(255,255,255,.34); background: linear-gradient(165deg, rgba(255,255,255,.16) 0%, rgba(255,255,255,.05) 80%); }
.tile-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tile-top h3 { margin: 0; font-size: 16px; font-weight: 600; white-space: nowrap; }
.status { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: rgba(255,255,255,.72); white-space: nowrap; }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.status.warn { color: var(--warn-text); }
.status.warn i { background: var(--warn); }
.tile .gauge { width: 126px; align-self: center; }
.tile .gauge-value { top: 37%; }
.tile .gauge-num b { font-size: 28px; font-weight: 400; }
.tile .gauge-num small { font-size: 10px; font-weight: 500; color: var(--text-60); }
.tile .gauge-sub { font-size: 10px; font-weight: 500; color: var(--text-60); margin-top: 2px; }

/* ---------- Stato vuoto ---------- */
.empty { margin: auto; max-width: 340px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 40px 0; }
.empty img { width: 40px; height: 40px; opacity: .5; }
.empty h2 { font-size: 20px; font-weight: 600; }
.empty p { color: var(--text-60); font-size: 14px; line-height: 1.45; }
.btn { margin-top: 8px; padding: 12px 20px; border-radius: 999px; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.18); font-weight: 600; }

/* =========================================================
   Tablet / iPhone orizzontale
   ========================================================= */
@media (max-width: 1100px) {
  .row-main { grid-template-columns: 1fr; }
  .card-power { min-height: 0; }
  .card-body { min-height: 300px; }
  .loads { flex-direction: row; }
  .card-loads { min-height: 0; }
}

/* =========================================================
   iPhone verticale: menu a scomparsa, contenuti impilati
   ========================================================= */
@media (max-width: 760px) {
  .rail {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: calc(var(--rail-open) + var(--safe-l));
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 20px 0 60px rgba(0,0,0,.5);
  }
  .app[data-menu="open"] .rail { transform: none; }
  .app[data-menu] .brand-name,
  .app[data-menu] .nav-item span,
  .app[data-menu] .nav-dot { opacity: 1; pointer-events: auto; }
  .app[data-menu] .nav-item { width: auto; padding: 0 12px; }
  .scrim {
    display: block; position: fixed; inset: 0; z-index: 20;
    background: rgba(0,0,0,.55); opacity: 0; pointer-events: none; transition: opacity .25s ease;
  }
  .app[data-menu="open"] .scrim { opacity: 1; pointer-events: auto; }

  .main { padding: calc(12px + var(--safe-t)) calc(16px + var(--safe-r)) calc(28px + var(--safe-b)) calc(16px + var(--safe-l)); gap: 16px; }
  .view { gap: 16px; }
  .header { gap: 12px; }
  .divider { display: none; }
  .title h1 { font-size: 16px; }
  .title p { font-size: 12px; }
  .alert-pill { height: 40px; padding: 0 14px 0 12px; gap: 8px; }
  .alert-text { display: none; }
  .alert-count { display: inline; }
  .profile { width: 40px; height: 40px; }

  .glass { border-radius: 28px; }
  .card-power { padding: 22px 20px 20px; gap: 18px; }
  .card-head { flex-direction: column; align-items: stretch; gap: 14px; }
  .segmented { align-self: flex-start; }
  .card-body { flex-direction: column; gap: 18px; min-height: 0; }
  .big-gauge { align-self: center; }
  .chart { height: 230px; flex: none; width: 100%; }
  .kpis { flex-direction: row; justify-content: space-between; width: 100%; gap: 12px; }
  .kpi strong { font-size: 18px; }

  .card-loads { padding: 20px; }
  .loads { flex-direction: column; }
  .load { gap: 8px; }

  .quadri { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .tile { min-height: 0; padding: 16px; gap: 18px; border-radius: 24px; }
  .tile-top { flex-direction: column; align-items: flex-start; gap: 6px; }
  .tile .gauge { width: 118px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
