/* assets/css/main.css */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

:root {
    /* Brand */
    --brand:          #1A56A0;
    --brand-light:    #D5E8F5;
    --brand-hover:    #154A8E;

    /* Backgrounds */
    --bg-page:        #F4F6F9;
    --bg-card:        #FFFFFF;
    --bg-sidebar:     #0F1923;
    --bg-sidebar-hover: rgba(255,255,255,0.07);
    --bg-sidebar-active: rgba(255,255,255,0.12);

    /* Text */
    --text-primary:   #1E293B;
    --text-secondary: #64748B;
    --text-muted:     #94A3B8;
    --text-sidebar:   rgba(255,255,255,0.75);
    --text-sidebar-active: #FFFFFF;

    /* Borders */
    --border:         #E2E8F0;
    --border-focus:   #1A56A0;

    /* Status badges */
    --status-nuevo-bg:       #EFF6FF;
    --status-nuevo-text:     #1D4ED8;
    --status-contactado-bg:  #FEFCE8;
    --status-contactado-text:#A16207;
    --status-seguimiento-bg: #FFF7ED;
    --status-seguimiento-text:#C2410C;
    --status-convertido-bg:  #F0FDF4;
    --status-convertido-text:#15803D;
    --status-perdido-bg:     #F8FAFC;
    --status-perdido-text:   #475569;

    /* Activity types */
    --act-comment-color:  #6366F1;
    --act-call-color:     #0EA5E9;
    --act-whatsapp-color: #16A34A;
    --act-email-color:    #F59E0B;
    --act-status-color:   #8B5CF6;
    --act-system-color:   #94A3B8;

    /* Layout */
    --sidebar-w:      240px;
    --sidebar-w-mini: 60px;
    --topbar-h:       56px;
    --radius-sm:      6px;
    --radius-md:      8px;
    --radius-lg:      12px;

    /* Shadows */
    --shadow-sm:  0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:  0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg:  0 8px 32px rgba(0,0,0,0.12);
    --shadow-drawer: -4px 0 24px rgba(0,0,0,0.12);

    /* Transitions */
    --t-fast:  0.15s ease;
    --t-med:   0.25s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-page);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Layout shell ──────────────────────────────────────────────────────── */

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

/* ─── Sidebar ───────────────────────────────────────────────────────────── */

.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    transition: width var(--t-med), min-width var(--t-med);
    overflow: hidden;
    z-index: 100;
    flex-shrink: 0;
}

.sidebar.mini {
    width: var(--sidebar-w-mini);
    min-width: var(--sidebar-w-mini);
    overflow: visible;
}

.sidebar-logo {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
    overflow: hidden;
    white-space: nowrap;
}

.sidebar-logo .logo-icon {
    width: 28px;
    height: 28px;
    background: var(--brand);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    letter-spacing: -0.5px;
}

.sidebar-logo .logo-text {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
}

.sidebar-logo .logo-sub {
    font-size: 11px;
    color: var(--text-sidebar);
    margin-top: 1px;
    white-space: nowrap;
}

.sidebar.mini .logo-copy {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

/* Project switcher */
.project-switcher {
    margin: 12px 10px 4px;
    position: relative;
    flex-shrink: 0;
}

.sidebar.mini .project-switcher { display: none; }

.project-switcher select {
    width: 100%;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.1);
    color: #fff;
    font-size: 12px;
    font-family: inherit;
    padding: 7px 28px 7px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    appearance: none;
    outline: none;
}

.project-switcher::after {
    content: '▾';
    position: absolute;
    right: 9px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-sidebar);
    font-size: 11px;
    pointer-events: none;
}

.project-switcher select option {
    background: #1E2D3D;
    color: #fff;
}

/* Nav */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0;
    scrollbar-width: none;
}

.sidebar-nav::-webkit-scrollbar { display: none; }

.nav-section-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.3);
    padding: 12px 16px 4px;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity var(--t-med);
}

.sidebar.mini .nav-section-label { opacity: 0; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    color: var(--text-sidebar);
    cursor: pointer;
    border-radius: 0;
    transition: background var(--t-fast), color var(--t-fast);
    white-space: nowrap;
    overflow: hidden;
    text-decoration: none;
    font-size: 13.5px;
    margin: 1px 6px;
    border-radius: var(--radius-md);
    position: relative;
}

.nav-item:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-active);
    text-decoration: none;
}

