/* ═══════════════════════════════════════════════════════════════════
   Hub Meta — Sistema de diseño (basado en Orkesta / nacaIA)
   Tema oscuro para la app autenticada · tema claro para páginas anónimas
   ═══════════════════════════════════════════════════════════════════ */

:root {
    /* Fondos (oscuro) */
    --bg-main: #0f1419;
    --bg-sidebar: #1a1f2e;
    --bg-card: #1e2433;
    --bg-card-hover: #252c3f;
    --bg-input: #161b27;
    --bg-elevated: #232a3d;
    /* Bordes */
    --border-light: #2a3142;
    --border-strong: #3a4256;
    /* Texto */
    --text-primary: #e6e8ec;
    --text-secondary: #9ca3b5;
    --text-muted: #6b7280;
    /* Acentos */
    --orange: #d99a3d;
    --orange-hover: #e8a94a;
    --orange-soft: rgba(217, 154, 61, 0.15);
    --green: #10b981;
    --green-soft: rgba(16, 185, 129, 0.15);
    --blue: #4a90d9;
    --purple: #7b68ee;
    --danger: #e05260;
    /* Layout */
    --sidebar-w: 260px;
    /* Escala de espaciado 4/8 (unica fuente de verdad para paddings y gaps) */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 24px;
    --sp-6: 32px;
    --sp-7: 48px;
    /* Tamanos de icono */
    --ico-sm: 16px;
    --ico-md: 18px;
    --ico-lg: 22px;
    /* Sombras / radios */
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 4px 12px rgba(0,0,0,.35);
    --shadow-lg: 0 10px 30px rgba(0,0,0,.4);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
}

* { box-sizing: border-box; }

body {
    font-family: 'Barlow', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    margin: 0;
    -webkit-font-smoothing: antialiased;
    background-color: var(--bg-main);
    color: var(--text-primary);
}

a { text-decoration: none; }

/* ── Botones ───────────────────────────────────────────────────── */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 500;
    padding: 9px 18px;
    font-size: .9rem;
    transition: all .15s ease;
    border: 1px solid transparent;
    cursor: pointer;
}
.btn-primary, .btn-orange {
    background: linear-gradient(135deg, var(--orange), #c48a2f);
    border: none;
    color: #fff;
}
.btn-primary:hover, .btn-orange:hover {
    background: linear-gradient(135deg, var(--orange-hover), var(--orange));
    color: #fff;
    transform: translateY(-1px);
}
.btn-ghost {
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
}
.btn-ghost:hover { background: var(--bg-elevated); color: var(--text-primary); }
.btn-danger-soft {
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
}
.btn-danger-soft:hover { background: rgba(224,82,96,.12); color: var(--danger); }
.btn:focus { box-shadow: 0 0 0 3px var(--orange-soft); }
.btn-sm-hub { padding: 6px var(--sp-3); font-size: .85rem; }
.btn .ico-svg { width: var(--ico-sm); height: var(--ico-sm); vertical-align: -3px; margin-right: 2px; }

/* ── Badges ────────────────────────────────────────────────────── */
.hub-badge {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: .72rem; font-weight: 600;
    padding: 3px 9px; border-radius: 999px;
    background: var(--bg-elevated); color: var(--text-secondary);
    border: 1px solid var(--border-light);
}
.hub-badge.is-green { background: var(--green-soft); color: var(--green); border-color: transparent; }
.hub-badge.is-orange { background: var(--orange-soft); color: var(--orange); border-color: transparent; }
.hub-badge.is-blue { background: rgba(74,144,217,.15); color: var(--blue); border-color: transparent; }
.hub-badge.is-purple { background: rgba(123,104,238,.15); color: var(--purple); border-color: transparent; }
.hub-badge.is-muted { background: var(--bg-elevated); color: var(--text-muted); }

/* ── Inputs ────────────────────────────────────────────────────── */
.form-control, .form-select, textarea.form-control {
    background-color: var(--bg-input);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: .9rem;
}
.form-control::placeholder { color: var(--text-muted); }
.form-control:focus, .form-select:focus {
    background-color: var(--bg-input);
    border-color: var(--orange);
    color: var(--text-primary);
    box-shadow: 0 0 0 3px var(--orange-soft);
}
.form-label { font-size: .8rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }

/* ── Tarjetas ──────────────────────────────────────────────────────
   Estructura: .hub-card > __head / __body / __foot
   El cuerpo crece y el pie se ancla abajo, de modo que todas las
   tarjetas de una misma fila comparten altura y alinean sus acciones. */
.hub-card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
}
.hub-card__head {
    padding: var(--sp-5) var(--sp-5) var(--sp-3);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-3);
}
.hub-card__head h2,
.hub-card__head h3 { margin: 0; font-size: 1.05rem; font-weight: 700; color: var(--text-primary); }
.hub-card__head .sub { margin: var(--sp-1) 0 0; font-size: .85rem; color: var(--text-muted); }
.hub-card__body {
    padding: 0 var(--sp-5) var(--sp-5);
    flex: 1 1 auto;
    min-height: 0;
}
.hub-card__body.is-scroll { max-height: 320px; overflow-y: auto; }
.hub-card__foot {
    padding: var(--sp-3) var(--sp-5) var(--sp-5);
    margin-top: auto;
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--sp-2);
}
.hub-card.accent-top { border-top: 3px solid transparent; border-image: linear-gradient(135deg, var(--blue), var(--green)) 1; }

