@keyframes spin{to{transform:rotate(360deg)}}
@keyframes smIn{from{opacity:0;transform:translateY(22px)}to{opacity:1;transform:none}}

.sm-overlay {
  position:fixed; left:0; right:0; bottom:0;

  top:calc(var(--sm-top, 0px) * 0.67); z-index:800;
  background:rgba(15,23,42,.48); backdrop-filter:blur(3px);
  display:none;
}
.sm-overlay.open { display:flex; align-items:stretch; justify-content:center; }
body.sm-open .topbar { z-index:920; }

body.sm-open .panel { z-index:930; }
body.sm-open .sk-panel { z-index:930; }
.sm-shell {
  position:fixed; left:0; right:0; bottom:0; top:0;
  margin-top:0;
  max-width:none; max-height:none;
  background:var(--bg-app);
  border-top:1px solid var(--border);
  border-radius:0;
  box-shadow:0 -16px 48px rgba(0,0,0,.25);
  display:flex; flex-direction:column;
  overflow:hidden;
  animation:smIn .24s cubic-bezier(.16,1,.3,1);
}
#sm-shell {
  position:fixed;
  top:calc(var(--sm-top, 0px) * 0.67) !important;
  margin-top:0 !important;
  border-radius:0 !important;
}

.sm-top {
  display:flex; align-items:center; justify-content:space-between;
  min-height:calc(var(--sm-top, 0px) * 0.33 + 52px); height:auto;
  padding:0 12px 0 18px;
  box-sizing:border-box; gap:12px; flex-shrink:0;
  background:var(--bg-surface); border-bottom:1px solid var(--border);
}
.sm-top-title { font-size:13.5px; font-weight:750; letter-spacing:-.01em; display:flex; align-items:center; gap:9px; color:var(--text); }
.sm-top-title svg { width:16px; height:16px; color:var(--text-mute); }
.sm-close {
  width:36px; height:36px; border-radius:8px; flex:none;
  border:1px solid var(--border); background:transparent; color:var(--text-mute);
  cursor:pointer; display:grid; place-items:center;
  transition:background .15s, color .15s, border-color .15s, transform .15s;
}
.sm-close svg { width:16px; height:16px; }
.sm-close:hover { background:var(--bg-hover); color:var(--text); border-color:var(--border-strong); }
.sm-close:active { transform:scale(.94); }
.sm-close:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }

#sidebar-settings-btn .nav-ico svg,
.sm-top-title svg,
.pm-gateway-settings svg,
.pm-c-gear svg {
  transition: transform .45s cubic-bezier(.16,1,.3,1);
  will-change: transform;
}
#sidebar-settings-btn:hover .nav-ico svg,
.sm-top-title:hover svg,
.pm-gateway-settings:hover svg,
.pm-c-gear:hover svg { transform: rotate(90deg); }
@media (prefers-reduced-motion: reduce) {
  #sidebar-settings-btn .nav-ico svg, .sm-top-title svg, .pm-gateway-settings svg, .pm-c-gear svg { transition:none; }
  #sidebar-settings-btn:hover .nav-ico svg, .sm-top-title:hover svg, .pm-gateway-settings:hover svg, .pm-c-gear:hover svg { transform:none; }
}
.sm-content { flex:1; min-height:0; width:100%; overflow:hidden; display:flex; flex-direction:column; border-radius:0 !important; }
#sm-content { border-radius:0 !important; }

.sm-content #settings-modal {
  border:0 !important; border-radius:0 !important; box-shadow:none !important;
  min-height:0 !important;

  display:grid !important;
  grid-template-columns:240px 1fr !important;
  grid-template-rows:1fr !important;
  height:100%; width:100%; max-width:none; min-width:0;
}
.sm-content #settings-modal .smod-nav {
  width:240px; min-width:240px; max-width:240px;
  height:100%; overflow-y:auto;
}
.sm-content .smod-body {
  overflow-y:auto; height:100%; min-height:0;
  max-height:none !important;
}
@media(max-width:860px){
  /* Mobile: one natural scroll container for the whole settings sheet. The desktop 2-column
     grid (each column its own scroll) collapses to a single vertical flow (nav, then body)
     that scrolls as one page, so content below is always reachable. Breakpoint matches the
     settings-page CSS (860px) so the modal scroller engages across the same range. */
  .sm-content { overflow-y:auto !important; -webkit-overflow-scrolling:touch; }
  .sm-content #settings-modal {
    display:block !important; height:auto !important; min-height:100%;
    grid-template-columns:1fr !important; grid-template-rows:none !important;
  }
  .sm-content #settings-modal .smod-nav { width:100%; min-width:0; max-width:none; height:auto; overflow-y:visible; }
  .sm-content .smod-body { height:auto !important; min-height:0; overflow-y:visible !important; max-height:none !important; }
}
.sm-loading { display:flex; align-items:center; justify-content:center; flex:1; color:var(--text-mute); gap:10px; font-size:14px; min-height:300px; }


