:root {
  /* Gravity Media brand palette */
  --brand: #ff671f;
  --brand-hover: #e2551a;
  --brand-soft: #ffe7da;
  --amber: #f79e1b;
  --plum: #2a1e2a;
  --plum-soft: #463847;
  --cream: #f5f3eb;
  --surface: #ffffff;
  --ink: #2a1e2a;
  --muted: #6b6470;
  --line: #e7e2d8;
  --line-strong: #d8d2c6;
  --ok: #198754;
  --danger: #dc3545;
  --radius: 4px;
  --radius-sm: 4px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, system-ui, sans-serif;
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
}

.material-symbols-outlined {
  font-size: 20px;
  line-height: 1;
  vertical-align: middle;
}

/* ---------- Topbar ---------- */
.topbar {
  background: var(--plum);
  color: #fff;
  border-bottom: 3px solid var(--brand);
}

.topbar-inner {
  width: min(1320px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 14px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: #fff;
  mask: url("/assets/admin/g_square.svg") center / contain no-repeat;
  -webkit-mask: url("/assets/admin/g_square.svg") center / contain no-repeat;
  background: var(--brand);
}

.brand-mark .material-symbols-outlined {
  font-size: 26px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.brand-name {
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.65);
}

.ws-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.85);
}

.ws-pill .material-symbols-outlined {
  font-size: 18px;
}

.ws-pill.is-on {
  background: rgba(25, 135, 84, 0.22);
  color: #b6f0cf;
}

.ws-pill.is-off {
  background: rgba(220, 53, 69, 0.2);
  color: #ffc2c8;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.server-clock {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
}

.server-clock .material-symbols-outlined {
  font-size: 18px;
  color: var(--brand);
}

.server-clock .clock-text {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.lang-select {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.lang-select .material-symbols-outlined {
  font-size: 18px;
  color: rgba(255, 255, 255, 0.8);
}

.lang-select select {
  border: none;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 4px 2px;
  cursor: pointer;
  appearance: auto;
}

.lang-select select option {
  color: var(--ink);
}

/* ---------- Layout ---------- */
.dashboard {
  width: min(1320px, calc(100vw - 32px));
  margin: 16px auto 32px;
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  align-items: start;
  gap: 16px;
}

.col {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.panel h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--plum);
}

.panel h2 .material-symbols-outlined {
  color: var(--brand);
  font-size: 22px;
}

/* ---------- Forms ---------- */
.form-grid {
  display: grid;
  gap: 10px 12px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  align-items: end;
}

.field {
  display: grid;
  gap: 4px;
}

.field-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

input,
select {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%236b6470' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 36px;
}

/* ---------- Communication config blocks ---------- */
.field-quality {
  max-width: 240px;
  margin-bottom: 16px;
}

.mini-status {
  min-height: 40px;
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #faf8f3;
  color: var(--muted);
  font-size: 0.88rem;
}

.monitor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0 0 16px;
}

.monitor-card {
  display: grid;
  gap: 8px;
}

.preview-stack {
  display: grid;
  grid-template-columns: minmax(0, 320px) 34px;
  gap: 8px;
  align-items: stretch;
}

.monitor-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.admin-preview-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--plum);
}

.admin-preview-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(42, 30, 42, 0.68);
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 800;
}

.video-overlay[hidden] {
  display: none;
}

.vu-meter {
  border-radius: 2px;
  overflow: hidden;
  background: #111;
  border: 1px solid var(--line-strong);
}

.vu-meter-bar {
  width: 100%;
  height: 0%;
  background: #d9dde3;
  transition: height 0.08s linear;
}

.vu-meter-bar.is-green {
  background: #3ddc84;
}

.vu-meter-bar.is-yellow {
  background: #ffd166;
}

.vu-meter-bar.is-red {
  background: #ff5d73;
}

.vu-meter-column {
  display: grid;
  grid-template-columns: 1fr 12px;
  gap: 4px;
  align-items: stretch;
}

.vu-meter-scale {
  display: grid;
  align-content: space-between;
  justify-items: end;
  padding: 2px 0;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--muted);
}

.vu-meter-vertical {
  position: relative;
  width: 12px;
}

.vu-meter-vertical .vu-meter-bar {
  position: absolute;
  inset: auto 0 0 0;
}

.config-blocks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}

.config-block {
  min-width: 0;
  margin: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 4px 14px 14px;
}

.config-block legend {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--plum);
  font-size: 0.9rem;
  font-weight: 700;
}

.config-block legend .material-symbols-outlined {
  color: var(--brand);
  font-size: 19px;
}

.config-group {
  margin-top: 14px;
}

.config-group-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.config-group-title .material-symbols-outlined {
  font-size: 17px;
  color: var(--brand);
}

.config-group .form-grid {
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
}

.studio-subblocks {
  display: grid;
  gap: 14px;
}

.config-subblock {
  min-width: 0;
  margin: 14px 0 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px 12px 12px;
  background: rgba(255, 255, 255, 0.5);
}

.config-subblock legend {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 700;
}

.config-subblock legend .material-symbols-outlined {
  color: var(--brand);
  font-size: 18px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--plum);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
}

.btn:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-soft);
}

.btn:active {
  transform: translateY(1px);
}