/* ── Rejillas simetricas ───────────────────────────────────────── */
.hub-grid {
    display: grid;
    gap: var(--sp-5);
    align-items: stretch;
    margin-bottom: var(--sp-5);
}
.hub-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.hub-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.hub-grid.cols-auto { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.hub-grid.split { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
/* Rejilla que ocupa el alto restante de la pantalla (patron de app: bandeja,
   paneles de trabajo). Las tarjetas llegan hasta abajo y el scroll va dentro. */
.hub-grid.fill {
    flex: 1 1 auto;
    min-height: 0;
    margin-bottom: 0;
}
.hub-grid.fill > .hub-card { min-height: 0; }
.hub-grid.fill .hub-card__body { overflow-y: auto; }
.hub-grid.fill .hub-card__body.is-scroll { max-height: none; }
@media (max-width: 991px) {
    .hub-grid.cols-2,
    .hub-grid.cols-3,
    .hub-grid.split { grid-template-columns: minmax(0, 1fr); }
}

/* ── Estado vacio homogeneo ────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: var(--sp-2);
    padding: var(--sp-6) var(--sp-4);
    color: var(--text-secondary);
    min-height: 160px;
}
.empty-state__ico {
    width: 44px; height: 44px;
    border-radius: 12px;
    background: var(--bg-elevated);
    color: var(--text-muted);
    display: flex; align-items: center; justify-content: center;
    margin-bottom: var(--sp-1);
}
.empty-state__title { font-weight: 600; color: var(--text-primary); }
.empty-state p { margin: 0; font-size: .9rem; max-width: 42ch; }

/* ── Foco visible (nunca eliminar el anillo) ───────────────────── */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.nav-item:focus-visible,
/* Con clase, para ganar a las reglas de Bootstrap que anulan el outline */
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.btn-close:focus-visible {
    outline: 2px solid var(--orange);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ── Datos tabulares y tablas del hub ──────────────────────────── */
.table, .hub-table { font-variant-numeric: tabular-nums; }
.hub-table { color: var(--text-primary); --bs-table-bg: transparent; --bs-table-color: var(--text-primary); }
.hub-table thead th {
    color: var(--text-secondary);
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom-color: var(--border-light);
}
.hub-table td { border-bottom-color: var(--border-light); vertical-align: middle; }
.hub-table tbody tr:last-child td { border-bottom: none; }
.nowrap { white-space: nowrap; }
.muted { color: var(--text-muted); }

/* Un formulario que actua como envoltorio transparente dentro de la tarjeta,
   para que __body y __foot sigan siendo hijos flex de .hub-card */
.d-contents { display: contents; }

/* ── Encabezado de seccion, avisos y acciones de formulario ────── */
.section-eyebrow {
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--orange);
    margin: 0 0 var(--sp-3);
}
.hub-notice {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-left: 3px solid var(--orange);
    border-radius: var(--radius-md);
    padding: var(--sp-4);
    margin-bottom: var(--sp-5);
    color: var(--text-secondary);
}
.hub-notice strong { color: var(--orange); }
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--sp-2);
    padding-top: var(--sp-2);
    padding-bottom: var(--sp-6);
}

