:root {
  --bg: #0f1115; --panel: #181b22; --panel2: #20242d; --line: #2c313c;
  --text: #eef0f4; --muted: #9aa3b2; --accent: #ff3b5c; --ok: #35d07f; --warn: #ffb020;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 600; }
.brand b { color: var(--accent); }
.chip {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; font-size: 13px; cursor: pointer; max-width: 55vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip.on { border-color: var(--ok); color: var(--ok); }

main { flex: 1; overflow-y: auto; padding: 16px; }
.tab { display: none; max-width: 760px; margin: 0 auto; }
.tab.active { display: block; }
h2 { font-size: 15px; margin: 0 0 10px; }
h2 small { color: var(--muted); font-weight: 400; margin-left: 6px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }

nav {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  border-top: 1px solid var(--line); background: var(--panel);
  padding-bottom: env(safe-area-inset-bottom);
}
nav button {
  position: relative; background: none; border: 0; padding: 12px 4px; color: var(--muted); cursor: pointer;
  border: 0; display: grid; place-items: center;
}
nav button svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
nav button.active { color: var(--accent); }
nav .badge { position: absolute; top: 8px; left: calc(50% + 8px); min-width: 9px; height: 9px; border-radius: 5px; background: var(--accent); }

/* sorgenti */
.sources { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 560px) { .sources { grid-template-columns: repeat(2, 1fr); } }
.source {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 4px;
  min-height: 78px;
}
.source .s-name { font-weight: 600; }
.source .s-state { color: var(--muted); font-size: 13px; }
.source.on { border-color: var(--ok); background: #16241d; }
.source.on .s-state { color: var(--ok); }
.source:disabled { opacity: .45; cursor: not-allowed; }

.meter { display: block; height: 6px; background: #0b0d11; border-radius: 3px; overflow: hidden; margin-top: auto; }
.meter b { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--ok) 0 70%, var(--warn) 85%, var(--accent)); background-size: 100vw 100%; }
.meter.big { height: 10px; flex: 1; margin: 0; }

#preview { width: 100%; max-height: 300px; background: #000; border-radius: var(--radius); margin-top: 12px; }

.monitor { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-top: 12px; }
.mon-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; overflow-x: auto; }
.seg button { background: none; border: 0; border-radius: 7px; padding: 6px 12px; cursor: pointer; color: var(--muted); font-size: 13px; white-space: nowrap; }
.seg button.active { background: var(--panel2); color: var(--text); }
.icon-btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; width: 36px; height: 36px; min-width: 36px; display: grid; place-items: center; cursor: pointer; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.viz-stage { position: relative; height: 220px; background: #0b0d11; border-radius: 10px; overflow: hidden; }
#viz, .viz3d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.viz3d canvas { display: block; width: 100% !important; height: 100% !important; }
.ov-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin: 0 3px 0 8px; vertical-align: -1px; }
.lg-imp { background: var(--warn); } .lg-clip { background: var(--accent); }
#overview { width: 100%; height: 56px; display: block; background: #0b0d11; border-radius: 8px; }
.meters { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.ch { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); }
.ch .meter { position: relative; }
.ch .meter em { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); left: 0; }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 10px; text-align: center; }
.stats div { background: var(--bg); border-radius: 8px; padding: 6px 2px; }
.stats small { display: block; color: var(--muted); font-size: 11px; }
.stats b { font-variant-numeric: tabular-nums; font-size: 13px; }
.stats b.bad { color: var(--accent); }
@media (max-width: 480px) { .stats { grid-template-columns: repeat(3, 1fr); } }
.monitor.full { position: fixed; inset: 0; z-index: 30; margin: 0; border-radius: 0; display: flex; flex-direction: column; overflow-y: auto; }
.monitor.full .viz-stage { flex: 1; min-height: 240px; height: auto; }
.monitor:fullscreen { background: var(--panel); }
.chat-h { margin-top: 18px; }
.avatar { width: 38px; height: 38px; min-width: 38px; border-radius: 50%; background: var(--panel2); display: grid; place-items: center; font-weight: 700; color: var(--accent); }
canvas.mini { display: block; width: 100%; height: 26px; margin: 4px 0 2px; }
.player-stage { height: 180px; }
.pv-wave { display: block; width: 100%; height: 70px; background: #0b0d11; border-radius: 8px; cursor: pointer; }
dialog:has(.player-stage) { width: min(720px, calc(100vw - 32px)); }
.master { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); }
.master #masterDb { width: 70px; text-align: right; }
.clip { padding: 2px 6px; border-radius: 4px; background: var(--panel2); color: var(--line); font-weight: 700; font-size: 11px; }
.clip.on { background: var(--accent); color: #fff; }

.status { text-align: center; margin: 18px 0 10px; }
#timer { font-size: 15px; font-variant-numeric: tabular-nums; color: var(--text); min-width: 42px; }
#recInfo { color: var(--muted); }
body.recording #timer { color: var(--accent); }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input[type=text], input[type=search], input[type=password], select {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; color: var(--text); width: 100%; min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.controls { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 20px 0 8px; }
.btn {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 16px; cursor: pointer; min-width: 110px;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.controls .btn:not(.rec) { padding: 10px 12px; white-space: nowrap; }
.link { color: var(--text); font-weight: 600; word-break: break-all; }
.btn.small { min-width: 0; padding: 8px 12px; font-size: 13px; white-space: nowrap; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--accent); }
.btn.rec { width: 76px; height: 76px; min-width: 76px; border-radius: 50%; border: 3px solid var(--text); background: none; padding: 0; display: grid; place-items: center; }
.btn.rec span { width: 54px; height: 54px; border-radius: 50%; background: var(--accent); transition: .15s; }
body.recording .btn.rec span { width: 28px; height: 28px; border-radius: 6px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .55; } }

