:root {
    --bg: #131317;
    --bg2: #15151a;
    --card: #1e1e24;
    --card2: #25252b;
    --border: #2c2c35;
    --green: #1db954;
    --green2: #34c759;
    --orange: #ff9500;
    --red: #ff453a;
    --red2: #ff3b30;
    --purple: #bf5af2;
    --blue: #007aff;
    --text: #ffffff;
    --sub: #a1a1aa;
    --muted: #8e8e93;
    --active-bg: rgba(29, 185, 84, 0.15);
}

[data-theme="light"] {
    --bg: #f4f4f7;
    --bg2: #ffffff;
    --card: #ffffff;
    --card2: #eef0f3;
    --border: #e2e8f0;
    --green: #1db954;
    --green2: #34c759;
    --orange: #ff9500;
    --red: #ff3b30;
    --red2: #e53e3e;
    --purple: #af52de;
    --blue: #007aff;
    --text: #1a202c;
    --sub: #4a5568;
    --muted: #718096;
    --active-bg: rgba(29, 185, 84, 0.1);
}

[data-theme="blue"] {
    --bg: #0b0f19;
    --bg2: #0e1424;
    --card: #172033;
    --card2: #1e2942;
    --border: #24324f;
    --green: #38bdf8;
    --green2: #0284c7;
    --orange: #f59e0b;
    --red: #ef4444;
    --red2: #dc2626;
    --purple: #a855f7;
    --blue: #3b82f6;
    --text: #f8fafc;
    --sub: #94a3b8;
    --muted: #64748b;
    --active-bg: rgba(56, 189, 248, 0.15);
}

[data-theme="purple"] {
    --bg: #0f0b15;
    --bg2: #140e1e;
    --card: #1f142e;
    --card2: #2a1b3d;
    --border: #382452;
    --green: #a855f7;
    --green2: #c084fc;
    --orange: #f59e0b;
    --red: #f43f5e;
    --red2: #e11d48;
    --purple: #bf5af2;
    --blue: #3b82f6;
    --text: #fbfaff;
    --sub: #a78bfa;
    --muted: #8e8e93;
    --active-bg: rgba(168, 85, 247, 0.15);
}

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

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 20px;
    overflow: hidden;
    user-select: none;
}

