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

:root {
  --bg:        #0c0d0f;
  --bg2:       #13141a;
  --bg3:       #1a1c24;
  --border:    #2a2d3a;
  --border2:   #363a4a;
  --text:      #e8eaf0;
  --text2:     #8b8fa8;
  --text3:     #555870;
  --accent:    #e8ff47;
  --accent2:   #b8cc20;
  --accent-dim:#e8ff4720;
  --red:       #ff4757;
  --green:     #2aff82;
  --radius:    10px;
  --sidebar-w: 260px;
  --font-body: 'JetBrains Mono', monospace;
  --font-head: 'Syne', sans-serif;
}

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

/* ─── SCREENS ───────────────────────────────────── */
.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: flex; }

/* ─── AUTH ──────────────────────────────────────── */
#auth-screen {
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.auth-bg { position: absolute; inset: 0; overflow: hidden; }
.grid-overlay {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity: 0.4;
}
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.15;
}
.orb-1 {
  width: 500px; height: 500px;
  background: var(--accent);
  top: -150px; left: -100px;
  animation: orb-drift 12s ease-in-out infinite alternate;
}
.orb-2 {
  width: 400px; height: 400px;
  background: #4776e8;
  bottom: -100px; right: -80px;
  animation: orb-drift 15s ease-in-out infinite alternate-reverse;
}
@keyframes orb-drift {
  from { transform: translate(0, 0); }
  to   { transform: translate(40px, 30px); }
}
.auth-card {
  position: relative; z-index: 1;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 18px;
  padding: 48px 44px;
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: 0 40px 80px rgba(0,0,0,0.5);
  animation: card-in 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}
.logo-mark { margin-bottom: 4px; }
.auth-title {
  font-family: var(--font-head);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
}
.auth-sub { color: var(--text2); font-size: 12.5px; text-align: center; }
.auth-tags { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 4px 0; }
.tag {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent2);
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
}
.signin-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 13px 28px;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  justify-content: center;
  margin-top: 8px;
  transition: all 0.2s;
}
.signin-btn:hover {
  background: var(--bg);
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(232,255,71,0.1);
}
.auth-note { color: var(--text3); font-size: 11px; text-align: center; }

/* ─── LOADING ───────────────────────────────────── */
#loading-screen {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  gap: 0;
}
.loading-content {
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  width: 100%; max-width: 480px; padding: 24px;
}
.loading-logo { animation: pulse-glow 2s ease-in-out infinite; }
@keyframes pulse-glow {
  0%, 100% { filter: drop-shadow(0 0 8px var(--accent)); }
  50%       { filter: drop-shadow(0 0 24px var(--accent)); }
}
.loading-title {
  font-family: var(--font-head);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}
.loading-bar-wrap {
  width: 100%;
  height: 4px;
  background: var(--bg3);
  border-radius: 2px;
  overflow: hidden;
}
.loading-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.4s ease;
  box-shadow: 0 0 12px var(--accent);
}
.loading-status { color: var(--text2); font-size: 12px; }
.loading-stats {
  display: flex; gap: 32px; margin-top: 12px;
}
.stat { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stat-val {
  font-family: var(--font-head);
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent);
}
.stat-lbl { color: var(--text3); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; }

/* ─── APP LAYOUT ────────────────────────────────── */
#app-screen { flex-direction: row; }

/* ─── SIDEBAR ───────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  transition: transform 0.3s cubic-bezier(0.16,1,0.3,1);
  z-index: 100;
}
.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-w))); }
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
}
.logo-sm {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}
.new-chat-btn {
  background: var(--accent-dim);
  border: 1px solid var(--accent2);
  color: var(--accent);
  width: 30px; height: 30px;
  border-radius: 8px;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
  line-height: 1;
}
.new-chat-btn:hover { background: var(--accent); color: var(--bg); }
.sidebar-section { flex: 1; overflow-y: auto; padding: 12px 8px; }
.sidebar-label {
  color: var(--text3);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0 8px;
  margin-bottom: 6px;
}
.chat-list { display: flex; flex-direction: column; gap: 2px; }
.chat-item {
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text2);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.15s;
  border: 1px solid transparent;
}
.chat-item:hover { background: var(--bg3); color: var(--text); }
.chat-item.active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent2); }
.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.model-badge {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--text2);
}
.model-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text3);
  transition: background 0.3s;
}
.model-dot.ready { background: var(--green); box-shadow: 0 0 6px var(--green); }
.model-dot.loading { background: var(--accent); animation: blink 1s ease-in-out infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.user-row {
  display: flex; align-items: center; gap: 8px;
}
.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border2);
  object-fit: cover;
}
.user-name-text {
  flex: 1; font-size: 12px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.signout-btn {
  background: none; border: none; color: var(--text3);
  cursor: pointer; font-size: 14px; padding: 2px;
  transition: color 0.2s;
}
.signout-btn:hover { color: var(--red); }

/* ─── CHAT MAIN ─────────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}
.chat-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.sidebar-toggle {
  background: none; border: 1px solid var(--border);
  color: var(--text2);
  width: 34px; height: 34px;
  border-radius: 8px; cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.sidebar-toggle:hover { border-color: var(--accent); color: var(--accent); }
.chat-title-bar {
  flex: 1;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 6px 12px;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 11.5px;
  cursor: pointer;
  transition: all 0.2s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ─── MESSAGES ──────────────────────────────────── */
