*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d1117;
  --sidebar: #161b22;
  --surface: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-dim: #1f6feb33;
  --user-bg: #1f6feb;
  --danger: #f85149;
  --code-bg: #161b22;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
}

/* ---- LOGIN ---- */
.login-wrap { display: flex; align-items: center; justify-content: center; height: 100dvh; }
.login-box { background: var(--sidebar); border: 1px solid var(--border); border-radius: 12px; padding: 2.5rem 2rem; width: 340px; }
.login-box h1 { font-size: 1.3rem; margin-bottom: 0.25rem; }
.login-box .sub { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 1.5rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.4rem; }
.field input { width: 100%; padding: 0.6rem 0.8rem; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 0.95rem; outline: none; transition: border-color 0.15s; }
.field input:focus { border-color: var(--accent); }
.btn-primary { width: 100%; padding: 0.65rem; background: var(--accent); color: #000; border: none; border-radius: 6px; font-size: 0.95rem; font-weight: 600; cursor: pointer; transition: opacity 0.15s; }
.btn-primary:hover { opacity: 0.88; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.error-msg { color: var(--danger); font-size: 0.82rem; margin-top: 0.75rem; text-align: center; }

/* ---- LAYOUT ---- */
.layout { display: flex; height: 100dvh; }

/* ---- SIDEBAR ---- */
.sidebar { width: 240px; min-width: 240px; background: var(--sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.sidebar-header { padding: 1rem 0.75rem 0.5rem; border-bottom: 1px solid var(--border); }
.sidebar-header h2 { font-size: 0.82rem; color: var(--text-muted); letter-spacing: 0.05em; text-transform: uppercase; }
.btn-new { margin: 0.6rem 0.75rem 0; display: flex; align-items: center; gap: 0.4rem; padding: 0.5rem 0.75rem; background: var(--accent-dim); border: 1px solid var(--accent); border-radius: 6px; color: var(--accent); font-size: 0.85rem; cursor: pointer; width: calc(100% - 1.5rem); transition: background 0.15s; }
.btn-new:hover { background: #1f6feb55; }
.conv-list { flex: 1; overflow-y: auto; padding: 0.25rem 0; }
.conv-item { display: flex; align-items: center; padding: 0.5rem 0.75rem; cursor: pointer; border-radius: 6px; margin: 0.1rem 0.5rem; font-size: 0.85rem; color: var(--text-muted); transition: background 0.1s; }
.conv-item:hover { background: var(--surface); color: var(--text); }
.conv-item.active { background: var(--surface); color: var(--text); }
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-del { opacity: 0; font-size: 0.75rem; color: var(--danger); background: none; border: none; cursor: pointer; padding: 0 0.2rem; }
.conv-item:hover .conv-del { opacity: 1; }
.sidebar-footer { padding: 0.75rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }
.btn-logout { padding: 0.45rem 0.75rem; background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--text-muted); font-size: 0.82rem; cursor: pointer; transition: color 0.15s, border-color 0.15s; }
.btn-logout:hover { color: var(--danger); border-color: var(--danger); }

/* ---- CHAT ---- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 1.5rem 1rem; display: flex; flex-direction: column; gap: 1.25rem; }

.message { display: flex; gap: 0.75rem; max-width: 820px; width: 100%; }
.message.user { flex-direction: row-reverse; align-self: flex-end; }
.message.assistant { align-self: flex-start; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 700; flex-shrink: 0; margin-top: 2px; }
.message.user .avatar { background: var(--user-bg); }
.message.assistant .avatar { background: var(--surface); border: 1px solid var(--border); }

.bubble { padding: 0.65rem 0.9rem; border-radius: 10px; max-width: calc(100% - 42px); font-size: 0.9rem; line-height: 1.6; }
.message.user .bubble { background: var(--user-bg); color: #fff; border-radius: 10px 2px 10px 10px; }
.message.assistant .bubble { background: var(--surface); border: 1px solid var(--border); border-radius: 2px 10px 10px 10px; }

/* Markdown */
.bubble p { margin: 0.4em 0; }
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }
.bubble code { background: var(--code-bg); border: 1px solid var(--border); padding: 0.1em 0.35em; border-radius: 4px; font-family: 'Menlo', 'Consolas', monospace; font-size: 0.85em; }
.bubble pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 6px; padding: 0.75rem 1rem; overflow-x: auto; margin: 0.6em 0; position: relative; }
.bubble pre code { background: none; border: none; padding: 0; font-size: 0.83em; }
.bubble ul, .bubble ol { padding-left: 1.4em; margin: 0.4em 0; }
.bubble li { margin: 0.2em 0; }
.bubble h1,.bubble h2,.bubble h3 { margin: 0.6em 0 0.3em; }
.bubble blockquote { border-left: 3px solid var(--border); padding-left: 0.75rem; color: var(--text-muted); margin: 0.4em 0; }
.bubble table { border-collapse: collapse; margin: 0.5em 0; font-size: 0.85em; width: 100%; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 0.3em 0.6em; text-align: left; }
.bubble th { background: var(--code-bg); }
.bubble a { color: var(--accent); }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 0.8em 0; }

/* File attachments in bubble */
.bubble .file-list { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.5rem; }
.bubble .file-badge { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.2rem 0.5rem; background: rgba(255,255,255,0.1); border-radius: 4px; font-size: 0.8rem; }

/* Cursor */
.cursor { display: inline-block; width: 2px; height: 1em; background: var(--accent); vertical-align: text-bottom; animation: blink 0.8s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* Empty state */
.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); gap: 0.5rem; }
.empty-state h3 { font-size: 1.1rem; color: var(--text); }
.empty-state p { font-size: 0.85rem; }

/* ---- INPUT BAR ---- */
.input-bar { padding: 0.75rem 1rem; border-top: 1px solid var(--border); background: var(--bg); }
.file-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.5rem; }
.file-chip { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.25rem 0.6rem; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; font-size: 0.78rem; color: var(--text-muted); }
.file-chip .chip-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .chip-rm { cursor: pointer; color: var(--danger); font-size: 0.7rem; line-height: 1; padding: 0 0.1rem; }
.file-chip.loading { opacity: 0.6; }
.input-row { display: flex; gap: 0.5rem; align-items: flex-end; }
.btn-attach { display: flex; align-items: center; justify-content: center; width: 38px; height: 38px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 1rem; color: var(--text-muted); flex-shrink: 0; transition: color 0.15s, border-color 0.15s; }
.btn-attach:hover { color: var(--accent); border-color: var(--accent); }
.input-bar textarea { flex: 1; resize: none; min-height: 38px; max-height: 160px; padding: 0.5rem 0.75rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 0.9rem; font-family: inherit; outline: none; line-height: 1.5; transition: border-color 0.15s; }
.input-bar textarea:focus { border-color: var(--accent); }
.input-bar textarea::placeholder { color: var(--text-muted); }
.btn-send { padding: 0 1rem; background: var(--accent); color: #000; border: none; border-radius: 8px; font-size: 0.9rem; font-weight: 600; cursor: pointer; height: 38px; flex-shrink: 0; transition: opacity 0.15s; white-space: nowrap; }
.btn-send:hover { opacity: 0.88; }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* Scrollbars */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
