:root {
  --bg: #0a0b10;
  --bg-2: #11131c;
  --panel: rgba(22, 24, 34, 0.72);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #eef0f6;
  --muted: #9aa0b3;
  --accent: #e4002b;        /* фирменный красный АФК «Система» */
  --accent-soft: #ff3355;
  --good: #3ddc84;
  --radius: 16px;
  --font: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(900px 600px at 80% -10%, rgba(228, 0, 43, 0.18), transparent 60%),
    radial-gradient(700px 500px at 0% 110%, rgba(80, 90, 255, 0.12), transparent 55%),
    var(--bg);
  z-index: -1;
}

/* TOPBAR */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--panel-border);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 1px;
  background: var(--accent);
  color: #fff;
  padding: 8px 12px;
  border-radius: 10px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 16px; }
.brand-text span { font-size: 12.5px; color: var(--muted); }

.status {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  color: var(--muted);
  padding: 8px 14px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
}
.status .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #5a6072;
  box-shadow: 0 0 0 0 rgba(0,0,0,0);
  transition: background .3s;
}
.status.live .dot { background: var(--good); animation: pulse 1.8s infinite; }
.status.connecting .dot { background: #f5b800; }
.status.error .dot { background: var(--accent); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(61,220,132,.5); }
  70% { box-shadow: 0 0 0 8px rgba(61,220,132,0); }
  100% { box-shadow: 0 0 0 0 rgba(61,220,132,0); }
}

/* LAYOUT */
.layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 22px;
  padding: 26px;
  max-width: 1200px;
  margin: 0 auto;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 22px;
  backdrop-filter: blur(12px);
}

/* CONTEXT FORM */
.context h2 { margin: 0 0 6px; font-size: 17px; }
.context .hint { margin: 0 0 18px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.context label {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 14px;
  font-weight: 600;
}
.context .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input, textarea, select {
  width: 100%;
  margin-top: 6px;
  background: rgba(0,0,0,0.28);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 12px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(228,0,43,0.15);
}
textarea { resize: vertical; }
.voice-pick { margin-top: 4px; }

/* STAGE */
.stage { display: flex; flex-direction: column; align-items: center; }
.orb-wrap { position: relative; width: 320px; height: 320px; display: grid; place-items: center; }
#viz { position: absolute; inset: 0; }
.orb {
  position: relative;
  width: 170px; height: 170px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #2a2d3d, #14151d 70%);
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: inset 0 0 40px rgba(0,0,0,0.6);
  transition: transform .15s ease, box-shadow .3s;
}
.orb #orbLabel {
  font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 1px;
}
.orb.live { box-shadow: inset 0 0 40px rgba(0,0,0,0.4), 0 0 60px rgba(228,0,43,0.25); }
.orb.speaking {
  background: radial-gradient(circle at 35% 30%, #ff506e, var(--accent) 75%);
}
.orb.speaking #orbLabel { color: #fff; }

/* CONTROLS */
.controls { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 22px 0 8px; }
.btn {
  border: 1px solid var(--panel-border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-family: var(--font);
  font-weight: 600;
  font-size: 14px;
  padding: 11px 18px;
  border-radius: 11px;
  cursor: pointer;
  transition: transform .12s, background .2s, opacity .2s;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); background: rgba(255,255,255,0.09); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-soft); }
