* { margin: 0; padding: 0; box-sizing: border-box; }

/* ===== THEMES ===== */
:root {
  --bg-main: #ffffff;
  --bg-sidebar: #f5f5f5;
  --bg-input: #ffffff;
  --bg-msg-ai: #f5f5f5;
  --bg-hover: #ebebeb;
  --bg-active: #e0e0e0;
  --bg-code: #1e1e1e;
  --text-primary: #111111;
  --text-secondary: #666666;
  --text-tertiary: #999999;
  --border: #e0e0e0;
  --accent: #111111;
  --accent-text: #ffffff;
  --shadow: rgba(0,0,0,0.06);
  --plan-plus: #111111;
  --plan-ultra: linear-gradient(135deg, #7c3aed, #a855f7);
}

[data-theme="dark"] {
  --bg-main: #0d0d0d;
  --bg-sidebar: #171717;
  --bg-input: #1a1a1a;
  --bg-msg-ai: #1a1a1a;
  --bg-hover: #252525;
  --bg-active: #2a2a2a;
  --bg-code: #0a0a0a;
  --text-primary: #ececec;
  --text-secondary: #9a9a9a;
  --text-tertiary: #666666;
  --border: #2a2a2a;
  --accent: #ececec;
  --accent-text: #0d0d0d;
  --shadow: rgba(0,0,0,0.2);
}

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}

/* ===== AUTH ===== */
.auth-overlay {
  position: fixed; inset: 0; background: var(--bg-main);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
  transition: background 0.3s;
}
.auth-modal { width: 360px; padding: 48px 28px; text-align: center; }
.auth-logo { width: 44px; margin-bottom: 20px; }
.auth-modal h2 { font-size: 22px; font-weight: 600; margin-bottom: 28px; }
.auth-input {
  width: 100%; padding: 11px 14px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 14px; font-family: inherit;
  outline: none; margin-bottom: 10px; background: var(--bg-input);
  color: var(--text-primary); transition: border-color 0.2s, background 0.3s;
}
.auth-input:focus { border-color: var(--accent); }
.auth-input::placeholder { color: var(--text-tertiary); }
.auth-btn {
  width: 100%; padding: 11px; background: var(--accent); color: var(--accent-text);
  border: none; border-radius: 10px; font-size: 14px; font-weight: 500;
  cursor: pointer; font-family: inherit; transition: opacity 0.2s;
  margin-top: 4px;
}
.auth-btn:hover { opacity: 0.85; }
.auth-switch { margin-top: 16px; font-size: 13px; color: var(--text-secondary); }
.auth-switch button {
  background: none; border: none; color: var(--text-primary); font-weight: 500;
  cursor: pointer; font-family: inherit; font-size: 13px; text-decoration: underline;
}
.auth-error { color: #ef4444; font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ===== LAYOUT ===== */
.app { display: flex; height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: 260px; background: var(--bg-sidebar); display: flex; flex-direction: column;
  flex-shrink: 0; transition: transform 0.25s ease, background 0.3s;
  border-right: 1px solid var(--border);
}
.sidebar.closed { transform: translateX(-260px); position: absolute; z-index: 50; height: 100%; }

.sb-top { padding: 12px; }
.new-chat-btn {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: transparent; color: var(--text-primary); font-size: 13px; font-weight: 500;
  font-family: inherit; cursor: pointer; display: flex; align-items: center; gap: 8px;
  transition: background 0.15s;
}
.new-chat-btn:hover { background: var(--bg-hover); }

.sb-chats { flex: 1; overflow-y: auto; padding: 4px 8px; }

.chat-item {
  padding: 10px 12px; border-radius: 10px; cursor: pointer; font-size: 13px;
  color: var(--text-primary); display: flex; align-items: center;
  justify-content: space-between; transition: background 0.12s; margin-bottom: 1px;
  white-space: nowrap; overflow: hidden;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-active); }
