/* ============================================
   BASE.CSS — Variables, reset, layout, typography
   Dashboard Clientes — Acelera tu CRM
   ============================================ */

/* --- CSS Variables (overridden per client via config) --- */
:root {
    /* Brand colors - defaults, overridden by client config */
    --color-primary: #146BFF;
    --color-primary-rgb: 20, 107, 255;
    --color-secondary: #8b5cf6;
    --color-accent: #FF8A00;

    /* Background layers */
    --bg-body: #0a0b0e;
    --bg-sidebar: rgba(14, 14, 18, 0.92);
    --bg-card: rgba(18, 18, 22, 0.85);
    --bg-card-hover: rgba(24, 24, 30, 0.9);
    --bg-input: rgba(20, 20, 25, 0.9);
    --bg-overlay: rgba(0, 0, 0, 0.65);

    /* Borders */
    --border-color: rgba(255, 255, 255, 0.06);
    --border-color-hover: rgba(255, 255, 255, 0.12);

    /* Text */
    --text-primary: #f1f3f5;
    --text-secondary: #8b8fa3;
    --text-muted: #555770;
    --text-inverse: #06070b;

    /* Semantic */
    --color-success: #10b981;
    --color-success-bg: rgba(16, 185, 129, 0.1);
    --color-danger: #ef4444;
    --color-danger-bg: rgba(239, 68, 68, 0.1);
    --color-warning: #f59e0b;
    --color-warning-bg: rgba(245, 158, 11, 0.1);
    --color-info: #3b82f6;
    --color-info-bg: rgba(59, 130, 246, 0.1);

    /* Chart palette */
    --chart-1: #146BFF;
    --chart-2: #FF8A00;
    --chart-3: #10b981;
    --chart-4: #8b5cf6;
    --chart-5: #ef4444;
    --chart-6: #06b6d4;
    --chart-7: #ec4899;
    --chart-8: #84cc16;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Layout */
    --sidebar-width: 260px;
    --sidebar-collapsed: 0px;
    --top-bar-height: 64px;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --border-radius-xs: 6px;

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-size-xs: 0.7rem;
    --font-size-sm: 0.8rem;
    --font-size-base: 0.875rem;
    --font-size-md: 1rem;
    --font-size-lg: 1.25rem;
    --font-size-xl: 1.5rem;
    --font-size-2xl: 2rem;
    --font-size-3xl: 2.5rem;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 400ms ease;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
    --shadow-glow: 0 0 20px rgba(var(--color-primary-rgb), 0.15);
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.5;
    overflow-x: hidden;
    min-height: 100vh;
    position: relative;
}

/* --- Circuit Lines Background (from aceleratucrm.com) --- */
.bg-circuit {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
    overflow: hidden;
}

@keyframes spark-flow {
    0% { stroke-dashoffset: -100; }
    100% { stroke-dashoffset: 100; }
}

.spark-line {
    stroke: #146BFF;
    stroke-width: 1;
    opacity: 0.05;
    fill: none;
    vector-effect: non-scaling-stroke;
}

.spark-dot, .spark-trail-1, .spark-trail-2, .spark-trail-3 {
    fill: none;
    vector-effect: non-scaling-stroke;
    animation: spark-flow var(--dur) linear infinite;
    animation-delay: var(--del);
    stroke-linecap: round;
}

.spark-dot {
    stroke: #146BFF;
    stroke-width: 3;
    stroke-dasharray: 0.1 200;
    opacity: 0.6;
    filter: url(#spark-glow);
}

.spark-trail-1 {
    stroke: #146BFF;
    stroke-width: 1.5;
    stroke-dasharray: 1 200;
    opacity: 0.4;
}

.spark-trail-2 {
    stroke: #146BFF;
    stroke-width: 1;
    stroke-dasharray: 2.5 200;
    opacity: 0.2;
}

.spark-trail-3 {
    stroke: #146BFF;
    stroke-width: 1;
    stroke-dasharray: 5 200;
    opacity: 0.1;
}

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

img { max-width: 100%; height: auto; }

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color-hover); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* --- Loading Overlay --- */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-body);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity var(--transition-slow);
}

