/* Ultra-compact dark stylesheet (rebuilt) */
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  background: #0b0f17;
  color: #e6ecff;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.25;
}

/* Topbar */
.topbar {
  background: #0f1421;
  padding: 6px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #1a2234;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar nav a {
  color: #9fc3ff;
  text-decoration: none;
  font-weight: 600;
}
.topbar nav a:hover {
  text-decoration: underline;
}

/* Layout */
main.layout {
  padding: 8px;
  display: grid;
  gap: 6px;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
}
main.layout.layout-3cols {
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.6fr) minmax(0, 1.2fr);
}
main .left-pane,
main .right-pane,
.center-pane {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.center-pane {
  font-size: 0.92rem;
}

/* Cards */
.card {
  background: #121725;
  border: 1px solid #1f2433;
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}
.card-header {
  padding: 6px 8px;
  border-bottom: 1px solid #1f2433;
}
.card-header.split {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.card-header h2 {
  margin: 0;
  font-size: 0.95rem;
}
.card-body {
  padding: 8px;
}
.small {
  font-size: 0.78rem;
  color: #9aabd6;
}
.tiny {
  font-size: 0.7rem;
  color: #9aabd6;
}

/* Buttons and inputs */
label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.78rem;
  color: #cbd6ff;
}
label input,
label select {
  width: 100%;
  margin-top: 4px;
}
input,
select,
textarea {
  background: #0f1421;
  border: 1px solid #202b42;
  border-radius: 8px;
  color: #e2e8ff;
  padding: 6px 8px;
  font-size: 0.85rem;
}
select {
  appearance: none;
}
button {
  background: #2563eb;
  color: #fff;
  border: none;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}
button.secondary {
  background: #1b2335;
  color: #c3d4ff;
  border: 1px solid #28324a;
}
button.ghost {
  background: transparent;
  color: #9fb4ff;
  border: 1px solid transparent;
}
button.danger {
  background: #be123c;
}
.btn-icon {
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  padding: 0;
}
button.success {
  background: #166534;
}
button.success:hover {
  background: #157033;
}
button.danger:hover {
  background: #a11133;
}
button.secondary:hover {
  background: #232d45;
}

/* Preview */
.preview-wrapper {
  position: relative;
}
.preview-video {
  width: 100%;
  border-radius: 8px;
  background: #080b12;
  border: 1px solid #1a2236;
  min-height: 140px;
}
.preview-controls {
  margin: 6px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.preview-controls label {
  margin: 0;
  font-size: 0.76rem;
  color: #9aa9d1;
}
.preview-controls input[type="range"] {
  accent-color: #3b82f6;
}
.cams-row {
  margin-top: 6px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

/* AIR */
.air-toggle {
  width: 100%;
  display: block;
  padding: 6px 10px;
  border-radius: 8px;
  font-weight: 800;
  letter-spacing: 0.08em;
  border: 1px solid #1f2433;
  background: #12212a;
  color: #a3c5ff;
  margin: 0 0 6px 0;
  text-align: center;
}
.air-toggle.on {
  background: #0d3b24;
  color: #d1fae5;
}
.air-toggle.off {
  background: #3b0d16;
  color: #ffe4e6;
}
.air-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: -2px 0 6px 2px;
}
.air-tools .copy-link-btn {
  padding: 6px 8px;
  border-radius: 6px;
  background: #1c2333;
  color: #c3d4ff;
  border: 1px solid #28324a;
}
.air-toggle.readonly {
  opacity: 0.8;
  cursor: default;
}

/* Chat */
.chat-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat-messages {
  min-height: 120px;
  max-height: 180px;
  overflow-y: auto;
  padding-right: 6px;
  display: grid;
  gap: 4px;
}
.chat-form {
  display: flex;
  gap: 6px;
}
.chat-form .btn-icon {
  width: 30px;
  height: 30px;
}
.chat-item {
  background: #0f1421;
  border: 1px solid #1b2438;
  border-radius: 6px;
  padding: 6px 8px;
}
.chat-meta {
  display: flex;
  justify-content: space-between;
  color: #8ea2cf;
  font-size: 0.78rem;
  margin-bottom: 2px;
}
.chat-user {
  font-weight: 600;
  color: #cfe0ff;
}
.chat-time {
  opacity: 0.8;
}
.chat-text {
  color: #e6ecff;
  word-wrap: break-word;
}

/* Comms */
.comm-status {
  background: rgba(18, 28, 48, 0.6);
  border: 1px solid rgba(60, 88, 140, 0.25);
  padding: 6px 8px;
  border-radius: 6px;
  color: #9fb3e0;
}
.comms-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0 6px;
}
.call-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 6px;
}
.participant-card {
  background: #101522;
  border: 1px solid #1f2433;
  border-radius: 8px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.participant-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.participant-name {
  font-weight: 600;
  color: #f8fafc;
  font-size: 0.9rem;
}
.participant-actions {
  display: flex;
  gap: 6px;
}
.badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 6px;
  background: #1e2a44;
  color: #b9ccff;
  font-size: 0.7rem;
}
.badge.mute {
  background: #442030;
  color: #ffd7e1;
}
.badge.hand {
  background: #2d423b;
  color: #d9fff1;
}
.participant-body {
  display: grid;
  gap: 6px;
}
.participant-video {
  display: flex;
  gap: 8px;
  align-items: center;
}
.participant-card .participant-video .video-thumb {
  display: none;
}
.volume-stack {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 6px;
}
.participant-level {
  display: flex;
  gap: 6px;
  align-items: center;
}
.level-bars {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 3px;
  height: 10px;
}
.level-bar {
  background: linear-gradient(
    180deg,
    rgba(96, 165, 250, 0.7),
    rgba(37, 99, 235, 0.1)
  );
  border-radius: 3px;
  opacity: 0.2;
}
.participant-level.active .level-bar {
  opacity: 1;
}
.volume-slider {
  width: 100%;
  margin-top: 4px;
}
.volume-slider label {
  font-size: 0.7rem;
  color: #7f8db3;
  display: flex;
  justify-content: space-between;
  margin-bottom: 2px;
}
.volume-slider input[type="range"] {
  width: 100%;
  height: 12px;
  accent-color: #60a5fa;
}
.participant-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.74rem;
  color: #7f8db3;
}
.btn-toggle {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid #24314a;
  background: #0f1421;
  color: #cbd6ff;
  font-weight: 700;
}
.btn-toggle.on {
  background: #0d3b24;
  color: #d1fae5;
  border-color: #165a31;
}
.btn-toggle.off {
  background: #3b0d16;
  color: #ffe4e6;
  border-color: #5d1a24;
}
.fx-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: center;
  margin-top: 4px;
}
.fx-row label {
  /* prevent global label width rules from stretching inside fx-row */
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: auto;
  margin: 0;
}
.fx-row .tiny {
  font-size: 0.7rem;
  color: #9fb3ff;
}
.fx-row select.tiny {
  background: #0b1020;
  color: #cbd6ff;
  border: 1px solid #24314a;
  border-radius: 4px;
  padding: 2px 4px;
}
.fx-row .nr-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.fx-row .nr-group .fx-nr {
  width: 90px;
  accent-color: #60a5fa;
  height: 10px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  background: rgba(21, 29, 44, 0.7);
  padding: 4px 6px 0;
  border-radius: 8px 8px 0 0;
  border: 1px solid #1f2433;
  border-bottom: none;
}
.tab-button {
  background: transparent;
  border: none;
  color: #7f8db3;
  padding: 5px 10px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-size: 0.9em;
}
.tab-button.active {
  color: #cbd6ff;
  border-color: #2563eb;
}
.tab-panels {
  background: rgba(8, 11, 18, 0.85);
  border: 1px solid #1f2433;
  border-radius: 0 8px 8px 8px;
  padding: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
}
.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
}
.scenes-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.scene-btn {
  background: #0f1421;
  color: #bcd2ff;
  border: 1px solid #1f2a42;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.scene-btn.active {
  background: #1e2b47;
  color: #e7efff;
  border-color: #2b3a5e;
}
.scene-list-wrap {
  display: grid;
  gap: 6px;
}
.scene-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.scene-row .secondary {
  padding: 4px 8px;
}

