/* Syrtra AI — estilos de la web (sin dependencias externas). */

:root {
  --bg: #0d0f14;
  --bg-elev: #151821;
  --bg-elev-2: #1c2030;
  --border: #262b3b;
  --text: #e8eaf2;
  --text-dim: #9aa1b7;
  --accent: #7c5cff;
  --accent-2: #22c3ee;
  --accent-soft: rgba(124, 92, 255, 0.14);
  --danger: #ff5d73;
  --success: #34d399;
  --user-bubble: linear-gradient(135deg, #7c5cff, #5b6cff);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --sidebar-w: 280px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fb;
    --bg-elev: #ffffff;
    --bg-elev-2: #eef0f7;
    --border: #e0e3ee;
    --text: #151827;
    --text-dim: #5f6680;
    --accent-soft: rgba(124, 92, 255, 0.1);
    --shadow: 0 10px 40px rgba(20, 24, 50, 0.1);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
code { font-family: var(--mono); font-size: 0.9em; }

/* ---------- Marca ---------- */
.logo-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  box-shadow: 0 6px 20px rgba(124, 92, 255, 0.35);
}
.logo-mark.big { width: 64px; height: 64px; border-radius: 18px; font-size: 32px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 700; font-size: 20px; letter-spacing: 0.2px; }
.brand.small .logo-mark { width: 30px; height: 30px; font-size: 15px; border-radius: 9px; }
.brand.small .brand-name { font-size: 17px; }

.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.boot .logo-mark { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(0.92); opacity: 0.7; } }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 600;
  transition: transform 0.08s ease, background 0.2s ease, opacity 0.2s ease;
}
.btn:active { transform: scale(0.98); }
.btn.block { width: 100%; }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.primary { background: linear-gradient(135deg, var(--accent), #5b6cff); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.outline { background: transparent; border-color: var(--border); }
.btn.outline:hover { background: var(--bg-elev-2); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn .spinner { display: none; }
.btn.loading .btn-label { opacity: 0.7; }
.btn.loading .spinner { display: inline-block; }
.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: var(--bg-elev-2);
}
.icon-btn.ghost { background: transparent; color: var(--text-dim); }
.icon-btn.ghost:hover { background: var(--bg-elev-2); color: var(--text); }
.link-btn { background: none; border: none; color: var(--accent); font-weight: 600; padding: 0; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Acceso ---------- */
.auth {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(600px 400px at 15% 10%, rgba(124, 92, 255, 0.18), transparent 60%),
    radial-gradient(500px 400px at 90% 90%, rgba(34, 195, 238, 0.14), transparent 60%);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 28px 24px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  animation: rise 0.35s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.auth-title { margin: 22px 0 4px; font-size: 24px; line-height: 1.25; }
.auth-sub { margin: 0 0 22px; color: var(--text-dim); }
.tabs {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  background: var(--bg-elev-2);
  border-radius: 12px;
  margin-bottom: 20px;
}
.tab {
  position: relative;
  z-index: 1;
  padding: 9px 0;
  border: none;
  background: none;
  border-radius: 9px;
  font-weight: 600;
  color: var(--text-dim);
  transition: color 0.2s ease;
}
.tab.active { color: var(--text); }
.tab-indicator {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: calc(50% - 4px);
  border-radius: 9px;
  background: var(--bg-elev);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: transform 0.25s ease;
}
.tabs.register .tab-indicator { transform: translateX(100%); }
.auth-form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 14px; font-weight: 600; color: var(--text-dim); }
.field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 48px; }
.password-wrap .icon-btn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.form-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 93, 115, 0.12);
  color: var(--danger);
  font-size: 14px;
}
.auth-switch { margin: 18px 0 0; text-align: center; color: var(--text-dim); font-size: 14px; }
.auth-foot { margin-top: 18px; color: var(--text-dim); font-size: 13px; }

