*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}

:root,[data-theme="dark"]{
  --bg:#212121;
  --bg-sidebar:#171717;
  --bg-input:#2f2f2f;
  --bg-hover:#2a2a2a;
  --bg-user-msg:#2f2f2f;
  --bg-btn-primary:#ffffff;
  --bg-btn-primary-hover:#e5e5e5;
  --border:#383838;
  --border-input:transparent;
  --text:#ececec;
  --text-muted:#8e8ea0;
  --text-faint:#565869;
  --text-on-primary:#000000;
  --accent:#10a37f;
  --accent-dim:#0d8f6e;
  --accent-glow:rgba(16,163,127,0.15);
  --danger:#ef4444;
  --warn:#f59e0b;
  --radius:16px;
  --radius-sm:8px;
  --radius-msg:18px;
  --font-ui:'Inter',sans-serif;
  --font-body:'Inter',sans-serif;
  --sidebar-w:260px;
  --safe-bottom:env(safe-area-inset-bottom,0px);
  --safe-top:env(safe-area-inset-top,0px);
  --shadow-dropdown:0 4px 24px rgba(0,0,0,0.6);
  --icon-filter:none;
}

[data-theme="light"]{
  --bg:#ffffff;
  --bg-sidebar:#f9f9f9;
  --bg-input:#f4f4f4;
  --bg-hover:#ebebeb;
  --bg-user-msg:#f4f4f4;
  --bg-btn-primary:#1a1a1a;
  --bg-btn-primary-hover:#333333;
  --border:#e5e5e5;
  --border-input:#e5e5e5;
  --text:#0d0d0d;
  --text-muted:#6e6e80;
  --text-faint:#adadb8;
  --text-on-primary:#ffffff;
  --accent:#10a37f;
  --accent-dim:#0d8f6e;
  --accent-glow:rgba(16,163,127,0.1);
  --danger:#ef4444;
  --warn:#f59e0b;
  --shadow-dropdown:0 4px 24px rgba(0,0,0,0.12);
  --icon-filter:none;
}

html,body{height:100%;overflow:hidden;background:var(--bg);color:var(--text);transition:background .2s,color .2s}
body{font-family:var(--font-body);font-size:15px;line-height:1.6}
#app{display:flex;height:100vh;height:100dvh}

/* ═══ TG INTERNAL BROWSER GATE ═══ */
#tg-browser-gate{
  position:fixed;inset:0;z-index:9999;
  background:var(--bg);
  display:flex;align-items:center;justify-content:center;
  padding:20px;
  overflow-y:auto;
}
.tgbg-card{
  width:100%;max-width:380px;
  display:flex;flex-direction:column;align-items:center;
  text-align:center;gap:0;
  padding:32px 24px 28px;
  background:var(--bg-input);
  border-radius:24px;
  border:1px solid var(--border);
}
.tgbg-logo{
  width:96px;height:96px;border-radius:24px;overflow:hidden;
  background:var(--bg-hover);
  display:flex;align-items:center;justify-content:center;
  margin-bottom:20px;
  box-shadow:0 4px 20px rgba(0,0,0,0.3);
}
.tgbg-logo img{width:96px;height:96px;object-fit:cover;border-radius:24px}
.tgbg-title{
  font-size:22px;font-weight:700;color:var(--text);
  margin-bottom:10px;letter-spacing:-.3px;
}
.tgbg-sub{
  font-size:14px;color:var(--text-muted);line-height:1.55;
  margin-bottom:24px;
}
.tgbg-steps{
  width:100%;display:flex;flex-direction:column;gap:12px;
  margin-bottom:28px;text-align:left;
}
.tgbg-step{
  display:flex;align-items:flex-start;gap:12px;
  background:var(--bg-hover);
  border-radius:12px;padding:12px 14px;
  border:1px solid var(--border);
}
.tgbg-step-num{
  min-width:26px;height:26px;border-radius:50%;
  background:var(--accent);color:#fff;
  display:flex;align-items:center;justify-content:center;
  font-size:13px;font-weight:700;flex-shrink:0;margin-top:1px;
}
.tgbg-step-text{
  font-size:14px;color:var(--text);line-height:1.5;
}
.tgbg-step-text strong{color:var(--text);font-weight:600}
.tgbg-btn{
  width:100%;padding:14px 20px;border-radius:12px;
  background:var(--accent);color:#fff;
  border:none;cursor:pointer;
  font-size:15px;font-weight:600;font-family:var(--font-ui);
  display:flex;align-items:center;justify-content:center;gap:8px;
  transition:background .15s,transform .1s;
  margin-bottom:12px;
}
.tgbg-btn:hover{background:var(--accent-dim)}
.tgbg-btn:active{transform:scale(0.98)}
.tgbg-skip{
  background:none;border:none;cursor:pointer;
  color:var(--text-muted);font-size:13px;font-family:var(--font-ui);
  padding:4px;text-decoration:underline;text-underline-offset:3px;
  transition:color .15s;
}
.tgbg-skip:hover{color:var(--text)}

/* ═══ SIDEBAR ═══ */
#sidebar{
  width:var(--sidebar-w);
  background:var(--bg-sidebar);
  display:flex;flex-direction:column;flex-shrink:0;
  transition:transform .25s,background .2s;z-index:10;
  overflow:hidden;
}
#sidebar-top{padding:8px 8px 4px;padding-top:calc(8px + var(--safe-top));display:flex;flex-direction:column;gap:1px}

