/* ============ SIDEBAR LATERAL FINANCIERO ============ */
:root {
    --sidebar-bg: #0f172a;
    --sidebar-bg-alt: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-text-muted: #94a3b8;
    --sidebar-active: #2563eb;
    --sidebar-active-glow: rgba(37, 99, 235, 0.3);
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg-app: #f3f6fb;
    --card: #ffffff;
    --border-soft: #e5e7eb;
}
html.dark {
    --bg-app: #0f172a;
    --card: #1e293b;
    --border-soft: #334155;
    --sidebar-bg: #020617;
    --sidebar-bg-alt: #0f172a;
}

body {
    background: var(--bg-app) !important;
}

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

/* SIDEBAR */
.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease;
    overflow-y: scroll;
}
@media (max-width: 1023px) {
    .sidebar { transform: translateX(-100%); }
    body.sidebar-mobile-open .sidebar { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,0.5); }
}



.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 18px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: #fff;
}
.sidebar-brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 8px 20px rgba(37,99,235,0.35);
}
.sidebar-brand-text {
    font-weight: 800;
    font-size: 16px;
    color: #fff;
    white-space: nowrap;
}
.sidebar-close {
    background: transparent;
    border: 0;
    color: var(--sidebar-text-muted);
    cursor: pointer;
}

.sidebar-nav {
    padding: 10px 14px 30px;
    flex: 1;
}
.sidebar-section {
    margin: 18px 6px 6px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--sidebar-text-muted);
    letter-spacing: 0.08em;
}
.sidebar-section:first-child { margin-top: 6px; }
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    margin-bottom: 2px;
    border-radius: 10px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
}
.sidebar-link svg { flex-shrink: 0; opacity: 0.85; }
.sidebar-link:hover {
    background: var(--sidebar-bg-alt);
    color: #fff;
}
.sidebar-link.active {
    background: linear-gradient(135deg, var(--sidebar-active), var(--primary-dark));
    color: #fff;
    box-shadow: 0 6px 18px var(--sidebar-active-glow);
}
.sidebar-link.active svg { opacity: 1; }

