/* ============================================================
   Empresa1 — Sistema de Gestión
   Design tokens: dual-theme (light/dark), Syne + DM Sans
   v2.0 — 2026-04
   ============================================================ */

/* ════════════════════════════════════ DESIGN TOKENS ══ */

/* Light (default) */
:root {
    --bg:          #f0f2f7;
    --bg2:         #e8eaf0;
    --card:        #ffffff;
    --card2:       #f5f6fa;
    --border:      #e2e5ee;
    --border2:     #d0d4e0;
    --surface-elev:#ffffff;

    --accent:      #5457e5;
    --accent-h:    #4345c0;
    --accent-soft: rgba(84,87,229,.1);
    --accent2:     #0ea572;
    --accent2-soft:rgba(14,165,114,.12);
    --accent3:     #f59e0b;
    --accent3-soft:rgba(245,158,11,.12);
    --danger:      #ef4444;
    --danger-soft: rgba(239,68,68,.1);

    --text:        #1a1d2e;
    --text2:       #4a5068;
    --text3:       #9299b0;

    --sidebar-w:   260px;
    --sidebar-w-c: 70px;
    --topbar-h:    62px;

    --radius:      10px;
    --radius-sm:   6px;
    --transition:  .2s cubic-bezier(.4,0,.2,1);
    --transition-theme: background-color .25s ease, color .25s ease, border-color .25s ease;

    --shadow:      0 4px 24px rgba(0,0,0,.08);
    --shadow-sm:   0 2px 8px rgba(0,0,0,.06);
    --shadow-lg:   0 12px 40px rgba(0,0,0,.12);

    --chart-grid:  #e2e5ee;
    --chart-tick:  #9299b0;
}

/* Dark */
[data-theme="dark"] {
    --bg:          #0d0f1a;
    --bg2:         #14172a;
    --card:        #181b2e;
    --card2:       #1e2238;
    --border:      #2a2f4a;
    --border2:     #363c5a;
    --surface-elev:#1e2238;

    --accent:      #6366f1;
    --accent-h:    #818cf8;
    --accent-soft: rgba(99,102,241,.18);
    --accent2:     #10b981;
    --accent2-soft:rgba(16,185,129,.18);
    --accent3:     #fbbf24;
    --accent3-soft:rgba(251,191,36,.15);
    --danger:      #f87171;
    --danger-soft: rgba(248,113,113,.15);

    --text:        #e8eaf5;
    --text2:       #a0a7c5;
    --text3:       #6b7194;

    --shadow:      0 4px 24px rgba(0,0,0,.35);
    --shadow-sm:   0 2px 8px rgba(0,0,0,.25);
    --shadow-lg:   0 12px 40px rgba(0,0,0,.5);

    --chart-grid:  #2a2f4a;
    --chart-tick:  #6b7194;
}