.am-overlay {
  position:fixed; inset:0; z-index:850;
  background:rgba(0,0,0,.52); backdrop-filter:blur(3px);
  display:none; align-items:center; justify-content:center; padding:20px;
}
.am-overlay.open { display:flex; }
.am-shell {
  width:100%; max-width:860px;
  height:min(820px, calc(100vh - 40px));
  background:var(--bg-surface); border-radius:16px;
  box-shadow:0 28px 60px -12px rgba(0,0,0,.42);
  display:flex; flex-direction:column; overflow:hidden;
  animation:smIn .22s cubic-bezier(.16,1,.3,1);
}
.am-head {
  display:flex; align-items:center; gap:10px;
  padding:14px 18px; border-bottom:1px solid var(--border);
  background:var(--bg-sidebar); flex-shrink:0;
}
.am-av {
  width:34px; height:34px; border-radius:9px; flex:none;
  background:linear-gradient(135deg, var(--accent), var(--accent-dk));
  color:#fff; display:grid; place-items:center;
  font-weight:700; font-size:13px; letter-spacing:.02em;
}
.am-title-wrap { flex:1; min-width:0; }
.am-title { font-size:14.5px; font-weight:700; color:var(--text); }
.am-subtitle { font-size:12px; color:var(--text-mute); margin-top:1px; }
.am-close {
  width:32px; height:32px; border-radius:8px; border:0;
  background:transparent; color:var(--text-mute); cursor:pointer;
  display:grid; place-items:center; transition:background .12s; flex:none;
}
.am-close:hover { background:var(--bg-hover); color:var(--text); }

.am-body { flex:1; min-height:0; overflow:hidden; display:flex; flex-direction:column; }
.am-loading {
  display:flex; align-items:center; justify-content:center;
  gap:10px; font-size:13.5px; color:var(--text-mute);
  padding:48px 24px;
}
.am-body .smod {
  border:0 !important; border-radius:0 !important; box-shadow:none !important;
  display:grid !important;

  grid-template-columns:240px minmax(0,1fr) !important;
  grid-template-rows:1fr !important;
  height:100%; width:100%; min-height:0; overflow:hidden;
}
.am-body .smod-nav { height:100%; overflow-y:auto; min-height:0; }
.am-body .smod-body { height:100%; min-height:0; overflow-y:auto !important; max-height:none !important; }
@media (max-width:640px) {
  .am-shell { max-width:100%; margin:0; border-radius:12px; height:min(92dvh, calc(100vh - 20px)); }
  .am-body .smod { grid-template-columns:1fr !important; grid-template-rows:auto 1fr !important; }
  .am-body .smod-nav { height:auto; overflow-y:visible; }
}
@media (prefers-reduced-motion:reduce) {
  .am-shell { animation:none; }
}


.sk-panel { position:fixed; right:14px; top:58px; z-index:201; width:400px; max-width:calc(100vw - 28px);
  height:min(660px, calc(100vh - 76px)); background:var(--bg-surface); border:1px solid var(--border);
  border-radius:16px; box-shadow:0 24px 60px -12px rgba(0,0,0,.34); display:flex; flex-direction:column; overflow:hidden;
  transform-origin:top right; animation:skIn .2s var(--ease); }
.sk-panel[hidden] { display:none; }
@keyframes skIn { from { opacity:0; transform:translateY(-12px) scale(.97); } to { opacity:1; transform:none; } }
.sk-head { display:flex; align-items:center; gap:10px; padding:13px 15px; border-bottom:1px solid var(--border); background:var(--bg-app); }
.sk-av { width:32px; height:32px; border-radius:9px; flex:none; display:grid; place-items:center; color:#fff; font-size:16px;
  background:linear-gradient(135deg, var(--accent), var(--accent-dk)); box-shadow:0 4px 10px -3px rgba(255,47,58,.55); }
