/* Светлая тема в духе ElevenLabs: белый, чёрные пилюли-кнопки, тонкие границы, мягкие тени */
:root {
  --bg: #ffffff; --panel: #ffffff; --panel2: #f5f5f4; --line: #e7e5e4; --line2: #d6d3d1;
  --text: #0c0a09; --muted: #78716c; --accent: #0c0a09; --accent-ink: #ffffff; --accent-soft: #f5f5f4;
  --ok: #15803d; --warn: #b45309; --err: #dc2626; --info: #2563eb;
  --r: 14px;
  --shadow: 0 1px 2px rgba(12,10,9,.04), 0 4px 16px rgba(12,10,9,.04);
  --shadow-lg: 0 8px 30px rgba(12,10,9,.10);
}
* { box-sizing: border-box; }
body { margin: 0; display: flex; height: 100vh; background: var(--bg); color: var(--text);
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--info); }
::selection { background: #0c0a0922; }

/* ---------- сайдбар ---------- */
#side { width: 248px; flex: none; background: #fafaf9; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow: hidden; }
.brand { font-weight: 700; font-size: 17px; padding: 20px 18px 14px; color: var(--text); letter-spacing: -.2px; }
nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px 12px; }
.nav-btn { text-align: left; background: transparent; border: 0; padding: 9px 12px; border-radius: 10px; cursor: pointer;
  color: var(--muted); font-weight: 500; transition: background .12s, color .12s; }
