:root {
  --bg: #0f1115;
  --panel: #181b22;
  --line: #2a2f3a;
  --text: #e8eaf0;
  --muted: #8b93a7;
  --accent: #4f8cff;
  --ok: #2ecc71;
  --warn: #f5a623;
  --bad: #e74c3c;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main { max-width: 560px; margin: 0 auto; padding: 16px; }
h1 { font-size: 20px; margin: 4px 0 16px; }
h2 { font-size: 15px; margin: 20px 0 8px; color: var(--muted); font-weight: 600; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  display: grid;
  gap: 12px;
}
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 15px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
input, select, button {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 44px;
  width: 100%;
}
input[type=checkbox] { width: 20px; min-height: 20px; height: 20px; }
input:disabled, select:disabled { opacity: .5; }
button { cursor: pointer; font-weight: 600; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.msg { margin: 0; min-height: 1.4em; color: var(--warn); font-size: 14px; }

/* ── Invio ── */
.preview {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 12px;
}
.preview video { width: 100%; height: 100%; object-fit: contain; }
.preview video.mirror { transform: scaleX(-1); }
.badge {
  position: absolute; top: 8px; left: 8px;
  padding: 3px 10px; border-radius: 99px;
  font-size: 12px; font-weight: 700; background: #0009;
}
.badge::before { content: "●  "; }
.badge.off::before { color: var(--muted); }
.badge.on::before { color: var(--ok); }
.badge.warn::before { color: var(--warn); }
.stats {
  position: absolute; bottom: 8px; left: 8px; right: 8px;
  font: 12px ui-monospace, Menlo, Consolas, monospace;
  color: #fff; text-shadow: 0 1px 2px #000;
}

/* ── Visione ── */
body.view { overflow: hidden; }
.grid {
  height: 100dvh;
  display: grid;
  grid-template-columns: repeat(var(--cols, 1), 1fr);
  gap: 4px;
  padding: 4px;
}
.tile { position: relative; background: #000; border-radius: 6px; overflow: hidden; min-height: 0; }
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; }
.tile .label, .tile .state {
  position: absolute; padding: 3px 8px; border-radius: 6px;
  background: #0009; font-size: 13px;
}
.tile .label { top: 6px; left: 6px; font-weight: 700; }
.tile .state { top: 50%; left: 50%; transform: translate(-50%, -50%); color: var(--muted); }
.tile .state:empty { display: none; }
.tile .tools { position: absolute; bottom: 6px; right: 6px; display: flex; gap: 6px; }
.tile .tools button { width: 40px; min-height: 36px; padding: 0; background: #000a; border-color: #fff3; }
@media (max-width: 700px) and (orientation: portrait) {
  .grid { grid-template-columns: 1fr; }
}

/* ── Link ── */
.links { display: grid; gap: 10px; }
.link { display: grid; gap: 4px; }
.link .lbl { font-size: 13px; color: var(--muted); }
.link .val { display: flex; gap: 6px; }
.link input { font: 12px ui-monospace, Menlo, Consolas, monospace; }
.link button { width: auto; flex: none; }
.note { color: var(--muted); font-size: 13px; }
