:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e232b;
  --border: #2a303a;
  --text: #e6e9ee;
  --muted: #8b93a1;
  --accent: #4f8cff;
  --user-bubble: #2b3b57;
  --bubble: #1e232b;
  --code-bg: #0b0d11;
  --active-bg: #2a3b57;
  --active-text: #ffffff;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --panel-2: #eef1f5;
    --border: #d7dce3;
    --text: #1a1d23;
    --muted: #5b6470;
    --accent: #2f6fed;
    --user-bubble: #dbe7ff;
    --bubble: #eef1f5;
    --code-bg: #f0f2f5;
    --active-bg: #cfe0ff;
    --active-text: #0d1b2e;
  }
}


* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#app { display: flex; height: 100vh; }

/* ── Sidebar ─────────────────────────────── */
#sidebar {
  width: 300px;
  min-width: 240px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-head {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.new-chat { flex: 1; background: var(--accent); border: 0; color: #fff; padding: 9px 0; border-radius: 8px; cursor: pointer; font-weight: 600; }
.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); border-radius: 8px; padding: 0 10px; cursor: pointer; }
.ghost:hover { color: var(--text); }

#chat-list { flex: 1; overflow-y: auto; padding: 6px; }
.group-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 12px 8px 4px; }
.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 13px;
  padding: 5px 8px;
  margin-bottom: 1px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.chat-item > span { overflow: hidden; text-overflow: ellipsis; }
.chat-item:hover, .chat-item:focus-visible { background: var(--panel-2); outline: none; }
.chat-item.active { background: var(--active-bg); color: var(--active-text); }
.chat-del { background: none; border: 0; color: inherit; cursor: pointer; padding: 0 2px; opacity: 0; flex: none; }
.chat-item:hover .chat-del, .chat-item.active .chat-del, .chat-del:focus-visible { opacity: .7; }
.chat-del:hover { opacity: 1; }
.sort-row { display: flex; align-items: center; gap: 10px; padding: 6px 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); }
.sort-label { text-transform: uppercase; letter-spacing: .05em; }
.segmented { display: inline-flex; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; gap: 2px; }
.seg { position: relative; cursor: pointer; padding: 3px 12px; border-radius: 6px; font-size: 12px; color: var(--muted); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg:hover { color: var(--text); }
.seg:has(input:checked) { background: var(--accent); color: #fff; }
.sidebar-foot { padding: 6px 12px; border-top: 1px solid var(--border); }
#admin-link { font-size: 12px; color: var(--muted); text-decoration: none; }
#admin-link:hover { color: var(--text); }
.chat-item.editing { background: var(--panel-2); padding: 2px; }
.title-edit { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--accent); color: var(--text); border-radius: 6px; padding: 4px 6px; font-size: 13px; }
.regen { flex: none; background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 15px; padding: 0 4px; }
.regen:hover { color: var(--text); }
.regen:disabled { opacity: .4; cursor: not-allowed; }

/* ── Chat area ───────────────────────────── */
#chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#messages { flex: 1; overflow-y: auto; padding: 24px 20px; }
.chat-title { font-size: 20px; font-weight: 700; margin: 0 0 18px; }

.chat-title-row { display: flex; align-items: center; gap: 8px; margin: 4px 0 18px; }
.chat-title-input { flex: 1; min-width: 0; background: transparent; border: 1px solid transparent; color: var(--text); font-size: 20px; font-weight: 700; border-radius: 8px; padding: 4px 8px; }
.chat-title-input:hover { border-color: var(--border); }
.chat-title-input:focus { outline: none; border-color: var(--accent); background: var(--panel); }
.chat-regen { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 18px; opacity: 0; padding: 4px; }
.chat-title-row:hover .chat-regen, .chat-regen:focus-visible, .chat-title-input:focus + .chat-regen { opacity: 1; }
.chat-regen:hover { color: var(--accent); }

.msg { display: flex; margin-bottom: 18px; }
.msg .bubble { max-width: 78%; padding: 10px 14px; border-radius: 12px; white-space: normal; overflow-wrap: anywhere; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--user-bubble); }
.msg.assistant { justify-content: flex-start; }
.msg.assistant .bubble { background: var(--bubble); }
.msg .meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.msg-actions { display: inline-flex; align-items: center; gap: 2px; opacity: 0; transition: opacity .12s; }
.msg:hover .msg-actions, .msg.selected .msg-actions { opacity: 1; }
.msg-actions button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 4px; font-size: 12px; line-height: 1; }
.msg-actions button:hover { color: var(--text); }
.copied { font-size: 11px; color: var(--accent); margin-right: 2px; }

/* muted title notice injected at the start of a conversation */
.msg.system { justify-content: center; }
.title-notice { font-size: 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 4px 12px; max-width: 80%; text-align: center; }

/* reasoning: muted, smaller, expanded by default, separated by an hr */
.reasoning { font-size: 12.5px; color: var(--muted); }
.reasoning summary { cursor: pointer; font-style: italic; font-size: 12px; }
.reasoning-body { margin-top: 6px; }
.reasoning-body p { margin: 4px 0; }
.reasoning-body pre, .reasoning-body code { font-size: 12px; }
.reason-hr { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }
.content { white-space: pre-wrap; }

/* markdown */
.bubble pre { background: var(--code-bg); padding: 10px; border-radius: 8px; overflow-x: auto; }
.bubble code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.bubble pre code { padding: 0; background: none; }
.bubble a { color: var(--accent); }
.bubble hr { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }
.bubble ul, .bubble ol { margin: 4px 0; padding-left: 24px; }
.bubble li { margin: 2px 0; }
.bubble table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
  width: 100%;
  display: table;
  table-layout: auto;
}
.bubble th, .bubble td {
  border: 1px solid var(--border);
  padding: 5px 10px;
  text-align: left;
  min-width: 2em;
  word-break: normal;
  overflow-wrap: normal;
  hyphens: none;
}
.bubble th { background: var(--panel-2); font-weight: 600; }

/* ── Composer ────────────────────────────── */
#composer { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--border); background: var(--panel); }
#menu { display: none; background: none; border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 0 12px; font-size: 18px; cursor: pointer; }
#input { flex: 1; resize: none; background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 11px 12px; max-height: 200px; }
#send { background: var(--accent); border: 0; color: #fff; border-radius: 10px; padding: 0 18px; cursor: pointer; font-weight: 600; }
#send:disabled { opacity: .5; cursor: not-allowed; }

/* ── Login ───────────────────────────────── */
.auth-body { display: flex; align-items: center; justify-content: center; }
.auth-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 32px; width: 340px; }
.auth-card h1 { margin: 0 0 4px; }
.auth-sub { color: var(--muted); margin: 0 0 20px; }
.auth-error { background: #4b1d1d; color: #ffb4b4; padding: 8px 10px; border-radius: 8px; margin-bottom: 16px; }
.auth-form { display: flex; flex-direction: column; gap: 6px; }
.auth-form input { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 10px 12px; }
.auth-form button { margin-top: 12px; background: var(--accent); border: 0; color: #fff; padding: 11px; border-radius: 8px; cursor: pointer; font-weight: 600; }

@media (max-width: 768px) {
  #sidebar { width: 240px; }
  #menu { display: inline-flex; }
  #sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  body.sidebar-open #sidebar { transform: translateX(0); box-shadow: 0 0 30px rgba(0,0,0,.4); }
}

