:root{
  --bg0:#070b14;
  --bg1:#0a1220;

  --panel:rgba(16, 26, 46, .62);
  --panel2:rgba(16, 26, 46, .42);

  --border:rgba(255,255,255,.08);
  --text:rgba(255,255,255,.92);
  --muted:rgba(255,255,255,.55);

  --radius:18px;
  --shadow:0 18px 55px rgba(0,0,0,.45);
  --shadow2:0 10px 25px rgba(0,0,0,.35);

  --maxChat: 920px;

  /* Accent defaults (teal) */
  --accent:#24c7b7;
  --accent2:#16a89a;
  --accentSoft: rgba(36,199,183,.16);
  --accentBorder: rgba(36,199,183,.40);

  /* Global background glow – MUST change with theme */
  --glowTop: rgba(36,199,183,.22);
  --glowBottom: rgba(36,199,183,.14);
  --glowViolet: rgba(161,78,255,.10);
}

/* BLUE */
:root[data-accent="blue"]{
  --accent:#2b78ff;
  --accent2:#1f5fe0;
  --accentSoft: rgba(43,120,255,.16);
  --accentBorder: rgba(43,120,255,.40);

  --glowTop: rgba(43,120,255,.26);
  --glowBottom: rgba(43,120,255,.14);
  --glowViolet: rgba(161,78,255,.10);
}

/* VIOLET */
:root[data-accent="violet"]{
  --accent:#a14eff;
  --accent2:#7c32d9;
  --accentSoft: rgba(161,78,255,.16);
  --accentBorder: rgba(161,78,255,.40);

  --glowTop: rgba(161,78,255,.24);
  --glowBottom: rgba(161,78,255,.14);
  --glowViolet: rgba(43,120,255,.10); /* лёгкий контраст */
}

/* TEAL */
:root[data-accent="teal"]{
  --accent:#24c7b7;
  --accent2:#16a89a;
  --accentSoft: rgba(36,199,183,.16);
  --accentBorder: rgba(36,199,183,.40);

  --glowTop: rgba(36,199,183,.22);
  --glowBottom: rgba(36,199,183,.14);
  --glowViolet: rgba(161,78,255,.10);
}

*{box-sizing:border-box}
html,body{height:100%; overflow:hidden}
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", "Helvetica Neue";
  color:var(--text);

  /* IMPORTANT: background now uses theme variables */
  background:
    radial-gradient(1200px 600px at 75% 15%, var(--glowTop), transparent 60%),
    radial-gradient(900px 520px at 65% 88%, var(--glowBottom), transparent 55%),
    radial-gradient(820px 520px at 55% 92%, var(--glowViolet), transparent 58%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
}

.app{
  height:100vh;
  min-height:0;
  display:grid;
  grid-template-columns: 320px 1fr;
}

.sidebar{
  padding:18px 14px;
  border-right:1px solid var(--border);
  background: linear-gradient(180deg, rgba(10,18,32,.92), rgba(8,12,22,.92));
  display:flex;
  flex-direction:column;
  gap:12px;
  min-width:280px;
  min-height:0;
}

.brand{padding:10px 12px}
.brand__title{font-weight:800;font-size:16px;line-height:1.2}
.brand__sub{font-size:12px;color:var(--muted);margin-top:2px}

.btn{
  border:1px solid var(--border);
  background: rgba(255,255,255,.06);
  color:var(--text);
  border-radius:14px;
  padding:12px 14px;
  font-weight:750;
  cursor:pointer;
  box-shadow: var(--shadow2);
  transition: transform .08s ease, background .15s ease, border-color .15s ease, filter .15s ease;
}
.btn:active{transform: translateY(1px)}
.btn--primary{
  background: linear-gradient(180deg, var(--accent), var(--accent2));
  border-color: var(--accentBorder);
}
.btn--primary:hover{filter: brightness(1.04)}
.btn--full{width:100%}