/* ── Metrica destacada (fichas de plataforma) ──────────────────── */
.metric-num {
    font-size: 2.4rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

/* ── Bandeja: lista de conversaciones ──────────────────────────── */
.conv-list { display: flex; flex-direction: column; }
.conv-item {
    display: block;
    padding: var(--sp-3);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    color: var(--text-primary);
    margin-bottom: var(--sp-2);
    transition: background .15s ease, border-color .15s ease;
}
.conv-item:hover { background: var(--bg-elevated); color: var(--text-primary); }
.conv-item.is-active { background: var(--orange-soft); border-color: var(--orange); }
.conv-item.is-nuevo { border-color: var(--green); }
.conv-item__top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.conv-item__name { font-weight: 600; }
.conv-item__meta {
    display: flex; align-items: center; gap: var(--sp-2);
    margin-top: var(--sp-1); font-size: .78rem; color: var(--text-muted);
}
.conv-item__extract { font-size: .85rem; color: var(--text-secondary); margin-top: var(--sp-1); }
.conv-item__date { font-size: .72rem; color: var(--text-muted); margin-top: var(--sp-1); }
.conv-head-ico { color: var(--text-muted); }

/* ── Bandeja: burbujas del hilo ────────────────────────────────── */
.msg { display: flex; margin-bottom: var(--sp-3); }
.msg-in { justify-content: flex-start; }
.msg-out { justify-content: flex-end; }
.msg__burbuja {
    max-width: 78%;
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius-lg);
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
}
.msg-out .msg__burbuja {
    background: var(--orange-soft);
    border-color: transparent;
}
.msg__texto { white-space: pre-wrap; word-break: break-word; }
.msg__pie {
    display: flex; align-items: center; gap: var(--sp-2);
    margin-top: var(--sp-1); font-size: .72rem; color: var(--text-muted);
}
#hiloConversacion .hub-card__foot { gap: var(--sp-3); align-items: flex-start; }

/* ── Fila de activo (paginas / cuentas conectadas) ─────────────── */
.asset-row {
    padding: var(--sp-3) 0;
    border-bottom: 1px solid var(--border-light);
}
.asset-row:last-child { border-bottom: none; }
.asset-row__name { font-weight: 600; color: var(--text-primary); }
.asset-row__meta {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    margin-top: var(--sp-1);
    font-size: .82rem;
    color: var(--text-muted);
}

/* ── Iconos en linea ───────────────────────────────────────────── */
.ico-svg { width: var(--ico-md); height: var(--ico-md); flex: none; display: inline-block; vertical-align: -3px; }

