:root {
  --bg: #f3f0ea;
  --panel: #fffdf8;
  --panel-soft: #e8e3da;
  --text: #111111;
  --muted: #75716a;
  --line: #d9d2c7;
  --accent: #111111;
  --accent-text: #f8f4ec;
  --danger: #b44f57;
  --bubble: #e7e1d7;
  --shadow: 0 18px 48px rgba(20, 16, 11, .12);
}

body.dark {
  --bg: #141923;
  --panel: #1e2531;
  --panel-soft: #2a3342;
  --text: #f5f2eb;
  --muted: #a7adba;
  --line: #344052;
  --accent: #f5f2eb;
  --accent-text: #141923;
  --danger: #ef9a9f;
  --bubble: #252e3c;
  --shadow: 0 18px 48px rgba(0, 0, 0, .36);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea { font: inherit; }

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

button:not(:disabled),
a {
  -webkit-tap-highlight-color: transparent;
}

button:not(:disabled):active,
a:active {
  transform: scale(.97);
}

.icon-button:not(:disabled):active,
.plain-button:not(:disabled):active,
.send:not(:disabled):active,
.image-upload:not(:disabled):active,
.history-delete:not(:disabled):active {
  transform: scale(.91);
}

.app-shell {
  transform-origin: center bottom;
  transition: transform .28s cubic-bezier(.22, .8, .3, 1), filter .28s ease;
}

body.sheet-open .app-shell {
  transform: scale(.992);
  filter: saturate(.96);
}

body.theme-transitioning,
body.theme-transitioning .app-shell,
body.theme-transitioning .drawer,
body.theme-transitioning .sheet,
body.theme-transitioning .composer,
body.theme-transitioning .bubble,
body.theme-transitioning button,
body.theme-transitioning a {
  transition-property: background-color, border-color, color, box-shadow, filter, transform;
  transition-duration: .24s;
  transition-timing-function: ease;
}

.app-shell {
  display: flex;
  flex-direction: column;
  max-width: 860px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--bg);
}

