:root {
  --bg: #08090c;
  --panel: #0e1014;
  --panel-2: #14171d;
  --line: rgba(255,255,255,0.07);
  --txt: #f2f4f8;
  --dim: #9aa3b2;
  --faint: #8b94a5;
  --acc: #7aa2ff;
  --acc-soft: rgba(122,162,255,0.12);
  --user-bubble: #2b3c63;
  --radius: 14px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--txt);
  font-family: var(--font); font-size: 15px; line-height: 1.6;
  height: 100vh; height: 100dvh; overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  color-scheme: dark;
}
#app { display: flex; height: 100vh; height: 100dvh; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 300px; flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: calc(20px + env(safe-area-inset-top)) 14px 14px;
  transition: margin-left .25s ease, visibility 0s;
}
body.sb-hidden #sidebar {
  margin-left: -300px; visibility: hidden;
  transition: margin-left .25s ease, visibility 0s .25s;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 16px; }
.logo { width: 38px; height: 38px; flex-shrink: 0; }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { font-size: 11.5px; color: var(--faint); }
.search-wrap { padding: 0 2px 12px; }
#model-search {
  width: 100%; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px;
  color: var(--txt); font-family: var(--font); font-size: 16px;
  padding: 9px 12px; outline: none; transition: border-color .15s;
}
#model-search:focus { border-color: var(--acc); }
#model-search::placeholder { color: var(--faint); }
#providers { flex: 1; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.prov { margin-bottom: 14px; }
.prov > .pname {
  font-size: 10.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--faint);
  padding: 4px 10px 6px; display: flex; justify-content: space-between; align-items: center;
}
.prov > .pname .count { font-weight: 500; opacity: .7; }
.model {
  display: flex; align-items: center; gap: 9px; width: 100%;
  text-align: left; background: none; border: 1px solid transparent;
  color: var(--txt); padding: 8px 10px; border-radius: 10px;
  cursor: pointer; font-family: var(--font); font-size: 13.5px; font-weight: 500;
  transition: background .12s, border-color .12s;
}
.model:hover { background: var(--panel-2); }
.model.active { background: var(--acc-soft); border-color: rgba(122,162,255,0.35); }
.model .cdot { width: 7px; height: 7px; border-radius: 50%; background: #3ddc84; flex-shrink: 0; }
.model span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.foot { color: var(--faint); font-size: 11px; padding: 12px 8px 0; border-top: 1px solid var(--line); }
.loading { color: var(--dim); padding: 12px 8px; font-size: 13px; display: flex; align-items: center; gap: 10px; }
.spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--acc);
  animation: spin .7s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- main ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
#sidebar-toggle {
  position: absolute; top: calc(14px + env(safe-area-inset-top)); left: 14px; z-index: 60;
  width: 44px; height: 44px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel-2);
  box-shadow: 0 4px 16px rgba(0,0,0,.45);
  color: var(--dim); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: color .15s, border-color .15s;
}
#sidebar-toggle:hover { color: var(--txt); border-color: var(--acc); }

