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

:root {
  --bg:            #FAF9F7;
  --sidebar-bg:    #F0EDE8;
  --surface:       #E9E5DF;
  --surface-hover: #E1DDD6;
  --border:        #DDD8CF;
  --text:          #1A1917;
  --text-sec:      #5C5855;
  --text-muted:    #9C9894;
  --accent:        #DA7756;
  --accent-hover:  #C46947;
  --accent-dim:    rgba(218,119,86,.12);
  --user-bg:       #1A1917;
  --user-text:     #FAF9F7;
  --code-inline:   #EBE8E2;
  --code-block:    #282C34;
  --danger:        #C0392B;
}

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

/* ── LOGIN ──────────────────────────────────────────── */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  height: 100dvh; background: var(--bg);
}
.login-box {
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  width: 360px;
  display: flex; flex-direction: column; align-items: center;
  box-shadow: 0 4px 24px rgba(0,0,0,.06);
}
.login-logo {
  width: 52px; height: 52px;
  background: var(--accent); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 1.25rem; flex-shrink: 0;
}
.login-box h1 { font-size: 1.2rem; font-weight: 600; margin-bottom: 0.3rem; }
.login-box .sub { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 1.75rem; }
.field { margin-bottom: 1rem; width: 100%; }
.field label { display: block; font-size: 0.8rem; color: var(--text-sec); margin-bottom: 0.4rem; font-weight: 500; }
.field input, .field textarea {
  width: 100%; padding: 0.65rem 0.9rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 0.95rem;
  font-family: inherit; outline: none; transition: border-color .15s;
}
.field textarea { resize: vertical; min-height: 110px; line-height: 1.5; }
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.btn-primary {
  width: 100%; padding: 0.7rem;
  background: var(--accent); color: #fff;
  border: none; border-radius: 8px;
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
  transition: background .15s; margin-top: 0.5rem;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .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: 256px; min-width: 256px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-header {
  padding: 1rem 0.875rem 0.75rem;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.sidebar-brand { display: flex; align-items: center; gap: 0.5rem; }
.sidebar-brand .brand-mark {
  width: 26px; height: 26px;
  background: var(--accent); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.brand-name { font-size: 0.9rem; font-weight: 600; color: var(--text); }
.btn-new-icon {
  width: 30px; height: 30px;
  background: none; border: none; border-radius: 7px;
  color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
}
.btn-new-icon:hover { background: var(--surface-hover); color: var(--text); }

/* ── SIDEBAR SECTIONS ──────────────────────────────────── */
.sidebar-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.sidebar-section {
  padding: 0.6rem 0.875rem 0.2rem;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.section-label {
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--text-muted);
}
.section-label.clickable { cursor: pointer; transition: color .12s; }
.section-label.clickable:hover { color: var(--accent); }
.btn-icon-sm {
  width: 22px; height: 22px;
  background: none; border: none; border-radius: 5px;
  color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
}
.btn-icon-sm:hover { background: var(--surface-hover); color: var(--text); }
.sidebar-divider { height: 1px; background: var(--border); margin: 0.25rem 0.75rem; flex-shrink: 0; }

/* ── PROJECT ITEMS ──────────────────────────────────────── */
.proj-list { padding: 0 0.5rem 0.25rem; }
.proj-item {
  display: flex; align-items: center; gap: 0.45rem;
  padding: 0.475rem 0.625rem; cursor: pointer;
  border-radius: 8px; margin-bottom: 1px;
  font-size: 0.86rem; color: var(--text-sec);
  transition: background .1s, color .1s;
}
.proj-item:hover { background: var(--surface-hover); color: var(--text); }
.proj-item.active { background: var(--surface-hover); color: var(--accent); font-weight: 500; }
.proj-icon { flex-shrink: 0; display: flex; color: var(--text-muted); }
.proj-item.active .proj-icon { color: var(--accent); }
.proj-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-edit, .proj-del {
  opacity: 0; font-size: 0.7rem;
  background: none; border: none; cursor: pointer;
  padding: 2px 4px; border-radius: 4px; flex-shrink: 0;
  color: var(--text-muted); transition: color .1s;
}
.proj-item:hover .proj-edit,
.proj-item:hover .proj-del { opacity: 1; }
.proj-del:hover { color: var(--danger) !important; }
.proj-edit:hover { color: var(--accent) !important; }

/* ── CONVERSATION ITEMS ──────────────────────────────────── */
.conv-list { padding: 0 0.5rem 0.5rem; flex: 1; }
.conv-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.475rem 0.625rem; cursor: pointer;
  border-radius: 8px; margin-bottom: 1px;
  font-size: 0.86rem; color: var(--text-sec);
  transition: background .1s, color .1s;
}
.conv-item:hover { background: var(--surface-hover); color: var(--text); }
.conv-item.active { background: var(--surface-hover); color: var(--text); }
.conv-icon { flex-shrink: 0; display: flex; color: var(--text-muted); }
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-del {
  opacity: 0; font-size: 0.7rem;
  background: none; border: none; cursor: pointer;
  padding: 2px 4px; border-radius: 4px; flex-shrink: 0;
  color: var(--text-muted); transition: color .1s;
}
.conv-item:hover .conv-del { opacity: 1; }
.conv-del:hover { color: var(--danger) !important; }

.sidebar-footer {
  padding: 0.75rem 0.875rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.btn-logout {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.625rem; width: 100%;
  background: none; border: none; border-radius: 8px;
  color: var(--text-muted); font-size: 0.85rem; cursor: pointer;
  transition: background .1s, color .1s; text-align: left;
}
.btn-logout:hover { background: var(--surface-hover); color: var(--danger); }

/* ── MODE TOGGLE ──────────────────────────────────────────── */
.mode-toggle {
  display: flex; gap: 3px;
  margin: 0.1rem 0.875rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px; padding: 3px;
}
.mode-btn {
  flex: 1; display: flex; align-items: center; justify-content: center;
  gap: 0.35rem; padding: 0.38rem 0.5rem;
  background: none; border: none; border-radius: 7px;
  font-size: 0.82rem; color: var(--text-muted); cursor: pointer;
  transition: all .12s; white-space: nowrap; font-family: inherit;
}
.mode-btn.active {
  background: #FFFFFF; color: var(--text); font-weight: 500;
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
}
.mode-btn.active.code-mode { color: var(--accent); }

/* ── PROJECT CONTEXT BAR ──────────────────────────────────── */
.project-bar {
  display: none;
  align-items: center; gap: 0.5rem;
  padding: 0.5rem 1.5rem;
  background: var(--accent-dim);
  border-bottom: 1px solid rgba(218,119,86,.2);
  font-size: 0.82rem; color: var(--accent); font-weight: 500;
}
.project-bar.visible { display: flex; }
.project-bar svg { flex-shrink: 0; }

/* ── MAIN / CHAT ──────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.messages {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center;
  padding: 2rem 1.5rem 1rem;
}

/* ── EMPTY STATE ──────────────────────────────────────────── */
.empty-state {
  flex: 1; width: 100%; max-width: 760px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 0.75rem;
  padding: 2rem 0;
}
.empty-logo {
  width: 60px; height: 60px;
  background: var(--accent); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 0.5rem;
}
.empty-state h3 { font-size: 1.4rem; font-weight: 600; color: var(--text); }
.empty-state p { font-size: 0.875rem; color: var(--text-muted); }

/* ── MESSAGES ──────────────────────────────────────────────── */
.message {
  display: flex; gap: 0.875rem;
  width: 100%; max-width: 760px;
  padding: 0.75rem 0;
}
.message.user { flex-direction: row-reverse; }

.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700;
  flex-shrink: 0; margin-top: 3px;
  user-select: none;
}
.avatar.user-avatar {
  background: var(--surface);
  color: var(--text-sec);
  border: 1px solid var(--border);
}
.avatar.claude-avatar { background: var(--accent); }

.bubble { font-size: 0.925rem; line-height: 1.7; max-width: calc(100% - 44px); }
.message.user .bubble {
  background: var(--user-bg);
  border-radius: 16px 4px 16px 16px;
  padding: 0.625rem 1rem;
  color: var(--user-text);
}
.message.assistant .bubble { background: transparent; padding: 0.2rem 0; }

/* ── MARKDOWN ──────────────────────────────────────────────── */
.bubble p { margin: 0.5em 0; }
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }
.bubble code {
  background: var(--code-inline);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.15em 0.4em; border-radius: 4px;
  font-family: 'Menlo', 'Consolas', monospace; font-size: 0.85em;
}
.bubble pre {
  background: var(--code-block) !important;
  border: 1px solid #3A3F4B;
  border-radius: 8px; padding: 0.875rem 1rem;
  overflow-x: auto; margin: 0.75em 0;
}
.bubble pre code { background: none !important; border: none; padding: 0; font-size: 0.82em; }
.bubble ul, .bubble ol { padding-left: 1.5em; margin: 0.5em 0; }
.bubble li { margin: 0.25em 0; }
.bubble h1,.bubble h2,.bubble h3 { margin: 0.8em 0 0.4em; font-weight: 600; }
.bubble h1 { font-size: 1.2em; }
.bubble h2 { font-size: 1.1em; }
.bubble h3 { font-size: 1em; }
.bubble blockquote {
  border-left: 3px solid var(--border);
  padding-left: 0.875rem; color: var(--text-sec); margin: 0.5em 0;
}
.bubble table { border-collapse: collapse; margin: 0.6em 0; font-size: 0.875em; width: 100%; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 0.35em 0.7em; text-align: left; }
.bubble th { background: var(--surface); font-weight: 600; }
.bubble a { color: var(--accent); text-decoration: none; }
.bubble a:hover { text-decoration: underline; }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 0.8em 0; }
.bubble strong { color: var(--text); font-weight: 600; }

