:root{
  --bg:#FAF6F0; --surface:#fff; --surface-2:#F3EDE4; --surface-3:#EBE2D5;
  --ink:#1F1A14; --ink-2:#5E554A; --ink-3:#7F7466; --line:#E4DACA;
  --accent:#E8892B; --accent-2:#C2571A; --accent-soft:rgba(232,137,43,.12);
  --ok:#2F7D5D; --warn:#B3341F;
  --radius-sm:10px; --radius:16px; --radius-lg:24px;
  --shadow-1:0 1px 2px rgba(31,26,20,.06);
  --shadow-2:0 8px 30px rgba(31,26,20,.08);
  --font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  --mono:ui-monospace,SFMono-Regular,Menlo,monospace;
}
@media (prefers-color-scheme:dark){
  :root{
    --bg:#16120E; --surface:#211B15; --surface-2:#2A231C; --surface-3:#342B22;
    --ink:#F5EFE6; --ink-2:#B3A695; --ink-3:#8F8476; --line:#3A3128;
    --accent:#F0A04B; --accent-2:#FFB870; --accent-soft:rgba(240,160,75,.16);
    --ok:#6FBF9B; --warn:#E0796A;
    --shadow-1:0 1px 2px rgba(0,0,0,.4); --shadow-2:0 8px 30px rgba(0,0,0,.5);
  }
}
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0; background:var(--bg); color:var(--ink); font-family:var(--font);
  font-size:16px; line-height:1.55; -webkit-font-smoothing:antialiased;
  overflow:hidden;
}
button,input,textarea,select{font:inherit; color:inherit}
a{color:var(--accent-2)}
[hidden]{display:none!important}

/* ---------- каркас ---------- */
.shell{display:grid; grid-template-columns:264px 1fr; height:100dvh}
.shell.auth{grid-template-columns:1fr}

aside{
  background:var(--surface); border-inline-end:1px solid var(--line);
  display:flex; flex-direction:column; padding:18px 14px; gap:6px; overflow-y:auto;
}
.brand{display:flex; align-items:center; gap:10px; font-weight:650; font-size:18px;
  letter-spacing:-.01em; padding:6px 8px 14px}