/* Game */
.game-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.game-row select {
  background: #0f1421;
  border: 1px solid #1f2a3f;
  color: #e2e8ff;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.82rem;
}
.select-inline {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: #9aa9d1;
}
.table-wrap {
  overflow: auto;
  max-height: 60vh;
  border: 1px solid #1f2433;
  border-radius: 8px;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.table th,
.table td {
  border-bottom: 1px solid #1f2433;
  padding: 4px 6px;
  text-align: left;
}
.table thead th {
  position: sticky;
  top: 0;
  background: #151d2c;
  z-index: 1;
}
.table tr:hover td {
  background: rgba(37, 99, 235, 0.08);
}
.table tr.focused td {
  background: rgba(34, 197, 94, 0.08);
}
.pit-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 6px;
  background: #3a1f2b;
  color: #ffd8e4;
  font-weight: 700;
  font-size: 0.72rem;
}
.camera-badge {
  margin-left: 6px;
  background: #1d2a44;
  color: #b9ccff;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.72rem;
}
.name-matched {
  color: #34d399; /* verde para indicar nombre mapeado desde BD */
  font-weight: 700;
}
.cam-actions {
  display: flex;
  gap: 4px;
}
.cam-btn {
  background: #0f1421;
  color: #cbd6ff;
  border: 1px solid #1f2a42;
  border-radius: 6px;
  padding: 2px 6px;
  cursor: pointer;
  font-size: 0.78rem;
}
.cam-btn:hover {
  background: #182238;
}

/* Cameras row */
.cam-tile {
  flex: 0 0 auto;
  width: 140px;
  height: 84px;
  border-radius: 8px;
  border: 1px solid #1a2236;
  background: #0e1320;
  position: relative;
  overflow: hidden;
}
.cam-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cam-tile .copy-cam-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  background: rgba(10, 18, 36, 0.7);
  color: #e6eeff;
  border: 1px solid rgba(96, 122, 180, 0.4);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.8rem;
}
.cam-tile .label {
  position: absolute;
  left: 6px;
  bottom: 6px;
  background: rgba(0, 0, 0, 0.45);
  color: #cbd6ff;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.72rem;
}

