/* Swytch Studio: top bar, Live and Preview windows, sources and assets, tabbed side panel. */
.studio { display: grid; grid-template: "bar bar" auto "main tabs" auto "main side" minmax(0, 1fr) / minmax(0, 1fr) 380px; height: 100%; overflow: hidden; }
#bar { grid-area: bar; display: flex; align-items: center; gap: 10px; padding: max(10px, env(safe-area-inset-top)) 14px 10px; }
.brand { font-size: 18px; letter-spacing: -.01em; }
.grow { flex: 1; }
.chip { padding: 5px 11px; border-radius: 999px; background: var(--card); font-size: 12px; font-weight: 600; color: var(--dim); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chip:empty { display: none; }
.chip.red { background: var(--red); color: #fff; }
.chip.warn { background: #ffb02026; color: var(--amber); }
#bar meter { width: 90px; height: 10px; }
#bar .btn svg { width: 20px; height: 20px; }
#record[aria-pressed="true"] { background: var(--red); }
main { grid-area: main; overflow: auto; padding: 0 14px 20px; min-width: 0; }
#monitors { display: flex; gap: 12px; justify-content: center; }
figure { margin: 0; position: relative; flex: 1; max-width: calc(var(--pgm-h, calc(100vh - 330px)) * 16 / 9); min-width: 0; }
#pgm, #pvw { display: block; width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: 18px; }
#pgmBox figcaption { display: none; }      /* the big view is the output: no outline, no label */
.pv #pgmBox figcaption { display: block; }
#pvwBox { box-shadow: 0 0 0 2.5px var(--green); border-radius: 18px; }
figcaption { position: absolute; top: 10px; left: 10px; padding: 3px 10px; border-radius: 999px; background: var(--green); color: #04210f; font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
figcaption.red { background: var(--red); color: #fff; }
#fx { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; margin: 12px 0 2px; }
#fx .seg { background: var(--card); }
.field.mini { width: auto; min-height: 40px; border-radius: 12px; padding: 0 10px; }
.sec { margin: 16px 4px 8px; font-size: 13px; color: var(--dim); font-weight: 600; }
#sources, #assets { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 10px; }
.tile { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 14px; overflow: hidden; box-shadow: 0 0 0 1.5px var(--line); }
.tile video, .tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .cut { position: absolute; inset: 0; width: 100%; }
.tile .cut:hover { background: #ffffff12; }
.tile .label { position: absolute; left: 6px; bottom: 6px; max-width: calc(100% - 12px); padding: 3px 9px; border-radius: 999px; background: #000000a6; backdrop-filter: blur(8px); font-size: 12px; font-weight: 600; pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .flags { position: absolute; left: 6px; top: 6px; display: flex; gap: 4px; pointer-events: none; }
.tile .flags span { padding: 2px 7px; border-radius: 999px; background: #000000a6; font-size: 10px; font-weight: 700; }
.tile .flags .warn { background: var(--amber); color: #111; }
.tile .flags .ai { background: var(--blue); color: #fff; }
.tile .more { position: absolute; top: 5px; right: 5px; width: 30px; height: 30px; border-radius: 50%; background: #000000a6; display: grid; place-items: center; }
.tile .more svg { width: 18px; height: 18px; rotate: 90deg; }
.tile.preview { box-shadow: 0 0 0 3px var(--green); }
.tile.suggest { box-shadow: 0 0 0 3px var(--blue); }
.tile.live { box-shadow: 0 0 0 3px var(--red); }
.tile.live .label { background: var(--red); }
.tile .label .batt { display: inline-flex; align-items: center; gap: 2px; margin-left: 6px; color: #ffd0cc; vertical-align: -3px; }
.tile:not(.live) .label .batt { color: var(--red); }
.tile .label .batt svg { width: 16px; height: 16px; }
.tile.offline video { opacity: .2; }
.tile.asset { background: var(--card); display: grid; place-items: center; color: var(--dim); }
.tile.asset svg { width: 34px; height: 34px; }
.tile.asset.on { box-shadow: 0 0 0 3px var(--red); color: var(--text); }

#tabs { grid-area: tabs; display: flex; gap: 2px; padding: 4px; margin: 0 14px 0 0; border-radius: 16px; background: var(--card); }
#tabs button { position: relative; flex: 1; display: grid; justify-items: center; gap: 1px; padding: 7px 0 5px; border-radius: 12px; color: var(--dim); font-size: 10.5px; font-weight: 600; }
#tabs svg { width: 22px; height: 22px; }
#tabs button[aria-current="true"] { background: var(--blue-deep); color: var(--blue); }
#unread { position: absolute; top: 4px; right: 10px; width: 9px; height: 9px; border-radius: 50%; background: var(--red); }
aside { grid-area: side; overflow: auto; padding: 4px 14px 24px 0; }
.panel { display: none; }
[data-panel="inputs"] .panel[data-panel="inputs"], [data-panel="assets"] .panel[data-panel="assets"], [data-panel="audio"] .panel[data-panel="audio"],
[data-panel="camera"] .panel[data-panel="camera"], [data-panel="auto"] .panel[data-panel="auto"], [data-panel="outputs"] .panel[data-panel="outputs"], [data-panel="settings"] .panel[data-panel="settings"] { display: block; }
[data-panel="chat"] .panel[data-panel="chat"] { display: flex; flex-direction: column; height: 100%; }
.panel h2 { font-size: 22px; margin: 12px 4px 10px; }
.panel .seg.wrap { flex-wrap: wrap; }
.panel .seg.wrap button { flex: 1 1 40%; }
.join { display: flex; gap: 14px; align-items: center; padding: 14px; border-radius: 16px; background: var(--card); }
.join img { width: 116px; height: 116px; border-radius: 12px; background: #fff; flex: none; }
.join p { margin: 4px 0 0; font-size: 13px; }
.url { overflow-wrap: anywhere; font-size: 11px !important; }
.filebtn { width: 100%; cursor: pointer; }
.dest { margin-top: 10px; }
.row input[type="range"] { max-width: 55%; }
.row input[type="password"] { background: none; border: 0; text-align: right; color: var(--dim); max-width: 62%; min-height: 34px; }
#thread { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 8px; padding: 6px 0; min-height: 120px; }
.bubble { max-width: 84%; padding: 8px 13px; border-radius: 18px; background: var(--card2); align-self: flex-start; }
.bubble.me { background: var(--blue); align-self: flex-end; }
.bubble small { display: block; font-size: 11px; opacity: .7; }
#chatForm { display: flex; gap: 6px; margin-top: 10px; }
#chatForm .field { border-radius: 999px; min-width: 0; }
#chatForm .icon-btn { background: var(--blue); border-radius: 50%; }
#toast { position: fixed; left: 50%; bottom: 24px; translate: -50%; margin: 0; padding: 10px 18px; border-radius: 999px; background: #f4f6faf2; color: #0b0f18; font-weight: 600; z-index: 80; max-width: 90vw; text-align: center; }
#toast:empty { display: none; }
.remote .local { display: none; }

/* Phones and upright tablets: Live on top, sources below, panels slide up as a sheet above the tab bar. */
@media (max-width: 860px) {
  .studio { grid-template: "bar" auto "main" minmax(0, 1fr) / minmax(0, 1fr); }
  #bar { gap: 6px; padding-left: 10px; padding-right: 10px; }
  #bar meter, .brand, #health { display: none; }
  #record span { display: none; }
  #record { padding: 0 12px; }
  main { padding: 0 10px calc(90px + env(safe-area-inset-bottom)); }
  figure { max-width: none; }
  #monitors { position: sticky; top: 0; z-index: 5; background: var(--bg); padding-bottom: 8px; }
  #fx { justify-content: flex-start; flex-wrap: nowrap; overflow-x: auto; margin: 2px -10px; padding: 0 10px 4px; scrollbar-width: none; }
  #fx > * { flex: none; }
  #sources, #assets { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
  .tile { border-radius: 12px; }
  .tile .label { font-size: 10.5px; left: 4px; bottom: 4px; }
  #tabs { position: fixed; left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); margin: 0; z-index: 30; border-radius: 22px; background: #141c2bf2; backdrop-filter: blur(20px); box-shadow: 0 10px 40px #000a; }
  #tabs button { font-size: 9.5px; }
  aside { position: fixed; left: 0; right: 0; bottom: 0; top: 38%; z-index: 20; padding: 6px 14px calc(96px + env(safe-area-inset-bottom)); background: var(--panel); border-radius: 26px 26px 0 0; box-shadow: 0 -20px 60px #000c; translate: 0 105%; transition: translate .25s ease; }
  .sheet aside { translate: 0 0; }
  #toast { bottom: calc(96px + env(safe-area-inset-bottom)); }
}

/* ---- Cleaner, flatter look for the switcher: neutral charcoal, tight corners, labels inside the tiles. ---- */
.studio { --bg: #111316; --panel: #17191d; --card: #1e2126; --card2: #2a2e35; --blue-deep: #2a2e35; background: var(--bg); grid-template: "bar bar" auto "main side" minmax(0, 1fr) "main tabs" auto / minmax(0, 1fr) 380px; }
.studio #pgm, .studio #pvw, .studio figure, .studio #pvwBox { border-radius: 8px; }
.studio .tile { border-radius: 6px; box-shadow: 0 0 0 1px var(--line); }
.studio .tile.live { box-shadow: 0 0 0 3px var(--red); }
.studio .tile.preview { box-shadow: 0 0 0 3px var(--green); }
.studio .tile.suggest { box-shadow: 0 0 0 3px var(--blue); }
.studio .tile .label { left: 0; right: 0; bottom: 0; max-width: none; border-radius: 0; text-align: center; padding: 4px 6px; background: linear-gradient(transparent, #000000c7); backdrop-filter: none; }
.studio .tile.live .label { background: linear-gradient(transparent, #c8281fd9); }
.studio .tile.add { border: 1.5px dashed #ffffff40; box-shadow: none; background: none; }
.studio #sources { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.studio #tabs { margin: 6px 14px 10px 0; border-radius: 10px; }
.studio #tabs button { border-radius: 8px; }
.studio #tabs button[aria-current="true"] { color: var(--red); background: none; }
.studio .group, .studio .join, .studio .seg { border-radius: 10px; }
.studio .seg > button { border-radius: 7px; }
.studio .icon-btn { border-radius: 10px; }

/* ---- Overlay layout: the picture fills the screen; sources ride along the bottom of it; panels slide in. ---- */
.overlay.studio { grid-template: "bar" auto "main" minmax(0, 1fr) "tabs" auto / minmax(0, 1fr); }
.overlay main { position: relative; padding: 0; overflow: hidden; }
.overlay #monitors { position: absolute; inset: 0; }
.overlay figure { max-width: none; height: 100%; }
.overlay #pgm, .overlay #pvw { width: 100%; height: 100%; object-fit: contain; border-radius: 0; }
.overlay .sec, .overlay #assets { display: none; }
.overlay #fx { position: absolute; top: 8px; left: 50%; translate: -50%; margin: 0; z-index: 4; flex-wrap: nowrap; padding: 4px; border-radius: 12px; background: #111316cc; backdrop-filter: blur(14px); }
.overlay #sources { position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 4; display: flex; gap: 8px; overflow-x: auto; padding: 4px; scrollbar-width: none; }
.overlay #sources .tile { flex: 0 0 clamp(110px, 13vw, 180px); }
.overlay #tabs { margin: 0; border-radius: 0; justify-content: center; gap: 18px; padding: 4px 12px max(4px, env(safe-area-inset-bottom)); }
.overlay #tabs button { flex: 0 0 64px; }
.overlay aside { position: fixed; top: 64px; right: 0; bottom: 62px; width: min(380px, 92vw); z-index: 20; padding: 4px 14px 20px; background: #17191df2; backdrop-filter: blur(18px); border-radius: 12px 0 0 12px; translate: 105% 0; transition: translate .22s ease; box-shadow: -20px 0 60px #0009; }
.overlay.sheet aside { translate: 0 0; }
@media (max-width: 860px) {
  .studio { grid-template: "bar" auto "main" minmax(0, 1fr) / minmax(0, 1fr); }
  .studio #sources { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .studio #tabs { margin: 0; border-radius: 16px; }
  .overlay aside { top: 38%; width: auto; left: 0; border-radius: 16px 16px 0 0; translate: 0 105%; }
  .overlay.sheet aside { translate: 0 0; }
}

/* ---- The side panel is a drawer: tap a tab to open it, tap it again to put it away. ---- */
@media (min-width: 861px) {
  .studio:not(.overlay):not(.sheet) { grid-template: "bar bar" auto "main tabs" minmax(0, 1fr) / minmax(0, 1fr) 72px; }
  .studio:not(.overlay):not(.sheet) aside { display: none; }
  .studio:not(.overlay):not(.sheet) #tabs { flex-direction: column; justify-content: flex-start; gap: 6px; margin: 0 10px 12px 0; }
  .studio:not(.overlay):not(.sheet) #tabs button { flex: none; padding: 9px 0 7px; }
}
#split { height: 18px; display: grid; place-items: center; cursor: row-resize; touch-action: none; margin-top: 4px; }
#split i { width: 54px; height: 5px; border-radius: 3px; background: #ffffff40; }
#split:hover i, #split:focus-visible i { background: #ffffff90; }
.overlay #split, .multiview #split { display: none; }

/* ---- Multiview: the classic switcher look. Big windows on top, eight sources in two rows below. ---- */
.multiview main { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto minmax(0, 1fr); overflow: hidden; padding-bottom: 12px; }
.multiview #monitors { min-height: 0; align-items: stretch; }
.multiview figure { flex: 0 1 auto; height: 100%; aspect-ratio: 16 / 9; max-width: calc(50% - 6px); }
.multiview:not(.pv) figure { max-width: 100%; }
.multiview #pgm, .multiview #pvw { width: 100%; height: 100%; object-fit: contain; }
.multiview #pgmBox figcaption { display: block; }
.multiview .sec, .multiview #assets { display: none; }
.multiview #sources { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-auto-rows: calc(50% - 5px); align-content: start; overflow: auto; min-height: 0; }
.multiview #sources .tile { aspect-ratio: auto; height: 100%; }
.multiview #sources .tile video { object-fit: contain; }
.multiview #sources .tile .label { font-size: 13px; padding: 5px 6px; }
@media (max-width: 860px) { .multiview #sources { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: auto; } .multiview #sources .tile { aspect-ratio: 16 / 9; height: auto; } .multiview figure { max-width: 100%; } }