.nav-item.active {
    background: var(--bg-sidebar-active);
    color: var(--text-sidebar-active);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--brand);
    border-radius: 0 3px 3px 0;
    margin-left: -6px;
}

.nav-item .nav-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
}

.nav-item .nav-label {
    transition: opacity var(--t-med);
    white-space: nowrap;
}

.sidebar.mini .nav-item .nav-label { opacity: 0; width: 0; overflow: hidden; }
.sidebar.mini .nav-item {
    justify-content: center;
    padding: 9px;
    width: 42px;
    overflow: visible;
}

.sidebar.mini .nav-item::after,
.sidebar.mini .sidebar-toggle button::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%) translateX(-4px);
    background: #111827;
    color: #fff;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    font-size: 12px;
    line-height: 1;
    opacity: 0;
    padding: 8px 9px;
    pointer-events: none;
    transition: opacity var(--t-fast), transform var(--t-fast);
    white-space: nowrap;
    z-index: 300;
}

.sidebar.mini .nav-item:hover::after,
.sidebar.mini .sidebar-toggle button:hover::after {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

/* Collapse toggle (en el header del logo, arriba) */
.sidebar-collapse {
    margin-left: auto;
    background: rgba(255,255,255,0.06);
    border: none;
    color: var(--text-sidebar);
    width: 28px;
    height: 28px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: background var(--t-fast), color var(--t-fast);
    position: relative;
}

.sidebar-collapse:hover { background: rgba(255,255,255,0.12); color: #fff; }

/* En modo mini el logo se centra y el botón queda solo, centrado */
.sidebar.mini .sidebar-logo {
    padding: 0;
    justify-content: center;
}
.sidebar.mini .logo-icon { display: none; }
.sidebar.mini .sidebar-collapse { margin-left: 0; }

.sidebar.mini .sidebar-collapse::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%) translateX(-4px);
    background: #111827;
    color: #fff;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    font-size: 12px;
    line-height: 1;
    opacity: 0;
    padding: 8px 9px;
    pointer-events: none;
    transition: opacity var(--t-fast), transform var(--t-fast);
    white-space: nowrap;
    z-index: 300;
}
.sidebar.mini .sidebar-collapse:hover::after {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

/* User info + logout (abajo) */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-top: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
    overflow: hidden;
    white-space: nowrap;
}

.sidebar-user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
    transition: opacity var(--t-med);
}

.sidebar-user-name {
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-email {
    font-size: 11px;
    color: var(--text-sidebar);
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-logout {
    color: var(--text-sidebar);
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-md);
    flex-shrink: 0;
    transition: background var(--t-fast), color var(--t-fast);
    position: relative;
}
.sidebar-logout:hover { background: rgba(229,62,62,0.15); color: #FF6B6B; }

.sidebar.mini .sidebar-user {
    justify-content: center;
    padding: 12px 9px;
}
.sidebar.mini .sidebar-user-info { opacity: 0; width: 0; overflow: hidden; }
.sidebar.mini .sidebar-user-avatar { display: none; }

.sidebar.mini .sidebar-logout::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%) translateX(-4px);
    background: #111827;
    color: #fff;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    font-size: 12px;
    line-height: 1;
    opacity: 0;
    padding: 8px 9px;
    pointer-events: none;
    transition: opacity var(--t-fast), transform var(--t-fast);
    white-space: nowrap;
    z-index: 300;
}
.sidebar.mini .sidebar-logout:hover::after {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

.sidebar.mini .sidebar-toggle button {
    width: 42px;
    height: 34px;
}

.sidebar.mini .sidebar-toggle button span {
    display: none;
}

/* ─── Main area ─────────────────────────────────────────────────────────── */

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.topbar {
    height: var(--topbar-h);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    flex-shrink: 0;
    z-index: 50;
}

.topbar-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ─── Cards ─────────────────────────────────────────────────────────────── */

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

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.card-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.card-body { padding: 20px; }

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.page-header h1 {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 13.5px;
    line-height: 1.5;
}

.two-col-grid {
    display: grid;
    grid-template-columns: minmax(280px, 380px) 1fr;
    gap: 18px;
    align-items: start;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* ─── Vista de detalle de contacto ──────────────────────────────────────── */
.back-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    margin-right: 10px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    vertical-align: middle;
    transition: background var(--t-fast), color var(--t-fast);
}
.back-link:hover { background: var(--bg-muted, rgba(0,0,0,0.05)); color: var(--text-primary); }

.contact-hero {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.contact-hero-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 600;
    flex-shrink: 0;
}

.contact-hero-info h1 {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.contact-hero-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 12.5px;
    color: var(--text-muted);
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--bg-muted, rgba(0,0,0,0.05));
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 12px;
    color: var(--text-secondary);
}

