:root {
    /* Marca Mandata (manual: azul #192359, gris #3C3C3B) */
    --brand-blue: #192359;
    --brand-gray: #3c3c3b;
    --primary: var(--brand-blue);
    --primary-light: #2e3d7a;
    --primary-dark: #121a42;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --bg: #f4f6f9;
    --card-bg: #ffffff;
    --text: var(--brand-gray);
    --text-light: #64748b;
    --border: #e2e8f0;
    --sidebar-bg: var(--brand-blue);
    --sidebar-text: #e8ecf7;
    --sidebar-active: rgba(255, 255, 255, 0.18);
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

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

html {
    width: 100%;
    min-height: 100%;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
    width: 100%;
    margin: 0;
}

body.sidebar-open {
    overflow: hidden;
}

.mobile-menu-toggle,
.sidebar-overlay,
.sidebar-close-btn {
    display: none;
}

.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-header {
    padding: 16px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    line-height: 0;
}

.sidebar-logo {
    flex-shrink: 0;
    width: auto;
    max-width: 72%;
    height: auto;
    object-fit: contain;
    display: block;
    margin: 0 auto;
}

.sidebar-footer {
    margin-top: auto;
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 12px;
}

.sidebar-view-as {
    margin-bottom: 12px;
}

.sidebar-view-as label {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: rgba(255,255,255,0.45);
    margin-bottom: 6px;
}

.sidebar-view-as .view-as-select {
    width: 100%;
    padding: 8px 10px;
    font-size: 12px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(0,0,0,0.2);
    color: var(--sidebar-text);
}

.sidebar-user {
    display: block;
    color: var(--sidebar-text);
    word-break: break-all;
    margin-bottom: 8px;
}

.sidebar-logout {
    color: #fff;
    text-decoration: none;
    font-weight: 600;
}

.sidebar-logout:hover {
    color: #fff;
}

.acreedor-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    padding: 12px 16px;
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.acreedor-bar label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-light);
}

.acreedor-select {
    min-width: 220px;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 14px;
}

.login-body {
    min-height: 100vh;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: var(--brand-blue);
}

.login-wrap {
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.login-wrap--wide {
    max-width: 520px;
}

.login-card--2fa {
    max-width: 100%;
    text-align: left;
}

.login-card--2fa h1 {
    text-align: center;
}

.login-card--2fa > .login-sub:first-of-type {
    text-align: center;
}

.login-card {
    background: var(--card-bg);
    padding: 40px 36px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-card .form-group {
    text-align: left;
}

.login-card h1 {
    font-size: 22px;
    margin-top: 16px;
    color: var(--text);
}

.login-sub {
    color: var(--text-light);
    font-size: 14px;
    margin: 8px 0 24px;
}

.login-brand {
    display: block;
    width: 100%;
    max-width: min(100%, 360px);
    height: auto;
    margin: 0 auto 16px;
    padding: 8px 12px;
    object-fit: contain;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    line-height: 0;
}

.login-logo {
    display: block;
    margin: 0 auto;
}

/* --- Login: verificación en dos pasos (2FA) --- */
.twofa-lead {
    color: var(--text);
    font-size: 14px;
    line-height: 1.55;
    margin: 0 0 16px;
}

.twofa-steps {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 20px;
}

.twofa-step {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fafbfc;
}

.twofa-step-num {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.twofa-step strong {
    display: block;
    font-size: 14px;
    margin-bottom: 4px;
    color: var(--text);
}

.twofa-step p {
    font-size: 13px;
    color: var(--text-light);
    line-height: 1.45;
    margin: 0;
}

.twofa-app-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
}

@media (max-width: 400px) {
    .twofa-app-grid {
        grid-template-columns: 1fr;
    }
}

.twofa-app-card {
    display: block;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    text-decoration: none;
    color: var(--text);
    font-size: 13px;
    line-height: 1.35;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.twofa-app-card:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow);
}

.twofa-app-card strong {
    display: block;
    font-size: 13px;
    margin-bottom: 2px;
}

.twofa-app-card span {
    font-size: 11px;
    color: var(--text-light);
}

.twofa-qr-wrap {
    margin: 12px auto 8px;
    padding: 12px;
    background: #fff;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    text-align: center;
    max-width: 300px;
}

.twofa-qr-wrap img {
    display: block;
    margin: 0 auto;
    width: 260px;
    height: 260px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.twofa-manual {
    margin-top: 10px;
    font-size: 13px;
    color: var(--text-light);
}

.twofa-manual summary {
    cursor: pointer;
    color: var(--primary);
    font-weight: 600;
}

.twofa-manual code {
    display: block;
    margin-top: 8px;
    padding: 10px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    word-break: break-all;
    color: var(--text);
}

.twofa-recovery-header {
    text-align: center;
    margin-bottom: 16px;
}

.twofa-recovery-icon {
    font-size: 36px;
    line-height: 1;
    margin-bottom: 8px;
}

.twofa-recovery-title {
    font-size: 18px;
    margin: 0 0 8px;
    color: var(--text);
}

.twofa-tips {
    margin: 0 0 16px 18px;
    padding: 0;
    font-size: 13px;
    color: var(--text-light);
    line-height: 1.5;
}

.twofa-tips li {
    margin-bottom: 6px;
}

.twofa-recovery-codes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 14px;
}

@media (max-width: 400px) {
    .twofa-recovery-codes {
        grid-template-columns: 1fr;
    }
}

.twofa-recovery-code {
    padding: 10px 12px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 14px;
    text-align: center;
    letter-spacing: 0.04em;
}

.twofa-warning {
    font-size: 13px;
    color: #b45309;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 14px;
    line-height: 1.45;
}

.twofa-confirm-save {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 13px;
    color: var(--text);
    margin-bottom: 12px;
    cursor: pointer;
    line-height: 1.4;
}

.twofa-confirm-save input {
    margin-top: 3px;
    flex-shrink: 0;
}

.btn-block {
    width: 100%;
    margin-top: 8px;
}

.sidebar-nav {
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    overflow-y: auto;
}

.input-readonly {
    background: var(--bg) !important;
    cursor: default;
}

.sidebar-nav a {
    color: var(--sidebar-text);
    text-decoration: none;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s;
}

.sidebar-nav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar-nav a.active { background: var(--sidebar-active); color: #fff; }

.sidebar-nav-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 4px;
}

.sidebar-nav-group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    border: none;
    background: transparent;
    color: var(--sidebar-text);
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s, color 0.15s;
}

