:root {
  --bg: #f6f6f9; --surface: #ffffff; --text: #17171c; --muted: #6b6b78; --line: #e4e4ec;
  --accent: #5b3df5; --accent-ink: #ffffff; --accent-soft: #eeeaff;
  --user: #5b3df5; --user-ink: #ffffff; --danger: #c62828; --danger-soft: #fdecec;
  --radius: 14px; --shadow: 0 1px 2px rgba(20,20,40,.06), 0 4px 16px rgba(20,20,40,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f14; --surface: #191920; --text: #ececf2; --muted: #9a9aab; --line: #2a2a35;
    --accent: #8b74ff; --accent-ink: #0f0f14; --accent-soft: #241e45;
    --user: #6d55ff; --user-ink: #ffffff; --danger: #ff6b6b; --danger-soft: #3a1d1d;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.25rem; margin: 0 0 1rem; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.logo { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; }
.topbar nav { display: flex; align-items: center; gap: 1rem; font-size: .92rem; }
.topbar nav a { color: var(--muted); text-decoration: none; }
.topbar nav a:hover { color: var(--text); }
.topbar nav a.credits { background: var(--accent-soft); color: var(--accent); padding: .3rem .7rem; border-radius: 99px; font-weight: 600; }

main { flex: 1; width: 100%; margin: 0 auto; padding: 1.25rem 16px 2rem; display: flex; flex-direction: column; }
main.narrow { max-width: 440px; }
main.wide { max-width: 820px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.auth { margin-top: 6vh; }
.auth form { margin-top: 1rem; }
label { display: block; font-size: .88rem; font-weight: 500; margin-bottom: .85rem; }
input, select, textarea { width: 100%; margin-top: .3rem; padding: .65rem .75rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; padding: .6rem 1.1rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.small { padding: .35rem .7rem; font-size: .85rem; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; font-size: .85rem; cursor: pointer; text-decoration: underline; }

.alert { background: var(--danger-soft); color: var(--danger); padding: .6rem .8rem; border-radius: 10px; margin: .75rem 0; font-size: .9rem; }
.notice { background: var(--accent-soft); padding: .6rem .8rem; border-radius: 10px; margin: .75rem 0; font-size: .9rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.row { display: flex; gap: .6rem; align-items: center; margin-top: .25rem; }
.row.between { justify-content: space-between; flex-wrap: wrap; }

.tabs { display: flex; gap: .4rem; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 1rem; }
.tab { flex: 1; padding: .55rem; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.tab.active { background: var(--accent-soft); color: var(--accent); }

/* chat */
.panel.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .75rem; padding: .25rem 0 1rem; min-height: 40vh; max-height: calc(100vh - 290px); }
.empty { margin: auto 0; text-align: center; padding: 2rem 0; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 99px; padding: .45rem .85rem; font: inherit; font-size: .88rem; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.msg { max-width: 88%; padding: .7rem .95rem; border-radius: 16px; overflow-wrap: anywhere; }
.msg p { margin: 0 0 .5rem; } .msg p:last-child { margin-bottom: 0; }
.msg.user { align-self: flex-end; background: var(--user); color: var(--user-ink); border-bottom-right-radius: 5px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.msg.error { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.msg h4 { margin: .6rem 0 .3rem; font-size: 1rem; }
.msg ul, .msg ol { margin: .25rem 0 .6rem; padding-left: 1.3rem; }
.msg code { background: var(--bg); padding: .1rem .3rem; border-radius: 5px; font-size: .88em; }
.msg pre { background: var(--bg); padding: .7rem; border-radius: 10px; overflow-x: auto; margin: .4rem 0 .6rem; }
.msg pre code { background: none; padding: 0; }
.dots { display: inline-flex; gap: 4px; padding: .3rem 0; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.composer { display: flex; gap: .5rem; align-items: flex-end; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: .45rem; box-shadow: var(--shadow); }
.composer textarea { margin: 0; border: 0; background: transparent; resize: none; max-height: 200px; }
.composer textarea:focus { outline: none; }
.composer-meta { display: flex; justify-content: space-between; padding: .4rem .3rem 0; font-size: .82rem; color: var(--muted); }

/* video */
.options { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin-top: .9rem; }
.price { font-size: .95rem; }
.video-list { display: grid; gap: 1rem; margin-top: 1.25rem; }
.vcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem; box-shadow: var(--shadow); }
.vcard video { width: 100%; border-radius: 10px; background: #000; display: block; margin-bottom: .5rem; }
.vcard video.tall { max-height: 70vh; width: auto; max-width: 100%; margin: 0 auto .5rem; }
.vprompt { margin: .6rem 0 .1rem; }
.vstate { display: flex; align-items: center; gap: .6rem; justify-content: center; text-align: center; padding: 2.2rem 1rem; background: var(--bg); border-radius: 10px; color: var(--muted); flex-direction: row; }
.vstate.failed { color: var(--danger); background: var(--danger-soft); flex-direction: column; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* buy / admin */
.packs { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; margin: 1rem 0; }
.pack { text-align: center; }
.pack .big { font-size: 1.6rem; font-weight: 700; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.table-wrap { overflow-x: auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.stat .big { font-size: 1.4rem; font-weight: 700; }
.inline-form { display: flex; gap: .3rem; }
.inline-form input { width: 80px; margin: 0; padding: .35rem .5rem; }
section + section { margin-top: 1.25rem; }

@media (max-width: 560px) {
  .options { grid-template-columns: 1fr; }
  .topbar nav { gap: .6rem; font-size: .85rem; }
  .msg { max-width: 94%; }
}