/* ---------- Layout del chat ---------- */
.app { display: flex; height: 100%; height: 100dvh; overflow: hidden; }
.sidebar {
  width: var(--sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 12px;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; }
.conversation-list { flex: 1; overflow-y: auto; display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 2px; }
.conversation-list .group-label { padding: 10px 10px 4px; font-size: 12px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.conv-item {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: 10px;
  background: none;
  text-align: left;
  color: var(--text-dim);
}
.conv-item:hover { background: var(--bg-elev-2); color: var(--text); }
.conv-item.active { background: var(--accent-soft); color: var(--text); }
.conv-item .conv-title { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 14px; }
.conv-item .conv-delete { opacity: 0; width: 28px; height: 28px; }
.conv-item:hover .conv-delete, .conv-item.active .conv-delete { opacity: 1; }
@media (hover: none) { .conv-item .conv-delete { opacity: 0.7; } }
.conv-delete svg { width: 16px; height: 16px; }
.sidebar-bottom { display: grid; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.side-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: none;
  border-radius: 10px;
  background: none;
  color: var(--text-dim);
  font-size: 14px;
}
.side-item:hover { background: var(--bg-elev-2); color: var(--text); }
.user-row { display: flex; align-items: center; gap: 10px; padding: 4px; }
.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-elev-2);
  font-weight: 700;
  color: var(--accent);
  flex: none;
}
.user-info { flex: 1; min-width: 0; display: grid; }
.user-name, .user-email { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.user-name { font-weight: 600; font-size: 14px; }
.user-email { font-size: 12px; color: var(--text-dim); }

.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
}
.chat-title { flex: 1; margin: 0; font-size: 16px; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.model-badge {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

/* ---------- Mensajes ---------- */
.messages { flex: 1; overflow-y: auto; padding: 24px 16px 8px; scroll-behavior: smooth; }
.message { display: flex; gap: 12px; max-width: 820px; margin: 0 auto 22px; animation: rise 0.25s ease; }
.message .msg-avatar { width: 30px; height: 30px; border-radius: 9px; font-size: 14px; flex: none; }
.message.user { justify-content: flex-end; }
.message.user .bubble {
  max-width: 85%;
  padding: 10px 16px;
  border-radius: 18px 18px 4px 18px;
  background: var(--user-bubble);
  color: #fff;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.message.assistant .bubble { flex: 1; min-width: 0; padding-top: 3px; word-wrap: break-word; }
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 10px; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble h1, .bubble h2, .bubble h3 { margin: 14px 0 8px; line-height: 1.3; }
.bubble h1 { font-size: 20px; } .bubble h2 { font-size: 18px; } .bubble h3 { font-size: 16px; }
.bubble a { color: var(--accent-2); }
.bubble :not(pre) > code { padding: 2px 6px; border-radius: 6px; background: var(--bg-elev-2); }
.bubble pre {
  position: relative;
  margin: 0 0 10px;
  padding: 14px;
  border-radius: 12px;
  background: #0a0c11;
  color: #e6e8f0;
  border: 1px solid var(--border);
  overflow-x: auto;
  font-size: 14px;
}
.bubble pre .copy-code {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid #2b3040;
  background: #151821;
  color: #9aa1b7;
  font-size: 12px;
}
.bubble.error { color: var(--danger); }
.msg-actions { display: flex; gap: 4px; margin-top: 6px; }
.msg-actions .icon-btn { width: 30px; height: 30px; }
.msg-actions svg { width: 16px; height: 16px; }
.cursor::after { content: "▍"; margin-left: 2px; animation: blink 1s steps(1) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }
.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); animation: bounce 1.2s infinite; }
.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.5; } 30% { transform: translateY(-5px); opacity: 1; } }

.empty-state { max-width: 720px; margin: 8vh auto 0; text-align: center; padding: 0 8px; }
.empty-state h3 { margin: 18px 0 22px; font-size: 26px; line-height: 1.25; }
.empty-state .logo-mark { margin: 0 auto; }
.suggestions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.suggestion {
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  text-align: left;
  font-size: 14px;
  color: var(--text-dim);
  transition: border-color 0.2s ease, color 0.2s ease, transform 0.1s ease;
}
.suggestion:hover { border-color: var(--accent); color: var(--text); }
.suggestion:active { transform: scale(0.98); }

/* ---------- Compositor ---------- */
.composer { padding: 8px 16px calc(12px + env(safe-area-inset-bottom)); }
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 820px;
  margin: 0 auto;
  padding: 8px 8px 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  box-shadow: var(--shadow);
  transition: border-color 0.2s ease;
}
.composer-box:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1;
  max-height: 200px;
  padding: 8px 0;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  line-height: 1.45;
}
.send-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--accent), #5b6cff);
  color: #fff;
  flex: none;
  transition: opacity 0.2s ease, transform 0.08s ease;
}
.send-btn:disabled { opacity: 0.4; cursor: default; }
.send-btn:active { transform: scale(0.95); }
.send-btn .icon-stop { display: none; }
.send-btn.stop .icon-send { display: none; }
.send-btn.stop .icon-stop { display: block; }
.composer-hint { max-width: 820px; margin: 6px auto 0; text-align: center; font-size: 12px; color: var(--text-dim); }

/* ---------- Diálogo ---------- */
.dialog {
  width: min(560px, calc(100% - 24px));
  padding: 20px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(2px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { margin: 0; font-size: 20px; }
.dialog-text { color: var(--text-dim); font-size: 14px; }
.new-key { display: flex; gap: 8px; }
.new-key input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  outline: none;
}
.new-key input:focus { border-color: var(--accent); }
.key-result { margin-top: 14px; padding: 12px; border-radius: 12px; background: rgba(52, 211, 153, 0.1); border: 1px solid rgba(52, 211, 153, 0.35); }
.key-result p { margin: 0 0 8px; font-size: 14px; }
.key-copy { display: flex; gap: 8px; align-items: center; }
.key-copy code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; padding: 6px 8px; border-radius: 8px; background: var(--bg); }
.keys-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; max-height: 45vh; overflow-y: auto; }
.keys-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.keys-list .key-info { flex: 1; min-width: 0; display: grid; }
.keys-list .key-name { font-weight: 600; font-size: 14px; }
.keys-list .key-meta { font-size: 12px; color: var(--text-dim); }
.keys-list .revoked { opacity: 0.5; }
.keys-empty { color: var(--text-dim); font-size: 14px; text-align: center; padding: 10px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 50;
}

/* ---------- Móvil ---------- */
.only-mobile { display: none; }
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 20; }
@media (max-width: 820px) {
  .only-mobile { display: inline-grid; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(86vw, 320px);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .chat-header { padding: 10px 12px; }
  .messages { padding: 16px 12px 8px; }
  .suggestions { grid-template-columns: 1fr; }
  .empty-state { margin-top: 5vh; }
  .empty-state h3 { font-size: 22px; }
  .message.user .bubble { max-width: 90%; }
  .composer { padding-left: 10px; padding-right: 10px; }
  .auth-card { padding: 24px 18px; }
}
