/* ============================================================
   WobykAgent — Panel de administración
   Sistema de diseño compartido por las 5 páginas (login incluido).
   Paleta clara original (gris/blanco + acento azul); tipografía
   monoespaciada para navegación/datos + grotesk para texto de UI.
   ============================================================ */

:root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --panel-alt: #f7f8fa;
    --panel-hover: #eef0f3;
    --border: #e2e4e9;
    --border-strong: #cfd3da;

    --text: #1c1e21;
    --text-dim: #6b7280;
    --text-faint: #8b93a1;

    --accent: #2563eb;
    --accent-strong: #1d4ed8;
    --accent-ink: #ffffff;
    --accent-dim: rgba(37, 99, 235, 0.1);
    --accent-border: rgba(37, 99, 235, 0.3);

    --ok: #166534;
    --ok-bg: #dcfce7;
    --ok-border: rgba(22, 101, 52, 0.25);

    --error: #dc2626;
    --error-bg: #fee2e2;
    --error-border: rgba(220, 38, 38, 0.25);

    --font-ui: 'Hanken Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

    --radius: 8px;
    --radius-sm: 5px;
    --shadow-panel: 0 1px 2px rgba(16, 24, 40, 0.04), 0 6px 16px rgba(16, 24, 40, 0.05);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font-ui);
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent); color: var(--accent-ink); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
::-webkit-scrollbar-corner { background: transparent; }

a { color: inherit; }

/* ── Estructura general: menú lateral + contenido ────────────────────
   .app-shell envuelve todo (sustituye al body en flujo normal): sidebar
   fija a la izquierda + columna de contenido a la derecha, cada una con
   su propio scroll. En chat.html la columna de contenido lleva además el
   <header> propio del chat y #messages/#composer en vez de <main>. ── */

@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

.app-shell { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 22px 0;
    overflow-y: auto;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-mono);
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text);
    padding: 0 22px 22px;
    white-space: nowrap;
}
.sidebar-brand .pulse-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--ok);
    box-shadow: 0 0 0 3px var(--ok-bg), 0 0 8px var(--ok);
    animation: pulse-dot 2.4s ease-in-out infinite;
    flex-shrink: 0;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 12px; }
.sidebar-nav a {
    font-family: var(--font-mono);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--text-dim);
    text-decoration: none;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    transition: color .15s ease, background .15s ease;
}
.sidebar-nav a:hover { color: var(--text); background: var(--panel-hover); }
.sidebar-nav a.active { color: var(--accent-ink); background: var(--accent); font-weight: 700; }

.app-content { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100vh; overflow: hidden; }

.topbar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 12px 22px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    position: relative;
}

/* ── Menú de usuario: avatar + desplegable (cuenta / cerrar sesión) ── */

.user-menu { position: relative; }
.avatar-btn {
    width: 34px; height: 34px;
    border-radius: 50%;
    border: 1px solid var(--border-strong);
    background: var(--accent);
    color: var(--accent-ink);
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: box-shadow .15s ease;
}
.avatar-btn:hover { box-shadow: 0 0 0 3px var(--accent-dim); }
.user-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 230px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-panel);
    padding: 12px 0;
    z-index: 200;
    animation: rise-in .15s ease both;
}
.user-dropdown[hidden] { display: none; }
.user-dropdown-label {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--text-faint);
    padding: 0 16px 4px;
}
.user-dropdown-email { font-size: 13px; color: var(--text); padding: 0 16px 10px; word-break: break-all; }
.user-dropdown-sep { height: 1px; background: var(--border); margin: 4px 0; }
.user-dropdown-item {
    display: block;
    width: 100%;
    text-align: left;
    text-decoration: none;
    background: none;
    border: none;
    padding: 10px 16px;
    font-family: var(--font-ui);
    font-size: 13px;
    color: var(--error);
    cursor: pointer;
    transition: background .15s ease;
}
.user-dropdown-item:hover { background: var(--error-bg); }
.user-dropdown-item.neutral { color: var(--text); }
.user-dropdown-item.neutral:hover { background: var(--panel-hover); }

/* ── Contenido principal ───────────────────────────────────────────── */
/* #view: contenedor fijo del shell (shell.html) donde el router (router.js)
   monta cada fragmento (views/*.html) sin recargar sidebar/topbar. Columna
   flex para que le sirva tanto a un <main> simple (dashboard/requests/config)
   como al layout de tres franjas del chat (toolbar + mensajes + composer). */
#view { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }

main {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    margin: 0 auto;
    width: 100%;
    animation: rise-in .5s ease both;
}

@keyframes rise-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.muted { color: var(--text-dim); }

/* ── Paneles / cards ───────────────────────────────────────────────── */

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-panel);
}

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 12px; margin-bottom: 30px; }
.cards .card { padding: 16px 18px; animation: rise-in .45s ease both; }
.cards .card:nth-child(1) { animation-delay: .02s; }
.cards .card:nth-child(2) { animation-delay: .06s; }
.cards .card:nth-child(3) { animation-delay: .10s; }
.cards .card:nth-child(4) { animation-delay: .14s; }
.cards .card:nth-child(5) { animation-delay: .18s; }
.cards .card:nth-child(6) { animation-delay: .22s; }
.cards .card:nth-child(7) { animation-delay: .26s; }
.cards .card:nth-child(8) { animation-delay: .30s; }
.card .label { font-family: var(--font-mono); font-size: 10px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); margin-bottom: 8px; }
.card .value { font-family: var(--font-mono); font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); }

h2 { font-family: var(--font-mono); font-size: 12.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-dim); margin: 0 0 14px; }

/* ── Tablas ────────────────────────────────────────────────────────── */

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 10px 14px; font-size: 13px; border-bottom: 1px solid var(--border); }
th { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--text-faint); background: var(--panel-alt); font-weight: 600; }
tr:last-child td { border-bottom: none; }

/* ── Badges de estado ──────────────────────────────────────────────── */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px 3px 7px;
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .03em;
    text-transform: uppercase;
    border: 1px solid transparent;
    white-space: nowrap;
}
.badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-border); }
.badge.ok::before { background: var(--ok); }
.badge.error, .badge.auth_failed, .badge.rate_limited { background: var(--error-bg); color: var(--error); border-color: var(--error-border); }
.badge.error::before, .badge.auth_failed::before, .badge.rate_limited::before { background: var(--error); }

.badge-override {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid var(--accent-border);
    margin-left: 6px;
}

/* Aviso persistente cuando el token de API del agente está ausente o el
   backend lo rechaza — nada se procesa mientras tanto (ver agent.ts), así
   que esto debe ser imposible de ignorar en cualquier página del panel. */
.agent-token-banner[hidden] { display: none; }
.agent-token-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    background: var(--error-bg);
    color: var(--error);
    border-bottom: 1px solid var(--error-border);
    font-size: 13px;
}
.agent-token-banner strong { font-weight: 700; }
.agent-token-banner button {
    margin-left: auto;
    flex-shrink: 0;
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--error-border);
    background: transparent;
    color: var(--error);
    font-size: 12px;
    cursor: pointer;
}
.agent-token-banner button:hover { background: rgba(220, 38, 38, 0.08); }

/* ── Inputs / selects (base; las páginas afinan tamaños concretos) ──── */

input, select, textarea {
    font-family: var(--font-ui);
    background: var(--bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 8px 10px;
    font-size: 13px;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}
input:disabled, select:disabled, textarea:disabled { opacity: .55; cursor: not-allowed; }

button { font-family: var(--font-ui); }
