:root {
  color-scheme: light;
  --canvas: #f4f4f5;
  --shell: #ffffff;
  --rail-bg: #fafafa;
  --side-bg: #ffffff;
  --chat-bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --ink: #18181b;
  --ink-soft: #52525b;
  --ink-faint: #a1a1aa;
  --line: #e8e8ea;
  --line-strong: #d4d4d8;
  --accent: #18181b;
  --accent-strong: #52525b;
  --accent-soft: rgba(24, 24, 27, 0.05);
  --accent-ink: #fafafa;
  --active-bg: rgba(24, 24, 27, 0.06);
  --ring: rgba(24, 24, 27, 0.12);
  --bubble-self-bg: #18181b;
  --bubble-self-ink: #fafafa;
  --bubble-self-meta: rgba(250, 250, 250, 0.62);
  --bubble-other-bg: #ffffff;
  --bubble-other-ink: #18181b;
  --shadow-sm: 0 1px 2px rgba(24, 24, 27, 0.05);
  --shadow-md: 0 6px 18px rgba(24, 24, 27, 0.07);
  --shadow-lg: 0 24px 70px rgba(24, 24, 27, 0.12);
  --serif: "Iowan Old Style", "Palatino Linotype", "Songti SC", Georgia, serif;
  --sans: "Inter", "Segoe UI", "Microsoft YaHei UI", system-ui, -apple-system, sans-serif;
  --mono: "SF Mono", "Cascadia Code", Consolas, "Courier New", monospace;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #09090b;
  --shell: #161618;
  --rail-bg: #121214;
  --side-bg: #161618;
  --chat-bg: #121214;
  --surface: #1d1d20;
  --surface-2: #242428;
  --ink: #ededed;
  --ink-soft: #a1a1aa;
  --ink-faint: #71717a;
  --line: #2a2a2e;
  --line-strong: #3f3f46;
  --accent: #ededed;
  --accent-strong: #a1a1aa;
  --accent-soft: rgba(237, 237, 237, 0.07);
  --accent-ink: #161618;
  --active-bg: rgba(255, 255, 255, 0.08);
  --ring: rgba(237, 237, 237, 0.16);
  --bubble-self-bg: #ededed;
  --bubble-self-ink: #161618;
  --bubble-self-meta: rgba(22, 22, 24, 0.55);
  --bubble-other-bg: #242428;
  --bubble-other-ink: #ededed;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 28px 80px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--canvas);
  overflow: hidden;
  transition: background 200ms ease, color 200ms ease;
}

/* Soft ambient wash behind the shell. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(60% 50% at 12% 0%, var(--accent-soft), transparent 70%),
    radial-gradient(50% 45% at 95% 100%, var(--accent-soft), transparent 70%);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2 {
  letter-spacing: 0;
}

/* ---------- shell ---------- */

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 68px minmax(264px, 320px) minmax(0, 1fr);
  width: min(1500px, calc(100vw - 32px));
  height: calc(100vh - 32px);
  margin: 16px auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: var(--shell);
  box-shadow: var(--shadow-lg);
  transition: grid-template-columns 200ms ease;
}

.app-shell[data-rail="expanded"] {
  grid-template-columns: 200px minmax(264px, 320px) minmax(0, 1fr);
}

/* ---------- rail ---------- */

.rail {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 14px 12px;
  border-right: 1px solid var(--line);
  background: var(--rail-bg);
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}

.rail-btn,
.rail-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  transition: background 140ms ease, color 140ms ease;
}

.rail-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: none;
}

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

.rail-label {
  font-size: 14px;
  font-weight: 600;
}

.rail-btn:hover,
.rail-item:hover {
  color: var(--ink);
  background: var(--active-bg);
}

.app-shell[data-section="user"] .rail-item[data-section="user"],
.app-shell[data-section="group"] .rail-item[data-section="group"],
.app-shell[data-section="chat"] .rail-item[data-section="chat"] {
  color: var(--accent);
  background: var(--active-bg);
}