#new-chat-btn{
  display:flex;align-items:center;justify-content:space-between;
  padding:9px 12px;border-radius:10px;
  background:transparent;border:none;
  color:var(--text);font-family:var(--font-ui);
  font-size:14px;font-weight:500;cursor:pointer;
  transition:background .12s;width:100%;text-align:left;
}
#new-chat-btn:hover{background:var(--bg-hover)}
#new-chat-btn .nc-left{display:flex;align-items:center;gap:10px}

.sb-logo-row{
  display:flex;align-items:center;justify-content:space-between;
  padding:10px 12px;margin-bottom:4px;
}
.sb-logo{
  display:flex;align-items:center;gap:9px;
  font-size:15px;font-weight:600;color:var(--text);text-decoration:none;
}
.sb-logo-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sb-logo-icon img{width:28px;height:28px;object-fit:cover;border-radius:6px}


.sb-section-label{
  font-size:11px;font-weight:600;color:var(--text-faint);
  padding:10px 14px 4px;letter-spacing:.04em;
}
#sidebar-info{
  flex-grow:1;overflow-y:auto;padding:0 8px;
  scrollbar-width:thin;scrollbar-color:var(--border) transparent;
}
.sb-conv-item{
  display:flex;align-items:center;gap:8px;
  padding:8px 10px;border-radius:8px;cursor:pointer;
  font-size:14px;color:var(--text-muted);
  transition:background .12s;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}
.sb-conv-item:hover{background:var(--bg-hover);color:var(--text)}
.sb-conv-item.active{background:var(--bg-hover);color:var(--text)}

.limit-bar-wrap{padding:10px 12px 6px}
.limit-label{
  font-size:12px;color:var(--text-muted);
  margin-bottom:6px;display:flex;justify-content:space-between;align-items:center;
}
.limit-label span:first-child{font-weight:500}
.limit-count{font-size:12px;font-weight:600;color:var(--text)}
.limit-bar{height:3px;background:var(--border);border-radius:99px;overflow:hidden}
.limit-bar-fill{height:100%;background:var(--accent);border-radius:99px;transition:width .4s}
.limit-bar-fill.warn{background:var(--warn)}.limit-bar-fill.danger{background:var(--danger)}

#sidebar-footer{padding:8px;border-top:1px solid var(--border);margin-top:4px}
.user-card{
  display:flex;align-items:center;gap:10px;
  padding:9px 10px;border-radius:10px;
  cursor:pointer;transition:background .12s;
}
.user-card:hover{background:var(--bg-hover)}
.user-avatar{
  width:32px;height:32px;border-radius:50%;
  background:linear-gradient(135deg,var(--accent),#7c3aed);
  display:flex;align-items:center;justify-content:center;
  font-size:13px;font-weight:700;flex-shrink:0;overflow:hidden;color:#fff;
}
.user-avatar img{width:100%;height:100%;object-fit:cover}
.user-info{flex:1;min-width:0}
.user-name{font-size:13px;font-weight:500;line-height:1.3;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.user-plan{font-size:11px;color:var(--accent);font-weight:500}

/* ═══ MAIN ═══ */
#main{flex:1;display:flex;flex-direction:column;overflow:hidden;position:relative;background:var(--bg);transition:background .2s}

/* ═══ HEADER ═══ */
#header{
  display:flex;align-items:center;justify-content:space-between;
  padding:10px 16px;padding-top:calc(10px + var(--safe-top));flex-shrink:0;z-index:5;
  background:var(--bg);transition:background .2s;
  border-bottom:1px solid transparent;
}
.header-left{display:flex;align-items:center;gap:8px;min-width:0;flex:1}
.header-right{display:flex;align-items:center;gap:6px;flex-shrink:0}

#menu-toggle{
  display:none;background:none;border:none;color:var(--text-muted);
  cursor:pointer;padding:6px;border-radius:8px;transition:background .12s;flex-shrink:0;
}
#menu-toggle:hover{background:var(--bg-hover)}

#model-selector{
  display:flex;align-items:center;gap:6px;
  padding:6px 10px;border-radius:8px;
  background:transparent;border:none;
  color:var(--text);font-family:var(--font-ui);
  font-size:15px;font-weight:600;cursor:pointer;
  transition:background .12s;max-width:100%;overflow:hidden;
}
#model-selector:hover{background:var(--bg-hover)}
#model-selector .chevron{color:var(--text-muted);transition:transform .2s;flex-shrink:0}
#model-selector.open .chevron{transform:rotate(180deg)}
#model-label{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}

.icon-btn{
  width:36px;height:36px;background:transparent;border:none;
  border-radius:8px;color:var(--text-muted);
  display:flex;align-items:center;justify-content:center;
  cursor:pointer;transition:all .12s;flex-shrink:0;
}
.icon-btn:hover{background:var(--bg-hover);color:var(--text)}