.btn .material-symbols-outlined {
  font-size: 19px;
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
  color: #fff;
}

.btn-danger {
  background: #fff;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

/* Compact ghost button for the dark topbar */
.btn-ghost {
  width: auto;
  padding: 7px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.btn-ghost:hover {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn-ghost .material-symbols-outlined {
  font-size: 18px;
}

.button-row {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  margin-top: 14px;
}

.invitation-actions {
  margin-top: 10px;
}

[data-session-control]:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1000;
  display: grid;
  gap: 10px;
}

.toast {
  min-width: 260px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: #fff;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  font-size: 0.88rem;
  line-height: 1.45;
}

.toast-success {
  border-color: rgba(25, 135, 84, 0.35);
  background: #f4fff8;
}

/* ---------- Lists & cards ---------- */
.list {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  max-height: 280px;
  overflow: auto;
}

.card {
  margin: 0;
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  line-height: 1.55;
  font-size: 0.85rem;
  overflow: auto;
}

.card strong {
  color: var(--plum);
  font-size: 0.92rem;
}

/* ---------- Sessions: id + LED + hover details ---------- */
.list-sessions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: none;
  overflow: visible;
}

.session-card {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--cream);
  color: var(--ink);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.session-card:hover {
  border-color: var(--brand);
}

.session-card.selected {
  border-color: var(--brand);
  background: var(--brand-soft);
  box-shadow: inset 0 0 0 1px var(--brand);
}

.session-id {
  font-family: "SFMono-Regular", "Menlo", monospace;
  font-size: 0.82rem;
  color: var(--plum);
  white-space: nowrap;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(220, 53, 69, 0.12);
  color: var(--danger);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  animation: live-blink 1s steps(2, start) infinite;
}

.led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: #b9b3ac;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.04);
}

.led-ok {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.18);
  animation: led-pulse 1.8s ease-in-out infinite;
}

.led-warn {
  background: var(--amber);
  box-shadow: 0 0 0 3px rgba(247, 158, 27, 0.2);
}

.led-error {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.18);
}

.led-idle {
  background: #b9b3ac;
}

@keyframes led-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.18); }
  50% { box-shadow: 0 0 0 5px rgba(25, 135, 84, 0.28); }
}

@keyframes live-blink {
  50% { opacity: 0.35; }
}

.session-tooltip {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 30;
  min-width: 220px;
  display: none;
  background: var(--plum);
  color: #f3efe9;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.8rem;
  line-height: 1.5;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
}

.session-tooltip::before {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 16px;
  border: 6px solid transparent;
  border-bottom-color: var(--plum);
}

.session-card:hover .session-tooltip,
.session-card:focus-visible .session-tooltip {
  display: block;
}

.tip-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.tip-key {
  color: var(--brand);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.03em;
}

.selection-hint {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--cream);
  border: 1px dashed var(--line-strong);
  color: var(--muted);
  font-size: 0.85rem;
}

pre {
  margin: 10px 0 0;
  background: var(--plum);
  color: #f0ece9;
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow: auto;
  font-family: "SFMono-Regular", "Menlo", monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  max-height: 220px;
}

#inviteResult:empty {
  display: none;
}

/* ---------- Collapsible full-width logs ---------- */
.logs-panel {
  grid-column: 1 / -1;
  padding: 0;
}

.logs-panel summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 18px;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--plum);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.logs-panel summary::-webkit-details-marker {
  display: none;
}

.logs-panel summary > .material-symbols-outlined:first-child {
  color: var(--brand);
  font-size: 22px;
}

.logs-panel summary .chevron {
  margin-left: auto;
  color: var(--muted);
  transition: transform 0.2s ease;
}

.logs-panel[open] summary .chevron {
  transform: rotate(180deg);
}

.logs-panel[open] summary {
  border-bottom: 1px solid var(--line);
}

.logs-toolbar {
  display: grid;
  gap: 10px;
  padding: 14px 18px 0;
}

.debug-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--plum);
  cursor: pointer;
}

.debug-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.debug-info {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #faf8f3;
  font-family: "SFMono-Regular", "Menlo", monospace;
  font-size: 0.76rem;
  line-height: 1.45;
  color: var(--ink);
}

.debug-info[hidden] {
  display: none;
}

.logs-panel #signalLog {
  margin: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 340px;
  padding-top: 12px;
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .dashboard {
    grid-template-columns: 1fr;
  }

  .preview-stack {
    grid-template-columns: minmax(0, 1fr) 30px;
  }
}

@media (max-width: 700px) {
  .panel {
    padding: 14px;
  }

  .topbar-inner {
    padding: 12px 0;
  }

  .list {
    grid-template-columns: 1fr;
  }

  .monitor-grid {
    grid-template-columns: 1fr;
  }
}

/* Device configuration modal ------------------------------------------------ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(42, 30, 42, 0.55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-dialog {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 960px;
  max-height: 90vh;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 18px 48px rgba(42, 30, 42, 0.28);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 1.05rem;
}

.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.modal-close:hover {
  background: var(--cream);
  color: var(--ink);
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
}

@media (max-width: 720px) {
  .modal-backdrop {
    padding: 12px;
  }
  .modal-dialog {
    max-height: 94vh;
  }
}
