/* ══════════════════════════════════════════════════════════
   Tesorería - Comprobantes de Pago (modernizado)
   Namespace: tgi-
   Consume tokens de vista/styles/<thmCia>/css/theme-vars.css
══════════════════════════════════════════════════════════ */

* { box-sizing: border-box; }
body { background: var(--bg-page, #f4f7fb); margin: 0; }

.tgi-page {
    padding: 18px 24px 40px;
    background: var(--bg-page, #f4f7fb);
    min-height: 100vh;
    font-family: "Segoe UI", Arial, sans-serif;
    color: var(--text-primary, #1a2a45);
}

#tgiLoading {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,.7);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
}
#tgiLoading.show { display: flex; }

/* ── HEADER ─────────────────────────────────────────────── */
.tgi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    margin-bottom: 18px;
    background: var(--gradient-primary);
    border-radius: 14px;
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
    flex-wrap: wrap;
    gap: 14px;
}
.tgi-header::after {
    content: "";
    position: absolute;
    right: -50px; top: -40px;
    width: 220px; height: 220px;
    background: radial-gradient(circle, rgba(255,255,255,.16) 0%, transparent 70%);
    border-radius: 50%;
}
.tgi-header-left {
    display: flex;
    align-items: center;
    gap: 14px;
    z-index: 1;
}
.tgi-header-icon {
    font-size: 26px;
    color: var(--accent);
    background: rgba(255,255,255,.14);
    width: 50px; height: 50px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.tgi-header h1 { margin: 0; color: #fff; font-size: 22px; font-weight: 800; }
.tgi-header p  { margin: 2px 0 0; color: rgba(255,255,255,.85); font-size: 12.5px; font-weight: 500; }

/* ── STAGE WRAPPER (centra el card de búsqueda) ─────────── */
.tgi-stage { margin-top: 6px; margin-bottom: 16px; }

/* ── BUSCADOR DE ESTUDIANTE (estilo sta-search-card) ────── */
.tgi-search-card {
    background: var(--bg-surface, #fff);
    border: 1px solid var(--border-soft, #e8ecf4);
    border-radius: 14px;
    padding: 26px 22px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    max-width: 560px;
    margin: 0 auto;
}
.tgi-search-icon {
    font-size: 38px;
    color: var(--primary);
    margin-bottom: 8px;
    display: block;
}
.tgi-search-card h2 {
    margin: 4px 0;
    font-size: 19px;
    color: var(--text-primary);
    font-weight: 800;
}
.tgi-search-card p {
    margin: 0 0 14px;
    font-size: 13px;
    color: var(--text-secondary);
}
.tgi-search-box { max-width: 380px; margin: 0 auto; }

/* ── CABECERA ESTUDIANTE (estilo sta-head) ──────────────── */
.tgi-head {
    background: var(--bg-surface);
    border: 1px solid var(--border-soft, #e8ecf4);
    border-radius: 14px;
    padding: 16px 18px;
    margin-bottom: 18px;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 18px;
}
.tgi-head-sticky {
    position: sticky;
    top: 8px;
    z-index: 30;
    box-shadow: var(--shadow-md);
}
.tgi-head-photo img {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    border: 2px solid var(--primary-soft, rgba(11,61,109,.12));
    object-fit: cover;
    background: var(--bg-page);
}
.tgi-head-body { flex: 1; min-width: 0; }
.tgi-head-name {
    margin: 0 0 6px;
    font-size: 17px;
    color: var(--text-primary);
    font-weight: 800;
}
.tgi-head-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px 16px;
}
.tgi-head-field { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tgi-head-field-wide { grid-column: span 2; }
.tgi-head-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.tgi-head-label i { color: var(--primary); font-size: 11px; }
.tgi-head-value {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Botón "Cambiar estudiante" anclado al lado derecho del head */
.tgi-head-change {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border: 1px solid var(--border-soft, #e8ecf4);
    border-radius: 999px;
    background: var(--bg-page, #f4f7fb);
    color: var(--primary-dark, #0b3d6d);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .12s, box-shadow .15s;
    flex-shrink: 0;
}
.tgi-head-change i { color: var(--primary); font-size: 13px; }
.tgi-head-change:hover {
    background: var(--primary-soft, rgba(11,61,109,.10));
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.tgi-head-change:active { transform: translateY(0); filter: brightness(.95); }
@media (max-width: 640px) {
    .tgi-head-change { align-self: stretch; justify-content: center; }
}

/* ── KPIs ───────────────────────────────────────────────── */
.tgi-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}
.tgi-kpi {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-sm);
}
.tgi-kpi-icon {
    width: 42px; height: 42px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: #fff;
    background: var(--gradient-primary);
    flex-shrink: 0;
}
.tgi-kpi-icon.success { background: linear-gradient(135deg, #2e7d32 0%, #66bb6a 100%); }
.tgi-kpi-icon.warning { background: linear-gradient(135deg, #ef6c00 0%, #ffb74d 100%); }
.tgi-kpi-icon.danger  { background: linear-gradient(135deg, #c62828 0%, #ef5350 100%); }
.tgi-kpi-value { font-size: 20px; font-weight: 800; color: var(--primary-dark); line-height: 1; }
.tgi-kpi-label { font-size: 11.5px; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: .3px; }

/* ── NAV PILLS ──────────────────────────────────────────── */
.tgi-nav-pills {
    display: flex;
    gap: 6px;
    padding: 6px;
    background: var(--bg-surface);
    border-radius: 14px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.tgi-nav-pill {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 9px 16px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all .18s;
}
.tgi-nav-pill:hover { color: var(--primary-dark); background: var(--bg-page); }
.tgi-nav-pill.active {
    background: var(--gradient-primary);
    color: #fff;
    box-shadow: 0 3px 10px rgba(11,61,109,.22);
}
.tgi-nav-pill.active i { color: var(--accent); }
.tgi-nav-badge {
    background: var(--danger, #c62828);
    color: #fff;
    font-size: 10.5px;
    font-weight: 800;
    padding: 3px 7px;
    border-radius: 999px;
    min-width: 18px;
    text-align: center;
}
.tgi-nav-pill:not(.active) .tgi-nav-badge {
    background: var(--border-soft, #e8ecf4);
    color: var(--text-secondary);
}

/* ── TOOLBAR ────────────────────────────────────────────── */
.tgi-toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    background: var(--bg-surface);
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    margin-bottom: 14px;
}
.tgi-search { position: relative; flex: 1; min-width: 240px; }
.tgi-search i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.tgi-search input {
    width: 100%;
    padding: 9px 12px 9px 36px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-page);
    font-size: 13px;
    color: var(--text-primary);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.tgi-search input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft, rgba(11,61,109,.12));
}

/* ── BOTONES ────────────────────────────────────────────── */
.tgi-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border: none;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: transform .12s, box-shadow .15s, filter .15s;
}
.tgi-btn:hover { transform: translateY(-1px); }
.tgi-btn:active { transform: translateY(0); filter: brightness(.95); }
.tgi-btn-primary {
    background: var(--gradient-primary);
    color: #fff;
    box-shadow: var(--shadow-sm);
}
.tgi-btn-primary:hover { box-shadow: var(--shadow-md); }
.tgi-btn-ghost {
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.tgi-btn-ghost:hover { color: var(--primary); border-color: var(--primary); }
.tgi-btn-success {
    background: linear-gradient(135deg, #2e7d32 0%, #66bb6a 100%);
    color: #fff;
}
.tgi-btn-warning {
    background: linear-gradient(135deg, #ef6c00 0%, #ffb74d 100%);
    color: #fff;
}
.tgi-btn-danger {
    background: linear-gradient(135deg, #c62828 0%, #ef5350 100%);
    color: #fff;
}
.tgi-btn-pse {
    background: linear-gradient(135deg, #003a70 0%, #0066cc 100%);
    color: #fff;
}

/* ── GRID DE CARDS ──────────────────────────────────────── */
.tgi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 14px;
}
.tgi-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: transform .12s, box-shadow .15s, border-color .15s;
    position: relative;
    border-left: 4px solid var(--primary);
}
.tgi-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.tgi-card.is-vigente   { border-left-color: #2e7d32; }
.tgi-card.is-vencido   { border-left-color: #c62828; }
.tgi-card.is-proximo   { border-left-color: #ef6c00; }
.tgi-card.is-pagado    { border-left-color: #1565c0; }
.tgi-card.is-active    { box-shadow: 0 0 0 2px var(--primary); }

.tgi-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.tgi-card-title { margin: 0; font-size: 14px; font-weight: 800; color: var(--primary-dark); line-height: 1.3; }
.tgi-card-id {
    background: var(--primary-soft, rgba(11,61,109,.10));
    color: var(--primary-dark);
    font-size: 11px;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: 999px;
    white-space: nowrap;
}
.tgi-card-period { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; }
.tgi-card-body { display: flex; flex-direction: column; gap: 6px; }
.tgi-card-field { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; }
.tgi-card-field-label { color: var(--text-muted); display: inline-flex; align-items: center; gap: 6px; }
.tgi-card-field-value { color: var(--text-primary); font-weight: 700; text-align: right; }
.tgi-card-money { font-size: 18px; font-weight: 900; color: var(--primary-dark); }
.tgi-card-state {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: .3px;
}
.tgi-state-vigente   { background: #e8f5e9; color: #2e7d32; }
.tgi-state-vencido   { background: #ffebee; color: #c62828; }
.tgi-state-proximo   { background: #fff3e0; color: #ef6c00; }
.tgi-state-pagado    { background: #e3f2fd; color: #1565c0; }
.tgi-state-neutral   { background: var(--border-soft, #eef2f7); color: var(--text-secondary); }

.tgi-card-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    border-top: 1px dashed var(--border-soft, #e8ecf4);
    padding-top: 10px;
}
.tgi-card-actions .tgi-btn { padding: 6px 12px; font-size: 12px; border-radius: 8px; }

/* ── ESTADO VACÍO ───────────────────────────────────────── */
.tgi-empty,
.tgi-state {
    text-align: center;
    padding: 36px 24px;
    background: var(--bg-surface);
    border: 1px dashed var(--border);
    border-radius: 14px;
    color: var(--text-muted);
}
.tgi-empty i,
.tgi-state i { font-size: 36px; margin-bottom: 8px; display: block; color: var(--text-muted); }
.tgi-empty p,
.tgi-state p { margin: 0; font-size: 13px; }

/* ── LAYOUT 75/25 (Generados: lista + detalle) ──────────── */
.tgi-layout { display: block; }
.tgi-layout-list { min-width: 0; }
.tgi-layout-detail { display: none; }

.tgi-layout.is-split {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}
.tgi-layout.is-split .tgi-layout-list {
    flex: 1 1 75%;
    min-width: 0;
}
.tgi-layout.is-split .tgi-layout-detail {
    display: block;
    flex: 0 0 25%;
    max-width: 25%;
    min-width: 0;
    /* Debajo de la cabecera del estudiante (sticky ~110px) */
    position: sticky;
    top: 118px;
}
.tgi-layout.is-split .tgi-detail {
    margin-top: 0;
    max-height: calc(100vh - 134px);
    display: flex;
    flex-direction: column;
}
.tgi-layout.is-split .tgi-detail-body { overflow-y: auto; }

/* En la columna estrecha el detalle reflowa: concepto en su propia
   línea y debajo cantidad · valor (muted) con subtotal a la derecha */
.tgi-layout.is-split .tgi-dud-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 8px;
    padding: 10px 12px;
}
.tgi-layout.is-split .tgi-dud-row.is-header { display: none; }
.tgi-layout.is-split .tgi-dud-name { flex: 1 1 100%; font-weight: 700; }
.tgi-layout.is-split .tgi-dud-qty,
.tgi-layout.is-split .tgi-dud-val {
    font-size: 11.5px;
    color: var(--text-muted);
    text-align: left;
}
.tgi-layout.is-split .tgi-dud-qty::before { content: "x"; margin-right: 2px; }
.tgi-layout.is-split .tgi-dud-sub { margin-left: auto; }

/* ── DETALLE DE COMPROBANTE ─────────────────────────────── */
.tgi-detail {
    margin-top: 18px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
}
.tgi-detail-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 14px 18px;
    background: var(--gradient-primary);
    color: #fff;
}
.tgi-detail-head h2 { margin: 0; font-size: 16px; font-weight: 800; }
.tgi-detail-head h2 i { margin-right: 6px; color: var(--accent); }
.tgi-detail-head p  { margin: 4px 0 0; font-size: 12px; color: rgba(255,255,255,.85); }
.tgi-detail-head #dlgNroKmp { font-weight: 800; color: var(--accent); }
.tgi-modal-close {
    background: rgba(255,255,255,.16);
    border: none;
    color: #fff;
    width: 32px; height: 32px;
    border-radius: 8px;
    cursor: pointer;
    transition: background .15s;
}
.tgi-modal-close:hover { background: rgba(255,255,255,.28); }
.tgi-detail-body { padding: 16px 18px; }

.tgi-dud-list { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.tgi-dud-row {
    display: grid;
    grid-template-columns: 1fr 80px 110px 130px;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-soft, #eef2f7);
    align-items: center;
    font-size: 13px;
}
.tgi-dud-row:last-child { border-bottom: none; }
.tgi-dud-row.is-header {
    background: var(--primary-soft, #eef2f7);
    font-weight: 800;
    color: var(--primary-dark);
    text-transform: uppercase;
    font-size: 11.5px;
    letter-spacing: .3px;
}
.tgi-dud-row .tgi-dud-name { color: var(--text-primary); }
.tgi-dud-row .tgi-dud-qty,
.tgi-dud-row .tgi-dud-val,
.tgi-dud-row .tgi-dud-sub { text-align: right; }
.tgi-dud-row .tgi-dud-sub { font-weight: 800; color: var(--primary-dark); }

.tgi-dud-total {
    display: flex;
    justify-content: flex-end;
    gap: 14px;
    align-items: center;
    margin-top: 10px;
    padding: 10px 14px;
    background: var(--primary-soft, #eef2f7);
    border-radius: 10px;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 700;
}
.tgi-dud-total strong {
    font-size: 18px;
    color: var(--primary-dark);
    font-weight: 900;
}

/* ── ACCESO DENEGADO ────────────────────────────────────── */
.tgi-denied {
    max-width: 520px;
    margin: 60px auto;
    text-align: center;
    background: var(--bg-surface);
    padding: 32px;
    border-radius: 14px;
    box-shadow: var(--shadow-md);
}
.tgi-denied img { max-width: 200px; margin-bottom: 16px; }
.tgi-denied h2 { color: var(--danger, #c62828); margin: 0 0 8px; }
.tgi-denied p  { margin: 0; color: var(--text-secondary); }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 980px) {
    /* El split 75/25 se apila: lista arriba, detalle debajo a ancho completo */
    .tgi-layout.is-split { display: block; }
    .tgi-layout.is-split .tgi-layout-detail {
        position: static;
        max-width: 100%;
        margin-top: 16px;
    }
    .tgi-layout.is-split .tgi-detail { max-height: none; }
    /* Recupera la tabla de 4 columnas cuando hay ancho completo */
    .tgi-layout.is-split .tgi-dud-row {
        display: grid;
        grid-template-columns: 1fr 80px 110px 130px;
        gap: 8px;
        padding: 10px 14px;
    }
    .tgi-layout.is-split .tgi-dud-row.is-header { display: grid; }
    .tgi-layout.is-split .tgi-dud-name { flex: none; font-weight: 400; }
    .tgi-layout.is-split .tgi-dud-qty,
    .tgi-layout.is-split .tgi-dud-val { font-size: 13px; color: inherit; text-align: right; }
    .tgi-layout.is-split .tgi-dud-qty::before { content: ""; margin-right: 0; }
    .tgi-layout.is-split .tgi-dud-sub { margin-left: 0; }
}

@media (max-width: 640px) {
    .tgi-page { padding: 12px 12px 30px; }
    .tgi-header { padding: 14px 16px; }
    .tgi-header h1 { font-size: 18px; }
    .tgi-grid { grid-template-columns: 1fr; }
    .tgi-dud-row { grid-template-columns: 1fr 60px 90px 100px; font-size: 12px; }
    .tgi-head { flex-direction: column; text-align: center; }
    .tgi-head-fields { text-align: left; }
    .tgi-head-photo img { width: 90px; height: 90px; }
    .tgi-head-field-wide { grid-column: span 1; }
}

/* ── PROGRAMAS: lista previa cuando la persona tiene 2 o mas ─ */
.tgi-pgm {
    background: var(--bg-surface);
    border: 1px solid var(--border-soft, #e8ecf4);
    border-radius: 14px;
    padding: 20px 22px;
    margin-bottom: 18px;
    box-shadow: var(--shadow-sm);
}
.tgi-pgm h2 {
    margin: 0 0 4px;
    font-size: 17px;
    font-weight: 800;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.tgi-pgm h2 i { color: var(--primary); }
.tgi-pgm p { margin: 0 0 14px; font-size: 13px; color: var(--text-secondary); }
.tgi-pgm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px;
}
.tgi-pgm-item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-page);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
    transition: background .15s, border-color .15s, box-shadow .15s;
}
.tgi-pgm-item > span { flex: 1; min-width: 0; }
.tgi-pgm-item > i:first-child { color: var(--primary); }
.tgi-pgm-item > i:last-child { color: var(--text-muted); font-size: 12px; }
.tgi-pgm-item:hover {
    background: var(--primary-soft, var(--bg-page));
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}
.tgi-pgm-change {
    align-self: flex-start;
    margin-top: 4px;
    min-height: 32px;
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-page);
    color: var(--primary-dark, var(--primary));
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}
.tgi-pgm-change:hover { border-color: var(--primary); background: var(--primary-soft, var(--bg-page)); }
@media (max-width: 640px) {
    .tgi-pgm { padding: 16px 14px; }
    .tgi-pgm-grid { grid-template-columns: 1fr; }
    .tgi-pgm-change { min-height: 40px; align-self: stretch; }
}
