
:root {
  --void: #05010a;
  --bg-deep: #0a0118;
  --bg-panel: rgba(20, 10, 45, 0.65);
  --bg-elevated: rgba(35, 15, 70, 0.7);
  --bg-hover: rgba(60, 30, 110, 0.5);
  --neon: #b47aff;
  --neon-bright: #d4a5ff;
  --neon-deep: #7c3aed;
  --neon-glow: rgba(180, 122, 255, 0.5);
  --neon-glow-strong: rgba(180, 122, 255, 0.8);
  --text: #ece3ff;
  --text-dim: #a396c0;
  --text-faint: #6b5b8a;
  --border: rgba(180, 122, 255, 0.15);
  --border-bright: rgba(180, 122, 255, 0.4);
  --error: #ff5577;
  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--void);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 40% at 20% 10%, rgba(124, 58, 237, 0.18) 0%, transparent 60%),
    radial-gradient(ellipse 50% 40% at 90% 90%, rgba(180, 122, 255, 0.12) 0%, transparent 60%),
    linear-gradient(rgba(180, 122, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(180, 122, 255, 0.025) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 44px 44px, 44px 44px;
  pointer-events: none;
  z-index: 0;
}

#auth-view, #chat-view { display: none; height: 100dvh; position: relative; z-index: 1; }
#auth-view.active, #chat-view.active { display: flex; }

/* AUTH */
#auth-view { align-items: center; justify-content: center; padding: 1rem; }

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow:
    0 0 60px rgba(124, 58, 237, 0.15),
    0 0 100px rgba(180, 122, 255, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  position: relative;
  overflow: hidden;
}

.auth-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--neon), transparent);
}

.auth-card h1 {
  font-size: 1.6rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 0.4rem;
  background: linear-gradient(135deg, var(--neon-bright), var(--neon), var(--neon-deep));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 0.02em;
}

.tagline {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.68rem;
  letter-spacing: 0.22em;
  margin-bottom: 2rem;
  text-transform: uppercase;
  font-weight: 500;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  background: rgba(0, 0, 0, 0.3);
  padding: 0.3rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 0.65rem;
  background: transparent;
  border: none;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s;
  font-family: inherit;
}

.tab.active {
  background: linear-gradient(135deg, var(--neon-deep), var(--neon));
  color: white;
  box-shadow: 0 0 20px var(--neon-glow);
}

#auth-form { display: flex; flex-direction: column; gap: 0.9rem; }

#auth-form input {
  padding: 0.9rem 1.1rem;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  transition: all 0.2s;
}

#auth-form input:focus {
  outline: none;
  border-color: var(--neon);
  box-shadow: 0 0 0 3px var(--neon-glow), inset 0 0 20px rgba(180, 122, 255, 0.05);
}

#auth-form input::placeholder { color: var(--text-faint); }

#auth-submit {
  padding: 0.95rem;
  background: linear-gradient(135deg, var(--neon-deep), var(--neon));
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
  font-family: inherit;
  transition: all 0.2s;
  box-shadow: 0 0 24px var(--neon-glow);
  letter-spacing: 0.03em;
}

#auth-submit:hover:not(:disabled) { box-shadow: 0 0 36px var(--neon-glow-strong); transform: translateY(-1px); }
#auth-submit:disabled { opacity: 0.5; cursor: not-allowed; }

.error { color: var(--error); font-size: 0.85rem; text-align: center; min-height: 1.2em; margin-top: 0.7rem; }

/* CHAT */
#chat-view { overflow: hidden; }

.sidebar {
  width: 280px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.1rem;
  flex-shrink: 0;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 5;
}

.brand {
  font-size: 1.15rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--neon-bright), var(--neon));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 1.2rem;
  padding: 0.4rem 0.2rem;
  letter-spacing: 0.06em;
}

.btn-new {
  padding: 0.75rem;
  background: linear-gradient(135deg, var(--neon-deep), var(--neon));
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  font-family: inherit;
  transition: all 0.2s;
  box-shadow: 0 0 20px var(--neon-glow);
}

.btn-new:hover { box-shadow: 0 0 32px var(--neon-glow-strong); }

.conv-list { flex: 1; overflow-y: auto; margin-bottom: 1rem; }
.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 2px; }

.conv-item {
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.15s;
  border-left: 2px solid transparent;
}