.sk-name { font-weight:700; font-size:14.5px; line-height:1.1; }
.sk-sub { font-size:11.5px; color:var(--text-mute); margin-top:2px; }
.sk-head .sp { flex:1; }
.sk-ico-btn { width:30px; height:30px; border:0; background:transparent; border-radius:8px; color:var(--text-mute); cursor:pointer; display:grid; place-items:center; }
.sk-ico-btn:hover { background:var(--bg-hover); color:var(--text); }
.sk-body { flex:1; overflow-y:auto; padding:16px; display:flex; flex-direction:column; gap:12px; }
.sk-msg { max-width:86%; font-size:13.5px; line-height:1.55; border-radius:14px; padding:9px 13px; white-space:normal; word-wrap:break-word; }
.sk-msg.user { align-self:flex-end; background:var(--accent); color:#fff; border-bottom-right-radius:5px; }
.sk-msg.bot  { align-self:flex-start; background:var(--bg-app); color:var(--text); border:1px solid var(--border); border-bottom-left-radius:5px; }
.sk-msg.bot code { background:rgba(0,0,0,.06); padding:1px 5px; border-radius:5px; font-size:12px; }
.sk-msg.bot ul { margin:6px 0; padding-left:18px; } .sk-msg.bot li { margin:2px 0; }
.sk-msg.bot b { font-weight:650; }
.sk-acts { display:flex; flex-direction:column; gap:5px; align-self:flex-start; max-width:86%; }
.sk-act { font-size:12px; font-weight:600; color:#15803d; background:rgba(22,163,74,.1); border:1px solid rgba(22,163,74,.22); border-radius:8px; padding:5px 10px; display:flex; align-items:center; gap:6px; }
.sk-greet { text-align:center; color:var(--text-mute); padding:18px 8px; }
.sk-greet .g-av { width:46px; height:46px; border-radius:13px; margin:0 auto 12px; display:grid; place-items:center; color:#fff; font-size:22px; background:linear-gradient(135deg, var(--accent), var(--accent-dk)); }
.sk-greet h4 { font-size:15px; color:var(--text); margin-bottom:4px; }
.sk-greet p { font-size:12.5px; line-height:1.5; }
.sk-sugs { display:flex; flex-wrap:wrap; gap:7px; justify-content:center; margin-top:14px; }
.sk-sug { font-size:12px; font-weight:550; color:var(--text-soft); background:var(--bg-surface); border:1px solid var(--border-strong); border-radius:20px; padding:6px 12px; cursor:pointer; transition:border-color .12s; }
.sk-sug:hover { border-color:var(--accent); color:var(--accent); }
.sk-typing { align-self:flex-start; display:flex; gap:4px; padding:11px 14px; background:var(--bg-app); border:1px solid var(--border); border-radius:14px; }
.sk-typing span { width:6px; height:6px; border-radius:50%; background:var(--text-mute); animation:skBlink 1.2s infinite both; }
.sk-typing span:nth-child(2){animation-delay:.2s} .sk-typing span:nth-child(3){animation-delay:.4s}
@keyframes skBlink { 0%,80%,100%{opacity:.3} 40%{opacity:1} }
.sk-foot { border-top:1px solid var(--border); padding:10px 12px; display:flex; align-items:flex-end; gap:8px; background:var(--bg-surface); }
.sk-foot textarea { flex:1; border:1px solid var(--border-strong); border-radius:11px; padding:9px 12px; font-family:inherit; font-size:13.5px; resize:none; outline:none; max-height:120px; color:var(--text); background:var(--bg-app); }
.sk-foot textarea:focus { border-color:var(--accent); box-shadow:0 0 0 3px var(--accent-soft); }
.sk-send { width:38px; height:38px; flex:none; border:0; border-radius:10px; background:var(--accent); color:#fff; cursor:pointer; display:grid; place-items:center; transition:background .12s; }
.sk-send:hover { background:var(--accent-dk); } .sk-send:disabled { opacity:.5; cursor:default; }
.sk-av svg { display:block; }
.sk-on { display:inline-block; width:7px; height:7px; border-radius:50%; background:#16a34a; margin-left:6px; vertical-align:middle; }

.sk-confirm { align-self:flex-start; max-width:88%; margin-top:2px; }
.sk-confirm-warn { font-size:12px; color:var(--text-mute); background:rgba(220,38,38,.07); border:1px solid rgba(220,38,38,.2); border-radius:10px; padding:8px 12px; margin-bottom:7px; line-height:1.5; }
.sk-confirm-warn b { color:#dc2626; }
.sk-confirm-btns { display:flex; gap:8px; }
.sk-allow { flex:1; background:var(--accent); color:#fff; border:0; border-radius:9px; padding:8px 14px; font-size:13px; font-weight:700; cursor:pointer; transition:background .12s; }
.sk-allow:hover { background:var(--accent-dk); }
.sk-allow:disabled { opacity:.5; cursor:default; }
.sk-deny  { flex:1; background:transparent; color:var(--text-soft); border:1.5px solid var(--border-strong); border-radius:9px; padding:8px 14px; font-size:13px; font-weight:600; cursor:pointer; transition:border-color .12s; }
.sk-deny:hover { border-color:#6b7280; color:var(--text); }
.sk-head .sk-id { min-width:0; }
.sk-conv-title { font-size:11.5px; color:var(--text-mute); margin-top:2px; max-width:150px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.sk-history { position:absolute; left:0; right:0; top:53px; bottom:0; background:var(--bg-surface); overflow-y:auto; padding:10px; display:flex; flex-direction:column; gap:3px; z-index:3; }
.sk-history[hidden]{ display:none; }
.sk-hist-new { display:flex; align-items:center; justify-content:center; gap:8px; font-size:13px; font-weight:600; color:#fff; background:var(--accent); border:0; border-radius:10px; padding:9px; cursor:pointer; margin-bottom:6px; }
.sk-hist-new:hover { background:var(--accent-dk); }
.sk-hist-item { display:flex; align-items:center; gap:8px; padding:9px 10px; border-radius:9px; cursor:pointer; }
.sk-hist-item:hover { background:var(--bg-hover); }
.sk-hist-item .t { flex:1; min-width:0; font-size:13px; color:var(--text); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.sk-hist-item.cur { background:var(--bg-active); } .sk-hist-item.cur .t { font-weight:650; }
.sk-hist-item .dt { font-size:11px; color:var(--text-mute); flex:none; }
.sk-hist-item .del { opacity:0; border:0; background:transparent; color:var(--text-mute); cursor:pointer; padding:2px; border-radius:5px; flex:none; }
.sk-hist-item:hover .del { opacity:1; } .sk-hist-item .del:hover { color:#dc2626; background:rgba(220,38,38,.1); }
.sk-hist-empty { text-align:center; color:var(--text-mute); font-size:12.5px; padding:18px; }
.pk-recent-wrap { margin:2px 0 4px; }
.pk-recent-head { display:flex; align-items:center; gap:7px; width:100%; border:0; background:transparent; padding:7px 9px 4px; color:var(--text-mute); font-size:11.5px; font-weight:700; letter-spacing:.03em; text-transform:uppercase; cursor:pointer; text-align:left; }
.pk-recent-head .pk-rh-mark { color:var(--accent); display:grid; place-items:center; }
.pk-recent-head .s-chev { transition:transform .18s; }
.pk-recent-head.collapsed .s-chev { transform:rotate(-90deg); }
.pk-recent { display:flex; flex-direction:column; gap:1px; }
.pk-recent.collapsed { display:none; }
.pk-recent.grown { max-height:300px; overflow-y:auto; }
.pk-recent a { display:block; font-size:12.5px; color:var(--text-soft); padding:5px 9px; border-radius:7px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; cursor:pointer; text-decoration:none; }
.pk-recent a:hover { background:var(--bg-hover); color:var(--text); }
.pk-recent a.pk-seeall { color:var(--accent); font-weight:600; font-size:12px; }
.pk-recent-empty { font-size:12px; color:var(--text-mute); padding:3px 9px 6px; }
@media (max-width:1080px){ .pk-recent-wrap { display:none; } }
@media (max-width:480px){ .sk-panel { right:8px; left:8px; width:auto; top:54px; bottom:8px; height:auto; } }
