:root {
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --bg-elev: #f0f2f5;
  --bg-input: #f3f4f6;
  --border: #e5e7eb;
  --border-soft: #eff1f4;
  --text: #1a1a1a;
  --text-dim: #6b7280;
  --text-faint: #9ca3af;
  --accent: #4d6bfe;
  --accent-strong: #3f5ce0;
  --accent-soft: #eef2ff;
  --user-bubble: #eef2ff;
  --code-bg: #f6f8fa;
  --code-border: #e5e7eb;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --shadow: 0 18px 50px rgba(17, 24, 39, 0.14);
  --radius: 16px;
  --hl-keyword: #cf222e;
  --hl-string: #0a3069;
  --hl-comment: #6e7781;
  --hl-number: #0550ae;
  --hl-title: #8250df;
  --hl-built: #953800;
  --hl-attr: #116329;
  --hl-meta: #6639ba;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --bg-soft: #1a1a1a;
    --bg-elev: #242424;
    --bg-input: #262626;
    --border: #333333;
    --border-soft: #2a2a2a;
    --text: #ececec;
    --text-dim: #a3a3a3;
    --text-faint: #737373;
    --accent: #6b8aff;
    --accent-strong: #5b7bf5;
    --accent-soft: #1e2742;
    --user-bubble: #1e2742;
    --code-bg: #0d1117;
    --code-border: #30363d;
    --green: #4ade80;
    --amber: #fbbf24;
    --red: #f87171;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
    --hl-keyword: #ff7b72;
    --hl-string: #a5d6ff;
    --hl-comment: #8b949e;
    --hl-number: #79c0ff;
    --hl-title: #d2a8ff;
    --hl-built: #ffa657;
    --hl-attr: #7ee787;
    --hl-meta: #d2a8ff;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.svg-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.logo-svg {
  display: block;
  flex: 0 0 auto;
}

.logo-lg {
  width: 56px;
  height: 56px;
}

.logo-sm {
  width: 30px;
  height: 30px;
}

.logo-xl {
  width: 62px;
  height: 62px;
  margin: 0 auto;
}

.i {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.muted {
  color: var(--text-dim);
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-thumb {
  background: rgba(128, 128, 128, 0.28);
  border-radius: 3px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

/* ---------- login ---------- */

.login-view {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% -10%, rgba(77, 107, 254, 0.14), transparent 46%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 34px 28px 28px;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 24px;
  box-shadow: 0 8px 40px rgba(17, 24, 39, 0.06);
  text-align: center;
}

.login-card .logo-svg {
  margin: 0 auto;
}

.login-card h1 {
  margin: 16px 0 6px;
  font-size: 26px;
  letter-spacing: -0.02em;
}

.login-sub {
  margin: 0 0 26px;
  color: var(--text-dim);
  font-size: 13.5px;
}

.field {
  display: block;
  text-align: left;
  margin-bottom: 16px;
}

.field span {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  color: var(--text-dim);
}

.field input,
.text-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: 12px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.field input:focus,
.text-input:focus {
  background: var(--bg);
  border-color: var(--accent);
}

.primary-btn {
  padding: 10px 18px;
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 12px;
  color: #fff;
  font-weight: 600;
  font-size: 14.5px;
  transition: background 0.15s, opacity 0.15s;
}

.primary-btn:hover {
  background: var(--accent-strong);
}

.primary-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.login-btn {
  width: 100%;
  padding: 13px;
  font-size: 15px;
}

.error-text {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--red);
  font-size: 13px;
}

/* ---------- layout ---------- */

.app {
  display: flex;
  height: 100%;
  height: 100dvh;
}

.sidebar {
  width: 276px;
  flex: 0 0 276px;
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  border-right: 1px solid var(--border-soft);
  z-index: 30;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 12px 10px;
  padding-top: calc(14px + env(safe-area-inset-top));
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-name {
  font-weight: 650;
  font-size: 15.5px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.new-chat-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px 6px 8px;
  background: var(--accent);
  border: 0;
  border-radius: 18px;
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  flex: 0 0 auto;
}

.new-chat-btn .i {
  width: 15px;
  height: 15px;
  stroke-width: 2;
}

.new-chat-btn:hover {
  background: var(--accent-strong);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 0;
  border-radius: 10px;
  color: var(--text-dim);
  flex: 0 0 auto;
}

.icon-btn:hover {
  background: var(--bg-elev);
  color: var(--text);
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 2px 8px 12px;
  -webkit-overflow-scrolling: touch;
}

.group-label {
  padding: 14px 10px 5px;
  font-size: 12px;
  color: var(--text-faint);
  font-weight: 500;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  margin-bottom: 1px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  text-align: left;
  transition: background 0.12s;
}

.session-item:hover {
  background: var(--bg-elev);
}

.session-item.active {
  background: var(--accent-soft);
}

.session-item.active .session-title {
  color: var(--accent);
  font-weight: 600;
}

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

.session-title {
  display: block;
  font-size: 13.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 1px;
  font-size: 11px;
  color: var(--text-faint);
}

.busy-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.6s infinite;
  flex: 0 0 auto;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(77, 107, 254, 0.35);
  }
  70% {
    box-shadow: 0 0 0 5px rgba(77, 107, 254, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(77, 107, 254, 0);
  }
}

.session-del {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  border-radius: 7px;
  color: var(--text-faint);
  font-size: 16px;
  line-height: 1;
  opacity: 0;
  flex: 0 0 auto;
  transition: opacity 0.12s, background 0.12s;
}

.session-item:hover .session-del,
.session-item.active .session-del {
  opacity: 0.7;
}

.session-del:hover {
  background: rgba(220, 38, 38, 0.1);
  color: var(--red);
  opacity: 1;
}

.side-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-soft);
  font-size: 12px;
  color: var(--text-faint);
}

