/* ═══ FONTS ═══ */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,400;0,500;0,600;0,700;0,800;1,400&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ═══ VARIABLES — DARK ═══ */
:root {
    --bg:           #0d1117;
    --bg-card:      #161c27;
    --bg-card2:     #1c2333;
    --bg-input:     #1a2030;
    --bg-hover:     #1e2540;
    --border:       #242d40;
    --border-mid:   #2e3a55;
    --text:         #e8ecf4;
    --text-sub:     #7e8ea8;
    --text-dim:     #4a5568;
    --accent:       #3b82f6;
    --accent-light: #1e3a6e;
    --accent-glow:  rgba(59,130,246,0.12);
    --green:        #10b981;
    --green-bg:     #0a2520;
    --red:          #f43f5e;
    --red-bg:       #2d0f18;
    --yellow:       #f59e0b;
    --yellow-bg:    #2a1d08;
    --blue:         #3b82f6;
    --blue-bg:      #0d1f3c;
    --purple:       #a78bfa;
    --sidebar-w:    250px;
    --topbar-h:     56px;
    --radius:       12px;
    --radius-sm:    8px;
    --shadow:       0 4px 24px rgba(0,0,0,0.35);
    --shadow-sm:    0 2px 8px rgba(0,0,0,0.2);
    --overlay-bg:   rgba(0,0,0,0.6);
    --transition:   0.25s cubic-bezier(0.4,0,0.2,1);
}

[data-theme="light"] {
    --bg:           #f0f4fa;
    --bg-card:      #ffffff;
    --bg-card2:     #f7f9fd;
    --bg-input:     #f2f4f9;
    --bg-hover:     #eaeff8;
    --border:       #dde3ef;
    --border-mid:   #c8d0e4;
    --text:         #0f172a;
    --text-sub:     #556080;
    --text-dim:     #94a3b8;
    --accent:       #2563eb;
    --accent-light: #dbeafe;
    --accent-glow:  rgba(37,99,235,0.08);
    --green:        #059669;
    --green-bg:     #ecfdf5;
    --red:          #e11d48;
    --red-bg:       #fff1f2;
    --yellow:       #d97706;
    --yellow-bg:    #fffbeb;
    --blue:         #2563eb;
    --blue-bg:      #eff6ff;
    --purple:       #7c3aed;
    --shadow:       0 4px 24px rgba(0,0,0,0.08);
    --shadow-sm:    0 2px 8px rgba(0,0,0,0.05);
    --overlay-bg:   rgba(15,23,42,0.5);
}

/* ═══ RESET ═══ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ═══ TOPBAR (mobile) ═══ */
#topbar {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    z-index: 200;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
}

#topbar .topbar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

#topbar .logo-title { font-size: 15px; font-weight: 800; }
#topbar .logo-sub   { font-size: 10px; color: var(--text-dim); }

#hamburger {
    width: 38px; height: 38px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-sub);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    transition: all 0.15s;
}
#hamburger:hover { background: var(--bg-hover); color: var(--text); }

/* ═══ OVERLAY ═══ */
#sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    z-index: 299;
    opacity: 0;
    transition: opacity var(--transition);
    backdrop-filter: blur(2px);
}
#sidebar-overlay.visible {
    display: block;
    opacity: 1;
}

/* ═══ LAYOUT ═══ */
#app { display: flex; min-height: 100vh; }

#sidebar {
    width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 300;
    transition: transform var(--transition);
}

#content {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 32px 36px 60px;
    min-height: 100vh;
    transition: margin var(--transition);
}

/* ═══ SIDEBAR ═══ */
.sidebar-header {
    padding: 20px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; font-weight: 800; color: #fff;
    box-shadow: 0 4px 14px rgba(59,130,246,0.4);
    flex-shrink: 0;
}

.logo-title { font-size: 15px; font-weight: 800; color: var(--text); line-height: 1.2; }
.logo-sub   { font-size: 10px; color: var(--text-dim); font-weight: 500; text-transform: uppercase; letter-spacing: 0.8px; }

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-nav-label {
    padding: 14px 10px 5px;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-dim);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-sub);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.15s;
    border: 1px solid transparent;
    cursor: pointer;
}

.nav-item:hover  { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent-glow); color: var(--accent); border-color: var(--accent-light); }

.nav-icon { font-size: 17px; width: 22px; text-align: center; flex-shrink: 0; }

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-footer button {
    width: 100%;
    padding: 9px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-sub);
    cursor: pointer;
    font-size: 12px;
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 600;
    transition: all 0.15s;
}
.sidebar-footer button:hover { background: var(--bg-hover); color: var(--text); }

/* ═══ SECTIONS ═══ */
.section { display: none; }
.section.active { display: block; }

