:root {
  --bg: #f6f5f2;
  --bg-elevated: #ffffff;
  --bg-sidebar: #efeee9;
  --bg-hover: #e7e5df;
  --bg-active: #e0ded7;
  --text: #1c1b19;
  --text-soft: #55524c;
  --text-muted: #85817a;
  --border: #dedbd3;
  --border-soft: #e8e5de;
  --accent: #2f6f5e;
  --accent-soft: #e3efe9;
  --accent-strong: #24584a;
  --code-bg: #1f2321;
  --code-text: #e9ede9;
  --danger: #b4433a;
  --shadow-sm: 0 1px 2px rgba(28, 27, 25, 0.06);
  --shadow-md: 0 8px 30px rgba(28, 27, 25, 0.09);
  --radius: 14px;
  --sidebar-w: 272px;
  --font: "Inter", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #141614;
  --bg-elevated: #1b1e1c;
  --bg-sidebar: #101211;
  --bg-hover: #242825;
  --bg-active: #2c312d;
  --text: #ecebe6;
  --text-soft: #b6b3aa;
  --text-muted: #837f77;
  --border: #2c302d;
  --border-soft: #242825;
  --accent: #7cc3a9;
  --accent-soft: #1f332c;
  --accent-strong: #a3d9c3;
  --code-bg: #0c0e0d;
  --code-text: #e4e8e4;
  --danger: #e5766b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

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

button {
  cursor: pointer;
  border: none;
  background: none;
}

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

/* ---------------- Sidebar ---------------- */

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  gap: 10px;
  z-index: 30;
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 10px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, var(--accent), #6f9c6a);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  box-shadow: var(--shadow-sm);
}

.brand-name {
  font-weight: 680;
  font-size: 13.5px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  font-size: 10.5px;
  color: var(--text-muted);
  margin-top: 1px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-soft);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 9px;
  font-size: 13px;
  color: var(--text-soft);
  text-align: left;
  font-weight: 520;
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--bg-active);
  color: var(--text);
  font-weight: 620;
}

.nav-item.active svg {
  color: var(--accent);
}

.sidebar-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 4px 10px 0;
  font-weight: 600;
}

.session-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 8px;
  scrollbar-width: thin;
}

.session-empty {
  color: var(--text-muted);
  font-size: 12px;
  padding: 8px 10px;
  line-height: 1.6;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 9px;
  color: var(--text-soft);
  font-size: 12.5px;
}

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

.session-item.active {
  background: var(--bg-active);
  color: var(--text);
  font-weight: 550;
}

.session-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-delete {
  opacity: 0;
  color: var(--text-muted);
  padding: 3px;
  border-radius: 5px;
  display: flex;
}

.session-item:hover .session-delete,
.session-delete:focus-visible {
  opacity: 1;
}

.session-delete:hover {
  color: var(--danger);
  background: rgba(180, 67, 58, 0.1);
}

.sidebar-footer {
  border-top: 1px solid var(--border-soft);
  padding-top: 10px;
}

.sidebar-action {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 9px;
  font-size: 12.5px;
  color: var(--text-soft);
  width: 100%;
  text-align: left;
}

.sidebar-action:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.theme-toggle .sun {
  display: none;
}

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

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

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

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

.view {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.view.active {
  display: flex;
}

.chat-header {
  height: 58px;
  flex: 0 0 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: var(--text-soft);
  flex: 0 0 auto;
}

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

.menu-btn {
  display: none;
}

.header-title {
  font-size: 14px;
  font-weight: 620;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.header-spacer {
  flex: 1;
}

.header-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ---------------- Buttons / fields ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 580;
  white-space: nowrap;
  transition: background 0.14s ease, opacity 0.14s ease, transform 0.12s ease;
}

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

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

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

.btn-small {
  height: 27px;
  padding: 0 9px;
  font-size: 11.5px;
}

.btn-danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}

