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

:root {
    --primary:   #1565c0;
    --primary-d: #0d47a1;
    --primary-l: #1976d2;
    --accent:    #f57c00;
    --accent-d:  #e65100;
    --accent-l:  #ff9800;
    --danger:    #d32f2f;
    --success:   #2e7d32;
    --warning:   #f9a825;
    --bg:        #f0f4f9;
    --surface:   #ffffff;
    --border:    #d0d9e8;
    --text:      #1a2540;
    --muted:     #6b7a99;
    --radius:    10px;
    --radius-lg: 16px;
    --shadow:    0 2px 12px rgba(21,101,192,.10);
    --shadow-md: 0 4px 20px rgba(21,101,192,.14);
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
}

.hidden { display: none !important; }

/* ===== LOGIN ===== */
#page-login {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0d47a1 0%, #1565c0 40%, #e65100 100%);
    position: relative; overflow: hidden;
}
#page-login::before {
    content: '';
    position: absolute; inset: 0;
    background: url('../img/logo.jpg') center/300px no-repeat;
    opacity: .04;
    filter: grayscale(1);
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 2.5rem 2rem;
    width: 100%; max-width: 390px;
    box-shadow: 0 12px 48px rgba(0,0,0,.25);
    position: relative;
    z-index: 1;
}
.login-logo {
    display: block; margin: 0 auto 1.2rem;
    width: 130px; height: 130px;
    object-fit: contain;
    border-radius: 50%;
    background: #f0f4f9;
    padding: 6px;
    box-shadow: 0 4px 16px rgba(21,101,192,.15);
}
.login-card h1 {
    text-align: center; margin-bottom: 1.5rem;
    color: var(--primary); font-size: 1.5rem; font-weight: 800;
    letter-spacing: .03em;
}
.login-subtitle {
    text-align: center; font-size: .82rem; color: var(--muted);
    margin-top: -.8rem; margin-bottom: 1.2rem; text-transform: uppercase; letter-spacing: .08em;
}
.login-card label { display: block; font-size: .85rem; font-weight: 600; margin: .75rem 0 .3rem; color: var(--text); }
.login-card input[type=email],
.login-card input[type=password] {
    width: 100%; padding: .65rem .85rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius); font-size: .95rem;
    transition: border-color .2s;
}
.login-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(21,101,192,.12); }
.login-card button[type=submit] {
    width: 100%; margin-top: 1.3rem; padding: .8rem;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    color: #fff; border: none; border-radius: var(--radius);
    font-size: 1rem; cursor: pointer; font-weight: 700;
    letter-spacing: .04em; transition: opacity .2s;
}
.login-card button[type=submit]:hover { opacity: .9; }

/* ===== TOPBAR ===== */
.topbar {
    display: flex; align-items: center; gap: 1rem;
    background: linear-gradient(90deg, var(--primary-d) 0%, var(--primary) 60%, #1a237e 100%);
    color: #fff;
    padding: .5rem 1.5rem;
    position: sticky; top: 0; z-index: 100;
    box-shadow: 0 3px 10px rgba(0,0,0,.25);
    border-bottom: 3px solid var(--accent);
}
.topbar-logo {
    height: 42px; width: 42px;
    object-fit: contain;
    border-radius: 50%;
    background: rgba(255,255,255,.12);
    padding: 2px;
    flex-shrink: 0;
}
.topbar-brand {
    font-weight: 800; font-size: 1.1rem;
    margin-right: auto; letter-spacing: .04em;
    display: flex; flex-direction: column; line-height: 1.1;
}
.topbar-brand span {
    font-size: .65rem; font-weight: 400;
    color: rgba(255,255,255,.7); letter-spacing: .12em; text-transform: uppercase;
}
.topbar-nav { display: flex; gap: .25rem; }
.topbar-nav .nav-link {
    color: rgba(255,255,255,.85); text-decoration: none;
    font-size: .9rem; padding: .4rem .8rem; border-radius: 6px;
    font-weight: 500; transition: background .15s, color .15s;
}
.topbar-nav .nav-link:hover { color: #fff; background: rgba(255,255,255,.15); }
.topbar-nav .nav-link.active {
    color: #fff;
    background: var(--accent);
    font-weight: 700;
}
#btn-logout {
    background: rgba(255,255,255,.12); color: rgba(255,255,255,.9);
    border: 1px solid rgba(255,255,255,.25); border-radius: 6px;
    padding: .35rem .85rem; font-size: .85rem; cursor: pointer;
    transition: background .15s;
}
#btn-logout:hover { background: rgba(255,255,255,.22); }

/* ===== Page inner ===== */
.page-inner { max-width: 980px; margin: 0 auto; padding: 1.6rem 1.2rem; }
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1.2rem;
    padding-bottom: .8rem;
    border-bottom: 2px solid var(--border);
}
.page-header h2 { font-size: 1.45rem; font-weight: 800; color: var(--primary); }

