[hidden] { display: none !important; }
:root {
  --font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --accent: #ff5a4e;
  --accent-2: #ff7a3d;
  --radius: 22px;
  --sidebar-w: 260px;
}
[data-theme="dark"] {
  --bg: #212121; --bg-side: #171717; --bg-elev: #2f2f2f; --bg-hover: #2a2a2a; --bg-active: #303030;
  --text: #ececec; --text-2: #b4b4b4; --text-3: #8e8e8e; --border: #3a3a3a; --bubble: #303030;
  --code-bg: #0d0d0d; --chip: #2a2a2a; --shadow: 0 0 0 1px rgba(255,255,255,.06), 0 8px 24px rgba(0,0,0,.35);
}
[data-theme="light"] {
  --bg: #ffffff; --bg-side: #f9f9f9; --bg-elev: #ffffff; --bg-hover: #ececec; --bg-active: #e3e3e3;
  --text: #0d0d0d; --text-2: #5d5d5d; --text-3: #8f8f8f; --border: #e5e5e5; --bubble: #f1f1f1;
  --code-bg: #f6f6f6; --chip: #f3f3f3; --shadow: 0 0 0 1px rgba(0,0,0,.08), 0 6px 20px rgba(0,0,0,.08);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.65 var(--font); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; }

.app { display: flex; height: 100dvh; overflow: hidden; }

/* ---------- Sidebar ---------- */
.sidebar { width: var(--sidebar-w); flex-shrink: 0; background: var(--bg-side); display: flex; flex-direction: column; padding: 8px; gap: 4px; transition: margin .25s ease, transform .25s ease; }
.app.sb-hidden .sidebar { margin-left: calc(-1 * var(--sidebar-w)); }
.sb-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 6px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 10px; font-weight: 650; font-size: 17px; }
.brand:hover { background: var(--bg-hover); }
.logo { width: 26px; height: 26px; }
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; color: var(--text-2); }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.new-chat { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; font-size: 14.5px; }
.new-chat:hover { background: var(--bg-hover); }
.sb-search input { width: 100%; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border); background: transparent; color: var(--text); font: inherit; font-size: 14px; outline: none; }
.sb-search input:focus { border-color: var(--text-3); }
.chat-list { flex: 1; overflow-y: auto; margin-top: 6px; padding-right: 2px; }
.chat-group { font-size: 12px; color: var(--text-3); font-weight: 600; padding: 14px 12px 6px; }
.chat-item { position: relative; display: flex; align-items: center; border-radius: 10px; }
.chat-item a { flex: 1; min-width: 0; padding: 8px 12px; font-size: 14px; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); border-radius: 10px; }
.chat-item:hover, .chat-item.active { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-active); }
.chat-item .del { opacity: 0; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; color: var(--text-3); margin-right: 4px; }
.chat-item:hover .del, .chat-item.active .del { opacity: 1; }
.chat-item .del:hover { color: #ef4444; }
.sb-bottom { border-top: 1px solid var(--border); padding-top: 6px; display: flex; flex-direction: column; gap: 2px; }
.sb-link { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px; font-size: 14px; color: var(--text-2); text-align: left; }
.sb-link:hover { background: var(--bg-hover); color: var(--text); }
.credit { font-size: 12px; color: var(--text-3); text-decoration: none; padding: 10px 12px 4px; }
.credit strong { color: var(--text-2); font-weight: 600; }
.credit:hover strong { color: var(--accent); }
.scrim { display: none; }

/* ---------- Main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.topbar { height: 56px; display: flex; align-items: center; justify-content: space-between; padding: 0 10px; flex-shrink: 0; }
.topbar .title { font-weight: 600; font-size: 17px; display: flex; align-items: center; gap: 8px; color: var(--text-2); }
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: #fff; }
#openSidebar { visibility: hidden; }
.app.sb-hidden #openSidebar { visibility: visible; }

.thread { flex: 1; overflow-y: auto; padding: 8px 16px 24px; scroll-behavior: smooth; }
.msg { max-width: 768px; margin: 0 auto 26px; display: flex; gap: 14px; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--bubble); padding: 10px 18px; border-radius: 22px; max-width: 75%; white-space: pre-wrap; word-wrap: break-word; }
.msg.assistant .avatar { width: 30px; height: 30px; flex-shrink: 0; margin-top: 2px; }
.msg.assistant .body { flex: 1; min-width: 0; }

.status { display: flex; align-items: center; gap: 10px; color: var(--text-2); font-size: 15px; padding: 2px 0 8px; }
.status .dots { display: inline-flex; gap: 4px; }
.status .dots i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: blink 1.2s infinite both; }
.status .dots i:nth-child(2) { animation-delay: .2s; } .status .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.shimmer { background: linear-gradient(90deg, var(--text-3) 0%, var(--text) 50%, var(--text-3) 100%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 1.6s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* sources strip */
.sources { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.src { flex: 0 0 auto; max-width: 220px; display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; background: var(--chip); border-radius: 12px; text-decoration: none; font-size: 12.5px; line-height: 1.35; border: 1px solid transparent; }
.src:hover { border-color: var(--border); }
.src .t { color: var(--text); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.src .h { color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.src .n { font-weight: 700; color: var(--text-2); }

/* markdown */
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 14px; }
.md h3, .md h4 { margin: 20px 0 8px; font-size: 16.5px; font-weight: 650; }
.md ul, .md ol { margin: 0 0 14px; padding-left: 24px; }
.md li { margin: 6px 0; }
.md blockquote { margin: 0 0 14px; padding: 10px 16px; border-left: 3px solid var(--accent); background: var(--chip); border-radius: 0 12px 12px 0; }
.md code { font-family: var(--mono); font-size: .88em; background: var(--code-bg); padding: 2px 6px; border-radius: 6px; }
.md a { color: var(--text); text-decoration: underline; text-decoration-color: var(--text-3); text-underline-offset: 3px; }
.md a.cite { display: inline-grid; place-items: center; min-width: 20px; height: 18px; padding: 0 5px; margin-left: 2px; font-size: 11px; font-weight: 600; text-decoration: none; background: var(--chip); color: var(--text-2); border-radius: 9px; vertical-align: 2px; line-height: 1; border: 1px solid var(--border); }
.md a.cite:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.caret::after { content: ""; display: inline-block; width: 9px; height: 9px; background: var(--text); border-radius: 50%; margin-left: 4px; vertical-align: middle; animation: blink 1s infinite; }

.actions { display: flex; gap: 2px; margin-top: 8px; color: var(--text-3); align-items: center; }
.actions button { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; }
.actions button:hover { background: var(--bg-hover); color: var(--text); }
.actions .meta { font-size: 12px; margin-left: 8px; }
.error-box { color: #f87171; background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3); padding: 10px 14px; border-radius: 12px; font-size: 14.5px; }

/* welcome */
.welcome { max-width: 768px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px 0 40px; }
.welcome-logo { width: 56px; height: 56px; margin-bottom: 16px; }
.welcome-title { font-size: 28px; font-weight: 600; margin: 0 0 6px; letter-spacing: -.01em; }
.welcome-sub { color: var(--text-2); margin: 0 0 28px; }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: 100%; }
.suggestion { text-align: left; padding: 14px 16px; border: 1px solid var(--border); border-radius: 16px; font-size: 14px; color: var(--text-2); transition: background .15s; }
.suggestion strong { display: block; color: var(--text); font-weight: 600; margin-bottom: 2px; }
.suggestion:hover { background: var(--bg-hover); }

/* composer */
.composer-wrap { padding: 0 16px 10px; flex-shrink: 0; }
.composer { max-width: 768px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; background: var(--bg-elev); border-radius: var(--radius); padding: 10px 10px 10px 20px; box-shadow: var(--shadow); }
[data-theme="dark"] .composer { background: #303030; }
.composer textarea { flex: 1; resize: none; border: 0; outline: none; background: transparent; color: var(--text); font: inherit; max-height: 200px; padding: 6px 0; line-height: 1.5; }
.composer textarea::placeholder { color: var(--text-3); }
.send { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--text); color: var(--bg); flex-shrink: 0; transition: opacity .15s; }
.send:disabled { opacity: .3; cursor: default; }
.send .i-stop { display: none; }
.busy .send .i-send { display: none; } .busy .send .i-stop { display: block; }
.busy .send:disabled { opacity: 1; cursor: pointer; }
.disclaimer { text-align: center; color: var(--text-3); font-size: 12px; margin: 8px 0 0; }

.toast { position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 10px; font-size: 14px; z-index: 50; animation: fade 2s forwards; }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

/* mobile */
@media (max-width: 800px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; transform: translateX(-100%); margin: 0 !important; box-shadow: var(--shadow); }
  .app.sb-open .sidebar { transform: none; }
  .app.sb-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
  #openSidebar { visibility: visible; }
  .suggestions { grid-template-columns: 1fr; }
  .msg.user .bubble { max-width: 88%; }
  .welcome-title { font-size: 24px; }
}
::-webkit-scrollbar { width: 8px; height: 8px; } ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

/* tables (local listings) */
.table-wrap { overflow-x: auto; margin: 0 0 14px; border: 1px solid var(--border); border-radius: 12px; }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; }
.md th, .md td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.md th { background: var(--chip); font-weight: 600; }
.md tr:last-child td { border-bottom: 0; }

/* Deep dive toggle */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-2); font-size: 13.5px; white-space: nowrap; flex-shrink: 0; transition: all .15s; }
.pill:hover { color: var(--text); background: var(--bg-hover); }
.pill[aria-pressed="true"] { color: #fff; background: linear-gradient(135deg, var(--accent-2), var(--accent)); border-color: transparent; }
.md h3 { border-top: 1px solid var(--border); padding-top: 14px; }
.md > h3:first-child { border-top: 0; padding-top: 0; }
.actions .deep-tag { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--text-2); margin-left: 6px; }
a.sb-link { text-decoration: none; }
/* Embed mode (chat widget inside other websites) */
.embed-credit { display: none; }
body.embed .sidebar, body.embed .scrim, body.embed #openSidebar, body.embed .disclaimer { display: none !important; }
body.embed .topbar { height: 48px; border-bottom: 1px solid var(--border); }
body.embed .thread { padding: 12px 12px 16px; }
body.embed .msg { gap: 10px; margin-bottom: 18px; }
body.embed .welcome-title { font-size: 21px; }
body.embed .suggestions { grid-template-columns: 1fr; }
body.embed .composer-wrap { padding: 0 10px 8px; }
body.embed .embed-credit { display: block; text-align: center; font-size: 11.5px; margin: 6px 0 0; }
body.embed .embed-credit a { color: var(--text-3); text-decoration: none; }
@media (max-width: 520px) { .pill span { display: none; } .pill { padding: 6px 8px; } }