/* ═══ PAGE HEADER ═══ */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-title    { font-size: 24px; font-weight: 800; line-height: 1.2; }
.page-subtitle { font-size: 13px; color: var(--text-sub); margin-top: 3px; font-weight: 500; }

/* ═══ KPIs ═══ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.kpi {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 22px 18px;
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.2s, border-color 0.2s, transform 0.15s;
    cursor: default;
}
.kpi:hover { box-shadow: var(--shadow); border-color: var(--border-mid); transform: translateY(-1px); }

.kpi-icon {
    width: 40px; height: 40px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    margin-bottom: 14px;
}

.kpi-label {
    font-size: 11px;
    color: var(--text-sub);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 6px;
}

.kpi-value {
    font-size: 24px;
    font-weight: 800;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: -1px;
    line-height: 1;
}

.kpi-sub {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 7px;
    font-weight: 500;
}

.kpi-bar {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 3px;
}

/* ═══ CARDS ═══ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    font-weight: 700;
    gap: 12px;
    flex-wrap: wrap;
}

.card-body { padding: 20px; }

/* ═══ TABLES ═══ */
.data-table { width: 100%; border-collapse: collapse; }

.data-table thead { background: var(--bg-card2); }

.data-table th {
    text-align: left;
    padding: 11px 16px;
    font-size: 10px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table th.right { text-align: right; }

.data-table td {
    padding: 13px 16px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover          { background: var(--bg-hover); }
.data-table td.right { text-align: right; }
.data-table td.mono  { font-family: 'JetBrains Mono', monospace; font-size: 12px; }

/* ═══ CLIENT AVATAR ═══ */
.cl-avatar {
    width: 34px; height: 34px;
    border-radius: 8px;
    background: var(--accent-glow);
    border: 1px solid var(--accent-light);
    color: var(--accent);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 800;
    flex-shrink: 0;
    text-transform: uppercase;
}

/* ═══ BADGES ═══ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}
.badge-green  { background: var(--green-bg);  color: var(--green);  }
.badge-red    { background: var(--red-bg);    color: var(--red);    }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-blue   { background: var(--blue-bg);   color: var(--blue);   }

/* ═══ ALERTS ═══ */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    font-size: 13px;
    font-weight: 600;
    border: 1px solid;
    transition: opacity 0.15s, transform 0.15s;
}
.alert:hover { opacity: 0.88; transform: translateX(2px); }
.alert-danger  { background: var(--red-bg);    color: var(--red);    border-color: #5a1a26; cursor: pointer; }
.alert-warning { background: var(--yellow-bg); color: var(--yellow); border-color: #5a3a10; }
.alert-success { background: var(--green-bg);  color: var(--green);  border-color: #0d4a30; }
.alert-info    { background: var(--blue-bg);   color: var(--blue);   border-color: #1a3a6a; }

/* ═══ FORMS ═══ */
.input, select, textarea {
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text);
    font-size: 13px;
    font-family: 'Plus Jakarta Sans', sans-serif;
    outline: none;
    width: 100%;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.input-mono { font-family: 'JetBrains Mono', monospace; text-align: right; }
.input-xs   { padding: 4px 8px; font-size: 11px; border-radius: 5px; width: auto; }

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%235b6478' d='M5 6L0 0h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

.form-label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-sub);
    margin-bottom: 5px;
}
.form-group { margin-bottom: 14px; }

/* ═══ BUTTONS ═══ */
.btn {
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-sub);
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    font-family: 'Plus Jakarta Sans', sans-serif;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-mid); }

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 4px 12px rgba(59,130,246,0.3);
}
.btn-primary:hover { background: #2563eb; box-shadow: 0 6px 18px rgba(59,130,246,0.4); color: #fff; }

.btn-accent {
    background: var(--accent-glow);
    color: var(--accent);
    border-color: var(--accent-light);
}
.btn-accent:hover { background: var(--accent); color: #fff; }

.btn-danger { background: var(--red-bg); color: var(--red); border-color: #5a1a26; }
.btn-danger:hover { background: var(--red); color: #fff; }

.btn-sm    { padding: 5px 12px; font-size: 11px; }
.btn-block { width: 100%; justify-content: center; }
.btn-lg    { padding: 13px 24px; font-size: 14px; border-radius: var(--radius); }

/* ═══ SEARCH ═══ */
.search-box { position: relative; margin-bottom: 16px; }
.search-box input {
    padding: 11px 16px 11px 42px;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    font-size: 13px;
    font-weight: 500;
}
.search-box::before {
    content: '🔍';
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    pointer-events: none;
}

/* ═══ LOADING ═══ */
.spinner {
    display: inline-block;
    width: 18px; height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 40px;
    color: var(--text-sub);
    font-size: 13px;
    gap: 12px;
    font-weight: 600;
}

/* ═══ GRID & FLEX UTILS ═══ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.flex   { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-12  { margin-top: 12px; }
.mb-12  { margin-bottom: 12px; }
.mb-16  { margin-bottom: 16px; }
.ml-8   { margin-left: 8px; }

/* ═══ TEXT UTILS ═══ */
.c-green  { color: var(--green); }
.c-red    { color: var(--red); }
.c-yellow { color: var(--yellow); }
.c-blue   { color: var(--blue); }
.c-purple { color: var(--purple); }
.c-accent { color: var(--accent); }
.c-muted  { color: var(--text-sub); }
.c-dim    { color: var(--text-dim); }
.fw-700   { font-weight: 700; }
.fw-800   { font-weight: 800; }
.fs-mono  { font-family: 'JetBrains Mono', monospace; }
.fs-11    { font-size: 11px; }
.fs-12    { font-size: 12px; }
.fs-14    { font-size: 14px; }
.fs-18    { font-size: 18px; }
.fs-22    { font-size: 22px; }
.right    { text-align: right; }
.cursor-pointer { cursor: pointer; }

/* ═══ SCROLLBAR ═══ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ═══ DIVIDER ═══ */
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* ═══ EMPTY STATE ═══ */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 600;
}
.empty-state .empty-icon { font-size: 32px; margin-bottom: 10px; opacity: 0.5; }

/* ═══ RESPONSIVE ═══ */
@media (max-width: 900px) {
    #topbar { display: flex; }

    #sidebar {
        transform: translateX(-100%);
        top: 0;
        box-shadow: var(--shadow);
    }
    #sidebar.open { transform: translateX(0); }

    #content {
        margin-left: 0;
        padding: 16px 16px 60px;
        margin-top: var(--topbar-h);
    }

    .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .grid-2   { grid-template-columns: 1fr; }
    .grid-3   { grid-template-columns: 1fr; }
    .dash-pies { grid-template-columns: 1fr !important; }
    .page-title { font-size: 20px; }
}

@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .kpi-value { font-size: 18px; }
    #content { padding: 12px 12px 60px; }
    .data-table th, .data-table td { padding: 10px 10px; }
    .pie-layout { flex-direction: column !important; align-items: flex-start !important; }
}

