/* ================= Atlas — UI moderna ================= */
/* Vanilla + CSS moderno, dark theme, look limpio. */

/* ---------------------------------------------------------------------------
   SISTEMA DE TOKENS
   Tres capas, y solo se toca la de arriba para cambiar el look:

     1. PRIMITIVOS  (--c-*)  paleta cruda. No se usan en las reglas, nunca.
     2. SEMÁNTICOS  (--bg, --text, --accent…)  lo que SÍ usan los componentes.
        Se declaran una vez con light-dark(claro, oscuro). Los nombres son los de
        siempre, así que las reglas existentes siguen funcionando sin tocarlas.
     3. ESCALAS  (spacing, radius, tipografía)  compartidas entre temas.

   Cambiar el look = editar la capa 2. Añadir un tema = añadir un valor por token.

   Tema: `data-theme="light|dark"` en <html> manda (lo escribe un <script> inline
   del <head>, antes del primer paint, para que no haya flash); sin atributo se
   sigue la preferencia del sistema vía `color-scheme: light dark`.
--------------------------------------------------------------------------- */

:root {
  /* ---------- 1. Primitivos ---------- */
  --c-ink-950: #0a0b0e;
  --c-ink-900: #0f1014;
  --c-ink-850: #14161c;
  --c-ink-800: #1a1d25;
  --c-ink-700: #232732;
  --c-ink-600: #2a303b;
  --c-slate-100: #f0f2f7;
  --c-slate-200: #c0c5d1;
  --c-slate-400: #8a92a3;
  --c-slate-500: #5a6273;
  --c-slate-700: #3f4757;
  --c-paper-0: #ffffff;
  --c-paper-50: #f7f8fa;
  --c-paper-100: #eef0f4;
  --c-paper-200: #e2e5ec;
  --c-emerald-300: #4ade80;
  --c-emerald-400: #34d399;
  --c-emerald-600: #12a37a;
  --c-emerald-700: #16a085;
  --c-emerald-950: #07120e;
  --c-blue-300: #93b5ff;
  --c-blue-400: #60a5fa;
  --c-blue-500: #5b8def;
  --c-blue-700: #2563eb;
  --c-red-300: #ffd8d8;
  --c-red-400: #f87171;
  --c-red-500: #ef4444;
  --c-red-700: #b91c1c;
  --c-amber-400: #fbbf24;
  --c-amber-700: #b45309;

  /* ---------- 3. Escalas (comunes a ambos temas) ---------- */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-7: 3rem;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-pill: 999px;

  --fs-xs: 0.72rem;
  --fs-sm: 0.82rem;
  --fs-md: 0.92rem;
  --fs-lg: 1.05rem;
  --fs-xl: 1.25rem;
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-bold: 700;

  --sidebar-w: 264px;
  --topbar-h: 60px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
          "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  /* ---------- 2. Semánticos ----------
     Cada token se declara UNA sola vez con light-dark(claro, oscuro). Cuál se aplica lo
     decide 'color-scheme', que es lo único que cambia el tema. Antes esto eran tres
     bloques duplicados (oscuro + claro explícito + claro del sistema) y ya se habían
     desincronizado dos tokens. */

  --bg:      light-dark(var(--c-paper-50),  var(--c-ink-950));
  --bg-2:    light-dark(var(--c-paper-0),   var(--c-ink-900));
  --panel:   light-dark(var(--c-paper-0),   var(--c-ink-850));
  --panel-2: light-dark(var(--c-paper-50),  var(--c-ink-800));
  --panel-3: light-dark(var(--c-paper-100), var(--c-ink-700));
  --border:    light-dark(rgba(16, 20, 30, 0.10), rgba(255, 255, 255, 0.08));
  --border-hi: light-dark(rgba(16, 20, 30, 0.18), rgba(255, 255, 255, 0.14));
  --text:    light-dark(#12151c, var(--c-slate-100));
  --text-2:  light-dark(#333a49, var(--c-slate-200));
  --muted:   light-dark(#5f6878, var(--c-slate-400));
  --muted-2: light-dark(#838c9d, var(--c-slate-500));

  --accent:      light-dark(var(--c-emerald-600), var(--c-emerald-400));
  --accent-hov:  light-dark(var(--c-emerald-700), var(--c-emerald-300));
  --accent-deep: var(--c-emerald-700);                 /* cierre del degradado de marca */
  --on-accent:   light-dark(var(--c-paper-0), var(--c-emerald-950));
  --accent-soft: light-dark(rgba(18, 163, 122, 0.12), rgba(52, 211, 153, 0.12));
  --accent-glow: light-dark(rgba(18, 163, 122, 0.28), rgba(52, 211, 153, 0.35));

  --blue:      light-dark(var(--c-blue-700), var(--c-blue-400));
  --blue-soft: light-dark(rgba(37, 99, 235, 0.10), rgba(96, 165, 250, 0.14));
  --user:      light-dark(var(--c-blue-700), var(--c-blue-500));
  --user-text: light-dark(var(--c-blue-700), var(--c-blue-300));
  --user-soft: light-dark(rgba(37, 99, 235, 0.10), rgba(91, 141, 239, 0.16));

  --error:        light-dark(#dc2626, var(--c-red-400));
  --error-strong: light-dark(var(--c-red-700), var(--c-red-500));
  --error-text:   light-dark(var(--c-red-700), var(--c-red-300));
  --error-soft:   light-dark(rgba(220, 38, 38, 0.10), rgba(248, 113, 113, 0.14));
  --warn:         light-dark(var(--c-amber-700), var(--c-amber-400));
  --warn-soft:    light-dark(rgba(180, 83, 9, 0.12), rgba(251, 191, 36, 0.14));

  --code-bg:  light-dark(var(--c-paper-100), #0a0c10);
  --on-solid: #ffffff;                                  /* texto sobre botón sólido */

  --glow-1: light-dark(rgba(18, 163, 122, 0.06), rgba(52, 211, 153, 0.04));
  --glow-2: light-dark(rgba(37, 99, 235, 0.05), rgba(96, 165, 250, 0.04));
  --glow-login-1: light-dark(rgba(18, 163, 122, 0.12), rgba(52, 211, 153, 0.10));
  --glow-login-2: light-dark(rgba(37, 99, 235, 0.10), rgba(96, 165, 250, 0.10));
  --login-card-bg: light-dark(rgba(255, 255, 255, 0.88), rgba(20, 22, 28, 0.85));

  /* light-dark() solo admite dos valores, y una sombra multicapa lleva comas: se
     tokeniza el COLOR, no la sombra entera, y así se conserva el borde fino. */
  --shadow-color: light-dark(rgba(16, 20, 30, 0.10), rgba(0, 0, 0, 0.35));
  --shadow-ring:  light-dark(rgba(16, 20, 30, 0.06), rgba(255, 255, 255, 0.06));
  --shadow-ring-sm: light-dark(rgba(16, 20, 30, 0.04), rgba(255, 255, 255, 0.04));
  --shadow-sm: 0 1px 2px var(--shadow-color), 0 0 0 1px var(--shadow-ring-sm);
  --shadow: 0 8px 32px var(--shadow-color), 0 0 0 1px var(--shadow-ring);
  --shadow-glow: 0 0 0 1px var(--accent), 0 0 24px var(--accent-glow);

  /* Sin data-theme seguimos al sistema; con él, manda la elección del usuario. */
  color-scheme: light dark;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

/* Navegador sin light-dark(): se queda con la paleta oscura, que es el look histórico. */
@supports not (color: light-dark(#000, #fff)) {
  :root {
    --bg: var(--c-ink-950); --bg-2: var(--c-ink-900); --panel: var(--c-ink-850);
    --panel-2: var(--c-ink-800); --panel-3: var(--c-ink-700);
    --border: rgba(255,255,255,0.08); --border-hi: rgba(255,255,255,0.14);
    --text: var(--c-slate-100); --text-2: var(--c-slate-200);
    --muted: var(--c-slate-400); --muted-2: var(--c-slate-500);
    --accent: var(--c-emerald-400); --accent-hov: var(--c-emerald-300);
    --on-accent: var(--c-emerald-950);
    --accent-soft: rgba(52,211,153,0.12); --accent-glow: rgba(52,211,153,0.35);
    --blue: var(--c-blue-400); --blue-soft: rgba(96,165,250,0.14);
    --user: var(--c-blue-500); --user-text: var(--c-blue-300); --user-soft: rgba(91,141,239,0.16);
    --error: var(--c-red-400); --error-strong: var(--c-red-500); --error-text: var(--c-red-300);
    --error-soft: rgba(248,113,113,0.14);
    --warn: var(--c-amber-400); --warn-soft: rgba(251,191,36,0.14);
    --code-bg: #0a0c10;
    --glow-1: rgba(52,211,153,0.04); --glow-2: rgba(96,165,250,0.04);
    --glow-login-1: rgba(52,211,153,0.10); --glow-login-2: rgba(96,165,250,0.10);
    --login-card-bg: rgba(20,22,28,0.85);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.35), 0 0 0 1px rgba(255,255,255,0.04);
    --shadow: 0 8px 32px rgba(0,0,0,0.35), 0 0 0 1px rgba(255,255,255,0.06);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
*::selection { background: var(--accent-soft); color: var(--text); }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 0% 0%, var(--glow-1), transparent 60%),
    radial-gradient(1000px 500px at 100% 100%, var(--glow-2), transparent 60%),
    var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.55;
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; transition: color 120ms; }
a:hover { color: var(--accent-hov); }

button, select, textarea, input {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

/* ================= App shell ================= */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  width: 100%;
}

/* Sidebar */
.sidebar {
  background: linear-gradient(180deg, rgba(20, 22, 28, 0.85), rgba(15, 16, 20, 0.92));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}
.sidebar .brand .logo {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  display: grid; place-items: center;
  font-weight: 700; font-size: 0.78rem; color: var(--on-accent);
  box-shadow: 0 4px 12px var(--accent-glow);
}
.sidebar nav {
  padding: 0.7rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1;
  overflow-y: auto;
}
.sidebar nav .nav-section {
  margin: 1rem 0.4rem 0.4rem;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted-2);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  color: var(--text-2);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
  font-size: 0.92rem;
  font-weight: 500;
  text-decoration: none;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.nav-item .nav-icon {
  width: 20px;
  display: inline-flex;
  justify-content: center;
  font-size: 1rem;
  opacity: 0.9;
}

/* Subcontroles en sidebar (selects, mini grupos) */
.sidebar-sub {
  padding: 0 0.6rem;
}
.sidebar-control {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font-size: 0.85rem;
  width: 100%;
  color: var(--text);
  transition: border-color 120ms, background 120ms;
}
.sidebar-control:hover { border-color: var(--border-hi); }
.sidebar-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.sidebar-footer {
  padding: 0.85rem 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.45rem 0.55rem;
  border-radius: 10px;
  transition: background 120ms;
}
.user-chip:hover { background: var(--panel-2); }
.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  display: grid; place-items: center;
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--on-accent);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.user-info { display: flex; flex-direction: column; min-width: 0; }
.user-name {
  font-size: 0.86rem;
  font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-role { font-size: 0.7rem; color: var(--muted); }

/* Main */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.topbar {
  height: var(--topbar-h);
  background: rgba(10, 11, 14, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  flex-shrink: 0;
  position: sticky;
  top: 0; z-index: 10;
}
.topbar h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.015em;
}
.topbar .topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ================= Componentes base ================= */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.95rem;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 500;
  transition: background 120ms ease, border-color 120ms ease, transform 60ms ease;
  color: var(--text);
}
.btn:hover { background: var(--panel-3); border-color: var(--border-hi); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  box-shadow: 0 4px 14px var(--accent-glow);
}
.btn-primary:hover {
  background: var(--accent-hov);
  border-color: var(--accent-hov);
  box-shadow: 0 6px 18px var(--accent-glow);
}
.btn-danger { background: transparent; border-color: var(--error); color: var(--error); }
.btn-danger:hover { background: var(--error-soft); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--panel-2); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.82rem; }
.btn-icon { padding: 0.45rem; }

.input, select.input, textarea.input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.85rem;
  color: var(--text);
  font: inherit;
  transition: border-color 120ms, box-shadow 120ms, background 120ms;
}
.input:hover { border-color: var(--border-hi); }
.input:focus, select.input:focus, textarea.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--panel-3);
}
textarea.input { resize: vertical; line-height: 1.55; }

.label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
  font-weight: 500;
}

.field { margin-bottom: 1rem; }
.field .help { font-size: 0.76rem; color: var(--muted-2); margin-top: 0.3rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.3rem 1.4rem;
  transition: border-color 120ms, transform 120ms;
}
.card:hover { border-color: var(--border-hi); }
.card h2 {
  margin: 0 0 1rem;
  font-size: 0.98rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.card h3 { margin: 0 0 0.5rem; font-size: 0.88rem; font-weight: 600; }
.card .desc { color: var(--muted); font-size: 0.86rem; margin-top: 0.3rem; line-height: 1.55; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--panel-2);
}
.badge-ok { color: var(--accent); border-color: rgba(52, 211, 153, 0.4); background: var(--accent-soft); }
.badge-bad { color: var(--error); border-color: rgba(248, 113, 113, 0.4); background: var(--error-soft); }
.badge-warn { color: var(--warn); border-color: rgba(251, 191, 36, 0.4); background: var(--warn-soft); }
.badge-info { color: var(--blue); border-color: rgba(96, 165, 250, 0.4); background: var(--blue-soft); }

.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  margin-right: 0.4rem;
  vertical-align: middle;
}
.dot-ok { background: var(--accent); box-shadow: 0 0 12px var(--accent-glow); }
.dot-bad { background: var(--error); box-shadow: 0 0 12px rgba(248, 113, 113, 0.5); }
.dot-warn { background: var(--warn); box-shadow: 0 0 12px rgba(251, 191, 36, 0.5); }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.table th, .table td {
  text-align: left;
  padding: 0.7rem 0.95rem;
  border-bottom: 1px solid var(--border);
}
.table th {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: rgba(20, 22, 28, 0.6);
  backdrop-filter: blur(10px);
  position: sticky; top: 0;
}
.table tbody tr { transition: background 100ms; }
.table tbody tr:hover td { background: var(--panel-2); }
.table .actions { white-space: nowrap; text-align: right; }
.table .mono { font-family: var(--mono); font-size: 0.83em; color: var(--muted); }

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.4rem;
  padding: 0 1.5rem;
  background: var(--bg);
  overflow-x: auto;
  position: sticky;
  top: 0;
  z-index: 5;
}
.tab {
  padding: 0.85rem 1rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.88rem;
  transition: color 120ms, border-color 120ms;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3.5rem 1rem;
  color: var(--muted);
  text-align: center;
}

