:root {
  --bg: #0a0a0f;
  --bg-elev: #14141d;
  --sidebar-bg: #0d0d13;
  --text: #eef0f7;
  --text-dim: #8b8fa3;
  --accent: #dc2626;
  --accent-2: #ef4444;
  --bubble-user: #1c2130;
  --bubble-assistant: #14141c;
  --border: #232330;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: inherit; text-decoration: none; }

/* ---------- Shell general (chat logueado) ---------- */

.shell {
  display: flex;
  height: 100dvh;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 14px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px 10px;
  border-bottom: 1px solid var(--border);
}
.brand-logo { width: 40px; height: 40px; border-radius: 10px; }
.sidebar-brand strong { display: block; font-size: 1.05rem; }
.sidebar-brand span { font-size: 0.65rem; letter-spacing: 0.08em; color: var(--accent); font-weight: 700; }

.nav-item {
  display: block;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text);
  font-size: 0.88rem;
  transition: background 0.15s;
}
.nav-item:hover { background: var(--bg-elev); }
.new-chat {
  border: 1px solid var(--accent);
  color: var(--accent-2);
  font-weight: 600;
  text-align: center;
}
.new-chat:hover { background: rgba(220, 38, 38, 0.1); }

.nav-group { flex: 1; overflow-y: auto; min-height: 0; display: flex; flex-direction: column; }
.nav-label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 6px 4px;
}
.chat-list { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.chat-list-item {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.83rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-list-item:hover { background: var(--bg-elev); color: var(--text); }
.chat-list-item.active { background: rgba(220, 38, 38, 0.15); color: var(--text); }
.chat-list-empty { font-size: 0.78rem; color: var(--text-dim); padding: 8px 10px; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
}
.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}
.sidebar-user strong { display: block; font-size: 0.82rem; }
.sidebar-user span { display: block; font-size: 0.7rem; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout { color: var(--text-dim); }

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 30;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 1.1rem;
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 19;
}
.sidebar-backdrop.visible { display: block; }

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

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo-small { width: 34px; height: 34px; border-radius: 9px; }
.brand h1 { font-size: 1.05rem; margin: 0; line-height: 1.1; }
.tagline { margin: 0; font-size: 0.72rem; color: var(--text-dim); }

.header-switch { font-size: 0.75rem; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.45;
  font-size: 0.95rem;
  overflow-wrap: break-word;
}
.msg p { margin: 0; }

.msg-user {
  align-self: flex-end;
  background: var(--bubble-user);
  border-bottom-right-radius: 4px;
}

.msg-assistant {
  align-self: flex-start;
  background: var(--bubble-assistant);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg-error {
  align-self: flex-start;
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}

.msg-pending { opacity: 0.6; }

.msg-provider {
  display: block;
  margin-top: 6px;
  font-size: 0.66rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.listening-indicator {
  text-align: center;
  font-size: 0.85rem;
  color: var(--accent-2);
  padding: 4px 0;
}
.listening-indicator.hidden { display: none; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.3;
}
.composer textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.icon-btn {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:active { transform: scale(0.94); }

.send-btn { background: var(--accent); color: #fff; border-color: transparent; }

.mic-btn.recording {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
  animation: pulse 1.2s infinite;
}

.icon-btn[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: transparent; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5); }
  70% { box-shadow: 0 0 0 10px rgba(220, 38, 38, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

.switch { display: flex; align-items: center; gap: 8px; color: var(--text-dim); }
.switch input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- Mobile ---------- */
@media (max-width: 880px) {
  .sidebar-toggle { display: flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: 82vw;
    max-width: 300px;
  }
  .sidebar.open { transform: translateX(0); }
  .app-header { padding-left: 58px; }
}

/* ---------- Login / Registro ---------- */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 20px;
  background: radial-gradient(circle at top, #17141a 0%, #0a0a0f 60%);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px 28px;
  text-align: center;
}

.auth-logo { width: 84px; height: 84px; border-radius: 50%; margin-bottom: 12px; }
.auth-card h1 { font-size: 1.3rem; margin: 0 0 4px; }
.auth-tagline { color: var(--text-dim); font-size: 0.82rem; margin: 0 0 22px; }

.auth-error {
  background: rgba(220, 38, 38, 0.12);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.82rem;
  margin-bottom: 16px;
}

.auth-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.auth-form label { font-size: 0.78rem; color: var(--text-dim); display: flex; flex-direction: column; gap: 6px; }
.auth-form input[type="email"],
.auth-form input[type="password"],
.auth-form input[type="text"] {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  color: var(--text);
  font-size: 0.95rem;
}
.auth-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.auth-checkbox { flex-direction: row !important; align-items: center; gap: 8px !important; }
.auth-checkbox input { accent-color: var(--accent); width: 16px; height: 16px; }

.auth-btn {
  margin-top: 4px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
.auth-btn:hover { background: var(--accent-2); }

.auth-switch { margin-top: 20px; font-size: 0.82rem; color: var(--text-dim); }
.auth-switch a { color: var(--accent-2); font-weight: 600; }

/* ---------- Panel admin ---------- */

.admin-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px 60px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.admin-section h2 {
  font-size: 0.95rem;
  margin: 0 0 12px;
  color: var(--text);
  border-left: 3px solid var(--accent);
  padding-left: 10px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.stat-card {
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.stat-card strong { display: block; font-size: 0.9rem; }
.stat-sub { display: block; font-size: 0.72rem; color: var(--text-dim); margin-top: 2px; }

.stat-big { flex-direction: column; align-items: flex-start; gap: 2px; }
.stat-big strong { font-size: 1.8rem; color: var(--accent-2); }

.status-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.status-ok { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
.status-off { background: #4b4b57; }

.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.admin-table th, .admin-table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.admin-table td:last-child { white-space: normal; }
.admin-table th { color: var(--text-dim); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover { background: var(--bg-elev); }
