:root {
    --primary-50: #fef2f2;
    --primary-100: #fde3e2;
    --primary-200: #fbc9c7;
    --primary-500: #E8261E;
    --primary-600: #d01912;
    --primary-700: #b81c16;
    --primary-color: var(--primary-500);
    --primary-dark: var(--primary-700);
    --primary-tint: var(--primary-50);

    --secondary-color: #64748b;
    --secondary-tint: #f1f5f9;
    --success-color: #10b981;
    --success-tint: #ecfdf5;
    --danger-color: #ef4444;
    --danger-tint: #fef2f2;
    --warning-color: #f59e0b;
    --warning-tint: #fffbeb;
    --info-color: #0ea5e9;
    --info-tint: #f0f9ff;
    --indigo-color: #6366f1;
    --indigo-tint: #eef2ff;

    --bg-body: #f8fafc;
    --bg-sidebar: #ffffff;
    --bg-card: #ffffff;
    --bg-card-alt: #f1f5f9;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    --border-color: #e2e8f0;
    --border-color-strong: #cbd5e1;

    --shadow-xs: 0 1px 2px 0 rgb(16 24 40 / 0.05);
    --shadow-sm: 0 1px 3px 0 rgb(16 24 40 / 0.07), 0 1px 2px -1px rgb(16 24 40 / 0.06);
    --shadow-md: 0 6px 16px -4px rgb(16 24 40 / 0.09), 0 2px 6px -3px rgb(16 24 40 / 0.06);
    --shadow-lg: 0 20px 40px -12px rgb(16 24 40 / 0.16), 0 6px 12px -6px rgb(16 24 40 / 0.08);
    --shadow-brand: 0 12px 24px -10px rgb(232 38 30 / 0.45);

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', Menlo, Monaco, Consolas, monospace;
    --sidebar-width: 268px;
    --header-height: 72px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 26px;
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

.font-mono { font-family: var(--font-mono) !important; }

/* ---- Login ---- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #1e293b, #0f172a 65%, #020617);
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 42px 34px;
    border: 1px solid var(--border-color);
}

.login-card img.logo {
    display: block;
    max-width: 220px;
    margin: 0 auto 10px;
}

.login-subtitle {
    text-align: center;
    color: var(--text-secondary);
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-size: 0.76rem;
    margin-bottom: 28px;
}

.login-card label {
    display: block;
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.login-card input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-color-strong);
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 0.95rem;
    transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.login-card input:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px var(--primary-100);
}

.login-card button {
    width: 100%;
    padding: 13px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary-500);
    color: #fff;
    font-weight: 700;
    font-size: 0.98rem;
    cursor: pointer;
    box-shadow: var(--shadow-brand);
    transition: background 0.2s var(--ease), transform 0.15s var(--ease);
}

.login-card button:hover { background: var(--primary-600); transform: translateY(-1px); }

.messages { list-style: none; margin-bottom: 16px; }
.messages li {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: var(--danger-tint);
    color: var(--danger-color);
    font-size: 0.88rem;
    margin-bottom: 8px;
}

/* ---- App shell ---- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    border-bottom: 1px solid var(--border-color);
    padding: 0 20px;
    gap: 12px;
}

.sidebar-brand img { max-width: 150px; }

.brand-badge {
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: #f1f5f9;
    color: #475569;
    padding: 3px 7px;
    border-radius: 6px;
}

.sidebar-section-label {
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 20px 22px 6px;
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 12px 20px; }

.sidebar-nav a {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 14px;
    border-radius: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.88rem;
    margin-bottom: 4px;
    transition: all 0.18s var(--ease);
}

.sidebar-nav a .nav-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-nav a .nav-icon {
    width: 22px;
    flex-shrink: 0;
    text-align: center;
    font-size: 1.05rem;
    transition: color 0.15s var(--ease);
}

.icon-dashboard { color: #0284c7; }
.icon-cortes    { color: #16a34a; }
.icon-facturas  { color: #e11d48; }
.icon-globales  { color: #7c3aed; }

.sidebar-nav a:hover {
    background: #f1f5f9;
    color: var(--text-primary);
}

.sidebar-nav a.active {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    color: #fff;
    box-shadow: 0 6px 16px -4px rgba(15, 23, 42, 0.4);
}
.sidebar-nav a.active .nav-icon { color: #38bdf8; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    background: #fafbfc;
}
.sidebar-footer .user-info-box {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}
.sidebar-footer .user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #e2e8f0;
    color: #334155;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}
.sidebar-footer .user-meta { flex: 1; min-width: 0; }
.sidebar-footer .user-name { font-weight: 700; font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-primary); }
.sidebar-footer .user-sucursal { color: var(--text-muted); font-size: 0.75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer a.logout {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--danger-color);
    font-weight: 600;
    font-size: 0.82rem;
    transition: opacity 0.15s;
}
.sidebar-footer a.logout:hover { opacity: 0.8; }

.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 90;
}

.topbar .title-group h1 {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

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

.content { padding: 32px; flex: 1; }

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

/* ---- KPI Grid & Cards Ultra Pro ---- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 18px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-xs);
    padding: 18px 20px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.kpi-data { flex: 1; }
.kpi-label {
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.kpi-value {
    font-size: 1.45rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.2;
    font-family: var(--font-mono);
}
.kpi-subtext {
    font-size: 0.76rem;
    color: var(--text-secondary);
    margin-top: 5px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.kpi-icon-wrap {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.kpi-blue   { background: #e0f2fe; color: #0284c7; }
.kpi-green  { background: #dcfce7; color: #16a34a; }
.kpi-purple { background: #f3e8ff; color: #9333ea; }
.kpi-amber  { background: #fef3c7; color: #d97706; }
.kpi-rose   { background: #ffe4e6; color: #e11d48; }

/* ---- Quick Date Presets ---- */
.quick-date-group {
    display: inline-flex;
    background: #f1f5f9;
    padding: 3px;
    border-radius: var(--radius-sm);
    gap: 2px;
}

.btn-quick-date {
    border: none;
    background: transparent;
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s var(--ease);
}

.btn-quick-date:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.6);
}