/* Barra de título */
.titlebar {
    height: 38px;
    background: var(--bg2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    -webkit-app-region: drag;
    border-bottom: 1px solid var(--border);
    padding-left: 14px;
}
.titlebar-title { font-size: 17px; color: var(--sub); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.titlebar-title .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); display: inline-block; }
.titlebar-controls { display: flex; -webkit-app-region: no-drag; height: 100%; }
.win-btn {
    width: 46px; height: 38px; border: none; background: transparent; color: var(--sub);
    font-size: 17px; cursor: pointer; transition: background .15s;
}
.win-btn:hover { background: #ffffff14; color: var(--text); }
.win-close:hover { background: var(--red2); color: #fff; }

/* Layout */
.app { display: flex; height: calc(100vh - 38px); }

.sidebar {
    width: 230px; background: var(--bg2); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 18px 12px; flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 20px; }
.brand-logo {
    width: 40px; height: 40px; border-radius: 12px; background: var(--green);
    display: flex; align-items: center; justify-content: center; font-size: 26px; color: #000;
}
.brand-name { font-weight: 700; font-size: 20px; }
.brand-sub { font-size: 16px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-btn {
    display: flex; align-items: center; gap: 12px; padding: 11px 14px; border: none;
    background: transparent; color: var(--sub); font-size: 18px; border-radius: 10px;
    cursor: pointer; text-align: left; transition: all .15s; font-weight: 500;
}
.nav-btn .ic { font-size: 20px; filter: grayscale(1) opacity(.7); }
.nav-btn:hover { background: #ffffff0a; color: var(--text); }
.nav-btn.active { background: var(--active-bg); color: var(--text); }
.nav-btn.active .ic { filter: none; }
.sidebar-foot { text-align: center; color: var(--muted); font-size: 15px; padding-top: 10px; }

.content { flex: 1; overflow-y: auto; padding: 28px 32px; }

.view-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 20px; }
h1 { font-size: 32px; font-weight: 700; }
h3 { font-size: 20px; font-weight: 600; margin-bottom: 14px; }
.muted { color: var(--muted); font-size: 18px; }

/* Botones */
.btn {
    padding: 10px 18px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--card); color: var(--text); font-size: 18px; font-weight: 600;
    cursor: pointer; transition: all .15s;
}
.btn:hover { background: var(--card2); }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:hover { background: #1ed760; }
.btn-danger { background: var(--red2); border-color: var(--red2); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; border: none; color: var(--muted); }
.btn-sm { padding: 6px 12px; font-size: 17px; }

/* Inputs */
.input {
    width: 100%; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--bg); color: var(--text); font-size: 18px; font-family: inherit;
    outline: none; transition: border .15s;
}
.input:focus { border-color: var(--green); }
.textarea { min-height: 110px; resize: vertical; margin-bottom: 16px; user-select: text; }
label { display: block; font-size: 17px; color: var(--sub); margin: 12px 0 6px; font-weight: 600; }
.search { max-width: 360px; user-select: text; }

.toolbar { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }

/* Chips / filtros */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
    padding: 7px 14px; border-radius: 20px; border: 1px solid var(--border);
    background: var(--card); color: var(--sub); font-size: 17px; cursor: pointer; font-weight: 500;
}
.chip.active { background: var(--active-bg); border-color: var(--green); color: var(--text); }
.account-filter { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }

/* Cards */
.cards { display: flex; flex-direction: column; gap: 14px; }
.card {
    background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px;
    transition: border .15s;
}
.card:hover { border-color: #3a3a45; }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-title { font-size: 22px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.card-meta { color: var(--muted); font-size: 17px; margin-top: 4px; display: flex; gap: 16px; flex-wrap: wrap; }
.card-actions { display: flex; gap: 6px; align-items: center; }

.badge { padding: 4px 12px; border-radius: 20px; font-size: 16px; font-weight: 700; color: #fff; white-space: nowrap; }
.badge-paid { background: var(--green2); }
.badge-pending { background: var(--orange); }
.badge-expired { background: var(--red2); }
.badge-soft { background: var(--card2); color: var(--sub); font-weight: 600; }

.icon-btn {
    width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg);
    color: var(--sub); cursor: pointer; font-size: 18px; display: inline-flex; align-items: center; justify-content: center;
    transition: all .15s;
}
.icon-btn:hover { color: var(--text); border-color: #3a3a45; }
.icon-btn.green:hover { color: var(--green); }
.icon-btn.purple:hover { color: var(--purple); }
.icon-btn.red:hover { color: var(--red); }
.icon-btn.wa { color: #25d366; border-color: rgba(37, 211, 102, 0.35); }
.icon-btn.wa:hover { background: rgba(37, 211, 102, 0.12); border-color: #25d366; }

/* Clientes dentro de cuenta / historial de pagos */
.client-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.client-chip {
    background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px;
    font-size: 17px; display: flex; align-items: center; gap: 8px;
}
.client-chip .st { width: 8px; height: 8px; border-radius: 50%; }
.pay-history { margin-top: 14px; background: var(--bg); border: 1px solid var(--card2); border-radius: 10px; padding: 12px 14px; }
.pay-history h4 { font-size: 17px; color: var(--muted); margin-bottom: 8px; font-weight: 600; }
.pay-row { display: flex; align-items: center; gap: 8px; font-size: 17px; padding: 5px 0; flex-wrap: wrap; }
.pay-row .ok { color: var(--green2); }

.empty { color: var(--muted); font-style: italic; padding: 30px; text-align: center; }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px; }
.kpi .k-label { color: var(--muted); font-size: 17px; display: flex; align-items: center; gap: 8px; }
.kpi .k-val { font-size: 30px; font-weight: 700; margin-top: 8px; }

.finance-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.panel { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 20px; margin-bottom: 16px; }
.pie-wrap { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.legend { display: flex; flex-direction: column; gap: 8px; font-size: 17px; }
.legend .lg { display: flex; align-items: center; gap: 8px; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; }

/* Tablas */
table { width: 100%; border-collapse: collapse; font-size: 18px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 16px; text-transform: uppercase; letter-spacing: .04em; }
td { color: var(--text); }
.pos { color: var(--green); font-weight: 700; }
.neg { color: var(--red2); font-weight: 700; }

/* Respaldos */
.backups-panel { display: flex; flex-direction: column; gap: 0; }
.backup-item { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--border); }
.backup-item:last-child { border-bottom: none; }
.backup-item.danger b { color: var(--red); }
.info-panel ul { margin: 10px 0 0 18px; color: #d1d1d6; font-size: 18px; line-height: 1.8; }
.info-panel code { background: var(--bg); padding: 1px 6px; border-radius: 5px; color: var(--green); font-size: 17px; }

/* Modal */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(3px);
    display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-box {
    background: var(--bg2); border: 1px solid var(--border); border-radius: 16px; padding: 26px;
    width: 460px; max-width: 92vw; max-height: 88vh; overflow-y: auto;
}
.modal-box h2 { font-size: 24px; margin-bottom: 4px; }
.modal-box .sub { color: var(--muted); font-size: 17px; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
select.input { appearance: none; cursor: pointer; }
.proj-note { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-top: 14px; font-size: 17px; color: var(--sub); }
.proj-note b { color: var(--green); }

/* Recibo */
.receipt { width: 100%; text-align: center; }
.receipt .r-head { font-size: 32px; font-weight: 800; color: var(--green); font-family: 'Consolas', monospace; }
.receipt .r-sub { font-size: 19px; color: var(--text); margin-bottom: 14px; }
.receipt .r-line { display: flex; justify-content: space-between; padding: 6px 0; font-size: 19px; }
.receipt .r-line .l { color: var(--muted); }
.receipt hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.receipt .r-foot { color: var(--green); font-weight: 700; margin-top: 12px; }

.hidden { display: none !important; }

/* Snackbar */
.snackbar {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(120px);
    background: var(--red2); color: #fff; padding: 13px 22px; border-radius: 10px; font-size: 18px;
    font-weight: 600; z-index: 200; opacity: 0; transition: all .3s; max-width: 80vw;
}
.snackbar.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2c2c35; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #3a3a45; }
::-webkit-scrollbar-track { background: transparent; }

/* Autenticación */
.auth-container {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: #09090b; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
}
.auth-box {
    background: #121214; border: 1px solid #27272a;
    border-radius: 12px; padding: 30px; width: 400px; max-width: 90vw;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.auth-box h2 { font-size: 28px; margin-bottom: 5px; color: #fff; }
.auth-box .muted { color: #a1a1aa; font-size: 17px; margin-bottom: 20px; }
.btn-block { width: 100%; }

/* Paginación */
.pagination {
    display: flex; align-items: center; justify-content: center;
    gap: 15px; margin-top: 20px; padding: 10px 0;
}
.pagination-info { font-size: 17px; color: var(--text-muted); }

/* Banner de Alerta Urgente */
.alert-banner {
    background: linear-gradient(135deg, #7f1d1d, #b91c1c);
    border: 2px solid #ef4444; border-radius: 10px;
    padding: 15px; margin-bottom: 20px;
    display: flex; flex-direction: column; gap: 8px;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}
.alert-banner-header {
    display: flex; align-items: center; gap: 8px;
    color: #fca5a5; font-weight: 800; font-size: 20px;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.alert-banner-body {
    display: flex; flex-direction: column; gap: 5px;
}
.alert-banner-item {
    font-size: 19px; color: #ffffff; padding: 4px 8px;
    background: rgba(0, 0, 0, 0.2); border-radius: 4px;
}
.alert-banner-item b { color: #fca5a5; }

/* ── Diseño Líquido / Responsivo para Celulares ────────────────────────────────── */
@media (max-width: 768px) {
    .titlebar {
        display: none !important;
    }
    
    .app {
        display: flex;
        flex-direction: column;
        height: 100%;
    }
    
    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 60px;
        background: var(--bg2);
        border-right: none;
        border-top: 1px solid var(--border);
        flex-direction: row;
        align-items: center;
        justify-content: space-around;
        padding: 4px 8px;
        z-index: 1000;
    }
    
    .brand {
        display: none !important;
    }
    
    .nav {
        flex-direction: row;
        justify-content: space-around;
        align-items: center;
        width: 100%;
        gap: 0;
    }
    
    .nav-btn {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 4px 6px;
        font-size: 14px;
        gap: 2px;
        flex: 1;
        border-radius: 6px;
        text-align: center;
    }
    
    .nav-btn span:not(.ic) {
        font-size: 13px;
        display: block;
    }
    
    .sidebar-foot {
        display: none !important;
    }
    
    .content {
        padding: 16px 16px 80px 16px;
        overflow-y: auto;
    }
    
    .view-head {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 16px;
    }
    
    h1 {
        font-size: 26px;
    }
    
    .toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .search {
        max-width: 100%;
    }
    
    .view-actions {
        flex-direction: column;
        align-items: stretch !important;
        gap: 10px;
    }
    
    #history-search {
        width: 100% !important;
    }
    
    .card-top {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .card-title {
        font-size: 20px;
    }
    
    .card-actions {
        justify-content: flex-start;
        margin-top: 6px;
        flex-wrap: wrap;
        width: 100%;
    }
    
    .kpi-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .kpi .k-val {
        font-size: 24px;
    }
    
    .finance-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .pie-wrap {
        justify-content: center;
        gap: 16px;
    }
    
    table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .alert-banner-item {
        flex-direction: column;
        align-items: stretch !important;
        gap: 8px;
    }
    
    .alert-banner-item button {
        align-self: flex-end;
    }

    /* Convertir tablas de Historial y Usuarios a formato CARD en móviles */
    #history-table table, 
    #history-table thead, 
    #history-table tbody, 
    #history-table tr, 
    #history-table td,
    #users-list-tbody,
    #users-list-tbody tr,
    #users-list-tbody td,
    #view-users table,
    #view-users thead,
    #view-users tbody {
        display: block;
        width: 100%;
    }
    
    #history-table thead, 
    #view-users table thead {
        display: none !important;
    }
    
    #history-table tr, 
    #users-list-tbody tr {
        background: var(--card);
        border: 1px solid var(--border);
        border-radius: 12px;
        padding: 14px;
        margin-bottom: 12px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    }
    
    #history-table td, 
    #users-list-tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border-bottom: 1px dashed var(--border);
        font-size: 17px;
        text-align: right;
    }
    
    #history-table td:last-child, 
    #users-list-tbody td:last-child {
        border-bottom: none;
    }
    
    #history-table td::before, 
    #users-list-tbody td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--muted);
        text-align: left;
        font-size: 16px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    
    #history-table td[data-label="Acciones"],
    #users-list-tbody td[data-label="Acciones"] {
        justify-content: space-between;
    }

    .icon-btn {
        width: 44px !important;
        height: 44px !important;
        font-size: 22px !important;
        border-radius: 10px !important;
    }

    .alert-banner-item button {
        align-self: stretch !important;
        padding: 10px 16px !important;
        font-size: 18px !important;
        height: auto !important;
        margin-top: 6px;
        text-align: center;
        justify-content: center;
    }
}

/* ── Modales de Confirmación y Alerta Personalizados ────────────────────────────── */
.custom-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.2s ease-out;
}
.custom-modal-box {
    background: #1e1e24;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    animation: scaleUp 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
    color: var(--text);
}
.custom-modal-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.custom-modal-message {
    font-size: 18px;
    color: var(--text-muted);
    margin-bottom: 12px;
    line-height: 1.5;
}
.custom-modal-detail {
    font-size: 16px;
    color: #f59e0b;
    margin-bottom: 20px;
    background: rgba(234, 179, 8, 0.05);
    padding: 8px 12px;
    border-radius: 6px;
    border-left: 3px solid #f59e0b;
}
.custom-modal-input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: white;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 18px;
    margin-bottom: 20px;
    outline: none;
    transition: border-color 0.2s;
}
.custom-modal-input:focus {
    border-color: var(--primary);
}
.custom-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes scaleUp {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