.app-shell[data-section="user"] .rail-item[data-section="user"]::before,
.app-shell[data-section="group"] .rail-item[data-section="group"]::before,
.app-shell[data-section="chat"] .rail-item[data-section="chat"]::before {
  content: "";
  position: absolute;
  left: -4px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 22px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.app-shell[data-rail="collapsed"] .rail-label {
  display: none;
}

.app-shell[data-rail="collapsed"] .rail-btn,
.app-shell[data-rail="collapsed"] .rail-item {
  justify-content: center;
  padding: 0;
}

.rail-toggle .chev {
  transition: transform 200ms ease;
}

.app-shell[data-rail="expanded"] .rail-toggle .chev {
  transform: rotate(180deg);
}

.theme-toggle {
  margin-top: auto;
}

.theme-toggle .icon-moon {
  display: none;
}

html[data-theme="dark"] .theme-toggle .icon-sun {
  display: none;
}

html[data-theme="dark"] .theme-toggle .icon-moon {
  display: block;
}

/* ---------- side panel ---------- */

.side-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--side-bg);
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 13px;
  border-bottom: 1px solid var(--line);
}

.side-head h2 {
  font-size: 18px;
  font-weight: 700;
}

.conn {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-faint);
  transition: background 200ms ease, box-shadow 200ms ease;
}

.app-shell.connected .status-dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.side-body {
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
}

.view {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.app-shell[data-section="user"] .view[data-view="user"],
.app-shell[data-section="group"] .view[data-view="group"],
.app-shell[data-section="chat"] .view[data-view="chat"] {
  display: flex;
}

.brand {
  padding: 4px 2px 2px;
}

.brand h1 {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 700;
  line-height: 1.05;
  background: linear-gradient(120deg, var(--ink) 30%, var(--accent-strong) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.brand p {
  margin-top: 7px;
  color: var(--ink-soft);
  font-size: 13px;
}

/* ---------- panels & forms ---------- */

.panel,
.profile {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.section-title + .inline-form {
  margin-top: 8px;
}

.profile {
  display: flex;
  align-items: center;
  gap: 11px;
}

.profile-meta {
  flex: 1;
  min-width: 0;
}

.profile-meta strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-meta p {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 12px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--accent-ink);
  font-weight: 700;
  flex: none;
  box-shadow: 0 2px 8px var(--ring);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  margin-bottom: 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
}

.tab,
.small-button,
.primary-button,
.send-button,
.icon-button,
.copy-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: var(--surface);
  transition: transform 130ms ease, border-color 130ms ease, background 130ms ease, box-shadow 130ms ease, color 130ms ease, opacity 130ms ease;
}

.small-button:hover,
.primary-button:hover,
.send-button:hover,
.icon-button:hover,
.copy-button:hover {
  border-color: var(--line-strong);
  background: var(--active-bg);
}

.small-button:active,
.primary-button:active,
.send-button:active,
.icon-button:active {
  transform: scale(0.97);
}

.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-weight: 600;
}

.tab:hover {
  color: var(--ink);
}

.tab.active,
.primary-button,
.send-button {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 2px 10px var(--ring);
}

.tab.active:hover,
.primary-button:hover,
.send-button:hover {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
  opacity: 0.92;
}

.primary-button,
.send-button {
  font-weight: 700;
}

.primary-button {
  width: 100%;
  margin-top: 11px;
}

.send-button {
  padding: 0 20px;
  border-radius: 12px;
}

.small-button {
  padding: 0 13px;
  white-space: nowrap;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 17px;
  color: var(--ink-soft);
}

.icon-button:hover {
  color: var(--accent);
}

label {
  display: block;
  color: var(--ink-soft);
  font-size: 13px;
  margin-top: 9px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 11px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
  transition: border-color 130ms ease, box-shadow 130ms ease;
}

input::placeholder,
textarea::placeholder {
  color: var(--ink-faint);
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

.inline-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-form + .section-title {
  margin-top: 13px;
}

/* ---------- lists ---------- */

.conversation-list,
.mini-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 9px;
}

.conversation-item,
.mini-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px;
  color: var(--ink);
  background: transparent;
  text-align: left;
  transition: border-color 130ms ease, background 130ms ease;
}

