:root {
  --bg: #0b0d12;
  --panel: #131722;
  --panel-soft: #1a2030;
  --line: #2a3146;
  --text: #f4f7ff;
  --muted: #9aa4c0;
  --accent: #58f7c2;
  --accent-2: #7d8fff;
  --error: #ff6978;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Manrope', sans-serif;
  background: radial-gradient(circle at 20% 10%, #151c30 0%, var(--bg) 45%);
  color: var(--text);
  min-height: 100vh;
}
body.auth-locked { overflow: hidden; }
.hidden { display: none !important; }

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
  position: fixed;
  inset: 0;
  z-index: 30;
  background: radial-gradient(circle at 20% 10%, #151c30 0%, var(--bg) 45%);
}
.auth-wrap.is-loading .auth-card { display: none; }
.auth-wrap.is-loading::after {
  content: 'Comprobando sesión...';
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.auth-card {
  width: min(420px, 94vw);
  background: #121826;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
}
.auth-card h1 { margin: 0 0 8px; }
.auth-card p { color: var(--muted); margin: 0 0 14px; }
.auth-form { display: grid; gap: 10px; }
.auth-form input {
  border: 1px solid var(--line);
  background: #0e1422;
  color: var(--text);
  border-radius: 10px;
  padding: 10px;
}
.auth-form button {
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #42dba8 0%, #4db7ff 100%);
  color: #001417;
  font-weight: 700;
  padding: 10px;
}
.auth-error { min-height: 16px; color: #ffb8c0; font-size: 12px; }

.app-shell { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(170deg, #0d111b 0%, #101522 100%);
  border-right: 1px solid var(--line);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sidebar h1 { font-family: 'Syne', sans-serif; margin: 0; font-size: 28px; }
.tagline { color: var(--muted); margin: 6px 0 10px; }

.ghost-btn {
  width: 100%;
  border: 1px solid var(--line);
  background: #0f1422;
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}

.conversation-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.conversation-item {
  text-align: left;
  border: 1px solid var(--line);
  background: #0f1524;
  color: var(--text);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  display: grid;
  gap: 4px;
}
.conversation-item small { color: var(--muted); font-size: 11px; }
.conversation-item.active { border-color: var(--accent-2); background: #18213a; }

.chat-panel { display: flex; flex-direction: column; height: 100vh; }
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 16px 22px;
  background: rgba(11, 14, 21, 0.84);
}
.chat-header h2 { margin: 0; font-size: 16px; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.logout-btn { width: auto; padding: 6px 10px; }

.status {
  font-size: 12px;
  color: var(--accent);
  border: 1px solid rgba(88, 247, 194, 0.4);
  padding: 4px 10px;
  border-radius: 999px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.message {
  max-width: 74ch;
  white-space: pre-wrap;
  line-height: 1.45;
  border-radius: 16px;
  padding: 14px 16px;
}
.message.user { margin-left: auto; background: linear-gradient(135deg, #304cbf 0%, #6075ff 100%); }
.message.assistant { background: var(--panel-soft); border: 1px solid var(--line); }
.message.error { background: rgba(255, 105, 120, 0.12); border: 1px solid rgba(255, 105, 120, 0.45); color: #ffd8de; }
.message-time { display: block; margin-top: 6px; font-size: 11px; opacity: 0.8; }

.typing { color: var(--muted); font-size: 14px; padding-left: 2px; }

.chat-input-wrap {
  border-top: 1px solid var(--line);
  background: rgba(10, 13, 20, 0.95);
  padding: 16px;
  display: flex;
  gap: 12px;
}
#chatInput {
  flex: 1;
  resize: none;
  min-height: 52px;
  max-height: 160px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #0e1422;
  color: var(--text);
  padding: 14px;
  font-family: inherit;
  font-size: 15px;
}
#chatInput:focus { outline: none; border-color: var(--accent-2); }
#sendButton {
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #42dba8 0%, #4db7ff 100%);
  color: #001417;
  font-weight: 700;
  width: 108px;
  cursor: pointer;
}
#sendButton:disabled { opacity: 0.5; cursor: wait; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