.progress {
  width: 100%; height: 6px;
  background: var(--panel-3);
  border-radius: 999px;
  overflow: hidden;
}
.progress > .bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--blue));
  border-radius: 999px;
  transition: width 250ms ease;
}
.progress.danger > .bar { background: linear-gradient(90deg, var(--warn), var(--error)); }

.kbd {
  font-family: var(--mono);
  font-size: 0.76em;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.06em 0.45em;
  color: var(--muted);
}

.toast-host {
  position: fixed; right: 1.25rem; bottom: 1.25rem;
  display: flex; flex-direction: column; gap: 0.55rem;
  z-index: 9999;
}
.toast {
  background: rgba(20, 22, 28, 0.95);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-hi);
  border-radius: 12px;
  padding: 0.85rem 1.1rem;
  box-shadow: var(--shadow);
  max-width: 380px;
  font-size: 0.88rem;
  animation: toast-in 200ms cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.error { border-color: var(--error); }
.toast.ok { border-color: var(--accent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

.modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4vh 1rem 2rem;
  z-index: 1000;
  animation: fade-in 180ms ease;
  overflow-y: auto;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-xl);
  width: min(480px, calc(100vw - 2rem));
  padding: 1.6rem 1.7rem;
  box-shadow: var(--shadow);
  animation: modal-in 220ms cubic-bezier(0.16, 1, 0.3, 1);
  margin: auto 0;
}
.modal h2 { margin: 0 0 1rem; font-size: 1.1rem; letter-spacing: -0.015em; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 0.55rem; margin-top: 1.2rem; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }

.row { display: flex; gap: 0.55rem; align-items: center; }
.row-between { display: flex; gap: 0.55rem; align-items: center; justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 0.55rem; }
.gap-2 { gap: 1rem; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.small { font-size: 0.8rem; }
.center { text-align: center; }
.grow { flex: 1; }
.padded { padding: 1.5rem; }

/* Bell + notifs */
.bell-wrap { position: relative; display: inline-block; }
.bell {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  cursor: pointer;
  position: relative;
  transition: background 120ms, border-color 120ms, transform 60ms;
  font-size: 1rem;
}
.bell:hover { background: var(--panel-3); border-color: var(--border-hi); }
.bell:active { transform: scale(0.95); }
.bell .count {
  position: absolute;
  top: -4px; right: -4px;
  background: var(--error);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 999px;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  display: grid; place-items: center;
  border: 2px solid var(--bg);
}
.notif-panel {
  position: absolute;
  top: 48px; right: 0;
  width: 380px;
  max-height: 500px;
  background: rgba(20, 22, 28, 0.96);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 100;
  animation: modal-in 180ms cubic-bezier(0.16, 1, 0.3, 1);
}
.notif-panel header {
  padding: 0.85rem 1.05rem;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 600;
}
.notif-panel .list { overflow-y: auto; flex: 1; }
.notif-item {
  padding: 0.85rem 1.05rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  position: relative;
  transition: background 100ms;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--panel-2); }