.messages-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
}
.messages-wrap::-webkit-scrollbar { width: 4px; }
.messages-wrap::-webkit-scrollbar-track { background: transparent; }
.messages-wrap::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

.welcome-state {
  margin: auto;
  display: flex; flex-direction: column; align-items: center;
  gap: 16px; max-width: 500px; text-align: center;
  padding: 40px 20px;
  animation: fade-up 0.5s ease both;
}
@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: none; }
}
.welcome-icon { animation: pulse-glow 3s ease-in-out infinite; }
.welcome-state h2 {
  font-family: var(--font-head);
  font-weight: 700; font-size: 1.4rem;
}
.welcome-state p { color: var(--text2); font-size: 13px; line-height: 1.7; }
.welcome-chips { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
.chip {
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text2);
  padding: 8px 16px;
  border-radius: 20px;
  font-family: var(--font-body);
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.2s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

.messages { display: flex; flex-direction: column; gap: 20px; }
.msg {
  display: flex;
  gap: 12px;
  animation: fade-up 0.3s ease both;
}
.msg.user { flex-direction: row-reverse; }
.msg-avatar {
  width: 32px; height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
}
.msg.user .msg-avatar { background: var(--accent-dim); border: 1px solid var(--accent2); }
.msg.bot .msg-avatar { background: var(--bg3); border: 1px solid var(--border2); }
.msg-bubble {
  max-width: 70%;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.7;
}
.msg.user .msg-bubble {
  background: var(--accent-dim);
  border: 1px solid var(--accent2);
  color: var(--accent);
  border-top-right-radius: 4px;
}
.msg.bot .msg-bubble {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-top-left-radius: 4px;
}
.typing-indicator { display: flex; gap: 4px; padding: 4px 2px; }
.typing-dot {
  width: 6px; height: 6px;
  background: var(--text3);
  border-radius: 50%;
  animation: typing 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-6px); opacity: 1; }
}

/* ─── INPUT ─────────────────────────────────────── */
.input-area {
  padding: 16px 20px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
}
.input-row { display: flex; align-items: flex-end; gap: 10px; }
.msg-input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13.5px;
  padding: 12px 16px;
  border-radius: 12px;
  resize: none;
  outline: none;
  max-height: 160px;
  line-height: 1.6;
  transition: border-color 0.2s;
}
.msg-input:focus { border-color: var(--accent); }
.msg-input::placeholder { color: var(--text3); }
.send-btn {
  width: 44px; height: 44px;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  color: var(--bg);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}
.send-btn:hover { background: var(--accent2); transform: scale(1.05); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.input-note { color: var(--text3); font-size: 10.5px; margin-top: 8px; text-align: center; }

/* ─── MODAL ─────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 16px;
  padding: 32px;
  width: 100%; max-width: 520px;
  display: flex; flex-direction: column; gap: 16px;
  box-shadow: 0 40px 80px rgba(0,0,0,0.5);
  animation: card-in 0.3s cubic-bezier(0.16,1,0.3,1) both;
}
.modal h3 { font-family: var(--font-head); font-weight: 700; font-size: 1.2rem; }
.modal p { color: var(--text2); font-size: 13px; }
.train-textarea {
  width: 100%; height: 160px;
  background: var(--bg3); border: 1px solid var(--border2);
  color: var(--text); font-family: var(--font-body); font-size: 12.5px;
  padding: 12px; border-radius: 10px; resize: vertical; outline: none;
}
.train-textarea:focus { border-color: var(--accent); }
.modal-row { display: flex; gap: 20px; align-items: center; }
.modal-row label { color: var(--text2); font-size: 12.5px; display: flex; align-items: center; gap: 8px; }
.num-input {
  background: var(--bg3); border: 1px solid var(--border2);
  color: var(--text); font-family: var(--font-body);
  padding: 6px 10px; border-radius: 8px; width: 90px;
  outline: none; font-size: 13px;
}
.num-input:focus { border-color: var(--accent); }
.train-progress { display: flex; flex-direction: column; gap: 8px; }
.train-bar-wrap {
  height: 4px; background: var(--bg3); border-radius: 2px; overflow: hidden;
}
.train-bar {
  height: 100%; background: var(--accent); border-radius: 2px;
  width: 0%; transition: width 0.3s ease;
  box-shadow: 0 0 8px var(--accent);
}
#train-status { color: var(--text2); font-size: 11.5px; }
.modal-btns { display: flex; gap: 10px; justify-content: flex-end; }
.btn-primary {
  background: var(--accent); border: none; color: var(--bg);
  font-family: var(--font-body); font-size: 13px;
  padding: 10px 20px; border-radius: 8px; cursor: pointer;
  transition: all 0.2s; font-weight: 500;
}
.btn-primary:hover { background: var(--accent2); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-secondary {
  background: var(--bg3); border: 1px solid var(--border2); color: var(--text2);
  font-family: var(--font-body); font-size: 13px;
  padding: 10px 20px; border-radius: 8px; cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover { border-color: var(--text2); color: var(--text); }

/* ─── RESPONSIVE ────────────────────────────────── */
@media (max-width: 680px) {
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100%;
  }
  .sidebar.collapsed { transform: translateX(-100%); }
  .msg-bubble { max-width: 90%; }
  .auth-card { margin: 16px; padding: 32px 24px; }
}