/* Auto-detect si el usuario no eligió tema manualmente */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --bg:#0d0f1a; --bg2:#14172a; --card:#181b2e; --card2:#1e2238;
        --border:#2a2f4a; --border2:#363c5a; --surface-elev:#1e2238;
        --accent:#6366f1; --accent-h:#818cf8; --accent-soft:rgba(99,102,241,.18);
        --accent2:#10b981; --accent2-soft:rgba(16,185,129,.18);
        --accent3:#fbbf24; --accent3-soft:rgba(251,191,36,.15);
        --danger:#f87171; --danger-soft:rgba(248,113,113,.15);
        --text:#e8eaf5; --text2:#a0a7c5; --text3:#6b7194;
        --shadow:0 4px 24px rgba(0,0,0,.35); --shadow-sm:0 2px 8px rgba(0,0,0,.25);
        --chart-grid:#2a2f4a; --chart-tick:#6b7194;
    }
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
    font-family: 'DM Sans', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
    transition: var(--transition-theme);
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ══════════════════════════════════════ SIDEBAR ══ */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width var(--transition), var(--transition-theme);
    z-index: 200;
    overflow: hidden;
    box-shadow: 2px 0 12px rgba(0,0,0,.06);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 14px;
    border-bottom: 1px solid var(--border);
    min-height: var(--topbar-h);
    flex-shrink: 0;
}
.brand-logo {
    width: 38px; height: 38px;
    background: linear-gradient(135deg, var(--accent), #818cf8);
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-family: 'Syne', sans-serif;
    font-weight: 800; font-size: 14px;
    flex-shrink: 0;
    color: #fff;
    letter-spacing: .5px;
}
.brand-text { flex: 1; overflow: hidden; min-width: 0; }
.brand-name {
    font-family: 'Syne', sans-serif;
    font-weight: 700; font-size: 16px;
    display: block; white-space: nowrap;
}
.brand-sub { font-size: 11px; color: var(--text3); display: block; }

.sidebar-toggle {
    background: var(--card2);
    border: 1px solid var(--border);
    color: var(--text2);
    width: 30px; height: 30px;
    border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
    cursor: pointer;
}
.sidebar-toggle:hover {
    background: var(--accent); color: #fff; border-color: var(--accent);
}

.sidebar-nav {
    flex: 1; overflow-y: auto; padding: 12px 10px;
    display: flex; flex-direction: column; gap: 2px;
}
.nav-label {
    font-size: 10px; letter-spacing: 1.5px; color: var(--text3);
    padding: 10px 8px 4px; font-weight: 600;
    white-space: nowrap; overflow: hidden;
    transition: opacity var(--transition);
}
.nav-divider { height: 1px; background: var(--border); margin: 8px 0; }

.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 10px;
    border-radius: var(--radius-sm);
    color: var(--text2);
    transition: all var(--transition);
    white-space: nowrap; overflow: hidden;
    position: relative;
}
.nav-item:hover { background: var(--bg2); color: var(--text); }
.nav-item.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 500;
}
.nav-item.active::before {
    content: '';
    position: absolute; left: 0; top: 20%; bottom: 20%;
    width: 3px; border-radius: 2px;
    background: var(--accent);
}
.nav-icon { font-size: 18px; flex-shrink: 0; width: 22px; text-align: center; }
.nav-text { font-size: 14px; overflow: hidden; }

.sidebar-footer {
    padding: 12px 10px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.user-card {
    display: flex; align-items: center; gap: 10px;
    padding: 8px; border-radius: var(--radius-sm);
    background: var(--bg2);
    overflow: hidden;
}
.user-avatar { font-size: 22px; flex-shrink: 0; }
.user-info { flex: 1; overflow: hidden; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--accent2); }
.logout-btn {
    background: none; border: none; color: var(--text3); font-size: 18px;
    padding: 4px; border-radius: 4px; flex-shrink: 0;
    transition: all var(--transition);
}
.logout-btn:hover { color: var(--danger); background: var(--danger-soft); }

.nav-section { margin-bottom: 2px; }
.nav-section-btn {
    width: 100%; display: flex; align-items: center; gap: 8px;
    padding: 7px 10px; border: none; background: none;
    color: var(--text3); cursor: pointer; border-radius: var(--radius-sm);
    font-size: 10px; font-weight: 700; letter-spacing: 1.2px;
    text-transform: uppercase; font-family: inherit;
    transition: all var(--transition);
    white-space: nowrap; overflow: hidden;
}
.nav-section-btn:hover { background: var(--bg2); color: var(--text2); }
.nav-section-icon { font-size: 14px; flex-shrink: 0; width: 22px; text-align: center; }
.nav-section-label { flex: 1; text-align: left; overflow: hidden; }
.nav-section-arrow { font-size: 10px; transition: transform .25s; flex-shrink: 0; }
.nav-section.collapsed .nav-section-arrow { transform: rotate(-90deg); }
.nav-section.collapsed .nav-section-items { display: none; }
.nav-section-items {
    border-left: 2px solid var(--border);
    margin-left: 18px;
    padding-left: 4px;
    margin-bottom: 4px;
}