/* ── Marca ─────────────────────────────────────────────────────── */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.2rem; color: var(--text-primary); }
.brand-mark {
    width: 34px; height: 34px; border-radius: 9px; flex: none;
    background: linear-gradient(135deg, var(--orange), #c48a2f);
    display: inline-flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 800; box-shadow: var(--shadow-sm);
}
.brand small { display: block; font-size: .6rem; letter-spacing: .12em; color: var(--text-muted); font-weight: 600; }

/* ═══════════════════════════════════════════════════════════════
   APP SHELL (autenticado, oscuro, con sidebar)
   ═══════════════════════════════════════════════════════════════ */
.app-shell { display: flex; min-height: 100vh; }
.app-sidebar {
    position: fixed; top: 0; left: 0; width: var(--sidebar-w); height: 100vh;
    background: var(--bg-sidebar); border-right: 1px solid var(--border-light);
    display: flex; flex-direction: column; z-index: 1050;
}
.sidebar-brand { padding: 20px 20px 14px; border-bottom: 1px solid var(--border-light); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.nav-section { font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--text-muted); margin: 16px 10px 8px; font-weight: 700; }
.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    color: var(--text-secondary); font-weight: 500; font-size: .92rem;
    border-left: 3px solid transparent; margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-item.active { background: var(--orange-soft); color: var(--orange); border-left-color: var(--orange); }
.nav-item.disabled { opacity: .5; pointer-events: none; }
.nav-item .ico { width: var(--ico-md); height: var(--ico-md); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.nav-item .ico .ico-svg { width: var(--ico-md); height: var(--ico-md); vertical-align: 0; }
.feature-card .fico .ico-svg { width: var(--ico-lg); height: var(--ico-lg); vertical-align: 0; }
.empty-state__ico .ico-svg { width: var(--ico-lg); height: var(--ico-lg); vertical-align: 0; }
.sidebar-user { padding: 12px; border-top: 1px solid var(--border-light); display: flex; align-items: center; gap: 10px; }
.sidebar-user .avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, var(--orange), #c48a2f); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.sidebar-user .who { min-width: 0; flex: 1; }
.sidebar-user .who strong { display: block; font-size: .85rem; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .who span { font-size: .72rem; color: var(--text-muted); }
/* El bloque de usuario es un enlace a "Mi cuenta": sin subrayado y con realce al pasar */
a.sidebar-user__who, .sidebar-user a.who { text-decoration: none; border-radius: var(--radius-sm); padding: 2px 4px; margin: -2px -4px; transition: background .15s ease; }
.sidebar-user a.who:hover { background: var(--bg-elevated); }
.sidebar-user a.who:hover strong { color: var(--orange); }

.app-main {
    flex: 1;
    margin-left: var(--sidebar-w);
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
/* En paginas de alto completo (bandeja) el aire inferior sigue el ritmo lateral */
.app-content.is-fill { padding-bottom: var(--sp-5); }
.app-content {
    padding: 28px 32px 60px;
    max-width: 1400px;
    width: 100%;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.page-head { margin-bottom: 22px; }
.breadcrumb-mini { font-size: .78rem; color: var(--text-muted); margin-bottom: 4px; }
.page-title { font-size: 1.7rem; font-weight: 700; margin: 0; color: #fff; }
.page-sub { color: var(--text-secondary); margin: 2px 0 0; }

.filter-bar { background: var(--bg-card); border: 1px solid var(--border-light); border-radius: var(--radius-md); padding: 16px; display: flex; gap: 14px; align-items: end; flex-wrap: wrap; margin-bottom: 22px; }
.filter-bar .fb-field { flex: 1; min-width: 180px; }

.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--sp-5); align-items: stretch; }

/* Sidebar responsive */
.sidebar-toggle { display: none; position: fixed; top: 12px; left: 12px; z-index: 1060; width: 42px; height: 42px; border-radius: var(--radius-sm); background: var(--bg-elevated); border: 1px solid var(--border-light); color: var(--text-primary); font-size: 1.2rem; cursor: pointer; }
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1040; opacity: 0; pointer-events: none; transition: opacity .25s ease; }
@media (max-width: 991px) {
    .app-sidebar { transform: translateX(-100%); transition: transform .25s ease; }
    .app-shell.sidebar-open .app-sidebar { transform: none; }
    .app-shell.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
    .app-main { margin-left: 0; }
    .app-content { padding: 64px 18px 48px; }
    .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
}

/* ═══════════════════════════════════════════════════════════════
   TEMA CLARO (páginas anónimas: login, conexión cliente)
   ═══════════════════════════════════════════════════════════════ */
body.theme-auth {
    --bg-main: #f3f4f8;
    --bg-card: #ffffff;
    --bg-input: #f4f5f9;
    --bg-elevated: #eef0f6;
    --border-light: #e5e7eb;
    --border-strong: #d1d5db;
    --text-primary: #1a1f2e;
    --text-secondary: #4b5563;
    --text-muted: #9099a8;
    color: var(--text-primary);
    background: var(--bg-main);
}
.auth-topbar { display: flex; align-items: center; justify-content: space-between; padding: 18px 28px; background: #fff; border-bottom: 1px solid var(--border-light); }
.auth-main { min-height: calc(100vh - 70px); display: flex; align-items: center; justify-content: center; padding: 32px 18px; }
.auth-card { width: 100%; max-width: 440px; background: #fff; border-radius: 22px; box-shadow: 0 10px 40px rgba(20,29,56,.10); padding: 40px 36px; }
body.theme-auth .form-control { box-shadow: none; }
body.theme-auth .form-control:focus { box-shadow: 0 0 0 3px var(--orange-soft); }

/* ═══════════════════════════════════════════════════════════════
   TEMA PÚBLICO (landing, hero oscuro)
   ═══════════════════════════════════════════════════════════════ */
body.theme-public { background: var(--bg-main); }
.landing-topbar { display: flex; align-items: center; justify-content: space-between; padding: 18px 32px; position: relative; z-index: 5; }
.landing-topbar .actions { display: flex; align-items: center; gap: 14px; }
.landing-topbar a.link { color: var(--text-secondary); font-weight: 500; }
.landing-topbar a.link:hover { color: var(--text-primary); }
.hero { position: relative; text-align: center; padding: 70px 20px 90px; background: radial-gradient(1200px 500px at 50% -10%, #2a2350 0%, transparent 60%), linear-gradient(180deg, #141232, #0f1419); overflow: hidden; }
.hero-badge { display: inline-flex; align-items: center; gap: 8px; font-size: .8rem; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border-strong); color: var(--text-secondary); margin-bottom: 26px; }
.hero-badge .pill { background: var(--orange); color: #fff; font-weight: 700; padding: 1px 8px; border-radius: 999px; font-size: .72rem; }
.hero h1 { font-size: clamp(2.2rem, 5vw, 3.4rem); font-weight: 800; line-height: 1.1; margin: 0 auto 22px; max-width: 900px; color: #fff; }
.hero h1 .accent { color: var(--orange); }
.hero p.lead { color: var(--text-secondary); max-width: 640px; margin: 0 auto 32px; font-size: 1.1rem; line-height: 1.6; }
.hero .cta-row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.section-label { text-align: center; color: var(--orange); font-weight: 700; letter-spacing: .12em; font-size: .78rem; text-transform: uppercase; margin-bottom: 12px; }
.section-label::before, .section-label::after { content: "—"; margin: 0 8px; color: var(--text-muted); }
.landing-section { padding: 70px 20px; max-width: 1100px; margin: 0 auto; }
.landing-section h2 { text-align: center; font-size: clamp(1.8rem, 4vw, 2.6rem); font-weight: 800; color: #fff; margin: 0 0 16px; }
.landing-section .lead { text-align: center; color: var(--text-secondary); max-width: 720px; margin: 0 auto 40px; line-height: 1.6; }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--sp-5); align-items: stretch; }
.feature-card { background: var(--bg-card); border: 1px solid var(--border-light); border-radius: var(--radius-lg); padding: var(--sp-5); display: flex; flex-direction: column; height: 100%; }
.feature-card .fico { width: 44px; height: 44px; border-radius: 12px; background: var(--orange-soft); color: var(--orange); display: flex; align-items: center; justify-content: center; font-size: 1.3rem; margin-bottom: 14px; }
.feature-card h3 { font-size: 1.1rem; color: #fff; margin: 0 0 8px; }
.feature-card p { color: var(--text-secondary); margin: 0; font-size: .95rem; line-height: 1.55; }
.landing-footer { text-align: center; padding: 30px; color: var(--text-muted); border-top: 1px solid var(--border-light); font-size: .85rem; }

/* Toast container (reutilizado por admin-panel.js) */
.toast-container { z-index: 1090; }
