/* SBE-styled components — Button, Card, Badge, Chip, HeroMetric, Toast, etc. */

* { box-sizing: border-box; }
* { margin: 0; }

body { background: var(--bg-page); }

/* ── Layout ─────────────────────────────────────────────────────────── */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.main {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-7) var(--space-5);
  width: 100%;
}
.section + .section { margin-top: var(--space-7); }

.topbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  background: color-mix(in oklch, var(--bg-page), transparent 5%);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  line-height: 0;
}
.topbar-brand {
  display: flex; align-items: center; gap: var(--space-3);
  font-weight: 700;
  line-height: 0;
}
.topbar-brand .brand-logo { display: block; height: 32px; width: auto; }
.topbar-brand .brand-product {
  display: flex; flex-direction: column;
  line-height: 1.15;
}
.topbar-brand .brand-product-name {
  font-size: .9375rem; font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}
.topbar-brand .brand-product-meta {
  font-family: var(--font-mono);
  font-size: .6875rem; font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
@media (max-width: 640px) {
  .topbar-brand .brand-product-meta { display: none; }
}

.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; gap: var(--space-2); align-items: center; }

/* Logo theme switching — !important keeps component-level rules from
   un-hiding the wrong theme version. */
.logo-light { display: block !important; }
.logo-dark  { display: none  !important; }
[data-theme="dark"] .logo-light { display: none  !important; }
[data-theme="dark"] .logo-dark  { display: block !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-light { display: none  !important; }
  :root:not([data-theme="light"]) .logo-dark  { display: block !important; }
}

/* ── Icon system (inline SVG sprite via <use href="#icon-…">) ──── */
.icon {
  width: 1em; height: 1em;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  vertical-align: -0.125em;
  flex-shrink: 0;
}
.icon-sprite { display: none; }

/* ── Broadcast status (promoted from a plain .badge) ────────────── */
.broadcast-status {
  display: inline-flex; align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-hover);
  font-size: .8125rem; font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}
.broadcast-status .icon { width: 16px; height: 16px; }
.broadcast-status .uptime {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  margin-left: var(--space-1);
  color: inherit;
  opacity: 0.85;
}
.broadcast-status.idle { color: var(--text-muted); }
.broadcast-status.starting {
  color: var(--warn);
  background: var(--warn-bg-15);
  border-color: color-mix(in oklch, var(--warn), transparent 70%);
}
.broadcast-status.starting .icon { animation: pulse 1.5s infinite ease-in-out; }
.broadcast-status.live {
  color: var(--ok);
  background: var(--ok-bg-15);
  border-color: color-mix(in oklch, var(--ok), transparent 70%);
}
.broadcast-status.live .icon {
  animation: pulse 2s infinite ease-in-out;
  filter: drop-shadow(0 0 4px var(--ok));
}
.broadcast-status.danger {
  color: var(--danger);
  background: var(--danger-bg-15);
  border-color: color-mix(in oklch, var(--danger), transparent 70%);
}

/* ── Bento broadcast section ──────────────────────────────────── */
.bento-broadcast {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-4);
  align-items: stretch;
}
.bento-broadcast > .card { padding: var(--space-5); }
.bento-control-section + .bento-control-section {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}
.bento-aside {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  gap: var(--space-3);
}
.bento-aside .metric { padding: var(--space-4); }
.bento-aside .metric-value { font-size: 2rem; }
.bento-aside .metric-label { font-size: .75rem; }
@media (max-width: 1100px) {
  .bento-broadcast { grid-template-columns: 1fr; }
  .bento-aside { grid-template-columns: repeat(3, 1fr); grid-template-rows: auto; }
}
@media (max-width: 640px) {
  .bento-aside { grid-template-columns: 1fr; }
}

/* Control row internals */
.control-row {
  display: flex;
  gap: var(--space-3);
  align-items: flex-end;
  flex-wrap: wrap;
}
.control-row .grow { flex: 1; min-width: 240px; }
.lang-chips {
  display: flex; gap: var(--space-3); flex-wrap: wrap;
  margin-top: var(--space-2);
}
.lang-chip {
  display: inline-flex; align-items: center;
  gap: 6px;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-page);
  cursor: pointer;
  font-size: .8125rem; font-weight: 500;
  transition: border-color var(--motion-base), background var(--motion-base);
}
.lang-chip:has(input:checked) {
  border-color: var(--accent-strong);
  background: var(--accent-bg-15);
}
[data-theme="dark"] .lang-chip:has(input:checked),
:root:not([data-theme="light"]) .lang-chip:has(input:checked) {
  border-color: var(--accent);
}
.lang-chip:has(input:disabled) { opacity: 0.5; cursor: not-allowed; }
.lang-chip input { accent-color: var(--accent-strong); }

.mux-output {
  display: flex; gap: var(--space-2); align-items: center;
  flex-wrap: wrap;
}
.mux-output-label {
  font-family: var(--font-mono); font-size: .6875rem;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted);
  min-width: 60px;
}
.mux-output .chip {
  font-size: .8125rem; padding: var(--space-1) var(--space-3);
}
.mux-output-hint {
  font-size: .6875rem; color: var(--text-muted);
  margin-top: var(--space-1);
}

