/* =========================================================
   Virtual Cam Stream - v2 visual refresh (pro on-set monitor)
   ========================================================= */

:root {
  /* Palette */
  --bg:            #08090c;
  --surface:       #13161c;
  --surface-2:     #1b1f27;
  --border:        rgba(255,255,255,0.07);
  --border-strong: rgba(255,255,255,0.14);
  --fg:            #e7e9ec;
  --muted:         #7a808d;
  --muted-2:       #555a66;
  --accent:        #4f8cff;
  --accent-on:     #ffffff;

  /* Status */
  --status-ok:   #2ecc71;
  --status-warn: #f5a524;
  --status-err:  #ff5c69;

  /* Sizing */
  --topbar-h:    40px;
  --drawer-w:    280px;
  --gap:         4px;
  --radius:      5px;
  --radius-sm:   3px;

  /* Type */
  --font-ui:    -apple-system, "Segoe UI", system-ui, sans-serif;
  --font-mono:  ui-monospace, "JetBrains Mono", "Cascadia Mono", "Consolas", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 13px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; }

kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  color: var(--fg);
  line-height: 1.4;
}

/* ==========================================================
   Top bar (40 px, hardware-style toolbar)
   ========================================================== */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  background: rgba(11, 13, 18, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 0 6px 0 4px;
  line-height: 1;
}
.brand-name {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--fg);
}
.brand-tagline {
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.08em;
  color: var(--muted-2);
  text-transform: lowercase;
}
.brand-tagline span {
  color: var(--muted);
  letter-spacing: 0.1em;
}

.topbar-sep {
  width: 1px;
  height: 22px;
  background: var(--border);
}

.topbar-group { display: flex; gap: 2px; align-items: center; }

/* Generic icon button - 28x28 with icon centered. */
.iconbtn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--muted);
  padding: 0;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.iconbtn:hover {
  background: rgba(255,255,255,0.05);
  color: var(--fg);
}
.iconbtn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.iconbtn.active {
  background: var(--accent);
  color: var(--accent-on);
}
.iconbtn.active:hover {
  background: var(--accent);
  filter: brightness(1.08);
}

.iconbtn .icon { display: block; }

/* Aspect dropdown trigger - has inline label when set */
.aspect-picker { position: relative; }
.aspect-btn {
  width: auto;
  min-width: 28px;
  padding: 0 4px;
  gap: 2px;
}
.aspect-btn .aspect-inline {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.02em;
  padding-right: 2px;
}
.aspect-btn .caret {
  display: inline-flex;
  align-items: center;
  margin-left: -2px;
}
.aspect-btn .caret .icon { width: 12px; height: 12px; }

.aspect-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  margin: 0;
  padding: 3px;
  list-style: none;
  background: rgba(20, 23, 30, 0.97);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  min-width: 110px;
  z-index: 30;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.aspect-menu li {
  padding: 5px 10px;
  font-size: 12px;
  font-family: var(--font-mono);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--fg);
}
.aspect-menu li:hover { background: rgba(255,255,255,0.06); }
.aspect-menu li[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-on);
}

/* Quality preset dropdown - shows current preset abbreviation */
.quality-picker { position: relative; }
.quality-btn {
  width: auto;
  min-width: 56px;
  padding: 0 6px;
  gap: 3px;
}
.quality-btn .quality-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--fg);
}
.quality-btn .caret { display: inline-flex; align-items: center; }
.quality-btn .caret .icon { width: 12px; height: 12px; }
.quality-btn.busy { opacity: 0.6; pointer-events: none; }

.quality-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: rgba(20, 23, 30, 0.97);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  min-width: 200px;
  z-index: 30;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.quality-menu li {
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.quality-menu li:hover { background: rgba(255,255,255,0.06); }
.quality-menu li[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-on);
}
.quality-menu li[aria-selected="true"] .q-detail { color: rgba(255,255,255,0.85); }
.quality-menu li .q-name {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.quality-menu li .q-detail {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
}

/* Status indicator (right-aligned, before drawer button) */
.status {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  padding: 0 8px 0 4px;
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted-2);
  transition: background 0.2s, box-shadow 0.2s;
}
.status[data-state="connected"] .status-dot {
  background: var(--status-ok);
  box-shadow: 0 0 6px rgba(46, 204, 113, 0.6);
}
.status[data-state="reconnecting"] .status-dot {
  background: var(--status-warn);
}

/* ==========================================================
   Grid + tiles
   ========================================================== */

.grid {
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  display: grid;
  gap: var(--gap);
  padding: var(--gap);
  background: black;
}
.grid.layout-1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.grid.layout-2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
.grid.layout-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }

.tile {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  outline: 1px solid var(--border);
}
.tile video {
  width: 100%; height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
}