.btn-danger:hover {
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field > span {
  font-size: 11.5px;
  font-weight: 620;
  color: var(--text-soft);
  letter-spacing: 0.01em;
}

.field input[type="text"],
.field input[type="url"],
.field textarea {
  width: 100%;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
  font-size: 13px;
  line-height: 1.55;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.field input:focus,
.field textarea:focus {
  border-color: color-mix(in srgb, var(--accent) 60%, var(--border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}

.field textarea {
  resize: vertical;
  min-height: 74px;
}

.mono-input {
  font-family: var(--mono) !important;
  font-size: 12px !important;
}

.field.grow {
  flex: 1;
  min-height: 0;
}

.field.grow textarea {
  flex: 1;
}

.muted {
  color: var(--text-muted);
  font-size: 11.5px;
}

.row-gap {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.mono {
  font-family: var(--mono);
  font-size: 11.5px;
}

/* ---------------- Messages ---------------- */

.messages-scroll {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  scrollbar-width: thin;
}

.messages {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 26px 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.msg {
  display: flex;
  gap: 13px;
  animation: rise 0.26s ease both;
}

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

.msg-avatar {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  margin-top: 2px;
}

.msg.user .msg-avatar {
  background: var(--bg-active);
  color: var(--text-soft);
}

.msg.assistant .msg-avatar {
  background: linear-gradient(140deg, var(--accent), #6f9c6a);
  color: #fff;
}

.msg-body {
  min-width: 0;
  flex: 1;
  padding-top: 1px;
}

.msg-role {
  font-size: 12px;
  font-weight: 650;
  color: var(--text-muted);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tool-tags {
  display: inline-flex;
  gap: 4px;
  flex-wrap: wrap;
}

.tool-tag {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-family: var(--mono);
}

.msg-text {
  font-size: 15px;
  line-height: 1.72;
  color: var(--text);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg.user .msg-text {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: 4px 14px 14px 14px;
  padding: 11px 15px;
  white-space: pre-wrap;
  display: inline-block;
  max-width: 100%;
  box-shadow: var(--shadow-sm);
}

.msg-text > *:first-child {
  margin-top: 0;
}

.msg-text > *:last-child {
  margin-bottom: 0;
}

.msg-text p {
  margin: 0 0 12px;
}

.msg-text h1,
.msg-text h2,
.msg-text h3,
.msg-text h4 {
  line-height: 1.35;
  margin: 20px 0 10px;
  letter-spacing: -0.015em;
}

.msg-text h1 {
  font-size: 22px;
}

.msg-text h2 {
  font-size: 19px;
}

.msg-text h3 {
  font-size: 16.5px;
}

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

.msg-text li {
  margin: 4px 0;
}

.msg-text a {
  color: var(--accent-strong);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg-text blockquote {
  margin: 0 0 12px;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--border);
  color: var(--text-soft);
}

.msg-text hr {
  border: none;
  border-top: 1px solid var(--border-soft);
  margin: 18px 0;
}

.msg-text code {
  font-family: var(--mono);
  font-size: 0.87em;
  background: var(--bg-hover);
  border: 1px solid var(--border-soft);
  padding: 1px 5px;
  border-radius: 5px;
}

.code-block {
  margin: 0 0 14px;
  border-radius: 11px;
  overflow: hidden;
  background: var(--code-bg);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.code-lang {
  font-family: var(--mono);
  font-size: 11px;
  color: #9fb0a6;
}

.code-copy {
  font-size: 11px;
  color: #9fb0a6;
  padding: 3px 7px;
  border-radius: 5px;
}

.code-copy:hover {
  color: #e9ede9;
  background: rgba(255, 255, 255, 0.08);
}

.code-block pre {
  margin: 0;
  padding: 13px 14px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.code-block code {
  font-family: var(--mono);
  font-size: 12.8px;
  line-height: 1.62;
  color: var(--code-text);
  background: none;
  border: none;
  padding: 0;
  white-space: pre;
}

.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.msg.assistant:hover .msg-actions,
.msg-actions:focus-within {
  opacity: 1;
}

.msg-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 6px;
}

.msg-action:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.streaming-cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  background: var(--accent);
  border-radius: 2px;
  vertical-align: -2px;
  margin-left: 2px;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  to {
    visibility: hidden;
  }
}

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

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: pulse 1.2s ease-in-out infinite;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes pulse {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.notice {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 9px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 26%, transparent);
  border-radius: 11px;
  padding: 11px 13px;
  max-width: 100%;
}

.notice-text {
  overflow-wrap: anywhere;
}

.retry-btn {
  font-weight: 600;
  font-size: 12px;
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  background: var(--bg-elevated);
  border-radius: 7px;
  padding: 4px 11px;
  transition: background 0.14s ease;
}

.retry-btn:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

/* ---------------- Empty state ---------------- */

.empty {
  flex: 1;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 22px;
}

.empty-inner {
  width: 100%;
  max-width: 700px;
  margin-top: -3vh;
}

.empty-mark {
  width: 52px;
  height: 52px;
  border-radius: 15px;
  background: linear-gradient(140deg, var(--accent), #6f9c6a);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 21px;
  box-shadow: var(--shadow-md);
  margin-bottom: 22px;
}

.empty h1 {
  font-size: clamp(26px, 3.4vw, 36px);
  line-height: 1.18;
  letter-spacing: -0.03em;
  margin: 0 0 10px;
  font-weight: 680;
}

.empty p {
  margin: 0 0 28px;
  color: var(--text-soft);
  font-size: 15px;
  line-height: 1.6;
  max-width: 500px;
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.suggestion {
  text-align: left;
  padding: 14px 15px;
  border-radius: 13px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.suggestion:hover {
  border-color: var(--border);
  background: var(--bg-hover);
  transform: translateY(-1px);
}

.suggestion-title {
  font-size: 13.5px;
  font-weight: 620;
  margin-bottom: 3px;
}

.suggestion-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ---------------- Composer ---------------- */

.composer-wrap {
  flex: 0 0 auto;
  padding: 8px 22px 18px;
  background: linear-gradient(to top, var(--bg) 62%, transparent);
}

.composer {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow-md);
  padding: 10px 12px 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  box-shadow: 0 8px 32px rgba(47, 111, 94, 0.14);
}

.composer-context {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.context-chip {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-soft);
  background: var(--bg-hover);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 2px 8px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.composer textarea {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-size: 15px;
  line-height: 1.55;
  max-height: 200px;
  min-height: 26px;
  padding: 2px 0;
}

.composer textarea::placeholder {
  color: var(--text-muted);
}

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

.composer-hint {
  font-size: 11px;
  color: var(--text-muted);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.composer-hint kbd {
  font-family: var(--mono);
  font-size: 10px;
  background: var(--bg-hover);
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  padding: 1px 4px;
}

.send-btn,
.stop-btn {
  flex: 0 0 auto;
  height: 34px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  padding: 0 13px;
  transition: background 0.15s ease, opacity 0.15s ease, transform 0.12s ease;
}

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

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

.send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

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

.stop-btn .sq {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: currentColor;
}

.legal {
  text-align: center;
  font-size: 10.5px;
  color: var(--text-muted);
  margin-top: 9px;
}

/* ---------------- Page views ---------------- */

.page-scroll {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
}

.page {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 22px 40px;
}

.page.wide {
  max-width: 1320px;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.panel-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

/* Prompt studio */

.studio {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.studio-list,
.studio-editor {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.studio-editor {
  display: flex;
  flex-direction: column;
  min-height: 560px;
}

.prompt-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.prompt-card {
  text-align: left;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--bg);
  transition: background 0.13s ease, border-color 0.13s ease;
}

.prompt-card:hover {
  background: var(--bg-hover);
}

.prompt-card.selected {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
  background: var(--accent-soft);
}

.prompt-card-top {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 3px;
}

.prompt-card-name {
  font-size: 13px;
  font-weight: 620;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prompt-card-detail {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.badge {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--bg-active);
  color: var(--text-soft);
  white-space: nowrap;
}

.editor-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  padding-top: 12px;
  flex-wrap: wrap;
}

.prompt-textarea {
  font-family: var(--mono) !important;
  font-size: 12.6px !important;
  line-height: 1.65 !important;
  min-height: 260px;
}

/* Builder */

.builder-grid {
  display: grid;
  grid-template-columns: minmax(340px, 420px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.template-card {
  text-align: left;
  padding: 10px 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  transition: border-color 0.13s ease, background 0.13s ease;
}

.template-card:hover {
  background: var(--bg-hover);
}

.template-card.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.template-name {
  font-size: 12.5px;
  font-weight: 620;
  margin-bottom: 2px;
}

.template-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.45;
}

.toggle-row {
  display: flex;
  gap: 6px 16px;
  flex-wrap: wrap;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-soft);
  cursor: pointer;
}

.check input {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
}

.blueprint {
  font-size: 13px;
  line-height: 1.68;
  color: var(--text-soft);
  max-height: 480px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.blueprint h3 {
  font-size: 13.5px;
  color: var(--text);
  margin: 16px 0 6px;
}

.blueprint h3:first-child {
  margin-top: 0;
}

.blueprint ul {
  margin: 0 0 10px;
  padding-left: 20px;
}

.blueprint li {
  margin: 3px 0;
}

.blueprint code {
  font-family: var(--mono);
  font-size: 11.5px;
  background: var(--bg-hover);
  border: 1px solid var(--border-soft);
  padding: 1px 5px;
  border-radius: 5px;
}

.placeholder {
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.7;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 22px;
  text-align: center;
}

.files-card {
  margin-top: 16px;
}

.files-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 12px;
  min-height: 380px;
}

.file-tree {
  display: flex;
  flex-direction: column;
  gap: 2px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 8px;
  background: var(--bg);
  overflow-y: auto;
  max-height: 460px;
  scrollbar-width: thin;
}

.file-node {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  text-align: left;
  padding: 6px 8px;
  border-radius: 7px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-node:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.file-node.selected {
  background: var(--bg-active);
  color: var(--text);
  font-weight: 600;
}

.file-viewer {
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--code-bg);
  min-width: 0;
}

.file-viewer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 11px;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  color: #9fb0a6;
}

.file-code {
  margin: 0;
  padding: 13px 14px;
  overflow: auto;
  flex: 1;
  max-height: 440px;
  scrollbar-width: thin;
}

.file-code code {
  font-family: var(--mono);
  font-size: 12.4px;
  line-height: 1.62;
  color: var(--code-text);
  white-space: pre;
}

/* MCP */

.mcp-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
  gap: 16px;
  align-items: start;
}

.mcp-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mcp-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  border-radius: 11px;
  border: 1px solid var(--border-soft);
  background: var(--bg);
}

.mcp-item.enabled {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: var(--accent-soft);
}

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

.mcp-name {
  font-size: 13px;
  font-weight: 620;
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.mcp-url {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 3px;
}

.mcp-actions {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 9px;
}

.switch {
  position: relative;
  width: 34px;
  height: 20px;
  flex: 0 0 34px;
  border-radius: 999px;
  background: var(--bg-active);
  border: 1px solid var(--border);
  transition: background 0.16s ease;
  margin-top: 2px;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s ease;
}

.switch.on {
  background: var(--accent);
  border-color: transparent;
}

.switch.on::after {
  transform: translateX(14px);
}

.test-output {
  margin-top: 12px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: var(--bg);
  padding: 11px 12px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-soft);
  max-height: 220px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.test-output.ok {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: var(--accent-soft);
}

.test-output.bad {
  border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
  background: color-mix(in srgb, var(--danger) 7%, transparent);
}

.test-output ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
}

.tool-card {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: var(--bg);
}

.tool-name {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent-strong);
  margin-bottom: 3px;
  overflow-wrap: anywhere;
}

.tool-desc {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Project picker dialog */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 15, 0.45);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 20px;
}

.modal {
  width: min(560px, 100%);
  max-height: 80vh;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
}

.modal-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
}

.modal-body {
  padding: 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.project-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 11px;
  border-radius: 9px;
}

.project-row:hover {
  background: var(--bg-hover);
}

.project-row-main {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.project-row-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-row-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.empty-note {
  padding: 22px 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.6;
}

/* ---------------- Overlay / utilities ---------------- */

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 15, 0.4);
  z-index: 25;
  backdrop-filter: blur(2px);
}

.overlay.show {
  display: block;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(8px);
  background: var(--text);
  color: var(--bg);
  font-size: 12.5px;
  font-weight: 560;
  padding: 9px 15px;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  max-width: min(520px, calc(100vw - 32px));
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.spinner {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

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

/* ---------------- Responsive ---------------- */

@media (max-width: 1100px) {
  .studio {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .builder-grid {
    grid-template-columns: 1fr;
  }

  .mcp-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-102%);
    transition: transform 0.24s cubic-bezier(0.3, 0.8, 0.3, 1);
    width: 284px;
    flex-basis: 284px;
    box-shadow: var(--shadow-md);
  }

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

  .menu-btn {
    display: grid;
  }

  .chat-header {
    padding: 0 12px;
    gap: 8px;
  }

  .header-meta {
    display: none;
  }

  .messages {
    padding: 20px 15px 12px;
    gap: 20px;
  }

  .composer-wrap {
    padding: 6px 12px 14px;
  }

  .empty {
    padding: 20px 16px;
  }

  .suggestions {
    grid-template-columns: 1fr;
  }

  .msg-actions {
    opacity: 1;
  }

  .page {
    padding: 16px 12px 32px;
  }

  .studio {
    grid-template-columns: 1fr;
  }

  .files-layout {
    grid-template-columns: 1fr;
  }

  .file-tree {
    max-height: 180px;
  }

  .template-grid {
    grid-template-columns: 1fr;
  }

  .status-pill {
    display: none;
  }
}

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

/* ---------------- Model credential settings ---------------- */

.project-state {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  line-height: 1.55;
  padding: 10px 12px;
  border-radius: 9px;
  margin-bottom: 16px;
  border: 1px solid var(--border-soft);
  background: var(--bg);
  color: var(--text-soft);
}

.project-state.ok {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.project-state.warn {
  border-color: color-mix(in srgb, #c58a2e 45%, var(--border));
  background: color-mix(in srgb, #c58a2e 10%, transparent);
  color: color-mix(in srgb, #8a5f14 80%, var(--text));
}

[data-theme="dark"] .project-state.warn {
  color: #e0b264;
}

.dot-on,
.dot-off {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: 0 0 7px;
  margin-top: 6px;
}

.dot-on {
  background: var(--accent);
}

.dot-off {
  background: #c58a2e;
}

.model-status {
  font-size: 11.5px;
  color: var(--text-muted);
}

.model-status.ok {
  color: var(--accent-strong);
}

.model-status.bad {
  color: var(--danger);
}

.badge-on {
  background: var(--accent);
  color: #fff;
}

.context-chip.chip-on {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.help-list {
  margin: 0;
  padding-left: 20px;
  font-size: 12.5px;
  line-height: 1.72;
  color: var(--text-soft);
}

.help-list li {
  margin: 5px 0;
}