/* Viewer open */
body.viewer-open #btnBackEmbed {
  display: inline-block !important;
}
body.viewer-open #btnOpenViewer {
  display: none !important;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 10px;
}
.modal {
  background: #0f1421;
  border: 1px solid #1f2433;
  border-radius: 10px;
  width: min(680px, 96vw);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
}
.modal header {
  padding: 8px 10px;
  border-bottom: 1px solid #1f2433;
}
.modal header h3 {
  margin: 0;
  font-size: 1rem;
}
.modal .modal-body {
  padding: 8px 10px;
  display: grid;
  gap: 8px;
}
.modal .modal-actions {
  padding: 8px 10px;
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  border-top: 1px solid #1f2433;
}
.source-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  border: 1px solid #1b2438;
  background: #0b101c;
  border-radius: 8px;
  padding: 8px 10px;
}
.source-row label {
  margin: 0;
  font-size: 0.8rem;
  color: #9aa9d1;
}
.source-row .sr-left {
  display: flex;
  gap: 12px;
  align-items: center;
  flex: 1;
  min-width: 0;
}
.source-row .sr-right {
  display: flex;
  gap: 12px;
  align-items: center;
}
.source-row .sr-name input[type="text"] {
  width: 240px;
  max-width: 45vw;
}
.source-row .sr-vol input[type="range"] {
  width: 200px;
}
.source-row .sr-visible input,
.source-row .sr-mute input {
  transform: translateY(1px);
}

/* Responsive */
@media (max-width: 1240px) {
  main.layout,
  main.layout.layout-3cols {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 720px) {
  .topbar {
    padding: 6px 8px;
  }
  main.layout {
    padding: 6px;
    gap: 6px;
  }
  .card-header {
    padding: 6px 8px;
  }
  .card-body {
    padding: 6px 8px;
  }
  body {
    font-size: 12.5px;
  }
}

/* YouTube Broadcast Selection */
.broadcast-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 400px;
  overflow-y: auto;
}

.broadcast-item {
  background: rgba(255, 255, 255, 0.03);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.broadcast-item:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateX(4px);
}

.broadcast-item.selected {
  background: rgba(102, 126, 234, 0.2);
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
}

.broadcast-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #fff;
}

.broadcast-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
}

.broadcast-meta .badge {
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  text-transform: uppercase;
}

.broadcast-meta .date {
  color: rgba(255, 255, 255, 0.7);
}

.broadcast-list .loading,
.broadcast-list .empty,
.broadcast-list .error {
  text-align: center;
  padding: 40px 20px;
  color: rgba(255, 255, 255, 0.5);
}

.broadcast-list .error {
  color: #ff6b6b;
}

/* Modal Tabs */
.modal-tabs {
  display: flex;
  gap: 4px;
  padding: 0 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.2);
}

.tab-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  padding: 12px 20px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
  color: #667eea;
  border-bottom-color: #667eea;
}

.tab-content {
  display: none;
  padding: 20px 0;
}

.tab-content.active {
  display: block;
}

/* AC Multi-Server Styles */
.delta-positive {
  color: #ff6b6b !important;
  font-weight: 600;
}

.delta-negative {
  color: #51cf66 !important;
  font-weight: 600;
}

#acTable tr.focused {
  background-color: rgba(102, 126, 234, 0.2) !important;
  border-left: 3px solid #667eea;
  transition: none !important;
}

#acTable tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.05);
  transition: none !important;
}

.select-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-right: 12px;
}

.select-inline select {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  color: #e6ecff;
  padding: 4px 8px;
  font-size: 12px;
}

.select-inline select:focus {
  outline: none;
  border-color: #667eea;
}

/* Stabilize AC table layout to avoid flicker during updates */
#acTable {
  table-layout: fixed;
  width: 100%;
  border-collapse: collapse;
}

#acTable th,
#acTable td {
  white-space: nowrap;
}

/* Name column: allow ellipsis to avoid layout shifts */
#acTable td:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Fixed widths for time columns to keep columns stable */
#acTable th:nth-child(1),
#acTable td:nth-child(1) {
  width: 48px;
}
#acTable th:nth-child(3),
#acTable td:nth-child(3) {
  width: 56px;
}
#acTable th:nth-child(4),
#acTable td:nth-child(4) {
  width: 72px;
}
#acTable th:nth-child(5),
#acTable td:nth-child(5) {
  width: 72px;
}
#acTable th:nth-child(6),
#acTable td:nth-child(6) {
  width: 84px;
}
#acTable th:nth-child(7),
#acTable td:nth-child(7) {
  width: 84px;
}
#acTable th:nth-child(8),
#acTable td:nth-child(8) {
  width: 84px;
}
#acTable th:nth-child(9),
#acTable td:nth-child(9) {
  width: 72px;
}