.conv-item:hover { background: var(--bg-hover); color: var(--text); }
.conv-item.active {
  background: var(--bg-elevated);
  color: var(--text);
  border-left-color: var(--neon);
  box-shadow: inset 0 0 20px rgba(180, 122, 255, 0.08);
}

.sidebar-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--text-faint);
  gap: 0.5rem;
}

#user-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; color: var(--text-dim); }

#logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.72rem;
  font-family: inherit;
  transition: all 0.15s;
}

#logout-btn:hover { border-color: var(--error); color: var(--error); }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg-deep); position: relative; z-index: 1; }

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1.4rem;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 1, 24, 0.6);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  gap: 0.75rem;
}

.chat-header h2 { font-size: 0.92rem; font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

.model-select {
  padding: 0.4rem 1.9rem 0.4rem 0.85rem;
  background-color: rgba(35, 15, 70, 0.7);
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23b47aff' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
  background-size: 12px;
  border: 1px solid var(--border-bright);
  border-radius: 999px;
  color: var(--neon);
  font-size: 0.72rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  transition: all 0.2s;
  outline: none;
  max-width: 180px;
  text-overflow: ellipsis;
}

.model-select:hover { border-color: var(--neon); box-shadow: 0 0 12px var(--neon-glow); }
.model-select:focus { border-color: var(--neon); box-shadow: 0 0 16px var(--neon-glow); }
.model-select option { background: #1a0f33; color: var(--text); padding: 0.5rem; }

.messages { flex: 1; overflow-y: auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 2px; }

.empty-state { text-align: center; color: var(--text-faint); margin: auto; padding: 2rem; }
.empty-state h3 { font-size: 1.2rem; color: var(--text-dim); margin-bottom: 0.6rem; font-weight: 500; }

.message {
  max-width: 75%;
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 0.94rem;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--neon-deep), var(--neon));
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 0 24px rgba(124, 58, 237, 0.3);
}

.message.assistant {
  align-self: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.message.typing { color: var(--text-dim); font-style: italic; }
.message.error { color: var(--error); border-color: var(--error); }

.chat-input-area {
  display: flex;
  gap: 0.75rem;
  padding: 1rem 1.4rem;
  border-top: 1px solid var(--border);
  background: rgba(10, 1, 24, 0.6);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

#chat-input {
  flex: 1;
  padding: 0.8rem 1.1rem;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.94rem;
  resize: none;
  max-height: 140px;
  font-family: inherit;
  line-height: 1.5;
  transition: all 0.2s;
}

#chat-input:focus { outline: none; border-color: var(--neon); box-shadow: 0 0 0 3px var(--neon-glow); }
#chat-input::placeholder { color: var(--text-faint); }

#send-btn {
  padding: 0 1.3rem;
  background: linear-gradient(135deg, var(--neon-deep), var(--neon));
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
  transition: all 0.2s;
  box-shadow: 0 0 20px var(--neon-glow);
}

#send-btn:hover:not(:disabled) { box-shadow: 0 0 32px var(--neon-glow-strong); }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.menu-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--neon);
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.menu-btn svg { width: 18px; height: 18px; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 4;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 10;
    background: rgba(10, 1, 24, 0.95);
    box-shadow: 4px 0 40px rgba(180, 122, 255, 0.2);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { display: block; }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
  .menu-btn { display: flex; }
  .chat-header { padding: 0.75rem 1rem; }
  .chat-header h2 { font-size: 0.85rem; }
  .model-select { font-size: 0.68rem; max-width: 130px; }
  .messages { padding: 1rem; }
  .message { max-width: 88%; }
  .chat-input-area { padding: 0.75rem 1rem; }
  .auth-card { padding: 1.8rem 1.3rem; }
  .auth-card h1 { font-size: 1.35rem; }
  .tagline { font-size: 0.6rem; }
}


/* model picker in sidebar */
.model-picker {
  margin-bottom: 1rem;
  padding: 0.65rem 0.85rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.model-picker-label {
  display: block;
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.4rem;
  font-weight: 500;
}
.model-picker .model-select {
  width: 100%;
  max-width: none;
  padding: 0.5rem 1.9rem 0.5rem 0.7rem;
  font-size: 0.8rem;
  background-color: rgba(35, 15, 70, 0.7);
  border-color: var(--border-bright);
}