/* ═══ DASHBOARD v2: PIE CHARTS ═══ */
.dash-pies {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.pie-layout {
    display: flex;
    align-items: center;
    gap: 16px;
}

.pie-layout canvas {
    flex-shrink: 0;
}

.pie-legend {
    flex: 1;
}

.pie-leg-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    margin-bottom: 6px;
    padding: 3px 4px;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
}
.pie-leg-item:hover { background: var(--bg-hover); }

.pie-dot {
    width: 10px; height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

.pie-lbl {
    color: var(--text-sub);
    flex: 1;
}

.pie-val {
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
}

/* ═══ DASHBOARD v2: AGING BARS ═══ */
.aging-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    padding: 4px 6px;
    transition: background 0.15s;
}
.aging-bar:hover { background: var(--bg-hover); }

.aging-label {
    font-size: 12px;
    width: 80px;
    flex-shrink: 0;
    color: var(--text-sub);
    font-weight: 600;
}

.aging-track {
    flex: 1;
    height: 24px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.aging-fill {
    height: 100%;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    padding-left: 8px;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    min-width: 32px;
    transition: width 0.5s ease;
}

.aging-amount {
    font-size: 13px;
    font-weight: 700;
    width: 100px;
    text-align: right;
    flex-shrink: 0;
    font-family: 'JetBrains Mono', monospace;
}

/* ═══ DASHBOARD v2: VISIT ROWS ═══ */
.visit-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 4px;
    border-bottom: 1px solid var(--border);
}
.visit-row:last-child { border-bottom: none; }

.visit-info {
    flex: 1;
    min-width: 0;
}
.visit-info > div {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cobr-circle {
    width: 30px; height: 30px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700;
    flex-shrink: 0;
}
.cobr-fa    { background: var(--blue-bg);  color: var(--blue); }
.cobr-to    { background: var(--green-bg); color: var(--green); }
.cobr-other { background: var(--yellow-bg);color: var(--yellow); }

/* ═══ DASHBOARD v2: RENDICIONES + SUSPENDER ROWS ═══ */
.rend-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
}
.rend-row:last-child { border-bottom: none; }

.susp-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
    border-radius: var(--radius-sm);
    padding-left: 4px;
    padding-right: 4px;
}
.susp-row:last-child { border-bottom: none; }
.susp-row:hover { background: var(--bg-hover); }