:root {
  --bg: #0c0e14;
  --bg-2: #12151f;
  --panel: #151926;
  --panel-2: #1b2030;
  --line: #262c3d;
  --text: #e6e9f2;
  --muted: #8b93a7;
  --accent: #5b8cff;
  --accent-2: #3a6bf0;
  --rec: #ff4d4d;
  --rec-dim: #7a2230;
  --ok: #46d39a;
  --warn: #f5b955;
  --radius: 10px;
  --radius-sm: 7px;

  /* Resizable bar sizes (overridden inline by the resizer, persisted). */
  --top-h: auto;
  --left-w: 290px;
  --right-w: 300px;
  --bottom-h: 168px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-rows: var(--top-h) 7px 1fr 7px var(--bottom-h);
  height: 100vh;
  overflow: hidden;
}

/* Drag handles between bars */
.gutter { position: relative; z-index: 5; background: transparent; }
.gutter::after {
  content: '';
  position: absolute;
  background: var(--line);
  transition: background .12s;
}
.gutter-col { cursor: col-resize; }
.gutter-col::after { top: 0; bottom: 0; left: 50%; width: 2px; transform: translateX(-50%); }
.gutter-row { cursor: row-resize; }
.gutter-row::after { left: 0; right: 0; top: 50%; height: 2px; transform: translateY(-50%); }
.gutter:hover::after, .gutter.dragging::after { background: var(--accent); }
.gutter-col:hover::after, .gutter-col.dragging::after { width: 3px; }
.gutter-row:hover::after, .gutter-row.dragging::after { height: 3px; }

.muted { color: var(--muted); }
.tiny { font-size: 11.5px; }
.hint { font-style: italic; }

/* ---------------- Toolbar ---------------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 14px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  min-height: 0;
  overflow: auto;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .3px; }
.brand-dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #ff7a7a, var(--rec));
  box-shadow: 0 0 10px rgba(255, 77, 77, .7);
}
.brand-name { font-size: 15px; }
.tb-group { display: flex; gap: 6px; align-items: center; }
.tb-spacer { flex: 1; }
.view-toggle { margin-left: auto; }

/* ---------------- Buttons ---------------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 7px 11px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #232a3d; border-color: #36405a; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-color: var(--accent-2); font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.rec { color: #ffd7d7; border-color: var(--rec-dim); }
.btn.rec:hover:not(:disabled) { background: #2a1820; }
.btn.danger { background: #2a1620; border-color: #5a2433; color: #ff9aa7; }
.btn.danger:hover:not(:disabled) { background: #381a26; }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn.block { width: 100%; margin-top: 10px; }

.segmented, .view-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.seg {
  appearance: none; border: 0; background: var(--panel-2); color: var(--muted);
  padding: 7px 13px; font-size: 13px; cursor: pointer; border-right: 1px solid var(--line);
}
.seg:last-child { border-right: 0; }
.seg.active { background: var(--accent-2); color: #fff; font-weight: 600; }
.seg:disabled { opacity: .4; cursor: not-allowed; }

/* Popup menus */
.menu-pop {
  position: fixed; z-index: 100; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .5); min-width: 180px; padding: 4px;
}
.menu-item {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  color: var(--text); padding: 8px 10px; border-radius: 5px; cursor: pointer; font-size: 13px;
}
.menu-item:hover { background: var(--accent-2); }

/* ---------------- Main layout ---------------- */
.main {
  display: grid;
  grid-template-columns: var(--left-w) 7px 1fr 7px var(--right-w);
  min-height: 0;
}
.panel {
  background: var(--panel);
  overflow-y: auto;
  padding: 16px;
}
.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); }
.panel-title { margin: 0 0 14px; font-size: 16px; }
.sub-title { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }

.stage {
  min-width: 0;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(91, 140, 255, .06), transparent),
    var(--bg);
  padding: 16px;
  overflow: auto;
}