.notif-item.unread::before {
  content: '';
  position: absolute;
  left: 0.45rem; top: 50%;
  transform: translateY(-50%);
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}
.notif-item.unread { padding-left: 1.4rem; }
.notif-item .title { font-weight: 600; font-size: 0.9rem; padding-right: 2rem; }
.notif-item .body { color: var(--muted); font-size: 0.82rem; margin-top: 0.25rem; line-height: 1.5; }
.notif-item .meta { color: var(--muted-2); font-size: 0.7rem; margin-top: 0.35rem; }
.notif-item .speak {
  position: absolute;
  top: 0.85rem; right: 0.85rem;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  opacity: 0.55;
  transition: opacity 120ms, transform 60ms;
  padding: 0.2rem;
}
.notif-item .speak:hover { opacity: 1; transform: scale(1.1); }
.notif-item.level-success .title::before { content: "✓ "; color: var(--accent); }
.notif-item.level-warn .title::before { content: "⚠ "; color: var(--warn); }
.notif-item.level-error .title::before { content: "✕ "; color: var(--error); }
.notif-empty {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ================= Página login ================= */

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  width: 100%;
  padding: var(--sp-4);
  background:
    radial-gradient(900px 500px at 25% 10%, var(--glow-login-1), transparent 60%),
    radial-gradient(800px 400px at 105% 105%, var(--glow-login-2), transparent 60%),
    var(--bg);
}
/* Botón de tema flotante: la pantalla de login no tiene topbar donde colgarlo. */
.login-theme-toggle {
  position: fixed;
  top: var(--sp-4);
  right: var(--sp-4);
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text-2);
  cursor: pointer;
  font-size: 1rem;
  transition: border-color 120ms, transform 120ms;
}
.login-theme-toggle:hover { border-color: var(--border-hi); transform: translateY(-1px); }
.login-card {
  width: min(420px, calc(100vw - 2rem));
  background: var(--login-card-bg);
  backdrop-filter: blur(24px);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-xl);
  padding: 2.4rem;
  box-shadow: var(--shadow);
}
.login-card .brand-big {
  display: flex; align-items: center; gap: 0.85rem;
  margin-bottom: 1.8rem;
}
.login-card .brand-big .logo {
  width: 46px; height: 46px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  display: grid; place-items: center;
  font-weight: 700; font-size: 1.15rem; color: var(--on-accent);
  box-shadow: 0 8px 24px var(--accent-glow);
}
.login-card .brand-big .title {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.015em;
}
.login-card .brand-big .sub {
  font-size: 0.8rem;
  color: var(--muted);
}
.login-card .login-error {
  background: var(--error-soft);
  border: 1px solid var(--error);
  color: var(--error-text);
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  margin-bottom: 0.95rem;
  font-size: var(--fs-sm);
}