/* ЖМИ button */
.zhmi-btn{
  background:#ef4444;color:#fff;border:none;
  border-radius:20px;padding:6px 14px;
  font-size:12px;font-weight:700;letter-spacing:.05em;
  cursor:pointer;flex-shrink:0;font-family:var(--font-ui);
  transition:all .15s;box-shadow:0 2px 8px rgba(239,68,68,.4);
}
.zhmi-btn:hover{background:#dc2626;box-shadow:0 3px 12px rgba(239,68,68,.55);transform:scale(1.04)}
.zhmi-btn:active{transform:scale(.95)}

/* ═══ DROPDOWN ═══ */
.dropdown{position:relative}
.dropdown-menu{
  position:absolute;top:calc(100% + 8px);
  background:var(--bg-sidebar);border:1px solid var(--border);
  border-radius:12px;padding:6px;
  min-width:220px;z-index:200;
  box-shadow:var(--shadow-dropdown);display:none;
  animation:dropIn .15s ease;
  max-height:320px;overflow-y:auto;
  overscroll-behavior:contain;
}
@keyframes dropIn{from{opacity:0;transform:translateY(-6px)}to{opacity:1;transform:none}}
.dropdown-menu.open{display:block}
.dropdown-menu.left{left:0;right:auto}
.dropdown-menu.right{right:0;left:auto}

.dd-label{font-size:11px;font-weight:600;color:var(--text-faint);padding:6px 10px 4px;letter-spacing:.04em;}
.dd-divider{height:1px;background:var(--border);margin:4px 0}
.dd-item{
  display:flex;align-items:center;gap:9px;
  padding:9px 10px;border-radius:8px;cursor:pointer;
  font-size:14px;color:var(--text);transition:background .1s;
}
.dd-item:hover{background:var(--bg-hover)}
.dd-item.active{font-weight:500}
.dd-item .check{width:16px;height:16px;color:var(--accent);flex-shrink:0;opacity:0}
.dd-item.active .check{opacity:1}
.dd-item .dd-icon{width:16px;height:16px;color:var(--text-muted);flex-shrink:0}
.dd-item-label{flex:1}
.dd-item-sub{font-size:11px;color:var(--text-faint);white-space:nowrap}
/* Stacked label+desc inside a dropdown item (model picker) */
.dd-item-block{display:flex;flex-direction:column;gap:1px;flex:1;min-width:0}
.dd-item-block .dd-item-label{font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.dd-item-block .dd-item-sub{font-size:11px}
.dd-item-badge{font-size:11px;color:var(--text-faint);background:var(--bg-input);padding:1px 7px;border-radius:99px}

/* ═══ MESSAGES ═══ */
#messages-wrap{flex:1;overflow-y:auto;scroll-behavior:smooth}
#messages-wrap::-webkit-scrollbar{width:4px}
#messages-wrap::-webkit-scrollbar-thumb{background:var(--border);border-radius:99px}
#messages{
  max-width:768px;margin:0 auto;
  padding:24px 16px 24px;
  display:flex;flex-direction:column;gap:0;
}

/* ═══ WELCOME ═══ */
#welcome{
  display:flex;flex-direction:column;align-items:center;
  justify-content:flex-start;
  text-align:center;padding:24px 20px 20px;
}
#welcome.hidden{display:none}
.welcome-logo {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}
.welcome-logo img{width:72px;height:72px;object-fit:cover;border-radius:20px}

.welcome-title{font-size:26px;font-weight:600;color:var(--text);margin-bottom:8px;letter-spacing:-.3px}
.welcome-sub{font-size:15px;color:var(--text-muted);max-width:400px;line-height:1.6}
.bot-link{
  display:inline-block;margin-top:6px;
  color:var(--accent);font-weight:500;font-size:14px;
  text-decoration:none;
  transition:opacity .15s;
}
.bot-link:hover{opacity:.75;text-decoration:underline}
.starter-chips {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 28px;
  padding: 4px 8px;
  width: 100%;
  max-width: 360px;
}
.starter-chips::-webkit-scrollbar{display:none}
.chip {
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  cursor: pointer;
  transition: all .15s;
  text-align: center;
}
.chip-full { width: 70%; }
.chip-full .chip-t { font-size: 18px; }
.chip-full .chip-s { font-size: 15px; }
.chip:hover{border-color:var(--text-muted);background:var(--bg-hover)}
.chip-t{font-size:14px;font-weight:600;color:var(--text);display:block;line-height:1.35}
.chip-s{font-size:13px;color:var(--text-muted);display:block;line-height:1.35;margin-top:2px}

/* ═══ MESSAGE ROWS ═══ */
.msg-row{display:flex;gap:0;padding:0;animation:fadeUp .2s ease}
@keyframes fadeUp{from{opacity:0;transform:translateY(10px)}to{opacity:1;transform:none}}

/* User messages */
.msg-row.msg-user{justify-content:flex-end;margin:8px 0}
.msg-row.msg-user .msg-bubble{
  background:var(--bg-user-msg);
  border-radius:var(--radius-msg) var(--radius-msg) 4px var(--radius-msg);
  padding:12px 16px;
  max-width:72%;word-break:break-word;
  font-size:15px;color:var(--text);line-height:1.65;
}
.msg-row.msg-user .msg-img{
  width:120px;height:80px;border-radius:10px;
  object-fit:cover;margin-bottom:8px;
  border:1px solid var(--border);display:block;
}
/* Time stamp on user messages */
.msg-time{
  font-size:11px;color:var(--text-faint);
  margin-top:4px;text-align:right;padding-right:2px;
}
.msg-row.msg-user .msg-time{text-align:right}

/* Voice message bubble */
.voice-bubble{
  display:flex;align-items:center;gap:10px;
  padding:10px 14px!important;min-width:160px;
}
.voice-bubble svg{flex-shrink:0;color:var(--text-muted)}
.voice-waveform{
  display:flex;align-items:center;gap:2px;height:24px;flex:1;
}
.voice-waveform span{
  width:3px;border-radius:99px;
  background:var(--accent);opacity:.7;
  transform-origin:center;
  animation:voiceIdle 1.8s ease-in-out infinite;
}
.voice-waveform span:nth-child(1){height:8px;animation-delay:0s}
.voice-waveform span:nth-child(2){height:14px;animation-delay:.12s}
.voice-waveform span:nth-child(3){height:20px;animation-delay:.24s}
.voice-waveform span:nth-child(4){height:16px;animation-delay:.36s}
.voice-waveform span:nth-child(5){height:10px;animation-delay:.48s}
.voice-waveform span:nth-child(6){height:14px;animation-delay:.6s}
.voice-waveform span:nth-child(7){height:8px;animation-delay:.72s}
@keyframes voiceIdle{0%,100%{opacity:.4;transform:scaleY(.6)}50%{opacity:.8;transform:scaleY(1)}}
.voice-duration{font-size:13px;color:var(--text-muted);font-variant-numeric:tabular-nums;white-space:nowrap}

