/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f0f10;
  --surface:   #1a1a1c;
  --surface2:  #242427;
  --surface3:  #2e2e32;
  --border:    #333337;
  --accent:    #4a90e2;
  --accent-hov:#5a9ff0;
  --text:      #e8e8ea;
  --text-dim:  #888892;
  --text-muted:#555560;
  --user-bg:   #1e3a5f;
  --assistant-bg: #1a1a1c;
  --error:     #e05252;
  --success:   #52c07a;
  --radius:    12px;
  --sidebar-w: 260px;
  --topbar-h:  56px;
  --input-h:   72px;
  --font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.6; }

/* ── Screens ── */
.screen { position: fixed; inset: 0; }
.hidden { display: none !important; }

/* ── Login ── */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 40%, #1a2740 0%, var(--bg) 70%);
}
.login-box {
  width: 360px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 40px 36px;
  display: flex; flex-direction: column; gap: 8px;
}
.login-logo {
  font-size: 28px; font-weight: 700; letter-spacing: -0.5px;
  text-align: center; margin-bottom: 4px;
}
.login-sub { color: var(--text-dim); text-align: center; font-size: 14px; margin-bottom: 16px; }
.logo-f { color: var(--accent); }

#login-form { display: flex; flex-direction: column; gap: 12px; }
input[type=email], input[type=password] {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 16px;
  color: var(--text); font-size: 15px; outline: none;
  transition: border-color .15s;
}
input:focus { border-color: var(--accent); }

button[type=submit], #login-btn {
  background: var(--accent); color: #fff; border: none;
  border-radius: 10px; padding: 13px; font-size: 15px; font-weight: 600;
  cursor: pointer; margin-top: 4px; transition: background .15s;
}
button[type=submit]:hover, #login-btn:hover { background: var(--accent-hov); }
button[type=submit]:disabled { opacity: .5; cursor: not-allowed; }

.error-msg { color: var(--error); font-size: 13px; text-align: center; padding-top: 4px; }

/* ── App layout ── */
#app-screen { display: flex; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: transform .25s ease;
  z-index: 20;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.logo-small { font-size: 17px; font-weight: 700; }
.sidebar-section { flex: 1; overflow-y: auto; padding: 8px 8px; }
.sidebar-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); padding: 8px 10px 6px; }

.session-list { display: flex; flex-direction: column; gap: 2px; }
.session-item {
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  font-size: 13px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .1s, color .1s;
}
.session-item:hover { background: var(--surface2); color: var(--text); }
.session-item.active { background: var(--surface3); color: var(--text); }
.session-loading { padding: 10px 12px; color: var(--text-muted); font-size: 13px; }

.sidebar-bottom {
  padding: 12px; border-top: 1px solid var(--border);
}
.btn-ghost {
  width: 100%; background: none; border: none; color: var(--text-muted);
  padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
  text-align: left; transition: background .1s, color .1s;
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }

/* ── Main ── */
.main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
}

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h); min-height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px; border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.chat-title { flex: 1; font-size: 15px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
}
.status-dot.online { background: var(--success); }

/* ── Button icons ── */
.btn-icon {
  background: none; border: none; color: var(--text-dim);
  width: 32px; height: 32px; border-radius: 8px; display: flex;
  align-items: center; justify-content: center; cursor: pointer;
  transition: background .1s, color .1s; flex-shrink: 0;
}
.btn-icon:hover { background: var(--surface2); color: var(--text); }
.btn-icon svg { width: 18px; height: 18px; }
.hamburger { display: none; }

/* ── Messages ── */
.messages {
  flex: 1; overflow-y: auto; padding: 24px 0;
  display: flex; flex-direction: column;
  scroll-behavior: smooth;
}

/* Welcome */
.welcome {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; flex: 1; gap: 12px;
  padding: 40px 24px; text-align: center;
}
.welcome-logo {
  width: 64px; height: 64px; border-radius: 18px;
  background: linear-gradient(135deg, #1a3a6a, #2a5aaa);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 800;
}
.welcome h2 { font-size: 24px; font-weight: 600; }
.welcome p { color: var(--text-dim); font-size: 15px; }

/* Message rows */
.msg-row {
  display: flex; padding: 6px 24px; gap: 12px;
  animation: fadein .2s ease;
}
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.msg-row.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 32px; height: 32px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}
.msg-row.user .msg-avatar { background: var(--accent); color: #fff; }
.msg-row.assistant .msg-avatar { background: var(--surface3); color: var(--text); }

.msg-bubble {
  max-width: min(600px, calc(100% - 80px));
  padding: 12px 16px; border-radius: 14px;
  font-size: 14px; line-height: 1.65; white-space: pre-wrap; word-break: break-word;
}
.msg-row.user .msg-bubble { background: var(--user-bg); border-bottom-right-radius: 4px; }
.msg-row.assistant .msg-bubble { background: var(--assistant-bg); border: 1px solid var(--border); border-bottom-left-radius: 4px; }

/* Code blocks in messages */
.msg-bubble pre {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; margin: 8px 0;
  overflow-x: auto; font-size: 13px; font-family: 'SF Mono', 'Fira Code', monospace;
}
.msg-bubble code {
  background: var(--surface2); border-radius: 4px;
  padding: 1px 5px; font-size: 13px; font-family: 'SF Mono', 'Fira Code', monospace;
}

/* Typing indicator */
.typing-indicator { display: flex; gap: 4px; align-items: center; padding: 14px 16px; }
.typing-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted);
  animation: bounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { 0%,80%,100% { transform: scale(1); } 40% { transform: scale(1.4); } }

/* ── Input area ── */
.input-area {
  padding: 12px 16px 20px;
  background: var(--bg); border-top: 1px solid var(--border);
}
.input-row {
  display: flex; gap: 8px; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 10px 10px 10px 16px;
  transition: border-color .15s;
}
.input-row:focus-within { border-color: var(--accent); }

textarea#msg-input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 15px; font-family: var(--font);
  resize: none; max-height: 180px; line-height: 1.5;
}
textarea#msg-input::placeholder { color: var(--text-muted); }

.btn-send {
  width: 34px; height: 34px; border-radius: 8px; border: none;
  background: var(--accent); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background .15s, opacity .15s;
}
.btn-send:hover { background: var(--accent-hov); }
.btn-send:disabled { opacity: .4; cursor: not-allowed; }
.btn-send svg { width: 16px; height: 16px; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 4px; }

/* ── Mobile ── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.5); }
  .hamburger { display: flex !important; }

  .msg-row { padding: 6px 12px; }
  .msg-bubble { max-width: calc(100% - 56px); }
  .topbar { padding: 0 12px; }
  .input-area { padding: 10px 12px 16px; }
}
