:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c222b;
  --border: #30363d;
  --text: #c9d1d9;
  --muted: #7d8590;
  --accent: #2f81f7;
  --accent-hover: #1f6feb;
  --ok: #3fb950;
  --err: #f85149;
  --warn: #d29922;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI",
        Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  overflow: hidden;
}

/* ---------- sidebar ---------- */
#sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 16px 12px;
  gap: 12px;
}
.brand {
  font-weight: 600; font-size: 15px; letter-spacing: 0.3px;
  padding: 0 4px 6px; color: var(--muted);
}
#conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.conv-item {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 10px; border-radius: 6px;
  cursor: pointer; color: var(--text);
  border: 1px solid transparent;
  white-space: nowrap;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--surface-2); border-color: var(--border); }
.conv-item .title {
  flex: 1; overflow: hidden; text-overflow: ellipsis;
  font-size: 13px;
}
.conv-item .del {
  opacity: 0; transition: opacity 0.1s;
  background: transparent; border: 0; color: var(--muted);
  cursor: pointer; font-size: 14px; padding: 2px 6px;
}
.conv-item:hover .del, .conv-item.active .del { opacity: 1; }
.conv-item .del:hover { color: var(--err); }
.sidebar-footer {
  padding-top: 10px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--muted);
}
.sidebar-footer a { color: var(--muted); text-decoration: none; }
.sidebar-footer a:hover { color: var(--text); }

/* ---------- main ---------- */
#main {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0;
}
#header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.conv-title {
  flex: 1; font-weight: 600; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.controls { display: flex; align-items: center; gap: 8px; }

select, button, input[type="text"], textarea {
  font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 10px;
}
select:focus, textarea:focus, input:focus {
  outline: none; border-color: var(--accent);
}
button { cursor: pointer; }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: white;
  font-weight: 500;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-danger {
  background: transparent; border-color: var(--border); color: var(--err);
}
.btn-danger:hover { background: rgba(248, 81, 73, 0.12); }

/* ---------- messages ---------- */
#messages {
  flex: 1; overflow-y: auto;
  padding: 16px 0;
}
.msg {
  max-width: 860px; margin: 0 auto; padding: 10px 24px;
  display: flex; gap: 14px;
}
.msg .avatar {
  flex-shrink: 0; width: 28px; height: 28px;
  border-radius: 6px; display: flex;
  align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
  border: 1px solid var(--border);
}
.msg.user .avatar { background: var(--surface-2); color: var(--muted); }
.msg.assistant .avatar { background: var(--accent); border-color: var(--accent); color: white; }
.msg.error .avatar { background: rgba(248,81,73,0.2); border-color: var(--err); color: var(--err); }
.msg .body { min-width: 0; flex: 1; white-space: pre-wrap; word-wrap: break-word; padding-top: 4px; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 6px; }
.msg.error .body { color: var(--err); }
.msg.pending .body::after {
  content: "▋"; color: var(--muted); animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- meter + input ---------- */
#meter {
  font-size: 11px; color: var(--muted);
  text-align: center; padding: 4px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
#input-form {
  display: flex; gap: 8px; padding: 14px 20px 20px;
  background: var(--surface); border-top: 1px solid var(--border);
}
#input {
  flex: 1; resize: none; padding: 10px 14px;
  font: inherit; line-height: 1.5;
  min-height: 42px; max-height: 240px;
}
#send { padding: 10px 20px; }

/* ---------- settings panel ---------- */
#settings-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 360px;
  background: var(--surface); border-left: 1px solid var(--border);
  padding: 20px; display: flex; flex-direction: column; gap: 16px;
  z-index: 10; box-shadow: -4px 0 24px rgba(0,0,0,0.4);
}
/* Higher specificity than the rule above so `hidden` actually hides.
   Without this, `display: flex` wins and the panel stays open. */
#settings-panel[hidden] { display: none; }
#model { min-width: 90px; }
.panel-head { display: flex; align-items: center; }
.panel-head h3 { flex: 1; margin: 0; }
.panel-head button {
  background: transparent; border: 0; font-size: 22px; color: var(--muted);
  padding: 0 6px;
}
.panel-head button:hover { color: var(--text); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
label.toggle { flex-direction: row; align-items: center; gap: 8px; }
label.toggle input { margin: 0; }
label textarea { color: var(--text); }
.note { font-size: 11px; color: var(--muted); font-style: italic; margin: 0; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 16px; font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  z-index: 20;
}
#toast.error { border-color: var(--err); color: var(--err); }

/* ---------- empty state ---------- */
.empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--muted); gap: 8px; padding: 40px 20px;
  text-align: center;
}
.empty h2 { color: var(--text); margin: 0; font-weight: 500; }
.empty p { margin: 0; max-width: 420px; font-size: 13px; }