.conn {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.conn span:last-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.text-btn {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  font-size: 12.5px;
  padding: 5px 7px;
  border-radius: 8px;
}

.text-btn:hover {
  background: var(--bg-elev);
  color: var(--text);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex: 0 0 auto;
}

.dot.ok {
  background: var(--green);
}

.dot.bad {
  background: var(--red);
}

.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
  z-index: 25;
}

/* ---------- main ---------- */

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
  z-index: 20;
}

.menu-btn {
  display: none;
}

.top-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: none;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 16px 6px;
  -webkit-overflow-scrolling: touch;
}

/* ---------- welcome ---------- */

.welcome {
  max-width: 660px;
  margin: 0 auto;
  padding: 9vh 8px 24px;
  text-align: center;
}

.welcome h1 {
  margin: 18px 0 8px;
  font-size: 23px;
  line-height: 1.35;
  letter-spacing: -0.02em;
}

.welcome > p {
  margin: 0 auto;
  max-width: 440px;
  color: var(--text-dim);
  font-size: 14px;
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 30px;
  text-align: left;
}

.suggestion {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  text-align: left;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.suggestion:hover {
  background: var(--bg);
  border-color: var(--accent);
}

.suggestion:active {
  transform: scale(0.985);
}

.suggestion-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-bottom: 4px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
}

.suggestion-icon .i {
  width: 16px;
  height: 16px;
}

.suggestion-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}

.suggestion-desc {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- messages ---------- */

.message {
  max-width: 760px;
  margin: 0 auto 24px;
}

.message.user {
  display: flex;
  justify-content: flex-end;
}

.bubble-user {
  max-width: 82%;
  padding: 10px 15px;
  background: var(--user-bubble);
  border-radius: 18px 18px 5px 18px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.65;
}

.assistant-block {
  min-width: 0;
}

.assistant-role {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
  font-size: 12.5px;
  color: var(--text-faint);
}

.assistant-logo {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  flex: 0 0 auto;
}

.md {
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: 16px;
  line-height: 1.75;
}

.md p {
  margin: 0 0 12px;
}

.md p:last-child {
  margin-bottom: 0;
}

.md h1,
.md h2,
.md h3,
.md h4 {
  margin: 18px 0 8px;
  line-height: 1.35;
}

.md h1 {
  font-size: 21px;
}
.md h2 {
  font-size: 19px;
}
.md h3 {
  font-size: 17px;
}
.md h4 {
  font-size: 16px;
}

.md ul,
.md ol {
  margin: 8px 0 12px;
  padding-left: 24px;
}

.md li {
  margin: 4px 0;
}

.md code {
  padding: 1.5px 5px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.86em;
}

.md pre {
  margin: 12px 0;
  padding: 13px 15px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 12px;
  overflow-x: auto;
}

.md pre code {
  padding: 0;
  background: transparent;
  border: 0;
  font-size: 13px;
  line-height: 1.65;
}

.md a {
  color: var(--accent);
  text-decoration: none;
}

.md a:hover {
  text-decoration: underline;
}

.md blockquote {
  margin: 10px 0;
  padding: 2px 0 2px 13px;
  border-left: 3px solid var(--border);
  color: var(--text-dim);
}

.md hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.md table {
  border-collapse: collapse;
  margin: 12px 0;
  display: block;
  overflow-x: auto;
}

.md th,
.md td {
  border: 1px solid var(--border);
  padding: 7px 11px;
  text-align: left;
}

.md th {
  background: var(--bg-soft);
}

details.reasoning {
  margin: 0 0 12px;
  border-radius: 12px;
  background: var(--bg-soft);
}

details.reasoning summary {
  padding: 9px 13px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  list-style: none;
}

details.reasoning summary::-webkit-details-marker {
  display: none;
}

details.reasoning summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 6px;
  transition: transform 0.15s;
  color: var(--text-faint);
}

