:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --soft: #f3f4f8;
  --soft-2: #eef2ff;
  --line: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --primary: #6366f1;
  --primary-dark: #5558df;
  --user: #eef2ff;
  --shadow: 0 10px 28px rgba(17, 24, 39, 0.08);
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

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

button {
  cursor: pointer;
}

.hidden { display: none !important; }

.layout {
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.side-head {
  height: 72px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}

.logo, .mark {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--primary);
  font-size: 13px;
  font-weight: 800;
}

.app-name {
  font-size: 18px;
  font-weight: 800;
}

.app-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.new-btn {
  margin: 16px;
  height: 46px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  transition: background 0.15s ease;
}

.new-btn:hover { background: var(--primary-dark); }

.side-label {
  padding: 0 18px 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.conversation-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0 10px 14px;
}

.conversation {
  border-radius: 10px;
  padding: 11px 10px;
  display: grid;
  gap: 7px;
  cursor: pointer;
}

.conversation:hover,
.conversation.active {
  background: var(--soft);
}

.conversation-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 650;
}

.conversation-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.conversation-time {
  color: var(--muted);
  font-size: 12px;
}

.conversation-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.conversation:hover .conversation-actions,
.conversation.active .conversation-actions {
  opacity: 1;
}

.mini-btn {
  height: 24px;
  border: 0;
  border-radius: 7px;
  background: #fff;
  color: var(--muted);
  padding: 0 8px;
  font-size: 12px;
}

.mini-btn:hover {
  color: var(--primary);
}

.chat {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: 72px 1fr auto;
  background: rgba(243, 244, 248, 0.72);
}

.chat-head {
  min-width: 0;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  padding: 13px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.title-wrap {
  min-width: 0;
}

.chat-title {
  max-width: 520px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 800;
}

.chat-sub {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.head-actions {
  min-width: 0;
  max-width: min(560px, 55vw);
  display: grid;
  grid-template-columns: minmax(120px, 180px) minmax(160px, 1fr);
  gap: 8px;
}

.model-search,
.model-select,
.chip-select {
  min-width: 0;
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--soft);
  padding: 0 10px;
  outline: none;
}

.model-search:focus,
.model-select:focus,
.chip-select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.12);
}

.messages {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 26px;
}

.message-row {
  width: 100%;
  min-width: 0;
  display: flex;
  gap: 12px;
  margin-bottom: 22px;
}

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

.message-row.assistant {
  justify-content: flex-start;
}

.avatar {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(99, 102, 241, 0.12);
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
}

.bubble {
  max-width: min(780px, calc(100% - 64px));
  min-width: 0;
  border-radius: 12px;
  padding: 13px 15px;
  box-shadow: 0 4px 16px rgba(17, 24, 39, 0.06);
  line-height: 1.7;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-row.user .bubble {
  background: var(--user);
}

.message-row.assistant .bubble {
  background: var(--panel);
  border: 1px solid var(--line);
}

.msg-time {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.stream-cursor {
  display: inline-block;
  margin-left: 2px;
  color: var(--primary);
  animation: blink 0.8s steps(2, start) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.sources {
  margin-top: 12px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 6px;
}

.sources a,
.sources span {
  color: #3157c8;
  font-size: 13px;
  text-decoration: none;
}

.composer {
  min-width: 0;
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 14px 18px 16px;
}

.control-row {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.chip {
  height: 34px;
  border: 0;
  border-radius: 9px;
  background: var(--soft);
  color: #374151;
  padding: 0 12px;
  font-weight: 650;
}

.chip:hover {
  color: var(--primary);
}

.chip-select {
  width: 120px;
}

.spacer { flex: 1; }

.counter {
  color: var(--muted);
  font-size: 12px;
}

.input-shell {
  position: relative;
  min-width: 0;
}

#promptInput {
  width: 100%;
  min-height: 86px;
  max-height: 180px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 88px 13px 14px;
  line-height: 1.55;
  outline: none;
}

.send-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 56px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: var(--primary);
  font-weight: 800;
}

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

.blocked {
  width: 100vw;
  height: 100vh;
  display: grid;
  place-items: center;
  background: var(--bg);
}

.blocked-card {
  width: min(420px, 92vw);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 28px;
  text-align: center;
}

.blocked-card .mark {
  margin: 0 auto;
}

.blocked-card h1 {
  margin: 16px 0 8px;
  font-size: 22px;
}

.blocked-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.42);
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal {
  width: min(720px, 96vw);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 14px;
}

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

.modal-head h3 {
  margin: 0;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: var(--soft);
}

.modal-text {
  width: 100%;
  height: 230px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  resize: vertical;
  outline: none;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.save-btn {
  height: 38px;
  border: 0;
  border-radius: 9px;
  color: #fff;
  background: var(--primary);
  padding: 0 18px;
  font-weight: 800;
}

@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .chat-head {
    height: auto;
    align-items: stretch;
    flex-direction: column;
  }
  .head-actions { grid-template-columns: 1fr; }
  .bubble { max-width: 92vw; }
}

@media (min-width: 921px) and (max-width: 1180px) {
  .layout { grid-template-columns: 280px minmax(0, 1fr); }
  .chat-head {
    height: auto;
    align-items: stretch;
    flex-direction: column;
  }
  .head-actions {
    max-width: 100%;
    grid-template-columns: minmax(120px, 0.45fr) minmax(160px, 0.55fr);
  }
  .messages { padding: 20px 18px; }
}