/* ── Stream-card extras ───────────────────────────────────────── */
.stream-card--source {
  border-left: 3px solid var(--text-muted);
}
.stream-source-tag {
  font-family: var(--font-mono); font-size: .625rem;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 1px var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
}
[data-theme="dark"] .card:hover, :root:not([data-theme="light"]) .card:hover {
  background: color-mix(in oklch, var(--bg-surface), var(--bg-elevated) 50%);
}

/* ── AI engines (Translation models) — purple agent marker ────── */
.engines-card {
  border-left: 3px solid var(--agent);
  background: linear-gradient(
    to right,
    var(--agent-bg-5),
    var(--bg-surface) 40%
  );
}
.engines-card .card-title { font-style: italic; }
.engines-card .ai-disclaimer {
  font-size: .6875rem; font-style: italic;
  color: var(--text-muted);
  margin-top: -8px; margin-bottom: var(--space-3);
}
.engines-card .model-row .display-name {
  font-style: italic;
  font-weight: 600;
}

/* ── Footer chips (drawer triggers) ───────────────────────────── */
.footer-chips {
  display: flex; gap: var(--space-3); flex-wrap: wrap;
  margin-top: var(--space-7);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border);
}
.footer-chip {
  display: inline-flex; align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: .8125rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color var(--motion-base), background var(--motion-base), color var(--motion-base);
}
.footer-chip:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
  color: var(--text-primary);
}
.footer-chip .icon { width: 14px; height: 14px; }
.footer-chip .count {
  font-family: var(--font-mono); font-size: .6875rem;
  background: var(--bg-hover); padding: 0 6px; border-radius: var(--radius-sm);
  margin-left: var(--space-1);
}
.footer-chip .count.warn { background: var(--warn-bg-15); color: var(--warn); }
.footer-chip .count.danger { background: var(--danger-bg-15); color: var(--danger); }

/* ── Drawer primitive ─────────────────────────────────────────── */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: color-mix(in oklch, var(--bg-page), transparent 30%);
  backdrop-filter: blur(2px);
  z-index: 150;
  opacity: 0; pointer-events: none;
  transition: opacity var(--motion-slow) ease;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; right: 0;
  width: 380px; height: 100vh;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform var(--motion-slow) ease;
  z-index: 200;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.drawer-title {
  font-size: 1rem; font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}
.drawer-body {
  flex: 1; overflow-y: auto;
  padding: var(--space-4) var(--space-5);
}
@media (max-width: 640px) {
  .drawer { width: 100vw; }
}

/* Log inside drawer */
.drawer #log,
.drawer-log {
  margin: 0; max-height: none; height: 100%;
  font-family: var(--font-mono); font-size: .75rem;
  background: var(--bg-console); color: var(--text-console);
  padding: var(--space-3); border-radius: var(--radius-sm);
  overflow-y: auto;
}
.drawer-log .log-line { padding: 1px 0; }
.drawer-log .log-ok { color: var(--text-console-ok); }
.drawer-log .log-warn { color: var(--text-console-warn); }
.drawer-log .log-err { color: var(--text-console-err); }

/* Keyboard shortcuts table */
.shortcuts-table {
  width: 100%; border-collapse: collapse;
  font-size: .8125rem;
}
.shortcuts-table th,
.shortcuts-table td {
  text-align: left;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}
.shortcuts-table th {
  font-weight: 600; color: var(--text-secondary);
  font-size: .6875rem; text-transform: uppercase; letter-spacing: 0.06em;
}
/* ── Dashboard helper utilities (replace inline-styles) ───────── */
.spacing-top-2  { margin-top: var(--space-2); }
.spacing-top-3  { margin-top: var(--space-3); }
.spacing-bot-3  { margin-bottom: var(--space-3); }
.row-spaced {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: var(--space-3);
}
.row-flow {
  display: flex; justify-content: space-between;
  padding: var(--space-1) 0;
  border-bottom: 1px solid var(--border);
}
.row-flow:last-child { border-bottom: none; }
.legend-spacer { margin-left: auto; }
.input-narrow { min-width: 140px; }
.preview-empty {
  font-style: italic;
  color: var(--text-muted);
}
.engines-card .quota-fill { width: var(--quota-ratio, 0%); }

.shortcuts-table kbd {
  display: inline-block;
  padding: 2px 6px;
  font-family: var(--font-mono); font-size: .75rem;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-family: inherit; font-size: .875rem; font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--motion-base) ease,
              border-color var(--motion-base) ease,
              transform var(--motion-base) ease;
  text-decoration: none;
  background: transparent;
  color: inherit;
  white-space: nowrap;
}
.btn:focus-visible {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}
.btn:active { transform: scale(0.97); }
.btn[disabled], .btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--text-primary);
  color: var(--bg-page);
  border-color: var(--text-primary);
}
[data-theme="dark"] .btn-primary, :root:not([data-theme="light"]) .btn-primary {
  background: var(--accent);
  color: var(--bg-page);
  border-color: var(--accent);
}
.btn-primary:hover { opacity: .9; }

