/* ── RESET & BASE ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --sidebar-w: 230px;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #1e3a5f;
    --sidebar-border: #1e293b;
    --accent: #3b82f6;
    --accent-dark: #2563eb;
    --accent-light: #eff6ff;
    --accent-border: #bfdbfe;
    --success: #22c55e;
    --success-light: #f0fdf4;
    --success-border: #bbf7d0;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --bg: #f1f5f9;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-mid: #374151;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -2px rgba(0,0,0,.05);
    --font: 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

html, body { height: 100%; font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg); }

/* ── TOPNAV ────────────────────────────────────────────────── */
.topnav {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    background: white;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    z-index: 100;
    box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.tn-logo { display: flex; align-items: center; gap: 10px; margin-right: 8px; flex-shrink: 0; }
.tn-icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: var(--text);
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; color: white; flex-shrink: 0;
}
.tn-title { font-size: 14px; font-weight: 800; color: var(--text); line-height: 1.2; }
.tn-sub   { font-size: 10px; color: var(--text-light); }
.tn-sep   { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; }
.tn-links { display: flex; align-items: center; gap: 2px; }
.tn-link {
    display: flex; align-items: center; gap: 7px;
    padding: 6px 12px; border-radius: 7px;
    font-size: 12.5px; font-weight: 500;
    color: var(--text-muted);
    transition: all .13s;
    cursor: pointer; border: none; background: none; font-family: var(--font);
    white-space: nowrap; position: relative;
}
.tn-link:hover  { background: #f1f5f9; color: var(--text); }
.tn-link.active { background: #f1f5f9; color: var(--text); font-weight: 600; }
.tn-link i      { font-size: 12px; }
.tn-right { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.tn-chip {
    display: flex; align-items: center; gap: 7px;
    background: var(--accent-light);
    border: 1px solid var(--accent-border);
    color: var(--accent-dark);
    padding: 5px 12px; border-radius: 20px;
    font-size: 11.5px; font-weight: 600;
}
.tn-chip-close {
    background: none; border: none;
    color: rgba(29,78,216,.45);
    cursor: pointer; font-size: 10px; margin-left: 2px; padding: 0;
    transition: color .15s;
}
.tn-chip-close:hover { color: var(--accent-dark); }
.tn-status { display: flex; align-items: center; gap: 6px; font-size: 11px; }
.tn-status .status-text { font-weight: 600; }
.tn-status.offline .status-text { color: var(--text-light); }
.tn-status.online  .status-text { color: #16a34a; }
.tn-status.warning .status-text { color: #b45309; }
.tn-status.online  .status-dot  { background: var(--success); box-shadow: 0 0 0 2px rgba(34,197,94,.25); animation: pulse-green 2.5s infinite; }
.tn-status.warning .status-dot  { background: var(--warning); }
.tn-status.offline .status-dot  { background: #94a3b8; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; flex-shrink: 0; }

.nav-badge {
    background: var(--danger);
    color: white;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

/* ── DROPDOWNS ────────────────────────────────────────────── */
.tn-dropdown { position: relative; display: flex; align-items: center; }
.dropdown-menu {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    background: white;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0,0,0,.1);
    min-width: 180px;
    display: none;
    flex-direction: column;
    padding: 6px;
    z-index: 1000;
}
.tn-dropdown:hover .dropdown-menu { display: flex; }
.dropdown-menu .tn-link {
    width: 100%;
    justify-content: flex-start;
    padding: 10px 14px;
}
.dropdown-menu .tn-link:hover { background: var(--bg); }
.dropdown-menu .tn-link.active { background: var(--accent-light); color: var(--accent-dark); }

/* Resaltar el toggle si hay un hijo activo */
.tn-dropdown:has(.tn-link.active) .dropdown-toggle {
    color: var(--accent-dark);
    background: var(--accent-light);
    font-weight: 700;
}

/* ── LAYOUT ────────────────────────────────────────────────── */
#app { display: block; }
.main-content { padding-top: 56px; min-height: 100vh; }
.view-container { padding: 24px 28px; max-width: 1200px; margin: 0 auto; }

/* ── CARDS ────────────────────────────────────────────────── */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-header h3 { font-size: 14px; font-weight: 700; color: var(--text); }
.card-body { padding: 20px; }

/* ── GRID ─────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 16px; }

/* ── FORM ─────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
}
.form-control {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-family: var(--font);
    color: var(--text);
    background: white;
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.12); }
.form-control:read-only { background: #f8fafc; color: var(--text-muted); }
select.form-control { cursor: pointer; }
input[type=file].form-control { padding: 6px 11px; cursor: pointer; }

/* ── BUTTONS ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    border: 1px solid transparent;
    transition: all .15s;
    white-space: nowrap;
}
.btn-primary   { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-secondary { background: white; color: var(--text-mid); border-color: var(--border); }
.btn-secondary:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn-success   { background: var(--success); color: white; border-color: var(--success); }
.btn-danger    { background: var(--danger); color: white; border-color: var(--danger); }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-lg { padding: 11px 22px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-mp { 
    background: #009ee3; 
    color: white; 
    border-color: #009ee3; 
    height: 48px;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-mp:hover { background: #008ad0; border-color: #008ad0; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,158,227,.2); }

/* ── PLAN BADGES ─────────────────────────────────────────── */
.plan-badge {
    padding: 3px 8px; border-radius: 6px; font-size: 11px; font-weight: 700;
}
.plan-gratis  { background: #f3f4f6; color: #4b5563; }
.plan-basico  { background: #eff6ff; color: #2563eb; }
.plan-pro     { background: #f5f3ff; color: #7c3aed; }
.plan-agencia { background: #fff7ed; color: #ea580c; }
.plan-administrador { background: #ecfeff; color: #0891b2; }
.plan-familia       { background: #fdf2f8; color: #db2777; }

.progress-bar-wrap { background: #e5e7eb; border-radius: 10px; height: 6px; width: 100%; overflow: hidden; }
.progress-bar-fill { background: var(--accent); height: 100%; transition: width .3s; }

/* ── KPI CARDS ────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.kpi-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    position: relative;
    overflow: hidden;
}
.kpi-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; }
.kpi-card.blue::before   { background: var(--accent); }
.kpi-card.green::before  { background: var(--success); }
.kpi-card.amber::before  { background: var(--warning); }
.kpi-card.purple::before { background: #8b5cf6; }
.kpi-label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.kpi-val   { font-size: 28px; font-weight: 800; margin: 6px 0 2px; line-height: 1; }
.kpi-card.blue   .kpi-val { color: var(--accent); }
.kpi-card.green  .kpi-val { color: #15803d; }
.kpi-card.amber  .kpi-val { color: #b45309; }
.kpi-card.purple .kpi-val { color: #7c3aed; }
.kpi-sub { font-size: 11px; color: var(--text-muted); }

/* ── STATUS CHIP (inline, junto al header) ─────────────────── */
.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    border: 1px solid transparent;
    white-space: nowrap;
}
.status-chip.ok   { background: var(--success-light); border-color: var(--success-border); color: #15803d; }
.status-chip.warn { background: var(--warning-light);  border-color: #fde68a; color: #92400e; }
.status-chip.sim  { background: #fff7ed; border-color: #fdba74; color: #c2410c; }
.status-chip.prod { background: #fff7ed; border-color: #fdba74; color: #c2410c; }

.sc-tooltip-wrap { position: relative; }
.sc-tooltip {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: #1e293b;
    color: #e2e8f0;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.6;
    padding: 10px 14px;
    border-radius: 10px;
    white-space: nowrap;
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    z-index: 999;
    pointer-events: none;
}
.sc-tooltip strong { color: #fff; font-weight: 700; }
.sc-tooltip::before {
    content: '';
    position: absolute;
    top: -6px; right: 14px;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid #1e293b;
}
.sc-tooltip-wrap:hover .sc-tooltip { display: block; }

/* ── STATUS BANNER ────────────────────────────────────────── */
.status-banner {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    border-radius: var(--radius);
    border: 1px solid;
    margin-bottom: 20px;
}
.status-banner.ok    { background: var(--success-light); border-color: var(--success-border); }
.status-banner.warn  { background: var(--warning-light);  border-color: #fde68a; }
.status-banner.error { background: var(--danger-light);   border-color: #fecaca; }
.status-banner.sim   { background: #fff7ed; border-color: #fdba74; }
.status-banner .sb-icon  { font-size: 22px; flex-shrink: 0; }
.status-banner .sb-body  { flex: 1; }
.status-banner .sb-title { font-weight: 700; font-size: 13px; }
.status-banner .sb-sub   { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── TABS ─────────────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--border); margin-bottom: 22px; }
.tab-btn {
    padding: 9px 20px;
    background: transparent;
    border: none; border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    font-family: var(--font);
    border-radius: 6px 6px 0 0;
    transition: all .15s;
    position: relative; bottom: -2px;
}
.tab-btn.active { color: var(--accent); font-weight: 700; border-bottom-color: var(--accent); background: var(--accent-light); }
.tab-btn:hover:not(.active) { background: #f8fafc; color: var(--text-mid); }

/* ── TABLES ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    background: #f8fafc;
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 13px;
    color: var(--text);
    vertical-align: middle;
}
.data-table tbody tr:hover td { background: #f8fafc; }
.data-table tfoot td { background: #f8fafc; font-weight: 700; border-top: 2px solid var(--border); }
.text-right  { text-align: right !important; }
.text-center { text-align: center !important; }
.font-mono   { font-family: var(--font-mono), monospace; }

/* ── BADGES ───────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    background: var(--accent-light);
    color: var(--accent-dark);
    border: 1px solid var(--accent-border);
}
.badge-success { background: var(--success-light); color: #15803d; border-color: var(--success-border); }
.badge-warning { background: var(--warning-light); color: #b45309; border-color: #fde68a; }
.badge-danger  { background: var(--danger-light);  color: #b91c1c; border-color: #fecaca; }
.badge-gray    { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }

/* ── PLAN BADGES ──────────────────────────────────────────── */
.plan-badge {
    display: inline-flex; align-items: center;
    padding: 2px 10px; border-radius: 20px;
    font-size: 11px; font-weight: 700; letter-spacing: .3px;
    border: 1px solid;
}
.plan-gratis   { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.plan-basico   { background: #f1f5f9; color: #475569; border-color: #cbd5e1; }
.plan-pro      { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.plan-agencia  { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.plan-premium_ia{ background: #fdf4ff; color: #7e22ce; border-color: #e9d5ff; }

/* ── PLAN BAR ─────────────────────────────────────────────── */
.plan-bar-wrap {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
}

/* ── EMPRESA CARDS ────────────────────────────────────────── */
.empresas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 18px;
}

.empresa-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: box-shadow .18s, border-color .18s, transform .12s;
    overflow: hidden;
    position: relative;
}
.empresa-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--accent-border);
    transform: translateY(-2px);
}

.ec-header {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 18px 18px 14px;
}

.ec-avatar {
    width: 46px;
    height: 46px;
    min-width: 46px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: white;
    font-size: 20px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ec-info { flex: 1; min-width: 0; }
.ec-nombre { font-size: 14px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ec-cuit   { font-size: 11px; color: var(--text-muted); margin-top: 2px; font-family: var(--font-mono), monospace; }

.ec-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.ec-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: white;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all .15s;
}
.ec-btn:hover { background: var(--accent-light); border-color: var(--accent-border); color: var(--accent); }
.ec-btn.danger:hover { background: var(--danger-light); border-color: #fecaca; color: var(--danger); }

.ec-badges {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 18px 14px;
    flex-wrap: wrap;
}

.ec-footer {
    display: flex;
    gap: 0;
    border-top: 1px solid var(--border);
    background: #f8fafc;
}
.ec-footer span {
    flex: 1;
    text-align: center;
    padding: 8px 4px;
    font-size: 11px;
    color: var(--text-muted);
    border-right: 1px solid var(--border);
    font-family: var(--font-mono), monospace;
}
.ec-footer span:last-child { border-right: none; }

/* ── AFIP STATUS PILL ─────────────────────────────────────── */
.afip-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid transparent;
}
.ap-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}
.afip-pill.on        { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.afip-pill.on .ap-dot { background: #22c55e; box-shadow: 0 0 0 2px rgba(34,197,94,.25); animation: pulse-green 2s infinite; }
.afip-pill.sim       { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.afip-pill.sim .ap-dot { background: #f59e0b; }
.afip-pill.off       { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.afip-pill.off .ap-dot { background: #ef4444; }
.afip-pill.err       { background: #f8fafc; border-color: #e2e8f0; color: #64748b; }
.afip-pill.err .ap-dot { background: #94a3b8; }
.afip-pill.checking  { background: #f8fafc; border-color: #e2e8f0; color: #64748b; }
.afip-pill.checking .ap-dot { background: #94a3b8; animation: blink 1s infinite; }

@keyframes pulse-green {
    0%, 100% { box-shadow: 0 0 0 2px rgba(34,197,94,.25); }
    50%       { box-shadow: 0 0 0 5px rgba(34,197,94,.1); }
}
@keyframes blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: .3; }
}

/* ── MODAL CONFIG EMPRESA ──────────────────────────────────── */
.modal-config-box {
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 760px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.mcfg-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.mcfg-title-row {
    display: flex;
    align-items: center;
    gap: 13px;
}
.mcfg-avatar {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    font-size: 18px !important;
}
.mcfg-nombre { font-size: 17px; font-weight: 800; color: var(--text); }
.mcfg-sub    { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.btn-close-modal {
    width: 32px; height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: white;
    color: var(--text-muted);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px;
    transition: all .15s;
    flex-shrink: 0;
}
.btn-close-modal:hover { background: var(--danger-light); border-color: #fecaca; color: var(--danger); }

.mcfg-body {
    flex: 1;
    overflow-y: auto;
    padding: 0 24px;
}
.mcfg-section {
    padding: 20px 0;
    border-bottom: 1px solid var(--border);
}
.mcfg-section:last-child { border-bottom: none; }
.mcfg-guide { background: transparent; }

.sim-toggle {
    background: var(--warning-light);
    border: 1px solid #fde68a;
    border-radius: var(--radius-sm);
    padding: 8px 12px !important;
}

.mcfg-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: #f8fafc;
    flex-shrink: 0;
}

/* ── CERT PASOS ───────────────────────────────────────────── */
.cert-paso {
    display: flex;
    gap: 14px;
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
}
.cert-paso:last-child { border-bottom: none; }
.cert-paso-num {
    width: 26px;
    height: 26px;
    min-width: 26px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    font-size: 12px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 2px;
    flex-shrink: 0;
}
.cert-paso-titulo { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.cert-paso-desc   { font-size: 12px; color: var(--text-muted); line-height: 1.6; }

/* chip btn en topbar */
.chip-btn {
    background: none;
    border: none;
    color: var(--accent-dark);
    cursor: pointer;
    padding: 0 0 0 4px;
    opacity: .7;
    font-size: 11px;
    transition: opacity .15s;
}
.chip-btn:hover { opacity: 1; }

/* ── EMPTY STATE ──────────────────────────────────────────── */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px 20px; color: var(--text-muted); text-align: center; }
.empty-state i { font-size: 40px; margin-bottom: 14px; opacity: .35; }
.empty-state p { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.empty-state small { font-size: 12px; }

/* ── TOTALS ───────────────────────────────────────────────── */
.totals-box { display: flex; justify-content: flex-end; gap: 32px; align-items: flex-end; padding: 16px 0 0; border-top: 1px solid var(--border); }
.total-item { text-align: right; }
.total-item .tl { font-size: 11px; color: var(--text-muted); margin-bottom: 2px; }
.total-item .tv { font-size: 17px; font-weight: 700; font-family: var(--font-mono), monospace; }
.total-item.big .tv { font-size: 26px; color: var(--accent); }

/* ── MODAL ────────────────────────────────────────────────── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 9999; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal-box {
    background: white;
    border-radius: 14px;
    padding: 32px 28px;
    max-width: 420px;
    width: 90%;
    max-height: 95vh;
    overflow-y: auto;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,.18);
    animation: modalIn .2s ease;
}
@keyframes modalIn { from { opacity:0; transform: scale(.95) translateY(8px); } to { opacity:1; transform: scale(1) translateY(0); } }
.modal-icon    { font-size: 40px; margin-bottom: 12px; }
.modal-title   { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.modal-msg     { font-size: 13px; color: var(--text-muted); line-height: 1.6; margin-bottom: 22px; white-space: pre-wrap; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }

/* ── TOAST ────────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 10000; }
.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--text);
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    min-width: 240px;
    max-width: 360px;
    box-shadow: 0 8px 24px rgba(0,0,0,.18);
    animation: toastIn .2s ease;
}
.toast.success { background: #15803d; }
.toast.error   { background: #b91c1c; }
.toast.warning { background: #b45309; }
@keyframes toastIn { from { opacity:0; transform: translateX(20px); } to { opacity:1; transform: translateX(0); } }

/* ── MISC ─────────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.section-title { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.toggle-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.toggle-row input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.toggle-row label { font-size: 13px; cursor: pointer; }
code { background: #f1f5f9; border: 1px solid var(--border); padding: 1px 6px; border-radius: 4px; font-size: 12px; font-family: var(--font-mono), monospace; }
.progress-bar-wrap { background: #e2e8f0; border-radius: 99px; height: 6px; overflow: hidden; margin-top: 6px; }
.progress-bar-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }

@media (max-width: 900px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-4   { grid-template-columns: 1fr 1fr; }
    .grid-3   { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
    .sidebar  { display: none; }
    .kpi-grid, .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ── LOGIN OVERLAY ────────────────────────────────────────── */
.login-overlay {
    position: fixed; inset: 0;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 60%, #0f4c2b 100%);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999;
    transition: opacity .3s;
}
.login-overlay.hidden { opacity: 0; pointer-events: none; }
.login-card {
    background: white; border-radius: 18px; padding: 40px 36px 36px;
    width: 100%; max-width: 380px;
    box-shadow: 0 32px 80px rgba(0,0,0,.35);
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-icon {
    width: 60px; height: 60px;
    background: linear-gradient(135deg, var(--accent), #15803d);
    border-radius: 16px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 26px; color: white; margin-bottom: 14px;
    box-shadow: 0 8px 24px rgba(22,163,74,.3);
}
.login-brand { font-size: 20px; font-weight: 800; color: var(--text); }
.login-sub   { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.login-form  { display: flex; flex-direction: column; gap: 14px; }
.login-eye {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; padding: 4px; font-size: 14px;
}
.login-eye:hover { color: var(--text); }
.login-error {
    background: #fef2f2; border: 1px solid #fecaca;
    color: #b91c1c; border-radius: 7px;
    padding: 8px 12px; font-size: 12.5px; font-weight: 500;
}

/* ── SIGNUP PLANS ─────────────────────────────────────────── */
.signup-plans { display: flex; flex-direction: column; gap: 12px; }
.s-plan-card {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border: 2px solid var(--border); border-radius: 14px;
    cursor: pointer; transition: all .2s; position: relative;
}
.s-plan-card:hover { border-color: var(--accent-border); background: var(--bg); }
.s-plan-card.active { border-color: var(--accent); background: var(--accent-light); }
.s-plan-tag {
    position: absolute; top: -10px; right: 20px;
    background: var(--accent); color: white;
    font-size: 9px; font-weight: 800; padding: 2px 8px; border-radius: 20px;
}
.s-plan-name { font-size: 14px; font-weight: 700; color: var(--text); }
.s-plan-desc { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.s-plan-price { font-size: 16px; font-weight: 800; color: var(--text); text-align: right; }
.s-plan-price sub { font-size: 10px; font-weight: 500; color: var(--text-muted); margin-left: 2px; }

/* ── TOPNAV USER CHIP ─────────────────────────────────────── */
.tn-user {
    display: flex; align-items: center; gap: 8px;
    padding: 5px 10px; border-radius: 8px;
    background: #f1f5f9; border: 1px solid var(--border);
    font-size: 12.5px; font-weight: 600; color: var(--text);
}
.tn-user-btn {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; padding: 3px 6px; border-radius: 5px; font-size: 12px;
}
.tn-user-btn:hover { background: var(--border); color: var(--text); }

/* ── USUARIOS VIEW ────────────────────────────────────────── */
.user-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.user-table th { background: var(--bg); font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; padding: 8px 12px; border-bottom: 2px solid var(--border); text-align: left; }
.user-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.user-table tr:last-child td { border-bottom: none; }
.user-table tr:hover td { background: #f8fafc; }
.role-badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.role-badge.admin   { background: #eff6ff; color: #1d4ed8; }
.role-badge.usuario { background: #f0fdf4; color: #15803d; }

/* ── DASHBOARD ────────────────────────────────────────────── */
.dash-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.dash-kpi { background: white; border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.dash-kpi .dk-label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 8px; }
.dash-kpi .dk-val   { font-size: 28px; font-weight: 800; color: var(--text); line-height: 1; }
.dash-kpi .dk-sub   { font-size: 11px; color: var(--text-muted); margin-top: 5px; }
.dash-kpi.blue  { border-top: 3px solid #3b82f6; }
.dash-kpi.green { border-top: 3px solid #16a34a; }
.dash-kpi.amber { border-top: 3px solid #f59e0b; }
.dash-kpi.purple{ border-top: 3px solid #8b5cf6; }
.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px; }
.qa-btn {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    background: white; border: 1px solid var(--border); border-radius: 12px;
    padding: 20px 16px; cursor: pointer; transition: all .15s;
    font-family: var(--font); font-size: 13px; font-weight: 600; color: var(--text);
}
.qa-btn:hover { border-color: var(--accent); background: #f0fdf4; color: var(--accent); box-shadow: 0 4px 12px rgba(22,163,74,.1); }
.qa-btn i { font-size: 22px; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: repeat(2, 1fr); } .quick-actions { grid-template-columns: 1fr 1fr; } }

/* ── BACK BUTTON ──────────────────────────────────────────── */
.tn-back {
    display: flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: 8px;
    background: none; border: 1.5px solid var(--border);
    color: var(--text-muted); cursor: pointer; font-size: 13px;
    flex-shrink: 0; transition: all .15s;
}
.tn-back:hover { background: #f1f5f9; color: var(--text); border-color: #94a3b8; }
.tn-back-sep { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; }

/* ── AUTOCOMPLETE ─────────────────────────────────────────── */
.ac-item { padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border); transition: background .1s; }
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: #f0fdf4; }

/* ── BACK BUTTON (content area) ───────────────────────────── */
.btn-back-content {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px 4px 6px; background: none; border: none;
    color: var(--text-muted); font-size: 13px; font-weight: 500;
    cursor: pointer; border-radius: 6px; transition: all .15s;
    margin-bottom: 10px;
}
.btn-back-content:hover { color: var(--text); background: var(--border); }

/* ── EXPORT CARDS ─────────────────────────────────────────── */
.export-card { display: flex; flex-direction: column; gap: 10px; }
.export-card-icon { width: 42px; height: 42px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.export-card-title { font-weight: 700; font-size: 14px; color: var(--text); }
.export-card-desc { font-size: 12px; color: var(--text-muted); flex: 1; line-height: 1.5; }

/* ── DISEÑO DE FACTURA ────────────────────────────────────── */
.diseño-wrap {
    display: grid;
    grid-template-columns: 480px 1fr;
    gap: 24px;
    align-items: start;
    min-height: calc(100vh - 120px);
}
@media (max-width: 1100px) { .diseño-wrap { grid-template-columns: 1fr; } }

.diseño-panel {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 0;
}
.diseño-title { font-size: 20px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.diseño-title i { color: var(--warning); }
.diseño-subtitle { font-size: 13px; color: var(--text-muted); margin-bottom: 24px; line-height: 1.5; }
.diseño-section { border-top: 1px solid var(--border); padding: 20px 0; }
.diseño-section h3 { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.diseño-hint { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; line-height: 1.5; }
.diseño-actions { padding-top: 20px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* Template cards */
.template-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.template-card {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 10px 8px; border: 2px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg); cursor: pointer; transition: all .15s; text-align: center;
}
.template-card:hover { border-color: var(--accent-border); background: var(--accent-light); }
.template-card.active { border-color: var(--accent); background: var(--accent-light); }
.template-preview { width: 100%; height: 28px; border-radius: 4px; }
.template-name { font-size: 12px; font-weight: 700; color: var(--text); }
.template-desc { font-size: 10px; color: var(--text-muted); }

/* Logo area */
.logo-area { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; min-height: 60px; }
.logo-preview-img { max-height: 60px; max-width: 180px; object-fit: contain; border: 1px solid var(--border); border-radius: 6px; padding: 4px; background: #fff; }
.logo-placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; width: 100px; height: 60px; border: 2px dashed var(--border); border-radius: 8px; color: var(--text-muted); font-size: 22px; }
.logo-placeholder span { font-size: 11px; font-weight: 500; }

/* Toggle row */
.toggle-row { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13px; color: var(--text-mid); }
.toggle-row input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); }

/* Preview */
.diseño-preview-wrap {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    position: sticky;
    top: 20px;
}
.preview-header {
    padding: 12px 18px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-mid);
    display: flex;
    align-items: center;
    gap: 8px;
}
.preview-scale-wrap {
    padding: 16px;
    overflow: auto;
    max-height: calc(100vh - 180px);
    background: #e2e8f0;
    display: flex;
    justify-content: center;
}

/* Factura preview (HTML approximation of PDF) */
.fp-doc {
    width: 420px;
    background: #fff;
    font-family: Helvetica, Arial, sans-serif;
    font-size: 11px;
    color: #111;
    box-shadow: 0 4px 16px rgba(0,0,0,.18);
    border-radius: 3px;
    overflow: hidden;
    flex-shrink: 0;
}
.fp-header { display: flex; background: #f8fafc; }
.fp-left { flex: 1; padding: 10px 12px; position: relative; }
.fp-accent { position: absolute; right: 0; top: 0; bottom: 0; width: 4px; }
.fp-empresa { font-size: 13px; font-weight: 700; color: #111; margin-bottom: 4px; }
.fp-meta { font-size: 9px; color: #64748b; line-height: 1.5; }
.fp-right { width: 120px; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 8px; }
.fp-letra { font-size: 36px; font-weight: 700; line-height: 1; }
.fp-tipo { font-size: 9px; font-weight: 700; color: #111; text-align: center; }
.fp-nro { font-size: 8px; color: #64748b; text-align: center; }
.fp-fecha { padding: 5px 12px; font-size: 9px; border-top: 1px solid; border-bottom: 1px solid; }
.fp-card { margin: 8px 12px; border: 1px solid #e2e8f0; border-radius: 3px; overflow: hidden; }
.fp-card-hdr { padding: 4px 10px; font-size: 8px; font-weight: 700; letter-spacing: .8px; background: #f8fafc; border-bottom: 1px solid #e2e8f0; }
.fp-card-body { padding: 6px 10px; }
.fp-table { width: calc(100% - 24px); margin: 6px 12px; border-collapse: collapse; font-size: 9px; }
.fp-table thead tr th { padding: 5px 6px; text-align: left; font-size: 8px; }
.fp-table tbody tr td { padding: 4px 6px; }
.fp-totales { display: flex; justify-content: flex-end; margin: 6px 12px; }
.fp-tot-box { width: 160px; border: 1px solid; border-radius: 3px; overflow: hidden; font-size: 9px; }
.fp-tot-row { display: flex; justify-content: space-between; padding: 4px 8px; border-bottom: 1px solid #dcfce7; }
.fp-tot-final { display: flex; justify-content: space-between; padding: 5px 8px; font-weight: 700; font-size: 11px; color: #fff; }
.fp-pie { margin: 6px 12px; padding: 5px 10px; border: 1px solid; border-radius: 3px; }
.fp-footer { display: flex; gap: 8px; margin: 8px 12px 12px; align-items: flex-start; }
.fp-cae { flex: 1; border: 1px solid #e2e8f0; border-radius: 3px; padding: 8px 10px; }
.fp-qr { display: flex; flex-direction: column; align-items: center; gap: 2px; }

/* ── COLOR SWATCHES ───────────────────────────────────────── */
.color-swatch {
    width: 28px; height: 28px; border-radius: 50%;
    border: 2px solid transparent; cursor: pointer;
    transition: transform .12s, border-color .12s;
    flex-shrink: 0; position: relative;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.color-swatch-custom {
    background: #f1f5f9; border: 2px dashed var(--border);
    display: flex; align-items: center; justify-content: center; overflow: hidden;
}

/* ── TEMPLATE CARDS (mejorado) ────────────────────────────── */
.template-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.template-card {
    display: flex; flex-direction: column; align-items: stretch; gap: 6px;
    padding: 8px; border: 2px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg); cursor: pointer; transition: all .15s; text-align: center;
}
.template-card:hover { border-color: var(--accent-border); background: #fff; transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.template-card.active { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent-light); }
.template-name { font-size: 11px; font-weight: 700; color: var(--text); margin-top: 2px; }

/* ── IA Tools ─────────────────────────────────────────────────────────────── */
.ia-tool-header { display: flex; align-items: flex-start; gap: 14px; }
.ia-tool-icon {
    width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 17px;
}
.ia-tool-title { font-weight: 700; font-size: 14px; margin-bottom: 3px; }
.ia-tool-desc  { font-size: 12px; color: var(--text-muted); line-height: 1.5; }