body.sidebar-collapsed .nav-section-btn { justify-content: center; padding: 8px; }
body.sidebar-collapsed .nav-section-label,
body.sidebar-collapsed .nav-section-arrow { display: none; }
body.sidebar-collapsed .nav-section-items {
    border-left: none; margin-left: 0; padding-left: 0;
}
body.sidebar-collapsed .nav-section.collapsed .nav-section-items { display: block; }
body.sidebar-collapsed .sidebar { width: var(--sidebar-w-c); }

/* En modo colapsado: brand-area solo muestra el toggle centrado.
   El logo se oculta (el toggle es el único control visible y accesible). */
body.sidebar-collapsed .sidebar-brand {
    padding: 14px 0;
    justify-content: center;
}
body.sidebar-collapsed .brand-logo { display: none; }

body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .nav-text,
body.sidebar-collapsed .user-info,
body.sidebar-collapsed .logout-btn,
body.sidebar-collapsed .brand-sub,
body.sidebar-collapsed .nav-divider { opacity: 0; pointer-events: none; height: 0; padding: 0; margin: 0; overflow: hidden; }
body.sidebar-collapsed .sidebar-toggle { transform: rotate(180deg); }
body.sidebar-collapsed .main-wrapper { margin-left: var(--sidebar-w-c); }
body.sidebar-collapsed .nav-item { justify-content: center; padding: 10px; }
body.sidebar-collapsed .nav-item.active::before { display: none; }

/* ══════════════════════════════════════ MAIN WRAPPER ══ */
.main-wrapper {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex; flex-direction: column;
    min-height: 100vh;
    transition: margin-left var(--transition);
    min-width: 0; /* para que no fuerce overflow horizontal */
}

/* Topbar */
.topbar {
    position: sticky; top: 0;
    height: var(--topbar-h);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 24px;
    gap: 16px;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,.04);
    transition: var(--transition-theme);
}
.topbar-left { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.mobile-toggle { display: none; background: none; border: 1px solid var(--border); color: var(--text2); padding: 6px 10px; border-radius: var(--radius-sm); font-size: 16px; }

.page-title { min-width: 0; }
.page-title h1 { font-family: 'Syne', sans-serif; font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-subtitle { font-size: 12px; color: var(--text3); margin-left: 10px; }

.sync-status {
    display: flex; align-items: center; gap: 6px;
    font-size: 12px; color: var(--text2);
    background: var(--card2); border: 1px solid var(--border);
    padding: 5px 12px; border-radius: 20px;
    font-family: 'JetBrains Mono', monospace;
}
.sync-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--accent2);
    box-shadow: 0 0 6px var(--accent2);
    animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100% { opacity:1 } 50% { opacity:.4 } }

.topbar-user {
    display: flex; align-items: center; gap: 6px;
    font-size: 13px; color: var(--text2);
}

/* Theme toggle button */
.theme-toggle {
    background: var(--card2);
    border: 1px solid var(--border);
    color: var(--text2);
    width: 34px; height: 34px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
    font-size: 16px;
    flex-shrink: 0;
}
.theme-toggle:hover { background: var(--bg2); color: var(--text); border-color: var(--border2); }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) .theme-toggle .icon-sun { display: block; }
    :root:not([data-theme]) .theme-toggle .icon-moon { display: none; }
}

/* Content */
.content { flex: 1; padding: 24px; overflow-y: auto; min-width: 0; }

/* Overlay mobile */
.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.6); z-index: 150;
}

/* ══════════════════════════════════════ COMPONENTS ══ */