.sidebar-nav-group-toggle:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.sidebar-nav-chevron {
    width: 0.45em;
    height: 0.45em;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(-45deg);
    transition: transform 0.15s ease;
    opacity: 0.75;
    flex-shrink: 0;
    margin-left: 8px;
}

.sidebar-nav-group.open .sidebar-nav-chevron {
    transform: rotate(45deg);
}

.sidebar-nav-group-items {
    display: none;
    flex-direction: column;
    gap: 2px;
    padding-left: 10px;
    border-left: 1px solid rgba(255, 255, 255, 0.12);
    margin: 0 0 2px 16px;
}

.sidebar-nav-group.open .sidebar-nav-group-items {
    display: flex;
}

.sidebar-nav-group-items a {
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
}

.main-content {
    margin-left: 260px;
    padding: 28px 32px;
    width: calc(100% - 260px);
    min-height: 100vh;
    overflow-x: auto;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
}

.btn {
    padding: 8px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* --- Busy / loading UX --- */
.btn.is-busy,
.btn:disabled.is-busy {
    position: relative;
    cursor: wait;
    opacity: 0.88;
    pointer-events: none;
}

.btn-busy-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-right: 8px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    vertical-align: -2px;
    animation: mandata-spin 0.7s linear infinite;
}

.btn-primary .btn-busy-spinner,
.btn-success .btn-busy-spinner,
.btn-danger .btn-busy-spinner {
    border-color: rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
}

.btn:not(.btn-primary):not(.btn-success):not(.btn-danger) .btn-busy-spinner {
    border-color: rgba(66, 80, 158, 0.25);
    border-top-color: var(--brand-blue);
}

@keyframes mandata-spin {
    to { transform: rotate(360deg); }
}

.mandata-skeleton {
    padding: 12px 0;
}

.mandata-skeleton-label {
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 12px;
}

.mandata-skel-bar {
    height: 12px;
    border-radius: 6px;
    margin-bottom: 10px;
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
    background-size: 200% 100%;
    animation: mandata-shimmer 1.2s ease-in-out infinite;
}

.mandata-skel-bar.w55 { width: 55%; }
.mandata-skel-bar.w75 { width: 75%; }
.mandata-skel-bar.h28 { height: 28px; }
.mandata-skel-bar.h40 { height: 40px; }

@keyframes mandata-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

#mandataGlobalBusy {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(66, 80, 158, 0.35);
}

#mandataGlobalBusy.is-visible {
    display: flex;
}

.mandata-global-busy-box {
    background: #fff;
    border-radius: var(--radius);
    padding: 28px 36px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    min-width: 180px;
}

.mandata-global-busy-spinner {
    width: 28px;
    height: 28px;
    border: 2.5px solid rgba(66, 80, 158, 0.2);
    border-top-color: var(--brand-blue);
    border-radius: 50%;
    animation: mandata-spin 0.7s linear infinite;
}

.mandata-global-busy-msg {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stats-grid[aria-busy="true"] {
    opacity: 0.55;
    pointer-events: none;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.stat-label {
    font-size: 13px;
    color: var(--text-light);
    font-weight: 500;
    margin-bottom: 6px;
}

.stat-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text);
}

.stat-sub {
    font-size: 13px;
    color: var(--text-light);
    margin-top: 4px;
}

.stat-card-danger {
    border-left: 4px solid var(--danger);
}

.stat-card-danger .stat-value {
    color: var(--danger);
}

.stat-card-warning {
    border-left: 4px solid var(--warning);
}

.stat-card-warning .stat-value {
    color: var(--warning);
}

.stat-card-info {
    border-left: 4px solid var(--info);
}

.stat-card-info .stat-value {
    color: var(--info);
}

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.chart-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.chart-card h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

.chart-card canvas { max-height: 280px; }

.mailbox-layout {
    display: grid;
    grid-template-columns: minmax(280px, 360px) 1fr;
    gap: 16px;
    align-items: start;
}

.mailbox-sidebar,
.mailbox-main {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.mailbox-toolbar {
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

.mailbox-toolbar input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
}

#mailboxDeudoresList {
    max-height: calc(100vh - 280px);
    overflow: auto;
    padding: 6px;
}

.mailbox-acreedor-block {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 10px;
    background: #fafbfc;
}

.mailbox-acreedor-block[open] > .mailbox-acreedor-summary {
    border-bottom: 1px solid var(--border);
}

.mailbox-acreedor-summary {
    list-style: none;
    cursor: pointer;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-weight: 600;
    color: var(--brand-blue);
}

.mailbox-acreedor-summary::-webkit-details-marker {
    display: none;
}

.mailbox-acreedor-name {
    font-size: 14px;
}

.mailbox-acreedor-rut {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-light);
}

.mailbox-acreedor-body {
    padding: 6px 8px 10px;
}

.mailbox-deudor-item {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    text-align: left;
    padding: 10px;
    margin-bottom: 8px;
    cursor: pointer;
}

.mailbox-deudor-item.active {
    border-color: var(--primary);
    box-shadow: inset 0 0 0 1px var(--primary-light);
}