.btn.active { background: rgba(245,184,0,0.16); border-color: #f5b800; color: #ffd54a; }
.btn.active:hover:not(:disabled) { background: rgba(245,184,0,0.24); }

.cue-hint {
  font-size: 12.5px; color: var(--muted); text-align: center;
  margin: 4px 0 18px; line-height: 1.5; max-width: 380px;
}

/* TRANSCRIPT */
.transcript {
  width: 100%;
  flex: 1;
  min-height: 220px;
  max-height: 360px;
  overflow-y: auto;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.transcript .empty { color: var(--muted); font-size: 13px; margin: auto; }
.msg { max-width: 88%; padding: 9px 13px; border-radius: 12px; font-size: 14px; line-height: 1.45; }
.msg.host { align-self: flex-end; background: rgba(255,255,255,0.07); border: 1px solid var(--panel-border); }
.msg.ai { align-self: flex-start; background: rgba(228,0,43,0.16); border: 1px solid rgba(228,0,43,0.3); }
.msg .who { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 3px; opacity: .7; }
.msg.ai .who { color: var(--accent-soft); }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 18px; }
.foot code { color: var(--text); background: rgba(255,255,255,0.06); padding: 2px 6px; border-radius: 5px; }

/* AVATAR PICKER (form) */
.avatar-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 6px 0 18px; }
.avatar-card {
  background: rgba(0,0,0,0.28);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 8px 8px 10px;
  cursor: pointer;
  font-family: var(--font);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  transition: transform .15s, border-color .2s, box-shadow .2s;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.avatar-card img {
  width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 10px;
}
.avatar-card:hover { transform: translateY(-1px); border-color: rgba(255,255,255,0.18); }
.avatar-card.selected {
  border-color: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(228,0,43,0.18);
}

/* AVATAR STAGE (right panel) */
.avatar-stage {
  position: relative;
  width: 100%;
  max-width: 360px;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  overflow: hidden;
  margin-bottom: 8px;
  background: #11131c;
  border: 1px solid var(--panel-border);
}
.avatar-stage img:not([hidden]), .avatar-stage video:not([hidden]) {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.avatar-glow {
  position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 80px rgba(228,0,43,0);
  transition: box-shadow .25s ease, opacity .3s;
}
.avatar-stage.speaking .avatar-glow {
  box-shadow: inset 0 0 80px rgba(228,0,43,0.45), 0 0 60px rgba(228,0,43,0.18);
}
.avatar-stage.live::after {
  content: "● в эфире";
  position: absolute; top: 10px; left: 12px;
  font-size: 11px; font-weight: 700; letter-spacing: .5px;
  color: var(--good); background: rgba(0,0,0,.55);
  padding: 4px 8px; border-radius: 999px;
}


.btn.danger {
  background: rgba(228,0,43,0.16);
  border-color: rgba(228,0,43,0.45);
  color: #ffd7dd;
}
.btn.danger:hover:not(:disabled) { background: rgba(228,0,43,0.24); }
.suggest-prompt-label {
  display: block;
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 700;
}
.suggest-prompt-label textarea { margin-top: 6px; min-height: 72px; resize: vertical; }
.scenario-category-stack { display: grid; gap: 10px; }
.scenario-category {
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 8px;
  background: rgba(0,0,0,0.12);
}
.scenario-category-title {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.category-empty { color: var(--muted); font-size: 12px; padding: 4px 2px; }
.modal-card select {
  width: 100%;
  margin-top: 6px;
  background: rgba(255,255,255,0.06);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: var(--font);
}

/* REPLY BANK */
.replies { width: 100%; margin-top: 4px; }
.replies-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.replies-header h3 { margin: 0; font-size: 13.5px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .6px; }
.btn.small { padding: 6px 12px; font-size: 12.5px; }
.replies-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.reply-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px 9px 14px;
  font-family: var(--font);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform .12s, background .2s;
}
.reply-btn:hover:not(:disabled) { transform: translateY(-1px); background: rgba(255,255,255,0.1); }
.reply-btn:disabled { opacity: .45; cursor: not-allowed; }
.reply-btn .edit {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 6px;
}
.reply-btn .edit:hover { color: var(--text); background: rgba(255,255,255,0.08); }
.replies-empty { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.replies-empty[hidden] { display: none; }



/* MODE TABS */
.mode-tabs {
  width: 100%;
  max-width: 420px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin: 8px 0 10px;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
}
.mode-tab {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  padding: 9px 12px;
  cursor: pointer;
}
.mode-tab.active {
  background: rgba(255,255,255,0.1);
  color: var(--text);
}
.mode-pane {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.scenario-replies { margin-top: 8px; }
.scenario-grid { align-items: stretch; }
.reply-btn.pending { border-color: rgba(245,184,0,0.55); color: #ffd54a; }
.reply-btn.ready { border-color: rgba(61,220,132,0.45); }
.reply-btn.error { border-color: rgba(228,0,43,0.55); color: #ff8da0; }
.reply-btn .reply-status {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}


.suggest-replies { margin-top: 8px; }
.suggest-meta { color: var(--muted); font-size: 12px; font-weight: 700; }
.suggest-grid .reply-btn { border-color: rgba(255,255,255,0.14); }
.suggest-btn { background: rgba(228,0,43,0.11); }
.scenario-workspace .transcript { margin-top: 14px; }

/* MODAL */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(8, 9, 14, 0.7);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--bg-2);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 22px;
  width: min(440px, 100%);
  display: flex; flex-direction: column;
}
.modal-card h3 { margin: 0 0 14px; font-size: 16px; }
.modal-card label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 12px; font-weight: 600; }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.modal-spacer { flex: 1; }


/* DIRECTOR LAYOUT */
.director-layout {
  display: grid;
  grid-template-columns: minmax(420px, 0.95fr) minmax(420px, 1.05fr);
  gap: 22px;
  padding: 26px;
  max-width: 1380px;
  margin: 0 auto;
}
.video-panel, .operator-panel { min-width: 0; }
.video-panel { display: flex; flex-direction: column; gap: 16px; }
.operator-panel { display: flex; flex-direction: column; gap: 14px; }
.operator-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.operator-head h2 { margin: 0; font-size: 18px; }
.operator-head span { color: var(--muted); font-size: 12px; font-weight: 700; }
.director-video {
  max-width: none;
  width: 100%;
  aspect-ratio: 16 / 9;
  margin: 0;
  border-radius: 12px;
}
.director-video #idleVideo,
.director-video #avatarVideo,
.director-video #avatarStill {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.avatar-stage.live::after { display: none; }
.stage-replies { flex: 1; margin-top: 0; }
.stage-replies .scenario-grid { max-height: 35vh; overflow: auto; padding-right: 2px; }
.compact-context { width: 100%; }
.compact-context .avatar-pick { grid-template-columns: minmax(120px, 180px); margin-bottom: 4px; }
.operator-controls { justify-content: flex-start; margin: 0; }
.operator-panel .transcript { min-height: 240px; max-height: 340px; }
.operator-panel .suggest-grid { max-height: 210px; overflow: auto; padding-right: 2px; }
@media (max-width: 980px) {
  .director-layout { grid-template-columns: 1fr; padding: 18px; }
  .operator-head { flex-direction: column; align-items: flex-start; }
}


.idle-direction {
  display: inline-flex;
  gap: 6px;
  align-self: flex-start;
  padding: 4px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(0,0,0,0.24);
}
.idle-direction button {
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 800;
  padding: 7px 10px;
  cursor: pointer;
}
.idle-direction button.active { background: rgba(255,255,255,0.11); color: var(--text); }
.idle-direction button.queued { color: #ffd54a; }

.login-page { min-height: 100vh; display: grid; place-items: center; }
.login-shell { width: min(420px, calc(100vw - 32px)); }
.login-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 26px;
  backdrop-filter: blur(12px);
}
.login-brand { margin-bottom: 22px; }
.login-form { display: grid; gap: 14px; }
.login-form label { font-size: 12.5px; color: var(--muted); font-weight: 700; }
.login-form .btn { width: 100%; margin-top: 4px; }
.login-error {
  color: #ffd7dd;
  background: rgba(228,0,43,0.14);
  border: 1px solid rgba(228,0,43,0.35);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
}