/* Assistant messages */
.msg-row.msg-assistant{flex-direction:column;margin:4px 0 16px}
.msg-row.msg-assistant .msg-header{display:flex;align-items:center;gap:10px;margin-bottom:6px}
.msg-row.msg-assistant .msg-ai-avatar{
  width:28px;height:28px;border-radius:50%;
  background:var(--accent);
  display:flex;align-items:center;justify-content:center;
  flex-shrink:0;
}
.msg-row.msg-assistant .msg-ai-avatar svg{color:#fff}
.msg-ai-meta{display:flex;flex-direction:column;gap:1px}
.msg-row.msg-assistant .msg-ai-name{font-size:14px;font-weight:600;color:var(--text)}
.msg-ai-model{display:none}
.msg-ai-time{font-size:11px;color:var(--text-faint);margin-left:auto}
.msg-row.msg-assistant .msg-content{
  color:var(--text);
  word-break:break-word;line-height:1.75;
  font-size:15px;padding-left:38px;
}
.streaming-cursor::after{content:'▋';animation:blink .7s step-end infinite;color:var(--text-muted)}
@keyframes blink{50%{opacity:0}}

/* ── Markdown inside AI messages ── */
.msg-row.msg-assistant .msg-content p{margin:0 0 .6em}
.msg-row.msg-assistant .msg-content p:last-child{margin-bottom:0}
.msg-row.msg-assistant .msg-content h1,.msg-row.msg-assistant .msg-content h2,
.msg-row.msg-assistant .msg-content h3,.msg-row.msg-assistant .msg-content h4{
  margin:.8em 0 .3em;font-weight:700;line-height:1.3}
.msg-row.msg-assistant .msg-content h1{font-size:1.25em}
.msg-row.msg-assistant .msg-content h2{font-size:1.1em}
.msg-row.msg-assistant .msg-content h3{font-size:1em}
.msg-row.msg-assistant .msg-content ul,.msg-row.msg-assistant .msg-content ol{
  padding-left:1.4em;margin:.4em 0 .6em}
.msg-row.msg-assistant .msg-content li{margin:.2em 0}
.msg-row.msg-assistant .msg-content code{
  font-family:'Menlo','Monaco','Courier New',monospace;font-size:.85em;
  background:var(--bg-input);border-radius:4px;padding:.1em .35em}
.msg-row.msg-assistant .msg-content pre{
  background:var(--bg-input);border-radius:10px;
  padding:12px 14px;margin:.6em 0;overflow-x:auto}
.msg-row.msg-assistant .msg-content pre code{
  background:none;padding:0;font-size:.82em;line-height:1.55}
.msg-row.msg-assistant .msg-content blockquote{
  border-left:3px solid var(--border);
  margin:.4em 0;padding:.2em .8em;color:var(--text-muted)}
.msg-row.msg-assistant .msg-content a{color:var(--accent);text-decoration:underline}
.msg-row.msg-assistant .msg-content hr{border:none;border-top:1px solid var(--border);margin:.6em 0}
.msg-row.msg-assistant .msg-content table{border-collapse:collapse;width:100%;margin:.5em 0;font-size:.9em}
.msg-row.msg-assistant .msg-content th,.msg-row.msg-assistant .msg-content td{
  border:1px solid var(--border);padding:.35em .65em;text-align:left}
.msg-row.msg-assistant .msg-content th{background:var(--bg-input);font-weight:600}
/* Loading state for speak button */
.msg-act.loading{opacity:.5;pointer-events:none;animation:blink 1s step-end infinite}

/* ═══ INPUT AREA — УВЕЛИЧЕННЫЙ И ЦЕНТРИРОВАННЫЙ ═══ */
#input-area{
  flex-shrink:0;
  padding: 20px 16px calc(24px + var(--safe-bottom));
  background:var(--bg);
  transition:background .2s;
  border-top:1px solid var(--border);
}
#input-outer{
  max-width: 860px;
  margin: 0 auto;
}

#tariff-banner{
  display:none;align-items:center;justify-content:space-between;gap:10px;
  background:var(--bg-input);border:1px solid var(--border);
  border-radius:12px;padding:12px 16px;
  margin-bottom:12px;font-size:14px;color:var(--text-muted);
}
#tariff-banner.show{display:flex}
.t-upgrade{color:var(--accent);font-weight:600;cursor:pointer;font-size:13px;white-space:nowrap}

#input-pill{
  display:flex;
  align-items:center;
  gap: 12px;
  background:var(--bg-input);
  border-radius: 48px;
  padding: 10px 18px;
  border:1.5px solid var(--text-muted);
  box-shadow:0 0 0 3px rgba(255,255,255,.04),0 2px 12px rgba(0,0,0,.18);
  transition:box-shadow .18s,border-color .18s;
}
#input-pill:focus-within{
  border-color:var(--text);
  box-shadow:0 0 0 3px rgba(255,255,255,.08),0 4px 16px rgba(0,0,0,.22);
}
[data-theme="light"] #input-pill{border-color:#aaaaaa;box-shadow:0 0 0 3px rgba(0,0,0,.04),0 2px 10px rgba(0,0,0,.1)}
[data-theme="light"] #input-pill:focus-within{border-color:#1a1a1a;box-shadow:0 0 0 3px rgba(0,0,0,.07)}