/* user bubble overrides */
.message.user .bubble code { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.2); color: var(--user-text); }
.message.user .bubble strong { color: var(--user-text); }

/* File badges */
.bubble .file-list { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.5rem; }
.bubble .file-badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; font-size: 0.8rem; color: var(--text-sec);
}
.message.user .bubble .file-badge {
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.18);
  color: rgba(255,255,255,.85);
}

/* Tool call badge (shown during code mode streaming) */
.tool-badge {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.22rem 0.65rem; margin: 0.35rem 0;
  background: var(--accent-dim);
  border: 1px solid rgba(218,119,86,.28);
  border-radius: 6px; font-size: 0.8rem; color: var(--accent);
}
.tool-badge code {
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 0.75rem; color: var(--text-sec);
  background: none; border: none; padding: 0;
}

/* Conv mode badge in sidebar */
.conv-mode-code {
  font-size: 0.67rem; padding: 1px 5px;
  background: var(--accent-dim); color: var(--accent);
  border-radius: 4px; flex-shrink: 0; font-weight: 500;
}

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

/* ── INPUT BAR ──────────────────────────────────────────────── */
.input-bar {
  padding: 0.5rem 1.5rem 1.25rem;
  background: var(--bg);
  display: flex; flex-direction: column; align-items: center;
}
.input-card {
  width: 100%; max-width: 760px;
  background: #FFFFFF;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 0.5rem 0.5rem 0.4rem;
  transition: border-color .15s;
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
}
.input-card:focus-within { border-color: #C9C4BC; }

.file-chips {
  display: flex; flex-wrap: wrap; gap: 0.35rem;
  padding: 0 0.3rem; margin-bottom: 0.35rem;
}
.file-chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.25rem 0.55rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; font-size: 0.78rem; color: var(--text-sec);
}
.file-chip .chip-name { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .chip-rm { cursor: pointer; color: var(--text-muted); font-size: 0.68rem; padding: 0 0.1rem; }
.file-chip .chip-rm:hover { color: var(--danger); }
.file-chip.loading { opacity: .6; }

.input-card textarea {
  width: 100%; resize: none;
  min-height: 40px; max-height: 200px;
  padding: 0.4rem 0.6rem;
  background: transparent; border: none;
  color: var(--text); font-size: 0.925rem;
  font-family: inherit; outline: none; line-height: 1.6;
}
.input-card textarea::placeholder { color: var(--text-muted); }

.input-actions {
  display: flex; align-items: center; gap: 0.375rem;
  padding: 0.2rem 0.25rem 0.1rem;
}
.btn-attach {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 7px;
  cursor: pointer; color: var(--text-muted);
  transition: background .12s, color .12s; flex-shrink: 0;
}
.btn-attach:hover { background: var(--surface); color: var(--text); }
.input-spacer { flex: 1; }
.btn-send {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; color: white;
  transition: background .15s, transform .1s;
}
.btn-send:hover { background: var(--accent-hover); transform: scale(1.06); }
.btn-send:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn-send:disabled:hover { background: var(--accent); transform: none; }

.input-hint { font-size: 0.73rem; color: var(--text-muted); margin-top: 0.45rem; text-align: center; }

/* ── MODAL ──────────────────────────────────────────────── */
.modal {
  display: none; position: fixed; inset: 0;
  z-index: 200; align-items: center; justify-content: center;
}
.modal.open { display: flex; }
.modal-overlay {
  position: absolute; inset: 0;
  background: rgba(26,25,23,.35);
  backdrop-filter: blur(2px);
}
.modal-box {
  position: relative; z-index: 1;
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.75rem 2rem;
  width: 500px; max-width: 92vw;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.12);
}
.modal-header { margin-bottom: 1.25rem; }
.modal-header h3 { font-size: 1.05rem; font-weight: 600; }
.modal-header p { font-size: 0.83rem; color: var(--text-muted); margin-top: 0.2rem; }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 0.5rem;
  margin-top: 1.25rem; padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.btn-modal-cancel {
  padding: 0.55rem 1rem;
  background: none; border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-sec);
  cursor: pointer; font-size: 0.9rem; transition: background .12s;
}
.btn-modal-cancel:hover { background: var(--surface); }
.btn-modal-confirm {
  padding: 0.55rem 1.25rem;
  background: var(--accent); border: none;
  border-radius: 8px; color: white;
  cursor: pointer; font-size: 0.9rem; font-weight: 600;
  transition: background .12s;
}
.btn-modal-confirm:hover { background: var(--accent-hover); }
.btn-modal-confirm:disabled { opacity: .5; cursor: not-allowed; }

/* ── SCROLLBARS ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #C9C4BC; }
