/* Portal TSU · estilo basado en cont@fact dashboard v3
   ---------------------------------------------------- */
:root {
    --c-bg: #f4f6fb;
    --c-panel: #ffffff;
    --c-border: #e6e9f0;
    --c-text: #1f2433;
    --c-text-muted: #6b7280;
    --c-primary: #2b5cff;
    --c-primary-dark: #1f47cc;
    --c-success: #14a44d;
    --c-warning: #f4a020;
    --c-danger: #d9304b;
    --c-info: #2b9bd9;
    --c-side: #161b2c;
    --c-side-hover: #232a44;
    --c-side-active: #2b5cff;
    --radius: 12px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, .08);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--c-bg);
    color: var(--c-text);
    font-family: inherit;
    font-size: 14px;
}

.mono { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }

/* ============== LOGIN ============== */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1f47cc 0%, #2b5cff 60%, #5b8cff 100%);
    padding: 24px;
}
.login-wrap { width: 100%; max-width: 420px; }
.login-card {
    background: var(--c-panel);
    border-radius: 16px;
    padding: 36px 32px;
    box-shadow: 0 24px 48px rgba(15, 23, 42, .22);
}
.login-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 28px;
}
.brand-mark {
    width: 52px; height: 52px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--c-primary), var(--c-primary-dark));
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    box-shadow: 0 8px 18px rgba(43, 92, 255, .35);
}
.brand-text h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: var(--c-text);
}
.brand-text p {
    margin: 0;
    font-size: 13px;
    color: var(--c-text-muted);
}
.login-card .form-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--c-text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.login-card .btn-primary {
    background: var(--c-primary);
    border: 0;
    padding: 11px;
    font-weight: 600;
    border-radius: 10px;
}
.login-card .btn-primary:hover { background: var(--c-primary-dark); }
.login-foot {
    margin-top: 22px;
    text-align: center;
    font-size: 12px;
    color: var(--c-text-muted);
}

/* ============== LAYOUT ============== */
.portal-body {
    display: flex;
    min-height: 100vh;
}
.portal-side {
    width: 240px;
    background: var(--c-side);
    color: #cbd2e3;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
}
.side-brand {
    padding: 22px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: white;
    font-size: 16px;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.side-brand i { color: var(--c-primary); font-size: 18px; }
.side-nav {
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    overflow-y: auto;
}
.side-nav::-webkit-scrollbar { width: 6px; }
.side-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 3px; }

/* Link "solo" (no agrupado) y links dentro de grupos */
.side-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    color: #aab2c8;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: background .15s, color .15s;
    cursor: pointer;
    border: 0;
    background: transparent;
    width: 100%;
    text-align: left;
}
.side-link i.fas { width: 16px; text-align: center; font-size: 13px; }
.side-link:hover {
    background: var(--c-side-hover);
    color: white;
}
.side-link.active {
    background: var(--c-side-active);
    color: white;
    box-shadow: 0 2px 8px rgba(43, 92, 255, .35);
}
.side-link.disabled {
    color: #5b6680;
    cursor: not-allowed;
    opacity: .65;
}
.side-link.disabled:hover { background: transparent; color: #5b6680; }

/* Grupos colapsables */
.side-group { margin-bottom: 2px; }
.side-group-head {
    text-transform: uppercase;
    letter-spacing: .04em;
    font-size: 11px;
    font-weight: 700;
    color: #7b85a0;
    padding: 10px 12px;
    border-radius: 8px;
    background: transparent;
    border: 0;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.side-group-head:hover { background: var(--c-side-hover); color: white; }
.side-group-head .chev {
    margin-left: auto;
    font-size: 10px;
    transition: transform .2s;
}
.side-group-head.open .chev { transform: rotate(180deg); }
.side-group-body {
    padding: 2px 0 6px 14px;
    border-left: 1px solid rgba(255,255,255,.06);
    margin-left: 18px;
}
.side-group-body .side-link { padding: 7px 10px; font-size: 12px; }
.side-group-body .side-link .dot {
    width: 5px; height: 5px;
    border-radius: 50%;
    background: #4b566f;
    flex-shrink: 0;
}
.side-group-body .side-link.active .dot { background: white; }
.pending-badge {
    margin-left: auto;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 6px;
    background: rgba(255,255,255,.04);
    color: #6b7593;
    border-radius: 999px;
    letter-spacing: .05em;
}
.side-foot { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.06); }
.btn-logout {
    background: rgba(255,255,255,.06);
    color: #cbd2e3;
    border: 1px solid rgba(255,255,255,.08);
}
.btn-logout:hover { background: rgba(255,255,255,.12); color: white; }

.portal-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.portal-top {
    background: var(--c-panel);
    border-bottom: 1px solid var(--c-border);
    padding: 18px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.top-title {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: var(--c-text);
}
.top-sub {
    font-size: 12px;
    color: var(--c-text-muted);
    margin-top: 2px;
}
.top-user {
    display: flex;
    align-items: center;
    gap: 12px;
}
.user-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--c-primary);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    font-size: 14px;
}
.user-name { font-weight: 600; font-size: 13px; line-height: 1.2; }
.user-role { font-size: 11px; color: var(--c-text-muted); }

