:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  --canvas: #12131a;
  --rail: #181922;
  --panel: #1b1c27;
  --panel-hover: #232433;
  --text: #f2f1f8;
  --muted: #a5a6ba;
  --quiet: #86899f;
  --line: #2d2e3d;
  --accent: #b8adff;
  --accent-ink: #1d153f;
  --blue: #8ca6ff;
  --mint: #a1ddcd;
  --thread-width: 766px;
  --rail-width: 272px;
  --safe-top: max(env(safe-area-inset-top), var(--tg-content-safe-area-inset-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom), var(--tg-content-safe-area-inset-bottom, 0px));
  background: var(--canvas);
  color: var(--text);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; overflow: hidden; }
button, textarea, input, select { font: inherit; }
button { cursor: pointer; color: inherit; }
button:disabled { cursor: default; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
input, textarea, select { min-width: 0; }
a { color: var(--accent); text-underline-offset: 3px; }
::selection { background: #53458f; color: #fff; }
svg { display: block; width: 20px; height: 20px; flex: none; }

.workspace {
  height: 100vh;
  height: var(--app-height, 100dvh);
  display: grid;
  grid-template-columns: var(--rail-width) minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  display: flex;
  min-height: 0;
  flex-direction: column;
  background: var(--rail);
  border-right: 1px solid var(--line);
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
}

.brand {
  display: flex;
  min-height: 51px;
  align-items: center;
  gap: 11px;
  padding: 0 5px;
  font-size: 19px;
  letter-spacing: -.55px;
  font-weight: 650;
}

.brand strong { color: var(--muted); font-weight: 500; }
.brand-mark, .message-mark {
  display: grid;
  flex: none;
  place-items: center;
  width: 35px;
  height: 35px;
  border: 1px solid #5b4f88;
  border-radius: 12px;
  color: #d9ccff;
  background: linear-gradient(145deg, #3e335e, #272743 70%);
  box-shadow: inset 0 1px #d8bcff16;
}

.brand-mark span, .message-mark span, .welcome-mark i {
  display: block;
  width: 17px;
  height: 17px;
  background: linear-gradient(135deg, #eee6ff 18%, #b0a7ff 60%, #83a6ff);
  clip-path: polygon(50% 0, 62% 37%, 100% 50%, 62% 63%, 50% 100%, 38% 63%, 0 50%, 38% 37%);
}

.new-chat, .sidebar-action, .profile-button, .history-chat {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 11px;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 12px;
}

.new-chat {
  margin: 17px 0 24px;
  padding: 12px 11px;
  border: 1px solid #484362;
  color: #dfd8ff;
  background: #27243b;
  font-weight: 650;
  font-size: 14px;
  min-height: 46px;
}

.new-chat:hover { background: #342d4d; }
.new-chat-shortcut {
  color: #bab2d3;
  background: #ffffff09;
  border: 1px solid #ffffff12;
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 12px;
  margin-left: auto;
}

.history { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.history-title { color: var(--quiet); font-size: 12px; font-weight: 650; padding: 1px 9px 9px; }
.history-list { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.history-chat {
  min-height: 42px;
  padding: 9px;
  color: var(--muted);
  white-space: nowrap;
  font-size: 14px;
}
.history-chat > span:last-child { overflow: hidden; text-overflow: ellipsis; }
.history-chat svg, .sidebar-action svg { width: 17px; height: 17px; }
.history-chat:hover, .sidebar-action:hover { background: var(--panel-hover); }
.history-chat[aria-current="page"] { color: var(--text); background: #29263b; }
.history-empty { margin: 0; padding: 9px; color: var(--quiet); font-size: 14px; }

.sidebar-footer { display: grid; gap: 3px; padding-top: 12px; }
.sidebar-action { color: var(--muted); font-size: 14px; padding: 11px 10px; }
.profile-button { margin-top: 9px; border: 1px solid var(--line); padding: 9px; min-height: 57px; }
.profile-button:hover { background: var(--panel-hover); }
.profile-button-text { flex: 1; overflow: hidden; }
.profile-button-text strong, .profile-button-text small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-button-text strong { font-size: 14px; font-weight: 650; }
.profile-button-text small { color: var(--quiet); margin-top: 3px; font-size: 12px; }
.profile-button > span:last-child { color: var(--quiet); }
.avatar {
  display: grid;
  flex: none;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 12px;
  color: #e0d8ff;
  background: #373050;
  border: 1px solid #5a4d78;
  font-size: 13px;
  font-weight: 700;
}

.main {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
  position: relative;
  background: radial-gradient(ellipse at 50% 29%, #201d31 0, #12131a 48%);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(12px + var(--safe-top)) 28px 12px;
  background: #14151dd6;
  border-bottom: 1px solid #292a37;
  min-height: 66px;
  z-index: 1;
}

.topbar-start, .topbar-actions { display: flex; align-items: center; min-width: 0; gap: 8px; }
.topbar-title { font-size: 16px; font-weight: 650; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-profile { display: none !important; }
.preview-tag { font-size: 12px; color: var(--muted); padding: 4px 9px; border: 1px solid var(--line); border-radius: 20px; }

.icon-button, .send-button {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 11px;
  color: var(--muted);
  background: transparent;
  transition: background .16s ease, color .16s ease, transform .16s ease;
}
.icon-button:hover { color: var(--text); background: #ffffff0c; }
.icon-button:active, .send-button:active, .suggestion:active, .primary-button:active { transform: scale(.96); }
.mobile-only { display: none; }

.transcript { min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable both-edges; }
.transcript:focus { outline: none; }
.welcome {
  min-height: 100%;
  max-width: calc(var(--thread-width) + 32px);
  margin: 0 auto;
  padding: 30px 20px 34px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.welcome-mark {
  position: relative;
  isolation: isolate;
  display: grid;
  width: 98px;
  height: 98px;
  margin-bottom: 22px;
  place-items: center;
  border-radius: 30px;
  border: 1px solid #7261a68a;
  background: radial-gradient(circle at 30% 8%, #8870c557, transparent 57%),
              linear-gradient(145deg, #3c315e, #24243d 76%);
  box-shadow: 0 12px 44px #8270ff26, inset 0 1px #e2ccff27;
}
.welcome-mark span:first-child, .welcome-mark span:nth-child(2) {
  width: 72px;
  height: 36px;
  position: absolute;
  border: 1px solid #b09af575;
  border-radius: 50%;
  transform: rotate(-42deg);
}
.welcome-mark span:nth-child(2) { transform: rotate(42deg); border-color: #8a9deb57; }
.welcome-mark i { width: 43px; height: 43px; filter: drop-shadow(0 0 8px #d4c5ff); }
.welcome-mark::after {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  position: absolute;
  background: var(--mint);
  box-shadow: 0 0 9px #a1ddcd8c;
  transform: translate(25px, -21px);
  animation: glimmer 4s ease-in-out infinite;
}
.welcome h1 { margin: 0; font-size: clamp(32px, 5vw, 53px); line-height: 1.04; font-weight: 680; letter-spacing: -.055em; }
.welcome p { margin: 13px 0 0; color: var(--muted); line-height: 1.55; font-size: 16px; }
.gate .primary-button { margin-top: 17px; }
.gate:not([hidden]) ~ .messages { display: none; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 586px; width: 100%; margin-top: 29px; }
.suggestion {
  display: flex;
  align-items: center;
  text-align: left;
  gap: 10px;
  min-width: 0;
  min-height: 68px;
  padding: 11px;
  background: #1c1d28e8;
  border: 1px solid #323345;
  border-radius: 14px;
  transition: background .17s ease, border-color .17s ease, transform .17s ease;
}
.suggestion:hover { background: #282639; border-color: #655784; transform: translateY(-2px); }
.suggestion-icon { display: grid; place-items: center; flex: none; width: 38px; height: 38px; border-radius: 10px; background: #333451; color: #c1bbff; }
.suggestion-icon.secondary { color: #a6dcd1; background: #223b3d; }
.suggestion strong, .suggestion small { display: block; }
.suggestion strong { font-size: 14px; font-weight: 650; }
.suggestion small { font-size: 12px; color: var(--muted); margin-top: 4px; }
.suggestion-chevron { margin-left: auto; color: var(--quiet); }
.suggestion-chevron svg { width: 16px; height: 16px; }

.messages { width: min(var(--thread-width), 100%); margin: 0 auto; padding: 29px 23px 13px; display: grid; gap: 25px; }
.message { min-width: 0; animation: enter .21s ease both; }
.message.user { justify-self: end; max-width: min(91%, 570px); }
.message.assistant { padding-bottom: 9px; }
.bubble { background: #29253d; border: 1px solid #403655; border-radius: 17px 17px 5px 17px; padding: 12px 16px; white-space: pre-wrap; font-size: 16px; line-height: 1.56; overflow-wrap: anywhere; }
.assistant-heading { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; color: #cfcae9; font-size: 13px; font-weight: 650; }
.message-mark { width: 28px; height: 28px; border-radius: 9px; }
.message-mark span { width: 13px; height: 13px; }
.message-meta { color: var(--quiet); font-weight: 500; font-size: 12px; margin-left: auto; }
.markdown { font-size: 16px; line-height: 1.64; overflow-wrap: anywhere; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: .62em 0; white-space: pre-wrap; }
.markdown h2, .markdown h3, .markdown h4 { line-height: 1.3; margin: .88em 0 .33em; }
.markdown ul, .markdown ol { margin: .65em 0; padding-left: 26px; }
.markdown li + li { margin-top: 3px; }
.markdown blockquote { margin: .65em 0; border-left: 2px solid #625b85; padding: 3px 12px; color: var(--muted); }
.markdown :not(pre) > code { padding: 2px 5px; border-radius: 5px; background: #252538; color: #d9d1ff; font-size: .88em; }
.code-block { margin: 12px 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #101118; }
.code-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 3px 9px 3px 12px; background: #1e1e2a; font-size: 12px; color: var(--muted); }
.code-header .icon-button, .message-controls .icon-button { width: 33px; height: 33px; }
.code-header svg, .message-controls svg { width: 17px; height: 17px; }
pre { margin: 0; overflow: auto; padding: 12px; font-size: 13px; line-height: 1.55; tab-size: 4; color: #e1dcf0; }
.table-wrap { overflow-x: auto; }
.markdown table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 14px; }
.markdown td, .markdown th { border: 1px solid var(--line); text-align: left; padding: 7px 10px; }
.markdown th { background: #222333; }
.message-controls { display: flex; gap: 3px; margin-top: 7px; }
.turn-state { color: var(--muted); line-height: 1.5; font-size: 14px; margin: 8px 0 0; }
.turn-state.error { color: #f6b3c3; }
.thinking { display: inline-flex; color: var(--muted); gap: 11px; align-items: center; }
.thinking-dots { display: inline-flex; gap: 4px; align-items: center; height: 18px; }
.thinking-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); animation: glimmer 1.2s infinite; }
.thinking-dots i:nth-child(2) { animation-delay: .14s; }
.thinking-dots i:nth-child(3) { animation-delay: .28s; }
.message-files { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 6px; margin-bottom: 7px; }
.message-context { display: flex; justify-content: flex-end; align-items: center; gap: 5px; color: var(--quiet); font-size: 12px; margin: 6px 0; overflow-wrap: anywhere; }
.message-context svg { width: 14px; height: 14px; }

.chat-footer {
  width: min(var(--thread-width), 100%);
  margin: 0 auto;
  padding: 7px 20px calc(15px + var(--safe-bottom));
  min-width: 0;
}
.composer {
  background: #1d1e29;
  border: 1px solid #3b3b51;
  box-shadow: 0 8px 30px #08080e3d, inset 0 1px #eff0ff08;
  border-radius: 19px;
  padding: 9px;
  display: grid;
  gap: 4px;
  transition: border-color .2s ease;
}
.composer:focus-within { border-color: #736394; }
.composer textarea {
  display: block;
  width: 100%;
  background: transparent;
  border: 0;
  outline: none;
  resize: none;
  min-height: 39px;
  max-height: 152px;
  padding: 8px 8px 4px;
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
}
.composer textarea::placeholder { color: #9b9bb1; }
.composer-tools { display: flex; width: 100%; align-items: center; gap: 3px; min-width: 0; }
.composer-spacer { flex: 1; }
.attach-button { width: 39px; height: 39px; }
.model-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #cec5ff;
  padding: 0 9px;
  height: 38px;
  min-width: 0;
  border-radius: 10px;
  border: 1px solid #47415e;
  background: #2b283d;
  font-size: 13px;
  margin-right: 3px;
}
.model-picker:hover { background: #35304a; }
.model-picker svg { width: 15px; height: 15px; }
.model-picker span:nth-child(2) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.send-button { background: var(--accent); color: var(--accent-ink); width: 40px; height: 39px; }
.send-button:hover { background: #d1c7ff; }
.send-button:disabled { background: #332f48; color: #8b82aa; }
.send-button.stopping { color: #ffd5e0; background: #5b344d; }
.composer-hint { color: var(--quiet); font-size: 12px; text-align: center; min-height: 15px; margin-top: 7px; }
.composer-hint:empty { display: none; }
.attachments { display: flex; gap: 6px; flex-wrap: wrap; padding: 3px 2px; }
.file-chip, .repo-summary {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  color: #ddd8f0;
  background: #29283b;
  border: 1px solid #414059;
  padding: 4px 8px;
  border-radius: 9px;
  min-height: 32px;
  max-width: 100%;
  font-size: 13px;
  line-height: 1.3;
}
.file-chip > span.phone-ellipsis, .repo-summary > span.phone-ellipsis { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.file-chip:hover:is(button) { border-color: var(--accent); }
.file-chip svg, .repo-summary svg { width: 15px; height: 15px; }
.file-chip small { flex: none; color: var(--quiet); font-size: 11px; }
.file-chip .icon-button, .repo-summary .icon-button { width: 23px; height: 23px; border-radius: 5px; }
.repo-summary { margin-bottom: 7px; }
.repo-link { display: flex; align-items: center; gap: 6px; padding: 0; min-width: 0; border: 0; background: none; }
.repo-branch, .repo-count { font-size: 12px; color: var(--muted); text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
.context-label { text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }

.sheet {
  width: min(500px, calc(100vw - 28px));
  max-height: min(85dvh, 740px);
  padding: 0;
  border: 1px solid #3f3e53;
  border-radius: 20px;
  background: #1b1c27;
  color: var(--text);
  box-shadow: 0 24px 95px #0009;
}
.sheet[open] { display: flex; flex-direction: column; animation: sheet-in .22s cubic-bezier(.2,.7,.25,1) both; }
.sheet::backdrop { background: #080912b0; backdrop-filter: blur(3px); }
.sheet-handle { display: none; }
.sheet-header { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 8px; padding: 13px 17px 9px; border-bottom: 1px solid var(--line); }
.sheet-header h2 { margin: 0; font-size: 20px; line-height: 1.3; letter-spacing: -.02em; }
.sheet-body { min-height: 0; overflow-y: auto; padding: 12px 17px 17px; overscroll-behavior: contain; }
.sheet-note { margin: 3px 0 12px; color: var(--muted); font-size: 14px; line-height: 1.55; overflow-wrap: anywhere; }
.sheet-note.error { color: #f6b3c3; }
.option, .primary-button, .secondary-button {
  min-height: 43px;
  border: 1px solid var(--line);
  border-radius: 11px;
  text-align: left;
  background: #232431;
  padding: 9px 11px;
  transition: background .17s ease, border-color .17s ease, transform .17s ease;
}
.option { display: flex; align-items: center; gap: 9px; justify-content: space-between; width: 100%; margin: 5px 0; overflow-wrap: anywhere; }
.option strong { display: block; font-size: 14px; font-weight: 650; }
.option small { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; }
.option svg { color: var(--accent); width: 17px; height: 17px; }
.option:hover, .secondary-button:hover { background: #2e2d41; border-color: #51496b; }
.option[aria-pressed="true"] { border-color: #6f609c; background: #302843; }
.primary-button { color: var(--accent-ink); background: var(--accent); border-color: transparent; text-align: center; font-weight: 650; }
.primary-button:hover { background: #d3c9ff; }
.primary-button:disabled, .secondary-button:disabled { opacity: .52; }
.danger { color: #ffc0cc; }
.sheet-actions { display: flex; gap: 7px; justify-content: flex-end; padding-top: 11px; flex-wrap: wrap; }
.sheet-actions .primary-button, .sheet-actions .secondary-button { flex: 0 1 auto; }
.field { display: grid; gap: 5px; margin: 0 0 10px; font-size: 14px; color: var(--muted); }
.field :is(input,select,textarea) {
  width: 100%;
  min-height: 43px;
  background: #11121b;
  border: 1px solid #39394d;
  border-radius: 9px;
  color: var(--text);
  padding: 8px 9px;
  font-size: 16px;
}
.field textarea { resize: vertical; min-height: 130px; font: 13px/1.5 monospace; }
.repo-files { max-height: 235px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.repo-file { display: flex; align-items: center; gap: 9px; padding: 8px 7px; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; cursor: pointer; }
.repo-file + .repo-file { border-top: 1px solid var(--line); }
.repo-file:hover { background: var(--panel-hover); }
.repo-file > label { display: flex; align-items: center; gap: 7px; min-width: 0; flex: 1; cursor: pointer; }
.repo-file input { accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.repo-file .icon-button { margin-left: auto; width: 29px; height: 29px; }
.repo-file .icon-button svg { width: 16px; height: 16px; }
.repo-file span { min-width: 0; }
.usage-card { border: 1px solid var(--line); border-radius: 13px; padding: 12px; margin: 7px 0; }
.usage-card > strong { display: block; font-size: 15px; margin-bottom: 8px; }
.usage-grid { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; font-size: 14px; }
.usage-grid dt { color: var(--muted); }
.usage-grid dd { margin: 0; font-variant-numeric: tabular-nums; }
.preview-code { display: block; max-height: 340px; background: #11121b; border: 1px solid var(--line); border-radius: 10px; }
.toast {
  position: fixed;
  z-index: 5;
  bottom: calc(18px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 30px);
  border: 1px solid #554968;
  border-radius: 12px;
  background: #272439;
  color: #f2edff;
  font-size: 14px;
  padding: 9px 13px;
  box-shadow: 0 6px 25px #03030869;
}

@keyframes glimmer { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
@keyframes sheet-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes enter { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 780px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    z-index: 4;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(310px, 86vw);
    visibility: hidden;
    transform: translateX(-102%);
    transition: transform .22s ease, visibility .22s;
    box-shadow: 12px 0 48px #0005;
  }
  .sidebar.open { visibility: visible; transform: translateX(0); }
  .sidebar .brand button { margin-left: auto; }
  .sidebar-backdrop { z-index: 3; position: fixed; inset: 0; border: 0; background: #07071099; }
  .mobile-only { display: grid; }
  .topbar-profile { display: grid !important; }
  .new-chat-shortcut { display: none; }
  .topbar { gap: 8px; min-height: 57px; padding: calc(6px + var(--safe-top)) 12px 6px; }
  .topbar-start, .topbar-actions { gap: 3px; }
  .topbar-actions .icon-button { width: 37px; }
  .chat-footer { padding: 6px 12px calc(10px + var(--safe-bottom)); }
  .messages { padding: 20px 14px 10px; gap: 19px; }
  .transcript { scrollbar-gutter: auto; }
}

@media (max-width: 550px) {
  .welcome { padding: 20px 16px 25px; }
  .welcome-mark { width: 81px; height: 81px; border-radius: 23px; margin-bottom: 18px; }
  .welcome-mark span:first-child, .welcome-mark span:nth-child(2) { width: 62px; height: 30px; }
  .welcome-mark i { width: 36px; height: 36px; }
  .welcome h1 { font-size: 38px; }
  .welcome p { font-size: 15px; margin-top: 9px; }
  .suggestions { grid-template-columns: 1fr; width: min(100%, 365px); margin-top: 22px; gap: 7px; }
  .suggestion { min-height: 58px; padding: 8px 10px; }
  .suggestion-icon { width: 34px; height: 34px; }
  .suggestion-icon svg { width: 17px; height: 17px; }
  .sheet { margin: auto 0 0; width: 100%; max-width: 100%; border-radius: 20px 20px 0 0; border-bottom: 0; }
  .sheet-handle { display: block; flex: none; align-self: center; width: 32px; height: 4px; border-radius: 4px; background: #676378; margin-top: 7px; }
  .sheet-body { padding-bottom: calc(15px + var(--safe-bottom)); }
  .sheet-header { padding-top: 5px; }
  .bubble { padding: 9px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; transition-duration: .001s !important; scroll-behavior: auto !important; }
}
