:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1e2230;
  --border: #2a2f3e;
  --text: #e6e9ef;
  --muted: #8b93a7;
  --accent: #6c8cff;
  --user: #2b3a67;
  --assistant: #1b1f2b;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 900px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand { font-weight: 600; letter-spacing: 0.5px; }

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

select, input, textarea, button {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  outline: none;
}

select:focus, input:focus, textarea:focus { border-color: var(--accent); }

button {
  cursor: pointer;
  background: var(--panel-2);
  transition: background 0.15s;
}
button:hover { background: #2a3142; }
button:active { transform: translateY(1px); }

.panel {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.hidden { display: none !important; }

.param-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px 18px;
  align-items: center;
}

.param-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.param-grid label.checkbox { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.param-grid input[type="range"] { width: 100%; padding: 0; }
.param-grid input[type="number"] { width: 100%; }
.param-grid select { width: 100%; }

.param-grid .val { color: var(--accent); font-weight: 600; }
.param-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; }

.tpl-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tpl-toolbar select { flex: 1; min-width: 160px; }
.hint { color: var(--muted); font-size: 12px; }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg { display: flex; flex-direction: column; max-width: 85%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }

.role-label { font-size: 11px; color: var(--muted); margin: 0 4px 4px; }

.bubble {
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user .bubble { background: var(--user); border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: var(--assistant); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.streaming::after { content: "▋"; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.composer {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}
#input { flex: 1; resize: none; height: 52px; line-height: 1.4; }
#sendBtn { align-self: stretch; padding: 0 22px; background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
#sendBtn:hover { background: #5a78f0; }

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  width: min(520px, 92vw);
  display: flex; flex-direction: column; gap: 12px;
}
.modal-box h3 { margin: 0 0 4px; }
.modal-box label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.modal-box input, .modal-box textarea, .modal-box select { width: 100%; }
.modal-box textarea { resize: vertical; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
#tempVal, #maxtokVal { color: var(--accent); }
#modelInfo { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
#modelInfo::before { content: "ℹ "; color: var(--accent); }