#pill-attach{
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border:none;
  background:transparent;
  color:var(--text-muted);
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  flex-shrink:0;
  transition:all .12s;
}
#pill-attach:hover{background:var(--bg-hover);color:var(--text)}
#file-attach{display:none}

#text-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-body);
  /* Адаптивный размер: на узких экранах (≤320px) — 15px, на десктопе — 18px,
     между ними плавно масштабируется по ширине окна. Иначе кириллический
     плейсхолдер не помещается в textarea и переносится на 2-ю строку. */
  font-size: clamp(15px, 4.2vw, 18px);
  resize: none;
  overflow-y: hidden;
  max-height: 320px;
  min-height: 56px;

  /* 🔧 Точное центрирование */
  padding-top: 16px;
  padding-bottom: 16px;
  height: 25px;
  line-height: 25px;
  transition: color .2s;
}

#text-input::placeholder {
  color: var(--text-faint);
  /* Плейсхолдер чуть меньше вводимого текста и тоже адаптивный. */
  font-size: clamp(13px, 3.6vw, 16px);
  display: block; /* Фикс для Safari */
}

#send-btn{
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background:var(--bg-btn-primary);
  border:none;
  color:var(--text-on-primary);
  display:none;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  flex-shrink:0;
  transition:all .15s;
}
#send-btn.visible{display:flex}
#send-btn:hover{background:var(--bg-btn-primary-hover)}
#send-btn:disabled{opacity:.3;cursor:not-allowed}

/* Mic button — click to toggle */
#pill-mic{
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border:none;
  background:transparent;
  color:var(--text-muted);
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  flex-shrink:0;
  transition:all .2s cubic-bezier(.4,0,.2,1);
}
#pill-mic:hover{color:var(--text);background:var(--bg-hover)}
#pill-mic.recording{
  background:rgba(239,68,68,.18);color:var(--danger);
  transform:scale(1.35);
  animation:siriPillMic 1.2s ease-in-out infinite;
}
#pill-mic.recording svg{
  transform:scale(1.25);
  transition:transform .2s;
}
@keyframes siriPillMic{
  0%   { box-shadow:0 0 0 0 rgba(239,68,68,.6),0 0 0 0 rgba(239,68,68,.3); }
  60%  { box-shadow:0 0 0 10px rgba(239,68,68,0),0 0 0 22px rgba(239,68,68,0); }
  100% { box-shadow:0 0 0 0 rgba(239,68,68,0),0 0 0 0 rgba(239,68,68,0); }
}

/* Orb → realtime mode */
#pill-orb{
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background:var(--text);
  color:var(--bg);
  border:none;
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  flex-shrink:0;
  transition:opacity .12s,transform .15s;
  box-shadow:0 2px 8px rgba(0,0,0,.2);
}
#pill-orb:hover{opacity:.85;transform:scale(1.05)}
#pill-orb:active{transform:scale(.93)}
[data-theme="light"] #pill-orb{background:#1a1a1a;color:#fff}

/* ── Variant navigation ── */
.msg-variants{
  display:none;align-items:center;gap:4px;
  margin-top:4px;padding-left:38px;
}
.variant-prev,.variant-next{
  width:24px;height:24px;border-radius:6px;
  border:none;background:transparent;
  color:var(--text-muted);cursor:pointer;
  display:flex;align-items:center;justify-content:center;
  transition:background .12s,color .12s;
}
.variant-prev:hover,.variant-next:hover{background:var(--bg-hover);color:var(--text)}
.variant-prev:disabled,.variant-next:disabled{opacity:.3;cursor:default}
.variant-counter{
  font-size:12px;color:var(--text-faint);
  min-width:30px;text-align:center;font-variant-numeric:tabular-nums;
}

/* ── Message actions ── */
.msg-actions{
  display:flex;align-items:center;gap:2px;
  margin-top:6px;padding-left:38px;
  opacity:0;transition:opacity .2s;
}
.msg-row.msg-assistant:hover .msg-actions,
.msg-actions:focus-within{opacity:1}
@media(hover:none){.msg-actions{opacity:.7}}
.msg-act{
  width:30px;height:30px;border-radius:7px;
  border:none;background:transparent;
  color:var(--text-faint);cursor:pointer;
  display:flex;align-items:center;justify-content:center;
  transition:all .12s;
}
.msg-act:hover{background:var(--bg-hover);color:var(--text)}
.msg-act.active{color:var(--accent)}
.msg-act.speaking{color:var(--accent);animation:speakPulse .8s ease infinite}
@keyframes speakPulse{0%,100%{opacity:1}50%{opacity:.4}}

/* ═══ VOICE MODAL (REALTIME) — УВЕЛИЧЕННЫЕ КНОПКИ ═══ */
#voice-modal{
  position:fixed;inset:0;z-index:200;
  background:var(--bg);
  display:flex;flex-direction:column;align-items:center;
  opacity:0;pointer-events:none;
  transition:opacity .3s ease;
  /* overflow:visible so the topbar dropdown can escape the flex container */
  overflow:visible;
}
#voice-modal.active{opacity:1;pointer-events:all}

#vm-topbar{
  width:100%;display:flex;align-items:center;justify-content:space-between;
  padding:calc(10px + var(--safe-top)) 14px 6px;
  gap:6px;flex-shrink:0;
  /* ensure topbar sits above dropdown */
  position:relative;z-index:10;
}

