/* ===== Variables ===== */
:root {
  --bg: #0f0f12;
  --bg-sidebar: #16161a;
  --bg-elevated: #1c1c22;
  --bg-input: #1e1e26;
  --bg-hover: #25252e;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #7c6af0;
  --accent-hover: #6b58e8;
  --accent-soft: rgba(124, 106, 240, 0.15);
  --user-bubble: #2a2a35;
  --ai-bubble: transparent;
  --radius: 16px;
  --radius-sm: 12px;
  --radius-full: 9999px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --sidebar-width: 280px;
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.12);
  --error: #f87171;
  --error-soft: rgba(248, 113, 113, 0.12);
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, textarea {
  font-family: inherit;
  border: none;
  background: none;
  color: inherit;
  outline: none;
}

button {
  cursor: pointer;
}

/* ===== AUTH OVERLAY ===== */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 14, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 24px;
  transition: opacity 0.4s ease, visibility 0.4s;
}

.auth-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 40px 32px;
  box-shadow: var(--shadow);
  animation: cardIn 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.auth-view.hidden {
  display: none;
}

.auth-header {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.logo-icon {
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, #7c6af0, #a78bfa);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: white;
  box-shadow: 0 8px 24px rgba(124, 106, 240, 0.35);
}

.auth-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.auth-header p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.auth-header p strong {
  color: var(--text);
  font-weight: 600;
  word-break: break-all;
}

/* ===== LANDING VIEW ===== */
.landing-view-head {
  margin-bottom: 20px;
}

.chat-preview {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.chat-preview-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.preview-dot {
  width: 8px;
  height: 8px;
  background: #34d399;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.5);
}

.preview-badge {
  margin-left: auto;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: var(--radius-full);
}

.preview-bubble {
  max-width: 85%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

.preview-bubble.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 5px;
  color: var(--text);
}

.preview-bubble.ai {
  align-self: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}

.landing-perks {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 26px;
  text-align: left;
}

.landing-perks li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.2s, background 0.2s;
}

.landing-perks li:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

.perk-icon {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  background: var(--accent-soft);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.landing-perks li div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.landing-perks li strong {
  font-size: 0.85rem;
  font-weight: 600;
}

.landing-perks li span {
  font-size: 0.775rem;
  color: var(--text-muted);
}

.landing-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-ghost {
  width: 100%;
  padding: 14px;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-ghost:active {
  transform: scale(0.98);
}

/* ===== CHECK YOUR EMAIL VIEW ===== */
.logo-icon.email {
  background: linear-gradient(135deg, #34d399, #6ee7b7);
  box-shadow: 0 8px 24px rgba(52, 211, 153, 0.3);
}

.email-hint {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--accent-soft);
  border: 1px solid rgba(124, 106, 240, 0.25);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 22px;
}

.email-hint-icon {
  flex-shrink: 0;
  font-size: 1rem;
  line-height: 1.4;
}

.email-hint p {
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

/* ===== AUTH MESSAGE BANNER ===== */
.auth-msg {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.825rem;
  line-height: 1.5;
  margin-bottom: 18px;
  border: 1px solid transparent;
  animation: msgIn 0.3s ease;
  word-break: break-word;
}

.auth-msg.error {
  background: var(--error-soft);
  border-color: rgba(248, 113, 113, 0.3);
  color: var(--error);
}

.auth-msg.success {
  background: var(--success-soft);
  border-color: rgba(52, 211, 153, 0.3);
  color: var(--success);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.field input {
  width: 100%;
  padding: 13px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field input::placeholder {
  color: var(--text-muted);
}

.password-wrap {
  position: relative;
}

.password-wrap input {
  padding-right: 44px;
}

.toggle-pass {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  padding: 4px;
  display: flex;
  transition: color 0.2s;
}

.toggle-pass:hover {
  color: var(--text-secondary);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  margin-top: 6px;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 6px 20px rgba(124, 106, 240, 0.35);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.text-link {
  color: var(--accent);
  font-weight: 500;
  font-size: inherit;
  transition: color 0.2s;
}

.text-link:hover {
  color: #a78bfa;
}

.back-link {
  font-size: 0.8rem;
}

.auth-switch {
  text-align: center;
  margin-top: 24px;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.auth-switch button {
  color: var(--accent);
  font-weight: 500;
  margin-left: 4px;
  transition: color 0.2s;
}

.auth-switch button:hover {
  color: #a78bfa;
}

/* ===== APP LAYOUT ===== */
.app {
  display: flex;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.app.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.sidebar-top {
  padding: 16px;
}

.new-chat-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  transition: background 0.2s, border-color 0.2s;
}

.new-chat-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.history-section {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 16px;
}

.history-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 12px 10px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-align: left;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item svg {
  flex-shrink: 0;
  opacity: 0.6;
}

.history-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.history-item.active {
  background: var(--accent-soft);
  color: var(--text);
}

.history-item.active svg {
  opacity: 1;
  color: var(--accent);
}

.sidebar-bottom {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  transition: background 0.15s;
}

.user-row:hover {
  background: var(--bg-hover);
}

.avatar {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #7c6af0, #a78bfa);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-plan {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.logout-btn {
  color: var(--text-muted);
  padding: 6px;
  border-radius: 8px;
  transition: color 0.2s, background 0.2s;
}

.logout-btn:hover {
  color: var(--text);
  background: var(--bg-hover);
}

/* ===== CHAT AREA ===== */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.chat-header {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.menu-btn {
  display: none;
  color: var(--text-secondary);
  padding: 6px;
  border-radius: 8px;
  transition: background 0.15s;
}

.menu-btn:hover {
  background: var(--bg-hover);
}

.model-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background 0.15s;
  cursor: pointer;
}

.model-selector:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.model-select {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  cursor: pointer;
  padding-right: 18px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2.4'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right center;
}

.model-select:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
  border-radius: 8px;
}

.model-select option {
  background: var(--bg-elevated);
  color: var(--text);
}

.model-dot {
  width: 8px;
  height: 8px;
  background: #34d399;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.5);
}

.header-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* ===== MESSAGES ===== */
.messages {
  flex: 1;
  overflow-y: auto;
  position: relative;
  scroll-behavior: smooth;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
  transition: opacity 0.3s;
}

.empty-state.hidden {
  opacity: 0;
  pointer-events: none;
}

.empty-icon {
  width: 72px;
  height: 72px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  margin-bottom: 20px;
}

.empty-state h2 {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 520px;
}

.suggestion {
  padding: 10px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 0.825rem;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.suggestion:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  color: var(--text);
}

.message-list {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.message {
  display: flex;
  gap: 14px;
  animation: msgIn 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.message.user .msg-avatar {
  background: linear-gradient(135deg, #7c6af0, #a78bfa);
}

.message.ai .msg-avatar {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--accent);
}

.msg-content {
  max-width: 85%;
}

.message.user .msg-content {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.msg-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .msg-bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 6px;
}

.message.ai .msg-bubble {
  background: transparent;
  padding: 4px 0;
}

.msg-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 6px;
  padding: 0 4px;
}

/* Typing indicator */
.typing {
  display: flex;
  gap: 5px;
  padding: 8px 0;
}

.typing span {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ===== INPUT AREA ===== */
.input-area {
  padding: 12px 20px 20px;
  flex-shrink: 0;
}

.input-form {
  max-width: 760px;
  margin: 0 auto;
}

.input-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 12px 10px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-box:focus-within {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px rgba(124, 106, 240, 0.1);
}

.attach-btn {
  color: var(--text-muted);
  padding: 6px;
  border-radius: 8px;
  flex-shrink: 0;
  margin-bottom: 2px;
  transition: color 0.2s;
}

.attach-btn:hover {
  color: var(--text-secondary);
}

#chatInput {
  flex: 1;
  resize: none;
  max-height: 160px;
  padding: 6px 4px;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text);
  background: transparent;
}

#chatInput::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, opacity 0.2s, transform 0.15s;
}

.send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.send-btn:not(:disabled):active {
  transform: scale(0.95);
}

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

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .menu-btn {
    display: flex;
  }

  .message-list {
    padding: 20px 16px 24px;
  }

  .msg-content {
    max-width: 90%;
  }

  .input-area {
    padding: 10px 14px 16px;
  }

  .auth-card {
    padding: 32px 24px;
  }

  /* Backdrop when sidebar open */
  .sidebar.open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: -1;
  }
}

/* Overlay when sidebar is open on mobile */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
}

.sidebar-backdrop.visible {
  display: block;
}