.btn-quick-date.active {
    background: #ffffff;
    color: var(--text-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    font-weight: 700;
}

/* ---- Modern Search Bar ---- */
.search-bar-wrap {
    position: relative;
    width: 100%;
    max-width: 320px;
}

.search-bar-wrap input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    background: #ffffff;
    transition: all 0.2s var(--ease);
}

.search-bar-wrap input:focus {
    outline: none;
    border-color: #94a3b8;
    box-shadow: 0 0 0 3px #f1f5f9;
}

.search-bar-wrap .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.85rem;
    pointer-events: none;
}

/* ---- Status Badges ---- */
.badge-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 9px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;
}

.badge-success { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.badge-danger  { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }
.badge-warning { background: #fef3c7; color: #b45309; border: 1px solid #fde68a; }
.badge-info    { background: #e0f2fe; color: #0369a1; border: 1px solid #bae6fd; }
.badge-neutral { background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }
.badge-purple  { background: #f3e8ff; color: #7e22ce; border: 1px solid #e9d5ff; }

/* ---- Progress Bars for Data Tables ---- */
.participation-bar {
    width: 100%;
    height: 6px;
    background: #e2e8f0;
    border-radius: 9999px;
    overflow: hidden;
    margin-top: 4px;
}
.participation-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #6366f1);
    border-radius: 9999px;
}

/* ---- Toast Notifications ---- */
.toast-container-fixed {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 380px;
    pointer-events: none;
}

.toast-item {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 18px;
    background: #ffffff;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    font-size: 0.88rem;
    color: var(--text-primary);
}

.toast-icon { font-size: 1.15rem; flex-shrink: 0; margin-top: 2px; }
.toast-content { flex: 1; }
.toast-message { font-weight: 600; line-height: 1.4; }
.toast-close {
    border: none;
    background: transparent;
    font-size: 1.2rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    margin-left: 4px;
}
.toast-close:hover { color: var(--text-primary); }

.toast-success { border-left: 4px solid var(--success-color); }
.toast-success .toast-icon { color: var(--success-color); }
.toast-error   { border-left: 4px solid var(--danger-color); }
.toast-error .toast-icon   { color: var(--danger-color); }
.toast-warning { border-left: 4px solid var(--warning-color); }
.toast-warning .toast-icon { color: var(--warning-color); }
.toast-info    { border-left: 4px solid var(--info-color); }
.toast-info .toast-icon    { color: var(--info-color); }

.animate-slide-in {
    animation: toastSlideIn 0.28s var(--ease) forwards;
}
.animate-fade-out {
    animation: toastFadeOut 0.22s var(--ease) forwards;
}

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateX(40px) scale(0.95); }
    to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toastFadeOut {
    from { opacity: 1; transform: translateX(0) scale(1); }
    to { opacity: 0; transform: translateX(40px) scale(0.95); }
}

/* ---- Dynamic High-Performance Spinners ---- */
.fa-spin, .spin-infinite, .spinner-dynamic {
    display: inline-block !important;
    animation: faSpinInfinite 0.85s linear infinite !important;
    transform-origin: center center;
}

@keyframes faSpinInfinite {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ---- Table Wrappers & Styling ---- */
.table-wrap, .mf-table-wrap, .fg-table-wrap {
    position: relative;
    overflow-x: auto;
    width: 100%;
    background: #ffffff;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    scrollbar-width: thin;
    scrollbar-color: var(--border-color-strong) transparent;
    -webkit-overflow-scrolling: touch;
}
.table-wrap.has-overflow-right::after,
.mf-table-wrap.has-overflow-right::after,
.fg-table-wrap.has-overflow-right::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 8px;
    width: 32px;
    background: linear-gradient(to right, transparent, rgba(22, 32, 46, 0.08));
    pointer-events: none;
}
.table-wrap::-webkit-scrollbar, .mf-table-wrap::-webkit-scrollbar, .fg-table-wrap::-webkit-scrollbar {
    height: 7px;
}
.table-wrap::-webkit-scrollbar-track, .mf-table-wrap::-webkit-scrollbar-track, .fg-table-wrap::-webkit-scrollbar-track {
    background: #f1f5f9;
}
.table-wrap::-webkit-scrollbar-thumb, .mf-table-wrap::-webkit-scrollbar-thumb, .fg-table-wrap::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 6px;
}
.table-wrap::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

.truncate {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.truncate-sm {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.truncate-md {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

th.sortable-th {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 18px !important;
}
th.sortable-th::after {
    content: '\f0dc';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7em;
    opacity: 0.35;
}
th.sortable-th:hover::after { opacity: 0.7; }
th.sortable-th.sort-asc::after { content: '\f0de'; opacity: 0.9; }
th.sortable-th.sort-desc::after { content: '\f0dd'; opacity: 0.9; }