.group-row {
  padding: 0;
}

.mini-open {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 10px;
  text-align: left;
}

.copy-button {
  min-height: 32px;
  padding: 0 10px;
  margin-right: 8px;
  font-size: 13px;
  color: var(--ink-soft);
}

.conversation-item.active {
  border-color: var(--line);
  background: var(--active-bg);
}

.conversation-item:hover,
.mini-item:hover,
.group-row:hover {
  border-color: var(--line);
  background: var(--active-bg);
}

.conversation-item small,
.mini-item small {
  display: block;
  color: var(--ink-soft);
  margin-top: 3px;
}

.conversation-item span:first-child,
.mini-item span:first-child,
.mini-open span {
  min-width: 0;
}

.conversation-item strong,
.conversation-item small,
.mini-item strong,
.mini-item small {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item > span:last-child {
  flex: none;
  display: grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border-radius: 99px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 12px;
  font-weight: 600;
}

/* ---------- chat pane ---------- */

.chat-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--chat-bg);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 76px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--side-bg);
}

.chat-header div {
  min-width: 0;
  flex: 1;
}

.chat-header h2 {
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 700;
}

.chat-header p {
  margin-top: 5px;
  color: var(--ink-soft);
  font-size: 13px;
}

.message-list {
  min-height: 0;
  overflow-y: auto;
  padding: 24px 22px;
  scroll-behavior: smooth;
}

.message-list::-webkit-scrollbar,
.side-body::-webkit-scrollbar {
  width: 8px;
}

.message-list::-webkit-scrollbar-thumb,
.side-body::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 99px;
  background: var(--line-strong);
  background-clip: padding-box;
}

.message-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin: 11px 0;
  animation: messageIn 190ms cubic-bezier(0.21, 1.02, 0.73, 1) both;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(7px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.message-row.self {
  justify-content: flex-end;
}

.message-row.system {
  justify-content: center;
}

.msg-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin-top: 2px;
  border-radius: 50%;
  color: #fafafa;
  background: var(--ink-faint);
  font-size: 14px;
  font-weight: 700;
  flex: none;
  user-select: none;
}

.msg-avatar.ai {
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid var(--line-strong);
  font-size: 12px;
  letter-spacing: 0.02em;
}

