/* ==========================================================
   Monitoraggio Consumi – tema grafico
   Solo presentazione: nessuna logica applicativa qui dentro.
   ========================================================== */
@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&family=Sora:wght@500;600;700&display=swap');

:root {
  --font: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Sora', 'Manrope', system-ui, sans-serif;

  --primary: #2563ff;
  --primary-hover: #1d4fd8;
  --primary-soft: rgba(37, 99, 255, .10);
  --accent: #06b6d4;
  --amber: #f5a524;
  --violet: #8b5cf6;

  --bg: #eef2f8;
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --text: #0b1b33;
  --muted: #5d6c84;
  --border: #dbe2ee;
  --danger: #e5484d;
  --danger-hover: #cf3a3f;
  --success: #12a66a;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgb(11 27 51 / .04), 0 8px 24px -12px rgb(11 27 51 / .12);
  --shadow-lg: 0 2px 4px rgb(11 27 51 / .05), 0 16px 36px -14px rgb(11 27 51 / .20);
  --table-bg-th: #f1f4fa;
  --header-bg: rgba(255, 255, 255, .82);
}

[data-theme="dark"] {
  --primary: #4d86ff;
  --primary-hover: #7aa3ff;
  --primary-soft: rgba(77, 134, 255, .14);
  --bg: #000000;
  --surface: #0b0b0c;
  --surface-2: #141416;
  --text: #f4f5f7;
  --muted: #9a9fa8;
  --border: #25272b;
  --danger: #ff6b70;
  --danger-hover: #ff8589;
  --success: #3ddc97;
  --shadow: 0 1px 2px rgb(0 0 0 / .6), 0 8px 24px -12px rgb(0 0 0 / .8);
  --shadow-lg: 0 2px 4px rgb(0 0 0 / .6), 0 16px 36px -14px rgb(0 0 0 / .9);
  --table-bg-th: #141416;
  --header-bg: rgba(0, 0, 0, .78);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  margin: 0;
  background:
    radial-gradient(1100px 420px at 100% -10%, var(--primary-soft), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  transition: background-color .3s, color .3s;
}

/* ---------- Header ---------- */
header {
  background: var(--header-bg);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 12px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  letter-spacing: -.01em;
  color: var(--text);
}
.brand img.logo { height: 56px; width: auto; object-fit: contain; }

.hdr-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: .92rem;
  color: var(--muted);
  flex-wrap: wrap;
}
.hdr-actions a:not(.whatsapp-btn) {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 8px;
  transition: background .2s;
}
.hdr-actions a:not(.whatsapp-btn):hover { background: var(--primary-soft); }
.hdr-actions .user {
  color: var(--text);
  font-weight: 600;
  padding: 6px 12px 6px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.hdr-actions .user::before {
  content: '';
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(18, 166, 106, .18);
}

/* ---------- Layout ---------- */
main { max-width: 1280px; margin: 28px auto 64px; padding: 0 24px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 24px;
  transition: background-color .3s, border-color .3s;
}
.card.flush { padding: 0; overflow: hidden; }

h3 { margin: 0 0 16px; font-family: var(--font-display); font-size: 1.1rem; font-weight: 600; letter-spacing: -.01em; }
.muted { color: var(--muted); font-size: .9rem; line-height: 1.5; }

/* ---------- Controlli ---------- */
label { display: flex; flex-direction: column; gap: 6px; font-size: .8rem; font-weight: 600; color: var(--muted); }
label br { display: none; }
.lbl { font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }

input, select, button {
  font: inherit;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .2s, box-shadow .2s, background-color .2s, transform .1s;
}
input:hover, select:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); }
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
select { min-width: 220px; font-weight: 600; cursor: pointer; }

button {
  background: var(--primary);
  color: #fff;
  border: 0;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 14px -8px var(--primary);
}
button:hover { background: var(--primary-hover); }
button:active { transform: translateY(1px); }
button:focus-visible, a:focus-visible { outline: 3px solid var(--primary-soft); outline-offset: 2px; box-shadow: 0 0 0 2px var(--primary); }
button:disabled { opacity: .45; cursor: default; transform: none; box-shadow: none; }
button.sec { background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: none; }
button.sec:hover { background: var(--surface-2); border-color: var(--muted); }
button.sec.icon { padding: 9px 12px; }
button.warn { background: var(--danger); box-shadow: 0 6px 14px -8px var(--danger); }
button.warn:hover { background: var(--danger-hover); }
button.go-today { background: var(--success); box-shadow: 0 6px 14px -8px var(--success); }
button.go-today:hover { filter: brightness(.94); background: var(--success); }

input[type="checkbox"] { width: 18px; height: 18px; padding: 0; accent-color: var(--primary); cursor: pointer; }

.row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; }
.date-nav { display: flex; gap: 6px; }