/* Campo de contraseña con botón mostrar/ocultar */
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 2.5rem; }
.input-wrap .peek {
  position: absolute;
  right: 0.5rem; top: 50%;
  transform: translateY(-50%);
  background: none; border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
  border-radius: 6px;
}
.input-wrap .peek:hover { color: var(--text-2); }

/* Código de 6 dígitos del segundo factor */
.otp-input {
  text-align: center;
  font-family: var(--mono);
  font-size: 1.5rem;
  letter-spacing: 0.4em;
  text-indent: 0.4em;   /* compensa el tracking para que se vea centrado */
  padding: 0.7rem;
}
.otp-input::placeholder { letter-spacing: 0.4em; opacity: 0.35; }
.link-btn {
  background: none; border: none; padding: 0;
  color: var(--muted);
  font-size: var(--fs-xs);
  text-decoration: underline;
  cursor: pointer;
}
.link-btn:hover { color: var(--text-2); }

/* ================= Chat ================= */

main#messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.95rem 1.2rem;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--panel);
  word-wrap: break-word;
  box-shadow: var(--shadow-sm);
  transition: border-color 120ms;
}
.msg:hover { border-color: var(--border-hi); }
.msg.user .content,
.msg.error .content,
.msg.system .content { white-space: pre-wrap; }
.msg.assistant .content { white-space: normal; }
.msg .role {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}
.msg.user {
  background: linear-gradient(135deg, rgba(91, 141, 239, 0.18), rgba(91, 141, 239, 0.10));
  border-color: rgba(91, 141, 239, 0.3);
  align-self: flex-end;
  max-width: 78%;
  border-bottom-right-radius: 6px;
}
.msg.user .role { color: var(--user-text); }
.msg.assistant {
  background: var(--panel);
  align-self: flex-start;
  max-width: 90%;
  border-bottom-left-radius: 6px;
}
.msg.error { background: var(--error-soft); border-color: var(--error); color: var(--error-text); }
.msg.system {
  background: transparent;
  border-color: var(--border);
  border-style: dashed;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.82rem;
  align-self: center;
  max-width: 90%;
}
.msg.system .role { color: var(--accent); }
.msg .content { line-height: 1.6; font-size: 0.95rem; }
.msg .gen-image {
  margin-top: 0.7rem;
  max-width: 100%;
  max-height: 60vh;
  border-radius: 14px;
  border: 1px solid var(--border);
  display: block;
}