.chat-item-title { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.chat-del {
  opacity: 0; background: none; border: none; cursor: pointer;
  color: var(--text-tertiary); padding: 2px; flex-shrink: 0; display: flex;
}
.chat-item:hover .chat-del { opacity: 1; }
.chat-del:hover { color: #ef4444; }

/* SIDEBAR BOTTOM */
.sb-bottom {
  padding: 12px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.sb-user { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.sb-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent);
  color: var(--accent-text); display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; flex-shrink: 0;
}
.sb-user-info { min-width: 0; }
.sb-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-plan {
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-tertiary); margin-top: 1px;
}
.sb-plan.plus { color: var(--text-primary); }
.sb-plan.ultra { color: #a855f7; }

.sb-actions { display: flex; gap: 4px; }
.sb-action-btn {
  width: 32px; height: 32px; border: none; border-radius: 8px; background: transparent;
  color: var(--text-secondary); cursor: pointer; display: flex; align-items: center;
  justify-content: center; transition: background 0.15s, color 0.15s;
}
.sb-action-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ===== MAIN ===== */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* HEADER */
.header {
  height: 48px; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.menu-toggle {
  background: none; border: none; cursor: pointer; color: var(--text-secondary);
  display: flex; align-items: center; padding: 4px; border-radius: 6px;
  transition: color 0.15s;
}
.menu-toggle:hover { color: var(--text-primary); }

.model-select { flex: 1; }
.model-select select {
  background: transparent; border: none; color: var(--text-primary);
  font-size: 14px; font-weight: 500; font-family: inherit; cursor: pointer;
  outline: none; padding: 4px 0;
}
.model-select select option { background: var(--bg-main); color: var(--text-primary); }

.header-credits {
  font-size: 12px; color: var(--text-tertiary); background: var(--bg-sidebar);
  padding: 4px 10px; border-radius: 8px; white-space: nowrap;
}

/* CONTENT */
.content { flex: 1; overflow-y: auto; position: relative; }

/* WELCOME */
.welcome {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 40px 24px;
  transition: opacity 0.3s;
}
.welcome.hidden { opacity: 0; pointer-events: none; }
.welcome-icon { margin-bottom: 16px; }
.welcome-icon img { width: 40px; height: 40px; opacity: 0.6; }
.welcome h1 { font-size: 24px; font-weight: 600; margin-bottom: 6px; }
.welcome p { color: var(--text-secondary); font-size: 15px; margin-bottom: 28px; }

.prompts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-width: 480px; width: 100%; }
.prompt {
  padding: 14px; border: 1px solid var(--border); border-radius: 12px;
  background: transparent; color: var(--text-primary); font-size: 13px;
  font-family: inherit; cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: 10px; transition: background 0.15s, border-color 0.15s;
}
.prompt:hover { background: var(--bg-hover); border-color: var(--text-tertiary); }
.prompt-icon { font-size: 16px; flex-shrink: 0; }

/* MESSAGES */
.messages { display: none; padding-bottom: 8px; }
.messages.visible { display: block; }

.msg { padding: 20px 0; animation: fadeUp 0.25s ease; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-row { max-width: 700px; margin: 0 auto; padding: 0 24px; display: flex; gap: 14px; }
.msg.ai { background: var(--bg-msg-ai); }

.msg-ava {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; margin-top: 1px;
}
.msg.ai .msg-ava { border: 1px solid var(--border); background: var(--bg-main); }
.msg.ai .msg-ava img { width: 16px; height: 16px; }
.msg.user .msg-ava { background: var(--accent); color: var(--accent-text); }

.msg-text {
  flex: 1; font-size: 14px; line-height: 1.7; min-width: 0; word-wrap: break-word;
}
.msg-text pre {
  background: var(--bg-code); color: #d4d4d4; padding: 14px; border-radius: 10px;
  overflow-x: auto; margin: 10px 0; font-size: 13px; line-height: 1.5;
}
.msg-text code {
  background: var(--bg-hover); padding: 2px 5px; border-radius: 4px; font-size: 12px;
}
.msg-text pre code { background: none; padding: 0; font-size: 13px; }

/* CURSOR */
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }
.cursor {
  display: inline-block; width: 2px; height: 15px; background: var(--text-primary);
  margin-left: 1px; vertical-align: text-bottom; animation: blink 0.7s infinite;
}

/* ===== INPUT ===== */
.input-area { padding: 12px 24px 16px; flex-shrink: 0; }
.input-box {
  max-width: 700px; margin: 0 auto; display: flex; align-items: flex-end;
  border: 1px solid var(--border); border-radius: 14px;
  padding: 6px 6px 6px 16px; background: var(--bg-input);
  transition: border-color 0.2s, background 0.3s, box-shadow 0.2s;
}
.input-box:focus-within {
  border-color: var(--text-tertiary);
  box-shadow: 0 0 0 3px var(--shadow);
}

#msgInput {
  flex: 1; border: none; outline: none; font-size: 14px; font-family: inherit;
  resize: none; max-height: 180px; line-height: 1.5; padding: 8px 0;
  background: transparent; color: var(--text-primary);
}
#msgInput::placeholder { color: var(--text-tertiary); }

#sendBtn {
  width: 34px; height: 34px; border: none; border-radius: 10px;
  background: var(--accent); color: var(--accent-text); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: opacity 0.15s;
}
#sendBtn:hover { opacity: 0.8; }
#sendBtn:disabled { opacity: 0.25; cursor: not-allowed; }

.disclaimer {
  text-align: center; font-size: 11px; color: var(--text-tertiary);
  margin-top: 8px; max-width: 700px; margin-left: auto; margin-right: auto;
}

/* SCROLLBAR */
.content::-webkit-scrollbar, .sb-chats::-webkit-scrollbar { width: 5px; }
.content::-webkit-scrollbar-track, .sb-chats::-webkit-scrollbar-track { background: transparent; }
.content::-webkit-scrollbar-thumb, .sb-chats::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 3px;
}

/* RESPONSIVE */
@media (max-width: 768px) {
  .sidebar { position: absolute; z-index: 50; height: 100%; transform: translateX(-260px); }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px var(--shadow); }
  .prompts { grid-template-columns: 1fr; }
}