/* libreria */
.folders { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; }
.folders button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 14px; cursor: pointer; white-space: nowrap; color: var(--muted);
}
.folders button.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.toolbar input { flex: 1 1 160px; }
/* sul telefono la ricerca prende tutta la riga e i pulsanti vanno sotto, senza sbordare */
@media (max-width: 480px) { .toolbar input { flex-basis: 100%; } .toolbar .btn { flex: 1; } }
.list { display: flex; flex-direction: column; gap: 8px; }
.item, .card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
}
.card { margin-bottom: 12px; }
.item { display: flex; align-items: center; gap: 12px; }
.item .play {
  width: 40px; height: 40px; min-width: 40px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--panel2); display: grid; place-items: center; font-size: 14px;
}
.item .info { flex: 1; min-width: 0; }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .more { background: none; border: 0; cursor: pointer; font-size: 20px; padding: 4px 8px; color: var(--muted); }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--panel2); color: var(--muted); margin-right: 4px; }
.tag.ok { color: var(--ok); } .tag.wait { color: var(--warn); } .tag.live { background: var(--accent); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }

.dot { width: 10px; height: 10px; min-width: 10px; border-radius: 50%; background: var(--line); }
.dot.on { background: var(--ok); } .dot.rec { background: var(--accent); animation: pulse 1.2s infinite; }
code { background: var(--panel2); padding: 2px 6px; border-radius: 6px; user-select: all; word-break: break-all; }