form#composer {
  padding: 1rem 1.5rem 1.4rem;
  background: linear-gradient(180deg, transparent, var(--bg) 40%);
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
}
#composerCol { display: flex; flex-direction: column; gap: 0.55rem; }
.composer-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 0.5rem 0.5rem 0.5rem 0.65rem;
  transition: border-color 120ms, box-shadow 120ms;
}
.composer-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea#input {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 240px;
  background: transparent;
  border: none;
  outline: none;
  padding: 0.55rem 0.35rem;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--text);
}
textarea#input::placeholder { color: var(--muted-2); }

#attachBtn, #micBtn {
  background: transparent;
  border: none;
  font-size: 1.15rem;
  width: 38px; height: 38px;
  border-radius: 10px;
  cursor: pointer;
  display: grid; place-items: center;
  color: var(--muted);
  transition: background 120ms, color 120ms;
}
#attachBtn:hover, #micBtn:hover { background: var(--panel-2); color: var(--text); }

#send {
  border-radius: 12px;
  background: var(--accent);
  border: none;
  color: var(--on-accent);
  font-weight: 600;
  padding: 0 1.1rem;
  height: 38px;
  cursor: pointer;
  transition: background 120ms, transform 60ms, box-shadow 120ms;
  box-shadow: 0 4px 14px var(--accent-glow);
}
#send:hover { background: var(--accent-hov); box-shadow: 0 6px 18px var(--accent-glow); }
#send:active { transform: scale(0.97); }
#send:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
#send.stop { background: var(--error); color: white; box-shadow: 0 4px 14px rgba(248, 113, 113, 0.3); }
#send.stop:hover { background: var(--error-strong); }