/* RT model+voice dropdown — mirrors chat header selector */
#rt-dd{position:relative}
#rt-selector{
  display:flex;align-items:center;gap:6px;
  padding:6px 10px 6px 12px;
  border-radius:10px;
  background:rgba(255,255,255,.07);
  border:1px solid rgba(255,255,255,.1);
  color:var(--text);font-size:13px;font-weight:500;
  cursor:pointer;font-family:var(--font-ui);
  transition:background .15s;white-space:nowrap;
}
#rt-selector:hover{background:rgba(255,255,255,.12)}
[data-theme="light"] #rt-selector{background:var(--bg-input);border-color:var(--border)}
#rt-selector .chevron{transition:transform .2s;flex-shrink:0;opacity:.7}
#rt-selector.open .chevron{transform:rotate(180deg)}
#rt-dd-menu{
  /* float over the modal content */
  position:absolute;top:calc(100% + 6px);left:0;
}
.vm-top-btn{
  width:36px;height:36px;border-radius:50%;
  background:none;border:none;color:var(--text-muted);
  display:flex;align-items:center;justify-content:center;
  cursor:pointer;transition:background .12s;flex-shrink:0;
}
.vm-top-btn:hover{background:var(--bg-hover)}

/* ── RT Volume popup ── */
#vm-vol-popup{
  display:none;flex-direction:column;align-items:center;gap:6px;
  position:absolute;top:calc(100% + 8px);right:0;
  background:var(--bg-card);
  border:1px solid var(--border);
  border-radius:14px;
  padding:14px 12px 10px;
  z-index:30;
  box-shadow:0 4px 24px rgba(0,0,0,.35);
  min-width:44px;
}
#vm-vol-popup.open{display:flex}
.vm-vol-slider{
  -webkit-appearance:slider-vertical;
  writing-mode:vertical-lr;
  direction:rtl;
  width:22px;height:110px;
  cursor:pointer;
  accent-color:var(--accent);
}
#vm-vol-pct{
  font-size:11px;font-weight:600;
  color:var(--text-muted);
  white-space:nowrap;
}

/* Camera card — shown first, fills remaining flex space */
#vm-cam-card{
  width:calc(100% - 16px);max-width:580px;
  border-radius:20px;overflow:hidden;
  background:#111;position:relative;
  display:none;margin:0 auto;
  box-shadow:0 12px 40px rgba(0,0,0,.5);
  /* flex-shrink позволяет карточке ужаться, min-height:0 — обязательно для flex */
  flex-shrink:1;
  min-height:0;
}
#vm-cam-card.show{display:flex;flex-direction:column}
#vm-cam-card video{
  width:100%;display:block;object-fit:cover;
  min-height:0;flex:1;
  transform:translateZ(0);
}
/* When camera active — карточка растягивается на всё свободное пространство */
#voice-modal.cam-active #vm-cam-card{
  flex:1;
  min-height:0;
}
/* Нет жёсткого max-height — высота определяется flex-контейнером */
#voice-modal.cam-active #vm-cam-card video{
  max-height:100%;
}
#vm-cam-card video.mirrored{transform:translateZ(0) scaleX(-1)}
.vm-cam-ovr{
  position:absolute;bottom:12px;
  width:36px;height:36px;border-radius:50%;
  background:rgba(0,0,0,.52);backdrop-filter:blur(10px);
  border:none;color:rgba(255,255,255,.85);
  display:flex;align-items:center;justify-content:center;
  cursor:pointer;
}
#vm-flash-btn{left:12px}
#vm-flip-btn{right:12px}

/* Waveform + status */
#vm-center{
  flex:1;display:flex;flex-direction:column;
  align-items:center;justify-content:center;gap:12px;
  width:100%;padding:12px 24px 8px;min-height:0;
}
/* When camera shown — center is compact */
#voice-modal.cam-active #vm-center{
  flex:0 0 auto;gap:8px;padding:10px 24px 4px;
}

/* ── Waveform equalizer ── */
#vm-wave{
  display:flex;align-items:center;justify-content:center;gap:4px;
  height:44px;
}
#vm-wave span{
  width:4px;border-radius:99px;
  background:var(--text-muted);
  transform-origin:center;
  transition:background .3s;
  animation:vmWaveIdle 2.2s ease-in-out infinite;
}
#vm-wave span:nth-child(1){height:10px;animation-delay:0s}
#vm-wave span:nth-child(2){height:18px;animation-delay:.18s}
#vm-wave span:nth-child(3){height:28px;animation-delay:.36s}
#vm-wave span:nth-child(4){height:36px;animation-delay:.54s}
#vm-wave span:nth-child(5){height:28px;animation-delay:.36s}
#vm-wave span:nth-child(6){height:18px;animation-delay:.18s}
#vm-wave span:nth-child(7){height:10px;animation-delay:0s}

@keyframes vmWaveIdle{
  0%,100%{transform:scaleY(1);opacity:.3}
  50%{transform:scaleY(.4);opacity:.15}
}
#vm-wave.listening span{background:var(--accent)}
#vm-wave.speaking span{background:var(--accent)}


#vm-status{
  font-size:14px;font-weight:500;color:var(--text-muted);
  transition:color .25s,opacity .25s;letter-spacing:-.1px;
  flex-shrink:0;text-align:center;max-width:280px;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}
#vm-status.listening{color:var(--accent)}
#vm-status.speaking{color:var(--text)}
#vm-status.thinking{color:var(--warn)}