#chat { flex: 1; overflow-y: auto; padding: 28px 24px 12px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
#chat:not(:has(.msg)) { display: none; }
#chat-inner { max-width: 780px; margin: 0 auto; }
.msg { margin-bottom: 20px; animation: fadeUp .25s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg.user { text-align: right; }
.msg.user .bubble {
  background: var(--user-bubble); color: #fff;
  border-radius: 18px 18px 5px 18px; padding: 10px 16px;
  display: inline-block; max-width: 85%; white-space: pre-wrap; text-align: left;
  font-size: 14.5px; overflow-wrap: break-word; word-break: break-word;
}
.msg.assistant .who {
  font-size: 11.5px; font-weight: 600; color: var(--faint);
  margin-bottom: 6px; letter-spacing: 0.02em;
}
.msg.assistant .body { font-size: 14.5px; max-width: 100%; overflow-x: auto; overflow-wrap: break-word; }
.msg.assistant .body p { margin: 7px 0; }
.msg.assistant .body pre {
  background: var(--panel); border: 1px solid var(--line);
  padding: 14px; border-radius: 12px; overflow-x: auto; margin: 10px 0;
}
.msg.assistant .body code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 13px; }
.msg.assistant .body p code { background: var(--panel-2); padding: 2px 6px; border-radius: 6px; }
.msg.assistant .body ul, .msg.assistant .body ol { margin: 7px 0 7px 20px; }
.msg.assistant .body h1, .msg.assistant .body h2, .msg.assistant .body h3 { margin: 14px 0 7px; font-weight: 700; letter-spacing: -0.01em; }
.msg.assistant .body a { color: var(--acc); }
.msg.assistant .body table { border-collapse: collapse; margin: 10px 0; font-size: 13.5px; display: block; overflow-x: auto; max-width: 100%; }
.msg.assistant .body th, .msg.assistant .body td { border: 1px solid var(--line); padding: 7px 12px; text-align: left; white-space: nowrap; }
.msg.assistant .body th { background: var(--panel-2); font-weight: 600; }
.typing { display: inline-flex; gap: 5px; padding: 12px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* ---------- empty state ---------- */
#empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  padding: 24px; gap: 6px;
}
#empty.hidden { display: none; }
.empty-logo { width: 64px; height: 64px; margin-bottom: 14px; }
#empty h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.25; }
#empty p { color: var(--dim); font-size: 14.5px; margin-top: 8px; }

/* ---------- composer ---------- */
#composer { padding: 8px 24px calc(18px + env(safe-area-inset-bottom)); margin-top: auto; }
#composer-inner { max-width: 780px; margin: 0 auto; }
#current-model {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 600; color: var(--dim);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 13px; margin-bottom: 10px;
  max-width: 100%; cursor: pointer;
}
#current-model-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 62vw; }
.model-dot { width: 7px; height: 7px; border-radius: 50%; background: #3ddc84; }
.row {
  display: flex; gap: 10px; align-items: flex-end;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 20px; padding: 8px 8px 8px 18px;
  transition: border-color .15s, box-shadow .15s;
}
.row:focus-within { border-color: rgba(122,162,255,0.5); box-shadow: 0 0 0 3px rgba(122,162,255,0.12); }
#input {
  flex: 1; background: none; border: none; color: var(--txt);
  font-family: var(--font); font-size: 16px; line-height: 1.5;
  resize: none; outline: none; max-height: 160px; padding: 8px 0;
}
#input::placeholder { color: var(--faint); }
/* collapsible reasoning block */
details.thinking { margin-bottom: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
details.thinking summary {
  cursor: pointer; padding: 8px 14px; font-size: 12px; font-weight: 600;
  color: var(--faint); list-style: none; user-select: none;
}
details.thinking summary::-webkit-details-marker { display: none; }
details.thinking summary::before { content: '› '; display: inline-block; transition: transform .15s; }
details.thinking[open] summary::before { transform: rotate(90deg); }
details.thinking .tbody { padding: 0 14px 12px; font-size: 13px; color: var(--dim); max-height: 300px; overflow-y: auto; }
#send {
  width: 40px; height: 40px; flex-shrink: 0;
  border: none; border-radius: 50%;
  background: var(--acc); color: #0a0c10;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform .12s, opacity .12s;
}
#send:hover { transform: scale(1.06); }
#send:disabled { opacity: .35; cursor: default; transform: none; }
.hint { text-align: center; color: var(--faint); font-size: 11px; margin-top: 8px; }

@media (max-width: 700px) {
  #sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 50;
    width: 280px; max-width: 85vw; margin-left: 0;
    transform: translateX(0);
    transition: transform .25s ease, visibility 0s;
    box-shadow: 24px 0 60px rgba(0,0,0,.55);
  }
  body.sb-hidden #sidebar {
    transform: translateX(-105%); visibility: hidden; margin-left: 0;
    transition: transform .25s ease, visibility 0s .25s;
  }
  #chat { padding: 20px 16px 8px; }
  #composer { padding: 8px 14px calc(14px + env(safe-area-inset-bottom)); }
  #empty h1 { font-size: 24px; }
  .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