.detail-grid {
    display: grid;
    grid-template-columns: minmax(320px, 1fr) 1fr;
    gap: 18px;
    align-items: start;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.detail-form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 4px;
}

.detail-save-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-right: auto;
}

@media (max-width: 900px) {
    .detail-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
}

.list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.list-row:last-child {
    border-bottom: none;
}

.list-row-title {
    font-weight: 600;
    color: var(--text-primary);
}

.list-row-meta {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 3px;
}

.project-uuid {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    max-width: 100%;
}

.project-uuid code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11.5px;
    color: var(--text-secondary);
    background: var(--bg-muted, rgba(0,0,0,0.04));
    padding: 2px 7px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.uuid-copy {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 3px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    font-size: 14px;
    transition: color var(--t-fast), background var(--t-fast);
    flex-shrink: 0;
}
.uuid-copy:hover { color: var(--brand); background: rgba(0,0,0,0.05); }

.empty-state {
    padding: 36px 20px;
    text-align: center;
    color: var(--text-secondary);
}

.empty-state h2,
.empty-state h3 {
    color: var(--text-primary);
    font-size: 18px;
    margin: 10px 0 6px;
}

.empty-state p {
    line-height: 1.5;
}

.empty-icon {
    color: var(--brand);
    font-size: 36px;
}

.guide-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
}

.guide-step {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    padding: 18px;
}

.guide-step h3 {
    font-size: 15px;
    margin-bottom: 8px;
}

.guide-step p {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.5;
}

.code-block {
    background: #111827;
    border-radius: var(--radius-md);
    color: #E5E7EB;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 12px;
    line-height: 1.55;
    margin-top: 12px;
    overflow-x: auto;
    padding: 12px;
    white-space: pre;
}

/* ─── KPI cards ─────────────────────────────────────────────────────────── */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
}

.kpi-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1;
}

.kpi-value.accent { color: var(--brand); }
.kpi-value.success { color: #16A34A; }
.kpi-value.warning { color: #D97706; }

.kpi-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

/* ─── Botones ────────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--t-fast);
    line-height: 1;
    white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }

.btn-secondary {
    background: #fff;
    color: var(--text-primary);
    border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg-page); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-page); color: var(--text-primary); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 7px; }

/* ─── Badges de status ──────────────────────────────────────────────────── */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 99px;
    font-size: 11.5px;
    font-weight: 500;
    white-space: nowrap;
}

.badge-nuevo       { background: var(--status-nuevo-bg);       color: var(--status-nuevo-text); }
.badge-en_proceso  { background: #F0F9FF; color: #0369A1; }
.badge-contactado  { background: var(--status-contactado-bg);  color: var(--status-contactado-text); }
.badge-seguimiento { background: var(--status-seguimiento-bg); color: var(--status-seguimiento-text); }
.badge-convertido  { background: var(--status-convertido-bg);  color: var(--status-convertido-text); }
.badge-perdido     { background: var(--status-perdido-bg);      color: var(--status-perdido-text); }

/* ─── Tabla ─────────────────────────────────────────────────────────────── */

.table-wrap {
    overflow-x: auto;
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

.data-table th {
    text-align: left;
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    background: var(--bg-card);
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid #F1F5F9;
    vertical-align: middle;
    color: var(--text-primary);
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tbody tr {
    transition: background var(--t-fast);
    cursor: pointer;
}

.data-table tbody tr:hover { background: #F8FAFC; }

.lead-name {
    font-weight: 500;
    color: var(--text-primary);
}

.lead-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 1px;
}

.text-muted { color: var(--text-muted); font-size: 12.5px; }

/* ─── Filtros ───────────────────────────────────────────────────────────── */

.filters-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.filter-input {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 6px 12px;
    font-size: 13px;
    color: var(--text-primary);
    min-width: 220px;
}

.filter-input input {
    border: none;
    background: transparent;
    font-size: 13px;
    font-family: inherit;
    color: var(--text-primary);
    outline: none;
    flex: 1;
    min-width: 0;
}

.filter-input input::placeholder { color: var(--text-muted); }

.filter-select {
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 7px 12px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text-primary);
    outline: none;
    cursor: pointer;
}

.filter-select:focus { border-color: var(--brand); }

.filters-count {
    margin-left: auto;
    font-size: 12.5px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ─── Paginación ────────────────────────────────────────────────────────── */

.pagination {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    justify-content: flex-end;
}

.page-btn {
    min-width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 8px;
    transition: all var(--t-fast);
}

.page-btn:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.page-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ─── Drawer ────────────────────────────────────────────────────────────── */

.drawer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,25,35,0.4);
    z-index: 200;
    backdrop-filter: blur(1px);
}

.drawer-overlay.open { display: block; }

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: 480px;
    max-width: 100vw;
    background: var(--bg-card);
    box-shadow: var(--shadow-drawer);
    z-index: 201;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform var(--t-med);
}

.drawer.open { transform: translateX(0); }

.drawer-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    flex-shrink: 0;
}