/* Bottom controls — всегда видны, увеличены */
#vm-controls{
  display:flex;align-items:center;justify-content:center;
  gap: 20px;
  width:100%;
  flex-shrink:0;
  padding:8px 16px calc(20px + var(--safe-bottom));
}
.vm-ctrl{
  width: 68px;   /* было 58px */
  height: 68px;  /* было 58px */
  border-radius:50%;
  background:var(--bg-input);
  border:none;
  color:var(--text);
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  transition:all .18s cubic-bezier(.4,0,.2,1);
  -webkit-tap-highlight-color:transparent;
  flex-shrink:0;
}
.vm-ctrl:active{transform:scale(.90)}
.vm-ctrl:hover{background:var(--bg-hover)}
[data-theme="light"] .vm-ctrl{background:#eeeeee}
.vm-ctrl-mic{
  width: 84px;   /* было 72px */
  height: 84px;  /* было 72px */
  background:var(--text)!important;
  color:var(--bg)!important;
  box-shadow:0 4px 16px rgba(0,0,0,.25);
  touch-action:none;
  user-select:none;
  -webkit-user-select:none;
  transition:transform .18s cubic-bezier(.34,1.56,.64,1), background .2s, color .2s, box-shadow .2s;
}
.vm-ctrl-mic:hover{opacity:.9}
[data-theme="light"] .vm-ctrl-mic{background:#1a1a1a!important;color:#fff!important}
#vm-cam-btn.cam-on{background:var(--text);color:var(--bg)}
[data-theme="light"] #vm-cam-btn.cam-on{background:#1a1a1a;color:#fff}

/* ─── Siri: зажат микрофон ─── */
#vm-mic-btn.listening{
  background:linear-gradient(145deg,#10a37f 0%,#6d28d9 60%,#10a37f 100%)!important;
  background-size:200% 200%!important;
  color:#fff!important;
  transform:scale(1.28)!important;
  box-shadow:0 0 0 0 rgba(16,163,127,.0)!important;
  animation:siriMicListen 1.2s ease-in-out infinite, siriGradient 3s ease infinite;
}
#vm-mic-btn.listening #vm-mic-icon{
  width:30px;height:30px;
  filter:drop-shadow(0 0 6px rgba(255,255,255,.6));
  transition:width .18s,height .18s,filter .18s;
}
@keyframes siriMicListen{
  0%  { box-shadow:0 8px 28px rgba(16,163,127,.45),
                   0 0 0 0   rgba(16,163,127,.7),
                   0 0 0 0   rgba(109,40,217,.5),
                   0 0 0 0   rgba(16,163,127,.25); }
  40% { box-shadow:0 8px 28px rgba(16,163,127,.45),
                   0 0 0 18px rgba(16,163,127,.0),
                   0 0 0 36px rgba(109,40,217,.0),
                   0 0 0 52px rgba(16,163,127,.0); }
  100%{ box-shadow:0 8px 28px rgba(16,163,127,.45),
                   0 0 0 0   rgba(16,163,127,.0),
                   0 0 0 0   rgba(109,40,217,.0),
                   0 0 0 0   rgba(16,163,127,.0); }
}
@keyframes siriGradient{
  0%  { background-position:0% 50%   }
  50% { background-position:100% 50% }
  100%{ background-position:0% 50%   }
}

/* ─── Красный: AI отвечает / обработка ─── */
#vm-mic-btn.rec{
  background:var(--danger)!important;color:#fff!important;
  transform:scale(1.18)!important;
  animation:siriMicRec 0.85s cubic-bezier(.4,0,.6,1) infinite;
}
#vm-mic-btn.rec #vm-mic-icon{
  width:28px;height:28px;
  transition:width .18s,height .18s;
}
@keyframes siriMicRec{
  0%  { box-shadow:0 6px 20px rgba(239,68,68,.4),0 0 0 0 rgba(239,68,68,.75),0 0 0 0 rgba(239,68,68,.3); }
  50% { box-shadow:0 6px 20px rgba(239,68,68,.4),0 0 0 18px rgba(239,68,68,0),0 0 0 36px rgba(239,68,68,0); }
  100%{ box-shadow:0 6px 20px rgba(239,68,68,.4),0 0 0 0 rgba(239,68,68,0),0 0 0 0 rgba(239,68,68,0); }
}
#vm-flash-btn.torch-on{color:#fbbf24}

/* ═══ AUTH ═══ */
#auth-overlay{
  position:fixed;inset:0;z-index:1000;background:var(--bg);
  display:flex;align-items:center;justify-content:center;padding:24px;
  transition:background .2s;
}
#auth-overlay.hidden{display:none}
.auth-card{
  background:var(--bg-sidebar);border:1px solid var(--border);
  border-radius:20px;padding:40px 32px;
  max-width:360px;width:100%;text-align:center;
}
.auth-logo{
  width:72px;height:72px;border-radius:18px;
  overflow:hidden;
  display:flex;align-items:center;justify-content:center;
  margin:0 auto 20px;
}
.auth-logo img{width:72px;height:72px;object-fit:cover;border-radius:18px}
.auth-title{font-size:22px;font-weight:700;margin-bottom:8px;letter-spacing:-.3px}
.auth-sub{font-size:14px;color:var(--text-muted);margin-bottom:28px;line-height:1.5}
.tg-btn{
  display:inline-flex;align-items:center;gap:10px;
  background:#2AABEE;color:#fff;
  padding:12px 24px;border-radius:12px;
  font-size:15px;font-weight:600;cursor:pointer;border:none;
  width:100%;justify-content:center;transition:background .15s;
}
.tg-btn:hover{background:#1a9dd9}
#tg-widget{margin-top:16px;display:flex;justify-content:center}
#auth-spin{margin-top:20px;color:var(--text-muted);font-size:13px;display:none}

/* ═══ TARIFF MODAL — ПРОКРУТКА ═══ */
#tariff-modal .modal {
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px;
}
.t-cards {
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 4px;
}