.card{
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  border-radius: 18px;
  padding:12px;
  box-shadow: var(--shadow2);
}
.card__head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  margin-bottom:10px;
}
.card__title{
  font-size:12px;
  color:rgba(255,255,255,.70);
  font-weight:800;
  letter-spacing:.02em;
}

.chipRow{
  display:flex;
  gap:8px;
  flex-wrap:nowrap;      /* НЕ переносим */
  align-items:center;
}

.chip{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:7px 9px;        /* чуть компактнее, чтобы 3 влезали */
  border-radius: 999px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: rgba(255,255,255,.85);
  font-weight:750;
  cursor:pointer;
  transition: background .15s ease, border-color .15s ease, transform .08s ease, filter .15s ease;

  white-space:nowrap;     /* текст “Бирюза” не ломаем */
  flex: 0 0 auto;         /* не растягиваемся */
}

.chip:hover{background: rgba(255,255,255,.06)}
.chip:active{transform: translateY(1px)}
.chip--active{
  border-color: var(--accentBorder);
  background: var(--accentSoft);
  color: rgba(255,255,255,.95);
  filter: brightness(1.02);
}

.dot{width:10px;height:10px;border-radius:999px; box-shadow: 0 0 0 3px rgba(255,255,255,.06) inset}
.dot--teal{background:#24c7b7}
.dot--violet{background:#a14eff}
.dot--blue{background:#2b78ff}

.folderTabs{display:flex; flex-direction:column; gap:10px}
.folderTab{
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  border-radius: 14px;
  padding:10px 12px;
  font-weight:800;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:space-between;
}
.folderTab:hover{background: rgba(255,255,255,.06)}
.folderTab--active{
  border-color: var(--accentBorder);
  box-shadow: 0 0 0 1px rgba(255,255,255,.02) inset;
}
.folderTab__name{display:flex; gap:10px; align-items:center}
.folderTab__actions{display:flex; gap:8px; align-items:center}

.sessions{
  flex:1;
  overflow:auto;
  padding-right:4px;
  min-height:0;
}

.session{
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  border-radius: 18px;
  padding:10px 10px;
  margin-bottom:10px;
  display:flex;
  flex-direction:column;
  gap:10px;
  box-shadow: var(--shadow2);
}
.session:hover{background: rgba(255,255,255,.055)}
.session--active{
  border-color: var(--accentBorder);
  box-shadow: 0 0 0 1px rgba(255,255,255,.02) inset;
}

.sessionTop{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:10px;
}
.sessionMain{min-width:0}
.session__title{
  font-weight:850;
  font-size:13px;
  line-height:1.25;
  display:-webkit-box;
  -webkit-line-clamp:2;
  -webkit-box-orient:vertical;
  overflow:hidden;
}
.session__meta{font-size:11px;color:var(--muted);margin-top:4px}
.session__preview{
  font-size:11px;
  color:rgba(255,255,255,.62);
  margin-top:6px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.sessionActions{
  display:flex;
  align-items:center;
  gap:8px;
}
.sessionActions .spacer{flex:1}

.iconBtn{
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  width:30px;height:30px;
  border-radius:12px;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  color:rgba(255,255,255,.78);
  transition: background .15s ease, transform .08s ease, border-color .15s ease, filter .15s ease;
}
.iconBtn:hover{background: rgba(255,255,255,.08)}
.iconBtn:active{transform: translateY(1px)}
.iconBtn--small{width:28px;height:28px;border-radius:10px}

.main{
  display:flex;
  flex-direction:column;
  min-width:0;
  min-height:0;
}

.topbar{
  padding:16px 22px 10px;
  border-bottom:1px solid var(--border);
  background: linear-gradient(180deg, rgba(10,18,32,.55), rgba(10,18,32,.15));
}
.topbar__title{font-weight:900;font-size:18px}
.topbar__meta{margin-top:4px;font-size:12px;color:var(--muted)}

.chatWrap{
  flex:1;
  overflow:auto;
  padding:24px 22px 110px;
  min-height:0;
}
.chat{
  max-width: var(--maxChat);
  margin: 0 auto;
  display:flex;
  flex-direction:column;
  gap:14px;
}
.msgRow{display:flex}
.msgRow--user{justify-content:flex-end}
.msgRow--assistant{justify-content:flex-start}

.msg{
  max-width: 86%;
  border:1px solid var(--border);
  border-radius: 18px;
  padding:12px 14px;
  background: rgba(255,255,255,.05);
  box-shadow: var(--shadow2);
  line-height:1.55;
  white-space:pre-wrap;
  word-break:break-word;
}
.msg--user{
  background: var(--accentSoft);
  border-color: var(--accentBorder);
}
.msg__role{
  font-size:11px;
  color:rgba(255,255,255,.62);
  margin-bottom:6px;
  font-weight:800;
  letter-spacing:.02em;
}

.composer{
  position:sticky;
  bottom:0;
  padding:14px 18px 18px;
  border-top:1px solid var(--border);
  background: linear-gradient(180deg, rgba(7,11,20,.0), rgba(7,11,20,.75));
  backdrop-filter: blur(10px);
}
.composer__form{
  max-width: var(--maxChat);
  margin: 0 auto;
  display:flex;
  gap:10px;
  align-items:center;
  padding:10px;
  border-radius: 22px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  box-shadow: var(--shadow);
}
.composer__input{
  flex:1;
  height:44px;
  border:none;
  outline:none;
  background:transparent;
  color:var(--text);
  font-size:14px;
  padding:0 10px;
}
.composer__send{
  height:44px;
  padding:0 16px;
  border-radius: 16px;
}

.status{
  max-width: var(--maxChat);
  margin: 8px auto 0;
  font-size:12px;
  color:var(--muted);
}
.muted{color:var(--muted)}

.ghostLink{
  margin-top:4px;
  background:transparent;
  border:none;
  color:rgba(255,255,255,.55);
  text-align:left;
  cursor:pointer;
  padding:8px 10px;
}
.ghostLink:hover{color:rgba(255,255,255,.72)}

/* AUTH */
.authOverlay{
  position:fixed;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  background: rgba(0,0,0,.50);
  backdrop-filter: blur(10px);
  z-index: 1000;
}
.authOverlay[hidden]{ display:none !important; }

.authCard{
  width: min(520px, calc(100vw - 32px));
  border:1px solid var(--border);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(16,26,46,.78), rgba(16,26,46,.45));
  box-shadow: var(--shadow);
  padding:16px;
}
.authHead{padding:8px 6px 14px}
.authTitle{font-weight:900;font-size:18px}
.authSub{margin-top:3px;color:var(--muted);font-size:12px}
.authForm{display:flex;flex-direction:column;gap:10px}
.field__label{font-size:12px;color:rgba(255,255,255,.72);font-weight:800;margin-bottom:6px}
.input{
  width:100%;
  height:44px;
  border-radius: 14px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  color:var(--text);
  padding:0 12px;
  outline:none;
}
.input:focus{
  border-color: var(--accentBorder);
  box-shadow: 0 0 0 2px rgba(255,255,255,.02) inset;
}
.authHint{font-size:12px;color:rgba(255,255,255,.65);min-height:16px}

/* ===== Scrollbar theming (dark) ===== */

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.22) rgba(0,0,0,0.25);
}

/* Chrome/Edge/Safari */
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.25);
}
*::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.18);
  border-radius: 10px;
  border: 2px solid rgba(0,0,0,0.25);
}
*::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.28);
}