/* Selettore periodo */
.seg { display: inline-flex; background: var(--surface-2); padding: 4px; border-radius: 12px; border: 1px solid var(--border); }
.seg button { background: transparent; color: var(--muted); border: none; border-radius: 8px; padding: 7px 14px; font-size: .86rem; font-weight: 600; margin: 0; box-shadow: none; }
.seg button:hover { color: var(--text); background: transparent; }
.seg button.on { background: var(--primary); color: #fff; box-shadow: 0 6px 14px -8px var(--primary); }

.range-title { margin-top: 18px; font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; letter-spacing: -.01em; }

/* ---------- Hero consumo ---------- */
.hero {
  position: relative;
  overflow: hidden;
  border-radius: 22px;
  padding: 34px 38px;
  margin-bottom: 24px;
  color: #fff;
  background:
    radial-gradient(700px 260px at 90% -30%, rgba(6, 182, 212, .45), transparent 62%),
    linear-gradient(120deg, #081633 0%, #0b2a6b 55%, #1550d6 100%);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 20px;
  box-shadow: 0 24px 48px -24px rgba(21, 80, 214, .55);
}
.hero-wave { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 70%; pointer-events: none; }
.hero > :not(svg) { position: relative; z-index: 1; }
.hero-label { font-size: .95rem; font-weight: 600; color: rgba(255, 255, 255, .72); }
.hero-val {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 6.5vw, 4.2rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -.03em;
  margin-top: 8px;
}
.hero-sub { font-size: .9rem; line-height: 1.5; text-align: right; color: rgba(255, 255, 255, .72); }
.hero-sub strong { color: #fff; font-weight: 600; }

/* ---------- Ultima lettura ---------- */
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.card-head h3 { margin: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.kpi {
  --k: var(--primary);
  position: relative;
  padding: 16px 16px 14px 20px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.kpi::before { content: ''; position: absolute; left: 0; top: 12px; bottom: 12px; width: 4px; border-radius: 0 4px 4px 0; background: var(--k); }
.kpi-label { font-size: .8rem; font-weight: 600; color: var(--muted); }
.kpi-val { font-family: var(--font-display); font-size: 1.4rem; font-weight: 600; letter-spacing: -.02em; margin-top: 6px; color: var(--text); }
.kpi.v { --k: #2563ff; } .kpi.a { --k: #06b6d4; } .kpi.m { --k: #f5a524; }
.kpi.p { --k: #e5484d; } .kpi.c { --k: #12a66a; } .kpi.r { --k: #8b5cf6; }

/* ---------- Grafici ---------- */
.chart { height: 320px; position: relative; }
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.charts .card { margin-bottom: 0; }
.charts { margin-bottom: 24px; }
@media (max-width: 960px) { .charts { grid-template-columns: 1fr; } }

/* ---------- Tabelle ---------- */
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: .92rem; color: var(--text); }
th { font-weight: 600; font-size: .82rem; color: var(--muted); background: var(--table-bg-th); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--primary-soft); }

.tw { overflow: auto; max-height: 480px; border-radius: 12px; border: 1px solid var(--border); }
.tw table { font-size: .88rem; }
.tw th, .tw td { text-align: right; white-space: nowrap; }
.tw th { position: sticky; top: 0; z-index: 10; }
.tw th:first-child, .tw td:first-child { text-align: left; }
.tw tbody tr:nth-child(even) td { background: var(--surface-2); }
.tw tbody tr:hover td { background: var(--primary-soft); }

/* stati (usati da JS sulle celle) */
.bad { color: var(--danger); font-weight: 600; }
.ok { color: var(--success); font-weight: 600; }
td.ok::before, td.bad::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: currentColor; margin-right: 8px; }

/* ---------- WhatsApp ---------- */
.whatsapp-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: #25d366; color: #06361b;
  padding: 8px 14px; border-radius: 999px;
  text-decoration: none; font-weight: 700; font-size: .88rem;
  box-shadow: 0 8px 18px -10px #25d366;
  transition: filter .2s, transform .1s;
}
.whatsapp-btn:hover { filter: brightness(.95); text-decoration: none; }

/* ---------- Modale di attesa ---------- */
.modal { position: fixed; inset: 0; background: rgba(6, 13, 26, .6); backdrop-filter: blur(4px); z-index: 999; align-items: center; justify-content: center; }
.modal .card { text-align: center; max-width: 340px; padding: 34px; margin: 0; box-shadow: var(--shadow-lg); }
.spinner { width: 44px; height: 44px; margin: 0 auto 18px; border-radius: 50%; border: 4px solid var(--primary-soft); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Accesso ---------- */
.auth { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); min-height: 100vh; }
.auth-art {
  position: relative; overflow: hidden; color: #fff;
  display: flex; align-items: flex-end; padding: 56px;
  background:
    radial-gradient(700px 400px at 100% 0%, rgba(6, 182, 212, .4), transparent 60%),
    linear-gradient(150deg, #071430 0%, #0a2766 60%, #1550d6 100%);
}
.auth-wave { position: absolute; inset: 0; width: 100%; height: 100%; }
.auth-wave .line { stroke-dasharray: 2400; stroke-dashoffset: 2400; animation: draw 2.6s .2s ease-out forwards; }
.auth-wave .area { opacity: 0; animation: fade 1.4s 1.6s ease-out forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes fade { to { opacity: 1; } }
.auth-copy { position: relative; max-width: 460px; }
.auth-copy h2 { font-family: var(--font-display); font-size: clamp(1.9rem, 3.4vw, 2.9rem); line-height: 1.1; letter-spacing: -.03em; margin: 0 0 14px; font-weight: 700; }
.auth-copy p { margin: 0; font-size: 1.05rem; line-height: 1.6; color: rgba(255, 255, 255, .78); }

.auth-form { position: relative; display: flex; align-items: center; justify-content: center; padding: 32px; }
.auth-top { position: absolute; top: 20px; right: 20px; display: flex; gap: 10px; align-items: center; }
.loginbox { width: 100%; max-width: 380px; text-align: center; }
.loginbox img.logo-login { height: 88px; margin-bottom: 18px; }
.loginbox h3 { font-size: 1.6rem; letter-spacing: -.02em; margin-bottom: 8px; }
.loginbox input { width: 100%; margin-bottom: 14px; padding: 13px 14px; }
.loginbox button#go { width: 100%; padding: 13px; font-weight: 700; margin-top: 4px; }
.pwd { position: relative; }
.pwd input { padding-right: 44px; margin-bottom: 14px; }
.row .pwd input { margin-bottom: 0; }
.pwd .eye { position: absolute; right: 12px; top: 13px; cursor: pointer; color: var(--muted); user-select: none; }

@media (prefers-reduced-motion: reduce) {
  .auth-wave .line { animation: none; stroke-dashoffset: 0; }
  .auth-wave .area { animation: none; opacity: 1; }
  .spinner { animation-duration: 2s; }
}

/* ==========================================================
   Adattamento tablet e cellulare
   ========================================================== */
body { overflow-x: hidden; }
img, canvas, svg { max-width: 100%; }

@media (max-width: 860px) {
  /* login */
  .auth { grid-template-columns: 1fr; min-height: 100svh; }
  .auth-art { min-height: 180px; padding: 24px; align-items: flex-end; }
  .auth-copy h2 { font-size: 1.5rem; margin: 0; }
  .auth-copy p { display: none; }
  .auth-form { align-items: flex-start; padding: 84px 20px 32px; }
  .auth-top { top: 12px; right: 12px; left: 12px; justify-content: space-between; }

  /* header */
  header { padding: 10px 16px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .brand { font-size: 1rem; gap: 10px; }
  .brand img.logo { height: 44px; }

  main { padding: 0 14px; margin-top: 18px; }
  .hero { padding: 26px 22px; border-radius: 18px; }
  .hero-sub { text-align: left; }
}

@media (max-width: 640px) {
  /* header su due righe: marchio sopra, azioni sotto a tutta larghezza */
  header { flex-direction: column; align-items: stretch; gap: 10px; }
  .hdr-actions { gap: 8px; justify-content: flex-start; }
  .hdr-actions .user { margin-right: auto; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .hdr-actions a:not(.whatsapp-btn) { padding: 8px 6px; }
  .whatsapp-btn { padding: 8px 12px; }

  .card { padding: 16px; border-radius: 14px; margin-bottom: 16px; }
  h3 { font-size: 1.02rem; }

  /* niente zoom automatico su iPhone: campi a 16px */
  input, select, button { font-size: 16px; }
  button, input, select { min-height: 44px; }
  .seg button { min-height: 38px; }

  /* barra comandi a colonna unica */
  .row { flex-direction: column; align-items: stretch; gap: 14px; }
  .row > *, .row label { width: 100%; }
  .row button { width: 100%; }
  select { min-width: 0; width: 100%; }
  .date-nav { width: 100%; }
  .date-nav input { flex: 1; min-width: 0; }
  .date-nav button { flex: 0 0 52px; }

  /* periodo: pulsanti equidistribuiti, scorrono se serve */
  .seg { display: flex; width: 100%; overflow-x: auto; scrollbar-width: none; }
  .seg::-webkit-scrollbar { display: none; }
  .seg button { flex: 1 0 auto; padding: 8px 12px; }

  .range-title { font-size: 1.02rem; margin-top: 14px; }

  /* hero e letture */
  .hero { padding: 22px 18px; margin-bottom: 16px; }
  .hero-val { font-size: clamp(2.1rem, 11vw, 2.8rem); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px 12px 12px 16px; }
  .kpi-val { font-size: 1.15rem; word-break: break-word; }
  .card-head { flex-direction: column; align-items: flex-start; gap: 2px; }

  /* grafici */
  .charts { gap: 16px; margin-bottom: 16px; }
  .chart { height: 260px; }

  /* tabelle: scorrimento orizzontale */
  .tw { max-height: 420px; -webkit-overflow-scrolling: touch; }
  th, td { padding: 10px 12px; }
  .card.flush { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .card.flush table { min-width: 560px; }
  td button { min-height: 38px; padding: 6px 10px; font-size: 14px; }

  .modal .card { margin: 0 20px; }

  /* login */
  .loginbox img.logo-login { height: 72px; }
  .loginbox h3 { font-size: 1.4rem; }
}

@media (max-width: 380px) {
  .kpis { grid-template-columns: 1fr; }
  .hdr-actions .user { max-width: 38%; }
}