/* KPI Cards */
.kpi-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; margin-bottom: 24px; }
.kpi-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px; position: relative; overflow: hidden;
    transition: transform var(--transition), border-color var(--transition), var(--transition-theme);
}
.kpi-card:hover { transform: translateY(-2px); border-color: var(--border2); }
.kpi-card::after {
    content: ''; position: absolute;
    top: 0; left: 0; right: 0; height: 2px;
    background: var(--kpi-color, var(--accent));
}
.kpi-icon { font-size: 28px; margin-bottom: 10px; display: block; }
.kpi-label { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px; }
.kpi-value { font-family: 'JetBrains Mono', monospace; font-size: 24px; font-weight: 600; color: var(--kpi-color, var(--text)); }
.kpi-sub { font-size: 12px; color: var(--text3); margin-top: 4px; }

/* Cards */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    transition: var(--transition-theme);
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 18px;
    flex-wrap: wrap;
    gap: 8px;
}
.card-title { font-family: 'Syne', sans-serif; font-size: 14px; font-weight: 700; letter-spacing: .3px; }

/* Grid */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.col-span-2 { grid-column: span 2; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 600px; }
.data-table th {
    text-align: left; padding: 10px 14px;
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .8px; color: var(--text3);
    border-bottom: 1px solid var(--border);
    background: var(--card);
    position: sticky; top: 0; z-index: 1;
}
.data-table td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text2);
    vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--card2); color: var(--text); }