.portal-content {
    padding: 24px 28px;
    flex: 1;
}

/* ============== KPI ============== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.kpi-card {
    background: var(--c-panel);
    border-radius: var(--radius);
    border: 1px solid var(--c-border);
    box-shadow: var(--shadow-sm);
    padding: 18px 18px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
    overflow: hidden;
}
.kpi-card::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
}
.kpi-blue   .kpi-icon, .kpi-blue::before   { background: var(--c-primary); }
.kpi-green  .kpi-icon, .kpi-green::before  { background: var(--c-success); }
.kpi-orange .kpi-icon, .kpi-orange::before { background: var(--c-warning); }
.kpi-purple .kpi-icon, .kpi-purple::before { background: #7c3aed; }

.kpi-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.kpi-body { flex: 1; min-width: 0; }
.kpi-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--c-text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.kpi-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--c-text);
    margin: 2px 0 0;
    font-variant-numeric: tabular-nums;
}
.kpi-foot { font-size: 12px; color: var(--c-text-muted); margin-top: 2px; }

/* ============== PANELS ============== */
.panel {
    background: var(--c-panel);
    border-radius: var(--radius);
    border: 1px solid var(--c-border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.panel-head {
    padding: 14px 18px;
    border-bottom: 1px solid var(--c-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.panel-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.panel-sub { font-size: 12px; color: var(--c-text-muted); }
.panel-link {
    font-size: 12px;
    color: var(--c-primary);
    text-decoration: none;
    font-weight: 600;
}
.panel-link:hover { text-decoration: underline; }
.panel-body { padding: 16px 18px; }
.panel-body.p-0 { padding: 0; }

/* ============== TABLAS ============== */
.tbl-compact { font-size: 13px; }
.tbl-compact thead th {
    background: #fafbfd;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--c-text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--c-border);
    white-space: nowrap;
    padding: 10px 12px;
}
.tbl-compact tbody td {
    padding: 10px 12px;
    vertical-align: middle;
    border-bottom: 1px solid #eef0f5;
}
.tbl-compact tbody tr:last-child td { border-bottom: 0; }

/* ============== CHIPS / TAGS ============== */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    background: #eef1f7;
    color: var(--c-text);
}
.chip-emit  { background: #e6f7ee; color: #097a3e; }
.chip-recib { background: #e8effd; color: #1f47cc; }

/* ============== RANK ============== */
.rank-list {
    list-style: none;
    margin: 0; padding: 0;
}
.rank-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #eef0f5;
}
.rank-list li:last-child { border-bottom: 0; }
.rank-pos {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: #eef1f7;
    color: var(--c-text-muted);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    font-size: 12px;
    flex-shrink: 0;
}
.rank-body { flex: 1; min-width: 0; }
.rank-name {
    font-size: 13px; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rank-meta { font-size: 11px; color: var(--c-text-muted); }
.rank-val { font-size: 13px; font-weight: 600; }

/* ============== OPS TOOLBAR / SEGMENTED ============== */
.ops-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}
.seg {
    display: inline-flex;
    background: var(--c-panel);
    border: 1px solid var(--c-border);
    border-radius: 10px;
    padding: 3px;
    box-shadow: var(--shadow-sm);
}
.seg-btn {
    border: 0;
    background: transparent;
    color: var(--c-text-muted);
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 7px;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, color .15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.seg-btn:hover { color: var(--c-text); }
.seg-btn.active {
    background: var(--c-primary);
    color: white;
    box-shadow: 0 2px 6px rgba(43, 92, 255, .25);
}
.ops-toolbar input[type="search"] {
    min-width: 240px;
    border-radius: 8px;
}

/* DataTables footer styling fit */
.dataTables_wrapper .dataTables_paginate,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_length {
    padding: 10px 18px;
    font-size: 12px;
}

/* Links */
.link-doc, .link-file {
    color: var(--c-primary);
    text-decoration: none;
    font-weight: 600;
}
.link-doc:hover, .link-file:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 768px) {
    .portal-side {
        position: fixed;
        left: -240px;
        transition: left .25s;
        z-index: 1040;
    }
    .portal-side.open { left: 0; }
    .portal-main { width: 100%; }
}