.drawer-header .lead-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--brand-light);
    color: var(--brand);
    font-weight: 600;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.drawer-header .lead-info { flex: 1; min-width: 0; }

.drawer-header .lead-info h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.drawer-header .lead-info .lead-contact {
    font-size: 12.5px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.drawer-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all var(--t-fast);
    font-size: 18px;
    line-height: 1;
    flex-shrink: 0;
}

.drawer-close:hover { background: var(--bg-page); color: var(--text-primary); }

.drawer-status-bar {
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    background: #FAFBFC;
}

.drawer-status-bar .status-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.drawer-status-bar select {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 5px 10px;
    font-size: 12.5px;
    font-family: inherit;
    color: var(--text-primary);
    cursor: pointer;
    outline: none;
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.drawer-section {
    padding: 16px 20px;
    border-bottom: 1px solid #F1F5F9;
}

.drawer-section-title {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* Acciones rápidas */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.quick-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 10px 8px;
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 11px;
    color: var(--text-secondary);
    font-family: inherit;
    transition: all var(--t-fast);
    font-weight: 500;
}

.quick-action-btn:hover {
    border-color: var(--brand);
    color: var(--brand);
    background: var(--brand-light);
}

.quick-action-btn .qa-icon { font-size: 18px; }

/* Formulario de actividad */
.activity-form {
    margin-bottom: 16px;
}

.activity-tabs {
    display: flex;
    gap: 2px;
    background: var(--bg-page);
    border-radius: var(--radius-md);
    padding: 3px;
    margin-bottom: 12px;
}

.activity-tab {
    flex: 1;
    padding: 6px 8px;
    border: none;
    background: transparent;
    font-size: 12px;
    font-family: inherit;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: all var(--t-fast);
    white-space: nowrap;
}

.activity-tab.active {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.activity-input-area textarea {
    width: 100%;
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text-primary);
    resize: none;
    outline: none;
    transition: border-color var(--t-fast);
    min-height: 72px;
}

.activity-input-area textarea:focus { border-color: var(--brand-focus); }
.activity-input-area textarea::placeholder { color: var(--text-muted); }

.activity-input-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.activity-input-row input, .activity-input-row select {
    flex: 1;
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 7px 10px;
    font-size: 12.5px;
    font-family: inherit;
    color: var(--text-primary);
    outline: none;
}

.activity-form-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
}

/* Bitácora / timeline */
.activity-timeline {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.activity-item {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid #F8FAFC;
}

.activity-item:last-child { border-bottom: none; }

.act-icon-wrap {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
    margin-top: 1px;
}

.act-comment   { background: #EEF2FF; color: var(--act-comment-color); }
.act-call      { background: #E0F2FE; color: var(--act-call-color); }
.act-whatsapp  { background: #DCFCE7; color: var(--act-whatsapp-color); }
.act-email     { background: #FEF3C7; color: var(--act-email-color); }
.act-status_change { background: #F3E8FF; color: var(--act-status-color); }
.act-system    { background: #F1F5F9; color: var(--act-system-color); }

.act-body { flex: 1; min-width: 0; }

.act-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 3px;
}

.act-type {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
}

.act-time {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-left: auto;
}

.act-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 4px;
    flex-shrink: 0;
}

.act-content {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.act-tags {
    display: flex;
    gap: 4px;
    margin-top: 4px;
    flex-wrap: wrap;
}

.act-tag {
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 99px;
    background: var(--bg-page);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

/* ─── Drawer footer ─────────────────────────────────────────────────────── */

.drawer-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    background: #FAFBFC;
}

/* ─── Formularios ────────────────────────────────────────────────────────── */

.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.form-control {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    font-size: 13.5px;
    font-family: inherit;
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--t-fast);
}

.form-control:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(26,86,160,0.08); }
.form-control::placeholder { color: var(--text-muted); }

/* ─── Modal ─────────────────────────────────────────────────────────────── */

.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,25,35,0.45);
    z-index: 300;
    align-items: center;
    justify-content: center;
}

.modal-backdrop.open { display: flex; }

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 440px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 64px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-header h3 { font-size: 15px; font-weight: 600; flex: 1; }

.modal-body { padding: 20px; overflow-y: auto; }

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.permission-list {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-page);
    max-height: 220px;
    overflow-y: auto;
    padding: 6px;
}

.permission-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.permission-option:hover { background: var(--bg-card); }

.permission-option input {
    width: 16px;
    height: 16px;
    accent-color: var(--brand);
}

.permission-option span {
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-primary);
}