/* TOPBAR */
.topbar {
    height: 64px;
    background: var(--card);
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 30;
    gap: 16px;
    box-shadow: 0 1px 3px rgba(15,23,42,0.04);
}
.topbar-menu-btn {
    background: transparent;
    border: 0;
    cursor: pointer;
    color: #475569;
    padding: 8px;
    border-radius: 8px;
}
.topbar-menu-btn:hover { background: #f1f5f9; }
.topbar-search {
    flex: 1;
    max-width: 480px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    background: #f1f5f9;
    border-radius: 999px;
    height: 40px;
}
html.dark .topbar-search { background: #0f172a; }
.topbar-search-input {
    flex: 1;
    border: 0;
    background: transparent;
    outline: none;
    font-size: 14px;
    color: inherit;
}
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.topbar-icon-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    color: #475569;
    background: transparent;
    border: 0;
    cursor: pointer;
    text-decoration: none;
}
html.dark .topbar-icon-btn { color: #cbd5e1; }
.topbar-icon-btn:hover { background: #f1f5f9; }
html.dark .topbar-icon-btn:hover { background: #1e293b; }

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px 6px 6px;
    background: #f8fafc;
    border-radius: 999px;
}
html.dark .topbar-user { background: #0f172a; }
.topbar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 13px;
}
.topbar-user-info { line-height: 1.2; }
.topbar-user-name { font-size: 13px; font-weight: 700; color: #1f2937; }
html.dark .topbar-user-name { color: #f1f5f9; }
.topbar-user-role { font-size: 10px; color: #94a3b8; text-transform: uppercase; }

/* MAIN CONTENT */
.app-main {
    flex: 1;
    margin-left: 250px;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
@media (max-width: 1023px) {
    .app-main { margin-left: 0; }
}

.modern-page-header {
    padding: 22px 28px;
    background: var(--card);
    border-bottom: 1px solid var(--border-soft);
}

/* ============ TABLAS UNIFORMES MODERNAS ============ */
.modern-page {
    padding: 28px 32px;
}
@media (max-width: 640px) {
    .modern-page { padding: 16px; }
}

.kontab-table {
    width: 100%;
    border-collapse: collapse;
}
.kontab-table thead {
    background: #f8fafc;
}
html.dark .kontab-table thead { background: #0f172a; }
.kontab-table th {
    text-align: left;
    padding: 12px 16px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: #64748b;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--border-soft);
}
html.dark .kontab-table th { color: #94a3b8; }
.kontab-table td {
    padding: 14px 16px;
    font-size: 14px;
    border-top: 1px solid var(--border-soft);
    color: #1f2937;
}
html.dark .kontab-table td { color: #e5e7eb; }
.kontab-table tbody tr:hover {
    background: #f8fbff;
}
html.dark .kontab-table tbody tr:hover { background: #1e293b; }

.kontab-card {
    background: var(--card);
    border-radius: 16px;
    border: 1px solid var(--border-soft);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
    overflow: hidden;
}
.kontab-card-header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.kontab-card-header h2 {
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
}
html.dark .kontab-card-header h2 { color: #f1f5f9; }

/* ============ BOTONES UNIFICADOS ============ */
.k-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 38px;
    padding: 0 16px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
    white-space: nowrap;
}
.k-btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}
.k-btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.k-btn-secondary {
    background: #fff;
    color: #475569;
    border-color: #d1d5db;
}
html.dark .k-btn-secondary { background: #1e293b; color: #cbd5e1; border-color: #334155; }
.k-btn-secondary:hover { background: #f8fafc; }
html.dark .k-btn-secondary:hover { background: #0f172a; }

.k-btn-success { background: #10b981; color: #fff; border-color: #10b981; }
.k-btn-success:hover { background: #059669; }
.k-btn-danger { background: #ef4444; color: #fff; border-color: #ef4444; }
.k-btn-danger:hover { background: #dc2626; }
.k-btn-warning { background: #f59e0b; color: #fff; border-color: #f59e0b; }
.k-btn-warning:hover { background: #d97706; }
.k-btn-ghost { background: transparent; color: var(--primary); border-color: transparent; }
.k-btn-ghost:hover { background: rgba(37, 99, 235, 0.08); }
.k-btn-sm { height: 32px; padding: 0 12px; font-size: 12px; }
.k-btn-lg { height: 46px; padding: 0 22px; font-size: 15px; }

/* ============ BADGES UNIFORMES ============ */
.k-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.k-badge-success { background: #d1fae5; color: #065f46; }
.k-badge-danger  { background: #fee2e2; color: #991b1b; }
.k-badge-warning { background: #fef3c7; color: #92400e; }
.k-badge-info    { background: #dbeafe; color: #1e40af; }
.k-badge-neutral { background: #f1f5f9; color: #475569; }
html.dark .k-badge-success { background: rgba(16,185,129,0.18); color: #6ee7b7; }
html.dark .k-badge-danger  { background: rgba(239,68,68,0.18);  color: #fca5a5; }
html.dark .k-badge-warning { background: rgba(245,158,11,0.18); color: #fcd34d; }
html.dark .k-badge-info    { background: rgba(37,99,235,0.18);  color: #93c5fd; }
html.dark .k-badge-neutral { background: rgba(100,116,139,0.18);color: #cbd5e1; }

/* KPI cards modernos */
.k-kpi {
    background: var(--card);
    border: 1px solid var(--border-soft);
    border-radius: 16px;
    padding: 18px;
    transition: all 0.15s ease;
}
.k-kpi:hover { box-shadow: 0 12px 30px rgba(15,23,42,0.08); transform: translateY(-2px); }
.k-kpi-label {
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 0 0 8px;
}
.k-kpi-value {
    font-size: 28px;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}
html.dark .k-kpi-value { color: #f8fafc; }
.k-kpi-sub {
    margin-top: 6px;
    font-size: 12px;
    color: #64748b;
}
.k-kpi-delta {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-top: 8px;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
}
.k-kpi-delta-up   { background: #d1fae5; color: #065f46; }
.k-kpi-delta-down { background: #fee2e2; color: #991b1b; }
.k-kpi-delta-neutral { background: #f1f5f9; color: #64748b; }

/* Filtros */
.k-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 16px 22px;
    border-bottom: 1px solid var(--border-soft);
    background: #fafbfc;
}
html.dark .k-filters { background: #0f172a; }
.k-input, .k-select {
    height: 38px;
    padding: 0 12px;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    font-size: 13px;
    color: #1f2937;
    background: #fff;
    outline: none;
}
html.dark .k-input, html.dark .k-select { background: #1e293b; color: #f1f5f9; border-color: #334155; }
.k-input:focus, .k-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }

/* ============ K-KPI VARIANTES CON GRADIENT ============ */
.k-kpi-blue {
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: #fff;
    border: 0;
    box-shadow: 0 8px 20px rgba(59,130,246,0.25);
}
.k-kpi-emerald {
    background: linear-gradient(135deg, #10b981, #047857);
    color: #fff;
    border: 0;
    box-shadow: 0 8px 20px rgba(16,185,129,0.25);
}
.k-kpi-rose {
    background: linear-gradient(135deg, #f43f5e, #be123c);
    color: #fff;
    border: 0;
    box-shadow: 0 8px 20px rgba(244,63,94,0.25);
}
.k-kpi-purple {
    background: linear-gradient(135deg, #a855f7, #6d28d9);
    color: #fff;
    border: 0;
    box-shadow: 0 8px 20px rgba(168,85,247,0.25);
}
.k-kpi-amber {
    background: linear-gradient(135deg, #f59e0b, #b45309);
    color: #fff;
    border: 0;
    box-shadow: 0 8px 20px rgba(245,158,11,0.25);
}
.k-kpi-cyan {
    background: linear-gradient(135deg, #06b6d4, #0e7490);
    color: #fff;
    border: 0;
    box-shadow: 0 8px 20px rgba(6,182,212,0.25);
}
.k-kpi-pink {
    background: linear-gradient(135deg, #ec4899, #be185d);
    color: #fff;
    border: 0;
    box-shadow: 0 8px 20px rgba(236,72,153,0.25);
}
.k-kpi-slate {
    background: linear-gradient(135deg, #64748b, #334155);
    color: #fff;
    border: 0;
    box-shadow: 0 8px 20px rgba(100,116,139,0.25);
}

/* Reset internal text colors cuando k-kpi tiene variant */
.k-kpi-blue .k-kpi-label,
.k-kpi-emerald .k-kpi-label,
.k-kpi-rose .k-kpi-label,
.k-kpi-purple .k-kpi-label,
.k-kpi-amber .k-kpi-label,
.k-kpi-cyan .k-kpi-label,
.k-kpi-pink .k-kpi-label,
.k-kpi-slate .k-kpi-label { color: rgba(255,255,255,0.85); }

.k-kpi-blue .k-kpi-value,
.k-kpi-emerald .k-kpi-value,
.k-kpi-rose .k-kpi-value,
.k-kpi-purple .k-kpi-value,
.k-kpi-amber .k-kpi-value,
.k-kpi-cyan .k-kpi-value,
.k-kpi-pink .k-kpi-value,
.k-kpi-slate .k-kpi-value { color: #fff !important; }

.k-kpi-blue .k-kpi-sub,
.k-kpi-emerald .k-kpi-sub,
.k-kpi-rose .k-kpi-sub,
.k-kpi-purple .k-kpi-sub,
.k-kpi-amber .k-kpi-sub,
.k-kpi-cyan .k-kpi-sub,
.k-kpi-pink .k-kpi-sub,
.k-kpi-slate .k-kpi-sub { color: rgba(255,255,255,0.85); }


/* sidebar-scrollbar-visible: barra siempre visible para bajar/subir */
.sidebar { scrollbar-width: thin; scrollbar-color: rgba(148,163,184,0.85) rgba(255,255,255,0.08); }
.sidebar::-webkit-scrollbar { width: 14px; }
.sidebar::-webkit-scrollbar-track { background: rgba(255,255,255,0.15); }
.sidebar::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; min-height: 40px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: rgba(203,213,225,1); }
