/* TRAC LIV — stile brand TRAC (nero / giallo #FFD600). Mobile-first. */
:root {
  --bg: #0d0d0d;
  --panel: #1a1a1a;
  --panel-2: #242424;
  --line: #333;
  --txt: #f2f2f2;
  --txt-dim: #9a9a9a;
  --yellow: #ffd600;
  --ok: #22c55e;
  --warn: #eab308;
  --alarm: #e03030;
  --error: #808080;
  --water: #3b82f6;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  overscroll-behavior-y: contain;
}
.view { min-height: 100vh; min-height: 100dvh; }
[hidden] { display: none !important; }

.brand-trac { color: var(--txt); font-weight: 800; letter-spacing: 1px; }
.brand-liv  { color: var(--yellow); font-weight: 800; letter-spacing: 1px; margin-left: 4px; }

/* ===== LOGIN ===== */
#loginView {
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 22px;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.brand { font-size: 34px; text-align: center; }
.subtitle { text-align: center; color: var(--txt-dim); margin: 4px 0 22px; font-size: 14px; }
#loginForm { display: flex; flex-direction: column; gap: 14px; }
#loginForm label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--txt-dim); }
#loginForm input {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--txt);
  font-size: 17px;
  padding: 13px 14px;
}
#loginForm input:focus { outline: none; border-color: var(--yellow); }
button {
  font-family: inherit; cursor: pointer; border: none;
}
#loginBtn {
  margin-top: 6px;
  background: var(--yellow);
  color: #000; font-weight: 800; font-size: 16px; letter-spacing: 1px;
  padding: 14px; border-radius: 10px;
}
#loginBtn:active { transform: translateY(1px); }
#loginBtn:disabled { opacity: .6; }
.error { color: var(--alarm); font-size: 13px; text-align: center; margin: 4px 0 0; }

/* ===== TOPBAR ===== */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  background: #000; border-bottom: 2px solid var(--yellow);
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
}
.topbar-title { font-size: 20px; }
.topbar-client { flex: 1; text-align: right; color: var(--txt-dim); font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  background: var(--panel-2); color: var(--txt); border: 1px solid var(--line);
  width: 38px; height: 38px; border-radius: 9px; font-size: 18px;
}

/* ===== TOOLBAR ===== */
.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px;
}
.status-line { color: var(--txt-dim); font-size: 12px; }
.ghost-btn {
  background: transparent; color: var(--yellow);
  border: 1px solid var(--yellow); border-radius: 9px;
  padding: 9px 12px; font-size: 13px; font-weight: 700;
}
.ghost-btn:disabled { opacity: .5; }

/* ===== CONTENT ===== */
#content { padding: 4px 12px 40px; }
.ter-group { margin-bottom: 22px; }
.ter-head {
  font-size: 13px; font-weight: 700; color: #000;
  background: var(--yellow); border-radius: 8px;
  padding: 6px 12px; margin: 0 0 12px;
  display: inline-block;
}
.cis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

/* ===== CISTERNA CARD ===== */
.cis {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 12px 10px; display: flex; flex-direction: column;
}
.cis-top { display: flex; justify-content: space-between; align-items: baseline; }
.cis-num { font-weight: 800; font-size: 16px; }
.cis-num small { color: var(--txt-dim); font-weight: 600; font-size: 11px; }
.cis-prod { font-size: 12px; color: var(--yellow); font-weight: 700; }

.gauge {
  position: relative; margin: 10px auto 8px; width: 64px; height: 150px;
  background: var(--panel-2); border: 1px solid #444; border-radius: 8px 8px 4px 4px;
  overflow: hidden;
}
.gauge-fill {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--ok); transition: height .5s ease;
}
.gauge.warn  .gauge-fill { background: var(--warn); }
.gauge.alarm .gauge-fill { background: var(--alarm); }
.gauge.error .gauge-fill { background: var(--error); }
.gauge-base { position: absolute; left: 0; right: 0; bottom: 0; height: 8px; background: #000; }
.gauge-att {
  position: absolute; left: 0; right: 0; bottom: 10px;
  text-align: center; font-weight: 800; font-size: 15px; color: #000;
  text-shadow: 0 1px 1px rgba(255,255,255,.25);
}
.gauge-miss {
  position: absolute; left: 0; right: 0; top: 4px;
  text-align: center; font-size: 11px; color: var(--txt-dim);
}

.cis-meta { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--txt-dim); }
.cis-meta .row { display: flex; justify-content: space-between; }
.cis-meta b { color: var(--txt); font-weight: 700; }
.badges { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 8px; }
.badge { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 20px; }
.badge.alarm { background: var(--alarm); color: #fff; }
.badge.warn  { background: var(--warn); color: #000; }
.badge.error { background: var(--error); color: #fff; }
.badge.water { background: var(--water); color: #fff; }
.badge.water-alarm { background: var(--water); color: #fff; border: 1px solid var(--alarm); }

/* Allarme acqua oltre soglia: TUTTO il riquadro lampeggia in modo evidente.
 * Lo sfondo intero passa dal nero (panel) al rosso allarme, il bordo si
 * ispessisce e si accende. Easing lineare per un battito netto. */
@keyframes pulseWaterAlarm {
  0%, 100% {
    background: var(--panel);
    border-color: var(--alarm);
    box-shadow: 0 0 0 0 rgba(224,48,48,.6);
  }
  50% {
    background: var(--alarm);
    border-color: #fff;
    box-shadow: 0 0 22px 6px rgba(224,48,48,.85);
  }
}
.cis.pulse-water-alarm {
  border-width: 3px !important;
  animation: pulseWaterAlarm 0.9s ease-in-out infinite;
}
/* Mentre la card pulsa rossa, il testo deve restare leggibile sul rosso */
.cis.pulse-water-alarm .cis-num,
.cis.pulse-water-alarm .cis-num small,
.cis.pulse-water-alarm .cis-meta .row span,
.cis.pulse-water-alarm .cis-meta b { color: #fff !important; }

.cis-refresh {
  margin-top: 9px; width: 100%;
  background: var(--panel-2); color: var(--yellow);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px; font-size: 12px; font-weight: 700;
}
.cis.busy { opacity: .55; }

.empty { text-align: center; color: var(--txt-dim); padding: 40px 20px; }

/* ===== TOAST ===== */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--panel-2); color: var(--txt);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 16px; font-size: 13px; z-index: 50;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
  max-width: 86%;
}
.toast.err { border-color: var(--alarm); color: #ffb4b4; }
.toast.ok  { border-color: var(--ok); }

/* spinner */
.spin { display: inline-block; width: 13px; height: 13px; vertical-align: -2px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