.nav-btn:hover { background: #f0efed; color: var(--text); }
.nav-btn.active { background: #ecebe9; color: var(--text); }
.nav-btn.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; border-radius: 99px;
  text-align: center; margin-bottom: 8px; padding: 10px 12px; }
.nav-btn.primary:hover { background: #292524; }
.side-title { padding: 12px 18px 6px; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .8px; }
#ep-list { overflow-y: auto; flex: 1; padding: 0 8px 12px; }
.ep-item { padding: 8px 10px; border-radius: 10px; cursor: pointer; margin-bottom: 2px; transition: background .12s; }
.ep-item:hover { background: #f0efed; }
.ep-item.active { background: #ecebe9; }
.ep-item .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.ep-item .s { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }

/* ---------- основная область ---------- */

main { flex: 1; overflow-y: auto; padding: 36px 44px 90px; background: var(--bg); }
main > * { max-width: 1240px; }
h1 { font-size: 28px; font-weight: 700; letter-spacing: -.6px; margin: 0 0 6px; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; letter-spacing: -.1px; }
.sub { color: var(--muted); margin-bottom: 24px; max-width: 720px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
label.f { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
label.f > span { font-weight: 600; color: #57534e; letter-spacing: .1px; }
input[type=text], input[type=number], input[type=password], select, textarea {
  background: #fff; border: 1px solid var(--line2); border-radius: 10px; padding: 9px 12px; width: 100%; color: var(--text);
  transition: border-color .12s, box-shadow .12s; }
textarea { resize: vertical; min-height: 64px; }
input::placeholder, textarea::placeholder { color: #a8a29e; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--text); box-shadow: 0 0 0 3px #0c0a0912; }
/* карточки-настройки: подпись сверху, значение крупнее, без «жирной» рамки селекта */
.pgrid { grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 10px; }
.pgrid > label.f { background: #fafaf9; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px 9px; gap: 2px;
  transition: border-color .12s, background .12s, box-shadow .12s; cursor: pointer; }
.pgrid > label.f:hover { border-color: var(--line2); background: #fff; }
.pgrid > label.f:focus-within { border-color: var(--text); background: #fff; box-shadow: 0 0 0 3px #0c0a0912; }
.pgrid > label.f > span { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.pgrid select { appearance: none; -webkit-appearance: none; border: 0; background: transparent; padding: 2px 22px 2px 0; border-radius: 0;
  font-size: 14px; font-weight: 600; color: var(--text); cursor: pointer; text-overflow: ellipsis; box-shadow: none !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2378716c' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0 center; }
.pgrid select:focus { outline: none; }
/* ---------- кастомный выпадающий список ---------- */
.dd { position: relative; width: 100%; }
.dd-native { position: absolute; inset: 0; opacity: 0; pointer-events: none; width: 100%; height: 100%; }
.dd-btn { width: 100%; text-align: left; cursor: pointer; background: #fff; border: 1px solid var(--line2); border-radius: 10px; padding: 9px 34px 9px 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; font-weight: 500;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2378716c' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; transition: border-color .12s, box-shadow .12s; }
.dd-btn:hover { border-color: #a8a29e; }
.dd-btn:focus-visible, .dd.open .dd-btn { outline: none; border-color: var(--text); box-shadow: 0 0 0 3px #0c0a0912; }
.dd.open .dd-btn { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2378716c' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m18 15-6-6-6 6'/%3E%3C/svg%3E"); }
.dd-menu { display: none; position: absolute; z-index: 40; top: calc(100% + 6px); left: 0; min-width: 100%; width: max-content; max-width: min(420px, 86vw);
  max-height: 320px; overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 6px; box-shadow: var(--shadow-lg); }
.dd.open .dd-menu { display: block; animation: ddIn .12s ease-out; }
@keyframes ddIn { from { opacity: 0; transform: translateY(-4px); } }
.dd-item { padding: 8px 32px 8px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; line-height: 1.35; position: relative; }
.dd-item:hover { background: var(--panel2); }
.dd-item.sel { font-weight: 600; background: #f5f5f4; }
.dd-item.sel::after { content: ""; position: absolute; right: 12px; top: 50%; width: 12px; height: 12px; transform: translateY(-50%);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230c0a09' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center/contain no-repeat; }
/* внутри карточек-настроек кнопка без своей рамки */
.pgrid .dd-btn, .pgrid .dd.open .dd-btn, .pgrid .dd-btn:focus-visible { border: 0; box-shadow: none; }
.pgrid .dd-btn { border: 0; background-color: transparent; padding: 2px 22px 2px 0; font-weight: 600; border-radius: 0; box-shadow: none; background-position: right 0 center; }
.pgrid .dd-menu { left: -14px; min-width: calc(100% + 28px); top: calc(100% + 12px); }

.topic-f { margin-top: 14px; }
.topic-f textarea { min-height: 120px; padding: 14px 16px; font-size: 15px; border-radius: 12px; }
.chk { display: flex; gap: 8px; align-items: center; cursor: pointer; color: var(--text); font-size: 14px; }
input[type=checkbox], input[type=radio] { accent-color: #0c0a09; }

/* ---------- кнопки ---------- */
a.btn { color: var(--text); text-decoration: none; display: inline-flex; align-items: center; }
a.btn.primary { color: var(--accent-ink); }
.btn { background: #fff; border: 1px solid var(--line2); border-radius: 99px; padding: 8px 16px; cursor: pointer; white-space: nowrap;
  font-weight: 500; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--panel2); border-color: #a8a29e; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: #292524; border-color: #292524; }
.btn.danger { color: var(--err); }
.btn.danger:hover { background: #fef2f2; border-color: #fca5a5; }
.btn.sm { padding: 5px 12px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.badge { display: inline-block; font-size: 11px; font-weight: 500; padding: 2px 9px; border-radius: 99px; background: var(--panel2); color: var(--muted); border: 1px solid var(--line); }
.badge.ok { color: var(--ok); background: #f0fdf4; border-color: #bbf7d0; }
.badge.warn { color: var(--warn); background: #fffbeb; border-color: #fde68a; }
.badge.info { color: var(--info); background: #eff6ff; border-color: #bfdbfe; }
.badge.busy { color: var(--text); background: #fff; border-color: var(--line2); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .45; } }

/* ---------- сцены ---------- */
.scene { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 16px; align-items: start; }
.sbody { min-width: 0; }
.scene-head { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.scene-num { font-weight: 700; font-size: 14px; margin-right: 2px; }
.scene video, .final video { width: 100%; border-radius: 10px; background: #000; aspect-ratio: 9/16; object-fit: contain; }
.vbox { display: flex; flex-direction: column; gap: 8px; }
.empty-video { aspect-ratio: 9/16; border: 1px dashed var(--line2); border-radius: 12px; display: grid; place-items: center;
  color: var(--muted); font-size: 13px; text-align: center; padding: 10px; background: #fafaf9; }
.counter { font-size: 12px; color: var(--muted); }
.counter.bad { color: var(--warn); }
audio { width: 100%; height: 32px; margin-top: 8px; }
.chain-line { height: 14px; display: flex; justify-content: center; color: var(--muted); font-size: 12px; margin: -10px 0 6px; }

/* ---------- выбор персонажей в формах ---------- */
.chars-pick { display: flex; gap: 12px; flex-wrap: wrap; }
.cpick { width: 96px; border: 2px solid transparent; border-radius: 12px; padding: 4px; cursor: pointer; text-align: center; font-size: 12px;
  background: var(--panel2); transition: border-color .12s, transform .12s; }
.cpick:hover { transform: translateY(-1px); }
.cpick.on { border-color: var(--text); background: #fff; box-shadow: var(--shadow); }
.cpick img, .cpick .noimg { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 9px; background: #e7e5e4; display: grid; place-items: center; }

/* ---------- страница персонажей: галерея слева, форма справа ---------- */
.chars-layout { display: grid; grid-template-columns: minmax(0, 1fr) 440px; gap: 28px; align-items: start; max-width: 1400px; }
.chars-gallery { min-width: 0; }
.chars-gallery .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.chars-form { position: sticky; top: 0; display: flex; flex-direction: column; gap: 14px; margin: 0;
  padding: 24px; box-shadow: var(--shadow-lg); }
.chars-form h2 { margin: 0; font-size: 17px; }
.chars-form .presets { display: flex; gap: 6px; flex-wrap: wrap; }
.chars-form > * { flex-shrink: 0; }
.chars-form .fields { display: flex; flex-direction: column; gap: 12px; }
.chars-form .fields textarea { min-height: 96px; resize: vertical; }
.chars-form .actions { display: flex; flex-direction: column; gap: 8px; }
.chars-form .actions .btn { text-align: center; justify-content: center; }
.empty-gallery { border: 1px dashed var(--line2); border-radius: var(--r); padding: 60px 20px; text-align: center; color: var(--muted); background: #fafaf9; }

.char-card { padding: 0; overflow: hidden; margin: 0; transition: box-shadow .15s, transform .15s; }
.char-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.char-card img, .char-card .noimg { width: 100%; aspect-ratio: 3/4; object-fit: cover; display: grid; place-items: center; color: var(--muted); background: var(--panel2); border-radius: 0; }
.char-card .thumb { position: relative; background: var(--panel2); border-bottom: 1px solid var(--line); }
.char-card .thumb img, .char-card .thumb .noimg { display: block; }
.char-card .tools { position: absolute; top: 8px; right: 8px; display: flex; flex-direction: column; gap: 6px;
  opacity: 0; transform: translateX(4px); transition: opacity .15s, transform .15s; }
.char-card:hover .tools, .char-card:focus-within .tools { opacity: 1; transform: none; }
@media (hover: none) { .char-card .tools { opacity: 1; transform: none; } }
.ib { width: 32px; height: 32px; display: grid; place-items: center; padding: 0; border-radius: 50%; cursor: pointer; font-size: 15px; line-height: 1;
  background: rgba(255,255,255,.92); border: 1px solid var(--line); box-shadow: var(--shadow); backdrop-filter: blur(6px); }
.ib:hover { background: #fff; border-color: var(--line2); }
.ib.danger { color: var(--err); }
.ib.danger:hover { background: #fef2f2; border-color: #fca5a5; }
.char-card .body { padding: 12px 14px 14px; }
.char-card .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.char-card .desc { color: var(--muted); font-size: 12px; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.final { display: grid; grid-template-columns: 300px 1fr; gap: 24px; }
.log { background: #fafaf9; border: 1px solid var(--line); border-radius: 10px; padding: 12px; font: 12px/1.55 ui-monospace, Consolas, monospace;
  max-height: 240px; overflow-y: auto; white-space: pre-wrap; color: #57534e; }
.log .e { color: var(--err); }
.copy { font: 13px/1.55 ui-monospace, Consolas, monospace; background: var(--panel2); border-radius: 10px; padding: 12px; white-space: pre-wrap; }
.hint { color: var(--muted); font-size: 12px; }
.warnbox { background: #fffbeb; border: 1px solid #fde68a; color: var(--warn); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: 13px; }
.sticky { position: sticky; top: -36px; z-index: 5; background: rgba(255,255,255,.9); backdrop-filter: blur(8px);
  padding: 14px 0; margin: -14px 0 14px; border-bottom: 1px solid var(--line); }

#toast { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--text); color: #fff; padding: 11px 16px; border-radius: 12px; max-width: 420px; box-shadow: var(--shadow-lg); }
.toast.err { background: #b91c1c; }

.part { display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 99px; background: var(--text); color: #fff; vertical-align: 1px; }
.modal-bg { position: fixed; inset: 0; background: rgba(12,10,9,.4); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 60; }
.modal { width: min(480px, 92vw); margin: 0; box-shadow: var(--shadow-lg); padding: 24px; }

@media (max-width: 1100px) {
  .chars-layout { grid-template-columns: 1fr; }
  .chars-form { position: static; order: -1; }
}
@media (max-width: 900px) {
  body { flex-direction: column; height: auto; }
  #side { width: auto; max-height: 40vh; }
  .scene, .final { grid-template-columns: 1fr; }
  main { padding: 18px; }
}

/* ---------- страница ролика ---------- */
.ep-top { display: grid; grid-template-columns: minmax(0, 7fr) minmax(280px, 3fr); gap: 16px; align-items: start; }
.ep-top > .card { margin: 0; }
.script-box { position: sticky; top: 72px; }
.btn.wide { width: 100%; text-align: center; padding: 11px 16px; }
.steps { display: flex; flex-direction: column; gap: 2px; }
.step { display: grid; grid-template-columns: 10px 1fr auto; grid-template-areas: "d l v" ". b b"; column-gap: 10px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); }
.step .dot { grid-area: d; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--line2); }
.step.ok .dot { background: var(--ok); border-color: var(--ok); }
.step .sl { grid-area: l; font-weight: 600; }
.step .sv { grid-area: v; color: var(--muted); font-size: 12px; }
.step .btn { grid-area: b; margin-top: 6px; justify-self: start; }
.ep-pub { display: grid; grid-template-columns: minmax(0, 7fr) minmax(280px, 3fr); gap: 16px; margin: 16px 0 0; align-items: start; }
.ep-pub > .card { margin: 0; }
.final-card .final { grid-template-columns: 150px 1fr; gap: 14px; }
.col { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }

.scene-card { padding: 14px; margin-bottom: 10px; box-shadow: none; }
.scene-card:hover { border-color: var(--line2); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two textarea { min-height: 72px; font-size: 13px; padding: 8px 10px; }
.two label.f > span { display: flex; justify-content: space-between; align-items: baseline; }
.counter { font-style: normal; font-weight: 500; }
.foot { margin-top: 8px; gap: 8px; }
label.f.inline { flex-direction: row; align-items: center; gap: 8px; }
label.f.inline input { width: 64px; padding: 5px 8px; }
.chk.sm { font-size: 13px; }
.ib.sm { width: 26px; height: 26px; font-size: 12px; }

@media (max-width: 1100px) {
  .ep-top, .ep-pub { grid-template-columns: 1fr; }
  .script-box { position: static; }
}
@media (max-width: 700px) { .two { grid-template-columns: 1fr; } .scene { grid-template-columns: 1fr; } }

.brand .tag { display: block; font-size: 11px; font-weight: 500; color: var(--muted); letter-spacing: 0; margin-top: 1px; }

.logout { margin: 0 10px 12px; color: var(--muted); }
.logout[hidden] { display: none; }

/* прослушивание голоса в списке */
.dd-item.has-play { display: flex; align-items: center; gap: 10px; padding-right: 12px; }
.dd-item.has-play .dd-text { flex: 1; min-width: 0; }
.dd-item.has-play.sel::after { display: none; }
.dd-item.has-play.sel .dd-text::after { content: " ✓"; font-weight: 700; }
.dd-play { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line2); background: #fff; cursor: pointer;
  font-size: 10px; line-height: 1; display: grid; place-items: center; color: var(--text); transition: background .12s, border-color .12s; padding: 0; }
.dd-play:hover { background: var(--text); color: #fff; border-color: var(--text); }
.dd-play.on { background: var(--text); color: #fff; border-color: var(--text); }
.dd-play.load { animation: pulse 1s infinite; }