.btn-ghost {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.btn-ghost:hover { background: var(--bg-hover); }

.btn-destructive {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-destructive:hover {
  background: var(--danger-bg-15);
}

.btn-pill { border-radius: 999px; padding-left: var(--space-5); padding-right: var(--space-5); }

.btn-icon {
  padding: var(--space-2);
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
}

/* ── Cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: border-color var(--motion-base) ease, transform var(--motion-base) ease;
}
.card:hover {
  border-color: var(--border-strong);
}
[data-theme="light"] .card:hover {
  transform: translateY(-2px);
}
.card-title { font-size: .875rem; font-weight: 600; color: var(--text-secondary); margin-bottom: var(--space-3); text-transform: uppercase; letter-spacing: 0.05em; }
.card-meta { font-size: .75rem; color: var(--text-muted); }

/* ── Hero metrics ───────────────────────────────────────────────── */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}
@media (max-width: 800px) {
  .metric-grid { grid-template-columns: 1fr; }
}
.metric {
  padding: var(--space-5);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.metric-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 3rem;
  line-height: 1;
  font-weight: 600;
  color: var(--text-primary);
}
.metric-label {
  font-size: .875rem;
  color: var(--text-muted);
  margin-top: var(--space-2);
}
.metric.ok .metric-value { color: var(--ok); }
.metric.warn .metric-value { color: var(--warn); }
.metric.danger .metric-value { color: var(--danger); }

/* ── Status pill / badge / chip ─────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: .75rem; font-weight: 600;
  background: var(--bg-hover);
  border: 1px solid var(--border);
}
.badge .icon { width: 12px; height: 12px; }
.badge.ok { background: var(--ok-bg-15); border-color: color-mix(in oklch, var(--ok), transparent 70%); color: var(--ok); }
.badge.warn { background: var(--warn-bg-15); border-color: color-mix(in oklch, var(--warn), transparent 70%); color: var(--warn); }
.badge.danger { background: var(--danger-bg-15); border-color: color-mix(in oklch, var(--danger), transparent 70%); color: var(--danger); }
.badge.agent { background: var(--agent-bg-5); border-color: color-mix(in oklch, var(--agent), transparent 70%); color: var(--agent); font-style: italic; }

.dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
}
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.warn { background: var(--warn); }
.dot.danger { background: var(--danger); }
.dot.pulse { animation: pulse 2s infinite ease-in-out; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.chip {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: .75rem;
  color: var(--text-muted);
  background: var(--bg-hover);
  cursor: default;
}
.chip-copyable { cursor: pointer; transition: background var(--motion-fast); }
.chip-copyable:hover { background: var(--bg-alt); color: var(--text-primary); }

/* ── Input / form ───────────────────────────────────────────────── */
.input, .select {
  display: block; width: 100%;
  padding: var(--space-2) var(--space-3);
  font-family: inherit;
  font-size: .875rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-page);
  color: var(--text-primary);
  transition: border-color var(--motion-base) ease, box-shadow var(--motion-base);
}
.input:focus, .select:focus {
  outline: none;
  border-color: var(--text-primary);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--text-primary), transparent 85%);
}
[data-theme="dark"] .input:focus, [data-theme="dark"] .select:focus,
:root:not([data-theme="light"]) .input:focus, :root:not([data-theme="light"]) .select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent), transparent 85%);
}
label {
  display: block;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-1);
}

/* ── Toggle (button-based switch) ───────────────────────────────── */
.toggle {
  /* reset button defaults — иначе браузер съедает width/height */
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  color: inherit;
  border: 0;
  padding: 0;
  margin: 0;
  /* layout */
  position: relative;
  display: inline-block;
  flex-shrink: 0;
  width: 40px;
  height: 22px;
  box-sizing: border-box;
  background: var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--motion-base) ease;
  vertical-align: middle;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: #FFFFFF;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform var(--motion-base) ease;
}
.toggle[aria-checked="true"] {
  background: var(--ok);
}
.toggle[aria-checked="true"]::after {
  transform: translateX(18px);
}
.toggle:hover {
  filter: brightness(1.05);
}
.toggle:focus-visible {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}
[data-theme="dark"] .toggle:focus-visible,
:root:not([data-theme="light"]) .toggle:focus-visible {
  outline-color: var(--accent);
}

/* ── Toast ──────────────────────────────────────────────────────── */
.toast-stack {
  position: fixed; bottom: var(--space-5); right: var(--space-5);
  z-index: 1000;
  display: flex; flex-direction: column; gap: var(--space-2);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: .875rem;
  max-width: 380px;
  box-shadow: var(--shadow-md);
  animation: toast-in var(--motion-base) ease-out;
}
.toast.ok { border-left: 3px solid var(--ok); }
.toast.warn { border-left: 3px solid var(--warn); }
.toast.danger { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--info); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Code box (for FFmpeg commands etc.) ────────────────────────── */
.cmd-box {
  font-family: var(--font-mono);
  font-size: .75rem;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-console);
  color: var(--text-console-syntax);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: all;
  overflow-x: auto;
  white-space: nowrap;
}

/* ── Reduced motion ─────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