/* ---------------- Video grid ---------------- */
.video-grid {
  display: grid;
  gap: 12px;
  height: 100%;
  min-height: 0;
  grid-auto-rows: minmax(0, 1fr);
  grid-template-columns: repeat(2, 1fr);
}
.video-grid[data-count="1"] { grid-template-columns: 1fr; }
.video-grid[data-count="2"] { grid-template-columns: repeat(2, 1fr); }
.video-grid[data-count="3"], .video-grid[data-count="4"] { grid-template-columns: repeat(2, 1fr); }
.video-grid[data-count="5"], .video-grid[data-count="6"] { grid-template-columns: repeat(3, 1fr); }
.video-grid[data-count="7"], .video-grid[data-count="8"], .video-grid[data-count="9"] { grid-template-columns: repeat(3, 1fr); }

.tile {
  position: relative;
  background: #000;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  height: 100%;
  min-height: 0;
  cursor: pointer;
}
.tile-video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.tile.is-selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(91, 140, 255, .35); }
.tile.is-recording { border-color: var(--rec); }
.tile.stream-ended { opacity: .55; }

.tile-overlay {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: rgba(255, 60, 60, .42);
  pointer-events: none;
}
.tile.is-paused .tile-overlay { display: flex; }
.tile.is-paused { border-color: var(--rec); }
.overlay-text { font-size: 22px; font-weight: 800; letter-spacing: 3px; color: #fff; text-shadow: 0 2px 8px rgba(0, 0, 0, .6); }

.tile-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 9px;
  background: linear-gradient(180deg, rgba(0, 0, 0, .65), transparent);
}
.tile-badges { display: flex; align-items: center; gap: 6px; }
.tile-name { font-size: 12.5px; font-weight: 600; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-shadow: 0 1px 3px #000; }
.tile-status { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: #cfd5e6; text-shadow: 0 1px 3px #000; }

.rec-dot { width: 9px; height: 9px; border-radius: 50%; background: #555c70; flex: none; }
.is-recording .rec-dot { background: var(--rec); animation: pulse 1.1s infinite; }
.is-paused .rec-dot { background: var(--warn); }
.is-stopped .rec-dot { background: var(--ok); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

.tile-bottom {
  position: absolute; bottom: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 9px;
  background: linear-gradient(0deg, rgba(0, 0, 0, .7), transparent);
  font-variant-numeric: tabular-nums;
}
.tile-res { font-size: 11.5px; color: #cfd5e6; text-shadow: 0 1px 3px #000; }
.tile-time { font-size: 13px; font-weight: 700; text-shadow: 0 1px 3px #000; }

.tile-controls {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: flex; gap: 6px; opacity: 0; transition: opacity .12s; z-index: 3;
}
.tile:hover .tile-controls, .tile.is-recording .tile-controls, .tile.is-paused .tile-controls { opacity: 1; }
.main-tile .tile-controls { transform: translate(-50%, -50%) scale(1.15); }

.tbtn {
  appearance: none; border: 0; cursor: pointer;
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(15, 18, 28, .82); color: #fff; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid rgba(255, 255, 255, .12); backdrop-filter: blur(3px);
}
.tbtn:hover:not(:disabled) { background: rgba(40, 46, 64, .92); }
.tbtn:disabled { opacity: .35; cursor: not-allowed; }
.tbtn.start { color: #ff8a8a; }
.tbtn.stop { color: #c9d0e2; }
.tbtn.remove:hover:not(:disabled) { background: #5a2433; }

/* ---------------- Speaker view ---------------- */
.speaker-view { display: flex; flex-direction: column; gap: 12px; height: 100%; }
.speaker-main { flex: 1; min-height: 0; display: flex; }
.speaker-main .tile { aspect-ratio: auto; width: 100%; height: 100%; }
.main-tile .tile-video { object-fit: contain; }
.speaker-strip { display: flex; gap: 10px; height: 116px; overflow-x: auto; padding-bottom: 4px; flex: none; }
.strip-tile { aspect-ratio: 16 / 9; height: 100%; flex: none; }

/* ---------------- Empty states ---------------- */
.empty-stage {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center;
}
.empty-emoji { font-size: 46px; }
.empty-title { font-size: 17px; font-weight: 600; }

/* ---------------- Audio bar ---------------- */
.audiobar-wrap { border-top: 1px solid var(--line); background: var(--bg-2); overflow: hidden; display: flex; min-height: 0; }
.audiobar { padding: 10px 14px; overflow: auto; flex: 1; min-height: 0; }
.audiobar-empty { padding: 14px 4px; }
.audio-lane { display: flex; gap: 10px; align-items: stretch; }

.aud-tile {
  flex: 0 0 230px; background: var(--panel); border: 2px solid var(--line);
  border-radius: var(--radius); padding: 9px 10px; cursor: pointer;
  display: flex; flex-direction: column; gap: 7px;
}
.aud-tile.is-selected { border-color: var(--accent); }
.aud-tile.is-recording { border-color: var(--rec); }
.aud-tile.is-paused { border-color: var(--warn); background: #221820; }
.aud-tile.stream-ended { opacity: .55; }
.aud-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.aud-titles { display: flex; align-items: center; gap: 6px; overflow: hidden; }
.aud-name { font-weight: 600; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aud-kind { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.aud-time { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 13px; }
.aud-controls { display: flex; gap: 6px; }
.aud-controls .tbtn { width: 30px; height: 30px; background: var(--panel-2); }

/* meters */
.meter { height: 8px; background: #0a0d15; border-radius: 5px; overflow: hidden; border: 1px solid var(--line); }
.meter-sm { height: 8px; flex: 1; }
.meter-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--ok), #9be36a 70%, #f5d955); transition: width .05s linear; }
.meter-fill.hot { background: linear-gradient(90deg, var(--ok), var(--warn) 60%, var(--rec)); }

/* ---------------- Inspector fields ---------------- */
.field { margin-bottom: 12px; }
.field > label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .5px; }
.text-input, .select {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 7px 9px; border-radius: var(--radius-sm); font-size: 13px;
}
.text-input:focus, .select:focus { outline: none; border-color: var(--accent); }
.kind-chip { display: inline-block; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); font-size: 11px; padding: 3px 9px; border-radius: 20px; margin-bottom: 12px; text-transform: capitalize; }
.check-row { display: flex; align-items: center; gap: 8px; margin: 7px 0; cursor: pointer; font-size: 13px; }
.check-row input { accent-color: var(--accent); width: 15px; height: 15px; }

.stats { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 4px 10px; }
.stat-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.stat-row:last-child { border-bottom: 0; }
.stat-key { color: var(--muted); font-size: 12px; }
.stat-value { font-size: 12px; font-variant-numeric: tabular-nums; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------- Export panel ---------------- */
.export-body { margin-top: 14px; }
.summary { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; margin: 10px 0; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.export-list { display: flex; flex-direction: column; gap: 7px; }
.export-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 10px; }
.ei-info { display: flex; flex-direction: column; min-width: 0; }
.ei-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ei-meta { color: var(--muted); font-size: 11px; }

.merge-block { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; margin-bottom: 10px; }
.merge-video { font-weight: 600; margin-bottom: 7px; font-size: 13px; }
.check-row.tiny { margin: 4px 0; font-size: 12.5px; }

.ff-status { margin-top: 14px; padding: 10px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--panel-2); }
.ff-status.error { border-color: #5a2433; background: #2a1620; color: #ff9aa7; }
.ff-status.ready { border-color: #245a44; }
.ff-msg { font-size: 12.5px; margin-bottom: 8px; }
.ff-status .ff-msg:only-child { margin-bottom: 0; }
.progress { height: 8px; background: #0a0d15; border-radius: 5px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--ok)); width: 0%; transition: width .2s; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; bottom: calc(var(--bottom-h) + 24px); left: 50%; transform: translateX(-50%) translateY(10px);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 16px; border-radius: var(--radius); box-shadow: 0 12px 30px rgba(0, 0, 0, .5);
  z-index: 200; opacity: 0; transition: opacity .2s, transform .2s; max-width: 70vw; font-size: 13px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.warn { border-color: #5a4a24; color: var(--warn); }
.toast.error { border-color: #5a2433; color: #ff9aa7; }

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2a3145; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1100px) {
  :root { --left-w: 230px; --right-w: 240px; }
}