/* === SETTINGS MODAL FIX (overlay should be usable on small screens) === */
#settingsOverlay{
  align-items: flex-start !important;   /* вместо вертикального центра */
  padding: 14px 12px !important;
  overflow: auto !important;
}
#settingsOverlay .settingsCard{
  width: min(1100px, 96vw);
  max-height: 90vh;                    /* карточка не выше экрана */
  overflow: auto;                      /* внутренний скролл */
}
#settingsOverlay .settingsHeader{
  position: sticky;                    /* крестик всегда виден */
  top: 0;
  z-index: 5;
  background: rgba(10, 14, 24, 0.92);
  backdrop-filter: blur(8px);
  padding-bottom: 10px;
  margin-bottom: 10px;
}
#settingsOverlay .settingsHeader .iconBtn{
  flex: 0 0 auto;
}

@media (max-width: 900px){
  #settingsOverlay .settingsGrid{
    grid-template-columns: 1fr !important;
  }
}
/* === /SETTINGS MODAL FIX === */

/* === MOBILE LAYOUT FIX (sidebar + main) === */
@media (max-width: 900px){
  /* главное: перестаем жать 2 колонки */
  .app{ 
    flex-direction: column !important;
    height: auto !important;
    min-height: 100dvh !important;
  }

  /* чтобы flex-дети не ломали ширину */
  .sidebar, .main{ min-width: 0 !important; }

  /* сайдбар делаем полноширинным "сверху" */
  .sidebar{
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    position: relative !important;
    border-right: none !important;
    border-bottom: 1px solid rgba(255,255,255,.08) !important;
  }

  /* контент — тоже 100% */
  .main{
    width: 100% !important;
  }

  /* чтобы верхняя панель не уезжала */
  .topbar{
    position: sticky !important;
    top: 0 !important;
    z-index: 20 !important;
  }

  /* чтобы чат не давился по ширине */
  .chatWrap{ 
    width: 100% !important;
  }

  /* чуть компактнее на мобильном */
  .sidebar .brand__title{ font-size: 18px !important; }
  .sidebar .brand__sub{ font-size: 12px !important; opacity: .85 !important; }

  /* длинные подсказки в сайдбаре — уменьшаем */
  .sidebar__hint{
    font-size: 12px !important;
    line-height: 1.25 !important;
  }
}
/* === /MOBILE LAYOUT FIX === */