details.reasoning[open] summary::before {
  transform: rotate(90deg);
}

details.reasoning .reasoning-body {
  padding: 0 13px 12px;
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.tool {
  margin: 10px 0;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: var(--bg-soft);
  overflow: hidden;
}

.tool summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 13px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.tool summary::-webkit-details-marker {
  display: none;
}

.tool-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: var(--accent);
  flex: 0 0 auto;
}

.tool-title {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-status {
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 20px;
  background: var(--bg-elev);
  color: var(--text-faint);
  flex: 0 0 auto;
}

.tool[data-status="running"] .tool-status {
  color: var(--amber);
}
.tool[data-status="completed"] .tool-status {
  color: var(--green);
}
.tool[data-status="error"] .tool-status {
  color: var(--red);
}

.tool-body {
  border-top: 1px solid var(--border-soft);
  padding: 11px 13px;
}

.tool-body pre {
  margin: 0 0 8px;
  padding: 10px 11px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 9px;
  font-size: 12px;
  line-height: 1.55;
  max-height: 300px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.tool-body pre:last-child {
  margin-bottom: 0;
}

.tool-label {
  margin: 0 0 4px;
  font-size: 10.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.error-card {
  margin: 10px 0;
  padding: 11px 13px;
  border: 1px solid rgba(220, 38, 38, 0.28);
  background: rgba(220, 38, 38, 0.06);
  border-radius: 12px;
  color: var(--red);
  font-size: 13.5px;
  white-space: pre-wrap;
}

.typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 6px 2px;
}

.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 1.2s infinite;
}

.typing i:nth-child(2) {
  animation-delay: 0.2s;
}
.typing i:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {
  0%,
  60%,
  100% {
    opacity: 0.22;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.empty-state {
  max-width: 420px;
  margin: 14vh auto 0;
  text-align: center;
  padding: 0 20px;
}

.empty-state h2 {
  margin: 16px 0 6px;
  font-size: 19px;
}

.empty-state p {
  margin: 0 0 18px;
  color: var(--text-dim);
  font-size: 13.5px;
}

.empty-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  border-radius: 15px;
  background: var(--accent);
  color: #fff;
  font-size: 24px;
  font-weight: 700;
}

/* ---------- pending ---------- */

.pending-bar {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 16px 0;
}

.pending-card {
  margin-bottom: 8px;
  padding: 12px 14px;
  border: 1px solid rgba(77, 107, 254, 0.28);
  background: var(--accent-soft);
  border-radius: 14px;
}

.pending-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.pending-kind {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
}

.pending-detail {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text-dim);
  word-break: break-all;
  margin-bottom: 9px;
  white-space: pre-wrap;
}

.pending-question {
  font-size: 13.5px;
  margin-bottom: 10px;
  white-space: pre-wrap;
}

.pending-options {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 8px 0;
}

.option-btn {
  padding: 7px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 12.5px;
}

.option-btn:hover,
.option-btn.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.pending-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}

.pending-actions button {
  padding: 7px 13px;
  border-radius: 9px;
  font-size: 12.5px;
}

.small-btn {
  padding: 7px 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 12.5px;
}

.small-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.danger-btn {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.danger-btn:hover {
  background: #b91c1c;
}

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

.composer {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 6px 16px 2px;
}

.input-shell {
  padding: 10px 10px 8px;
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: 22px;
  transition: border-color 0.15s, background 0.15s;
}

.input-shell:focus-within {
  background: var(--bg);
  border-color: var(--border);
}

.input-shell textarea {
  width: 100%;
  min-height: 26px;
  max-height: 38vh;
  padding: 4px 6px 2px;
  background: transparent;
  border: 0;
  outline: none;
  resize: none;
  font-size: 16px;
  line-height: 1.5;
}

.input-shell textarea::placeholder {
  color: var(--text-faint);
}

.input-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}

