:root {
  --navy: #0a1c4a;
  --abyss: #050d28;
  --deep: #081846;
  --amber: #cca273;
  --amber-dim: #a07a4f;
  --blue: #5990c0;
  --cream: #f7e9cf;
  --cream-dim: rgba(247,233,207,0.55);
  --cream-fade: rgba(247,233,207,0.3);
  --surface: rgba(247,233,207,0.04);
  --surface-h: rgba(247,233,207,0.07);
  --border: rgba(247,233,207,0.1);
  --border-h: rgba(247,233,207,0.18);
  --bubble-me: rgba(204,162,115,0.12);
  --bubble-them: rgba(89,144,192,0.08);
  --serif: "Cormorant Garamond", "Noto Serif SC", serif;
  --sans: "Manrope", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --ease: cubic-bezier(.22,.61,.36,1);
  --ease-snap: cubic-bezier(.34,1.56,.64,1);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  background: radial-gradient(140% 90% at 20% -10%, #15336e 0%, #0a1c4a 38%, #050d28 90%);
  background-attachment: fixed;
  color: var(--cream);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
#root { height: 100%; }
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-h); border-radius: 2px; }

.app { display: flex; height: 100%; position: relative; }
.sidebar {
  width: 280px; flex-shrink: 0;
  background: rgba(5,13,40,0.6);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.sidebar-header {
  padding: 20px 16px 12px;
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-title {
  font-family: var(--serif);
  font-size: 22px; font-weight: 300; font-style: italic;
  color: var(--cream); letter-spacing: 0.02em;
}
.sidebar-search {
  margin: 0 12px 8px; padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; color: var(--cream);
  font-size: 12px; font-family: var(--sans);
  outline: none; width: calc(100% - 24px);
  transition: border-color 200ms var(--ease);
}
.sidebar-search:focus { border-color: var(--amber); }
.sidebar-search::placeholder { color: var(--cream-fade); }
.chat-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.chat-item {
  padding: 10px 12px; border-radius: 8px;
  cursor: pointer; margin-bottom: 1px;
  transition: background 150ms var(--ease);
  display: flex; align-items: center; gap: 10px;
}
.chat-item:hover { background: var(--surface-h); }
.chat-item.active { background: var(--surface-h); }
.chat-item-title {
  font-size: 13px; font-weight: 400;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  flex: 1; min-width: 0;
}
.chat-item-del {
  opacity: 0; background: none; border: none; color: var(--cream-dim);
  cursor: pointer; font-size: 13px; padding: 2px 6px; transition: opacity 150ms;
}
.chat-item:hover .chat-item-del { opacity: 1; }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.btn {
  appearance: none; border: none; cursor: pointer;
  font-family: var(--sans); font-size: 12px;
  border-radius: 8px; padding: 8px 14px;
  transition: all 150ms var(--ease);
}
.btn-primary { background: var(--amber); color: var(--abyss); font-weight: 500; }
.btn-ghost { background: transparent; color: var(--cream-dim); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--border-h); color: var(--cream); }
.btn-new {
  width: 100%; padding: 10px;
  background: var(--surface); border: 1px dashed var(--border-h);
  color: var(--amber); font-family: var(--serif); font-style: italic;
  font-size: 13px; border-radius: 10px; cursor: pointer;
}
.btn-new:hover { background: var(--surface-h); }
.chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.chat-header-name { font-size: 15px; font-weight: 500; }
.chat-header-status {
  font-size: 11px; color: var(--cream-dim);
  font-family: var(--serif); font-style: italic;
}
.burger {
  display: none; background: none; border: none;
  color: var(--cream-dim); font-size: 20px; cursor: pointer; padding: 4px;
}
.messages {
  flex: 1; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 6px;
}
.msg { display: flex; gap: 10px; max-width: 80%; animation: msg-in 300ms var(--ease) both; }
.msg-me { align-self: flex-end; flex-direction: row-reverse; }
.msg-them { align-self: flex-start; }
.msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--amber); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: #fff; font-family: var(--serif); font-style: italic;
}
.msg-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.msg-think-btn {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 10px;
  cursor: pointer; font-size: 11px; color: var(--cream-dim);
  font-family: var(--serif); font-style: italic;
  display: inline-flex; align-items: center; gap: 4px;
  align-self: flex-start; transition: all 150ms var(--ease);
}
.msg-think-btn:hover { border-color: var(--border-h); }
.msg-think-content {
  font-size: 12px; color: var(--cream-dim);
  font-style: italic; line-height: 1.6;
  padding: 8px 12px; margin-left: 2px;
  border-left: 2px solid var(--border-h);
  white-space: pre-wrap; word-break: break-word;
  max-height: 400px; overflow-y: auto;
}
.msg-bubble {
  padding: 10px 14px; font-size: 14px; line-height: 1.65;
  white-space: pre-wrap; word-break: break-word;
}
.msg-me .msg-bubble { background: var(--bubble-me); border-radius: 18px 18px 4px 18px; }
.msg-them .msg-bubble { background: var(--bubble-them); border-radius: 18px 18px 18px 4px; }
.msg-time { font-size: 10px; color: var(--cream-fade); font-family: var(--mono); padding: 0 2px; }
.typing-dot {
  display: inline-block; width: 6px; height: 6px;
  border-radius: 50%; background: var(--cream-dim);
  animation: blink 1.4s infinite both;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
.composer {
  padding: 12px 16px; border-top: 1px solid var(--border);
  display: flex; align-items: flex-end; gap: 10px;
}
.composer-input {
  flex: 1; padding: 10px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; color: var(--cream);
  font-size: 14px; font-family: var(--sans);
  line-height: 1.5; resize: none; max-height: 120px; outline: none;
  transition: border-color 200ms var(--ease);
}
.composer-input:focus { border-color: rgba(204,162,115,0.4); }
.composer-input::placeholder { color: var(--cream-fade); }
.composer-send {
  width: 38px; height: 38px; border-radius: 50%;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0; transition: all 200ms var(--ease);
}
.composer-send.active { background: var(--amber); color: var(--abyss); }
.composer-send.inactive { background: var(--surface); color: var(--cream-fade); }
.composer-send.stop { background: var(--amber); }
.settings-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5,13,40,0.8);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; justify-content: flex-end;
  animation: fade-in 200ms var(--ease) both;
}
.settings-panel {
  width: 420px; max-width: 100vw; height: 100%;
  background: rgba(8,24,70,0.95);
  border-left: 1px solid var(--border);
  overflow-y: auto; padding: 24px; position: relative;
  animation: slide-in 300ms var(--ease) both;
}
.settings-close {
  background: none; border: none; color: var(--cream-dim);
  font-size: 20px; cursor: pointer; padding: 4px 8px;
  position: absolute; top: 16px; right: 16px;
}
.settings-section { margin-bottom: 24px; }
.settings-label {
  font-size: 11px; color: var(--amber);
  font-family: var(--serif); font-style: italic;
  letter-spacing: 0.08em; margin-bottom: 10px;
}
.settings-textarea {
  width: 100%; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; color: var(--cream);
  font-size: 13px; font-family: var(--serif);
  line-height: 1.7; resize: vertical; outline: none; min-height: 80px;
}
.settings-textarea:focus { border-color: rgba(204,162,115,0.3); }
.settings-input {
  width: 100%; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; color: var(--cream);
  font-size: 13px; font-family: var(--mono); outline: none;
}
.settings-input:focus { border-color: rgba(204,162,115,0.3); }
.field-row { margin-bottom: 12px; }
.field-label { font-size: 11px; color: var(--cream-dim); margin-bottom: 4px; }
.token-count { font-size: 10px; color: var(--cream-fade); font-family: var(--mono); margin-top: 4px; }
.toggle {
  width: 42px; height: 22px; border-radius: 11px;
  background: var(--border-h); border: none; cursor: pointer;
  position: relative; transition: background 200ms var(--ease);
}
.toggle.on { background: var(--amber); }
.toggle-knob {
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; position: absolute; top: 3px;
  transition: left 200ms var(--ease-snap);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle.on .toggle-knob { left: 23px; }
.toggle:not(.on) .toggle-knob { left: 3px; }
.empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--cream-fade); gap: 8px; padding: 40px;
}
.empty-icon { font-size: 32px; opacity: 0.4; }
.empty-text { font-family: var(--serif); font-style: italic; font-size: 14px; }
.sidebar-mobile-overlay { display: none; position: fixed; inset: 0; z-index: 50; background: rgba(5,13,40,0.6); backdrop-filter: blur(4px); }
@keyframes msg-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-in { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }
@media (max-width: 768px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 51; transform: translateX(-100%); transition: transform 300ms var(--ease); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-mobile-overlay.open { display: block; }
  .burger { display: block; }
  .msg { max-width: 90%; }
  .settings-panel { width: 100vw; }
}
