@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #071014;
  --bg-deep: #050b0e;
  --glass: rgba(14, 28, 32, .68);
  --glass-strong: rgba(18, 38, 42, .82);
  --line: rgba(182, 238, 229, .13);
  --line-strong: rgba(182, 238, 229, .26);
  --text: #effdfa;
  --muted: #91aaa9;
  --accent: #51d5c3;
  --accent-strong: #20b8a6;
  --accent-soft: rgba(81, 213, 195, .12);
  --danger: #ff8e8e;
  --user: rgba(48, 91, 93, .62);
  --radius: 18px;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg-deep);
  color: var(--text);
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
body::before, body::after { content: ''; position: fixed; z-index: -1; border-radius: 50%; filter: blur(1px); pointer-events: none; }
body::before { width: 42vw; height: 42vw; top: -24vw; left: 18%; background: rgba(21, 128, 119, .22); box-shadow: 0 0 150px rgba(21,128,119,.18); }
body::after { width: 32vw; height: 32vw; right: -16vw; bottom: -12vw; background: rgba(72, 93, 198, .17); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
svg { width: 18px; height: 18px; display: block; }
button, select, textarea { font: inherit; }
button, .chip, .chat-item { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.app { display: grid; grid-template-columns: 286px 1fr; height: 100dvh; padding: 14px; gap: 14px; }
.sidebar, .topbar, .composer { background: var(--glass); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); }
.sidebar { display: flex; flex-direction: column; min-height: 0; border: 1px solid var(--line); border-radius: 24px; padding: 18px 14px; gap: 16px; box-shadow: 0 18px 60px rgba(0,0,0,.2); }
.brand { display: flex; align-items: center; gap: 11px; padding: 2px 6px 8px; }
.brand-badge { width: 34px; height: 34px; border-radius: 12px; background: linear-gradient(145deg, var(--accent), #239c9d); color: #062421; display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 24px rgba(81,213,195,.2); }
.brand-badge svg { width: 17px; height: 17px; }
.brand-name { font-weight: 800; letter-spacing: -.3px; }
.btn-new { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px; border: 1px solid var(--line-strong); border-radius: 13px; background: linear-gradient(135deg, rgba(81,213,195,.16), rgba(81,213,195,.05)); color: var(--text); font-size: 14px; font-weight: 700; transition: .2s ease; }
.btn-new:hover { border-color: var(--accent); transform: translateY(-1px); background: var(--accent-soft); }
.btn-new svg { width: 17px; height: 17px; color: var(--accent); }
.history-scroll { flex: 1; overflow-y: auto; min-height: 0; }
.history-scroll::-webkit-scrollbar, .messages::-webkit-scrollbar { width: 6px; }
.history-scroll::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; }
.chat-list { display: flex; flex-direction: column; gap: 5px; }
.chat-item { display: flex; align-items: center; gap: 8px; min-height: 42px; padding: 9px 10px; border-radius: 12px; color: var(--muted); font-size: 13px; border: 1px solid transparent; transition: .18s ease; }
.chat-item:hover { background: rgba(255,255,255,.055); color: var(--text); }
.chat-item.active { background: var(--accent-soft); color: var(--text); border-color: rgba(81,213,195,.34); }
.chat-item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .del { opacity: 0; visibility: hidden; border: none; background: none; color: var(--muted); cursor: pointer; padding: 5px; }
.chat-item:hover .del, .chat-item:focus-within .del { opacity: 1; visibility: visible; }
.chat-item .del:hover { color: var(--danger); }
.chat-item .del svg { width: 15px; height: 15px; }
.empty-hint { display: none; flex-direction: column; align-items: center; gap: 8px; padding: 34px 0; color: var(--muted); font-size: 13px; }
.chat-list.empty .empty-hint { display: flex; }
.empty-hint svg { width: 27px; height: 27px; opacity: .55; color: var(--accent); }
.sidebar-foot { border-top: 1px solid var(--line); padding: 16px 2px 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row-label { font-size: 12px; color: var(--muted); }
.select { max-width: 176px; min-height: 36px; background: rgba(3,13,16,.5); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 6px 9px; font-size: 12px; }

.main { display: flex; flex-direction: column; min-height: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 24px; background: rgba(7,16,20,.4); box-shadow: 0 18px 60px rgba(0,0,0,.18); }
.topbar { display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.chat-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 700; letter-spacing: -.2px; }
.icon-btn { display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 12px; background: transparent; border: 1px solid transparent; color: var(--muted); cursor: pointer; transition: .18s ease; }
.icon-btn:hover { background: rgba(255,255,255,.06); color: var(--text); border-color: var(--line); }
.sidebar-toggle { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 34px 0; }
.msg { max-width: 850px; margin: 0 auto 22px; padding: 0 26px; animation: message-in .22s ease both; }
.msg-user { display: flex; flex-direction: column; align-items: flex-end; }
.msg-assistant { display: flex; flex-direction: column; align-items: flex-start; }
.bubble { padding: 13px 17px; border-radius: var(--radius); max-width: min(90%, 700px); white-space: pre-wrap; word-break: break-word; }
.msg-user .bubble { background: var(--user); border: 1px solid rgba(137,224,214,.18); border-bottom-right-radius: 5px; }
.msg-assistant .bubble { padding: 0; }
.msg-role { font-size: 11px; color: var(--muted); margin: 0 0 6px 2px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; }
.reasoning { background: rgba(14,28,32,.75); border: 1px solid rgba(81,213,195,.24); border-radius: 14px; margin-bottom: 12px; font-size: 13px; color: var(--muted); transition: .2s ease; overflow: hidden; }
.reasoning summary { display: flex; align-items: center; gap: 7px; padding: 10px 14px; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--accent); font-weight: 800; cursor: pointer; user-select: none; }
.reasoning summary:hover { background: rgba(81,213,195,.08); }
.reasoning summary .brain-icon { width: 15px; height: 15px; color: var(--accent); }
.reasoning .reason-text { padding: 4px 14px 14px; white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: 12.5px; opacity: .9; border-top: 1px solid rgba(182,238,229,.08); line-height: 1.6; }
.reasoning.streaming { border-color: rgba(81,213,195,.45); box-shadow: 0 0 16px rgba(81,213,195,.08); }
.caret, .thinking { animation: blink 1s infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }
.tool-card { margin: 8px 0; overflow: hidden; font-size: 13px; }
.tool-head { display: flex; align-items: center; gap: 8px; padding: 10px 13px; color: var(--muted); }
.tool-head svg { width: 15px; height: 15px; color: var(--accent); }
.tool-head .name { font-weight: 700; color: var(--text); }
.tool-head .state { margin-left: auto; font-size: 11px; }
.tool-head .state.running { color: var(--accent); }
.tool-payload { padding: 9px 13px; border-top: 1px solid var(--line); font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: pre-wrap; word-break: break-word; max-height: 260px; overflow: auto; }
.bubble-assistant h1, .bubble-assistant h2, .bubble-assistant h3 { margin: 12px 0 6px; line-height: 1.3; }
.bubble-assistant h1 { font-size: 20px; } .bubble-assistant h2 { font-size: 17px; } .bubble-assistant h3 { font-size: 15px; }
.bubble-assistant p { margin: 6px 0; }.bubble-assistant ul, .bubble-assistant ol { margin: 6px 0 6px 22px; }.bubble-assistant li { margin: 3px 0; }
.bubble-assistant code { background: rgba(255,255,255,.08); padding: 2px 5px; border-radius: 5px; font-family: var(--mono); font-size: .9em; }.bubble-assistant pre { background: rgba(3,13,16,.75); border: 1px solid var(--line); border-radius: 12px; padding: 13px; overflow: auto; margin: 8px 0; }.bubble-assistant pre code { background: none; padding: 0; }.bubble-assistant a { color: var(--accent); }.bubble-assistant th, .bubble-assistant td { border: 1px solid var(--line); padding: 6px 10px; }.bubble-assistant blockquote { border-left: 3px solid var(--accent); padding-left: 12px; color: var(--muted); margin: 8px 0; }

.composer { border-top: 1px solid var(--line); padding: 14px 26px 20px; }
.toolbar, #composer-form { max-width: 850px; margin-left: auto; margin-right: auto; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 11px; }
.chip { display: flex; align-items: center; gap: 7px; min-height: 36px; padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line); background: rgba(8,20,23,.52); color: var(--muted); font-size: 12px; user-select: none; transition: .18s ease; }
.chip:hover { border-color: var(--line-strong); color: var(--text); }.chip svg { width: 15px; height: 15px; }.chip-check { display: none; align-items: center; }.chip-check svg { width: 14px; height: 14px; color: var(--accent); }.chip.on { border-color: rgba(81,213,195,.55); background: var(--accent-soft); color: var(--text); }.chip.on .chip-check { display: flex; }
#composer-form { display: flex; align-items: flex-end; gap: 10px; background: var(--glass-strong); border: 1px solid var(--line-strong); border-radius: 18px; padding: 10px 10px 10px 16px; transition: .2s ease; box-shadow: 0 12px 30px rgba(0,0,0,.12); }
#composer-form:focus-within { border-color: rgba(81,213,195,.68); box-shadow: 0 0 0 4px rgba(81,213,195,.08); }
#input { flex: 1; background: none; border: none; outline: none; resize: none; color: var(--text); font-size: 15px; line-height: 1.5; max-height: 160px; }#input::placeholder { color: var(--muted); }
.send-btn { width: 42px; height: 42px; flex-shrink: 0; border: none; border-radius: 13px; cursor: pointer; background: linear-gradient(145deg, var(--accent), var(--accent-strong)); color: #062421; display: flex; align-items: center; justify-content: center; transition: .18s ease; }.send-btn:hover { transform: translateY(-1px); filter: brightness(1.08); }.send-btn:active { transform: scale(.95); }.send-btn:disabled { opacity: .45; cursor: default; transform: none; }.send-btn svg { width: 19px; height: 19px; }
.typing-dots { display: inline-flex; gap: 4px; padding: 4px 0; }.typing-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: bounce 1.2s infinite; }.typing-dots span:nth-child(2) { animation-delay: .15s; }.typing-dots span:nth-child(3) { animation-delay: .3s; }@keyframes bounce { 0%,60%,100% { transform: translateY(0); opacity: .4; }30% { transform: translateY(-5px); opacity: 1; } }
.welcome { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; min-height: 300px; text-align: center; color: var(--muted); gap: 8px; padding: 30px; }.welcome-icon { width: 64px; height: 64px; border-radius: 21px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; margin-bottom: 8px; box-shadow: 0 0 50px rgba(81,213,195,.1); }.welcome-icon svg { width: 30px; height: 30px; }.welcome-title { font-size: 22px; font-weight: 800; letter-spacing: -.5px; color: var(--text); }.welcome-sub { font-size: 13px; max-width: 380px; }.error-line { color: var(--danger); }
@keyframes message-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

@media (max-width: 820px) {
  .app { display: block; padding: 0; }.main { min-height: 100dvh; border: 0; border-radius: 0; }.topbar { border-radius: 0; }.sidebar { position: fixed; inset: 10px auto 10px 10px; width: min(286px, calc(100vw - 20px)); z-index: 20; transform: translateX(calc(-100% - 20px)); transition: transform .24s ease; }.sidebar-toggle { display: flex; }#history-toggle:checked ~ .app .sidebar { transform: translateX(0); box-shadow: 12px 0 60px rgba(0,0,0,.5); }.messages { padding-top: 24px; }.msg { padding: 0 16px; }.composer { padding: 11px 14px max(14px, env(safe-area-inset-bottom)); }.chip { min-height: 40px; }.bubble { max-width: 94%; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
