:root {
  color-scheme: dark;
  --bg: #0b1020;
  --card: #141b2e;
  --card-2: #1b2440;
  --line: #2a3654;
  --text: #e8edf7;
  --muted: #93a1bd;
  --accent: #5b8cff;
  --accent-2: #7c5cff;
  --danger: #ff6b6b;
  --ok: #35d399;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 20% -10%, #1b2a55 0%, transparent 60%), var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.app { max-width: 1400px; margin: 0 auto; padding: 24px; }

header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
  font-weight: 800; letter-spacing: .5px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
h1 { font-size: 20px; margin: 0; }
header p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.connection { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.connection i { width: 9px; height: 9px; border-radius: 50%; background: #64748b; display: inline-block; }
.connection i.on { background: var(--ok); box-shadow: 0 0 12px var(--ok); }

.btn {
  border: 1px solid var(--line); background: var(--card-2); color: var(--text);
  padding: 10px 16px; border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 600;
  transition: .15s ease;
}
.btn:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; }
.btn.danger { color: #ffdada; border-color: #5c3030; background: #2b1a22; }
.btn.recording { background: #5c1f2b; border-color: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255,107,107,.12); } }

.warning {
  padding: 12px 16px; border-radius: 12px; margin-bottom: 16px;
  background: #37240f; border: 1px solid #7a5420; color: #ffd7a1; font-size: 13px;
}
.hidden { display: none !important; }

main { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(340px, .85fr); gap: 18px; }

.video-card {
  position: relative; border: 1px solid var(--line); border-radius: 18px; overflow: hidden;
  background: #050814; aspect-ratio: 16 / 9; display: grid; place-items: center;
}
.video-card video { width: 100%; height: 100%; object-fit: contain; background: #050814; }
.video-hint { position: absolute; color: var(--muted); font-size: 14px; pointer-events: none; }
.video-overlay { position: absolute; inset: 12px 12px auto; display: flex; justify-content: space-between; align-items: center; }
.badge {
  padding: 5px 12px; border-radius: 999px; background: rgba(9,14,28,.75); border: 1px solid var(--line);
  font-size: 12px; backdrop-filter: blur(8px);
}
.session { font-size: 11px; color: var(--muted); font-family: ui-monospace, monospace; }
.caption {
  position: absolute; left: 10%; right: 10%; bottom: 18px; text-align: center;
  padding: 10px 14px; border-radius: 12px; background: rgba(6,10,22,.78);
  border: 1px solid var(--line); font-size: 16px; backdrop-filter: blur(8px);
}

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 18px; display: flex; flex-direction: column; min-height: 520px; }
.panel-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.panel-title h2 { margin: 0; font-size: 16px; }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 12px; }
.link-btn:hover { color: var(--text); }
.messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 4px; max-height: 44vh; }
.empty { color: var(--muted); font-size: 13px; margin: auto; text-align: center; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: 14px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, #2b4a8f, #3c3a8f); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--card-2); border-bottom-left-radius: 4px; }
.msg.meta { align-self: center; background: transparent; color: var(--muted); font-size: 12px; padding: 2px; }
.msg.error { align-self: center; color: #ffb4b4; font-size: 12px; }

.chat-form { display: flex; gap: 8px; margin-top: 14px; }
.chat-form input {
  flex: 1; min-width: 0; padding: 11px 13px; border-radius: 10px;
  border: 1px solid var(--line); background: #0d1426; color: var(--text); outline: none;
}
.chat-form input:focus { border-color: var(--accent); }
.controls { display: flex; gap: 8px; margin-top: 8px; }
.controls .btn { flex: 1; }

.health-title { margin-top: 18px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.health { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-top: 8px; }
.health div { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.health i { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); }
.health i.on { background: var(--ok); }

.modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(3, 6, 15, .72); backdrop-filter: blur(4px); padding: 20px;
}
.modal-card {
  width: min(640px, 100%); background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 22px; box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-head .link-btn { font-size: 18px; line-height: 1; }
.modal-note { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 10px 0 14px; }
.embed-options { display: flex; flex-wrap: wrap; gap: 14px 20px; margin-bottom: 12px; }
.embed-options label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.embed-options select {
  background: #0d1426; color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 8px; font-size: 13px;
}
#embedCode {
  width: 100%; box-sizing: border-box; resize: vertical; padding: 11px 13px;
  border-radius: 10px; border: 1px solid var(--line); background: #0d1426;
  color: #cfe0ff; font: 12px/1.5 ui-monospace, monospace;
}
.modal-actions { display: flex; gap: 8px; margin-top: 12px; }
.modal-actions .btn { text-decoration: none; text-align: center; }

@media (max-width: 960px) {
  main { grid-template-columns: 1fr; }
  .panel { min-height: 420px; }
}