.bubble {
  max-width: min(680px, 78%);
  border: 1px solid var(--line);
  border-radius: 16px;
  border-top-left-radius: 6px;
  padding: 11px 13px;
  background: var(--bubble-other-bg);
  color: var(--bubble-other-ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
}

.self .bubble {
  background: var(--bubble-self-bg);
  color: var(--bubble-self-ink);
  border-color: transparent;
  border-radius: 16px;
  border-top-right-radius: 6px;
  box-shadow: var(--shadow-md);
}

.system .bubble {
  max-width: 90%;
  color: var(--ink-soft);
  background: var(--surface-2);
  border-color: transparent;
  border-radius: 99px;
  text-align: center;
  font-size: 13px;
  padding: 6px 14px;
  box-shadow: none;
}

.bubble-meta {
  color: var(--ink-faint);
  font-size: 12px;
  margin-bottom: 5px;
}

.self .bubble .bubble-meta {
  color: var(--bubble-self-meta);
}

.recall-button {
  display: block;
  margin-top: 7px;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
}

.self .recall-button {
  color: var(--bubble-self-meta);
}

.recall-button:hover {
  text-decoration: underline;
}

.message-text.recalled {
  color: var(--ink-soft);
  font-style: italic;
}

/* ---------- markdown (AI replies) ---------- */

.message-markdown {
  white-space: normal;
}

.message-markdown > :first-child {
  margin-top: 0;
}

.message-markdown > :last-child {
  margin-bottom: 0;
}

.message-markdown p,
.message-markdown ul,
.message-markdown ol,
.message-markdown pre,
.message-markdown blockquote,
.message-markdown table {
  margin: 8px 0;
}

.message-markdown h1,
.message-markdown h2,
.message-markdown h3,
.message-markdown h4 {
  margin: 12px 0 6px;
  font-size: 1.05em;
  line-height: 1.3;
}

.message-markdown ul,
.message-markdown ol {
  padding-left: 22px;
}

.message-markdown li {
  margin: 3px 0;
}

.message-markdown code {
  font-family: var(--mono);
  font-size: 0.88em;
  padding: 2px 5px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.message-markdown pre {
  overflow-x: auto;
  padding: 11px 13px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.message-markdown pre code {
  padding: 0;
  border: 0;
  background: transparent;
}

.message-markdown blockquote {
  padding: 2px 12px;
  border-left: 3px solid var(--accent);
  color: var(--ink-soft);
}

.message-markdown a {
  color: var(--accent-strong);
}

.message-markdown table {
  border-collapse: collapse;
  font-size: 0.92em;
}

.message-markdown th,
.message-markdown td {
  border: 1px solid var(--line);
  padding: 5px 9px;
}

/* ---------- attachments & files ---------- */

.file-message {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  color: inherit;
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  background: var(--surface-2);
  transition: border-color 130ms ease;
}

.file-message:hover {
  border-color: var(--accent);
}

.self .bubble .file-message {
  border-color: color-mix(in srgb, currentColor 30%, transparent);
  background: color-mix(in srgb, currentColor 10%, transparent);
}

.file-message strong,
.file-message small {
  display: block;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-message small {
  color: var(--ink-soft);
  font-size: 12px;
}

.self .bubble .file-message small {
  color: var(--bubble-self-meta);
}

.file-icon {
  font-size: 20px;
  color: var(--ink-soft);
}

.self .bubble .file-icon {
  color: var(--bubble-self-meta);
}

.message-text + .attachment {
  margin-top: 9px;
}

.attachment {
  margin: 0;
}

.image-attachment img {
  display: block;
  max-width: min(360px, 100%);
  max-height: 360px;
  border: 1px solid var(--line);
  border-radius: 12px;
  object-fit: contain;
  background: var(--surface-2);
}

.attachment figcaption {
  max-width: min(360px, 100%);
  margin-top: 6px;
  color: var(--ink-soft);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.self .bubble figcaption {
  color: var(--bubble-self-meta);
}

.audio-attachment audio {
  width: min(340px, 100%);
  max-width: 100%;
  display: block;
}

.hidden-file {
  display: none;
}

/* ---------- composer ---------- */

.icon-button.recording {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
  animation: recordPulse 1.4s ease infinite;
}

@keyframes recordPulse {
  0%, 100% {
    box-shadow: 0 0 0 3px var(--ring);
  }
  50% {
    box-shadow: 0 0 0 7px var(--accent-soft);
  }
}

.composer {
  display: flex;
  align-items: center;
  position: relative;
  z-index: 2;
  flex-shrink: 0;
  gap: 10px;
  padding: 13px 18px 18px;
  border-top: 1px solid var(--line);
  background: var(--side-bg);
}

.composer-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.composer-main {
  flex: 1;
  min-width: 0;
}

.composer textarea {
  resize: none;
  max-height: 128px;
  min-height: 42px;
  border-radius: 12px;
  background: var(--surface-2);
  border-color: transparent;
}

.composer textarea:focus {
  background: var(--surface);
  border-color: var(--accent);
}

.history-icon {
  position: relative;
  display: block;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.history-icon::before,
.history-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  border-radius: 99px;
  background: currentColor;
  transform-origin: 50% 0;
}

.history-icon::before {
  height: 5px;
  transform: translate(-50%, -1px);
}

.history-icon::after {
  height: 6px;
  transform: translate(-50%, -1px) rotate(90deg);
}

.image-icon {
  position: relative;
  display: block;
  width: 22px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 2px;
  overflow: hidden;
}

.image-icon::before {
  content: "";
  position: absolute;
  right: 3px;
  top: 3px;
  width: 3px;
  height: 3px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
}

.image-icon::after {
  content: "";
  position: absolute;
  left: -2px;
  bottom: -2px;
  width: 13px;
  height: 9px;
  border: 2px solid currentColor;
  border-top: 0;
  border-right: 0;
  border-radius: 0 0 0 13px;
}

.pending-attachment {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
}

.pending-preview {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.pending-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pending-preview audio {
  width: 150px;
}

.pending-meta {
  min-width: 0;
}

.pending-meta strong,
.pending-meta small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pending-meta small {
  margin-top: 3px;
  color: var(--ink-soft);
  font-size: 12px;
}

/* ---------- toast & utilities ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 40;
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 16px;
  border-radius: 99px;
  color: var(--canvas);
  background: var(--ink);
  box-shadow: var(--shadow-lg);
  transform: translateX(-50%);
  animation: toastIn 180ms cubic-bezier(0.21, 1.02, 0.73, 1) both;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.hidden {
  display: none !important;
}

.mobile-only {
  display: none;
}

/* ---------- responsive ---------- */

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

  .app-shell,
  .app-shell[data-rail="expanded"] {
    display: flex;
    grid-template-columns: none;
    width: 100vw;
    height: 100dvh;
    min-height: 100svh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .rail {
    width: calc(56px + env(safe-area-inset-left));
    flex: none;
    padding: calc(12px + env(safe-area-inset-top)) 8px 12px calc(8px + env(safe-area-inset-left));
  }

  .rail-label {
    display: none !important;
  }

  .rail-btn,
  .rail-item {
    justify-content: center;
    padding: 0;
  }

  .rail-toggle {
    display: none;
  }

  .side-panel {
    flex: 1;
    min-width: 0;
    height: 100%;
  }

  .side-head {
    padding-top: calc(16px + env(safe-area-inset-top));
  }

  .chat-pane {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: none;
  }

  body.chat-open .chat-pane {
    display: grid;
  }

  /* On phones the chat pane is a full-screen overlay that hides the rail and
     conversation list, so reveal the back button to get back to the panel. */
  .mobile-only {
    display: grid;
  }

  .brand h1 {
    font-size: 25px;
  }

  .chat-header {
    min-height: 64px;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  }

  .chat-header h2 {
    font-size: 20px;
  }

  .chat-header p {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .message-list {
    padding: 14px 12px 18px;
  }

  .msg-avatar {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .msg-avatar.ai {
    font-size: 10px;
  }

  .bubble {
    max-width: 88%;
  }

  .composer {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "tools send"
      "main main";
    align-items: center;
    gap: 8px;
    padding: 9px 10px calc(10px + env(safe-area-inset-bottom));
  }

  .composer-tools {
    grid-area: tools;
    min-width: 0;
    overflow-x: auto;
    padding-bottom: 1px;
    scrollbar-width: none;
  }

  .composer-tools::-webkit-scrollbar {
    display: none;
  }

  .composer-main {
    grid-area: main;
    width: 100%;
  }

  .send-button {
    grid-area: send;
    min-width: 64px;
    min-height: 38px;
    padding: 0 14px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
    min-width: 38px;
  }

  .composer textarea {
    min-height: 40px;
    max-height: 96px;
  }
}

/* Installed as a PWA: let the shell fill the window edge to edge. */
@media (display-mode: standalone) {
  .app-shell,
  .app-shell[data-rail="expanded"] {
    width: 100vw;
    height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
}
