:root {
  --bg: #f7f7f4;
  --panel: #ffffff;
  --panel-soft: #fbfbf8;
  --line: #e4e3dd;
  --line-strong: #d4d2c8;
  --text: #202124;
  --muted: #6f716b;
  --muted-2: #8f918a;
  --brand: #4f46e5;
  --brand-2: #3730a3;
  --brand-soft: #eef0ff;
  --ok-soft: #eef8f0;
  --warn-soft: #fff8e8;
  --warn-line: #f0cf7a;
  --danger: #b42318;
  --danger-soft: #fff2f0;
  --shadow: 0 10px 30px rgba(32, 33, 36, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(520px, 1fr) 360px;
  height: 100vh;
  overflow: hidden;
}

.sidebar,
.model-panel,
.main-panel {
  min-width: 0;
}

.sidebar,
.model-panel {
  overflow-y: auto;
  background: var(--panel);
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 18px 16px;
}

.model-panel {
  border-left: 1px solid var(--line);
  padding: 18px 16px 22px;
}

.main-panel {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: #f5f5f1;
}

.brand-row,
.topbar,
.panel-header,
.composer-actions,
.form-actions,
.response-head,
.model-item,
.model-toggle,
.model-actions {
  display: flex;
  align-items: center;
}

.brand-row {
  gap: 11px;
  margin-bottom: 22px;
}

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 10px;
  background: var(--text);
  color: #ffffff;
  font-weight: 800;
}

.brand-copy {
  min-width: 0;
  flex: 1;
}

.brand {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-subtitle,
.panel-subtitle,
.response-head small,
.model-toggle small,
.branch-status,
.model-summary,
.empty-state {
  color: var(--muted);
  font-size: 12px;
}

.section-label,
.panel-title,
.form-group-title {
  color: #343631;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sidebar-section {
  margin-bottom: 24px;
}

.conversation-list,
.branch-list,
.model-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.conversation-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  transition: background 0.15s, border-color 0.15s;
}

.conversation-item:hover,
.branch-item:hover {
  background: #f4f4ef;
}

.conversation-item.active,
.branch-item.active {
  border-color: #d7d9ff;
  background: var(--brand-soft);
}

.conversation-open,
.conversation-delete,
.branch-item {
  border: 0;
  background: transparent;
  color: #343631;
}

.conversation-open {
  min-width: 0;
  padding: 9px 10px;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-delete {
  width: 28px;
  height: 30px;
  color: transparent;
  transition: color 0.15s;
}

.conversation-item:hover .conversation-delete {
  color: var(--muted-2);
}

.conversation-delete:hover {
  color: var(--danger);
}

.branch-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  text-align: left;
}

.branch-item span {
  color: var(--brand);
  font-size: 11px;
  font-weight: 800;
}

.branch-item strong {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar {
  justify-content: space-between;
  gap: 12px;
  min-height: 78px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
}

.title-block {
  flex: 1;
  min-width: 0;
}

.title-input {
  width: 100%;
  border: 0;
  background: transparent;
  color: #151615;
  font-size: 22px;
  font-weight: 800;
  outline: none;
}

.branch-status {
  margin-top: 3px;
}

.topbar-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.notice {
  display: flex;
  gap: 10px;
  margin: 14px 24px 0;
  padding: 11px 13px;
  border: 1px solid var(--warn-line);
  border-radius: 8px;
  background: var(--warn-soft);
  color: #7a4b00;
  font-size: 13px;
  line-height: 1.5;
}

.notice strong {
  white-space: nowrap;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.welcome {
  max-width: 760px;
  margin: 12vh auto 0;
  text-align: center;
}

.welcome h1 {
  margin: 0 0 12px;
  color: #151615;
  font-size: 38px;
  line-height: 1.1;
  letter-spacing: 0;
}

.welcome p {
  max-width: 560px;
  margin: 0 auto 22px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}

.example-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 22px;
}

.example-prompt {
  min-height: 70px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: #343631;
  text-align: left;
  line-height: 1.45;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.05s;
}

.example-prompt:hover {
  border-color: #c7c9ff;
  box-shadow: var(--shadow);
}

.turn {
  max-width: 1160px;
  margin: 0 auto 24px;
}

.user-message {
  width: fit-content;
  max-width: min(780px, 100%);
  margin: 0 0 14px auto;
  padding: 13px 15px;
  border-radius: 10px;
  background: #292a27;
  color: #ffffff;
  line-height: 1.58;
  box-shadow: 0 6px 18px rgba(32, 33, 36, 0.12);
}

.responses-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.response-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 1px 0 rgba(32, 33, 36, 0.03);
}