/* ===== Botones ===== */
.btn-primary {
    background: linear-gradient(90deg, var(--primary), var(--primary-l));
    color: #fff; border: none;
    padding: .5rem 1.2rem; border-radius: var(--radius);
    cursor: pointer; font-size: .9rem; font-weight: 700;
    box-shadow: 0 2px 8px rgba(21,101,192,.25);
    transition: opacity .15s, transform .1s;
}
.btn-primary:hover { opacity: .92; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: var(--surface); color: var(--primary);
    border: 1.5px solid var(--primary);
    padding: .45rem 1rem; border-radius: var(--radius);
    cursor: pointer; font-size: .88rem; font-weight: 600;
    transition: background .15s;
}
.btn-secondary:hover { background: #e8f0fe; }

.btn-accent {
    background: linear-gradient(90deg, var(--accent), var(--accent-l));
    color: #fff; border: none;
    padding: .5rem 1.2rem; border-radius: var(--radius);
    cursor: pointer; font-size: .9rem; font-weight: 700;
    box-shadow: 0 2px 8px rgba(245,124,0,.3);
    transition: opacity .15s;
}
.btn-accent:hover { opacity: .9; }

.btn-danger {
    background: var(--danger); color: #fff; border: none;
    padding: .35rem .8rem; border-radius: var(--radius);
    cursor: pointer; font-size: .85rem; font-weight: 600;
}
.btn-link { background: none; border: none; cursor: pointer; color: inherit; font-size: .9rem; }
.btn-link:hover { text-decoration: underline; }
.btn-back {
    background: none; border: none; cursor: pointer;
    color: var(--primary); font-size: .9rem;
    padding: 0; margin-bottom: .9rem;
    display: inline-flex; align-items: center; gap: .3rem;
    font-weight: 600;
}
.btn-back:hover { color: var(--accent); }

/* ===== Métricas ===== */
.metricas { display: flex; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.metrica-card {
    background: var(--surface); border-radius: var(--radius);
    padding: 1rem 1.3rem; box-shadow: var(--shadow);
    flex: 1; min-width: 130px;
    border-left: 4px solid var(--primary);
    transition: box-shadow .2s;
}
.metrica-card:hover { box-shadow: var(--shadow-md); }
.metrica-card .num { font-size: 1.6rem; font-weight: 800; color: var(--primary); }
.metrica-card .lbl { font-size: .78rem; color: var(--muted); margin-top: .15rem; text-transform: uppercase; letter-spacing: .05em; }

/* ===== Filtros ===== */
.filtros { display: flex; gap: .75rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.filtros input, .filtros select {
    padding: .5rem .85rem; border: 1.5px solid var(--border);
    border-radius: var(--radius); font-size: .9rem; background: var(--surface);
    transition: border-color .2s;
}
.filtros input:focus, .filtros select:focus { outline: none; border-color: var(--primary); }
.filtros input { flex: 1; min-width: 180px; }

/* ===== Tabla ===== */
.tabla {
    width: 100%; border-collapse: collapse;
    background: var(--surface); border-radius: var(--radius);
    overflow: hidden; box-shadow: var(--shadow);
}
.tabla th, .tabla td { padding: .7rem 1.1rem; text-align: left; }
.tabla th {
    background: linear-gradient(90deg, #e8f0fe, #f0f4f9);
    font-size: .78rem; color: var(--primary);
    font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
}
.tabla tbody tr { border-top: 1px solid #edf0f7; transition: background .12s; }
.tabla tbody tr:hover { background: #f5f8ff; }
.tabla a.link-detalle { color: var(--primary); font-weight: 600; text-decoration: none; }
.tabla a.link-detalle:hover { color: var(--accent); text-decoration: underline; }

/* ===== Badge estado ===== */
.badge {
    display: inline-block; padding: .2rem .65rem; border-radius: 20px;
    font-size: .76rem; font-weight: 700; letter-spacing: .02em;
}
.badge-pendiente { background: #fff8e1; color: #e65100; border: 1px solid #ffcc80; }
.badge-parcial   { background: #e3f2fd; color: #1565c0; border: 1px solid #90caf9; }
.badge-pagada    { background: #e8f5e9; color: #2e7d32; border: 1px solid #a5d6a7; }
.badge-vencida   { background: #ffebee; color: #c62828; border: 1px solid #ef9a9a; }

/* ===== Detalle clienta ===== */
.detalle-header {
    display: flex; gap: 1rem; align-items: flex-start;
    flex-wrap: wrap; margin-bottom: 1.2rem;
    background: var(--surface); padding: 1.2rem 1.4rem;
    border-radius: var(--radius); box-shadow: var(--shadow);
    border-left: 5px solid var(--accent);
}
.detalle-header > div:first-child { flex: 1; }
.detalle-nombre { font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.detalle-datos { font-size: .88rem; color: var(--muted); margin-top: .3rem; }

.resumen-financiero { display: flex; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.resumen-item {
    background: var(--surface); padding: .9rem 1.2rem;
    border-radius: var(--radius); box-shadow: var(--shadow);
    flex: 1; min-width: 120px;
    border-top: 3px solid var(--primary);
}
.resumen-item .num { font-size: 1.3rem; font-weight: 800; }
.resumen-item .lbl { font-size: .76rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.alerta-cuota {
    background: #fff8e1; border-left: 4px solid var(--accent);
    padding: .75rem 1rem; border-radius: 6px;
    margin-bottom: 1rem; font-size: .88rem; color: #5d3e00;
}

.ventas-list { display: flex; flex-direction: column; gap: .8rem; }
.venta-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.venta-card-header {
    display: flex; align-items: center; gap: 1rem; padding: .8rem 1.1rem;
    cursor: pointer; user-select: none; transition: background .12s;
}
.venta-card-header:hover { background: #f5f8ff; }
.venta-card-header .fecha { font-size: .82rem; color: var(--muted); }
.venta-card-header .monto { font-weight: 800; margin-left: auto; color: var(--primary); }
.venta-card-body { padding: .85rem 1.1rem; border-top: 2px solid #edf0f7; background: #fafbff; }
.cuotas-tabla { width: 100%; border-collapse: collapse; font-size: .87rem; }
.cuotas-tabla th, .cuotas-tabla td { padding: .45rem .7rem; text-align: left; border-bottom: 1px solid #edf0f7; }
.cuotas-tabla th { color: var(--primary); font-weight: 700; font-size: .78rem; text-transform: uppercase; }

/* ===== Historial pagos ===== */
.historial-pagos { margin-top: 1.3rem; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.2rem; }
.historial-pagos h3 { font-size: 1rem; font-weight: 700; margin-bottom: .7rem; color: var(--primary); border-bottom: 1px solid var(--border); padding-bottom: .4rem; }
.pago-item { display: flex; gap: 1rem; align-items: center; padding: .5rem .2rem; border-bottom: 1px solid #f0f4f9; font-size: .87rem; }
.pago-item:last-child { border-bottom: none; }
.pago-item .fecha { color: var(--muted); min-width: 90px; }
.pago-item .monto { font-weight: 700; color: var(--primary); }
.pago-item .detalle { color: var(--muted); flex: 1; }

/* ===== Formularios ===== */
.form-section {
    background: var(--surface); padding: 1.3rem 1.4rem;
    border-radius: var(--radius); box-shadow: var(--shadow);
    margin-bottom: 1rem; border-top: 3px solid var(--primary);
}
.form-section h3 { margin-bottom: .9rem; font-size: 1rem; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
label { display: block; font-size: .84rem; font-weight: 600; margin: .6rem 0 .25rem; color: var(--text); }
input[type=text], input[type=number], input[type=email], input[type=tel],
input[type=date], input[type=search], input[type=password], input[type=month],
select, textarea {
    width: 100%; padding: .58rem .8rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius); font-size: .92rem;
    background: var(--surface); color: var(--text);
    transition: border-color .2s, box-shadow .2s;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(21,101,192,.1); }
.row-group { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 600px) { .row-group { grid-template-columns: 1fr; } }
.radio-group { display: flex; gap: 1.5rem; }
.radio-group label { display: flex; align-items: center; gap: .4rem; cursor: pointer; font-weight: 500; }

/* Items venta */
.item-venta { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: .5rem; align-items: end; margin-bottom: .5rem; }
@media (max-width: 600px) { .item-venta { grid-template-columns: 1fr 1fr; } }
.total-label { margin-top: .8rem; font-size: 1.05rem; font-weight: 700; color: var(--primary); }

/* Preview cuotas */
.preview-cuotas { margin-top: .9rem; }
.preview-cuotas table { width: 100%; border-collapse: collapse; font-size: .87rem; }
.preview-cuotas th, .preview-cuotas td { padding: .38rem .65rem; border-bottom: 1px solid #edf0f7; }
.preview-cuotas th { color: var(--primary); font-weight: 700; font-size: .78rem; text-transform: uppercase; }

/* Sugerencias autocomplete */
.sugerencias {
    list-style: none; border: 1.5px solid var(--border);
    border-radius: var(--radius); background: var(--surface);
    position: absolute; z-index: 200; max-height: 200px;
    overflow-y: auto; min-width: 220px; box-shadow: var(--shadow-md);
}
.sugerencias li { padding: .55rem .85rem; cursor: pointer; font-size: .9rem; border-bottom: 1px solid #f0f4f9; }
.sugerencias li:hover { background: #e8f0fe; color: var(--primary); }
.chip-seleccionada {
    background: linear-gradient(90deg, #e8f0fe, #eef4ff);
    border: 1.5px solid #90b4ef; color: var(--primary);
    padding: .3rem .85rem; border-radius: 20px;
    font-size: .87rem; display: inline-block; margin-top: .4rem;
    font-weight: 600;
}

/* Info box */
.info-box { background: #e8f0fe; border-radius: var(--radius); padding: .85rem 1.1rem; margin-bottom: 1rem; font-size: .9rem; border-left: 4px solid var(--primary); }

/* Error */
.error { color: var(--danger); font-size: .86rem; margin-top: .4rem; }

/* ===== Modal ===== */
#modal-overlay {
    position: fixed; inset: 0; background: rgba(10,20,50,.55);
    display: flex; align-items: center; justify-content: center; z-index: 1000;
    backdrop-filter: blur(2px);
}
#modal-box {
    background: var(--surface); border-radius: var(--radius-lg);
    padding: 1.8rem; max-width: 490px; width: 92%;
    position: relative; box-shadow: 0 12px 48px rgba(0,0,0,.25);
    max-height: 85vh; overflow-y: auto;
    border-top: 4px solid var(--accent);
}
.modal-close-btn { position: absolute; top: .85rem; right: .85rem; font-size: 1.1rem; color: var(--muted); }
.modal-close-btn:hover { color: var(--danger); }
#modal-content h3 { margin-bottom: 1.1rem; font-size: 1.15rem; font-weight: 800; color: var(--primary); }

/* ===== Resumen ===== */
.resumen-section-title {
    font-size: 1.1rem; font-weight: 800; color: var(--primary);
    margin: 1.6rem 0 .8rem; padding-bottom: .4rem;
    border-bottom: 2px solid var(--border);
    display: flex; align-items: center; gap: .5rem;
}
.resumen-section-title::before {
    content: ''; display: inline-block;
    width: 5px; height: 20px; background: var(--accent);
    border-radius: 3px;
}

/* ===== Alerta próximas cuotas detalle ===== */
.proximas-vencer { margin-bottom: 1rem; }
.proximas-vencer h3 { font-size: 1rem; margin-bottom: .5rem; }

/* ===== PIN gate ===== */
#resumen-pin-gate .login-card { border-top: 4px solid var(--accent); }
#resumen-pin-gate .login-card h3 { color: var(--primary); font-weight: 800; }