/* Badges */
.badge {
    display: inline-flex; align-items: center;
    padding: 3px 10px; border-radius: 20px;
    font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-green  { background: var(--accent2-soft); color: var(--accent2); }
.badge-blue   { background: var(--accent-soft);  color: var(--accent); }
.badge-yellow { background: var(--accent3-soft); color: var(--accent3); }
.badge-red    { background: var(--danger-soft);  color: var(--danger); }
.badge-gray   { background: var(--card2);        color: var(--text3); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 18px; border-radius: var(--radius-sm);
    font-size: 13.5px; font-weight: 500;
    border: none; transition: all var(--transition); cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-success { background: var(--accent2); color: #fff; }
.btn-success:hover { filter: brightness(1.1); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover  { filter: brightness(1.1); }
.btn-ghost   { background: var(--card2); color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg2); color: var(--text); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn:disabled { opacity:.5; cursor: not-allowed; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 6px; letter-spacing: .5px; }
.form-control {
    width: 100%; padding: 9px 12px;
    background: var(--card); border: 1px solid var(--border2);
    border-radius: var(--radius-sm); color: var(--text); font-size: 14px;
    transition: border-color var(--transition), var(--transition-theme);
    outline: none;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-control::placeholder { color: var(--text3); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; font-family: inherit; }

/* Toggle switch */
.toggle-wrap { display: flex; align-items: center; gap: 8px; }
.toggle { position: relative; width: 40px; height: 22px; display: inline-block; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; inset: 0;
    background: var(--border2); border-radius: 22px;
    cursor: pointer; transition: .3s;
}
.toggle-slider::before {
    content: ''; position: absolute;
    width: 16px; height: 16px; left: 3px; top: 3px;
    background: #fff; border-radius: 50%;
    transition: .3s;
}
.toggle input:checked + .toggle-slider { background: var(--accent2); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* Alerts */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 13.5px; }
.alert-success { background: var(--accent2-soft); border: 1px solid var(--accent2); color: var(--accent2); }
.alert-error   { background: var(--danger-soft);  border: 1px solid var(--danger);  color: var(--danger); }
.alert-info    { background: var(--accent-soft);  border: 1px solid var(--accent);  color: var(--accent); }
.alert-warning { background: var(--accent3-soft); border: 1px solid var(--accent3); color: var(--accent3); }

/* Bar charts (horizontal) */
.bar-item { margin-bottom: 12px; }
.bar-header { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 4px; }
.bar-header span:last-child { font-family: 'JetBrains Mono', monospace; color: var(--accent2); }
.bar-track { height: 6px; background: var(--card2); border-radius: 3px; overflow: hidden; }
.bar-fill  { height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--accent), var(--accent2)); }

/* Modal */
.modal-backdrop {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.7); z-index: 400;
    align-items: center; justify-content: center;
    padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: var(--card); border: 1px solid var(--border);
    border-radius: 14px; padding: 28px;
    width: 100%; max-width: 480px;
    box-shadow: var(--shadow-lg);
    animation: modalIn .2s ease;
    max-height: 90vh; overflow-y: auto;
}
@keyframes modalIn { from { transform: scale(.95); opacity:0 } to { transform: scale(1); opacity:1 } }
.modal-title { font-family: 'Syne', sans-serif; font-size: 18px; font-weight: 700; margin-bottom: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; flex-wrap: wrap; }

/* Search input */
.search-wrap { position: relative; }
.search-wrap input { padding-left: 34px; }
.search-wrap::before { content: '🔍'; position: absolute; left: 10px; top: 50%; transform: translateY(-50%); font-size: 13px; }

/* Pagination */
.pagination { display: flex; gap: 4px; margin-top: 16px; flex-wrap: wrap; }
.page-btn {
    padding: 6px 12px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: none;
    color: var(--text2); font-size: 13px; cursor: pointer;
    transition: all var(--transition);
}
.page-btn:hover { background: var(--card2); color: var(--text); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Empty state */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text3); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* Mono */
.mono { font-family: 'JetBrains Mono', monospace; }

/* Chips */
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 20px;
    font-size: 12px; font-weight: 500;
    background: var(--card2); color: var(--text2);
    border: 1px solid var(--border);
}
.chip.chip-accent { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* ══════════════════════════════════════ LOGIN PAGE ══ */
.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; width: 100%;
    background: var(--bg);
    position: relative; overflow: hidden;
}
.login-bg {
    position: absolute; inset: 0;
    background:
        radial-gradient(ellipse at 20% 50%, var(--accent-soft) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 20%, var(--accent2-soft) 0%, transparent 50%);
}
.login-card {
    position: relative; z-index: 1;
    background: var(--card); border: 1px solid var(--border);
    border-radius: 16px; padding: 40px 36px;
    width: 100%; max-width: 400px;
    box-shadow: var(--shadow);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .logo-box {
    width: 54px; height: 54px;
    background: linear-gradient(135deg, var(--accent), #818cf8);
    border-radius: 14px;
    display: inline-flex; align-items: center; justify-content: center;
    font-family: 'Syne', sans-serif; font-weight: 800; font-size: 20px;
    color: #fff; margin-bottom: 12px;
}
.login-logo h2 { font-family: 'Syne', sans-serif; font-size: 22px; font-weight: 800; }
.login-logo p  { font-size: 13px; color: var(--text3); margin-top: 4px; }
.login-footer  { text-align: center; margin-top: 20px; font-size: 12px; color: var(--text3); }

/* ══════════════════════════════════════ AI PANEL ══ */

/* Botón flotante */
.ai-fab {
    position: fixed;
    bottom: 24px; right: 24px;
    width: 56px; height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #818cf8);
    color: #fff;
    border: none; cursor: pointer;
    font-size: 24px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 8px 24px rgba(84,87,229,.4);
    transition: transform var(--transition), box-shadow var(--transition);
    z-index: 250;
}
/* Botón flotante — z-index mayor al drawer para que siempre sea clickeable */
.ai-fab {
    position: fixed;
    bottom: 24px; right: 24px;
    width: 56px; height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #818cf8);
    color: #fff;
    border: none; cursor: pointer;
    font-size: 24px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 8px 24px rgba(84,87,229,.4);
    transition: transform var(--transition), box-shadow var(--transition), right var(--transition);
    z-index: 270;  /* por encima del drawer (260) */
}
.ai-fab:hover { transform: scale(1.08); box-shadow: 0 12px 32px rgba(84,87,229,.55); }
.ai-fab.open {
    /* Cuando el drawer está abierto, el FAB se corre sobre el drawer para seguir siendo "cerrar" */
    transform: rotate(90deg);
    background: var(--danger);
}
.ai-fab.open:hover { transform: rotate(90deg) scale(1.08); }
.ai-fab-badge {
    position: absolute; top: -4px; right: -4px;
    width: 18px; height: 18px;
    background: var(--accent2);
    border: 2px solid var(--card);
    border-radius: 50%;
    font-size: 10px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}

/* Alpine x-cloak — oculta elementos hasta que Alpine inicializa.
   Sin esto, se ve un "flash" del drawer abierto antes de que init() corra. */
[x-cloak] { display: none !important; }

/* Drawer */
.ai-drawer {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: 420px; max-width: 100vw;
    background: var(--card);
    border-left: 1px solid var(--border);
    box-shadow: -8px 0 40px rgba(0,0,0,.15);
    z-index: 260;
    display: flex; flex-direction: column;
    transform: translateX(100%);
    transition: transform .3s cubic-bezier(.4,0,.2,1), var(--transition-theme);
}
.ai-drawer.open { transform: translateX(0); }

.ai-drawer-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.ai-drawer-title {
    display: flex; align-items: center; gap: 10px;
    font-family: 'Syne', sans-serif; font-weight: 700; font-size: 15px;
}
.ai-drawer-title .ai-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #818cf8);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 16px;
}
.ai-drawer-title .ai-provider-tag {
    font-size: 10px; color: var(--text3); font-family: 'JetBrains Mono',monospace;
    font-weight: 400; letter-spacing: .5px;
    display: block;
}
.ai-drawer-close {
    background: var(--card2);
    border: 1px solid var(--border);
    color: var(--text2);
    font-size: 18px; font-weight: 600;
    width: 36px; height: 36px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    transition: all var(--transition);
    cursor: pointer;
    flex-shrink: 0;
}
.ai-drawer-close:hover {
    background: var(--danger); color: #fff; border-color: var(--danger);
    transform: rotate(90deg);
}

/* Mensajes */
.ai-messages {
    flex: 1; overflow-y: auto;
    padding: 22px 18px 18px;
    display: flex; flex-direction: column; gap: 18px;
    scroll-behavior: smooth;
}
.ai-msg {
    display: flex; gap: 10px;
    max-width: 85%;          /* Antes 92% — más natural visualmente */
    width: fit-content;      /* Burbuja se adapta al texto */
}
.ai-msg-user { align-self: flex-end; flex-direction: row-reverse; }
.ai-msg-avatar {
    width: 30px; height: 30px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; font-size: 14px;
    margin-top: 2px;          /* Alinea con la primera línea del texto */
}
.ai-msg-user .ai-msg-avatar { background: var(--accent); color: #fff; }
.ai-msg-assistant .ai-msg-avatar { background: var(--card2); }
.ai-msg-bubble {
    padding: 11px 15px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    letter-spacing: 0.01em;
}
.ai-msg-user .ai-msg-bubble {
    background: var(--accent); color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 2px rgba(84,87,229,.18);
}
.ai-msg-assistant .ai-msg-bubble {
    background: var(--card2); color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}
.ai-msg-bubble strong { font-weight: 600; }
.ai-msg-bubble p { margin: 0 0 8px 0; }
.ai-msg-bubble p:last-child { margin-bottom: 0; }
.ai-msg-bubble ul, .ai-msg-bubble ol { margin: 6px 0 8px 0; padding-left: 22px; }
.ai-msg-bubble li { margin: 2px 0; }
.ai-msg-bubble code {
    background: rgba(0,0,0,.08);
    padding: 1px 6px; border-radius: 4px;
    font-family: 'JetBrains Mono',monospace; font-size: 12.5px;
}
[data-theme="dark"] .ai-msg-bubble code { background: rgba(255,255,255,.08); }

/* Streaming cursor */
.ai-cursor {
    display: inline-block; width: 6px; height: 14px;
    background: var(--accent); margin-left: 2px;
    vertical-align: middle;
    animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* Typing dots */
.ai-typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.ai-typing span {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--text3);
    animation: typingBounce 1.2s infinite ease-in-out;
}
.ai-typing span:nth-child(2) { animation-delay: .15s; }
.ai-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes typingBounce {
    0%,60%,100% { transform: translateY(0); opacity:.4 }
    30% { transform: translateY(-5px); opacity:1 }
}

/* ══════════════════════════════════════ ADMIN: SLOTS DE SUGERENCIAS ══ */
.suggestion-slot {
    position: relative;
    background: var(--card2);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    padding: 14px 12px 12px;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    min-height: 120px;
    font-family: inherit;
    text-align: left;
    overflow: hidden;
}
.suggestion-slot:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(84,87,229,.15);
}
.suggestion-slot .slot-num {
    position: absolute;
    top: 8px; right: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px; font-weight: 700;
    color: var(--text3);
    background: var(--card);
    border: 1px solid var(--border);
    width: 22px; height: 22px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}
.suggestion-slot.slot-empty {
    border-style: dashed;
    background: transparent;
    align-items: center;
    justify-content: center;
}
.suggestion-slot.slot-empty:hover {
    background: var(--accent-soft);
    border-style: solid;
}
.suggestion-slot.slot-filled:hover .slot-num {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.slot-label {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
    margin-top: 2px;
    padding-right: 22px;
    word-wrap: break-word;
}
.slot-preview {
    font-size: 11.5px;
    color: var(--text3);
    line-height: 1.4;
    margin-top: auto;
    padding-top: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Sugerencias — chips compactos (cuando ya hay conversación) */
.ai-suggestions {
    display: flex; flex-wrap: wrap; gap: 6px;
    padding: 10px 18px 0;
    flex-shrink: 0;
}
.ai-suggestion-chip {
    padding: 6px 12px;
    background: var(--card2);
    border: 1px solid var(--border);
    border-radius: 18px;
    font-size: 12px; color: var(--text2);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    font-family: inherit;
    display: inline-flex; align-items: center; gap: 5px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-suggestion-chip:hover {
    background: var(--accent-soft); color: var(--accent);
    border-color: var(--accent);
}
.ai-suggestion-chip .chip-num {
    display: inline-flex;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--bg2);
    color: var(--text3);
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px; font-weight: 700;
    align-items: center; justify-content: center;
    flex-shrink: 0;
}
.ai-suggestion-chip:hover .chip-num { background: var(--accent); color: #fff; }

/* Empty state wrapper — contiene hola + galería numerada */
.ai-empty-wrap {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 4px 0;
}

/* Galería de sugerencias (cuadraditos numerados) — visible solo en empty state */
.ai-suggestion-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 0 2px;
}

.ai-suggestion-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 12px 12px 10px;
    background: var(--card2);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
    font-family: inherit;
    min-height: 80px;
    overflow: hidden;
}
.ai-suggestion-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), #818cf8);
    opacity: 0;
    transition: opacity var(--transition);
}
.ai-suggestion-card:hover {
    background: var(--card);
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(84, 87, 229, .18);
}
.ai-suggestion-card:hover::before { opacity: 1; }
.ai-suggestion-card:active { transform: translateY(0); }
.ai-suggestion-num {
    position: absolute;
    top: 6px; right: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px; font-weight: 700;
    color: var(--text3);
    background: var(--card);
    border: 1px solid var(--border);
    width: 18px; height: 18px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    transition: all var(--transition);
}
.ai-suggestion-card:hover .ai-suggestion-num {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.ai-suggestion-icon { font-size: 20px; line-height: 1; }
.ai-suggestion-label {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.3;
    word-wrap: break-word;
    padding-right: 16px;
}

/* Input */
.ai-input-wrap {
    padding: 12px 18px 16px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--card);
}
.ai-input-box {
    display: flex; gap: 8px; align-items: flex-end;
    background: var(--card2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 8px 8px 14px;
    transition: border-color var(--transition);
}
.ai-input-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ai-input {
    flex: 1;
    background: none; border: none;
    color: var(--text); font-size: 14px;
    resize: none; outline: none;
    max-height: 120px; min-height: 22px;
    font-family: inherit;
    line-height: 1.4;
}
.ai-input::placeholder { color: var(--text3); }
.ai-send-btn {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: var(--accent); color: #fff;
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px;
    transition: all var(--transition);
    flex-shrink: 0;
}
.ai-send-btn:disabled { background: var(--border2); cursor: not-allowed; }
.ai-send-btn:not(:disabled):hover { background: var(--accent-h); }

/* Empty state panel — compacto porque las cards son el protagonista */
.ai-empty {
    text-align: center;
    padding: 8px 4px 12px;
    color: var(--text3);
}
.ai-empty-icon { font-size: 32px; margin-bottom: 8px; }
.ai-empty h4 { font-family: 'Syne',sans-serif; color: var(--text); font-size: 15px; margin-bottom: 3px; }
.ai-empty p { font-size: 12px; line-height: 1.4; }

.ai-error-banner {
    margin: 8px 18px 0;
    padding: 8px 12px;
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid var(--danger);
    border-radius: 8px;
    font-size: 12px;
}

/* ══════════════════════════════════════ RESPONSIVE ══ */
@media (max-width: 1200px) {
    .ai-drawer { width: 380px; }
}

@media (max-width: 1024px) {
    .kpi-grid { grid-template-columns: repeat(2,1fr); }
    .grid-3   { grid-template-columns: 1fr 1fr; }
    .col-span-2 { grid-column: span 1; }
    /* En tablet: botón toggle más grande para touch */
    .sidebar-toggle { width: 36px; height: 36px; font-size: 16px; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); width: var(--sidebar-w) !important; }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-overlay { display: block; }
    .main-wrapper { margin-left: 0 !important; }
    .mobile-toggle { display: flex; }
    .sidebar-toggle { display: none; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .content { padding: 16px; }
    .sync-status { display: none; }
    .page-subtitle { display: none; }
    .topbar { padding: 0 14px; gap: 10px; }
    .topbar-user span:last-child { display: none; }

    .ai-drawer { width: 100vw; border-left: none; }
    .ai-fab { bottom: 16px; right: 16px; width: 52px; height: 52px; }
    /* En mobile las cards se apilan en 1 columna (mejor legibilidad) */
    .ai-suggestion-grid { grid-template-columns: 1fr; gap: 8px; }
    .ai-suggestion-card { min-height: 72px; padding: 12px 14px; }
}

@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .kpi-card { padding: 16px; }
    .card { padding: 16px; }
    .topbar { padding: 0 10px; }
    .page-title h1 { font-size: 16px; }
    .topbar-user { display: none; }
    .content { padding: 12px; }
    html { font-size: 14px; }
    .modal { padding: 20px; }
}

@media (max-width: 360px) {
    .ai-fab { bottom: 12px; right: 12px; width: 48px; height: 48px; font-size: 20px; }
    .theme-toggle { width: 30px; height: 30px; font-size: 14px; }
}
/* ─────────────────────────────────────────────────────────
   v6.4 — Estilos para links dentro de mensajes del asistente
   Agregar este archivo al main.css o incluirlo aparte.
   ───────────────────────────────────────────────────────── */

.ai-msg-bubble .ai-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    margin: 4px 2px;
    background: rgba(84, 87, 229, 0.12);
    border: 1px solid rgba(84, 87, 229, 0.3);
    color: var(--accent, #5457e5);
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    transition: all 0.15s ease;
    max-width: 100%;
    word-break: break-word;
}

.ai-msg-bubble .ai-link:hover {
    background: rgba(84, 87, 229, 0.22);
    border-color: var(--accent, #5457e5);
    transform: translateY(-1px);
}

.ai-msg-bubble .ai-link:active {
    transform: translateY(0);
}

.ai-msg-bubble strong {
    font-weight: 700;
    color: var(--text, inherit);
}