.response-card.error {
  border-color: #f2b8b5;
}

.response-card.pending {
  border-color: #c7d2fe;
}

.response-head {
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid #eeede8;
  background: var(--panel-soft);
}

.response-head div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.response-body {
  padding: 13px;
  line-height: 1.62;
}

.loading {
  color: var(--brand);
}

.error-text {
  color: var(--danger);
  white-space: pre-wrap;
}

.markdown-lite {
  overflow-wrap: anywhere;
  white-space: normal;
}

.markdown-lite pre {
  margin: 10px 0;
  padding: 11px;
  overflow-x: auto;
  border-radius: 7px;
  background: #1f201d;
  color: #f7f7f4;
}

.markdown-lite code {
  padding: 1px 5px;
  border-radius: 5px;
  background: #eeeee7;
  color: #3730a3;
}

.markdown-lite pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.composer {
  padding: 14px 24px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

.composer textarea {
  width: 100%;
  min-height: 82px;
  max-height: 220px;
  resize: vertical;
  padding: 13px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  outline: none;
  line-height: 1.55;
}

.composer textarea:focus,
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  border-color: #9aa1ff;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.13);
}

.composer-actions {
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.model-summary {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn,
.primary-btn,
.ghost-btn,
.danger-btn {
  border: 1px solid transparent;
  border-radius: 8px;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.05s, box-shadow 0.15s;
}

.icon-btn {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  background: var(--brand);
  color: #ffffff;
  font-size: 22px;
  line-height: 1;
}

.primary-btn {
  padding: 10px 15px;
  background: var(--brand);
  color: #ffffff;
  font-weight: 700;
}

.primary-btn:hover,
.icon-btn:hover {
  background: #4338ca;
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.22);
}

.primary-btn:disabled,
.ghost-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  box-shadow: none;
}

.ghost-btn {
  padding: 9px 12px;
  border-color: var(--line-strong);
  background: #ffffff;
  color: #343631;
}

.ghost-btn:hover {
  border-color: #bebcb3;
  background: #f8f8f4;
}

.danger-btn {
  padding: 9px 12px;
  border-color: #f2b8b5;
  background: #fff8f7;
  color: var(--danger);
}

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

.small {
  padding: 5px 8px;
  font-size: 12px;
}

.panel-header {
  justify-content: space-between;
  min-height: 42px;
  margin-bottom: 12px;
}

.panel-title {
  color: #151615;
  font-size: 15px;
  letter-spacing: 0;
  text-transform: none;
}

.model-item {
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.model-toggle {
  min-width: 0;
  gap: 8px;
}

.model-toggle input {
  margin-top: 2px;
  accent-color: var(--brand);
}

.model-toggle span {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}

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

.model-actions {
  flex: 0 0 auto;
  gap: 6px;
}

.model-form {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.form-group {
  margin-bottom: 18px;
}

.form-group-title {
  margin-bottom: 10px;
  color: var(--muted);
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.form-row label {
  color: #343631;
  font-size: 12px;
  font-weight: 750;
}

.form-row input,
.form-row select,
.form-row textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

.form-row input[type="password"] {
  letter-spacing: 0.03em;
}

.form-row textarea {
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-actions {
  position: sticky;
  bottom: -22px;
  gap: 8px;
  padding: 12px 0 0;
  background: linear-gradient(180deg, rgba(255,255,255,0), #ffffff 35%);
}

.empty-state {
  padding: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: #fbfbf8;
  line-height: 1.5;
}

.mobile-only {
  display: none;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .model-panel {
    grid-column: 1 / -1;
    height: 360px;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .model-form {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
  }

  .form-actions {
    position: static;
    align-self: end;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: 286px;
    transform: translateX(-100%);
    transition: transform 0.2s;
    box-shadow: var(--shadow);
  }

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

  .main-panel {
    min-height: 100vh;
    height: auto;
  }

  .model-panel {
    height: auto;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .model-form {
    display: block;
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 12px 14px;
  }

  .title-input {
    font-size: 19px;
  }

  .mobile-only {
    display: inline-flex;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .notice {
    flex-direction: column;
    gap: 4px;
    margin: 12px 14px 0;
  }

  .chat-log {
    padding: 16px 14px;
  }

  .welcome {
    margin-top: 8vh;
  }

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

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

  .composer {
    padding: 12px 14px 14px;
  }

  .composer-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-btn {
    width: 100%;
  }
}