/* === MOBILE LAYOUT FIX v2 (grid+flex) === */
@media (max-width: 900px){

  /* на всякий: и flex, и grid */
  .app{
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    min-height: 100dvh !important;
    height: auto !important;

    /* если вдруг было grid — перекрываем */
    grid-template-columns: 1fr !important;
    grid-template-rows: auto 1fr !important;
    grid-auto-flow: row !important;
  }

  /* чтобы элементы не "ломали" ширину в flex/grid */
  .sidebar, .main{ min-width: 0 !important; width: 100% !important; }

  .sidebar{
    max-width: 100% !important;
    height: auto !important;
    position: relative !important;
    border-right: none !important;
    border-bottom: 1px solid rgba(255,255,255,.08) !important;
  }

  .main{
    max-width: 100% !important;
  }

  /* верхняя панель остаётся сверху при скролле */
  .topbar{
    position: sticky !important;
    top: 0 !important;
    z-index: 50 !important;
  }

  /* чат/контент не сжимаем */
  .chatWrap, .chat, .composer{
    width: 100% !important;
    max-width: 100% !important;
  }

  /* на мобиле делаем чуть компактнее */
  .sidebar__hint{
    font-size: 12px !important;
    line-height: 1.25 !important;
  }
}
/* === /MOBILE LAYOUT FIX v2 === */

/* mobile-fix-ios-dvh v1 */
html, body { height: 100%; }
body { overflow: hidden; }

/* основной контейнер приложения */
.app {
  height: 100dvh;
  min-height: 100dvh;
}

/* iOS fallback */
@supports (-webkit-touch-callout: none) {
  .app {
    height: -webkit-fill-available;
    min-height: -webkit-fill-available;
  }
}

/* чат и компоновка: чтобы не уезжало под нижнюю панель */
.main {
  min-height: 0;
}