.attachments {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  padding: 0.6rem;
  border: 1px dashed var(--border);
  border-radius: 14px;
  background: var(--panel);
}
.attachment {
  position: relative;
  width: 70px; height: 70px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.attachment img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attachment .remove {
  position: absolute;
  top: 3px; right: 3px;
  background: rgba(0,0,0,0.75);
  color: var(--on-solid);
  width: 22px; height: 22px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-size: 0.85rem; line-height: 1;
  padding: 0;
}
form#composer.dragover { background: var(--accent-soft); }

/* Markdown */
.msg .content > *:first-child { margin-top: 0; }
.msg .content > *:last-child { margin-bottom: 0; }
.msg .content p { margin: 0.55rem 0; }
.msg .content ul, .msg .content ol { margin: 0.55rem 0; padding-left: 1.5rem; }
.msg .content code {
  background: rgba(255,255,255,0.08);
  padding: 0.1rem 0.4rem;
  border-radius: 5px;
  font-family: var(--mono);
  font-size: 0.88em;
}
.msg .content pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.95rem 1.05rem;
  overflow-x: auto;
  margin: 0.7rem 0;
}
.msg .content pre code { background: transparent; padding: 0; font-size: 0.85em; }
.msg .content a { color: var(--accent); border-bottom: 1px dashed var(--accent); }
.msg .content a:hover { border-bottom-style: solid; }
.msg .content blockquote {
  border-left: 3px solid var(--accent);
  margin: 0.7rem 0;
  padding-left: 0.9rem;
  color: var(--muted);
  background: var(--accent-soft);
  padding: 0.6rem 0.9rem;
  border-radius: 0 8px 8px 0;
}
.msg .content table { border-collapse: collapse; margin: 0.7rem 0; }
.msg .content th, .msg .content td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.7rem;
}
.msg .content h1, .msg .content h2, .msg .content h3 {
  margin: 0.7rem 0 0.35rem;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.msg .attached-images {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  margin-bottom: 0.45rem;
}
.msg .attached-images img {
  max-width: 240px;
  max-height: 240px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

/* Status pill */
.status {
  font-size: 0.74rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-weight: 500;
}
.status--ok { color: var(--accent); border-color: rgba(52, 211, 153, 0.4); background: var(--accent-soft); }
.status--bad { color: var(--error); border-color: rgba(248, 113, 113, 0.4); background: var(--error-soft); }
.status--unknown { color: var(--muted); }

/* ================= Admin grids/cards ================= */

.admin-grid {
  display: grid;
  gap: 1.2rem;
  padding: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.metric {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.35rem;
  transition: border-color 120ms;
}
.metric:hover { border-color: var(--border-hi); }
.metric .label {
  color: var(--muted);
  font-size: 0.76rem;
  margin-bottom: 0.4rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.metric .value { font-size: 1.85rem; font-weight: 600; line-height: 1.15; letter-spacing: -0.02em; }
.metric .sub { color: var(--muted); font-size: 0.82rem; margin-top: 0.4rem; }

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: auto;
  max-height: 65vh;
  margin: 0 1.5rem 1.5rem;
}

/* ================= Conexiones (cards de integraciones) ================= */

/* Lista de conversaciones del agente */
.conv-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.84rem;
  color: var(--text-2);
  transition: background 120ms;
  position: relative;
}
.conv-item:hover { background: var(--panel-2); color: var(--text); }
.conv-item.active { background: var(--accent-soft); color: var(--accent); }
.conv-item .title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item .del {
  opacity: 0;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  transition: opacity 120ms, color 120ms;
}
.conv-item:hover .del { opacity: 1; }
.conv-item .del:hover { color: var(--error); background: var(--error-soft); }

/* Regenerate button en messages */
.msg .msg-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.55rem;
  opacity: 0;
  transition: opacity 120ms;
}
.msg:hover .msg-actions { opacity: 1; }
.msg .msg-actions button {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2rem 0.55rem;
  font-size: 0.74rem;
  color: var(--muted);
  cursor: pointer;
  transition: all 120ms;
}
.msg .msg-actions button:hover { color: var(--text); border-color: var(--border-hi); }

.conn-grid {
  display: grid;
  gap: 1.1rem;
  padding: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}
.conn-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.4rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  transition: border-color 120ms, transform 120ms;
}
.conn-card:hover { border-color: var(--border-hi); }
.conn-card .conn-head {
  display: flex;
  align-items: center;
  gap: 0.95rem;
}
.conn-card .conn-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: var(--panel-3);
  display: grid; place-items: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.conn-card .conn-title { font-size: 1rem; font-weight: 600; letter-spacing: -0.01em; }
