:root {
  --bg: #0b1226; --side: #0e1730; --card: #14203d; --card2: #19284a; --line: #23345c; --ink: #eaf1ff; --muted: #94a3c2;
  --blue: #2a7bff; --red: #ff4a4a; --user: #1f4fb5; --ring: #2a7bff55;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f7f5f0; --side: #f0ede6; --card: #ffffff; --card2: #f3f0ea; --line: #ddd8cc; --ink: #1d2433; --muted: #6b7384;
  --user: #e7edfb; --ring: #2a7bff40;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.shell { display: flex; height: 100dvh; }

/* ---- sidebar */
.side { width: 288px; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 10px 10px; transition: margin-left .2s; flex: none; }
.shell.closed .side { margin-left: -288px; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 12px; }
.logo { display: flex; align-items: center; gap: 9px; color: var(--ink); text-decoration: none; font-size: 1.3rem; font-weight: 700; letter-spacing: -.01em; }
.logo b { color: var(--red); }
.icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; color: var(--muted); }
.icon:hover { background: var(--card2); color: var(--ink); }
.icon[aria-pressed="true"] { background: var(--blue); color: #fff; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.nav { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 10px; border-radius: 12px; text-align: left; }
.nav:hover { background: var(--card2); }
.nav .plus { width: 26px; height: 26px; border-radius: 50%; background: var(--card2); display: grid; place-items: center; }
.nav .plus svg { width: 16px; height: 16px; }
.nav:first-child { background: var(--card); border: 1px solid var(--line); }
.searchbox { padding: 6px 4px; }
.searchbox input { width: 100%; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.searchbox input:focus, textarea:focus { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.hist-title { color: var(--muted); font-size: .8rem; padding: 16px 12px 6px; }
.hist { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; min-height: 0; }
.hist .none { color: var(--muted); text-align: center; padding: 28px 12px; font-size: .92rem; }
.chat-item { display: flex; align-items: center; gap: 4px; border-radius: 10px; }
.chat-item:hover, .chat-item.on { background: var(--card2); }
.chat-item .t { flex: 1; text-align: left; padding: 8px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .95rem; }
.chat-item .x { width: 30px; height: 30px; display: none; place-items: center; color: var(--muted); border-radius: 8px; }
.chat-item:hover .x { display: grid; } .chat-item .x:hover { color: var(--red); }
.side-bottom { position: relative; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 6px; }
.user { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border-radius: 12px; text-align: left; }
.user:hover { background: var(--card2); }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: linear-gradient(135deg, var(--blue), #1448b8); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; overflow: hidden; }
.uinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.uinfo b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .uinfo small { color: var(--muted); }
.chev { color: var(--muted); }
.menu { position: absolute; left: 4px; right: 4px; bottom: 64px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 6px; box-shadow: 0 10px 30px #0006; display: flex; flex-direction: column; z-index: 5; }
.menu button, .menu a { text-align: left; padding: 9px 12px; border-radius: 9px; color: var(--ink); text-decoration: none; }
.menu button:hover, .menu a:hover { background: var(--card2); }

/* ---- main */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.mtop { display: flex; align-items: center; padding: 10px 14px; gap: 8px; }
.mtop .spacer { flex: 1; }
#burger { display: none; }
.banner { background: linear-gradient(90deg, #2a7bff2e, #ff4a4a2e); border-block: 1px solid var(--line); text-align: center; padding: 8px 16px; font-size: .92rem; }
.banner.priv { background: var(--card2); }
.scroll { flex: 1; overflow-y: auto; display: flex; flex-direction: column; min-height: 0; }
.main.empty { justify-content: center; }
.main.empty .scroll { flex: 0 0 auto; overflow: visible; }
.main.empty .mtop { position: absolute; inset: 0 0 auto 0; }
.home { display: none; text-align: center; padding: 0 20px 8px; }
.main.empty .home { display: block; }
.main.empty .thread { display: none; }
.pill { display: inline-block; background: var(--card2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 14px; color: var(--muted); font-size: .9rem; margin-bottom: 22px; }
.pill:hover { border-color: var(--blue); }
.pill u { color: var(--ink); text-underline-offset: 3px; }
.hello { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 0 0 6px; font-weight: 500; font-size: clamp(1.9rem, 4.6vw, 2.9rem); letter-spacing: -.02em; font-family: Georgia, "Times New Roman", serif; }
.sub { color: var(--muted); margin: 0 0 14px; }

.thread { width: min(760px, 100%); margin: 0 auto; padding: 8px 18px 20px; display: flex; flex-direction: column; gap: 18px; }
.msg { overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); border-radius: 18px 18px 4px 18px; padding: 10px 16px; max-width: 85%; white-space: pre-wrap; }
.msg.bot { display: flex; gap: 12px; align-items: flex-start; }
.msg.bot img { margin-top: 3px; flex: none; }
.msg.bot .body { flex: 1; min-width: 0; }
.msg.err .body { color: #ff9a9a; }
.body p { margin: 0 0 10px; } .body p:last-child { margin-bottom: 0; }
.body code { background: var(--card2); padding: 1px 6px; border-radius: 6px; font: .9em ui-monospace, Consolas, monospace; }
.body pre { background: var(--card); border: 1px solid var(--line); padding: 12px 14px; border-radius: 12px; overflow-x: auto; margin: 8px 0; }
.body pre code { background: none; padding: 0; }
.dots::after { content: "●●●"; letter-spacing: 3px; color: var(--muted); animation: blink 1.1s infinite; }
@keyframes blink { 50% { opacity: .25; } }

.dock { width: min(760px, 100%); margin: 0 auto; padding: 0 16px 10px; }
.notice { border: 1px solid var(--red); background: #ff4a4a18; padding: 10px 14px; border-radius: 12px; margin-bottom: 10px; }
.notice button { color: var(--blue); text-decoration: underline; }
.composer { background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 14px 14px 10px 18px; box-shadow: 0 2px 14px #0003; transition: box-shadow .15s, border-color .15s; }
.composer:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px var(--ring); }
textarea { width: 100%; font: inherit; color: var(--ink); background: none; border: 0; resize: none; max-height: 40vh; padding: 0; }
textarea:focus { box-shadow: none; }
textarea::placeholder { color: var(--muted); }
.comp-row { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 10px; }
.modelpick { position: relative; }
.modelbtn { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 10px; color: var(--muted); }
.modelbtn:hover { background: var(--card2); color: var(--ink); }
.modelbtn svg { width: 16px; height: 16px; }
.modellist { position: absolute; right: 0; bottom: 42px; min-width: 250px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 6px; box-shadow: 0 10px 30px #0006; z-index: 6; }
.modellist button { display: flex; flex-direction: column; align-items: flex-start; width: 100%; padding: 9px 12px; border-radius: 9px; text-align: left; }
.modellist button:hover, .modellist button.on { background: var(--card2); }
.modellist small { color: var(--muted); }
.send { width: 38px; height: 38px; border-radius: 12px; background: var(--blue); color: #fff; display: grid; place-items: center; }
.send:hover { filter: brightness(1.12); } .send:disabled { opacity: .4; cursor: not-allowed; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.main:not(.empty) .chips { display: none; }
.chip { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); }
.chip:hover { border-color: var(--blue); background: var(--card2); }
.chip svg { width: 18px; height: 18px; color: var(--muted); }
.foot { margin: 10px 0 0; text-align: center; color: var(--muted); font-size: .78rem; }

.scrim { display: none; }
@media (max-width: 800px) {
  .side { position: fixed; inset: 0 auto 0 0; z-index: 20; margin-left: -300px; box-shadow: 8px 0 30px #0008; }
  .shell.mopen .side { margin-left: 0; }
  .shell.mopen .scrim { display: block; position: fixed; inset: 0; background: #0006; z-index: 15; }
  .shell.closed .side { margin-left: -300px; }
  #burger { display: grid; } #open { display: none !important; }
  .msg.user { max-width: 94%; }
}
.caret { display: inline-block; width: 8px; height: 1.05em; margin-left: 2px; vertical-align: text-bottom; background: var(--ink); border-radius: 2px; animation: blink 1s steps(2) infinite; }