.modal-back{
  position:fixed;inset:0;background:rgba(0,0,0,.65);z-index:200;
  display:flex;align-items:center;justify-content:center;padding:20px;
}
.modal-back.hidden{display:none}
.modal{
  background:var(--bg-sidebar);border:1px solid var(--border);
  border-radius:20px;padding:28px;max-width:380px;width:100%;
}
.modal-title{font-size:20px;font-weight:700;margin-bottom:4px;letter-spacing:-.2px}
.modal-sub{font-size:13px;color:var(--text-muted);margin-bottom:20px}
.t-cards{display:flex;flex-direction:column;gap:10px}
.t-card{border:1px solid var(--border);border-radius:12px;padding:14px 16px;transition:all .15s}
.t-card:hover{border-color:var(--accent);background:var(--accent-glow)}
.t-card.pop{border-color:var(--accent)}
.t-name{font-weight:600;font-size:15px}
.t-price{font-size:20px;font-weight:700;color:var(--accent);margin:2px 0}
.t-feat{font-size:12px;color:var(--text-muted)}
.t-highlight{font-size:13px;font-weight:600;color:var(--accent);margin-top:6px;line-height:1.35}
.t-tok-head{font-size:11px;font-weight:600;color:var(--text-faint);text-transform:uppercase;letter-spacing:.04em;margin-top:10px;margin-bottom:4px}
.t-tok-list{display:flex;flex-direction:column;gap:2px}
.t-tok-row{display:flex;justify-content:space-between;align-items:center;font-size:12px;color:var(--text-muted);padding:2px 0}
.t-tok-row span:last-child{font-weight:600;color:var(--text);font-variant-numeric:tabular-nums}
.t-tok-def{opacity:.7}
.t-pay-row{display:flex;gap:8px;margin-top:14px}
.t-pay-btn{flex:1;padding:10px 12px;border-radius:10px;border:1px solid var(--border);background:var(--bg-input);color:var(--text);font-family:var(--font-ui);font-size:13px;font-weight:600;cursor:pointer;transition:all .12s}
.t-pay-btn:hover{border-color:var(--accent);background:var(--accent-glow)}
.t-pay-btn:active{transform:scale(.98)}
.t-pay-card{background:var(--accent);border-color:var(--accent);color:#fff}
.t-pay-card:hover{filter:brightness(1.08);background:var(--accent)}
.modal-close{
  margin-top:16px;width:100%;padding:10px;
  background:var(--bg-input);border:1px solid var(--border);
  border-radius:10px;color:var(--text-muted);
  cursor:pointer;font-size:14px;font-family:var(--font-ui);transition:all .12s;
}
.modal-close:hover{background:var(--bg-hover);color:var(--text)}

/* ═══ PWA INSTALL MODAL ═══ */
.pwa-steps{display:flex;flex-direction:column;gap:12px;margin-bottom:20px;text-align:left}
.pwa-step{display:flex;align-items:flex-start;gap:12px}
.pwa-step-num{
  flex-shrink:0;width:26px;height:26px;border-radius:50%;
  background:var(--accent);color:#fff;
  display:flex;align-items:center;justify-content:center;
  font-size:13px;font-weight:700;
}
.pwa-step p{font-size:14px;color:var(--text);margin:0;line-height:1.5}
.pwa-step strong{color:var(--text)}
.pwa-share-icon{font-size:16px;vertical-align:middle}

/* ═══ TOAST ═══ */
#toast{
  position:fixed;bottom:100px;left:50%;transform:translateX(-50%);
  background:var(--bg-sidebar);border:1px solid var(--border);
  color:var(--text);padding:10px 18px;border-radius:99px;
  font-size:13px;box-shadow:var(--shadow-dropdown);z-index:500;
  opacity:0;pointer-events:none;transition:opacity .2s;white-space:nowrap;
}
#toast.show{opacity:1}
#toast.error{border-color:var(--danger);color:var(--danger)}

/* ═══ RESPONSIVE ═══ */
@media(max-width:640px){
  #sidebar{position:fixed;top:0;left:0;bottom:0;transform:translateX(-100%)}
  #sidebar.open{transform:none}
  #menu-toggle{display:flex}
  #messages{padding:16px 12px 24px}
  .msg-row.msg-user .msg-bubble{max-width:85%}
  #vm-controls{gap: 16px;}
  .vm-ctrl{width: 58px; height: 58px;}
  .vm-ctrl-mic{width: 72px; height: 72px;}
  /* на мобильных устройствах кнопки ввода остаются достаточно крупными */
  #pill-attach, #pill-mic, #pill-orb, #send-btn { width: 44px; height: 44px; }
  /* font-size в #text-input — через clamp(), здесь не перебиваем. */
  #text-input { min-height: 52px; padding: 14px 0; }
}

#sb-back{display:none;position:fixed;inset:0;background:rgba(0,0,0,.5);z-index:9}
*{scrollbar-width:thin;scrollbar-color:var(--border) transparent}

#pwa-banner {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 999;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: var(--surface, #2a2a3e);
  border-top: 1px solid var(--border, rgba(255,255,255,0.1));
  box-shadow: 0 -4px 24px rgba(0,0,0,0.3);
  animation: slideUp .3s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.pwa-banner-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 600px;
  margin: 0 auto;
}
.pwa-banner-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.pwa-banner-text strong { font-size: 14px; }
.pwa-banner-text span   { font-size: 12px; opacity: .6; }
.pwa-banner-btn {
  flex-shrink: 0;
  padding: 8px 18px;
  border-radius: 20px;
  background: #2481cc;
  color: #fff;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.pwa-banner-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: inherit;
  opacity: .5;
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
}