:root {
  --bg: #0f1115;
  --card: #181b22;
  --card-2: #20242d;
  --text: #e8eaf0;
  --muted: #8b91a1;
  --accent: #3b82f6;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
}
* { box-sizing: border-box; }
/* L'attributo hidden deve vincere su qualsiasi display impostato dalle classi */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
body.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
h1 { font-size: 1.4rem; margin: 0 0 8px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
a { color: var(--accent); }
code { background: var(--card-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); margin: 8px 0 0; }
.notice { background: #3b2f0d; color: #fcd34d; padding: 10px; border-radius: 8px; font-size: .9rem; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin: 12px 16px; }
.card.login { width: min(420px, 100%); margin: 0; }
label { display: block; margin: 12px 0; }
input[type=password], input[type=text] {
  width: 100%; margin-top: 6px; padding: 12px; border-radius: 8px; border: 1px solid #333846;
  background: var(--card-2); color: var(--text); font-size: 1rem;
}
button, a.secondary {
  font: inherit; cursor: pointer; border: none; border-radius: 8px; padding: 12px 16px;
  color: #fff; background: var(--card-2); text-decoration: none; display: inline-block;
}
button.primary { background: var(--accent); width: 100%; }
button.big { padding: 18px; font-size: 1.1rem; }
button.secondary, a.secondary { background: var(--card-2); }
button.danger { background: var(--danger); }
.link-btn { background: none; padding: 4px 8px; color: var(--accent); }
.row { display: flex; gap: 10px; margin-top: 12px; }
.row > * { flex: 1; }

.bar {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--card); position: sticky; top: 0; z-index: 5;
}
.bar .title { font-weight: 600; flex: 1; }
.bar .link { font-size: .9rem; }
.pill { font-size: .75rem; padding: 3px 10px; border-radius: 999px; background: var(--card-2); }
.pill.on { background: #14532d; color: #86efac; }
.pill.off { background: #4c1d1d; color: #fca5a5; }
.pill.warn { background: #3b2f0d; color: #fcd34d; }

.preview, .live-frame { position: relative; background: #000; }
.preview video, .live-frame img { display: block; width: 100%; max-height: 60vh; object-fit: contain; background: #000; }
.live-frame img { min-height: 200px; }
.badge {
  position: absolute; top: 10px; left: 10px; padding: 4px 10px; border-radius: 6px;
  background: var(--danger); color: #fff; font-weight: 700; font-size: .8rem; letter-spacing: .05em;
  opacity: 0; transition: opacity .15s;
}
.badge.show { opacity: 1; }
.badge.calib { background: var(--warn); color: #000; opacity: 1; top: auto; bottom: 18px; }
.meter { position: absolute; left: 0; right: 0; bottom: 0; height: 6px; background: rgba(255,255,255,.15); }
.meter-fill { height: 100%; width: 0; background: var(--ok); transition: width .1s; }
.meter-mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--danger); left: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.stats > div { background: var(--card-2); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; }
.stats .label { font-size: .7rem; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; }
.stats span:last-child { font-weight: 600; }

.slider input[type=range] { width: 100%; margin-top: 6px; }

.flash-overlay { position: fixed; inset: 0; background: #fff; z-index: 100; }

.banner {
  position: absolute; inset: 0; display: none; place-items: center;
  background: rgba(15,17,21,.75); color: #fca5a5; font-weight: 600; font-size: 1.1rem;
}
.banner.show { display: grid; }

.live { padding: 0 0 8px; }
.live .stats { margin: 12px 16px 0; }
.live p { margin: 8px 16px 0; }
.gallery { padding: 8px 16px 40px; }
.gallery details { background: var(--card); border-radius: var(--radius); margin-bottom: 10px; }
.gallery summary { cursor: pointer; padding: 12px 14px; font-weight: 600; }
.gallery summary .muted { font-weight: 400; margin-left: 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; padding: 0 10px 10px; }
.thumb { position: relative; aspect-ratio: 4/3; background: #000; border-radius: 6px; overflow: hidden; cursor: pointer; border: none; padding: 0; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb span {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 2px 6px; font-size: .7rem;
  background: rgba(0,0,0,.6); color: #fff;
}
.thumb.manual span { color: #fcd34d; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 50; display: grid; place-items: center; padding: 12px; }
.lightbox-inner { max-width: 100%; max-height: 100%; display: flex; flex-direction: column; gap: 10px; }
.lightbox-inner img { max-width: 100%; max-height: 80vh; object-fit: contain; border-radius: 8px; }
.lightbox-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.lightbox-bar span { flex: 1; font-size: .85rem; color: var(--muted); }

.overlay { position: absolute; pointer-events: none; image-rendering: pixelated; }
.check { display: flex; gap: 10px; align-items: flex-start; }
.check input { margin-top: 4px; width: 20px; height: 20px; flex: none; }