.chip-group {
  display: flex;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.chip-select {
  min-width: 0;
  max-width: 150px;
  padding: 5px 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  font-size: 12px;
  color: var(--text-dim);
  outline: none;
  text-overflow: ellipsis;
}

.chip-select:hover {
  border-color: var(--text-faint);
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
}

.send-btn,
.stop-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  border: 0;
  transition: background 0.15s, opacity 0.15s;
}

.send-btn {
  background: var(--accent);
  color: #fff;
}

.send-btn:hover {
  background: var(--accent-strong);
}

.send-btn:disabled {
  background: var(--border);
  color: var(--text-faint);
  cursor: default;
}

.send-btn .i,
.stop-btn .i {
  width: 19px;
  height: 19px;
  stroke-width: 2.2;
}

.stop-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
}

.stop-btn:hover {
  background: var(--bg-elev);
}

.stop-btn .i {
  width: 16px;
  height: 16px;
}

.disclaimer {
  margin: 8px 0 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-faint);
}

/* ---------- buttons ---------- */

.ghost-btn {
  padding: 9px 15px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--text-dim);
  font-size: 13.5px;
}

.ghost-btn:hover {
  background: var(--bg-elev);
  color: var(--text);
}

.danger-text {
  color: var(--red);
  border-color: rgba(220, 38, 38, 0.28);
}

/* ---------- modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(2px);
}

.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow);
  animation: slideUp 0.2s ease-out;
}

.modal-card.small {
  max-width: 420px;
  border-radius: 20px;
  margin-bottom: 18vh;
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0.5;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 8px;
}

.modal-head h2 {
  margin: 0;
  font-size: 17px;
}

.modal-body {
  overflow-y: auto;
  padding: 2px 18px 26px;
  padding-bottom: calc(26px + env(safe-area-inset-bottom));
}

.settings-section {
  padding: 15px 0;
  border-top: 1px solid var(--border-soft);
}

.settings-section:first-child {
  border-top: 0;
}

.settings-section h3 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}

.provider-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.provider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-soft);
  border-radius: 11px;
}

.provider-row .provider-name {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  padding: 1px 8px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10.5px;
  flex: 0 0 auto;
}

.provider-select {
  width: 100%;
  margin: 8px 0;
  padding: 5px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 11px;
  outline: none;
}

.provider-select option {
  padding: 6px 8px;
  border-radius: 6px;
}

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

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

.hint {
  margin: 10px 0 0;
  font-size: 11.5px;
  color: var(--text-faint);
}

.confirm-text {
  margin: 0 0 6px;
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.6;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 88vw;
  padding: 10px 16px;
  background: #1f2937;
  color: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 13px;
  z-index: 60;
  animation: fadeIn 0.15s ease-out;
}

.toast.error {
  background: var(--red);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translate(-50%, 6px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* ---------- message meta / copy ---------- */

.user-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  max-width: 82%;
}

.bubble-user {
  max-width: 100%;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 6px;
  min-height: 20px;
  font-size: 11.5px;
  color: var(--text-faint);
}

.message.user .message-meta {
  justify-content: flex-end;
}

.message-time,
.message-duration {
  white-space: nowrap;
}

.message-copy {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-faint);
  font-size: 11.5px;
  line-height: 1.4;
}

.message-copy .i {
  width: 13px;
  height: 13px;
  stroke-width: 1.8;
}

.message-copy:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- reasoning (always expanded) ---------- */

.reasoning {
  margin: 0 0 12px;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: var(--bg-soft);
  overflow: hidden;
}

.reasoning-title {
  padding: 9px 13px 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
}