.chatWrap {
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.composer {
  position: sticky;
  bottom: 0;
  padding-bottom: env(safe-area-inset-bottom);
}


/* mobile-drawer-v1 */
/* На десктопе кнопка не нужна */
#btnSidebar { display: none; }

.mobileOverlay {
  display: none;
}

/* Мобилка: показываем чат, а список чатов прячем в выезжающий сайдбар */
@media (max-width: 900px) {
  #btnSidebar { display: inline-flex; }

  .app { height: 100dvh; min-height: 100dvh; }

  /* overlay */
  .mobileOverlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 40;
    display: none;
  }
  .mobileOverlay.is-open { display: block; }

  /* drawer sidebar */
  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: min(92vw, 360px);
    transform: translateX(-105%);
    transition: transform .18s ease;
    z-index: 50;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar.is-open { transform: translateX(0); }

  /* main на всю ширину */
  .main { width: 100%; }

  /* композер не уезжает под нижнюю панель */
  .composer { padding-bottom: env(safe-area-inset-bottom); }
}


/* mobile-layout-v2 */
/* ===== Mobile layout v2 (iOS/Safari friendly) ===== */

/* Десктоп: скрываем кнопку "Чаты" */
#btnSidebar { display: none; }

/* Оверлей под drawer */
.mobileOverlay {
  display: none;
}

/* Класс блокировки скролла страницы, когда открыт drawer */
html.mobile-lock, body.mobile-lock {
  overflow: hidden !important;
  height: 100% !important;
}

/* Мобилка */
@media (max-width: 900px) {
  #btnSidebar { display: inline-flex; }

  /* Самое важное: не даём странице скроллиться, скролл только внутри chatWrap */
  html, body {
    height: 100%;
    overflow: hidden;
  }

  .app {
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  /* MAIN как колонка: topbar сверху, чат по центру (скролл), composer снизу */
  .main {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  /* Верхняя панель всегда видна */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    padding-top: env(safe-area-inset-top);
    background: rgba(10,14,20,0.92);
    backdrop-filter: blur(10px);
  }

  /* Чат занимает всё оставшееся место и скроллится */
  .chatWrap {
    flex: 1 1 auto;
    min-height: 0;            /* критично для iOS */
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 12px;
  }

  /* Нижняя панель не закрывает ввод */
  .composer {
    position: sticky;
    bottom: 0;
    z-index: 25;
    padding-bottom: calc(env(safe-area-inset-bottom) + 8px);
    background: rgba(10,14,20,0.92);
    backdrop-filter: blur(10px);
  }

  /* Поджимаем кнопки в topbar на мобиле */
  .topbar .btn {
    padding: 10px 12px;
    font-size: 14px;
    white-space: nowrap;
  }

  /* Overlay */
  .mobileOverlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 40;
    display: none;
  }
  .mobileOverlay.is-open { display: block; }

  /* Drawer sidebar */
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(92vw, 360px);
    transform: translateX(-105%);
    transition: transform .18s ease;
    z-index: 50;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sidebar.is-open { transform: translateX(0); }

  /* на мобиле main всегда 100% */
  .main { width: 100%; }
}

/* ====== Mobile Drawer Layout (stage2_mobile_drawer2) ====== */
.sidebarBackdrop{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
  z-index: 999;
}
body.sidebarOpen .sidebarBackdrop{
  opacity: 1;
  pointer-events: auto;
}

.sidebarMobileTop{
  display: none;
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 10px 10px 0 10px;
  backdrop-filter: blur(10px);
}