.user-access-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

/* ─── Alerts / toasts ────────────────────────────────────────────────────── */

.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--text-primary);
    color: #fff;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-size: 13px;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: all;
    animation: slideUp 0.2s ease;
    max-width: 320px;
}

.toast.success { background: #15803D; }
.toast.error   { background: #B91C1C; }
.toast.warning { background: #B45309; }

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

/* ─── Empty state ────────────────────────────────────────────────────────── */

.empty-state {
    padding: 48px 24px;
    text-align: center;
    color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }

.empty-state p { font-size: 14px; margin-top: 6px; }

/* ─── Loading skeleton ───────────────────────────────────────────────────── */

.skeleton {
    background: linear-gradient(90deg, #F1F5F9 25%, #E8EDF3 50%, #F1F5F9 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: var(--radius-sm);
}

@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ─── Utilities ─────────────────────────────────────────────────────────── */

.flex       { display: flex; }
.flex-1     { flex: 1; }
.items-center { align-items: center; }
.gap-2      { gap: 8px; }
.gap-3      { gap: 12px; }
.mt-1       { margin-top: 4px; }
.mt-2       { margin-top: 8px; }
.mt-4       { margin-top: 16px; }
.mb-4       { margin-bottom: 16px; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.text-sm    { font-size: 12.5px; }
.text-xs    { font-size: 11.5px; }
.truncate   { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Ghost fields — inline editing (lead-detail) ────────────────────────── */

.field-ghost {
    width: 100%;
    border: 1.5px solid transparent;
    border-radius: var(--radius-md);
    padding: 7px 10px;
    font-size: 13.5px;
    font-family: inherit;
    color: var(--text-primary);
    background: transparent;
    outline: none;
    transition: border-color var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
    cursor: default;
    resize: none;
}
.field-ghost:hover {
    border-color: var(--border);
    background: var(--bg-page);
    cursor: text;
}
.field-ghost:focus {
    border-color: var(--brand);
    background: var(--bg-card);
    box-shadow: 0 0 0 3px rgba(26,86,160,0.08);
    cursor: text;
}
.field-ghost::placeholder { color: var(--text-muted); }
select.field-ghost { cursor: pointer; appearance: auto; }
select.field-ghost:hover { cursor: pointer; }

.form-group-ghost {
    display: flex;
    flex-direction: column;
    gap: 0;
}
.form-group-ghost .form-label {
    padding: 0 10px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0;
}

/* Autosave indicator */
.autosave-bar {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--text-muted);
    min-height: 28px;
    transition: color var(--t-fast);
}
.autosave-bar.saving { color: var(--brand); }
.autosave-bar.saved  { color: #15803D; }
.autosave-bar.error  { color: #B91C1C; }
.autosave-bar .ph-circle-notch { animation: autosave-rotate 0.8s linear infinite; display: inline-block; }
@keyframes autosave-rotate { to { transform: rotate(360deg); } }

/* ─── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 150;
        transform: translateX(-100%);
        transition: transform var(--t-med), width var(--t-med);
    }

    .sidebar.open-mobile {
        transform: translateX(0);
    }

    .page-content { padding: 16px; }

    .page-header,
    .two-col-grid {
        display: block;
    }

    .two-col-grid > * + * {
        margin-top: 16px;
    }

    .drawer { width: 100vw; }

    .kpi-grid { grid-template-columns: repeat(2, 1fr); }

    .quick-actions { grid-template-columns: repeat(2, 1fr); }
}