.reasoning-body {
  padding: 6px 13px 12px;
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- syntax highlight ---------- */

.md pre.code-pre {
  position: relative;
  background: var(--code-bg);
}

.md pre.code-pre[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  top: 6px;
  right: 10px;
  font-size: 10px;
  line-height: 1;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
  pointer-events: none;
}

.md pre code.hljs {
  display: block;
  padding: 0;
  background: transparent;
  color: var(--text);
}

.hljs-comment,
.hljs-quote {
  color: var(--hl-comment);
  font-style: italic;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-doctag,
.hljs-type {
  color: var(--hl-keyword);
}

.hljs-string,
.hljs-regexp,
.hljs-addition,
.hljs-attribute {
  color: var(--hl-string);
}

.hljs-number,
.hljs-symbol,
.hljs-bullet,
.hljs-link,
.hljs-selector-attr,
.hljs-selector-pseudo {
  color: var(--hl-number);
}

.hljs-title,
.hljs-section,
.hljs-selector-id,
.hljs-selector-class,
.hljs-function .hljs-title {
  color: var(--hl-title);
}

.hljs-built_in,
.hljs-name,
.hljs-tag,
.hljs-variable,
.hljs-template-variable,
.hljs-params {
  color: var(--hl-built);
}

.hljs-attr,
.hljs-property,
.hljs-subst {
  color: var(--hl-attr);
}

.hljs-meta,
.hljs-meta-keyword,
.hljs-meta-string {
  color: var(--hl-meta);
}

.hljs-deletion {
  color: var(--red);
}

.hljs-emphasis {
  font-style: italic;
}

.hljs-strong {
  font-weight: 700;
}

/* ---------- scroll to bottom ---------- */

.scroll-bottom {
  position: fixed;
  right: 26px;
  bottom: calc(184px + env(safe-area-inset-bottom));
  z-index: 40;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  color: var(--text-dim);
  box-shadow: 0 6px 22px rgba(17, 24, 39, 0.14);
}

.scroll-bottom:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.scroll-bottom .i {
  width: 17px;
  height: 17px;
  stroke-width: 2;
}

/* ---------- settings extras ---------- */

.textarea {
  margin-top: 8px;
  resize: vertical;
  min-height: 54px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
}

.config-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.config-form .provider-select {
  margin: 0;
  padding: 11px 12px;
  border-radius: 12px;
}

.provider-sub {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-faint);
  white-space: normal;
  word-break: break-all;
}

.config-row .provider-name {
  white-space: normal;
}

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

@media (max-width: 760px) {
  .scroll-bottom {
    right: 16px;
    bottom: calc(174px + env(safe-area-inset-bottom));
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(84vw, 320px);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    box-shadow: 24px 0 60px rgba(0, 0, 0, 0.18);
  }

  .app.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .app.sidebar-open .scrim {
    display: block;
  }

  .menu-btn {
    display: inline-flex;
  }

  .welcome {
    padding-top: 7vh;
  }

  .welcome h1 {
    font-size: 21px;
  }

  .messages {
    padding: 6px 14px 4px;
  }

  .composer {
    padding: 6px 12px calc(8px + env(safe-area-inset-bottom));
  }

  .chip-select {
    max-width: 43%;
  }

  .modal {
    align-items: stretch;
  }

  .modal-card {
    max-height: 100dvh;
    border-radius: 0;
    border: 0;
  }

  .modal-card.small {
    margin: auto 14px;
    max-height: none;
    border-radius: 18px;
    border: 1px solid var(--border-soft);
  }

  .pending-bar {
    padding: 6px 12px 0;
  }

  .session-del {
    opacity: 0.55;
  }
}

@media (max-width: 380px) {
  .suggestions {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 761px) {
  .modal {
    align-items: center;
    padding: 24px;
  }

  .modal-card {
    border-radius: 22px;
  }

  .modal-card.small {
    margin-bottom: 0;
  }

  .messages {
    padding: 16px 28px 8px;
  }

  .composer {
    padding-bottom: 14px;
  }
}

/* ---------- token usage ---------- */

.token-bar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 14px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 6px 16px calc(6px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.token-bar.is-empty {
  border-top-color: transparent;
}

.tk-ctx {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.tk-key {
  color: var(--text-faint);
}

.tk-meter {
  position: relative;
  width: 68px;
  height: 5px;
  border-radius: 3px;
  background: var(--bg-elev);
  overflow: hidden;
}

.tk-meter > i {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.3s ease;
}

.tk-meter.warn > i {
  background: #e0a72e;
}

.tk-meter.danger > i {
  background: #e05b5b;
}

.tk-val {
  color: var(--text-dim);
}

.tk-pct {
  color: var(--text-dim);
  font-weight: 600;
}

.tk-nums {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  white-space: nowrap;
}

.tk-nums b {
  color: var(--text-dim);
  font-weight: 600;
}

.tk-sep {
  opacity: 0.45;
}

.message-tokens {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--bg-elev);
  color: var(--text-faint);
  font-size: 11px;
  line-height: 1.5;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  cursor: default;
}

.message-tokens .mt-b {
  color: var(--text-dim);
  font-weight: 600;
}

.message-tokens .mt-sep {
  opacity: 0.4;
}

@media (max-width: 720px) {
  .token-bar {
    justify-content: flex-start;
    font-size: 11px;
    gap: 4px 10px;
  }

  .tk-meter {
    width: 46px;
  }

  .message-tokens {
    font-size: 10.5px;
    gap: 4px;
  }
}

.message-tokens.turn-total {
  background: var(--accent-soft);
  color: var(--accent);
}

.message-tokens.turn-total .mt-b {
  color: var(--accent);
}

.message-meta {
  flex-wrap: wrap;
  row-gap: 4px;
}