.file-drop-overlay {
  position: fixed;
  z-index: 4;
  inset: 10px max(10px, calc((100vw - 840px) / 2));
  display: grid;
  place-items: center;
  border: 2px dashed color-mix(in srgb, #657bd8 58%, var(--line));
  border-radius: 24px;
  background: color-mix(in srgb, var(--panel) 88%, #7187dc 12%);
  opacity: 0;
  pointer-events: none;
  transform: scale(.985);
  transition: opacity .18s ease, transform .22s cubic-bezier(.2, .82, .3, 1);
  backdrop-filter: blur(10px);
}

.file-drop-overlay.visible {
  opacity: .96;
  transform: scale(1);
}

.file-drop-card {
  display: grid;
  justify-items: center;
  gap: 7px;
  padding: 24px;
  color: var(--text);
  text-align: center;
  animation: file-drop-breathe 1.8s ease-in-out infinite;
}

.file-drop-card small { color: var(--muted); font-size: 12px; }
.file-drop-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin-bottom: 5px;
  border-radius: 18px;
  background: linear-gradient(135deg, #806bd8, #527fda, #55add1);
  box-shadow: 0 10px 28px rgba(82, 105, 202, .28);
  color: #fff;
  font-size: 34px;
  font-weight: 400;
}

@keyframes file-drop-breathe {
  50% { transform: translateY(-4px) scale(1.02); }
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 68px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(14px);
}

.icon-button,
.plain-button {
  background: transparent;
}

.menu-button {
  display: grid;
  align-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  padding: 0 8px;
}

.menu-button span {
  display: block;
  width: 24px;
  height: 2px;
  border-radius: 2px;
  background: var(--text);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  font-size: 20px;
  font-weight: 850;
}

.brand b { color: var(--muted); }

.drawer-logo,
.welcome-logo {
  display: grid;
  place-items: center;
  background: var(--text);
  color: var(--bg);
  font-weight: 900;
}

.model-current {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(56vw, 360px);
  margin-left: auto;
  padding: 6px 9px 6px 6px;
  border-radius: 13px;
  background: var(--panel-soft);
  font-size: 12px;
  font-weight: 700;
}

#selectedModelName {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tiny-logo,
.logo {
  display: grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--text);
  color: var(--bg);
  font-size: 10px;
  font-weight: 900;
}

.logo-media,
.tiny-logo.logo-media {
  position: relative;
  overflow: hidden;
  padding: 0;
  background: color-mix(in srgb, var(--panel) 82%, var(--panel-soft));
  color: var(--text);
}

.catalog-logo-image {
  position: absolute;
  inset: 5px;
  width: calc(100% - 10px);
  height: calc(100% - 10px);
  object-fit: contain;
  opacity: 0;
  transition: opacity .15s ease;
}

.logo-fallback {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.logo-media.logo-loaded .catalog-logo-image { opacity: 1; }
.logo-media.logo-loaded .logo-fallback { visibility: hidden; }
.logo-media.logo-failed .catalog-logo-image { display: none; }

body.dark .logo-invert-dark.catalog-logo-image,
body.dark .logo-invert-dark .catalog-logo-image {
  filter: invert(92%) sepia(8%) saturate(160%) hue-rotate(345deg);
}

.chevron {
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.chat {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 16px;
}

.welcome {
  margin: auto;
  text-align: center;
}

.welcome-logo {
  width: 76px;
  height: 76px;
  margin: 0 auto 16px;
  border-radius: 25px;
  font-size: 36px;
}

.welcome h1 {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1.05;
}

.welcome p {
  margin: 0;
  color: var(--muted);
}

.bubble {
  max-width: min(86%, 680px);
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: min(86%, 680px);
}

.message-wrap.message-enter {
  animation: message-enter .3s cubic-bezier(.2, .82, .3, 1) both;
}

@keyframes message-enter {
  from { opacity: 0; transform: translateY(9px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.message-wrap.user { align-self: flex-end; align-items: flex-end; }
.message-wrap.assistant { align-self: flex-start; align-items: flex-start; }

.message-wrap .bubble {
  max-width: 100%;
}

.message-images {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 180px));
  gap: 5px;
  max-width: 365px;
}

.message-images a {
  display: block;
  overflow: hidden;
  border-radius: 14px;
  background: var(--panel-soft);
}

.message-images img {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: cover;
}

.message-images a:only-child img {
  max-height: 360px;
  object-fit: contain;
}

.message-attachments {
  display: grid;
  gap: 7px;
  width: min(100%, 320px);
}

.message-documents {
  display: grid;
  gap: 7px;
  width: 100%;
}

.message-meta {
  max-width: 100%;
  padding: 0 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.message-meta.meta-ready {
  animation: meta-reveal .28s ease both;
}

@keyframes meta-reveal {
  from { opacity: 0; transform: translateY(-3px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-footer {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  min-height: 22px;
}

.message-wrap.user .message-footer { justify-content: flex-end; }
.message-wrap.assistant .message-footer { justify-content: flex-start; }

.message-copy {
  display: grid;
  place-items: center;
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  opacity: .72;
  transition: background .16s ease, color .16s ease, opacity .16s ease, transform .16s ease;
}

.message-copy:hover,
.message-copy:active {
  background: var(--panel-soft);
  color: var(--text);
  opacity: 1;
}

.message-copy.copied {
  color: #25a55f;
  opacity: 1;
  animation: copy-success .34s cubic-bezier(.2, .9, .3, 1);
}

@keyframes copy-success {
  35% { transform: scale(1.28) rotate(-7deg); }
  100% { transform: scale(1) rotate(0); }
}

.message-copy:disabled { visibility: hidden; }

.message-wrap.user .message-meta {
  text-align: right;
}

.bubble.user {
  align-self: flex-end;
  border-bottom-right-radius: 5px;
  background: var(--text);
  color: var(--bg);
}

.bubble.assistant {
  align-self: flex-start;
  border-bottom-left-radius: 5px;
  background: var(--bubble);
  white-space: normal;
}

.bubble.assistant.streaming::after {
  content: '';
  display: inline-block;
  width: 7px;
  height: 1.15em;
  margin-left: 3px;
  border-radius: 2px;
  vertical-align: -.18em;
  background: var(--accent);
  animation: stream-cursor .8s steps(2, jump-none) infinite;
}

.bubble.assistant.awaiting {
  color: var(--muted);
  animation: waiting-breathe 1.25s ease-in-out infinite;
}

.bubble.assistant.streaming-plain {
  white-space: pre-wrap;
}

.bubble.assistant.stream-formatted {
  animation: stream-format .2s ease both;
}

@keyframes waiting-breathe {
  0%, 100% { opacity: .62; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-1px); }
}

@keyframes stream-format {
  from { opacity: .86; }
  to { opacity: 1; }
}

@keyframes stream-cursor { 50% { opacity: .15; } }

.bubble.assistant > :first-child { margin-top: 0; }
.bubble.assistant > :last-child { margin-bottom: 0; }

.bubble h1,
.bubble h2,
.bubble h3,
.bubble h4,
.bubble h5,
.bubble h6 {
  margin: 17px 0 8px;
  line-height: 1.25;
}

.bubble h1 { font-size: 22px; }
.bubble h2 { font-size: 19px; }
.bubble h3 { font-size: 17px; }
.bubble h4 { font-size: 15px; }
.bubble h5,
.bubble h6 { font-size: 14px; }

.bubble p {
  margin: 0 0 11px;
}

.bubble ul,
.bubble ol {
  display: block;
  margin: 7px 0 12px;
  padding-left: 24px;
}

.bubble ul { list-style: disc outside; }
.bubble ol { list-style: decimal outside; }

.bubble li {
  display: list-item;
  margin: 4px 0;
  padding-left: 2px;
}

.bubble blockquote {
  margin: 10px 0;
  padding: 7px 11px;
  border-left: 3px solid var(--muted);
  color: var(--muted);
  background: rgba(127, 127, 127, .08);
}

.bubble hr {
  height: 1px;
  margin: 15px 0;
  border: 0;
  background: var(--line);
}

.bubble code {
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(0, 0, 0, .08);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.bubble pre {
  max-width: 100%;
  overflow-x: auto;
  margin: 10px 0;
  padding: 11px;
  border-radius: 9px;
  background: rgba(0, 0, 0, .1);
  white-space: pre;
  line-height: 1.45;
}

.bubble pre code {
  padding: 0;
  background: transparent;
  white-space: inherit;
}

.bubble .math-display {
  max-width: 100%;
  overflow-x: auto;
  margin: 12px 0;
  padding: 4px 2px;
  text-align: center;
  overscroll-behavior-x: contain;
}

.bubble .katex-display {
  margin: 0;
}

.bubble a {
  color: #2878d7;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.markdown-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  margin: 10px 0 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
}

.markdown-table-wrap table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.markdown-table-wrap th,
.markdown-table-wrap td {
  min-width: 100px;
  padding: 8px 10px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  white-space: normal;
  vertical-align: top;
}

.markdown-table-wrap th {
  background: rgba(127, 127, 127, .1);
  font-weight: 800;
}

.markdown-table-wrap th:last-child,
.markdown-table-wrap td:last-child { border-right: 0; }
.markdown-table-wrap tbody tr:last-child td { border-bottom: 0; }

.composer {
  flex: none;
  margin: 0 12px max(14px, env(safe-area-inset-bottom));
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.context-compression-status {
  display: flex;
  flex: none;
  align-items: center;
  align-self: center;
  gap: 8px;
  max-height: 0;
  margin: 0 auto;
  padding: 0 14px;
  overflow: hidden;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 14px 14px 0 0;
  opacity: 0;
  transform: translateY(18px) scale(.96);
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  transition: max-height .25s ease, padding .25s ease, opacity .2s ease, transform .25s ease;
}

.context-compression-status.visible {
  max-height: 42px;
  padding: 8px 14px 7px;
  border-color: var(--line);
  opacity: 1;
  transform: translateY(1px) scale(1);
}

.context-compression-status.visible > span:last-child {
  animation: status-breathe 1.3s ease-in-out infinite;
}

@keyframes status-breathe {
  50% { opacity: .55; }
}

.context-compression-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid color-mix(in srgb, var(--muted) 30%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: context-spin .75s linear infinite;
}

@keyframes context-spin { to { transform: rotate(360deg); } }

.composer-tools {
  display: flex;
  align-items: center;
  min-height: 26px;
  padding-bottom: 2px;
}

.reasoning-current {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.reasoning-current:not(:disabled):hover {
  background: var(--panel-soft);
  color: var(--text);
}

.web-search-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  padding: 5px 9px;
  border-radius: 10px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  transition: background .18s ease, color .18s ease, transform .18s ease, box-shadow .18s ease;
}

.web-search-toggle[aria-pressed="true"] {
  background: #2878d7;
  color: #fff;
  box-shadow: 0 4px 13px color-mix(in srgb, #2878d7 28%, transparent);
}

.web-search-toggle.toggle-bounce .ui-icon {
  animation: globe-toggle .42s cubic-bezier(.2, .85, .3, 1);
}

.web-search-toggle.searching .ui-icon {
  animation: globe-search 1.15s linear infinite;
}

@keyframes globe-toggle {
  50% { transform: rotate(24deg) scale(1.14); }
}

@keyframes globe-search {
  to { transform: rotate(360deg); }
}

.image-preview-list {
  display: flex;
  gap: 7px;
  padding: 6px 2px 7px;
  overflow-x: auto;
}

.image-preview-list[hidden] { display: none; }

.image-preview {
  position: relative;
  flex: 0 0 64px;
  width: 64px;
  height: 64px;
}

.image-preview img {
  width: 100%;
  height: 100%;
  border-radius: 11px;
  object-fit: cover;
}

.document-preview-content {
  display: grid;
  align-content: center;
  gap: 4px;
  width: 100%;
  height: 100%;
  padding: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel-soft);
}

.document-preview-content b { font-size: 11px; }
.document-preview-content small { overflow: hidden; color: var(--muted); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }

.message-document {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 62px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  box-shadow: 0 4px 14px rgba(20, 16, 11, .06);
  transition: border-color .16s ease, background .16s ease, transform .16s ease;
}

.message-document:hover {
  border-color: color-mix(in srgb, #6578c8 42%, var(--line));
  background: color-mix(in srgb, var(--panel) 92%, #6578c8 8%);
}

.message-document-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: color-mix(in srgb, var(--muted) 72%, var(--panel));
  color: var(--panel);
}

.message-document-icon svg { width: 22px; height: 22px; }

.message-document-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.message-document-copy strong,
.message-document-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-document-copy strong { font-size: 13px; }
.message-document-copy small { color: var(--muted); font-size: 11px; }

body.dark .message-document {
  border-color: color-mix(in srgb, var(--line) 76%, #fff 24%);
  box-shadow: 0 5px 18px rgba(0, 0, 0, .18);
}

.image-preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: #24262b;
  color: #fff;
  font-size: 0;
}

.image-preview-remove::before,
.image-preview-remove::after {
  position: absolute;
  width: 10px;
  height: 1.5px;
  border-radius: 2px;
  background: currentColor;
  content: '';
}

.image-preview-remove::before { transform: rotate(45deg); }
.image-preview-remove::after { transform: rotate(-45deg); }

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.input-row textarea {
  flex: 1;
  display: block;
  min-height: 30px;
  max-height: 168px;
  padding: 6px 7px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  line-height: 1.45;
  transition: height .16s ease;
}

.image-upload {
  display: grid;
  place-items: center;
  flex: 0 0 35px;
  width: 35px;
  height: 35px;
  margin-bottom: 1px;
  border-radius: 11px;
  background: var(--panel-soft);
  color: var(--muted);
}

.image-upload:disabled { opacity: .4; }

.image-upload svg {
  width: 21px;
  height: 21px;
  fill: currentColor;
}

.send {
  display: grid;
  place-items: center;
  width: 35px;
  height: 35px;
  margin-bottom: 1px;
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 21px;
  font-weight: 800;
  transition: opacity .18s ease, transform .16s ease, background .2s ease;
}

.send:disabled { opacity: .45; }

.send.sending { position: relative; }
.send.sending svg { opacity: 0; transform: scale(.65); }
.send.sending::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid color-mix(in srgb, var(--accent-text) 35%, transparent);
  border-top-color: var(--accent-text);
  border-radius: 50%;
  animation: send-spin .72s linear infinite;
}

.send svg { transition: opacity .15s ease, transform .15s ease; }
@keyframes send-spin { to { transform: rotate(360deg); } }

.drawer {
  position: fixed;
  z-index: 5;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  width: min(88vw, 356px);
  padding: 16px;
  background: var(--panel);
  box-shadow: 16px 0 42px rgba(0, 0, 0, .28);
  transform: translateX(-105%);
  transition: transform .3s cubic-bezier(.22, .82, .28, 1);
}

.drawer.open { transform: translateX(0); }

.drawer > .drawer-head,
.drawer > .new-chat,
.drawer > .history-title,
.drawer > .history-list,
.drawer > .drawer-bottom {
  opacity: 0;
  transform: translateY(7px);
  transition: opacity .18s ease, transform .24s cubic-bezier(.2, .8, .3, 1);
}

.drawer.open > .drawer-head,
.drawer.open > .new-chat,
.drawer.open > .history-title,
.drawer.open > .history-list,
.drawer.open > .drawer-bottom {
  opacity: 1;
  transform: translateY(0);
}

.drawer.open > .drawer-head { transition-delay: .035s; }
.drawer.open > .new-chat { transition-delay: .065s; }
.drawer.open > .history-title { transition-delay: .09s; }
.drawer.open > .history-list { transition-delay: .115s; }
.drawer.open > .drawer-bottom { transition-delay: .14s; }

.drawer-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  padding-right: 42px;
  padding-bottom: 18px;
}

.drawer-head strong {
  font-size: 18px;
}

.drawer-logo {
  width: 34px;
  height: 34px;
  border-radius: 11px;
}

.drawer-head button {
  margin-left: auto;
  color: var(--muted);
  font-size: 28px;
}

.drawer-head .upgrade-plan {
  position: relative;
  isolation: isolate;
  margin-left: auto;
  padding: 7px 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .34);
  border-radius: 999px;
  background: linear-gradient(110deg, #806bd8, #527fda, #55add1, #806bd8);
  background-size: 300% 100%;
  box-shadow: 0 5px 16px rgba(82, 105, 202, .24);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .2px;
  animation: upgrade-gradient 7s ease-in-out infinite;
}

.drawer-head .upgrade-plan::after {
  position: absolute;
  z-index: -1;
  inset: 0;
  background: linear-gradient(110deg, transparent 22%, rgba(255, 255, 255, .2) 48%, transparent 74%);
  content: '';
  transform: translateX(-100%);
  animation: upgrade-sheen 7s ease-in-out infinite;
}

.drawer-head .upgrade-plan[hidden] { display: none; }
.drawer-head .plain-button { margin-left: 0; }
.drawer-head #closeButton {
  position: absolute;
  top: calc(50% - 9px);
  right: 0;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin: 0;
  transform: translateY(-50%);
}

@keyframes upgrade-gradient {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

@keyframes upgrade-sheen {
  0%, 35% { transform: translateX(-100%); }
  62%, 100% { transform: translateX(100%); }
}

.new-chat {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  text-align: left;
  font-weight: 750;
}

.history-title {
  padding: 26px 8px 10px;
  color: color-mix(in srgb, var(--muted) 58%, var(--panel));
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .6px;
  text-transform: uppercase;
}

.history-list {
  flex: 1;
  min-height: 0;
  display: grid;
  align-content: start;
  grid-auto-rows: max-content;
  gap: 6px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 4px;
  color: var(--muted);
  font-size: 14px;
}

.history-list p { margin: 4px 0; }

.history-item {
  display: grid;
  grid-template-columns: 1fr 34px;
  align-items: stretch;
  min-height: 52px;
  max-height: 72px;
  overflow: hidden;
  border-radius: 10px;
  transform-origin: top center;
  transition: background .18s ease, opacity .18s ease, transform .18s ease, max-height .2s ease, min-height .2s ease;
}

.history-item.history-enter {
  animation: history-enter .28s cubic-bezier(.2, .82, .3, 1) both;
}

.history-item.history-exit {
  min-height: 0;
  max-height: 0;
  opacity: 0;
  transform: translateX(-12px) scale(.98);
  pointer-events: none;
}

@keyframes history-enter {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.history-item.active {
  background: var(--panel-soft);
}

.history-open {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 9px 8px;
  background: transparent;
  text-align: left;
}

.history-open strong,
.history-open small {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.history-open strong {
  font-size: 13px;
}

.history-open small {
  color: var(--muted);
  font-size: 11px;
}

.history-delete {
  background: transparent;
  color: var(--muted);
  font-size: 20px;
}

.history-management {
  display: grid;
  gap: 10px;
  margin: 10px 0 4px;
  padding: 14px 10px 4px;
  border-top: 1px solid var(--line);
}

.history-management small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.history-delete-all {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 32%, transparent);
  border-radius: 10px;
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  color: var(--danger);
  font-weight: 750;
}

.history-delete-all:disabled {
  opacity: .55;
}

.drawer-bottom {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.theme-toggle,
.support-link,
.documents-button,
.account-preview {
  display: flex;
  align-items: center;
  width: 100%;
  background: transparent;
  text-align: left;
}

.theme-toggle {
  gap: 10px;
  padding: 10px 7px;
  color: var(--muted);
  font-size: 13px;
}

.support-link,
.documents-button {
  gap: 10px;
  padding: 10px 7px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}

.support-link:hover,
.documents-button:hover {
  background: var(--panel-soft);
  color: var(--text);
}

.support-link .chevron,
.documents-button .chevron {
  margin-left: auto;
  font-size: 20px;
}

.support-link[hidden],
.documents-button[hidden] { display: none; }

.documents-list {
  display: grid;
  gap: 8px;
  padding: 14px 16px max(22px, env(safe-area-inset-bottom));
}

.document-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel-soft);
  color: var(--text);
  text-decoration: none;
}

.document-link > span {
  display: grid;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.document-link strong { font-size: 14px; }
.document-link small { color: var(--muted); font-size: 12px; line-height: 1.4; }
.document-link > b { color: var(--muted); font-size: 24px; font-weight: 400; }
.document-link[hidden] { display: none; }

.account-preview {
  gap: 10px;
  padding: 10px 4px;
}

.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 43px;
  height: 43px;
  border-radius: 50%;
  background-position: center;
  background-size: cover;
}

.placeholder {
  background: var(--text);
  color: var(--bg);
  font-weight: 800;
}

.account-text {
  display: grid;
  gap: 3px;
  min-width: 0;
  flex: 1;
}

.account-text strong,
.account-text small {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.account-text strong { font-size: 14px; }
.account-text small { color: var(--muted); font-size: 12px; }

.backdrop,
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .46);
  opacity: 0;
  visibility: hidden;
  transition: opacity .24s ease, visibility .24s ease;
}

.backdrop.show {
  z-index: 4;
  opacity: 1;
  visibility: visible;
}

.sheet-backdrop.show {
  z-index: 6;
  opacity: 1;
  visibility: visible;
}

.sheet {
  position: fixed;
  z-index: 7;
  inset: auto 0 0;
  display: flex;
  flex-direction: column;
  max-width: 860px;
  max-height: 78dvh;
  margin: auto;
  border-radius: 24px 24px 0 0;
  background: var(--panel);
  box-shadow: 0 -16px 42px rgba(0, 0, 0, .2);
  opacity: .92;
  transform: translateY(105%) scale(.985);
  transform-origin: center bottom;
  transition: transform .3s cubic-bezier(.22, .82, .28, 1), opacity .2s ease;
}

.sheet.show { opacity: 1; transform: translateY(0) scale(1); }

.sheet.show .sheet-head,
.sheet.show > :not(.sheet-head) {
  animation: sheet-content-enter .28s .07s ease both;
}

@keyframes sheet-content-enter {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 17px 18px;
  border-bottom: 1px solid var(--line);
}

.sheet-head strong {
  flex: 1;
  font-size: 16px;
}

.sheet-head button {
  width: 30px;
  color: var(--muted);
  font-size: 28px;
}

.sheet-head .back {
  background: transparent;
  font-size: 35px;
  line-height: 12px;
}

.model-list {
  overflow: auto;
  padding: 9px 13px 22px;
}

.company-row,
.model-row {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 12px 8px;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  transition: background .16s ease, transform .16s ease, box-shadow .18s ease;
}

.company-row:hover,
.model-row:not(:disabled):hover {
  background: var(--panel-soft);
}

.company-row span:nth-child(2) {
  flex: 1;
  font-weight: 750;
}

.company-row b,
.model-row > b {
  margin-left: auto;
  color: var(--muted);
  font-size: 21px;
  font-weight: 400;
}

.model-row > span:nth-child(2) {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.model-row strong {
  font-size: 14px;
}

.model-row em {
  color: var(--muted);
  font-style: normal;
  font-weight: 650;
}

.model-row small {
  color: var(--muted);
  font-size: 12px;
}

.model-row.locked {
  opacity: .38;
  cursor: not-allowed;
}

.model-row.selected {
  background: color-mix(in srgb, var(--accent) 8%, var(--panel-soft));
}

.model-row.selected-flash {
  animation: model-selected .28s cubic-bezier(.2, .85, .3, 1);
}

.selection-check {
  color: #4f8d48 !important;
  animation: selection-check .28s cubic-bezier(.2, .9, .3, 1);
}

.model-current.model-changing .tiny-logo {
  animation: selected-logo-pop .32s cubic-bezier(.2, .9, .3, 1);
}

.model-current.model-changing #selectedModelName {
  animation: selected-name-fade .28s ease;
}

@keyframes model-selected {
  45% { transform: scale(.975); background: color-mix(in srgb, #4f8d48 18%, var(--panel-soft)); }
}

@keyframes selection-check {
  from { opacity: 0; transform: scale(.45) rotate(-18deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}

@keyframes selected-logo-pop {
  45% { transform: scale(.82); }
}

@keyframes selected-name-fade {
  from { opacity: .2; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}

.profile-full {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 22px;
  text-align: center;
}

.profile-sheet {
  max-height: calc(100dvh - 12px - env(safe-area-inset-top));
}

.profile-full > .avatar {
  width: 76px;
  height: 76px;
  margin: 0 auto;
  font-size: 28px;
}

.profile-full h2 {
  margin: 12px 0 3px;
  font-size: 21px;
}

.profile-full > p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.profile-data {
  display: grid;
  gap: 1px;
  overflow: hidden;
  margin: 23px 0;
  border: 1px solid var(--line);
  border-radius: 13px;
  text-align: left;
}

.profile-data span {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  background: var(--panel-soft);
  font-size: 13px;
}

.profile-data b {
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: right;
  font-weight: 750;
}

.profile-setting {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: -10px 0 18px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel-soft);
  text-align: left;
}

.profile-setting > span { display: grid; flex: 1; min-width: 0; gap: 4px; }
.profile-setting strong { font-size: 14px; }
.profile-setting small { color: var(--muted); font-size: 12px; line-height: 1.4; }
.setting-switch { position: relative; display: block; flex: none; width: 42px; height: 24px; padding: 3px; border: 0; border-radius: 999px; background: var(--line); transition: background .2s ease; }
.setting-switch i { display: block; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px #0003; pointer-events: none; transition: transform .2s ease; }
.setting-switch[aria-checked="true"] { background: var(--accent); }
.setting-switch[aria-checked="true"] i { transform: translateX(18px); }
.setting-switch:disabled { opacity: .6; }

.plan-picker-open {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin-bottom: 12px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel-soft);
  color: var(--text);
  text-align: left;
}

.plan-picker-open > span {
  display: grid;
  gap: 3px;
  flex: 1;
}

.plan-picker-open strong { font-size: 14px; }
.plan-picker-open small { color: var(--muted); font-size: 12px; }
.plan-picker-open > b { color: var(--muted); font-size: 25px; font-weight: 400; }

.payments-open i {
  display: grid;
  place-items: center;
  min-width: 23px;
  height: 23px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 10px;
  font-style: normal;
  font-weight: 850;
}

.plan-picker-open[hidden] { display: none; }

.tariff-sheet {
  max-height: 88dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.tariff-intro {
  margin: 0;
  padding: 13px 18px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}

.billing-period-switch {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-self: center;
  width: min(290px, calc(100% - 36px));
  margin: 14px 18px 0;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel-soft);
  isolation: isolate;
}

.billing-period-switch::before {
  content: '';
  position: absolute;
  z-index: 0;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc(50% - 3px);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 3px 10px rgba(0, 0, 0, .1);
  transition: transform .24s cubic-bezier(.2, .82, .3, 1);
}

.billing-period-switch.annual::before {
  transform: translateX(100%);
}

.billing-period-switch button {
  position: relative;
  z-index: 1;
  min-height: 34px;
  padding: 7px 12px;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  transition: color .2s ease;
}

.billing-period-switch button.active {
  color: var(--text);
}

.tariff-list {
  display: flex;
  align-items: stretch;
  flex-shrink: 0;
  gap: 12px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding: 16px max(18px, calc((100% - 340px) / 2)) 20px;
  scroll-padding-inline: max(18px, calc((100% - 340px) / 2));
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  touch-action: pan-x;
}

.tariff-list::-webkit-scrollbar { display: none; }

.tariff-card {
  position: relative;
  display: flex;
  flex: 0 0 min(82vw, 340px);
  flex-direction: column;
  min-height: 390px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel-soft);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .08);
  scroll-snap-align: center;
  transform: translateY(2px) scale(.985);
  transition: transform .25s cubic-bezier(.2, .82, .3, 1), box-shadow .25s ease, border-color .25s ease;
}

.tariff-card.focused {
  transform: translateY(-3px) scale(1);
  box-shadow: 0 14px 34px rgba(0, 0, 0, .13);
}

.tariff-card.current {
  border-color: #4f8d48;
  box-shadow: 0 0 0 1px #4f8d48, 0 10px 28px rgba(0, 0, 0, .1);
}

.tariff-card.premium {
  background: linear-gradient(125deg, var(--panel-soft) 12%, rgba(79, 141, 72, .18) 43%, var(--panel-soft) 72%);
  background-size: 220% 220%;
  animation: premium-gradient 8s ease-in-out infinite alternate;
}

@keyframes premium-gradient {
  from { background-position: 0% 50%; }
  to { background-position: 100% 50%; }
}

.tariff-badge {
  align-self: flex-start;
  min-height: 23px;
  margin-bottom: 15px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #4f8d48;
  color: #fff;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .35px;
  text-transform: uppercase;
}

.tariff-badge.empty {
  visibility: hidden;
}

.tariff-summary {
  display: grid;
  gap: 5px;
}

.tariff-summary strong {
  font-size: 24px;
  line-height: 1.1;
}

.tariff-summary span {
  color: var(--text);
  font-size: 15px;
  font-weight: 750;
}

.tariff-price {
  display: grid;
  gap: 3px;
  min-height: 47px;
}

.tariff-price span {
  font-size: 17px;
  font-weight: 800;
}

.tariff-price small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.tariff-price em {
  justify-self: start;
  padding: 3px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, #4f8d48 16%, transparent);
  color: #4f8d48;
  font-size: 10px;
  font-style: normal;
  font-weight: 800;
}

.tariff-card > p {
  min-height: 42px;
  margin: 12px 0 15px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.tariff-card ul {
  display: grid;
  gap: 10px;
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
  text-align: left;
}

.tariff-card li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  line-height: 1.4;
}

.tariff-card li > b { color: #4f8d48; }

.tariff-card > button {
  width: 100%;
  margin-top: auto;
  padding: 11px;
  border-radius: 11px;
  background: var(--text);
  color: var(--bg);
  font-weight: 750;
  flex: none;
}

.tariff-card > button:disabled {
  opacity: .48;
  cursor: not-allowed;
}

.tariff-upcoming {
  align-items: center;
  justify-content: center;
  border-style: dashed;
  text-align: center;
}

.tariff-upcoming .upcoming-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin: 8px 0 16px;
  border-radius: 18px;
  background: rgba(79, 141, 72, .15);
  color: #4f8d48;
  font-size: 28px;
}

.tariff-upcoming h3 { margin: 0; font-size: 21px; }
.tariff-upcoming > p { min-height: 0; }
.tariff-upcoming > small { color: var(--muted); font-size: 12px; }

.tariff-controls {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  gap: 15px;
  padding: 0 18px 14px;
  color: var(--muted);
  font-size: 11px;
}

.tariff-buy.loading { animation: waiting-breathe 1s ease-in-out infinite; }

.payments-sheet { max-height: 88dvh; }

.payments-intro {
  margin: 0;
  padding: 13px 18px 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.payments-list {
  display: grid;
  gap: 10px;
  overflow-y: auto;
  padding: 12px 16px max(22px, env(safe-area-inset-bottom));
}

.payments-empty {
  padding: 28px 16px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.payment-item {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--panel-soft);
}

.payment-item-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  justify-content: space-between;
}

.payment-item-head > span {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.payment-item-head strong { font-size: 14px; }
.payment-item-head small { color: var(--muted); font-size: 11px; }

.payment-status {
  flex: none;
  max-width: 48%;
  padding: 5px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, #d99b35 17%, transparent);
  color: #a56b0a;
  font-size: 9px;
  line-height: 1.25;
  text-align: center;
}

body.dark .payment-status { color: #f2bd64; }
.payment-status.status-canceled,
.payment-status.status-failed,
.payment-status.status-chargebacked { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

.payment-item > p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.4; }

.payment-actions { display: flex; gap: 8px; }
.payment-actions button {
  flex: 1;
  min-height: 38px;
  padding: 9px 10px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 800;
}
.payment-actions button.secondary { border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.payment-actions button:disabled { opacity: .5; }

.tariff-controls button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 24px;
}

.admin-reset {
  width: 100%;
  padding: 11px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 750;
}

.admin-secondary {
  margin-top: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
}

.admin-panel {
  display: grid;
  gap: 12px;
  overflow: auto;
  padding: 18px;
}

.admin-field {
  display: grid;
  gap: 7px;
  text-align: left;
}

.admin-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.admin-field input,
.admin-field select {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: 0;
  background: var(--panel-soft);
  color: var(--text);
  font: inherit;
}

.admin-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.admin-result {
  min-height: 44px;
  color: var(--muted);
  font-size: 13px;
}

.admin-user-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel-soft);
  color: var(--text);
  text-align: left;
}

.admin-user-card strong {
  display: block;
  font-size: 15px;
}

.admin-user-card small {
  display: block;
  color: var(--muted);
  line-height: 1.5;
}

.auth-lock {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 28px;
  background: var(--bg);
  text-align: center;
}

.auth-lock.hidden { display: none; }

.auth-icon {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  border-radius: 23px;
  background: var(--text);
  font-size: 29px;
}

.auth-lock h1 {
  margin: 14px 0 8px;
  font-size: 27px;
}

.auth-lock p {
  max-width: 330px;
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

@media (max-width: 430px) {
  .brand span:last-child { display: none; }
  .model-current { max-width: calc(100vw - 116px); }
  .bubble { max-width: 92%; }
}

/* Ezhik pastel redesign overrides. */
:root {
  --bg: #f4f0e9;
  --panel: #fffaf3;
  --panel-soft: #ebe5dc;
  --text: #292b2a;
  --muted: #797a75;
  --line: #ded6ca;
  --accent: #788b76;
  --accent-text: #fffaf3;
  --bubble: #e8e2d9;
  --shadow: 0 18px 48px rgba(77, 67, 56, .10);
  /* Composer geometry: these two values control the requested spacing. */
  --composer-top-padding: 15px;
  --composer-tools-lift: -9px;
}

body.dark {
  --bg: #1c2227;
  --panel: #252d32;
  --panel-soft: #303a40;
  --text: #f1ede5;
  --muted: #aeb4ad;
  --line: #3b474c;
  --accent: #a7b9a1;
  --accent-text: #1d2525;
  --bubble: #2c363b;
  --shadow: 0 18px 48px rgba(5, 10, 12, .28);
}

body { font-family: "Plus Jakarta Sans", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
[hidden] { display: none !important; }

.ui-icon { display: block; width: 20px; height: 20px; flex: 0 0 auto; }
.ui-icon-small { width: 15px; height: 15px; }
.menu-button .ui-icon { width: 24px; height: 24px; }
.menu-button svg line { stroke: currentColor; }

.brand { gap: 7px; }
.brand-logo {
  display: block;
  width: 48px;
  height: 42px;
  object-fit: contain;
  object-position: center;
}
.brand b { color: var(--text); font-size: 19px; }

.welcome-logo {
  width: 126px;
  height: 126px;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
}
.welcome-logo img { width: 100%; height: 100%; object-fit: contain; }

.drawer-brand-logo {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  overflow: visible;
  border-radius: 0;
  background: transparent;
}
.drawer-brand-logo img { width: 100%; height: 100%; object-fit: contain; }
body.dark .brand-logo,
body.dark .welcome-logo img,
body.dark .drawer-brand-logo img { filter: invert(92%) sepia(8%) saturate(160%) hue-rotate(345deg); }

.drawer-head .plain-button,
.sheet-head .plain-button,
.sheet-head .back { display: grid; place-items: center; }
.sheet-head .back[hidden] { display: none !important; }
.new-chat { display: flex; align-items: center; justify-content: center; gap: 7px; background: var(--accent); color: var(--accent-text); }

.composer { padding-top: var(--composer-top-padding); }
.composer-tools {
  position: relative;
  z-index: 1;
  transform: translateY(var(--composer-tools-lift));
  margin-bottom: -5px;
}
.reasoning-current .ui-icon,
.web-search-toggle .ui-icon { width: 16px; height: 16px; }
.web-search-toggle[aria-pressed="true"] { background: #7898ba; color: #fff; }

.image-upload { border: 1px solid color-mix(in srgb, var(--line) 84%, transparent); }
.image-upload svg { fill: none; }
.send { display: grid; place-items: center; background: var(--accent); color: var(--accent-text); }
.send .ui-icon { width: 21px; height: 21px; }

.message-wrap.user .bubble { background: #81917d; color: #fffdf8; }
body.dark .message-wrap.user .bubble { background: #72836f; color: #fff; }

.theme-toggle > span:first-child,
.support-link > span:first-child,
.documents-button > span:first-child { display: grid; place-items: center; }
.menu-action-icon { width: 24px; height: 24px; color: var(--muted); }
.menu-action-icon svg { display: block; width: 22px; height: 22px; }

.profile-heading { display: grid; justify-items: center; }
.profile-heading .avatar { width: 76px; height: 76px; font-size: 28px; }
.profile-heading h2 { margin: 12px 0 3px; }
.profile-heading p { margin: 0; color: var(--muted); font-size: 13px; }

.tariff-controls { justify-content: center; gap: 11px; padding-inline: 22px; }
.tariff-controls button { display: grid; place-items: center; border-radius: 12px; }
.tariff-pagination { display: flex; align-items: center; justify-content: center; gap: 6px; min-width: 72px; }
.tariff-dot {
  width: 7px;
  height: 7px;
  padding: 0;
  border: 0;
  border-radius: 99px;
  background: color-mix(in srgb, var(--muted) 42%, transparent);
  transition: width .2s ease, background .2s ease, transform .2s ease;
}
.tariff-dot.active { width: 19px; background: var(--accent); }
.tariff-dot:active { transform: scale(.9); }
.tariff-card.current { border-color: color-mix(in srgb, var(--accent) 62%, var(--line)); }
.tariff-card.premium {
  background: linear-gradient(125deg, var(--panel-soft) 12%, color-mix(in srgb, var(--accent) 18%, transparent) 43%, var(--panel-soft) 72%);
  background-size: 220% 220%;
}

.theme-icon-switch {
  animation: theme-icon-switch .34s cubic-bezier(.2, .86, .3, 1);
}

@keyframes theme-icon-switch {
  from { opacity: .25; transform: rotate(-35deg) scale(.72); }
  to { opacity: 1; transform: rotate(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    transition-delay: 0s !important;
  }

  .app-shell,
  body.sheet-open .app-shell,
  .tariff-card,
  .tariff-card.focused {
    transform: none;
    filter: none;
  }
}

@media (max-width: 430px) {
  .brand-logo { width: 43px; }
  .brand b { font-size: 18px; }
}

.auth-brand {
  position: absolute;
  top: max(22px, env(safe-area-inset-top));
  left: 28px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
}

.auth-brand img {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

body.dark .auth-brand img { filter: invert(92%) sepia(8%) saturate(160%) hue-rotate(345deg); }

.telegram-login-button,
.auth-retry {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 250px;
  margin-top: 20px;
  padding: 13px 18px;
  border-radius: 13px;
  background: var(--accent);
  color: var(--accent-text);
  text-decoration: none;
  font-weight: 700;
}

.auth-retry {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
}

.web-sessions-intro {
  margin: 0;
  padding: 15px 20px 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.web-sessions-list {
  display: grid;
  gap: 10px;
  overflow-y: auto;
  padding: 8px 16px 14px;
}

.web-session-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-soft);
}

.web-session-item > div {
  display: grid;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.web-session-item strong { font-size: 14px; }
.web-session-item small { color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }

.web-session-item button {
  flex: none;
  padding: 8px 10px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--danger) 14%, var(--panel));
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
}

.web-sessions-empty {
  padding: 26px 12px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.danger-action {
  margin: 0 16px 18px;
  padding: 12px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--danger) 14%, var(--panel));
  color: var(--danger);
  font-weight: 700;
}

@media (min-width: 980px) {
  body.web-mode {
    --desktop-sidebar-width: 286px;
    --desktop-chat-width: 820px;
    background: var(--bg);
  }

  body.web-mode .drawer {
    inset: 0 auto 0 0;
    width: var(--desktop-sidebar-width);
    height: 100vh;
    height: 100dvh;
    padding: 14px 12px 12px;
    border-right: 1px solid color-mix(in srgb, var(--line) 82%, transparent);
    border-radius: 0;
    box-shadow: none;
    transform: none;
  }

  body.web-mode .drawer > .drawer-head,
  body.web-mode .drawer > .new-chat,
  body.web-mode .drawer > .history-title,
  body.web-mode .drawer > .history-list,
  body.web-mode .drawer > .drawer-bottom {
    opacity: 1;
    transform: none;
  }

  body.web-mode .drawer-head #closeButton,
  body.web-mode .menu-button,
  body.web-mode > .backdrop {
    display: none;
  }

  body.web-mode .app-shell {
    width: calc(100vw - var(--desktop-sidebar-width));
    max-width: none;
    margin: 0 0 0 var(--desktop-sidebar-width);
    border: 0;
    background: var(--bg);
  }

  body.web-mode .topbar {
    height: 60px;
    padding: 0 clamp(24px, 3vw, 48px);
    border-bottom-color: transparent;
    background: color-mix(in srgb, var(--bg) 91%, transparent);
  }

  body.web-mode .brand { display: none; }
  body.web-mode .model-current { margin-left: 0; }

  body.web-mode .chat {
    width: 100%;
    padding: 34px clamp(24px, 5vw, 88px) 28px;
    scroll-padding-bottom: 120px;
  }

  body.web-mode .welcome {
    width: min(100%, var(--desktop-chat-width));
  }

  body.web-mode .message-wrap {
    align-self: center;
    width: min(100%, var(--desktop-chat-width));
    max-width: var(--desktop-chat-width);
  }

  body.web-mode .message-wrap.assistant {
    align-items: stretch;
  }

  body.web-mode .message-wrap.assistant .bubble {
    width: 100%;
    max-width: 100%;
    padding: 8px 0;
    border-radius: 0;
    background: transparent;
  }

  body.web-mode .message-wrap.user .bubble {
    width: fit-content;
    max-width: min(72%, 620px);
  }

  body.web-mode .message-wrap.assistant .message-footer {
    padding-inline: 0;
  }

  body.web-mode .context-compression-status {
    max-width: var(--desktop-chat-width);
  }

  body.web-mode .composer {
    width: min(calc(100% - 48px), var(--desktop-chat-width));
    margin: 0 auto 18px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: 0 7px 26px rgba(40, 34, 27, .07);
  }

  body.web-mode .composer-tools {
    min-height: 28px;
    margin-bottom: 4px;
    padding: 0 2px;
    transform: none;
  }

  body.web-mode .input-row {
    min-height: 39px;
    align-items: center;
  }

  body.web-mode .input-row textarea {
    min-height: 35px;
    padding-block: 7px;
  }

  body.web-mode .drawer-head {
    padding: 2px 4px 14px;
  }

  body.web-mode .new-chat {
    padding-block: 10px;
  }

  body.web-mode .history-title {
    padding-top: 22px;
  }

  body.web-mode .history-item {
    min-height: 44px;
    max-height: 62px;
  }

  body.web-mode .file-drop-overlay {
    left: calc(var(--desktop-sidebar-width) + 12px);
    right: 12px;
  }

  body.web-mode .sheet {
    right: 0;
    bottom: 50%;
    left: var(--desktop-sidebar-width);
    width: min(560px, calc(100vw - var(--desktop-sidebar-width) - 48px));
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: var(--shadow);
    transform: translateY(calc(50vh + 110%)) scale(.985);
  }

  body.web-mode .sheet.show { transform: translateY(50%) scale(1); }

  body.web-mode.desktop-picker-open .app-shell {
    filter: none;
    transform: none;
  }

  body.web-mode.desktop-reasoning-picker-open .composer {
    position: relative;
    z-index: 8;
  }

  body.web-mode.desktop-picker-open .sheet-backdrop.show {
    background: transparent;
    backdrop-filter: none;
  }

  body.web-mode #modelSheet.desktop-dropdown {
    top: var(--picker-top, 68px);
    right: auto;
    bottom: auto;
    left: var(--picker-left, calc(var(--desktop-sidebar-width) + 24px));
    width: min(var(--picker-width, 430px), calc(100vw - 24px));
    max-width: none;
    max-height: min(72dvh, 620px);
    margin: 0;
    border-radius: 16px;
    opacity: 0;
    transform: translateY(-7px) scale(.985);
    transform-origin: top left;
    box-shadow: 0 14px 38px rgba(35, 30, 25, .16);
    transition: opacity .14s ease, transform .18s cubic-bezier(.2, .82, .3, 1);
  }

  body.web-mode #modelSheet.desktop-dropdown.show {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  body.web-mode #modelSheet.desktop-dropdown.model-dropdown {
    transform: translateY(-10px) scale(.985);
    transform-origin: top left;
  }

  body.web-mode #modelSheet.desktop-dropdown.reasoning-dropdown {
    transform: translateY(12px) scale(.985);
    transform-origin: bottom left;
  }

  body.web-mode #modelSheet.desktop-dropdown.model-dropdown.show,
  body.web-mode #modelSheet.desktop-dropdown.reasoning-dropdown.show {
    transform: translateY(0) scale(1);
  }

  body.web-mode #modelSheet.desktop-dropdown.dropdown-closing {
    pointer-events: none;
  }

  body.web-mode #modelSheet.desktop-dropdown .sheet-head {
    padding: 12px 14px;
  }

  body.web-mode #modelSheet.desktop-dropdown .model-list {
    padding: 7px 9px 11px;
  }

  body.web-mode #modelSheet.desktop-dropdown .company-row,
  body.web-mode #modelSheet.desktop-dropdown .model-row {
    padding: 10px 8px;
  }
}
