@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=DM+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg-base: #0a0e1a;
  --bg-surface: #111827;
  --bg-elevated: #1e293b;
  --bg-input: #0f172a;
  --bg-hover: rgba(255,255,255,0.04);

  --border: #1e293b;
  --border-light: #334155;
  --border-focus: #29A7DE;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #475569;

  --accent: #29A7DE;
  --accent-hover: #1E8FC2;
  --accent-soft: rgba(41,167,222,0.10);
  --accent-border: rgba(41,167,222,0.25);

  --danger: #ef4444;
  --danger-soft: rgba(239,68,68,0.12);
  --success: #22c55e;
  --warning: #f59e0b;

  --font-display: 'Bebas Neue', 'Segoe UI', sans-serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.35);
  --shadow-glow: 0 4px 20px rgba(41,167,222,0.25);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font-family: inherit; }
::selection { background: var(--accent-soft); color: var(--text-primary); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: var(--radius-full); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Login ---------- */
.login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(41,167,222,0.08), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(41,167,222,0.06), transparent 40%),
    var(--bg-base);
}
.login-card {
  width: 360px;
  max-width: 90vw;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px 32px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-brand {
  font-family: var(--font-display);
  font-size: 48px;
  letter-spacing: 2px;
  color: var(--accent);
  text-shadow: var(--shadow-glow);
  margin: 0 0 4px;
}
.login-sub {
  color: var(--text-secondary);
  font-size: 12px;
  margin: 0 0 28px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.field { text-align: left; margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.field input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color 150ms var(--ease-out), box-shadow 150ms var(--ease-out);
}
.field input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #051018;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: transform 120ms var(--ease-out), box-shadow 120ms var(--ease-out);
  box-shadow: 0 2px 16px rgba(41,167,222,0.3);
}
.btn-primary:hover { box-shadow: 0 4px 24px rgba(41,167,222,0.45); }
.btn-primary:active { transform: scale(0.98); }
.login-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 12px;
  min-height: 16px;
}

/* ---------- App shell ---------- */
.app {
  display: none;
  height: 100vh;
  grid-template-columns: 280px 1fr;
}
.app.active { display: grid; }

.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
}
.sidebar-brand {
  font-family: var(--font-display);
  font-size: 30px;
  letter-spacing: 1.5px;
  color: var(--accent);
  margin: 4px 4px 24px;
}
.sidebar-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin: 4px 8px 8px;
}
.proyecto-list { list-style: none; margin: 0 0 20px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.proyecto-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 120ms var(--ease-out), color 120ms var(--ease-out);
  border: 1px solid transparent;
}
.proyecto-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.proyecto-item.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--text-primary);
}
.proyecto-nombre { font-weight: 500; text-transform: capitalize; }
.nivel-badge {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  white-space: nowrap;
}
.nivel-badge[data-nivel="1"] { background: rgba(148,163,184,0.15); color: #94a3b8; }
.nivel-badge[data-nivel="2"] { background: var(--warning); color: #1a1200; opacity: 0.85; }
.nivel-badge[data-nivel="3"] { background: var(--danger); color: #1a0505; opacity: 0.85; }

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.user-chip { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: 13px; overflow: hidden; }
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; flex-shrink: 0;
}
.icon-btn {
  background: transparent; border: 1px solid var(--border-light);
  color: var(--text-secondary); border-radius: var(--radius-sm);
  width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background 120ms var(--ease-out), color 120ms var(--ease-out);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ---------- Chat ---------- */
.chat {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
}
.chat-header {
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
}
.chat-header h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 22px;
  letter-spacing: 0.5px;
  margin: 0;
  text-transform: capitalize;
}
.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-muted); gap: 8px; text-align: center; padding: 24px;
}
.chat-empty .big { font-family: var(--font-display); font-size: 26px; color: var(--text-secondary); letter-spacing: 1px; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.msg { display: flex; gap: 12px; max-width: 780px; }
.msg-user { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700;
}
.msg-user .msg-avatar { background: var(--accent-soft); color: var(--accent); }
.msg-ai .msg-avatar { background: var(--bg-elevated); color: var(--text-secondary); border: 1px solid var(--border-light); }
.msg-body {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-user .msg-body { background: var(--accent-soft); border-color: var(--accent-border); }
.msg-ai .msg-body { background: var(--bg-surface); }
.msg-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.msg-time { font-size: 10px; color: var(--text-muted); }
.speak-btn {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 2px; display: flex; align-items: center; transition: color 120ms var(--ease-out);
}
.speak-btn:hover { color: var(--accent); }
.speak-btn.speaking { color: var(--accent); animation: pulse 1.1s infinite ease-in-out; }

.thinking { display: flex; gap: 4px; padding: 6px 2px; }
.thinking span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  animation: pulse 1.1s infinite ease-in-out;
}
.thinking span:nth-child(2) { animation-delay: 0.15s; }
.thinking span:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }

.chat-inputbar {
  border-top: 1px solid var(--border);
  padding: 16px 28px 20px;
  background: var(--bg-surface);
}
.inputbar-inner {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 16px;
  transition: border-color 150ms var(--ease-out), box-shadow 150ms var(--ease-out);
}
.inputbar-inner:focus-within { border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-soft); }
.inputbar-inner textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  resize: none;
  max-height: 160px;
  padding: 8px 0;
  font-family: inherit;
}
.inputbar-inner textarea::placeholder { color: var(--text-muted); }
.round-btn {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  border: 1px solid var(--border-light); background: var(--bg-elevated);
  color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 150ms var(--ease-out);
}
.round-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.round-btn.mic-active { background: var(--danger-soft); border-color: rgba(239,68,68,0.4); color: var(--danger); animation: mic-pulse 1.4s infinite; }
@keyframes mic-pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.35);} 50% { box-shadow: 0 0 0 6px rgba(239,68,68,0);} }
.round-btn.send { background: linear-gradient(135deg, var(--accent), var(--accent-hover)); color: #051018; border: none; }
.round-btn.send:disabled { opacity: 0.4; cursor: not-allowed; }
.inputbar-hint { font-size: 10px; color: var(--text-muted); margin-top: 8px; text-align: center; }

/* ---------- Modal de ajustes ---------- */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(5,8,16,0.7);
  align-items: center; justify-content: center;
  z-index: 500;
}
.modal-overlay.active { display: flex; }
.modal-card {
  width: 380px; max-width: 90vw;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-lg);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-head h2 { font-family: var(--font-display); font-weight: 400; font-size: 20px; letter-spacing: 0.5px; margin: 0; color: var(--text-primary); }
.field-hint { font-size: 11px; color: var(--text-muted); margin: 6px 2px 0; }
#voice-select {
  width: 100%; background: var(--bg-input); border: 1px solid var(--border-light);
  border-radius: var(--radius-sm); padding: 9px 10px; color: var(--text-primary); font-size: 13px;
}
#voice-rate { width: 100%; accent-color: var(--accent); }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.btn-secondary {
  flex: 1; background: var(--bg-elevated); border: 1px solid var(--border-light);
  color: var(--text-secondary); border-radius: var(--radius-sm); padding: 10px; cursor: pointer;
  font-weight: 500; font-size: 13px; transition: color 120ms var(--ease-out), background 120ms var(--ease-out);
}
.btn-secondary:hover { color: var(--text-primary); background: var(--bg-hover); }
.modal-actions .btn-primary { flex: 1; width: auto; }

@media (max-width: 760px) {
  .app.active { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 30% 0 0; z-index: 50; transform: translateX(-100%); transition: transform 200ms var(--ease-out); }
  .sidebar.open { transform: translateX(0); }
}
