:root {
  color-scheme: light;
  --bg: #eef1ed;
  --surface: #fbfcfa;
  --surface-strong: #ffffff;
  --ink: #1f2328;
  --muted: #67706f;
  --border: #d8ddd7;
  --border-strong: #b8c1ba;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --amber: #c87508;
  --rose: #b42355;
  --blue: #3451b2;
  --green: #15803d;
  --shadow: 0 18px 40px rgba(31, 35, 40, 0.09);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.75), rgba(238, 241, 237, 0.85)),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1800px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(251, 252, 250, 0.92);
  box-shadow: var(--shadow);
}

.topbar h1,
.panel h2 {
  margin: 0;
  font-weight: 780;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 1.55rem;
}

.panel h2 {
  font-size: 1.05rem;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar-actions,
.button-row,
.control-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--ink);
  background: var(--surface-strong);
  font-weight: 740;
  transition:
    transform 130ms ease,
    border-color 130ms ease,
    background 130ms ease,
    color 130ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
  transform: none;
}

.button.primary {
  color: #fff;
  background: var(--teal);
}

.button.secondary {
  color: #fff;
  background: var(--blue);
}

.button.danger {
  color: #fff;
  background: var(--rose);
}

.button.ghost {
  border-color: var(--border-strong);
  background: transparent;
}

.status-pill,
.small-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 760;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}

.status-pill[data-state="live"] .status-dot {
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(21, 128, 61, 0.12);
}

.status-pill[data-state="connecting"] .status-dot {
  background: var(--amber);
  box-shadow: 0 0 0 5px rgba(200, 117, 8, 0.14);
}

.status-pill[data-state="error"] .status-dot {
  background: var(--rose);
  box-shadow: 0 0 0 5px rgba(180, 35, 85, 0.12);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(280px, 330px) minmax(420px, 1fr) minmax(300px, 360px);
  grid-template-areas:
    "controls stage telemetry"
    "controls transcripts telemetry";
  gap: 16px;
  margin-top: 16px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(251, 252, 250, 0.94);
  box-shadow: var(--shadow);
}

.controls-panel {
  grid-area: controls;
  padding: 16px;
}

.stage-panel {
  grid-area: stage;
  padding: 16px;
}

.transcript-panel {
  grid-area: transcripts;
  padding: 16px;
}

.telemetry-panel {
  grid-area: telemetry;
  padding: 16px;
}

.panel-heading,
.block-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-heading {
  margin-bottom: 16px;
}

.block-heading {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 760;
}

.block-heading strong {
  color: var(--ink);
}

.stage-actions {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.visual-field {
  width: 136px;
  margin: 0;
  gap: 4px;
}

.visual-field span {
  font-size: 0.68rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

.visual-field select {
  min-height: 32px;
  padding: 0 8px;
  font-size: 0.78rem;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  min-width: 0;
  margin: 0 0 16px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f3f6f2;
}

.segmented legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.segmented label {
  min-width: 0;
}

.segmented input {
  position: absolute;
  opacity: 0;
}

.segmented span {
  display: grid;
  min-height: 36px;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 780;
}

.segmented input:checked + span {
  color: #fff;
  background: var(--teal-dark);
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 740;
}

.field.compact {
  flex: 1;
  margin: 0;
}

.field select,
.slider-block input[type="range"] {
  width: 100%;
}

select,
input[type="text"] {
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
}

input[type="text"] {
  min-width: 0;
}

.mode-segmented {
  margin-top: -6px;
}

.export-field {
  margin-top: 14px;
}

.language-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 0 0 16px;
}

.language-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 760;
}

.swatch {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 730;
}

.toggle.tight {
  min-height: 30px;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.control-row {
  margin-bottom: 14px;
}

.slider-block {
  display: grid;
  gap: 8px;
  margin-bottom: 15px;
}

.slider-block label {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 740;
}

input[type="range"] {
  accent-color: var(--teal);
}

.button-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 8px;
}

.system-note {
  min-height: 58px;
  margin-top: 14px;
  padding: 12px;
  border-left: 3px solid var(--amber);
  border-radius: 7px;
  background: #fff8eb;
  color: #6f4e05;
  font-size: 0.84rem;
  line-height: 1.45;
}

.signal-frame {
  position: relative;
  overflow: hidden;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: clamp(150px, 18vw, 220px);
  border: 1px solid #20262c;
  border-radius: 8px;
  background: #111418;
  contain: paint;
}

#signalCanvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 100%;
}

.signal-overlay {
  position: absolute;
  inset: auto 12px 12px 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.8rem;
  font-weight: 760;
}

.preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.preview-block {
  min-height: 148px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

#sourceVideo {
  display: none;
  width: 100%;
  height: 100px;
  margin-top: 10px;
  border-radius: 6px;
  background: #111418;
  object-fit: cover;
}