/* Empty tile state */
.tile.empty {
  outline: 1px dashed rgba(255,255,255,0.12);
  cursor: pointer;
}
.tile-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  color: var(--muted-2);
  pointer-events: none;
}
.tile-empty .icon { width: 32px; height: 32px; opacity: 0.6; }
.tile-empty-hint { font-size: 11px; letter-spacing: 0.04em; color: var(--muted); }

/* SVG overlay layer covers the tile; aspect mask geometry is computed in JS */
.tile .overlay-layer {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* Histogram canvas - top-right area below the stats pill */
.tile .histogram {
  position: absolute;
  top: 30px;
  right: 6px;
  width: 180px;
  height: 64px;
  border-radius: var(--radius-sm);
  pointer-events: none;
  z-index: 2;
  box-shadow: 0 0 0 1px var(--border-strong);
}

/* Always-visible stats pill (resolution + fps) */
.tile-stats {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.02em;
  color: var(--fg);
  background: rgba(0,0,0,0.65);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  pointer-events: none;
  text-transform: lowercase;
}

/* Tile chrome - bottom row, hover-revealed */
.tile-chrome {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 6px 8px 10px;
  background: linear-gradient(transparent, rgba(0,0,0,0.78));
  z-index: 3;
  opacity: 0;
  transition: opacity 0.12s;
}
.tile:hover .tile-chrome,
.tile:focus-within .tile-chrome { opacity: 1; }

.tile-label {
  flex: 1;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.92);
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
}

.tile-chrome .iconbtn {
  width: 24px;
  height: 24px;
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.85);
}
.tile-chrome .iconbtn:hover {
  background: rgba(255,255,255,0.18);
  color: white;
}
.tile-chrome .iconbtn .icon { width: 13px; height: 13px; }

/* Empty tiles still need their chrome buttons hidden (no actions yet) */
.tile.empty .tile-chrome { display: none; }
.tile.empty .tile-stats { display: none; }
.tile:not(.empty) .tile-empty { display: none; }

/* Fullscreen */
.tile:fullscreen { background: black; border-radius: 0; outline: none; }
.tile:fullscreen video { object-fit: contain; }
.tile:fullscreen .tile-chrome { opacity: 1; padding: 14px 18px; }
.tile:fullscreen .tile-label { font-size: 12px; }
.tile:fullscreen .tile-stats { top: 14px; right: 14px; font-size: 11px; padding: 3px 8px; }

/* ==========================================================
   Drawer + backdrop
   ========================================================== */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: var(--topbar-h);
  bottom: 0;
  right: 0;
  width: var(--drawer-w);
  max-width: 90vw;
  background: rgba(15, 17, 22, 0.97);
  border-left: 1px solid var(--border-strong);
  z-index: 25;
  transform: translateX(100%);
  transition: transform 0.18s cubic-bezier(0.2, 0.85, 0.2, 1);
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(12px);
}
.drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.drawer-close {
  color: var(--muted);
}

#cameras { list-style: none; padding: 6px; margin: 0; overflow-y: auto; flex: 1; }
#cameras li {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 12px;
  margin: 2px 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: background 0.1s;
}
#cameras li:hover { background: rgba(255,255,255,0.05); }
#cameras li.active {
  background: rgba(79, 140, 255, 0.10);
  border-left-color: var(--accent);
}
#cameras li.active .cam-name { color: var(--accent); }

#cameras li .cam-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
#cameras li .cam-name {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg);
}
#cameras li .cam-stats {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.02em;
}
#cameras li .cam-ndi {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted-2);
  letter-spacing: 0.01em;
}

#cameras li.empty {
  cursor: default;
  border-left: 0;
  color: var(--muted-2);
  font-size: 12px;
  padding: 10px 12px;
}
#cameras li.empty:hover { background: transparent; }

.drawer-footer {
  padding: 8px 12px 10px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.04em;
}
.drawer-footer kbd { margin: 0 2px 0 0; }

/* ==========================================================
   Responsive: small screens (< 700 px) - drawer slides up,
   topbar may wrap.
   ========================================================== */

@media (max-width: 700px) {
  :root {
    --topbar-h: 78px; /* allows two-row wrap */
  }
  .topbar {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--topbar-h);
    padding: 6px 8px;
    gap: 4px;
  }
  .topbar-sep { display: none; }
  .grid { inset: var(--topbar-h) 0 0 0; }
  .iconbtn { width: 30px; height: 30px; }
  .iconbtn .icon { width: 15px; height: 15px; }
  .status { margin-left: 0; flex: 1 1 100%; padding: 4px 4px 0; font-size: 10px; }
  .status-text { display: inline; }

  .drawer {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: none;
    height: 65vh;
    transform: translateY(100%);
    border-left: 0;
    border-top: 1px solid var(--border-strong);
    border-radius: 14px 14px 0 0;
  }
  .drawer.open { transform: translateY(0); }

  .tile .histogram { width: 130px; height: 50px; top: 28px; }
}