.conn-card .conn-desc { color: var(--muted); font-size: 0.84rem; line-height: 1.5; }
.conn-card .conn-status-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.conn-card .conn-meta { font-size: 0.78rem; color: var(--muted-2); }
.conn-card .conn-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ================= Responsive ================= */

.hamburger {
  display: none;
  background: var(--panel-2);
  border: 1px solid var(--border);
  width: 38px; height: 38px;
  border-radius: 10px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--text);
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 280px;
    height: 100vh;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 200ms cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 0 40px rgba(0,0,0,0.6);
  }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: inline-flex; }
  .sidebar-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 150;
    display: none;
  }
  .sidebar-overlay.open { display: block; }
  .topbar { padding: 0 1rem; gap: 0.5rem; }
  .topbar h1 { font-size: 0.95rem; }
  main#messages { padding: 1rem 0.75rem; }
  form#composer { padding: 0.7rem 0.85rem 1rem; }
  .msg.user, .msg.assistant { max-width: 92%; }
  .conn-grid, .admin-grid { padding: 0.75rem; grid-template-columns: 1fr; }
  .table-wrap { margin: 0 0.75rem 0.75rem; max-height: 50vh; }
  .tabs { padding: 0 0.5rem; }
  .tab { padding: 0.6rem 0.7rem; font-size: 0.82rem; }
  .notif-panel { width: calc(100vw - 1rem); right: -0.5rem; }
}

/* Custom scrollbar (Webkit) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--panel-3);
  border-radius: 999px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--border-hi); }