.loading-overlay .loading-spinner {
    z-index: 1;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-text {
    margin-top: var(--space-md);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- App Layout --- */
.app-layout {
    display: flex;
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--transition-base);
    overflow-y: auto;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.sidebar-header {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    min-height: 72px;
}

.client-logo {
    width: 36px;
    height: 36px;
    border-radius: var(--border-radius-xs);
    object-fit: contain;
}

.client-logo-fallback {
    width: 36px;
    height: 36px;
    border-radius: var(--border-radius-xs);
    background: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.client-name {
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Sidebar Brand (Acelera tu CRM) --- */
.sidebar-brand {
    padding: 0 var(--space-lg) var(--space-md);
    border-bottom: 1px solid var(--border-color);
}

.brand-logo {
    width: 130px;
    height: 20px;
    opacity: 0.7;
    transition: opacity var(--transition-fast);
}

.brand-logo:hover {
    opacity: 1;
}

/* --- Sidebar Navigation --- */
.sidebar-nav {
    flex: 1;
    padding: var(--space-md) 0;
}

.nav-group {
    margin-bottom: var(--space-sm);
}

.nav-group-label {
    padding: var(--space-sm) var(--space-lg);
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    margin: 1px var(--space-sm);
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(var(--color-primary-rgb), 0.1);
    color: var(--color-primary);
}

.nav-item .nav-icon {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.nav-item.active .nav-icon {
    color: var(--color-primary);
}

.nav-item .nav-icon svg {
    width: 18px;
    height: 18px;
}

.nav-item.sub-item {
    padding-left: calc(var(--space-lg) + 28px);
    font-size: var(--font-size-xs);
}

/* --- Sidebar Footer --- */
.sidebar-footer {
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-color);
}

.powered-by {
    font-size: var(--font-size-base);
    color: var(--text-secondary);
    text-align: center;
    padding: var(--space-md) 0;
}

.powered-by strong {
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* --- Content Footer Branding --- */
.content-footer-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-xl) 0 var(--space-md);
    margin-top: var(--space-xl);
    border-top: 1px solid var(--border-color);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.content-footer-brand strong {
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: var(--font-size-base);
}

/* --- Top Bar Branding --- */
.top-bar-brand {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    white-space: nowrap;
}

.top-bar-brand strong {
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* --- Mobile Menu Toggle --- */
.menu-toggle {
    display: none;
    position: fixed;
    top: var(--space-md);
    left: var(--space-md);
    z-index: 200;
    width: 40px;
    height: 40px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.menu-toggle span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text-secondary);
    border-radius: 1px;
    transition: all var(--transition-fast);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    z-index: 90;
}

/* --- Main Content --- */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- Top Bar --- */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-xl);
    min-height: var(--top-bar-height);
    background: rgba(10, 11, 14, 0.75);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
}

.top-bar-left {
    display: flex;
    align-items: baseline;
    gap: var(--space-md);
    flex-shrink: 0;
}

.section-title {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--text-primary);
}

.date-range-label {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: wrap;
    justify-content: flex-end;
}

.filters-bar {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

/* --- Content Area --- */
.content {
    flex: 1;
    padding: var(--space-xl);
    transition: opacity 150ms ease, transform 150ms ease;
}

/* --- Section Transitions --- */
.content.section-exit {
    opacity: 0;
    transform: translateY(6px);
}

.content.section-enter {
    opacity: 0;
    transform: translateY(-6px);
    animation: section-fade-in 200ms ease forwards;
}

@keyframes section-fade-in {
    to { opacity: 1; transform: translateY(0); }
}

/* --- Skeleton Loading --- */
@keyframes shimmer {
    0% { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}

.skeleton-card {
    pointer-events: none;
}

.skeleton-line {
    height: 14px;
    border-radius: 4px;
    background: linear-gradient(90deg, rgba(255,255,255,0.04) 25%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.04) 75%);
    background-size: 400px 100%;
    animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton-line.skeleton-sm { width: 60%; margin-bottom: var(--space-sm); }
.skeleton-line.skeleton-lg { width: 40%; height: 28px; }

.skeleton-block {
    height: 200px;
    border-radius: var(--border-radius-sm);
    background: linear-gradient(90deg, rgba(255,255,255,0.04) 25%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.04) 75%);
    background-size: 400px 100%;
    animation: shimmer 1.5s ease-in-out infinite;
}

/* --- Data Freshness --- */
.data-freshness {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    white-space: nowrap;
}

/* --- Count-up Animation --- */
@keyframes count-pop {
    0% { transform: scale(0.8); opacity: 0; }
    60% { transform: scale(1.05); }
    100% { transform: scale(1); opacity: 1; }
}

.scorecard-value.count-up {
    animation: count-pop 400ms ease-out forwards;
}