.mailbox-deudor-top {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.mailbox-deudor-rut {
    color: var(--text-light);
    font-size: 12px;
}

.mailbox-deudor-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 12px;
    color: var(--text-light);
}

#mailboxDetail {
    padding: 16px;
}

.mailbox-detail-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 14px;
}

.mailbox-detail-kpis {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.mailbox-thread {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mailbox-conversation {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #f8fafc;
}

.mailbox-conversation-summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px;
    font-size: 12px;
}

.mailbox-conversation-summary::-webkit-details-marker {
    display: none;
}

.mailbox-msg {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
}

.mailbox-msg.inbound {
    border-left: 4px solid #10b981;
}

.mailbox-msg.outbound {
    border-left: 4px solid #3b82f6;
}

.mailbox-msg-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
    font-size: 12px;
}

.mailbox-msg-summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px;
    font-size: 12px;
}

.mailbox-msg-summary::-webkit-details-marker {
    display: none;
}

.mailbox-msg-summary-main {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mailbox-msg-summary-main strong {
    font-size: 14px;
    color: var(--text);
    font-weight: 600;
}

.mailbox-msg-body-wrap {
    border-top: 1px solid var(--border);
    padding: 12px;
}

.mailbox-msg h4 {
    font-size: 15px;
    margin-bottom: 4px;
}

.mailbox-msg-meta {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 4px;
}

.mailbox-msg-body {
    white-space: normal;
    line-height: 1.4;
    font-size: 14px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

@media (max-width: 1100px) {
    .mailbox-layout {
        grid-template-columns: 1fr;
    }
}

th {
    background: #f1f5f9;
    padding: 10px 14px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 10px 14px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

tr:hover td { background: #f8fafc; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

.badge-pending { background: #fef3c7; color: #92400e; }
.badge-carta { background: #dbeafe; color: #1e40af; }
.badge-notif { background: #e0e7ff; color: #3730a3; }
.badge-demanda { background: #fce7f3; color: #9d174d; }
.badge-extra { background: #fef3c7; color: #92400e; }
.badge-pre { background: #dbeafe; color: #1e40af; }
.badge-juicio { background: #fce7f3; color: #9d174d; }
.badge-caducado { background: #f3f4f6; color: #374151; font-weight: 600; }
.badge-paid { background: #d1fae5; color: #065f46; }
.badge-caducada { background: #fee2e2; color: #991b1b; font-weight: 700; }
.badge-por-caducar { background: #fff7ed; color: #9a3412; white-space: nowrap; }
.badge-vigente { background: #f0fdf4; color: #166534; }

.badge-estado-venc {
    white-space: nowrap;
    line-height: 1.25;
}
.badge-estado-vigente { background: #f0fdf4; color: #166534; border: 1px solid #9ccc9c; }
.badge-estado-por-caducar { background: #fffbeb; color: #92400e; border: 1px solid #d4b96a; }
.badge-estado-caducada { background: #fef2f2; color: #991b1b; border: 1px solid #d99a9a; }

.badge-dte-ok { background: #d1fae5; color: #065f46; }
.badge-dte-sin { background: #fef3c7; color: #92400e; }
.badge-dte-desc { background: #fee2e2; color: #991b1b; cursor: help; }
.badge-deudor-datos { background: #fef3c7; color: #92400e; font-size: 10px; font-weight: 600; margin-left: 2px; white-space: nowrap; }
.badge-inter { background: #ede9fe; color: #5b21b6; }
.badge-prep { background: #dbeafe; color: #1e3a8a; }
.badge-notif-pend { background: #cffafe; color: #0e7490; }
.badge-castigado { background: #e5e7eb; color: #374151; }
.badge-expediente { background: #fef3c7; color: #92400e; font-weight: 600; }

.stat-card-compact {
    padding: 10px 12px;
    min-height: auto;
}
.stat-card-compact .stat-label { font-size: 11px; }
.stat-card-compact .stat-value { font-size: 18px; }

.factura-tooltip-panel {
    position: fixed;
    z-index: 10000;
    max-width: 380px;
    padding: 12px 14px;
    font-size: 12px;
    line-height: 1.45;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    pointer-events: none;
}
.factura-tooltip-panel div { margin-bottom: 4px; }

/* ─── Tabla Facturas (responsive / compacta) ───────────────────────── */
.facturas-table-host {
    max-width: 100%;
}

.facturas-table-wrap {
    overflow-x: auto;
    overflow-y: visible;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--card-bg);
    box-shadow: var(--shadow);
}

.facturas-table-wrap:focus-visible {
    outline: 2px solid var(--primary-light);
    outline-offset: 2px;
}

.facturas-table-wrap .facturas-table {
    width: max-content;
    min-width: 100%;
    margin: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

.facturas-table-wrap .facturas-table th,
.facturas-table-wrap .facturas-table td {
    padding: 6px 8px;
    font-size: 12px;
    line-height: 1.35;
    vertical-align: middle;
}

.facturas-table-wrap .facturas-table th {
    font-size: 10px;
    padding: 7px 8px;
    white-space: nowrap;
}

.facturas-table-wrap .facturas-table .ft-col-entity {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.facturas-table-wrap .facturas-table .ft-col-date,
.facturas-table-wrap .facturas-table .ft-col-num,
.facturas-table-wrap .facturas-table .ft-col-money {
    white-space: nowrap;
}

.facturas-table-wrap .facturas-table .ft-col-money {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.facturas-table-wrap .facturas-table .ft-col-compact {
    font-size: 11px;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.facturas-table-wrap .facturas-table .ft-col-acciones {
    white-space: nowrap;
}

.facturas-table-wrap .facturas-table .ft-col-acciones .btn-sm {
    padding: 3px 7px;
    font-size: 10px;
    margin: 1px 0;
}

.facturas-table-wrap .facturas-table .ft-col-acciones select.btn-sm {
    max-width: 92px;
    padding: 3px 4px;
}

.facturas-table-wrap .facturas-table .ft-sticky-start {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--card-bg);
    box-shadow: 4px 0 8px -4px rgba(15, 23, 42, 0.1);
    width: 1%;
    max-width: 72px;
    min-width: 0;
    padding-left: 4px;
    padding-right: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-variant-numeric: tabular-nums;
    font-size: 11px;
}

.facturas-table-wrap .facturas-table thead .ft-sticky-start {
    max-width: 44px;
    text-align: center;
    padding-left: 3px;
    padding-right: 3px;
}

.facturas-table-wrap .facturas-table .ft-sticky-start.ft-col-grupo {
    max-width: 168px;
    width: auto;
    font-size: 12px;
}

.facturas-table-wrap .facturas-table .ft-sticky-start .badge-tipo-doc {
    display: block;
    margin: 2px 0 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.facturas-table-wrap .facturas-table .ft-sticky-end {
    position: sticky;
    right: 0;
    z-index: 2;
    background: var(--card-bg);
    box-shadow: -4px 0 8px -4px rgba(15, 23, 42, 0.1);
}

.facturas-table-wrap .facturas-table thead .ft-sticky-start,
.facturas-table-wrap .facturas-table thead .ft-sticky-end {
    z-index: 4;
    background: #f1f5f9;
}

.facturas-table-wrap .facturas-table thead tr.ti-filtros > :first-child {
    position: sticky;
    left: 0;
    z-index: 3;
    background: #f1f5f9;
    max-width: 72px;
    width: 72px;
    padding-left: 4px;
    padding-right: 4px;
}

.facturas-table-wrap .facturas-table thead tr.ti-filtros > :first-child input {
    width: 100%;
    min-width: 0;
    max-width: 64px;
    padding: 2px 4px;
    font-size: 11px;
}

.facturas-table-wrap .facturas-table thead tr.ti-filtros > :last-child {
    position: sticky;
    right: 0;
    z-index: 3;
    background: #f1f5f9;
}

.facturas-table-wrap .facturas-table tbody tr:hover .ft-sticky-start,
.facturas-table-wrap .facturas-table tbody tr:hover .ft-sticky-end {
    background: #f8fafc;
}

.facturas-table-wrap .facturas-table .badge {
    font-size: 10px;
    padding: 2px 7px;
}

@media (min-width: 901px) {
    .main-content:has(.facturas-table-host) {
        padding: 22px 20px;
    }
}

@media (max-width: 1540px) {
    .facturas-table-wrap .facturas-table .ft-col-optional-lg {
        display: none;
    }
}

@media (max-width: 1280px) {
    .facturas-table-wrap .facturas-table .ft-col-optional-md {
        display: none;
    }
}

@media (max-width: 900px) {
    .main-content:has(.facturas-table-host) {
        padding-left: 12px;
        padding-right: 12px;
    }

    .facturas-table-wrap .facturas-table th,
    .facturas-table-wrap .facturas-table td {
        padding: 5px 6px;
        font-size: 11px;
    }

    .facturas-table-wrap .facturas-table .ft-col-entity {
        max-width: 110px;
    }
}

.deposito-preview-dl {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 6px 12px;
    margin: 0;
    font-size: 13px;
}
.deposito-preview-dl dt {
    color: var(--text-light);
    font-weight: 600;
}
.deposito-preview-dl dd {
    margin: 0;
    font-weight: 500;
}
.deposito-form-card textarea {
    width: 100%;
    min-height: 72px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
}

.tareas-section { margin-bottom: 24px; }
.tarea-deudor-details {
    margin-bottom: 12px;
    padding: 10px 12px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.tarea-deudor-details summary { cursor: pointer; font-size: 14px; padding: 4px 0; }
.tareas-h2 { font-size: 1.05rem; margin: 20px 0 10px; color: var(--text); }

.agrupar-facturas-list { display: flex; flex-direction: column; gap: 8px; max-height: 280px; overflow-y: auto; margin-top: 10px; }
.agrupar-line { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; cursor: pointer; }
.agrupar-line input { margin-top: 3px; flex-shrink: 0; }

.fila-grupo-ag { background: #f8fafc; }
.fila-grupo-ag td { border-top: 2px solid var(--border); }
.fila-ag-miembro td { background: #fafbfc; font-size: 12px; }
.fila-ag-indent { padding-left: 28px !important; color: var(--text-light); }
.tareas-h3 { font-size: 0.95rem; margin: 12px 0 8px; color: var(--text-light); }
.tareas-list { list-style: none; padding: 0; }
.tarea-item {
    padding: 12px 14px;
    margin-bottom: 10px;
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.tarea-prio-alta { border-left: 4px solid var(--danger); }
.tarea-prio-media { border-left: 4px solid var(--warning); }
.tarea-detalle { font-size: 12px; margin-top: 6px; }
.muted { color: var(--text-light); font-size: 13px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }

/* Deudor / Acreedor: ~75% del ancho típico de entidad (150px → 112px) */
#pagosRoot .data-table .col-entity,
#pagosRoot .data-table th.col-entity {
    max-width: 112px;
    width: 112px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.actividad-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 320px;
    overflow-y: auto;
}

.actividad-list li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.act-notas {
    color: var(--text-light);
    font-size: 13px;
    margin-top: 6px;
    white-space: pre-wrap;
}

/* ─── Modal actividades de factura ─────────────────────────────────── */
.factura-act-modal .modal-content {
    max-width: 720px;
}

.act-modal-subtitle {
    margin: 4px 0 0;
    font-size: 13px;
}

.act-modal-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.act-modal-section-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.act-modal-section-head h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-light);
}

.act-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    border-radius: 999px;
    background: var(--primary-light, #eef0f8);
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
}

.act-timeline {
    display: flex;
    flex-direction: column;
    gap: 0;
    max-height: 340px;
    overflow-y: auto;
    padding-right: 4px;
}

.act-timeline-item {
    display: grid;
    grid-template-columns: 36px 1fr;
    gap: 12px;
    padding-bottom: 16px;
    position: relative;
}

.act-timeline-item:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 17px;
    top: 32px;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.act-timeline-marker {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 2px;
}

.act-tipo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--card-bg);
    border: 2px solid var(--border);
    font-size: 15px;
    line-height: 1;
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,.06));
}

.act-timeline-body {
    background: var(--bg, #f8fafc);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
}

.act-timeline-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    margin-bottom: 4px;
}

.act-timeline-head time {
    font-size: 12px;
    color: var(--text-light);
    font-variant-numeric: tabular-nums;
}

.act-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.act-badge-llamada { background: #dbeafe; color: #1d4ed8; }
.act-badge-correo { background: #e0e7ff; color: #4338ca; }
.act-badge-carta { background: #fef3c7; color: #b45309; }
.act-badge-default { background: #f1f5f9; color: #475569; }

.act-timeline-meta {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 2px;
}

.act-adjunto-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    font-size: 12px;
    font-weight: 500;
    color: var(--primary);
    text-decoration: none;
}

.act-adjunto-link:hover { text-decoration: underline; }

.act-empty {
    text-align: center;
    padding: 28px 16px;
    border: 1px dashed var(--border);
    border-radius: 10px;
    background: var(--bg, #f8fafc);
}

.act-empty-icon {
    font-size: 28px;
    margin-bottom: 8px;
    opacity: 0.7;
}

.act-empty p { margin: 0 0 4px; font-size: 14px; }

.act-form-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    background: linear-gradient(180deg, #fff 0%, var(--bg, #f8fafc) 100%);
}

.act-form-card h4 {
    margin: 0 0 14px;
    font-size: 15px;
    font-weight: 600;
}

.act-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 14px;
}

.act-form-grid .form-group-full { grid-column: 1 / -1; }

@media (max-width: 560px) {
    .act-form-grid { grid-template-columns: 1fr; }
}

.act-form-hint {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-light);
}

.act-file-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.act-file-wrap input[type="file"] {
    font-size: 13px;
    max-width: 100%;
}

.act-form-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 12px;
    width: 90%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-lg { max-width: 800px; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text-light);
    padding: 4px;
}

.modal-body { padding: 20px 24px; }

.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s;
    color: var(--text-light);
}

.upload-area:hover { border-color: var(--primary); }
.upload-area.dragover { border-color: var(--primary); background: #eef2ff; }

.upload-hint {
    font-size: 12px;
    color: var(--text-light);
    text-align: center;
    margin-top: 12px;
}

.progress-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin: 12px 0;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s;
    width: 0%;
}

.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 5px; font-size: 13px; font-weight: 600; color: var(--text); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text);
    background: var(--card-bg);
}
.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.form-group label.checkbox-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0;
    cursor: pointer;
    font-weight: 600;
}

.form-group input[type="checkbox"],
.form-group input[type="radio"] {
    width: auto;
    flex: 0 0 auto;
    padding: 0;
    margin: 0;
    box-shadow: none;
}

.form-group input[type="checkbox"]:focus,
.form-group input[type="radio"]:focus {
    box-shadow: none;
    outline: 2px solid rgba(79, 70, 229, 0.35);
    outline-offset: 2px;
}

.filters-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.filters-bar select, .filters-bar input {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    background: var(--card-bg);
}

.filters-bar input { flex: 1; }

.checkbox-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
}

.checkbox-list label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    cursor: pointer;
    font-size: 13px;
    border-radius: 4px;
}

.checkbox-list input[type="checkbox"] {
    width: auto;
    flex: 0 0 auto;
    margin: 0;
}

.checkbox-list label:hover { background: #f1f5f9; }

.doc-gen-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
}

.doc-gen-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.doc-gen-card h3 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--primary-dark);
}

.doc-gen-card p {
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 16px;
    line-height: 1.5;
}

.deudor-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 16px;
    cursor: pointer;
    transition: box-shadow 0.15s;
}

.deudor-card:hover { box-shadow: var(--shadow-lg); }

.deudor-card .deudor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.deudor-card .deudor-name {
    font-size: 16px;
    font-weight: 700;
}

.deudor-card .deudor-total {
    font-size: 18px;
    font-weight: 700;
    color: var(--danger);
}

.deudor-card .deudor-meta {
    font-size: 12px;
    color: var(--text-light);
}

.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 13px;
}

.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }
.alert-warning { background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; }

.upload-dual {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.upload-section h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.descuadre-detail {
    margin-top: 6px;
    font-size: 11px;
}

.descuadre-item {
    background: #fee2e2;
    color: #991b1b;
    padding: 3px 8px;
    border-radius: 4px;
    margin-top: 3px;
    line-height: 1.4;
}

/* ---- Upload Panel (floating bottom-right) ---- */
.upload-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 400px;
    max-height: 420px;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.08);
    border: 1px solid var(--border);
    z-index: 2000;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.upload-panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--sidebar-bg);
    color: #fff;
    cursor: pointer;
    user-select: none;
    flex-shrink: 0;
}

.upload-panel-title {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
}

.upload-panel-counter {
    font-size: 11px;
    background: rgba(255,255,255,0.2);
    padding: 2px 10px;
    border-radius: 10px;
    font-weight: 600;
}

.upload-panel-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 18px;
    padding: 0 4px;
    opacity: 0.7;
    line-height: 1;
}

.upload-panel-btn:hover { opacity: 1; }

.upload-panel-body {
    overflow-y: auto;
    max-height: 340px;
    padding: 8px 0;
}

.upload-panel-cliente-msg {
    padding: 20px 18px;
    text-align: center;
    font-size: 14px;
    line-height: 1.5;
}

.upload-panel-cliente-msg .upload-item-icon {
    display: block;
    font-size: 28px;
    margin-bottom: 10px;
    color: var(--success, #16a34a);
}

.upload-panel-cliente-msg .upload-item-icon-spin {
    display: inline-block;
    animation: uploadSpin 1s linear infinite;
    color: var(--primary, #2563eb);
}

.upload-panel-cliente-msg .muted {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 6px;
}

.carga-revision-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 12px;
    background: var(--card-bg);
}

.revision-cliente-group {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 18px;
    margin-bottom: 20px;
    background: var(--card-bg);
}

.revision-cliente-header,
.revision-subida-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.revision-cliente-header h3,
.revision-subida-header h4 {
    margin: 0 0 4px;
}

.revision-subida-group {
    border-left: 3px solid var(--primary, #2563eb);
    padding-left: 14px;
    margin: 14px 0 0;
}

.revision-subida-cargas .carga-revision-card:last-child {
    margin-bottom: 0;
}

.revision-pendientes-summary {
    margin-bottom: 16px;
}

.revision-pendientes-summary h2 {
    margin-bottom: 4px;
}

.carga-revision-card h4 {
    margin: 0 0 6px;
    font-size: 15px;
}

.carga-revision-meta {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 8px;
}

.carga-revision-detalle {
    font-size: 12px;
    background: var(--bg);
    border-radius: 6px;
    padding: 10px;
    margin: 8px 0;
    max-height: 200px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.sidebar-badge {
    display: inline-block;
    min-width: 18px;
    padding: 1px 6px;
    margin-left: 6px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    text-align: center;
}

.upload-panel-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    font-size: 12px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.upload-panel-item:last-child { border-bottom: none; }

.upload-item-icon {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
}

.upload-panel-item.processing .upload-item-icon {
    animation: uploadSpin 1s linear infinite;
    color: var(--primary);
}

@keyframes uploadSpin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.upload-item-info {
    flex: 1;
    min-width: 0;
}

.upload-item-name {
    display: block;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
}

.upload-item-type {
    font-size: 10px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.upload-item-status {
    font-size: 11px;
    color: var(--text-light);
    white-space: nowrap;
    flex-shrink: 0;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.upload-panel-item.queued { background: #fafafa; }
.upload-panel-item.queued .upload-item-icon { color: var(--text-light); }
.upload-panel-item.done .upload-item-icon { color: var(--success); }
.upload-panel-item.done .upload-item-status { color: var(--success); font-weight: 600; }
.upload-panel-item.error .upload-item-icon { color: var(--danger); }
.upload-panel-item.error .upload-item-status { color: var(--danger); font-weight: 600; }

/* Desglose cálculo de cobro (modal facturas) */
.calculo-tabla {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin: 8px 0 12px;
}
.calculo-tabla th,
.calculo-tabla td {
    border: 1px solid var(--border);
    padding: 6px 8px;
    text-align: left;
}
.calculo-tabla thead th {
    background: var(--bg);
    font-weight: 600;
}
.calculo-dl {
    margin: 8px 0 16px;
    padding-left: 1.25rem;
}
.calculo-dl li { margin: 4px 0; }
.calculo-warn {
    background: #fff8e6;
    border: 1px solid #f0d060;
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 12px;
    font-size: 13px;
}
.calculo-warn ul { margin: 6px 0 0 1rem; }
.calculo-total-final {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 2px solid var(--border);
    color: var(--text);
}
.calculo-total-cel { cursor: pointer; }

/* Promesas de pago */
.promesas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
}
.promesas-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
}
.promesas-card h3 {
    margin-bottom: 12px;
}
.promesas-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
}
.promesa-review-item {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
}
.promesa-review-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.promesa-facturas-sum {
    margin-top: 8px;
    font-weight: 600;
    color: var(--text);
}
.promesas-calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.promesas-month-title {
    font-weight: 700;
    margin-bottom: 8px;
}
.promesas-calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 6px;
}
.promesas-calendar-weekday {
    font-size: 12px;
    color: var(--text-light);
    text-align: center;
    font-weight: 600;
}
.promesas-calendar-cell {
    min-height: 96px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px;
    background: #fff;
}
.promesas-calendar-cell.empty {
    background: transparent;
    border-style: dashed;
}
.promesas-day-num {
    font-weight: 700;
    font-size: 12px;
    margin-bottom: 4px;
}
.promesas-day-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.promesas-day-item {
    font-size: 11px;
    line-height: 1.2;
    background: #f8fafc;
    border-radius: 6px;
    padding: 4px 6px;
}

@media (max-width: 900px) {
    body {
        display: block;
    }

    .mobile-menu-toggle {
        display: inline-flex;
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 220;
        align-items: center;
        gap: 6px;
        border: 1px solid var(--border);
        background: #fff;
        color: var(--text);
        border-radius: 999px;
        padding: 10px 14px;
        font-size: 13px;
        font-weight: 600;
        box-shadow: var(--shadow);
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        z-index: 180;
        width: 100%;
        height: 100%;
        border: 0;
        background: rgba(2, 6, 23, 0.5);
    }

    body.sidebar-open .sidebar-overlay {
        display: block;
    }

    .sidebar {
        z-index: 200;
        width: min(88vw, 320px);
        max-width: 320px;
        height: 100vh;
        height: 100dvh;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        will-change: transform;
        box-shadow: var(--shadow-lg);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-header {
        justify-content: space-between;
        gap: 8px;
    }

    .sidebar-logo {
        width: auto;
        max-width: min(72%, calc(100% - 48px));
    }

    .sidebar-close-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 34px;
        height: 34px;
        border: 1px solid rgba(66, 80, 158, 0.35);
        border-radius: 999px;
        background: transparent;
        color: var(--brand-blue);
        font-size: 22px;
        line-height: 1;
        cursor: pointer;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        min-height: 100vh;
        min-height: 100dvh;
        padding: 64px 14px 20px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .acreedor-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .acreedor-select {
        min-width: 0;
        width: 100%;
    }

    .stats-grid,
    .charts-grid,
    .upload-dual,
    .doc-gen-container,
    .promesas-grid {
        grid-template-columns: 1fr;
    }

    .filters-bar {
        flex-direction: column;
    }

    .modal-content {
        width: min(94vw, 560px);
        max-height: 92dvh;
    }

    .upload-panel {
        left: 10px;
        right: 10px;
        width: auto;
        max-height: 45dvh;
        bottom: 10px;
    }
}

.portal-empresa-banner {
    background: var(--surface-elevated, #f4f4f5);
    border: 1px solid var(--border, #e4e4e7);
}
.portal-empresa-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-light);
    font-weight: 600;
}
.portal-empresa-nombre {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    flex: 1;
}
.portal-empresa-select {
    max-width: 360px;
}
.badge-pago-none { background: #e4e4e7; color: #3f3f46; }
.badge-pago-partial { background: #fef3c7; color: #92400e; }
.badge-pago-full { background: #d1fae5; color: #065f46; }
.badge-pago-castigo { background: #ede9fe; color: #5b21b6; }
#mandataChatbotRoot { position: fixed; right: 20px; bottom: 20px; z-index: 9999; font-family: inherit; }
.chatbot-fab {
    width: 56px; height: 56px; border-radius: 50%; border: none;
    background: linear-gradient(135deg, var(--primary, #192359) 0%, var(--primary-dark, #121a42) 100%);
    color: #fff; font-size: 24px; cursor: pointer;
    box-shadow: 0 6px 24px rgba(66, 80, 158, 0.45);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex; align-items: center; justify-content: center;
}
.chatbot-fab:hover { transform: scale(1.05); box-shadow: 0 8px 28px rgba(66, 80, 158, 0.55); }
.chatbot-panel {
    position: absolute; right: 0; bottom: 68px; width: 380px; max-width: calc(100vw - 32px);
    height: 520px; max-height: calc(100vh - 120px);
    background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 20px;
    display: flex; flex-direction: column;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.18);
    overflow: hidden;
}
.chatbot-header {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 14px 16px; background: linear-gradient(135deg, var(--primary, #192359), var(--primary-dark, #121a42));
    color: #fff;
}
.chatbot-header-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chatbot-avatar {
    width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,0.2);
    display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0;
}
.chatbot-header-title { font-weight: 600; font-size: 14px; line-height: 1.2; }
.chatbot-header-status { font-size: 11px; opacity: 0.85; }
.chatbot-close {
    border: none; background: rgba(255,255,255,0.15); color: #fff; cursor: pointer;
    width: 32px; height: 32px; border-radius: 50%; font-size: 18px; line-height: 1;
    flex-shrink: 0;
}
.chatbot-close:hover { background: rgba(255,255,255,0.28); }
.chatbot-messages {
    flex: 1; overflow-y: auto; padding: 16px 14px;
    display: flex; flex-direction: column; gap: 4px;
    background: linear-gradient(180deg, #eef2ff 0%, #f8fafc 40%);
    scroll-behavior: smooth;
}
.chatbot-row { display: flex; margin-bottom: 6px; }
.chatbot-row-user { justify-content: flex-end; }
.chatbot-row-assistant { justify-content: flex-start; }
.chatbot-bubble {
    max-width: 82%; padding: 10px 14px; border-radius: 18px;
    font-size: 14px; line-height: 1.45; word-wrap: break-word;
}
.chatbot-bubble-user {
    background: linear-gradient(135deg, #192359, #121a42); color: #fff;
    border-bottom-right-radius: 4px;
}
.chatbot-bubble-assistant {
    background: #fff; color: #1e293b; border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.chatbot-typing {
    display: none; align-self: flex-start; margin-bottom: 6px;
    padding: 12px 16px; background: #fff; border: 1px solid #e2e8f0;
    border-radius: 18px; border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.chatbot-typing.is-visible { display: flex; align-items: center; gap: 8px; }
.chatbot-typing-label { font-size: 12px; color: #64748b; }
.chatbot-typing-dots { display: flex; gap: 4px; align-items: center; }
.chatbot-typing-dots span {
    width: 7px; height: 7px; border-radius: 50%; background: #94a3b8;
    animation: chatbot-typing-bounce 1.2s ease-in-out infinite;
}
.chatbot-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.chatbot-typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatbot-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
    30% { transform: translateY(-5px); opacity: 1; }
}
.chatbot-input-row {
    display: flex; gap: 8px; padding: 12px 14px; background: #fff;
    border-top: 1px solid #e2e8f0; align-items: center;
}
.chatbot-input-row input {
    flex: 1; border: 1px solid #e2e8f0; border-radius: 24px;
    padding: 10px 16px; font-size: 14px; background: #f8fafc;
    outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.chatbot-input-row input:focus {
    border-color: var(--primary, #192359);
    box-shadow: 0 0 0 3px rgba(66, 80, 158, 0.12);
    background: #fff;
}
.chatbot-send {
    width: 40px; height: 40px; border-radius: 50%; border: none;
    background: var(--primary, #192359); color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: opacity 0.15s, transform 0.15s;
}
.chatbot-send:hover:not(:disabled) { transform: scale(1.05); }
.chatbot-send:disabled { opacity: 0.45; cursor: not-allowed; }

.clientes-resumen-stats { margin-bottom: 8px; }
.clientes-admin-table th.num,
.clientes-admin-table td.num { text-align: right; white-space: nowrap; }

/* ─── Test Panel (/test-panel) ─────────────────────────────────────── */
.test-panel-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.test-panel-tab.active { font-weight: 600; background: var(--primary); color: #fff; }
.health-row {
    display: flex; align-items: center; gap: 8px; padding: 8px 12px;
    border-radius: 6px; margin-bottom: 4px;
    background: var(--card-bg); border: 1px solid var(--border);
}
.health-row strong { min-width: 140px; }
.mermaid-container {
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; margin: 12px 0 24px 0;
    overflow-x: auto; min-height: 80px;
}
.mermaid-container pre { font-size: 11px; color: var(--text); white-space: pre-wrap; }

/* ─── Toasts ───────────────────────────────────────────────────────── */
#toastContainer { position: fixed; top: 16px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; padding: 12px 16px; border-radius: 8px; font-size: 14px; max-width: 380px; display: flex; align-items: center; justify-content: space-between; gap: 12px; box-shadow: 0 4px 16px rgba(0,0,0,0.18); animation: toastIn 0.2s ease; }
.toast-info { background: #1e293b; color: #f1f5f9; }
.toast-success { background: #14532d; color: #dcfce7; }
.toast-error { background: #7f1d1d; color: #fef2f2; }
.toast-warning { background: #78350f; color: #fff7ed; }
.toast-close { background: none; border: none; cursor: pointer; color: inherit; font-size: 18px; padding: 0; line-height: 1; }
@keyframes toastIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── Badges tipo de documento ─────────────────────────────────────── */
.badge-tipo-doc { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; vertical-align: middle; margin-left: 6px; }
.badge-td-cheque { background: #fed7aa; color: #c2410c; }
.badge-td-pagare { background: #e9d5ff; color: #7c3aed; }
.badge-td-contrato { background: #d1fae5; color: #065f46; }
.badge-td-otro { background: #f3f4f6; color: #4b5563; }

/* ---- Dashboard: centro de operaciones ---- */
.stat-card-hero {
    grid-column: span 2;
    container-type: inline-size;
    min-width: min(100%, 260px);
}

.stat-card-hero .stat-value {
    font-size: clamp(1.35rem, 9cqi, 2rem);
    font-weight: 700;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.stat-card-hero .stat-label {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stats-workflow-wrap { display: flex !important; flex-wrap: wrap; gap: 8px; }
.stats-workflow-wrap .stat-card-compact { flex: 1 1 120px; }

@media (max-width: 520px) {
    .stat-card-hero {
        grid-column: 1 / -1;
    }
}

.atencion-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 20px 0; }
.atencion-card ul { list-style: none; margin: 0; padding: 0; }
.atencion-card li {
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
    padding: 8px 0; border-bottom: 1px solid rgba(0, 0, 0, 0.08); font-size: 14px;
}
.atencion-card li:last-child { border-bottom: none; }
.atencion-ok { color: #16a34a; font-weight: 600; }
.atencion-num-danger { color: #dc2626; font-weight: 700; white-space: nowrap; }
.atencion-num-warning { color: #d97706; font-weight: 700; white-space: nowrap; }

/* Documentos de la factura (modal actividades) */
.doc-list {
    list-style: none;
    margin: 0 0 16px;
    padding: 0;
}
.doc-list-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 6px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}
.doc-list-item:last-child {
    border-bottom: none;
}
.doc-list-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.doc-list-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    align-items: center;
}
.doc-list-btn {
    white-space: nowrap;
}
.doc-list-meta {
    font-size: 12px;
}

/* Popover causa (doble clic en columna Causa de facturas) */
.ft-causa-cel {
    cursor: pointer;
    user-select: none;
}
.ft-causa-popover {
    position: absolute;
    z-index: 1200;
    min-width: 220px;
    max-width: 320px;
    padding: 12px 14px;
    background: #fff;
    border: 1px solid var(--border, #d8dce8);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(26, 32, 56, 0.16);
    font-size: 13px;
    color: var(--text, #1a1a1a);
}
.ft-causa-popover-title {
    font-weight: 600;
    margin-bottom: 8px;
}
.ft-causa-popover-dl {
    margin: 0 0 12px;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 10px;
}
.ft-causa-popover-dl dt {
    margin: 0;
    color: var(--muted, #606060);
    font-weight: 500;
}
.ft-causa-popover-dl dd {
    margin: 0;
}

@media (max-width: 900px) { .atencion-grid { grid-template-columns: 1fr; } }

/* Tabla interactiva: filtros por columna y ordenamiento */
.ti-th-sortable {
    cursor: pointer;
    user-select: none;
}
.ti-sort-ind {
    font-size: 10px;
    opacity: 0.75;
}
.ti-filtros th {
    padding: 4px 6px;
    background: rgba(0, 0, 0, 0.02);
}
.ti-filtro-input {
    width: 100%;
    box-sizing: border-box;
    padding: 4px 6px;
    font-size: 12px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}
.ti-sin-resultados td {
    text-align: center;
    color: #777;
    font-style: italic;
    padding: 14px;
}

/* Estado vacío (p. ej. dashboard del cliente sin documentos) */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: var(--card, #ffffff);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 56px 32px;
    margin-top: 8px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}
.empty-state-icon {
    width: 96px;
    height: 96px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(66, 80, 158, 0.08);
    color: var(--primary);
    margin-bottom: 20px;
}
.empty-state h2 {
    margin: 0 0 8px;
    font-size: 20px;
    color: var(--text, #0f172a);
}
.empty-state p {
    margin: 0 0 24px;
    max-width: 480px;
    color: var(--text-light);
    line-height: 1.5;
}