.perm { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.perm:last-child { border: 0; }

/* finestre */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; width: min(440px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h3 { margin-bottom: 12px; }
dialog form { display: flex; flex-direction: column; gap: 10px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
dialog .menu { display: flex; flex-direction: column; gap: 6px; }
dialog .menu .btn { text-align: left; }
dialog video, dialog audio { width: 100%; margin-top: 4px; border-radius: 8px; }

#toast {
  position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px); text-align: center; z-index: 10;
}
#toast.show { opacity: 1; }

/* ---- testata del monitor (correzioni 02.11): registra · timer · impostazioni · viste | sorgenti · viste multiple · schermo intero */
.mon-head { flex-wrap: wrap; row-gap: 8px; }
.mh-left, .mh-right { display: flex; align-items: center; gap: 6px; min-width: 0; }
.mh-right { margin-left: auto; }
.rec-ico { width: 34px; height: 34px; min-width: 34px; border-radius: 50%; border: 2px solid var(--text); background: none; padding: 0; display: grid; place-items: center; cursor: pointer; }
.rec-ico span { width: 20px; height: 20px; border-radius: 50%; background: var(--accent); transition: .15s; }
body.recording .rec-ico span { width: 12px; height: 12px; border-radius: 3px; animation: pulse 1.2s infinite; }
.ico-btn { background: none; border: 0; width: 32px; height: 32px; min-width: 32px; display: grid; place-items: center; cursor: pointer; color: var(--muted); border-radius: 8px; padding: 0; }
.ico-btn:hover, .ico-bar button:hover { color: var(--text); }
.ico-btn svg, .ico-bar svg, .opts-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ico-bar { display: flex; align-items: center; gap: 2px; }
.ico-bar button { position: relative; background: none; border: 0; width: 30px; height: 32px; min-width: 30px; padding: 0; display: grid; place-items: center; cursor: pointer; color: var(--muted); }
.ico-bar button.active { color: var(--accent); }
.ico-bar .source, .ico-bar .source.on { min-height: 0; border-radius: 8px; display: grid; gap: 0; background: none; border: 0; padding: 0; }
.ico-bar .source.on { color: var(--ok); }
.ico-bar .source:disabled { opacity: .35; cursor: not-allowed; }
.ico-bar .source .meter { position: absolute; left: 5px; right: 5px; bottom: 1px; height: 2px; margin: 0; background: transparent; }
.opts { position: relative; }
.opts-btn { display: flex; align-items: center; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; height: 32px; padding: 0 6px; cursor: pointer; color: var(--text); font-size: 12px; max-width: 230px; }
.opts-btn #optsSum { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opts-btn .chev { width: 14px; height: 14px; color: var(--muted); }
.opts-pop { position: absolute; z-index: 40; top: 38px; left: 0; width: min(300px, calc(100vw - 32px)); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.opts-pop[hidden] { display: none !important; }
#recInfo { color: var(--muted); font-size: 12px; }
body.recording #timer { color: var(--accent); }
@media (max-width: 560px) { #optsSum { display: none; } .monitor:not(.full) { position: relative; } .opts { position: static; } .opts-pop { left: 12px; right: 12px; top: 54px; width: auto; } }

/* ---- viste multiple: 1, 2 o 4 finestre, ognuna con la sua vista */
#vizStage { display: grid; gap: 4px; background: transparent; grid-auto-rows: 1fr; }
#vizStage[data-n="2"] { grid-template-columns: 1fr 1fr; height: 260px; }
#vizStage[data-n="4"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; height: 420px; }
.vcell { position: relative; background: #0b0d11; border-radius: 10px; overflow: hidden; min-width: 0; min-height: 0; outline: 1px solid transparent; }
#vizStage:not([data-n="1"]) .vcell.sel { outline-color: rgba(238,240,244,.28); }
.vcell > canvas, .vcell > .viz3d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
@media (max-width: 560px) { #vizStage[data-n="4"] { height: 360px; } #vizStage[data-n="2"] { grid-template-columns: 1fr; height: 360px; } }
.monitor.full #vizStage[data-n] { height: auto; }

/* ---- sfera: cursore del piano di taglio */
.vsfera .cut { position: absolute; right: 8px; bottom: 6px; display: flex; align-items: center; gap: 6px; font-size: 11px; color: rgba(238,240,244,.6); }
.vsfera .cut input { width: 110px; accent-color: var(--accent); }

/* ---- Cartelle: registrazioni (gruppi e cartelle) e dispositivi */
.sec-h { display: flex; align-items: center; gap: 8px; margin: 4px 0 10px; }
#tab-lib .sec-h:not(:first-child) { margin-top: 24px; }
.info-i { width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--muted); background: none; color: var(--muted); font: italic 600 11px/1 Georgia, serif; cursor: pointer; padding: 0; }
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin: 8px 0; }
.fcard { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: flex; align-items: center; gap: 10px; cursor: pointer; text-align: left; min-width: 0; color: var(--text); }
.fcard svg { width: 26px; height: 26px; min-width: 26px; fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.fcard.active svg { stroke: var(--accent); }
.fcard b { display: block; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fcard small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fcard span { min-width: 0; }
.fcard.off { cursor: default; opacity: .55; }

/* ---- chat comune di YouppyApps */
.yc-box { height: calc(100dvh - 150px); min-height: 380px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.nc-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 8px; }
.nc-bar .hint { margin: 0; flex: 1 1 200px; min-width: 0; }
body.yc-on .yc-box { height: calc(100dvh - 215px); }
.nc-act { display: flex; gap: 6px; flex-shrink: 0; }