.brand .sun{width:26px;height:26px;border-radius:50%;flex:0 0 auto;
  background:radial-gradient(circle at 35% 32%,#FFD79A 0%,var(--accent) 55%,var(--accent-2) 100%);
  box-shadow:0 0 0 3px var(--accent-soft),0 0 16px rgba(232,137,43,.3)}
nav{display:flex; flex-direction:column; gap:2px}
nav button{
  display:flex; align-items:center; gap:10px; width:100%; text-align:start;
  background:none; border:0; padding:10px 12px; border-radius:var(--radius-sm);
  cursor:pointer; color:var(--ink-2); font-size:15px;
}
nav button:hover{background:var(--surface-2); color:var(--ink)}
nav button[aria-current="page"]{background:var(--accent-soft); color:var(--ink); font-weight:600}
nav button svg{width:18px;height:18px;flex:0 0 auto;opacity:.8}
.side-foot{margin-top:auto; padding:12px 8px 0; border-top:1px solid var(--line); font-size:13px; color:var(--ink-3)}
.side-foot .balance{color:var(--ink-2); font-size:14px; margin-bottom:8px}
.side-foot .balance b{color:var(--ink); font-size:16px}

main{display:flex; flex-direction:column; min-width:0; overflow:hidden}
.topbar{
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  padding:14px 20px; border-bottom:1px solid var(--line); background:var(--bg);
  min-height:60px;
}
.topbar h1{font-size:17px; margin:0; font-weight:640; letter-spacing:-.01em}
.status{display:flex; align-items:center; gap:8px; font-size:13px; color:var(--ink-2)}
.dot{width:8px;height:8px;border-radius:50%;background:var(--ok)}
.dot.busy{background:var(--accent); animation:pulse 1.4s infinite}
@keyframes pulse{0%,100%{opacity:1}50%{opacity:.35}}

.view{flex:1; overflow-y:auto; min-height:0}
.pad{padding:22px 20px 40px; max-width:760px; margin:0 auto; width:100%}

/* ---------- чат ---------- */
.chat{display:flex; flex-direction:column; height:100%}
.msgs{flex:1; overflow-y:auto; padding:20px; display:flex; flex-direction:column; gap:14px}
.msgs-inner{max-width:760px; margin:0 auto; width:100%; display:flex; flex-direction:column; gap:14px}

.msg{max-width:min(88%,620px); display:flex; flex-direction:column; gap:4px}
.msg .bubble{
  padding:13px 16px; border-radius:var(--radius); background:var(--surface);
  border:1px solid var(--line); box-shadow:var(--shadow-1);
  white-space:pre-wrap; overflow-wrap:anywhere;
}
.msg.me{align-self:flex-end; align-items:flex-end}
.msg.me .bubble{background:var(--surface-2); border-color:var(--surface-3)}
.msg-row{display:flex; gap:9px; align-items:flex-start}
.msg-row.me{flex-direction:row-reverse}
.avatar{width:26px;height:26px;border-radius:50%;flex:0 0 auto;margin-top:2px;
  background:radial-gradient(circle at 35% 32%,#FFD79A 0%,var(--accent) 55%,var(--accent-2) 100%);
  box-shadow:0 0 0 2px var(--accent-soft)}
.msg .saved{
  font-size:12.5px; color:var(--ink-3); padding-inline-start:6px;
  display:flex; gap:6px; align-items:center;
}
.msg .saved b{color:var(--ink-2); font-weight:600}

.composer{border-top:1px solid var(--line); padding:12px 20px calc(12px + env(safe-area-inset-bottom)); background:var(--bg)}
.composer-inner{max-width:760px; margin:0 auto; display:flex; gap:10px; align-items:flex-end}
textarea#input{
  flex:1; resize:none; min-height:46px; max-height:160px; padding:12px 14px;
  border:1px solid var(--line); border-radius:14px; background:var(--surface);
  outline:none; line-height:1.4;
}
textarea#input:focus{border-color:var(--accent); box-shadow:0 0 0 3px var(--accent-soft)}
.send{
  width:46px;height:46px;border-radius:14px;border:0;cursor:pointer;flex:0 0 auto;
  background:linear-gradient(180deg,#F6A34E,var(--accent)); color:#2A1A08;
  display:grid; place-items:center; box-shadow:0 4px 14px rgba(232,137,43,.3);
}
.send:disabled{opacity:.5; cursor:default}
.composer .hint{max-width:760px; margin:8px auto 0; font-size:12.5px; color:var(--ink-3);
  display:flex; justify-content:space-between; gap:12px; white-space:nowrap}
@media(max-width:520px){
  .composer .hint{font-size:12px; justify-content:flex-end}
  .composer .hint #hint-left{display:none}
}


/* ---------- markdown внутри пузыря ---------- */
.bubble p{margin:0 0 8px}
.bubble p:last-child{margin-bottom:0}
.bubble ul{margin:6px 0 8px; padding-inline-start:20px}
.bubble li{margin:2px 0}
.bubble strong{font-weight:650}
.bubble code{font-family:var(--mono); font-size:.92em; background:var(--surface-2);
  padding:1px 5px; border-radius:5px}

/* ---------- онбординг ---------- */
.choices{display:flex; flex-wrap:wrap; gap:8px; margin-top:4px}
.choice{
  padding:9px 14px; border-radius:999px; border:1px solid var(--line);
  background:var(--surface); cursor:pointer; font-size:14.5px;
}
.choice:hover{border-color:var(--accent); background:var(--accent-soft)}
.choice[aria-pressed="true"]{background:var(--accent-soft); border-color:var(--accent); font-weight:600}
.choice[aria-pressed="true"]::before{content:"✓ "; color:var(--accent-2)}
.card{
  background:var(--surface); border:1px solid var(--line); border-radius:var(--radius);
  padding:16px; box-shadow:var(--shadow-1);
}
.card h3{margin:0 0 10px; font-size:15px; font-weight:640}
.kv{display:grid; grid-template-columns:auto 1fr; gap:6px 14px; font-size:14.5px}
.kv dt{color:var(--ink-2)}
.kv dd{margin:0}


/* ---------- тарифы ---------- */
.plans{display:grid; grid-template-columns:1fr 1fr; gap:12px}
@media(max-width:620px){ .plans{grid-template-columns:1fr} }
.plan{
  position:relative; background:var(--surface); border:1px solid var(--line);
  border-radius:var(--radius); padding:18px; display:flex; flex-direction:column;
}
.plan-best{border-color:var(--accent); box-shadow:0 0 0 3px var(--accent-soft)}
.plan .pill{position:static; align-self:flex-start; margin-bottom:10px}
.plan .pill-ghost{visibility:hidden}
.plan-name{font-size:14px; color:var(--ink-2); margin-bottom:6px; min-height:2.6em; line-height:1.3}
.plan-price{font-size:30px; font-weight:660; letter-spacing:-.02em; line-height:1.1}
.plan-price span{font-size:14px; font-weight:400; color:var(--ink-3); margin-inline-start:4px}
.plan-per{font-size:13.5px; color:var(--ink-2); margin-top:2px}
.plan-points{font-size:13px; color:var(--ink-3); margin-top:8px}
.plan-note{font-size:12.5px; color:var(--ink-2); margin-top:10px; padding-top:10px; border-top:1px solid var(--line)}
.plan-save{font-size:13px; font-weight:600; color:var(--ok); margin-top:6px}
.plan-soon{opacity:.62; border-style:dashed}
.plan-soon .pill{background:var(--line); color:var(--ink-2)}
.plan .btn{margin-top:auto}
.plan-points{margin-bottom:2px}

/* ---------- формы и экраны ---------- */
.field{display:flex; flex-direction:column; gap:6px; margin-bottom:14px}
.field label{font-size:13.5px; color:var(--ink-2)}
.field input,.field select{
  padding:12px 14px; border:1px solid var(--line); border-radius:12px;
  background:var(--surface); outline:none;
}
.field input:focus,.field select:focus{border-color:var(--accent); box-shadow:0 0 0 3px var(--accent-soft)}
.btn{
  padding:13px 20px; border:0; border-radius:12px; cursor:pointer; font-weight:600;
  background:linear-gradient(180deg,#F6A34E,var(--accent)); color:#2A1A08;
  box-shadow:0 4px 16px rgba(232,137,43,.26);
}
.btn:hover{transform:translateY(-1px)}
.btn:disabled{opacity:.6; cursor:default; transform:none}
.btn.ghost{background:none; border:1px solid var(--line); color:var(--ink); box-shadow:none}
.btn.danger{background:none; border:1px solid var(--warn); color:var(--warn); box-shadow:none}
.err{color:var(--warn); font-size:14px; min-height:20px; margin:6px 0 0}
.muted{color:var(--ink-2); font-size:14px}
.section{margin-bottom:26px}
.section > h2{font-size:15px; text-transform:uppercase; letter-spacing:.06em;
  color:var(--ink-3); margin:0 0 10px; font-weight:600}
.row{display:flex; gap:10px; align-items:center; justify-content:space-between; padding:11px 0; border-bottom:1px solid var(--line)}
.row:last-child{border-bottom:0}
.row .label{font-size:15px}
.row .sub{font-size:13px; color:var(--ink-3)}
.switch{position:relative; width:44px; height:26px; flex:0 0 auto}
.switch input{position:absolute; opacity:0; width:100%; height:100%; margin:0; cursor:pointer}
.switch span{position:absolute; inset:0; background:var(--line); border-radius:999px; transition:.15s}
.switch span::after{content:""; position:absolute; top:3px; inset-inline-start:3px; width:20px; height:20px;
  border-radius:50%; background:#fff; transition:.15s; box-shadow:var(--shadow-1)}
.switch input:checked + span{background:var(--accent)}
.switch input:checked + span::after{transform:translateX(18px)}
[dir="rtl"] .switch input:checked + span::after{transform:translateX(-18px)}

.bar{height:8px; border-radius:999px; background:var(--surface-3); overflow:hidden; margin:8px 0 4px}
.bar > i{display:block; height:100%; background:linear-gradient(90deg,var(--accent),var(--accent-2))}
.big{font-size:30px; font-weight:660; letter-spacing:-.02em}
.pill{display:inline-block; padding:3px 10px; border-radius:999px; background:var(--accent-soft);
  color:var(--accent-2); font-size:12.5px; font-weight:600}

.auth-wrap{display:grid; place-items:center; min-height:100dvh; padding:24px}
.auth-card{width:100%; max-width:420px; background:var(--surface); border:1px solid var(--line);
  border-radius:var(--radius-lg); padding:28px; box-shadow:var(--shadow-2)}
.auth-card h2{margin:0 0 4px; font-size:22px; letter-spacing:-.02em}
.auth-card .sub{color:var(--ink-2); font-size:14.5px; margin:0 0 20px}
.tabs{display:flex; gap:4px; background:var(--surface-2); padding:4px; border-radius:12px; margin-bottom:20px}
.tabs button{flex:1; padding:9px; border:0; background:none; border-radius:9px; cursor:pointer; font-size:14.5px; color:var(--ink-2)}
.tabs button[aria-selected="true"]{background:var(--surface); color:var(--ink); font-weight:600; box-shadow:var(--shadow-1)}

.toast{
  position:fixed; inset-inline:0; bottom:24px; margin:auto; width:max-content; max-width:90vw;
  background:var(--ink); color:var(--bg); padding:11px 18px; border-radius:999px;
  font-size:14px; box-shadow:var(--shadow-2); opacity:0; transform:translateY(8px);
  transition:.2s; pointer-events:none; z-index:50;
}
.toast.show{opacity:1; transform:none}

/* ---------- мобильный ---------- */
.mobile-only{display:none}
@media(max-width:820px){
  .shell{grid-template-columns:1fr}
  aside{
    position:fixed; inset-block:0; inset-inline-start:0; width:264px; z-index:40;
    transform:translateX(-100%); transition:.2s; box-shadow:var(--shadow-2);
  }
  [dir="rtl"] aside{transform:translateX(100%)}
  aside.open{transform:none}
  .mobile-only{display:grid}
  .menu-btn{width:38px;height:38px;border-radius:10px;border:1px solid var(--line);
    background:var(--surface); cursor:pointer; place-items:center}
  .topbar{padding:10px 14px}
  .msgs{padding:14px}
  .msg{max-width:92%}
  .pad{padding:16px 14px 32px}
}
.scrim{position:fixed; inset:0; background:rgba(0,0,0,.4); z-index:35}
@media(prefers-reduced-motion:reduce){*{transition:none!important; animation:none!important}}

/* ---------- регистрация: подсказки и чекбокс ---------- */
.field .hint{display:block; margin-top:6px; font-size:12.5px; color:var(--ink-3)}
.check{display:flex; align-items:center; gap:10px; font-size:14px; cursor:pointer;
  padding:11px 13px; border:1px solid var(--line); border-radius:var(--radius-sm,10px)}
.check input{width:18px; height:18px; accent-color:var(--accent); margin:0; flex:none}
.check:hover{border-color:var(--ink-3)}