.preview-placeholder {
  display: grid;
  height: 100px;
  margin-top: 10px;
  place-items: center;
  border: 1px dashed var(--border-strong);
  border-radius: 6px;
  color: var(--muted);
  background: #f7f8f6;
  font-size: 0.84rem;
  font-weight: 720;
}

.audio-meter {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  align-items: end;
  height: 100px;
  margin-top: 10px;
  padding: 12px;
  border-radius: 6px;
  background: #f7f8f6;
}

.audio-meter span {
  display: block;
  min-height: 15%;
  border-radius: 4px 4px 0 0;
  background: var(--teal);
  opacity: 0.55;
  transform-origin: bottom;
}

.audio-meter.is-live span {
  animation: meter 820ms ease-in-out infinite;
}

.audio-meter span:nth-child(2) {
  animation-delay: 90ms;
}

.audio-meter span:nth-child(3) {
  animation-delay: 180ms;
}

.audio-meter span:nth-child(4) {
  animation-delay: 270ms;
}

.audio-meter span:nth-child(5) {
  animation-delay: 360ms;
}

.audio-meter span:nth-child(6) {
  animation-delay: 450ms;
}

@keyframes meter {
  0%,
  100% {
    transform: scaleY(0.35);
  }
  50% {
    transform: scaleY(1);
  }
}

.transcript-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.transcript-column {
  min-height: 360px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.translated-column {
  border-color: rgba(15, 118, 110, 0.35);
}

.live-caption {
  min-height: 86px;
  margin: 12px 0;
  padding: 12px;
  border-radius: 7px;
  background: #f3f6f2;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  padding-right: 2px;
}

.history-item {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: #33383d;
  font-size: 0.9rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.history-item time {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 760;
}

.meeting-summary {
  display: none;
  grid-template-columns: 0.6fr 1.4fr 0.6fr;
  gap: 10px;
  margin-bottom: 12px;
}

.meeting-summary div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.meeting-summary span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 760;
  text-transform: uppercase;
}

.meeting-summary strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meeting-feed {
  display: none;
  gap: 8px;
  max-height: 260px;
  margin-bottom: 12px;
  overflow: auto;
  padding-right: 2px;
}

.meeting-item {
  padding: 12px;
  border: 1px solid rgba(15, 118, 110, 0.28);
  border-radius: 8px;
  background: #fff;
}

.meeting-item-heading {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 780;
  text-transform: uppercase;
}

.meeting-source,
.meeting-translated {
  margin: 0;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.meeting-source {
  color: var(--muted);
  font-size: 0.86rem;
}

.meeting-translated {
  margin-top: 6px;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 720;
}

body[data-mode="meeting"] .meeting-summary,
body[data-mode="meeting"] .meeting-feed {
  display: grid;
}

body[data-mode="meeting"] .transcript-column {
  min-height: 260px;
}

body[data-mode="meeting"] .live-caption {
  min-height: 70px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric-tile {
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.metric-tile span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 760;
  text-transform: uppercase;
}

.metric-tile strong {
  display: block;
  min-width: 0;
  font-size: 1.02rem;
  overflow-wrap: anywhere;
}

.event-log {
  display: grid;
  align-content: start;
  gap: 8px;
  height: 300px;
  margin-top: 14px;
  overflow: auto;
  padding-right: 2px;
}

.event-line {
  padding: 9px 10px;
  border-left: 3px solid var(--blue);
  border-radius: 6px;
  background: #fff;
  color: #343941;
  font-size: 0.8rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.event-line.error {
  border-left-color: var(--rose);
  background: #fff4f7;
}

.event-line.good {
  border-left-color: var(--green);
}

.checklist {
  display: grid;
  gap: 9px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 720;
}

.checklist div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}

.check-dot.good {
  background: var(--green);
}

.check-dot.warn {
  background: var(--amber);
}

@media (max-width: 1180px) {
  .dashboard-grid {
    grid-template-columns: 320px 1fr;
    grid-template-areas:
      "controls stage"
      "controls transcripts"
      "telemetry telemetry";
  }

  .telemetry-panel {
    display: grid;
    grid-template-columns: minmax(280px, 0.8fr) minmax(340px, 1.2fr) minmax(220px, 0.6fr);
    gap: 14px;
  }

  .telemetry-panel .panel-heading {
    grid-column: 1 / -1;
  }

  .event-log,
  .checklist {
    margin-top: 0;
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions .button,
  .status-pill {
    flex: 1;
    justify-content: center;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "controls"
      "stage"
      "transcripts"
      "telemetry";
  }

  .preview-grid,
  .transcript-grid,
  .telemetry-panel,
  .meeting-summary {
    grid-template-columns: 1fr;
  }

  .signal-frame {
    height: clamp(180px, 42vw, 230px);
  }
}