@media (max-width: 900px){
  html, body{ height: 100%; }
  body{ overflow-x: hidden; }

  .app{ display: block !important; }

  .sidebar{
    position: fixed !important;
    top: 0;
    left: 0;
    height: 100dvh;
    width: min(92vw, 380px);
    transform: translateX(-105%);
    transition: transform .22s ease;
    z-index: 1000;
    overflow-y: auto;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  body.sidebarOpen .sidebar{ transform: translateX(0); }

  .sidebarMobileTop{ display: flex; justify-content: flex-end; }

  .main{
    width: 100% !important;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
  }

  .topbar{
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .chatWrap{
    flex: 1;
    min-height: 0;
  }

  .chat{
    height: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .composer{
    position: sticky;
    bottom: 0;
    z-index: 10;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  #btnSidebar{ margin-right: 8px; }
}

/* ====== Mobile UX fixes (stage2_mobile_final3) ====== */

/* Drawer backdrop */
.sidebarBackdrop{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
  z-index: 999;
}
body.sidebarOpen .sidebarBackdrop{
  opacity: 1;
  pointer-events: auto;
}

/* Mobile close row inside sidebar */
.sidebarMobileTop{
  display: none;
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 10px 10px 0 10px;
  backdrop-filter: blur(10px);
}

/* Settings modal: make it usable on phone (height, scroll, sticky actions) */
#settingsOverlay .authCard{
  max-height: calc(100dvh - 24px);
  overflow: auto;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
#settingsOverlay .settingsActions{
  position: sticky;
  bottom: 0;
  z-index: 5;
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom)) 0;
  backdrop-filter: blur(10px);
}

/* Slightly reduce spacing on small screens */
@media (max-width: 900px){
  html, body{ height: 100%; }
  body{ overflow-x: hidden; }

  .app{ display: block !important; }

  .sidebar{
    position: fixed !important;
    top: 0;
    left: 0;
    height: 100dvh;
    width: min(92vw, 380px);
    transform: translateX(-105%);
    transition: transform .22s ease;
    z-index: 1000;
    overflow-y: auto;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  body.sidebarOpen .sidebar{ transform: translateX(0); }
  .sidebarMobileTop{ display: flex; justify-content: flex-end; }

  .main{
    width: 100% !important;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
  }

  .topbar{
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .chatWrap{ flex: 1; min-height: 0; }
  .chat{
    height: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .composer{
    position: sticky;
    bottom: 0;
    z-index: 10;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  #btnSidebar{ margin-right: 8px; }

  /* If some old "Чаты" button exists in header actions — we hide it by class hook in JS too */
}

/* ===== stage2_drawer_cssonly2 (NO JS) ===== */
@media (max-width: 900px){
  input, textarea, select, button { font-size: 16px; }
}

.sidebarBackdrop{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
  z-index: 999;
}

.sidebarMobileTop{
  display: none;
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 10px 10px 0 10px;
  backdrop-filter: blur(10px);
}

@media (max-width: 900px){
  html, body { height: 100%; }
  body { overflow-x: hidden; }

  .app { display: block !important; }

  .sidebar{
    position: fixed !important;
    top: 0; left: 0;
    height: 100dvh;
    width: min(92vw, 380px);
    transform: translateX(-105%);
    transition: transform .22s ease;
    z-index: 1000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .main{
    width: 100% !important;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .topbar{ position: sticky; top: 0; z-index: 10; }
  .chatWrap{ flex: 1; min-height: 0; overflow: hidden; }
  .chat{ height: 100%; overflow: auto; -webkit-overflow-scrolling: touch; }
  .composer{
    position: sticky;
    bottom: 0;
    z-index: 10;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  #btnSidebar{ position: relative; z-index: 2000; }

  #drawerToggle:checked ~ #sidebarBackdrop{
    display: block;
    opacity: 1;
    pointer-events: auto;
  }
  #drawerToggle:checked ~ .app .sidebar{ transform: translateX(0); }
  .sidebarMobileTop{ display: flex; justify-content: flex-end; }
}

/* ===== stage2_fixburger1 ===== */
#btnSidebar{
  cursor: pointer;
  position: relative;
  z-index: 3000; /* выше всего, чтобы не перекрывался */
  -webkit-tap-highlight-color: transparent;
}
