/* ═══════════════════════════════════════════════
   VIKAR GPS — Design System (estilo Buk / SaaS)
   ═══════════════════════════════════════════════ */
:root {
    /* Paleta Buk — azul corporativo vivo */
    --primary: #2B4EB4;
    --primary-dark: #1A3278;
    --primary-mid: #3366CC;
    --primary-glow: rgba(43, 78, 180, .14);
    --primary-light: #E8EEFB;
    --primary-soft: #F0F4FC;
    --accent: #4F7BF7;
    --sidebar-bg: #152847;
    --sidebar-bg-hover: #1C3260;
    --sidebar-active: #2B4EB4;
    --accent-warm: #F5C542;
    --sidebar-w: 260px;
    --topbar-h: 64px;
    --bg: #F0F4FA;
    --bg-subtle: #E8EEF6;
    --surface: #FFFFFF;
    --surface-2: #F8FAFD;
    --text: #1A2332;
    --text-2: #3D4F66;
    --text-muted: #6B7C93;
    --border: #DDE4EF;
    --border-light: #EEF2F8;
    --success: #10B981;
    --success-text: #047857;
    --success-bg: #ECFDF5;
    --success-soft: #A7F3D0;
    --warning: #F59E0B;
    --warning-text: #B45309;
    --warning-bg: #FFFBEB;
    --warning-soft: #FDE68A;
    --danger: #EF4444;
    --danger-text: #DC2626;
    --danger-bg: #FEF2F2;
    --danger-soft: #FECACA;
    --info: #0EA5E9;
    --info-text: #0369A1;
    --info-bg: #F0F9FF;
    --radius: 16px;
    --radius-sm: 10px;
    --radius-lg: 20px;
    --radius-pill: 999px;
    --shadow-xs: 0 1px 2px rgba(26, 35, 50, .04);
    --shadow-sm: 0 2px 8px rgba(26, 35, 50, .06);
    --shadow: 0 4px 24px rgba(26, 35, 50, .07);
    --shadow-lg: 0 24px 48px rgba(26, 35, 50, .12);
    --transition: .2s cubic-bezier(.4, 0, .2, 1);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    font-size: 14px;
    overflow-x: hidden;
    max-width: 100%;
}

.hidden { display: none !important; }
.text-muted { color: var(--text-muted); font-size: .875rem; line-height: 1.5; }

/* ─── Login ─── */
.login-screen {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    background: var(--surface);
}

.login-left {
    background: linear-gradient(160deg, #4F7BF7 0%, #3366CC 55%, #2B4EB4 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem;
    position: relative;
    overflow: hidden;
}
.login-left::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 20% 80%, rgba(255,255,255,.12) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255,255,255,.08) 0%, transparent 40%);
}
.login-left::after {
    content: '';
    position: absolute;
    bottom: -120px; right: -120px;
    width: 400px; height: 400px;
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 50%;
}
.login-brand { position: relative; color: #fff; max-width: 420px; z-index: 1; }
.login-logo {
    width: 52px; height: 52px;
    background: rgba(255,255,255,.2);
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; font-weight: 800;
    margin-bottom: 2rem;
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,.25);
    box-shadow: 0 8px 32px rgba(0,0,0,.15);
}
.login-brand h1 { font-size: 2.25rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.15; }
.login-wordmark {
    font-weight: 800; font-size: 3.25rem; color: #fff;
    letter-spacing: -.04em; line-height: 1;
}
.login-brand > p { margin-top: 1.25rem; opacity: .88; font-size: 1rem; line-height: 1.65; font-weight: 400; }

.login-right {
    display: flex; align-items: center; justify-content: center;
    padding: 3rem; background: var(--surface);
}
.login-card { width: 100%; max-width: 400px; }
.login-card h2 { font-size: 1.625rem; font-weight: 800; color: var(--text); letter-spacing: -.02em; }
.login-sub { color: var(--text-muted); font-size: .9rem; margin: .5rem 0 2rem; }

/* Accesos sutiles bajo el formulario de login */
.login-links {
    margin-top: 1.5rem;
    display: flex; align-items: center; justify-content: center;
    flex-wrap: wrap; gap: .5rem;
    text-align: center;
}
.login-link {
    color: var(--text-muted); font-size: .8125rem; font-weight: 500;
    text-decoration: none; opacity: .8;
    transition: color var(--transition), opacity var(--transition);
}
.login-link:hover { color: var(--primary); opacity: 1; }
.login-link-sep { color: var(--border); font-size: .8125rem; }

/* ─── Forms ─── */
.form-group { margin-bottom: 1.25rem; }
.form-group label {
    display: block; font-size: .8125rem; font-weight: 600;
    color: var(--text-2); margin-bottom: .5rem;
}
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: .75rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .9375rem; font-family: inherit;
    transition: border-color var(--transition), box-shadow var(--transition);
    background: var(--surface); color: var(--text);
}
.form-group input::placeholder { color: #A0AEC0; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    padding: .625rem 1.25rem; border: none; border-radius: var(--radius-sm);
    font-size: .875rem; font-weight: 600; cursor: pointer;
    transition: all var(--transition); font-family: inherit; white-space: nowrap;
}
.btn-primary {
    background: var(--primary); color: #fff;
    box-shadow: 0 2px 8px var(--primary-glow);
}
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 16px var(--primary-glow); transform: translateY(-1px); }
.btn-secondary {
    background: var(--surface); color: var(--text-2);
    border: 1.5px solid var(--border);
    box-shadow: var(--shadow-xs);
}
.btn-secondary:hover { background: var(--surface-2); border-color: #CBD5E1; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: .5rem 1rem; font-size: .8125rem; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #DC2626; }
.link-btn { color: var(--primary); font-size: .8125rem; font-weight: 600; background: none; border: none; cursor: pointer; font-family: inherit; }
.link-btn:hover { text-decoration: underline; }

.error-msg {
    background: var(--danger-bg); color: var(--danger-text);
    padding: .875rem 1rem; border-radius: var(--radius-sm);
    font-size: .875rem; margin-bottom: 1rem; border: 1px solid var(--danger-soft);
}

/* ─── App Shell ─── */
.app-shell {
    display: flex;
    min-height: 100vh;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

/* Sidebar estilo Buk — navy oscuro */
.sidebar {
    width: var(--sidebar-w); min-width: var(--sidebar-w);
    background: var(--sidebar-bg);
    border-right: none;
    display: flex; flex-direction: column;
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 200;
    transition: transform var(--transition);
    box-shadow: 4px 0 24px rgba(21, 40, 71, .18);
}
.sidebar-brand {
    padding: 1.5rem 1.5rem 1rem;
}
.sidebar-logo {
    font-weight: 800; font-size: 1.5rem; color: #fff;
    letter-spacing: -.03em; line-height: 1;
}
.sidebar-greeting {
    display: flex; align-items: center; gap: .75rem;
    padding: 0 1.25rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    margin-bottom: .5rem;
}
.sidebar-greeting .avatar {
    width: 44px; height: 44px;
    background: linear-gradient(135deg, var(--accent), var(--primary-mid));
    color: #fff; border: 2px solid rgba(255, 255, 255, .2);
    font-size: .875rem;
}
.greeting-hi { display: block; font-size: .75rem; color: rgba(255, 255, 255, .55); }
.sidebar-greeting strong {
    display: block; color: #fff; font-size: .9375rem; font-weight: 700;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px;
}
.greeting-role { display: block; font-size: .6875rem; color: rgba(255, 255, 255, .45); margin-top: .1rem; }

.sidebar-nav {
    flex: 1;
    padding: .5rem .875rem 1rem;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.sidebar-nav::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}
.nav-section-label {
    font-size: .625rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .08em; color: rgba(255, 255, 255, .35);
    padding: .875rem .75rem .4rem; margin-top: .25rem;
}
.nav-item {
    display: flex; align-items: center; gap: .75rem;
    width: 100%; padding: .7rem 1rem;
    border: none; background: transparent;
    color: rgba(255, 255, 255, .78);
    font-size: .875rem; font-weight: 500;
    border-radius: 10px;
    cursor: pointer; transition: all var(--transition);
    font-family: inherit; margin-bottom: 3px;
    position: relative;
}
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; opacity: .75; transition: opacity var(--transition); }
.nav-item:hover { background: var(--sidebar-bg-hover); color: #fff; }
.nav-item:hover svg { opacity: 1; }
.nav-item.active {
    background: var(--sidebar-active); color: #fff; font-weight: 600;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .2);
}
.nav-item.active::before {
    content: ''; position: absolute; left: -0.875rem; top: 50%; transform: translateY(-50%);
    width: 4px; height: 24px; background: var(--accent-warm); border-radius: 0 4px 4px 0;
}
.nav-item.active svg { opacity: 1; }
.nav-badge {
    margin-left: auto; font-size: .6875rem; font-weight: 700;
    padding: .15rem .5rem; border-radius: var(--radius-pill); min-width: 20px; text-align: center;
}
.nav-badge.danger { background: var(--danger); color: #fff; }
.nav-divider { height: 1px; background: rgba(255, 255, 255, .08); margin: .5rem .5rem; }

.sidebar-footer {
    padding: 1rem 1.25rem; border-top: 1px solid rgba(255, 255, 255, .08);
    display: flex; align-items: center; gap: .5rem;
    background: rgba(0, 0, 0, .15);
}
.sidebar-user { display: flex; align-items: center; gap: .625rem; flex: 1; min-width: 0; }
.avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--primary-mid));
    color: #fff; border: 2px solid rgba(255, 255, 255, .15);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .8125rem; flex-shrink: 0;
}
.sidebar-user strong { display: block; color: #fff; font-size: .8125rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user span { color: #6EE7A0; font-size: .6875rem; font-weight: 500; }
.sidebar-user span::before { content: '● '; font-size: .5rem; vertical-align: middle; }
/* Footer admin sin avatar: solo nombre + "Conectado" + botón salir. Se quita el
   ícono redondo (markup) y el puntito verde (este ::before), dejando el bloque
   prolijo. No afecta al footer del portal cliente (que conserva avatar y punto). */
.sidebar-user.no-avatar span::before { content: none; }
.btn-logout {
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, .15); background: transparent;
    color: rgba(255, 255, 255, .6); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all var(--transition); flex-shrink: 0;
}
.btn-logout svg { width: 18px; height: 18px; }
.btn-logout:hover { background: rgba(239, 68, 68, .2); color: #FCA5A5; border-color: rgba(239, 68, 68, .3); }

/* Main */
.main-area {
    margin-left: var(--sidebar-w);
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: var(--bg);
    min-width: 0;
    max-width: 100%;
    overflow-x: hidden;
}

.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border-light);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1.75rem;
    position: sticky; top: 0; z-index: 100;
    gap: 1rem;
}
.topbar-left { display: flex; align-items: center; gap: 1rem; flex-shrink: 0; }
.topbar-center { flex: 1; max-width: 480px; margin: 0 auto; }
.global-search {
    display: flex; align-items: center; gap: .625rem;
    background: var(--bg); border: 1.5px solid var(--border);
    border-radius: var(--radius-pill); padding: .5rem 1.125rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.global-search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-glow); background: var(--surface); }
.global-search svg { width: 18px; height: 18px; color: var(--text-muted); flex-shrink: 0; }
.global-search input {
    flex: 1; border: none; background: transparent; font-size: .875rem;
    font-family: inherit; color: var(--text); outline: none; min-width: 0;
}
.global-search input::placeholder { color: var(--text-muted); }
.page-title { font-size: 1.375rem; font-weight: 700; color: var(--text); letter-spacing: -.02em; }
.page-sub { font-size: .8125rem; color: var(--text-muted); margin-top: .125rem; }
.topbar-right { display: flex; align-items: center; gap: .75rem; flex-shrink: 0; }
.topbar-icon-btn {
    position: relative; width: 40px; height: 40px; border-radius: 50%;
    border: 1.5px solid var(--border); background: var(--surface);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all var(--transition); color: var(--text-muted);
}
.topbar-icon-btn svg { width: 20px; height: 20px; }
.topbar-icon-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.topbar-badge {
    position: absolute; top: -2px; right: -2px;
    min-width: 18px; height: 18px; padding: 0 5px;
    background: var(--danger); color: #fff; font-size: .625rem; font-weight: 700;
    border-radius: var(--radius-pill); display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--surface);
}
.mobile-menu {
    display: none; background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); width: 40px; height: 40px;
    font-size: 1.1rem; cursor: pointer; color: var(--text);
}

.content-area {
    padding: 1.75rem 2.25rem 3rem;
    flex: 1;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow-x: hidden;
    overflow-y: visible;
}
.view {
    min-width: 0;
    max-width: 100%;
}
.view.fade-in { animation: fadeIn .35s ease; }
[id$="-content"] { min-width: 0; max-width: 100%; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ─── KPI / stats portal ─── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.kpi-grid-3 { grid-template-columns: repeat(3, 1fr) !important; }

.portal-stats-band {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-xs);
    margin-bottom: 1.25rem;
    overflow: hidden;
}
.portal-stat {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.15rem 1.35rem;
    border-right: 1px solid var(--border-light);
    min-width: 0;
}
.portal-stat:last-child { border-right: none; }
.portal-stat-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    flex-shrink: 0;
}
.portal-stat-icon.clients { background: linear-gradient(135deg, #E8EEFB, #DBEAFE); }
.portal-stat-icon.success { background: linear-gradient(135deg, #D1FAE5, #A7F3D0); }
.portal-stat-icon.warning { background: linear-gradient(135deg, #FEF3C7, #FDE68A); }
.portal-stat-icon.money { background: linear-gradient(135deg, #EDE9FE, #DDD6FE); }
.portal-stat-body { min-width: 0; }
.portal-stat-val {
    font-size: 1.375rem;
    font-weight: 800;
    letter-spacing: -.02em;
    line-height: 1.1;
    color: var(--text);
}
.portal-stat-val.money { font-size: 1.125rem; }
.portal-stat-lbl {
    font-size: .75rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-top: .2rem;
}
.portal-stat-sub {
    font-size: .6875rem;
    color: var(--text-muted);
    margin-top: .15rem;
}
.portal-stat.is-success .portal-stat-val { color: var(--success-text); }
.portal-stat.is-warning .portal-stat-val { color: var(--warning-text); }

/* KPI legacy (otras vistas) */
.kpi-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem 1.375rem;
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-xs);
}
.kpi-card .label { font-size: .8125rem; color: var(--text-muted); font-weight: 500; }
.kpi-card .value { font-size: 1.75rem; font-weight: 800; margin-top: .375rem; line-height: 1.1; letter-spacing: -.02em; color: var(--text); }
.kpi-card .value.kpi-money { font-size: 1.25rem; }
.kpi-card .sub { font-size: .75rem; color: var(--text-muted); margin-top: .375rem; }

/* ─── Layout ─── */
.dash-layout { display: grid; grid-template-columns: 1fr 300px; gap: 1.25rem; align-items: start; }
.dash-main { display: flex; flex-direction: column; gap: 1.25rem; min-width: 0; }
.dash-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }

/* ─── Cards / Panels ─── */
.page-card, .panel {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-xs);
    border: 1px solid var(--border-light);
    overflow: hidden;
}
.page-card-head, .panel-header {
    padding: 1rem 1.375rem;
    border-bottom: 1px solid var(--border-light);
    display: flex; align-items: center; justify-content: space-between;
    background: var(--surface);
}
.page-card-head h2, .panel-header h2 {
    font-size: .9375rem; font-weight: 700; color: var(--text);
    letter-spacing: -.01em;
}
.page-card-body, .panel-body { padding: 1.25rem 1.375rem; }
.panel-body.compact { padding: 0; }
.panel-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.panel + .panel, .page-card + .page-card { margin-top: 1rem; }

/* ─── Alerts ─── */
.alerts-panel { position: sticky; top: calc(var(--topbar-h) + 1.25rem); }
.alert-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: .625rem; margin-bottom: 1rem; }
.alert-stat {
    text-align: center; padding: .875rem .5rem;
    border-radius: var(--radius-sm); cursor: pointer;
    transition: all var(--transition); border: 2px solid transparent;
}
.alert-stat.active { border-color: currentColor; transform: scale(1.02); }
.alert-stat.danger { background: var(--danger-bg); color: var(--danger-text); }
.alert-stat.warning { background: var(--warning-bg); color: var(--warning-text); }
.alert-stat.info { background: var(--info-bg); color: var(--info-text); }
.alert-stat .num { font-size: 1.5rem; font-weight: 800; line-height: 1; }
.alert-stat .lbl { font-size: .625rem; font-weight: 700; text-transform: uppercase; margin-top: .25rem; letter-spacing: .05em; }
.alert-compact-list { display: flex; flex-direction: column; gap: .375rem; max-height: 400px; overflow-y: auto; }
.alert-compact {
    display: flex; align-items: center; gap: .625rem;
    padding: .625rem .875rem; border-radius: var(--radius-sm);
    font-size: .8125rem; cursor: pointer;
    transition: all var(--transition); border: 1px solid transparent;
}
.alert-compact:hover { border-color: var(--border); background: var(--surface-2); }
.alert-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.alert-dot.danger { background: var(--danger); }
.alert-dot.warning { background: var(--warning); }
.alert-dot.info { background: var(--info); }
.alert-compact.danger { background: var(--danger-bg); }
.alert-compact.warning { background: var(--warning-bg); }
.alert-compact.info { background: var(--info-bg); }
.alert-compact .name { font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.alert-compact .detail { font-size: .75rem; color: var(--text-muted); }
.alert-empty { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted); font-size: .875rem; }
.empty-inline { padding: 2rem 1.25rem; color: var(--text-muted); font-size: .875rem; text-align: center; }

/* ─── Tabs ─── */
.morosos-tabs, .doc-filters { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.moro-tab {
    padding: .5rem 1rem; border-radius: var(--radius-pill);
    border: 1.5px solid var(--border); background: var(--surface);
    font-size: .8125rem; font-weight: 600; cursor: pointer;
    transition: all var(--transition); font-family: inherit; color: var(--text-muted);
    box-shadow: var(--shadow-xs);
}
.moro-tab:hover { border-color: var(--primary-mid); color: var(--primary); }
.moro-tab.active { border-color: var(--primary-mid); background: var(--primary-light); color: var(--primary-dark); }
.moro-tab .count { background: var(--bg); padding: .1rem .45rem; border-radius: var(--radius-pill); margin-left: .25rem; font-size: .75rem; }
.moro-tab.active .count { background: var(--primary-mid); color: #fff; }

/* ─── Tables ─── */
.table-wrap,
.buk-card-body.table-scroll-body,
.buk-card-body.clients-matrix-wrap {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-x pan-y;
    width: 100%;
    max-width: 100%;
}
.buk-card-body.clients-matrix-wrap {
    scrollbar-width: none;
    -ms-overflow-style: none;
    overflow-x: auto;
    overflow-y: visible;
}
.table-wrap,
.buk-card-body.table-scroll-body {
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.table-wrap::-webkit-scrollbar,
.buk-card-body.table-scroll-body::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}
.buk-card-body.clients-matrix-wrap::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}
.table-wrap::-webkit-scrollbar-thumb,
.buk-card-body.table-scroll-body::-webkit-scrollbar-thumb {
    background: #b8c5da;
    border-radius: 8px;
    border: 2px solid var(--surface);
}
.table-wrap::-webkit-scrollbar-track,
.buk-card-body.table-scroll-body::-webkit-scrollbar-track {
    background: var(--surface-2);
}
.buk-card-body.table-scroll-body,
.buk-card-body.clients-matrix-wrap {
    padding: 0 !important;
}
.buk-card-body.table-scroll-body > .table-wrap {
    overflow: visible;
    width: auto;
    max-width: none;
}
.table-wrap table,
.buk-card-body.table-scroll-body table {
    width: max-content;
    min-width: 100%;
    table-layout: auto;
    border-collapse: collapse;
    font-size: .8125rem;
}
.buk-card-body.clients-matrix-wrap table {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: .8125rem;
}
.table-scroll-hint {
    display: none;
    padding: .45rem 1rem;
    font-size: .75rem;
    color: var(--text-muted);
    text-align: center;
    background: var(--surface-2);
    border-top: 1px solid var(--border-light);
}
.table-scroll-body.can-scroll-x .table-scroll-hint,
.table-wrap.can-scroll-x .table-scroll-hint {
    display: block;
}
.buk-card-body.clients-matrix-wrap .table-scroll-hint {
    display: none !important;
}
@supports (position: sticky) {
    .table-wrap th.col-actions,
    .table-wrap td.col-actions,
    .table-wrap th.actions-cell,
    .table-wrap td.actions-cell {
        position: sticky;
        right: 0;
        z-index: 2;
        background: var(--surface);
        box-shadow: -8px 0 16px rgba(26, 35, 50, .06);
    }
    .table-wrap th.col-actions,
    .table-wrap th.actions-cell {
        background: var(--surface-2);
        z-index: 3;
    }
}
.table-wrap td.actions-cell {
    white-space: nowrap;
    min-width: 148px;
}
.table-wrap th, .table-wrap td {
    padding: .5rem .625rem; text-align: left;
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap; line-height: 1.4;
}
.table-wrap th {
    background: var(--surface-2); font-weight: 600; color: var(--text-muted);
    font-size: .6875rem; text-transform: uppercase; letter-spacing: .04em;
    position: sticky; top: 0; z-index: 1; padding: .625rem;
}
.table-wrap tbody tr { transition: background var(--transition); }
.table-wrap tbody tr:hover td { background: var(--primary-soft); }
.table-wrap tbody tr:last-child td { border-bottom: none; }
.col-razon { max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.client-name { font-weight: 600; }

/* Lista cobranza pendiente — portal (responsive) */
.pending-list { display: flex; flex-direction: column; }
.pending-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 1rem 1.25rem;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-light);
    transition: background var(--transition);
}
.pending-item:last-child { border-bottom: none; }
.pending-item:hover { background: var(--primary-soft); }
.pending-item-info { min-width: 0; }
.pending-client-name {
    font-weight: 700; font-size: .9375rem; color: var(--text);
    line-height: 1.35; word-break: normal; overflow-wrap: break-word;
}
.pending-item-meta {
    display: flex; align-items: center; flex-wrap: wrap; gap: .5rem .75rem;
    margin-top: .5rem;
}
.pending-fact { font-size: .8125rem; color: var(--text-muted); }
.pending-amount { font-size: .875rem; font-weight: 700; color: var(--primary-dark); }
.pending-item-pay { display: flex; flex-direction: column; gap: .25rem; flex-shrink: 0; }
.pending-pay-label { font-size: .625rem; font-weight: 600; text-transform: uppercase; color: var(--text-muted); letter-spacing: .04em; }
.pending-item-actions { flex-shrink: 0; }
.pending-item-actions .invoice-actions { flex-wrap: wrap; }

/* Matriz clientes — compacta, cabe en pantalla */
.buk-card-table {
    max-width: 100%;
    min-width: 0;
    overflow: visible;
}
#clients-content .buk-card-table {
    overflow: visible;
}
.clients-matrix-wrap { padding: 0 !important; }
#clients-grid {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    table-layout: fixed;
    font-size: .8125rem;
}
#clients-grid th,
#clients-grid td {
    padding: .45rem .35rem;
    vertical-align: middle;
    overflow: hidden;
}
#clients-grid th:first-child,
#clients-grid td:first-child {
    width: 23%;
    min-width: 0;
    white-space: nowrap;
    padding-left: .875rem;
    position: static;
    box-shadow: none;
}
#clients-grid thead th:first-child {
    background: var(--surface-2);
}
#clients-grid .client-name-cell { gap: .5rem; min-width: 0; }
#clients-grid .client-name-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: .8125rem;
    font-weight: 600;
    color: var(--text);
}
#clients-grid th:nth-child(2),
#clients-grid td:nth-child(2) {
    width: 10%;
    min-width: 0;
    font-size: .75rem;
    color: var(--text-muted);
    position: static;
    box-shadow: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#clients-grid thead th:nth-child(2) {
    background: var(--surface-2);
}
#clients-grid th:nth-child(3),
#clients-grid td:nth-child(3) {
    width: 8%;
    min-width: 0;
    text-align: center;
    position: static;
    box-shadow: none;
}
#clients-grid thead th:nth-child(3) {
    background: var(--surface-2);
}
#clients-grid .status-badge {
    padding: .2rem .4rem;
    font-size: .625rem;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Corte de servicio "Mi Flota" en la columna ESTADO del listado de clientes. */
/* Chip ESTADO accionable: el MISMO chip de morosidad/suspensión actúa como botón
   (cortar ⇄ reactivar "Mi Flota") cuando el rol tiene permiso (svc-actionable). Para
   roles de solo lectura el chip se rinde sin esta clase: informativo y no clickeable. */
.status-badge.svc-actionable { cursor: pointer; transition: filter .15s ease, box-shadow .15s ease; }
.status-badge.svc-actionable:hover { filter: brightness(.94); box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 40%, transparent); }
.status-badge.svc-actionable:focus-visible { outline: 2px solid var(--accent, #2563eb); outline-offset: 1px; }
.status-badge.svc-actionable.is-loading { opacity: .65; cursor: progress; }
.client-status-select {
    width: 100%;
    max-width: 7.5rem;
    padding: .3rem .35rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .6875rem;
    font-weight: 600;
    font-family: inherit;
    background: var(--surface);
    cursor: pointer;
}
.client-status-select.status-active { border-color: var(--success-soft); color: var(--success-text); background: var(--success-bg); }
.client-status-select.status-warning { border-color: var(--warning-soft); color: var(--warning-text); background: var(--warning-bg); }
.client-status-select.status-suspended { border-color: var(--danger-soft); color: var(--danger-text); background: var(--danger-bg); }
.clients-matrix-hint { flex: 1 1 200px; align-self: center; min-width: 0; }
#clients-grid tbody tr:hover td { background: var(--primary-soft); }
#clients-grid tbody tr:hover .month-cell { background: transparent !important; }

/* Encabezados de mes — distribuidos en el ancho disponible */
#clients-grid .month-header {
    width: auto;
    min-width: 0;
    text-align: center;
    font-size: .6875rem;
    font-weight: 700;
    color: var(--primary-dark);
    background: linear-gradient(180deg, var(--primary-light) 0%, var(--primary-soft) 100%);
    border-bottom: 2px solid var(--primary-mid);
    padding: .5rem .1rem !important;
    letter-spacing: .01em;
    text-transform: uppercase;
}
#clients-grid .month-cell {
    width: auto;
    min-width: 0;
    max-width: none;
    text-align: center;
    padding: .25rem .1rem !important;
    font-size: .8125rem;
    font-weight: 400;
    border-radius: 0;
    height: 34px;
    background: transparent !important;
    border: none !important;
    vertical-align: middle;
}

.month-cell-inner {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 28px;
    line-height: 1;
}

.month-ticket {
    font-size: 1.05rem;
    font-weight: 800;
    line-height: 1;
    user-select: none;
    transition: transform .12s ease, color .12s ease;
}

.month-ticket-paid { color: #16a34a; }
.month-ticket-due { color: #dc2626; }
.month-ticket-missing { color: #94a3b8; font-weight: 700; font-size: 1.125rem; }
.month-ticket-future { color: #cbd5e1; font-weight: 500; font-size: .875rem; }

.month-factura-dot {
    display: block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--primary-mid);
    flex-shrink: 0;
}

#clients-grid thead th {
    background: var(--surface-2);
    font-weight: 600;
    color: var(--text-muted);
    font-size: .6875rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    z-index: 1;
}
#clients-grid tbody tr {
    border-bottom: 1px solid var(--border-light);
}
#clients-grid tbody tr:last-child {
    border-bottom: none;
}

.status-badge, .pay-badge {
    display: inline-flex; align-items: center;
    padding: .25rem .625rem; border-radius: var(--radius-pill);
    font-size: .6875rem; font-weight: 600; letter-spacing: .02em;
}
.status-badge.active, .pay-badge.paid { background: var(--success-bg); color: var(--success-text); }
.status-badge.warning, .pay-badge.pending { background: var(--warning-bg); color: var(--warning-text); }
.status-badge.suspended, .pay-badge.partial { background: var(--danger-bg); color: var(--danger-text); }
.status-badge.annulled, .pay-badge.annulled {
    background: var(--surface-2); color: var(--text-muted);
    text-decoration: line-through; text-decoration-thickness: 1px;
}
.status-badge.nota_credito, .pay-badge.nota_credito {
    background: var(--info-bg, #e7efff); color: var(--info-text, #1d4ed8);
    border: 1px dashed currentColor;
}
.audit-report h4 { margin: 1rem 0 .5rem; font-size: .9rem; }
.audit-list { list-style: none; margin: 0 0 .5rem; padding: 0; }
.audit-list li {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; padding: .4rem .6rem; border-bottom: 1px solid var(--border);
}
.audit-list li strong { color: var(--primary, #2563eb); font-variant-numeric: tabular-nums; }
.audit-list-review li strong { color: var(--warning-text, #92400e); }
.audit-ok { color: var(--success-text, #166534); font-weight: 600; }
.pay-badge-btn {
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: transform .1s ease, filter .1s ease;
}
.pay-badge-btn:hover { transform: scale(1.06); filter: brightness(0.96); }
.pay-badge-btn:active { transform: scale(0.98); }
.pay-badge.partial { background: var(--info-bg); color: var(--info-text); }

.month-cell { text-align: center; }
.month-paid,
.month-pending,
.month-overdue,
.month-missing,
.month-future,
.month-empty {
    background: transparent !important;
    border: none !important;
    color: inherit;
}
.month-cell.clickable { cursor: pointer; }
.month-cell.clickable:hover .month-ticket { transform: scale(1.15); }
.month-cell.clickable:hover .month-ticket-paid { color: #15803d; }
.month-cell.clickable:hover .month-ticket-due { color: #b91c1c; }
.month-cell.month-toggling { opacity: .55; pointer-events: none; }
.clickable { cursor: pointer; }

.btn-action {
    padding: .375rem .75rem; font-size: .75rem; border-radius: 8px;
    border: 1px solid var(--border); background: var(--surface);
    cursor: pointer; font-weight: 600; transition: all var(--transition); font-family: inherit;
    box-shadow: var(--shadow-xs);
}
.btn-action:hover { background: var(--surface-2); border-color: #CBD5E1; }
.btn-action.success { background: var(--success-bg); color: var(--success-text); border-color: var(--success-soft); }
.btn-action.success:hover { background: var(--success-soft); color: var(--success-text); }

.inline-pay-date {
    width: 92px; padding: .375rem .5rem;
    border: 1.5px solid var(--border); border-radius: 8px;
    font-size: .75rem; font-family: inherit; text-align: center;
    background: var(--surface);
}
.inline-pay-date:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.pay-date-cell { padding: .375rem .5rem !important; }
.actions-cell { white-space: nowrap; }

/* Search */
.search-bar { display: flex; gap: .625rem; margin-bottom: 1rem; flex-wrap: wrap; max-width: 100%; }
.search-bar input {
    flex: 1 1 180px; min-width: 0; max-width: 100%; padding: .625rem 1rem;
    border: 1.5px solid var(--border); border-radius: var(--radius-sm);
    font-size: .875rem; font-family: inherit; background: var(--surface);
    box-shadow: var(--shadow-xs);
}
.search-bar input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-glow); }
.search-bar select {
    flex: 0 1 auto;
    min-width: 7rem;
    max-width: 100%;
    padding: .625rem 1rem; border: 1.5px solid var(--border);
    border-radius: var(--radius-sm); font-size: .875rem;
    background: var(--surface); font-family: inherit; box-shadow: var(--shadow-xs);
    cursor: pointer;
    position: relative;
    z-index: 2;
}

/* Upload */
.upload-zone {
    border: 2px dashed var(--border); border-radius: var(--radius);
    padding: 2.5rem 2rem; text-align: center; cursor: pointer;
    transition: all var(--transition); background: var(--primary-soft);
    margin-top: .75rem;
}
.upload-zone.compact { padding: 1.75rem 1.25rem; margin-top: .5rem; }
.upload-zone:hover, .upload-zone.dragover { border-color: var(--primary); background: var(--primary-light); }
.upload-zone input { display: none; }
.upload-icon svg { width: 48px; height: 48px; color: var(--primary); margin-bottom: .75rem; }
.upload-title { font-weight: 700; font-size: 1rem; color: var(--text); }
.upload-hint { color: var(--text-muted); font-size: .875rem; margin-top: .375rem; }
.upload-progress { margin-top: 1rem; color: var(--primary); font-weight: 600; }
.upload-progress-head { display: flex; justify-content: space-between; align-items: center; font-size: .85rem; margin-bottom: .4rem; }
.upload-progress-pct { font-variant-numeric: tabular-nums; color: var(--primary); }
.upload-progress-track { height: 8px; background: var(--border, #e2e8f0); border-radius: 999px; overflow: hidden; }
.upload-progress-fill { height: 100%; background: linear-gradient(90deg, #2b4eb4, #1a3278); border-radius: 999px; transition: width .25s ease; }
.upload-result { margin-top: 1rem; padding: 1rem; border-radius: var(--radius-sm); font-size: .875rem; }
.doc-upload-card { margin-bottom: 1rem; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
/* El diálogo de confirmación es global y debe quedar SIEMPRE al frente, por
   encima de cualquier otro modal (p.ej. la ficha del cliente #detail-modal) y
   su backdrop. Sin esto comparte z-index 500 con .modal y, al ir antes en el
   DOM, quedaba tapado por el modal del cliente. */
#confirm-modal { z-index: 1300; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(26, 35, 50, .45); backdrop-filter: blur(6px); }
.modal-content {
    position: relative; background: var(--surface); border-radius: var(--radius-lg);
    width: 100%; max-width: 1100px; max-height: 90vh;
    overflow: hidden; box-shadow: var(--shadow-lg);
    display: flex; flex-direction: column;
    animation: modalIn .3s cubic-bezier(.4, 0, .2, 1);
    border: 1px solid var(--border-light);
}
.modal-content.modal-wide { max-width: min(96vw, 1080px); }
@keyframes modalIn { from { opacity: 0; transform: scale(.97) translateY(12px); } to { opacity: 1; transform: none; } }
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border-light);
    background: var(--surface);
}
.modal-header h2 { font-size: 1.125rem; font-weight: 700; color: var(--text); letter-spacing: -.01em; }
.modal-close {
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--surface);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: all var(--transition);
}
.modal-close svg { width: 18px; height: 18px; color: var(--text-muted); }
.modal-close:hover { background: var(--danger-bg); border-color: var(--danger-soft); }
.modal-close:hover svg { color: var(--danger); }
.modal-body { padding: 1.5rem; overflow-y: auto; }
.modal-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.modal-summary .item {
    background: var(--surface-2); padding: 1rem; border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    min-width: 0; /* permite que el contenido se recorte en lugar de desbordar la grilla */
    overflow: hidden;
}
.modal-summary .item .lbl { font-size: .6875rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.modal-summary .item .val {
    font-weight: 700; margin-top: .25rem; font-size: 1rem; color: var(--text);
    min-width: 0; max-width: 100%;
    overflow-wrap: anywhere; word-break: break-word; /* valores largos no se salen de la tarjeta */
}
/* Valores de una sola línea (email/RUT): recorta con elipsis y muestra tooltip (title). */
.modal-summary .item .val.val-ellipsis {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; word-break: normal;
}

/* Client tabs */
.client-tabs {
    display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--border-light); padding-bottom: 0;
}
.client-tab {
    padding: .625rem 1rem; border: none; background: transparent;
    font-size: .8125rem; font-weight: 600; color: var(--text-muted);
    cursor: pointer; font-family: inherit;
    transition: all var(--transition);
    border-bottom: 2px solid transparent; margin-bottom: -1px;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.client-tab:hover { color: var(--text); background: var(--surface-2); }
.client-tab.active { color: var(--primary); border-bottom-color: var(--primary); background: var(--primary-soft); }
.client-tab.tab-highlight { color: var(--warning-text); font-weight: 700; }
.client-tab.tab-highlight.active { color: var(--primary); }

.ghost-tag {
    display: inline-block; font-size: .625rem; font-weight: 700; text-transform: uppercase;
    padding: .2rem .5rem; border-radius: var(--radius-pill);
    background: var(--warning-bg); color: var(--warning-text); vertical-align: middle; margin-left: .35rem;
}
.ghost-banner {
    background: var(--warning-bg); border: 1px solid var(--warning-soft);
    border-radius: var(--radius-sm); padding: 1rem 1.25rem; margin-bottom: 1.25rem;
}
.ghost-banner strong { display: block; color: var(--warning-text); margin-bottom: .35rem; }
.ghost-banner p { font-size: .875rem; color: var(--text-muted); margin-bottom: .75rem; }
.client-profile-header.is-ghost { background: linear-gradient(135deg, var(--warning-bg), var(--surface)); }

.assign-billing-panel { padding: .25rem 0; }
.assign-billing-head h4 { font-size: 1rem; font-weight: 700; margin-bottom: .5rem; color: var(--text); }
.assign-billing-head { margin-bottom: 1rem; }
.assign-client-list {
    max-height: 380px; overflow-y: auto;
    border: 1px solid var(--border-light); border-radius: var(--radius-sm);
}
.assign-client-row {
    display: flex; align-items: center; gap: .875rem;
    padding: .875rem 1rem; border-bottom: 1px solid var(--border-light);
    transition: background var(--transition);
}
.assign-client-row:last-child { border-bottom: none; }
.assign-client-row:hover { background: var(--primary-soft); }
.assign-client-info { flex: 1; min-width: 0; }
.assign-client-info strong {
    display: block; font-size: .875rem; color: var(--text);
    white-space: normal; word-break: break-word; line-height: 1.35;
}
.assign-client-info span { font-size: .75rem; color: var(--text-muted); }
.loading-inline { padding: 1.5rem; text-align: center; }

.edit-form .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.edit-form .form-group.full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: .625rem; justify-content: flex-end; margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--border-light); }

.activity-item { font-size: .8125rem; padding: .75rem 0; border-bottom: 1px solid var(--border-light); color: var(--text-muted); }
.activity-item:last-child { border-bottom: none; }
.activity-item strong { color: var(--text); font-weight: 600; }
.activity-item .time { font-size: .75rem; margin-top: .25rem; }

.sheet-toolbar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.sheet-table input.cell-input {
    width: 100%; min-width: 58px; padding: .375rem .5rem;
    border: 1.5px solid transparent; border-radius: 6px;
    font-size: .8125rem; background: transparent; font-family: inherit;
}
.sheet-table input.cell-input:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px var(--primary-glow); }
.sheet-table th { background: var(--primary-soft); color: var(--primary-dark); font-size: .6875rem; position: sticky; top: 0; z-index: 2; }
.sheet-table td { padding: .25rem .375rem; }
.sheet-table .row-num { width: 28px; text-align: center; color: var(--text-muted); font-size: .75rem; background: var(--surface-2); }
.sheet-actions { display: flex; gap: .625rem; margin-top: 1rem; flex-wrap: wrap; }
.register-result { margin-top: 1rem; padding: 1rem; border-radius: var(--radius-sm); font-size: .875rem; }
.register-result.ok { background: var(--success-bg); color: var(--success-text); border: 1px solid var(--success-soft); }
.register-result.err { background: var(--danger-bg); color: var(--danger-text); border: 1px solid var(--danger-soft); }

.dupe-intro { margin-bottom: 1.25rem; }
.dupe-groups-list { display: flex; flex-direction: column; gap: 1.25rem; }
.dupe-group-card {
    background: var(--surface); border: 1px solid var(--border-light);
    border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-xs);
}
.dupe-group-head {
    display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
    padding: 1rem 1.25rem; background: var(--surface-2);
    border-bottom: 1px solid var(--border-light);
}
.dupe-group-head h4 { font-size: .9375rem; font-weight: 700; flex: 1; min-width: 200px; }
.dupe-reason-badge {
    font-size: .6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
    padding: .25rem .625rem; border-radius: var(--radius-pill);
    background: var(--warning-bg); color: var(--warning-text); border: 1px solid var(--warning-soft);
}
.dupe-count { font-size: .75rem; color: var(--text-muted); }
.dupe-clients { display: flex; flex-direction: column; }
.dupe-client-row {
    display: grid; grid-template-columns: auto 1fr auto; gap: 1rem; align-items: center;
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--border-light);
    transition: background var(--transition);
}
.dupe-client-row:last-child { border-bottom: none; }
.dupe-client-row.is-suggested,
.dupe-client-row.is-primary { background: var(--primary-soft); }
.dupe-primary-pick {
    display: flex; flex-direction: column; align-items: center; gap: .25rem;
    font-size: .6875rem; font-weight: 600; color: var(--text-muted); cursor: pointer;
    min-width: 64px; text-align: center;
}
.dupe-primary-pick input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.dupe-client-info { display: flex; align-items: center; gap: .875rem; min-width: 0; }
.dupe-client-info strong {
    display: block; font-size: .9375rem; color: var(--text);
    white-space: normal; word-break: break-word; line-height: 1.35;
}
.dupe-client-meta {
    display: flex; flex-wrap: wrap; gap: .35rem .75rem;
    font-size: .75rem; color: var(--text-muted); margin-top: .35rem;
}
.dupe-row-actions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
.dupe-group-footer {
    padding: 1rem 1.25rem; background: var(--surface-2);
    border-top: 1px solid var(--border-light); text-align: right;
}
@media (max-width: 768px) {
    .dupe-client-row { grid-template-columns: 1fr; gap: .75rem; }
    .dupe-row-actions { justify-content: flex-start; }
}

/* Toast */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999; display: flex; flex-direction: column; gap: .625rem; }
.toast {
    background: var(--text); color: #fff;
    padding: .875rem 1.375rem; border-radius: var(--radius-sm);
    font-size: .875rem; font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: toastIn .35s ease;
    max-width: 360px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }
@keyframes toastIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }

.loading { text-align: center; padding: 4rem 2rem; color: var(--text-muted); }
.spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--border-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
    margin: 0 auto 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; padding: 3rem 2rem; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 3rem; margin-bottom: .75rem; opacity: .4; }
.empty-state h3 { font-size: 1rem; font-weight: 700; color: var(--text); margin-bottom: .375rem; }

.chart-container { position: relative; height: 280px; }
.dash-chart { height: 300px; }
.chart-box { background: var(--surface); border-radius: var(--radius); padding: 1.25rem; border: 1px solid var(--border-light); box-shadow: var(--shadow-xs); }

/* ─── Dashboard analítico ─── */
.dash-shell { display: flex; flex-direction: column; gap: 1.25rem; }
.dash-header {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 1.25rem 1.5rem; background: var(--surface); border: 1px solid var(--border-light);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-xs);
}
.dash-header-main { display: flex; align-items: center; gap: 1rem; min-width: 0; }
.dash-title { font-size: 1.375rem; font-weight: 800; letter-spacing: -.02em; margin: 0; }
.dash-subtitle { font-size: .875rem; color: var(--text-muted); margin: .2rem 0 0; }
.dash-shortcuts { display: flex; flex-wrap: wrap; gap: .5rem; }
.dash-shortcut {
    display: inline-flex; align-items: center; gap: .45rem; padding: .5rem .85rem;
    border: 1px solid var(--border-light); border-radius: 999px; background: var(--surface-2);
    font-family: inherit; font-size: .8125rem; font-weight: 600; color: var(--text-2); cursor: pointer;
    transition: all var(--transition);
}
.dash-shortcut:hover { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.dash-shortcut em { font-style: normal; background: var(--warning-bg); color: var(--warning-text); padding: .1rem .4rem; border-radius: 999px; font-size: .6875rem; font-weight: 700; }
.dash-shortcut-icon {
    width: 1.5rem; height: 1.5rem; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    font-size: .75rem; font-weight: 700;
}
.dash-shortcut-icon.warn { background: #FEF3C7; color: #B45309; }
.dash-shortcut-icon.mail { background: #DBEAFE; color: #1D4ED8; }
.dash-shortcut-icon.doc { background: #EDE9FE; color: #6D28D9; }
.dash-shortcut-icon.up { background: #D1FAE5; color: #047857; }

.dash-kpi-grid {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem;
}
.dash-kpi-card {
    background: var(--surface); border: 1px solid var(--border-light); border-radius: var(--radius-lg);
    padding: 1.1rem 1.25rem; box-shadow: var(--shadow-xs); min-width: 0;
}
.dash-kpi-ring { display: flex; align-items: center; gap: 1rem; }
.dash-ring {
    --pct: 0; flex-shrink: 0; width: 4.5rem; height: 4.5rem; border-radius: 50%;
    background: conic-gradient(var(--ring-color, var(--primary)) calc(var(--pct) * 1%), var(--surface-2) 0);
    display: flex; align-items: center; justify-content: center; position: relative;
}
.dash-ring::after {
    content: ''; position: absolute; inset: 6px; border-radius: 50%; background: var(--surface);
}
.dash-ring-inner { position: relative; z-index: 1; font-size: .875rem; font-weight: 800; color: var(--text); }
.dash-kpi-card.tone-success .dash-ring { --ring-color: #10B981; }
.dash-kpi-card.tone-primary .dash-ring { --ring-color: var(--primary); }
.dash-kpi-card.tone-warn .dash-ring { --ring-color: #F59E0B; }
.dash-kpi-body { min-width: 0; }
.dash-kpi-label { font-size: .8125rem; font-weight: 700; color: var(--text); }
.dash-kpi-sub { font-size: .75rem; color: var(--text-muted); margin-top: .2rem; line-height: 1.35; }
.dash-kpi-stat .dash-kpi-value { font-size: 1.375rem; font-weight: 800; color: var(--primary-dark); line-height: 1.1; }
.dash-kpi-card.tone-danger .dash-kpi-value { color: #DC2626; }

.dash-body {
    display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(260px, 1fr); gap: 1.25rem; align-items: start;
}
.dash-main, .dash-aside { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.dash-card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.dash-card-head h3 { margin: 0; }
.dash-legend { margin: 0 0 .75rem; }
.dash-empty { color: var(--text-muted); font-size: .8125rem; margin: 0; }

.dash-month-bars { display: flex; flex-direction: column; gap: .65rem; }
.dash-month-row {
    display: grid; grid-template-columns: 4.5rem minmax(0, 1fr) 2.5rem 5.5rem; gap: .6rem; align-items: center;
}
.dash-month-name { font-size: .75rem; font-weight: 600; color: var(--text-muted); }
.dash-month-track {
    position: relative; height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden;
}
.dash-month-invoiced {
    position: absolute; left: 0; top: 0; bottom: 0; background: #CBD5E1; border-radius: 999px;
}
.dash-month-collected {
    position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, var(--primary), #10B981); border-radius: 999px;
}
.dash-month-pct { font-size: .75rem; font-weight: 700; text-align: right; }
.dash-month-pct.is-good { color: #059669; }
.dash-month-pct.is-mid { color: #D97706; }
.dash-month-pct.is-low { color: #DC2626; }
.dash-month-amt { font-size: .75rem; font-weight: 700; text-align: right; color: var(--text); }

.dash-semester-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.dash-semester-card {
    background: var(--surface); border: 1px solid var(--border-light); border-radius: var(--radius-lg);
    padding: 1rem 1.15rem; box-shadow: var(--shadow-xs);
}
.dash-semester-label { display: block; font-size: .75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.dash-semester-val { display: block; font-size: 1.25rem; font-weight: 800; color: var(--primary-dark); margin: .25rem 0 .5rem; }
.dash-semester-bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.dash-semester-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), #10B981); border-radius: 999px; }
.dash-semester-meta { display: block; font-size: .75rem; color: var(--text-muted); margin-top: .4rem; }

.dash-client-mix { display: flex; flex-direction: column; gap: .75rem; }
.dash-mix-bar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.dash-mix-seg { display: block; height: 100%; }
.dash-mix-seg.is-ok { background: #10B981; }
.dash-mix-seg.is-warn { background: #F59E0B; }
.dash-mix-seg.is-danger { background: #EF4444; }
.dash-mix-legend { display: flex; flex-direction: column; gap: .35rem; font-size: .8125rem; color: var(--text-muted); }
.dash-mix-legend .dot { display: inline-block; width: .5rem; height: .5rem; border-radius: 50%; margin-right: .35rem; vertical-align: middle; }
.dash-mix-legend .dot.ok { background: #10B981; }
.dash-mix-legend .dot.warn { background: #F59E0B; }
.dash-mix-legend .dot.danger { background: #EF4444; }
.dash-mix-total { margin-top: .25rem; font-weight: 600; color: var(--text); }

.dash-debtor-list { display: flex; flex-direction: column; }
.dash-debtor-row {
    display: flex; align-items: center; gap: .65rem; width: 100%; padding: .75rem 1.15rem;
    border: 0; border-bottom: 1px solid var(--border-light); background: transparent; text-align: left;
    font-family: inherit; cursor: pointer; transition: background var(--transition);
}
.dash-debtor-row:hover { background: var(--primary-soft); }
.dash-debtor-rank {
    width: 1.5rem; height: 1.5rem; border-radius: 50%; background: var(--surface-2);
    display: flex; align-items: center; justify-content: center; font-size: .6875rem; font-weight: 800; color: var(--text-muted);
}
.dash-debtor-info { flex: 1; min-width: 0; }
.dash-debtor-name { display: block; font-weight: 600; font-size: .8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-debtor-meta { display: block; font-size: .6875rem; color: var(--text-muted); }
.dash-debtor-amt { font-weight: 800; font-size: .8125rem; color: #DC2626; white-space: nowrap; }
.dash-debtor-more { width: 100%; padding: .75rem; border: 0; background: transparent; text-align: center; font-family: inherit; cursor: pointer; }
.dash-activity .activity-item { padding: .5rem 0; }

/* ─── Portal Buk (legacy widgets) ─── */
.portal-top {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    gap: 1.25rem;
    margin-bottom: 1.5rem;
    max-width: 100%;
}
.portal-welcome {
    background: var(--surface); border-radius: var(--radius-lg);
    border: 1px solid var(--border-light); box-shadow: var(--shadow-xs);
    padding: 1.5rem 1.75rem;
}
.portal-welcome-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; }
.portal-welcome-head .avatar {
    width: 56px; height: 56px; font-size: 1.125rem;
    background: linear-gradient(135deg, var(--primary-light), var(--primary-soft));
    color: var(--primary); border: 2px solid var(--primary-light);
    box-shadow: 0 4px 12px var(--primary-glow);
}
.portal-welcome-head h2 { font-size: 1.375rem; font-weight: 800; color: var(--text); letter-spacing: -.02em; }
.portal-welcome-head p { font-size: .875rem; color: var(--text-muted); margin-top: .2rem; }
.quick-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; }
.quick-action {
    display: flex; flex-direction: column; align-items: center; gap: .5rem;
    padding: 1rem .5rem; border-radius: var(--radius-sm);
    border: 1.5px solid var(--border-light); background: var(--surface-2);
    cursor: pointer; transition: all var(--transition); font-family: inherit;
    text-align: center; color: var(--text-2); font-size: .75rem; font-weight: 600;
}
.quick-action:hover { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.quick-action-icon {
    width: 44px; height: 44px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center; font-size: 1.25rem;
}
.quick-action-icon.blue { background: #DBEAFE; }
.quick-action-icon.green { background: #D1FAE5; }
.quick-action-icon.orange { background: #FEF3C7; }
.quick-action-icon.purple { background: #EDE9FE; }

.month-hero {
    background: linear-gradient(160deg, var(--primary-dark) 0%, var(--primary) 55%, var(--accent) 100%);
    border-radius: var(--radius-lg); color: #fff; overflow: hidden;
    display: flex; flex-direction: column; justify-content: space-between;
    min-height: 200px; position: relative; box-shadow: 0 8px 32px rgba(43, 78, 180, .22);
}
.month-hero::after {
    content: ''; position: absolute; bottom: -40px; right: -40px;
    width: 180px; height: 180px; border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, .12);
}
.month-hero-top { padding: 1.75rem 1.75rem .5rem; position: relative; z-index: 1; }
.month-hero-label { font-size: .75rem; font-weight: 600; opacity: .75; text-transform: uppercase; letter-spacing: .06em; }
.month-hero-name { font-size: 2.75rem; font-weight: 800; letter-spacing: -.03em; line-height: 1; margin-top: .25rem; }
.month-hero-year { font-size: 1rem; opacity: .7; margin-top: .25rem; }
.month-hero-note {
    margin-top: .5rem;
    font-size: .75rem;
    opacity: .65;
    font-weight: 500;
}
.month-hero-stats {
    display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0;
    background: rgba(0, 0, 0, .15); position: relative; z-index: 1;
}
.month-hero-stat { padding: 1rem 1.25rem; text-align: center; border-right: 1px solid rgba(255, 255, 255, .1); }
.month-hero-stat:last-child { border-right: none; }
.month-hero-stat .num { font-size: 1.25rem; font-weight: 800; }
.month-hero-stat .lbl { font-size: .625rem; opacity: .7; text-transform: uppercase; letter-spacing: .04em; margin-top: .2rem; }

.portal-main {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(280px, 1fr);
    gap: 1.25rem; align-items: start;
}
.portal-main > .buk-card,
.portal-side { min-width: 0; }
.portal-side .task-list { max-height: 420px; overflow-y: auto; }
.buk-card {
    background: var(--surface); border-radius: var(--radius);
    border: 1px solid var(--border-light); box-shadow: var(--shadow-xs); overflow: hidden;
}
.buk-card-banner {
    background: linear-gradient(90deg, var(--primary-light), var(--primary-soft));
    border-bottom: 2px solid var(--primary-mid);
    padding: 1rem 1.5rem;
    display: flex; align-items: center; justify-content: space-between;
}
.buk-card-banner h3 { font-size: 1.0625rem; font-weight: 800; color: var(--primary-dark); letter-spacing: -.01em; }
.buk-card-banner .badge-pill {
    background: var(--primary); color: #fff; font-size: .6875rem; font-weight: 700;
    padding: .25rem .75rem; border-radius: var(--radius-pill);
}
.buk-card-body { padding: 0; }
.buk-card-body.padded { padding: 1.25rem 1.5rem; }

.task-list { display: flex; flex-direction: column; }
.task-item {
    display: flex; align-items: flex-start; gap: .875rem;
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--border-light);
    cursor: pointer; transition: background var(--transition);
}
.task-item:last-child { border-bottom: none; }
.task-item:hover { background: var(--primary-soft); }
.task-num {
    width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: .75rem; font-weight: 800; color: #fff;
}
.task-num.danger { background: var(--danger); }
.task-num.warning { background: var(--warning); }
.task-num.info { background: var(--info); }
.task-body { flex: 1; min-width: 0; }
.task-body .name { font-weight: 700; font-size: .875rem; color: var(--text); white-space: normal; word-break: break-word; }
.task-body .detail { font-size: .75rem; color: var(--text-muted); margin-top: .15rem; }

.period-hero-bar {
    display: flex; align-items: stretch; gap: 0; margin-bottom: 1.25rem;
    background: linear-gradient(90deg, var(--primary-dark), var(--primary));
    border-radius: var(--radius); overflow: hidden; color: #fff;
    box-shadow: 0 4px 20px rgba(43, 78, 180, .18);
    max-width: 100%;
    flex-wrap: wrap;
}
.period-hero-month-block {
    padding: 1.25rem 2rem; display: flex; flex-direction: column; justify-content: center;
    border-right: 1px solid rgba(255, 255, 255, .15); min-width: 140px;
}
.period-hero-month-block .month { font-size: 2rem; font-weight: 800; line-height: 1; letter-spacing: -.02em; }
.period-hero-month-block .year { font-size: .875rem; opacity: .75; margin-top: .25rem; }
.period-hero-metrics { display: flex; flex: 1; }
.period-hero-metric {
    flex: 1; padding: 1rem 1.5rem; display: flex; flex-direction: column; justify-content: center;
    border-right: 1px solid rgba(255, 255, 255, .1);
}
.period-hero-metric:last-child { border-right: none; }
.period-hero-metric .val { font-size: 1.375rem; font-weight: 800; }
.period-hero-metric .lbl { font-size: .6875rem; opacity: .7; text-transform: uppercase; letter-spacing: .04em; margin-top: .15rem; }

.client-name-cell { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.client-avatar {
    width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
    background: linear-gradient(135deg, var(--primary-light), #DBEAFE);
    color: var(--primary); border: 2px solid var(--surface);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .6875rem;
    box-shadow: var(--shadow-xs);
}
.client-avatar.lg { width: 48px; height: 48px; font-size: .875rem; }
.client-name-text { font-weight: 600; font-size: .875rem; color: var(--text); white-space: normal; word-break: break-word; line-height: 1.35; }

.client-profile-header {
    display: flex; align-items: center; gap: 1.25rem;
    padding: 1.25rem 1.5rem; margin: -1.5rem -1.5rem 1.25rem;
    background: linear-gradient(135deg, var(--primary-soft), var(--surface));
    border-bottom: 1px solid var(--border-light);
}
.client-profile-header h3 { font-size: 1.125rem; font-weight: 800; color: var(--text); }
.client-profile-header .meta { font-size: .8125rem; color: var(--text-muted); margin-top: .2rem; }

/* Tabla facturas en ficha cliente */
.invoice-tab-summary {
    display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
    font-size: .8125rem; color: var(--text-muted); margin-bottom: 1rem;
    padding: .75rem 1rem; background: var(--surface-2); border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
}
.invoice-tab-summary strong { color: var(--text); }
.invoice-tab-dot { opacity: .4; }

.invoice-table-client-wrap { border-radius: var(--radius-sm); border: 1px solid var(--border-light); overflow: hidden; }
.invoices-table-client {
    width: 100%; border-collapse: collapse; font-size: .875rem;
}
.invoices-table-client th,
.invoices-table-client td {
    padding: .875rem 1rem; vertical-align: middle;
    border-bottom: 1px solid var(--border-light);
}
.invoices-table-client th {
    background: var(--surface-2); font-size: .6875rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted);
    white-space: nowrap;
}
.invoices-table-client tbody tr:last-child td { border-bottom: none; }
.invoices-table-client tbody tr.is-pending { background: var(--warning-bg); }
.invoices-table-client tbody tr.is-paid:hover,
.invoices-table-client tbody tr.is-pending:hover { background: var(--primary-soft); }
.invoices-table-client .col-period { width: 88px; text-align: center; }
.invoices-table-client .col-inv-factura { min-width: 5.5rem; }
.invoices-table-client .client-inv-num { font-weight: 600; }
.invoices-table-client .client-inv-date { margin-top: .15rem; }
.invoices-table-client .col-estado-pay { white-space: nowrap; }
.invoices-table-client .col-estado-pay .pay-badge-btn { min-width: 5.75rem; }
.invoice-tab-hint { margin: 0 0 .75rem; }
.client-debt-hero {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
    margin-bottom: 1rem; padding: 1rem 1.15rem; border-radius: var(--radius-md);
    background: linear-gradient(135deg, rgba(245, 158, 11, .1), rgba(245, 158, 11, .04));
    border: 1px solid rgba(245, 158, 11, .22);
}
.client-debt-label { font-size: .6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.client-debt-amount { font-size: 1.5rem; font-weight: 800; color: #b45309; margin-top: .15rem; }
.client-debt-sub { font-size: .75rem; color: var(--text-muted); margin-top: .25rem; }
.client-debt-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.portal-debt-intro { padding: 0 1.25rem; margin: 0; }
.portal-debt-list { display: flex; flex-direction: column; }
.portal-debt-item {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    width: 100%; padding: .9rem 1.25rem; border: 0; border-bottom: 1px solid var(--border-light);
    background: transparent; text-align: left; cursor: pointer; transition: background .12s;
}
.portal-debt-item:hover { background: var(--primary-soft); }
.portal-debt-name { font-weight: 600; color: var(--text); }
.portal-debt-sub { font-size: .75rem; color: var(--text-muted); margin-top: .15rem; }
.portal-debt-amount { font-weight: 800; color: var(--primary); white-space: nowrap; }
.portal-debt-total {
    display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem 1rem;
    padding: 1rem 1.25rem; background: var(--surface-2); border-top: 1px solid var(--border-light);
    font-size: .875rem;
}
.portal-debt-total strong { font-size: 1.125rem; color: var(--primary); }
.portal-debt-total-sub { width: 100%; font-size: .75rem; color: var(--text-muted); }
.morosos-debt-banner {
    margin-bottom: 1rem; padding: 1rem 1.25rem; border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--primary-soft), var(--surface));
    border: 1px solid var(--border-light);
}
.morosos-debt-label { font-size: .6875rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); letter-spacing: .04em; }
.morosos-debt-val { font-size: 1.75rem; font-weight: 800; color: var(--primary); margin-top: .2rem; }
.morosos-debt-sub { font-size: .75rem; color: var(--text-muted); margin-top: .25rem; }
.morosos-debt-cell { font-variant-numeric: tabular-nums; white-space: nowrap; }
.morosos-actions { white-space: nowrap; }
.invoices-table-client .col-actions-workbench { width: 5.5rem; text-align: right; }
.invoices-table-client .col-amount { text-align: right; white-space: nowrap; }
.invoices-table-client .col-inv-num { white-space: nowrap; }

.invoice-num-link {
    display: inline-flex; align-items: center; gap: .25rem;
    border: 0; background: none; padding: 0; margin: 0;
    color: var(--primary-dark); cursor: pointer; font: inherit;
    border-bottom: 1px dashed rgba(43, 78, 180, .45);
    transition: color .15s, border-color .15s;
}
.invoice-num-link:hover { color: var(--primary); border-bottom-color: var(--primary); }
.invoice-num-link strong { font-weight: 700; }
.invoice-num-icon { font-size: .75rem; opacity: .75; }
.invoice-num-link-inline { border-bottom-style: solid; }

.invoice-doc-popover {
    position: fixed; inset: 0; z-index: 1200; pointer-events: none;
}
.invoice-doc-popover:not(.hidden) { pointer-events: auto; }
.invoice-doc-popover-card {
    position: fixed; width: 420px; max-width: calc(100vw - 32px);
    background: #fff; border: 1px solid var(--border); border-radius: 14px;
    box-shadow: 0 20px 50px rgba(26, 35, 50, .18); overflow: hidden;
    display: flex; flex-direction: column; max-height: 520px;
}
.invoice-doc-popover-head {
    display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem;
    padding: .85rem 1rem; background: linear-gradient(135deg, #1a3278, #2b4eb4); color: #fff;
}
.invoice-doc-popover-kicker {
    font-size: .65rem; text-transform: uppercase; letter-spacing: .06em; opacity: .85;
}
.invoice-doc-popover-title { display: block; font-size: 1rem; margin-top: .15rem; }
.invoice-doc-popover-close {
    border: 0; background: rgba(255,255,255,.15); color: #fff; width: 28px; height: 28px;
    border-radius: 8px; cursor: pointer; font-size: 1.25rem; line-height: 1;
}
.invoice-doc-popover-close:hover { background: rgba(255,255,255,.25); }
.invoice-doc-popover-body { flex: 1; min-height: 320px; background: #f0f4fa; }
.invoice-doc-popover-frame { width: 100%; height: 360px; border: 0; background: #fff; }
.invoice-doc-popover-foot {
    display: flex; align-items: center; justify-content: space-between; gap: .75rem;
    padding: .65rem 1rem; border-top: 1px solid var(--border); background: #fafbfd;
}
.invoice-doc-popover-name {
    font-size: .75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px;
}
.invoices-table-client .col-estado {
    max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    color: var(--text-muted); font-size: .8125rem;
}
.invoices-table-client .col-actions { width: 140px; text-align: right; }
.invoices-table-client .pay-date-cell { white-space: nowrap; }
.invoices-table-client .inline-pay-date { width: 100px; }

.invoice-month-badge {
    display: inline-flex; flex-direction: column; align-items: center;
    background: var(--primary-light); border: 1px solid var(--border);
    border-radius: 10px; padding: .45rem .65rem; min-width: 58px;
}
.invoice-month-badge .imb-month {
    font-size: .8125rem; font-weight: 700; color: var(--primary-dark);
    text-transform: uppercase; letter-spacing: .02em; line-height: 1.2;
}
.invoice-month-badge .imb-year { font-size: .6875rem; color: var(--text-muted); margin-top: .15rem; }

.invoice-actions { display: flex; gap: .375rem; justify-content: flex-end; flex-wrap: nowrap; }
.btn-action-sm { padding: .4rem .75rem; font-size: .75rem; white-space: nowrap; }
.edited-mark { color: var(--text-muted); font-size: .75rem; margin-left: .25rem; }

.invoices-table-full .col-razon-full {
    min-width: 200px; max-width: 280px; white-space: normal;
    word-break: break-word; line-height: 1.35; font-weight: 500;
}
.invoices-table-full .col-amount { white-space: nowrap; text-align: right; }
.invoices-table-full .col-estado { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.invoices-table-full .col-actions { white-space: nowrap; }

/* ─── Facturas: vista trabajo (toggle rápido por N°) ─── */
#invoices-content .invoices-list-body {
    overflow: visible;
    padding: 0;
}
.invoices-search-bar {
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem .75rem;
}
.invoices-hint {
    flex: 1 1 220px;
    min-width: 180px;
}

/* Facturas — tabla tipo billing SaaS */
.inv-summary-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-light);
    background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
}
.inv-summary-chip {
    display: flex;
    flex-direction: column;
    gap: .1rem;
    min-width: 4.5rem;
}
.inv-summary-val {
    font-size: 1.125rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
    color: var(--text);
}
.inv-summary-chip.is-success .inv-summary-val { color: #16a34a; }
.inv-summary-chip.is-warning .inv-summary-val { color: #d97706; }
.inv-summary-chip.is-money .inv-summary-val { color: var(--primary); }
.inv-summary-lbl {
    font-size: .6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
}

.inv-table-wrap {
    overflow-x: auto;
}
.inv-billing-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .8125rem;
}
.inv-billing-table th,
.inv-billing-table td {
    padding: .625rem 1rem;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}
.inv-billing-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface-2);
    font-size: .6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    white-space: nowrap;
}
.inv-billing-table tbody tr:last-child td { border-bottom: none; }
.inv-table-row {
    transition: background .12s ease;
}
.inv-table-row:hover {
    background: var(--primary-soft);
}
.inv-table-row.is-pending {
    box-shadow: inset 3px 0 0 #f59e0b;
}
.inv-table-row.is-pending:hover {
    background: rgba(245, 158, 11, .06);
}
.inv-td-client { min-width: 10rem; max-width: 22rem; }
.inv-client-cell { min-width: 0; }
.inv-client-name {
    display: block;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.inv-client-sub {
    display: block;
    margin-top: .1rem;
    font-size: .75rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.inv-td-month { width: 4.5rem; }
.inv-td-amount {
    text-align: right;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    color: var(--text);
}
.inv-th-amount { text-align: right; }
.inv-td-status { width: 1%; white-space: nowrap; }
.inv-status-cell {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
}
.inv-status-num {
    min-width: 2.75rem;
    text-align: right;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    font-size: .8125rem;
}
.inv-status-num .invoice-num-link {
    border: 0;
    background: none;
    padding: 0;
    cursor: pointer;
    color: inherit;
    font: inherit;
}
.inv-status-num .invoice-num-link:hover { color: var(--primary); }
.inv-billing-table .pay-badge-btn {
    min-width: 5.5rem;
    padding: .35rem .75rem;
    font-size: .6875rem;
    font-weight: 700;
    letter-spacing: .04em;
}
.inv-td-actions {
    width: 2.5rem;
    text-align: center;
    padding-left: .25rem;
    padding-right: .5rem;
}
.inv-row-edit-btn {
    width: 2rem;
    height: 2rem;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.125rem;
    line-height: 1;
    letter-spacing: .05em;
    transition: background .12s, color .12s;
}
.inv-row-edit-btn:hover {
    background: var(--surface-2);
    color: var(--primary);
}
.inv-table-empty {
    padding: 2.5rem 1rem !important;
    text-align: center;
    color: var(--text-muted);
}
.invoices-table-client .col-quick-pay { min-width: 11rem; }
.client-checklist-min {
    margin-top: .75rem;
    padding: .75rem 1rem;
    border-radius: var(--radius-sm);
    background: var(--warning-bg);
    border: 1px solid rgba(245, 158, 11, .2);
}

.invoices-table-workbench {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}
.invoices-table-workbench th,
.invoices-table-workbench td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}
.invoices-table-workbench th {
    background: var(--surface-2);
    font-size: .6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
}
.invoices-table-workbench tbody tr.is-pending {
    background: rgba(245, 158, 11, .06);
}
.invoices-table-workbench tbody tr:hover {
    background: var(--primary-soft);
}
.invoices-table-workbench .col-inv-num-workbench {
    white-space: nowrap;
    font-weight: 600;
    min-width: 110px;
}
.invoices-table-workbench .col-client-workbench {
    min-width: 160px;
    max-width: 280px;
}
.invoices-table-workbench .inv-client-name {
    display: block;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.invoices-table-workbench .inv-client-meta {
    display: block;
    font-size: .75rem;
    margin-top: .1rem;
}
.invoices-table-workbench .col-month-workbench {
    white-space: nowrap;
    color: var(--text-muted);
}
.invoices-table-workbench .col-amount-workbench {
    text-align: right;
    white-space: nowrap;
    min-width: 90px;
}
.invoices-table-workbench .col-pay-workbench {
    text-align: center;
    min-width: 130px;
}
.invoices-table-workbench .pay-badge-btn {
    min-width: 108px;
    padding: .45rem .85rem;
    font-size: .75rem;
    font-weight: 700;
    letter-spacing: .03em;
    border-radius: var(--radius-pill);
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform .1s, box-shadow .15s;
}
.invoices-table-workbench .pay-badge-btn:hover {
    transform: scale(1.04);
    box-shadow: var(--shadow-xs);
}
.invoices-table-workbench .pay-badge-btn.paid {
    background: var(--success-bg);
    color: var(--success);
    border-color: rgba(16, 185, 129, .35);
}
.invoices-table-workbench .pay-badge-btn.pending {
    background: var(--warning-bg);
    color: #b45309;
    border-color: rgba(245, 158, 11, .4);
}
.invoices-table-workbench .col-actions-workbench {
    text-align: right;
    white-space: nowrap;
    width: 80px;
}
#view-invoices,
#invoices-content {
    min-width: 0;
}

.col-razon { max-width: none; white-space: normal; word-break: break-word; }

/* Cobranza por correo */
.collection-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 1rem;
    align-items: start;
}
.collection-layout-side {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    position: sticky;
    top: 1rem;
}
.collection-checklist, .collection-mail-help {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 1rem 1.1rem;
}
.collection-checklist h4, .collection-mail-help h4 {
    margin: 0 0 .75rem;
    font-size: .875rem;
    font-weight: 700;
}
.collection-checklist ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: .65rem;
}
.collection-checklist li {
    display: flex;
    gap: .6rem;
    align-items: flex-start;
    font-size: .8125rem;
}
.collection-checklist li.is-done .collection-check-icon { color: #16a34a; }
.collection-checklist li.is-pending .collection-check-icon { color: var(--text-muted); }
.collection-check-icon { flex-shrink: 0; width: 1.1rem; font-weight: 700; line-height: 1.35; }
.collection-mail-help dl { margin: 0; display: flex; flex-direction: column; gap: .75rem; }
.collection-mail-help dt { font-size: .6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: .15rem; }
.collection-mail-help dd { margin: 0; font-size: .8125rem; line-height: 1.45; }
.collection-mail-help code { font-size: .75rem; word-break: break-word; }
.collection-smtp-banner {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 1rem 1.25rem; border-radius: 12px; margin-bottom: 1rem;
    border: 1px solid var(--border); background: var(--surface);
}
.collection-smtp-banner.ok { border-color: #86efac; background: #f0fdf4; }
.collection-smtp-banner.warn { border-color: #fcd34d; background: #fffbeb; }
.collection-smtp-banner p { margin: .25rem 0 0; font-size: .875rem; }

.collection-kpi-grid {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; margin-bottom: 1rem;
}
.collection-kpi {
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    padding: 1rem; display: flex; flex-direction: column; gap: .25rem;
}
.collection-kpi.ready { border-color: #93c5fd; background: var(--primary-light); }
.collection-kpi.warn .kpi-num { color: #d97706; }
.collection-kpi .kpi-num { font-size: 1.5rem; font-weight: 800; color: var(--primary-dark); }
.collection-kpi .kpi-lbl { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

.collection-toolbar {
    display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end;
    justify-content: space-between; max-width: 100%;
}
.collection-toolbar-left, .collection-toolbar-right {
    display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end;
    min-width: 0; flex: 1 1 280px; max-width: 100%;
}
.collection-toolbar-row {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr);
    gap: .75rem;
    align-items: end;
}
.collection-filters-bar {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr);
    gap: .75rem;
    align-items: end;
    padding: .85rem 1.25rem;
    border-bottom: 1px solid var(--border-light);
    background: var(--surface-2);
}
.collection-field { display: flex; flex-direction: column; min-width: 0; }
.collection-field-grow { min-width: 0; }
.collection-filter-label { font-size: .75rem; color: var(--text-muted); display: block; margin-bottom: .25rem; font-weight: 600; }
.collection-select, .collection-search {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .5rem .75rem;
    font-size: .875rem;
    background: #fff;
    min-height: 38px;
    box-sizing: border-box;
}
.collection-table-body { padding: 0; }
.collection-table-wrap { border-radius: 0; border: 0; }
.collection-empty { padding: 1.5rem 1.25rem; }
.collection-client-cell {
    display: flex;
    align-items: center;
    gap: .65rem;
    min-width: 0;
}
.collection-client-text { min-width: 0; }
.collection-client-name {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px;
}
.collection-client-rut {
    display: block;
    font-size: .75rem;
    color: var(--text-muted);
}
.collection-email-link {
    font-size: .8125rem;
    word-break: break-all;
}
.collection-missing {
    color: #dc2626;
    font-size: .8125rem;
    font-weight: 600;
}
.collection-pending-amount {
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--primary-dark);
}
.collection-pending-meta {
    font-size: .75rem;
    color: var(--text-muted);
    margin-top: .1rem;
}
.collection-inv-chips {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem;
    margin-top: .35rem;
}
.collection-inv-chip {
    display: inline-block;
    padding: .1rem .4rem;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border-light);
    font-size: .6875rem;
    font-weight: 600;
    color: var(--text-muted);
}
.collection-inv-more {
    font-size: .6875rem;
    color: var(--text-muted);
    align-self: center;
}
.collection-issue-tags {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
}
.collection-issue-tag {
    display: inline-flex;
    align-items: center;
    padding: .2rem .5rem;
    border-radius: 999px;
    font-size: .6875rem;
    font-weight: 700;
    white-space: nowrap;
}
.collection-issue-tag.is-ok { background: var(--success-bg); color: var(--success-text); }
.collection-issue-tag.is-danger { background: var(--danger-bg); color: var(--danger-text); }
.collection-issue-tag.is-warn { background: var(--warning-bg); color: var(--warning-text); }
.collection-issue-tag.is-muted { background: var(--surface-2); color: var(--text-muted); }
.collection-actions {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    align-items: stretch;
    min-width: 7rem;
}
.collection-banner { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.collection-banner-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.collection-table .col-check { width: 42px; text-align: center; }
.collection-table .col-client { min-width: 200px; }
.collection-table .col-email { min-width: 140px; max-width: 200px; }
.collection-table .col-pending { min-width: 150px; }
.collection-table .col-status { min-width: 110px; }
.collection-table td.actions-cell { min-width: 7.5rem; vertical-align: middle; }
.collection-table tr.row-ready { background: rgba(43, 78, 180, .03); }
.collection-table tr.row-blocked { background: var(--surface); }
.collection-table tr.row-blocked .collection-pending-amount { opacity: .85; }
.year-static-pill {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .45rem .75rem;
    border-radius: 8px;
    background: var(--surface-2, #f4f6f8);
    color: var(--text-muted);
    font-size: .875rem;
    white-space: nowrap;
}
.year-static-pill strong { color: var(--text, #1a1a1a); font-weight: 700; }
.matrix-legend {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem 1.25rem;
    margin: .5rem 0 1rem;
    padding: .6rem .85rem;
    border-radius: 10px;
    background: var(--surface-2, #f4f6f8);
    font-size: .8rem;
    color: var(--text-muted);
}
.matrix-legend .month-ticket {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35rem;
    height: 1.35rem;
    margin-right: .35rem;
    border-radius: 6px;
    font-size: .75rem;
    vertical-align: middle;
}
.month-cell.month-missing { cursor: default; }
.empty-centered { text-align: center; padding: 2rem 1rem; width: 100%; }
.collection-select, .collection-search, .collection-note-input {
    border: 1px solid var(--border); border-radius: 8px; padding: .5rem .75rem; font-size: .875rem;
    background: #fff; min-height: 38px;
}
.collection-search { flex: 1 1 180px; min-width: 0; max-width: 100%; }
.collection-note-input { flex: 1 1 220px; min-width: 0; max-width: 100%; }

.text-xs { font-size: .75rem; }
.text-sm { font-size: .8125rem; }
.text-danger { color: #dc2626; }

.collection-preview-meta {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem 1rem;
    margin-bottom: 1rem; padding: 1rem; background: var(--primary-light); border-radius: 10px;
}
.collection-preview-meta .lbl { display: block; font-size: .7rem; text-transform: uppercase; color: var(--text-muted); margin-bottom: .15rem; }
.collection-preview-frame-wrap {
    border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #f0f4fa;
}
.collection-preview-frame { width: 100%; height: 420px; border: 0; background: #fff; }

/* --- Plantillas de correo: tabs + paneles --- */
.settings-tabs { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: 1.1rem; border-bottom: 1px solid var(--border); }
.settings-tab {
    appearance: none; background: transparent; border: 0; border-bottom: 2px solid transparent;
    padding: .55rem .9rem; font-size: .85rem; font-weight: 600; color: var(--text-muted);
    cursor: pointer; border-radius: 6px 6px 0 0;
}
.settings-tab:hover { color: var(--text); background: var(--primary-light); }
.settings-tab.is-active { color: var(--primary, #1a3278); border-bottom-color: var(--primary, #1a3278); }
.settings-pane { display: none; }
.settings-pane.is-active { display: block; }
.form-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem 1rem; }
@media (max-width: 640px) { .form-grid-2 { grid-template-columns: 1fr; } }
.settings-divider { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }
.whatsapp-preview {
    white-space: pre-wrap; word-break: break-word; background: #f0f4fa; border: 1px solid var(--border);
    border-radius: 10px; padding: 1rem; font-size: .85rem; line-height: 1.5; max-height: 420px; overflow: auto;
}

/* --- Selector de tipo de correo en vista previa --- */
.collection-preview-typebar { display: flex; align-items: center; flex-wrap: wrap; gap: .6rem; margin-bottom: .9rem; }
.collection-preview-typebar .lbl { font-size: .7rem; text-transform: uppercase; color: var(--text-muted); }
.collection-type-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.collection-type-btn { appearance: none; background: #fff; border: 0; padding: .4rem .8rem; font-size: .82rem; font-weight: 600; color: var(--text-muted); cursor: pointer; }
.collection-type-btn + .collection-type-btn { border-left: 1px solid var(--border); }
.collection-type-btn.is-active { background: var(--primary, #1a3278); color: #fff; }

/* Chip de tipo sugerido en la cola */
.collection-type-chip { display: inline-block; margin-top: .25rem; padding: .1rem .45rem; border-radius: 999px; font-size: .65rem; font-weight: 700; text-transform: uppercase; }
.collection-type-chip.is-emission { background: #e6f4ea; color: #1e7a3d; }
.collection-type-chip.is-reminder { background: #eef1f8; color: #41506e; }

/* Botón WhatsApp */
.btn-whatsapp, .btn-success { background: #25d366; color: #0b3d1f; border-color: #1ebe5a; }
.btn-whatsapp:hover:not(:disabled), .btn-success:hover:not(:disabled) { background: #1ebe5a; color: #07331a; }
.btn-action.btn-whatsapp { background: #25d366; color: #0b3d1f; }
.btn-action.btn-whatsapp:disabled { opacity: .5; cursor: not-allowed; }

/* Menú desplegable «WhatsApp ▾» (agrupa todas las acciones de WhatsApp).
   La lista usa position:fixed (posicionada por JS) para que NUNCA la recorten
   contenedores con overflow (tablas con scroll, modales, etc.). */
.wa-menu { position: relative; display: inline-block; }
.wa-menu-toggle { background: #25d366; color: #0b3d1f; border-color: #1ebe5a; }
.wa-menu-toggle:hover:not(:disabled) { background: #1ebe5a; color: #07331a; }
.wa-menu-caret { font-size: .7em; opacity: .85; margin-left: .15rem; }
.wa-menu-list {
    position: fixed; z-index: 1250; display: none;
    min-width: 220px; padding: .35rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm, 10px); box-shadow: var(--shadow-lg, 0 10px 30px rgba(26,35,50,.18));
}
.wa-menu.is-open .wa-menu-list { display: block; }
.wa-menu-item {
    display: block; width: 100%; text-align: left;
    padding: .5rem .65rem; border: 0; border-radius: 8px;
    background: transparent; color: var(--text); cursor: pointer;
    font-size: .8125rem; line-height: 1.3; white-space: nowrap;
}
.wa-menu-item:hover { background: var(--primary-soft, #eef2fb); color: var(--primary, #2b4eb4); }

/* Ventana del TEXTO de WhatsApp (overlay autocontenido, sin librerías). */
.wa-text-overlay {
    position: fixed; inset: 0; z-index: 1200;
    display: flex; align-items: center; justify-content: center;
    padding: 1.25rem; background: rgba(26, 35, 50, .45);
}
.wa-text-card {
    width: 100%; max-width: 480px; max-height: 88vh; overflow-y: auto;
    background: var(--surface); border-radius: var(--radius-lg, 16px);
    box-shadow: var(--shadow-lg, 0 18px 50px rgba(26,35,50,.28)); padding: 1.1rem 1.25rem;
}
.wa-text-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .65rem; }
.wa-text-head strong { font-size: 1rem; color: var(--text); }
.wa-text-close { border: 0; background: transparent; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--text-muted); }
.wa-text-close:hover { color: var(--text); }
.wa-text-warn { font-size: .8rem; color: #92400e; background: #fef3c7; border-radius: 8px; padding: .45rem .6rem; margin-bottom: .55rem; }
.wa-text-area {
    width: 100%; font: inherit; font-size: .85rem; line-height: 1.45;
    padding: .65rem; border: 1px solid var(--border); border-radius: 10px;
    resize: vertical; background: var(--surface-2, #f8fafd); color: var(--text);
}
.wa-text-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .65rem; }
.wa-text-note { font-size: .75rem; color: var(--text-muted); margin-top: .55rem; line-height: 1.45; }

.invoice-tab-summary-actions {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem;
}
.invoice-tab-email-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.btn-sm { padding: .4rem .85rem; font-size: .8125rem; }

.badge-pill.success { background: #dcfce7; color: #166534; }
.badge-pill.warning { background: #fef3c7; color: #92400e; }
.badge-pill.danger { background: #fee2e2; color: #991b1b; }

.modal-content-sm { max-width: 420px; }
.confirm-message { margin: 0 0 1.25rem; line-height: 1.55; color: var(--text); }
.confirm-actions { justify-content: flex-end; margin: 0; }

.pagination-bar {
    display: flex; align-items: center; justify-content: center; gap: 1rem;
    padding: 1rem; border-top: 1px solid var(--border); flex-wrap: wrap;
}
.pagination-info { font-size: .875rem; color: var(--text-muted); }
.loading-inline { padding: 2rem; text-align: center; color: var(--text-muted); }

.client-checklist {
    margin-top: 1rem; padding: 1rem; background: var(--primary-light);
    border: 1px solid var(--border); border-radius: 10px;
}
.client-checklist-title {
    font-size: .75rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .05em; color: var(--text-muted); margin-bottom: .65rem;
}
.client-check-item {
    display: flex; align-items: flex-start; gap: .6rem; padding: .45rem 0;
    border-bottom: 1px solid rgba(26, 50, 120, .08);
}
.client-check-item:last-child { border-bottom: 0; }
.client-check-item.ok .client-check-icon { color: #16a34a; }
.client-check-item.miss .client-check-icon { color: #d97706; }
.client-check-icon { font-weight: 700; width: 1.1rem; text-align: center; }

.btn.is-loading { opacity: .75; cursor: wait; }

@media (max-width: 900px) {
    .collection-layout { grid-template-columns: 1fr; }
    .collection-layout-side { position: static; }
    .collection-filters-bar { grid-template-columns: 1fr; }
    .collection-toolbar-row { grid-template-columns: 1fr; }
    .collection-kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .collection-banner-actions { width: 100%; }
}

/* Responsive */
@media (max-width: 1400px) {
    .dash-kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .dash-body { grid-template-columns: 1fr; }
    .dash-semester-grid { grid-template-columns: 1fr; }
    .dash-month-row { grid-template-columns: 4rem minmax(0, 1fr) 2.25rem; }
    .dash-month-amt { display: none; }
    .portal-side .task-list { max-height: none; }
}

@media (max-width: 1200px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .portal-stats-band { grid-template-columns: repeat(2, 1fr); }
    .portal-stat:nth-child(2) { border-right: none; }
    .portal-stat:nth-child(1),
    .portal-stat:nth-child(2) { border-bottom: 1px solid var(--border-light); }
    .dash-layout { grid-template-columns: 1fr; }
    .portal-top { grid-template-columns: 1fr; }
    .quick-actions { grid-template-columns: repeat(2, 1fr); }
    .topbar-center { display: none; }
}

@media (max-width: 768px) {
    .dash-header { flex-direction: column; align-items: stretch; }
    .dash-kpi-grid { grid-template-columns: 1fr; }
    .dash-shortcuts { justify-content: stretch; }
    .dash-shortcut { flex: 1 1 calc(50% - .25rem); justify-content: center; }
    .pending-item {
        grid-template-columns: 1fr;
        gap: .75rem;
    }
    .pending-item-pay,
    .pending-item-actions { width: 100%; }
    .pending-item-actions .invoice-actions { justify-content: flex-start; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .portal-stats-band { grid-template-columns: 1fr; }
    .portal-stat { border-right: none; border-bottom: 1px solid var(--border-light); }
    .portal-stat:last-child { border-bottom: none; }
}

/* Módulo Pro */
.user-role-badge {
    display: inline-block; margin-top: .2rem; font-size: .7rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .04em; color: var(--primary);
    background: var(--primary-light); padding: .15rem .45rem; border-radius: 999px;
}
.pro-role-list { margin: .75rem 0 0; padding-left: 1.25rem; line-height: 1.7; color: var(--text-muted); }
.pro-role-list strong { color: var(--text); }

.activity-feed { display: flex; flex-direction: column; gap: .65rem; max-height: 280px; overflow-y: auto; }
.activity-item { font-size: .85rem; line-height: 1.45; padding-bottom: .55rem; border-bottom: 1px solid var(--border); }
.activity-item:last-child { border-bottom: 0; padding-bottom: 0; }
.activity-item .time { font-size: .75rem; color: var(--text-muted); margin-top: .2rem; }

.reconcile-card {
    display: grid; grid-template-columns: 1fr 1.4fr; gap: 1rem; align-items: start;
    padding: 1rem; border-bottom: 1px solid var(--border);
}
.reconcile-card:last-child { border-bottom: 0; }
.reconcile-bank { display: flex; flex-direction: column; gap: .35rem; }
.reconcile-bank span { font-size: .85rem; color: var(--text-muted); }
.reconcile-matches { display: flex; flex-direction: column; gap: .5rem; }
.reconcile-match-btn {
    display: flex; justify-content: space-between; align-items: center; gap: .75rem;
    width: 100%; text-align: left; padding: .65rem .85rem; border: 1px solid var(--border);
    border-radius: 8px; background: #fff; cursor: pointer; transition: border-color .15s, background .15s;
}
.reconcile-match-btn:hover { border-color: var(--primary); background: var(--primary-light); }

.mobile-search-fab {
    display: none; position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 90;
    width: 3.25rem; height: 3.25rem; border-radius: 50%; border: 0;
    background: var(--primary); color: #fff; box-shadow: var(--shadow-lg); cursor: pointer;
}
.mobile-search-fab svg { width: 1.35rem; height: 1.35rem; }
.mobile-search-overlay {
    position: fixed; inset: 0; z-index: 200; background: rgba(15, 23, 42, .45);
    display: flex; align-items: flex-end; justify-content: center; padding: 1rem;
}
.mobile-search-overlay.hidden { display: none; }
.mobile-search-sheet {
    width: 100%; max-width: 480px; background: #fff; border-radius: 14px 14px 0 0;
    padding: 1rem; display: flex; flex-direction: column; gap: .65rem;
}
.mobile-search-sheet input { width: 100%; padding: .75rem 1rem; border: 1px solid var(--border); border-radius: 8px; }

body.modal-open { overflow: hidden; }

.notif-wrap { position: relative; }
.notif-panel {
    position: absolute; right: 0; top: calc(100% + 8px); width: min(380px, 92vw);
    background: #fff; border: 1px solid var(--border); border-radius: 12px;
    box-shadow: var(--shadow-lg); z-index: 120; overflow: hidden;
}
.notif-panel.hidden { display: none; }
.notif-panel-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: .75rem 1rem; border-bottom: 1px solid var(--border); background: var(--primary-light);
}
.notif-list { max-height: 360px; overflow-y: auto; display: flex; flex-direction: column; }
.notif-item {
    display: block; width: 100%; text-align: left; padding: .85rem 1rem;
    border: 0; border-bottom: 1px solid var(--border); background: #fff; cursor: pointer;
}
.notif-item:hover { background: #f8fafc; }
.notif-item:last-child { border-bottom: 0; }
.notif-item-title { font-weight: 700; font-size: .875rem; margin-bottom: .2rem; }
.notif-item-msg { font-size: .8rem; color: var(--text-muted); line-height: 1.4; }
.notif-item.notif-danger .notif-item-title { color: #b91c1c; }
.notif-item.notif-warning .notif-item-title { color: #b45309; }
.notif-empty { padding: 1.25rem; color: var(--text-muted); font-size: .875rem; text-align: center; }
.match-label { font-style: normal; font-size: .7rem; font-weight: 700; color: var(--primary); background: var(--primary-light); padding: .1rem .4rem; border-radius: 999px; margin-left: .35rem; }
body.role-readonly .danger-text,
body.role-readonly #btn-new-treasury,
body.role-readonly #btn-goto-register,
body.role-readonly [data-treasury-edit],
body.role-readonly [data-treasury-del],
body.role-readonly [data-doc-delete],
body.role-readonly [data-require-write],
body.role-readonly #btn-collection-send-bulk,
body.role-readonly #btn-collection-reminders,
body.role-readonly #btn-collection-resume-queue,
body.role-readonly [data-collection-send] { display: none !important; }

.code-textarea {
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
    font-size: .8rem; line-height: 1.45;
}
.backup-restore-form input[type="file"] { width: 100%; }

/* ─── Escala proporcional (scroll natural con rueda en toda la pagina) ─── */
body:has(#app:not(.hidden)) {
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

body:has(#app:not(.hidden))::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

#clients-content {
    max-width: 100%;
    min-width: 0;
}

#clients-content .buk-card-table {
    max-width: 100%;
}

#clients-content .period-hero-bar {
    flex-wrap: nowrap;
}

#clients-content .period-hero-month-block .month {
    font-size: clamp(1.25rem, 2vw, 2rem);
}

#clients-content .period-hero-metric .val {
    font-size: clamp(1rem, 1.6vw, 1.375rem);
}

#clients-content .client-avatar {
    width: clamp(24px, 2.2vw, 34px);
    height: clamp(24px, 2.2vw, 34px);
    font-size: clamp(.55rem, .9vw, .6875rem);
}

#clients-grid {
    font-size: clamp(.65rem, .85vw, .8125rem);
}

#clients-grid .month-header {
    font-size: clamp(.55rem, .75vw, .6875rem);
    padding: clamp(.25rem, .4vw, .5rem) .05rem !important;
}

#clients-grid .month-cell {
    font-size: clamp(.65rem, .8vw, .8125rem);
    height: clamp(26px, 3vw, 34px);
    padding: .2rem .05rem !important;
}

@media (max-width: 1500px) {
    :root { --sidebar-w: 240px; }
}

@media (max-width: 1350px) {
    #clients-grid th:first-child,
    #clients-grid td:first-child { width: 20%; }
    #clients-grid th:nth-child(2),
    #clients-grid td:nth-child(2) { width: 9%; }
    #clients-grid th:nth-child(3),
    #clients-grid td:nth-child(3) { width: 7%; }
}

@media (max-width: 1200px) {
    .content-area { padding: 1.25rem 1.25rem 2rem; }
    .topbar-center { max-width: 320px; }
}

@media (max-width: 900px) {
    .mobile-search-fab { display: flex; align-items: center; justify-content: center; }
    .reconcile-card { grid-template-columns: 1fr; }
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: translateX(0); }
    .main-area { margin-left: 0; width: 100%; max-width: 100%; }
    .mobile-menu { display: flex; align-items: center; justify-content: center; }
    .login-screen { grid-template-columns: 1fr; }
    .login-left { display: none; }
    .content-area { padding: 1rem; }
    .topbar { padding: 0 1rem; }
    .dash-grid-2 { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .period-hero-bar { flex-direction: column; }
    .period-hero-metrics { flex-wrap: wrap; }
    .period-hero-metric { min-width: 50%; border-bottom: 1px solid rgba(255,255,255,.1); }
    .month-hero-name { font-size: 2rem; }
}

/* --- Acceso del cliente (ficha admin) --- */
.access-status {
    background: var(--surface-2, #f5f7fa);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 10px;
    padding: 1rem 1.1rem;
    margin-bottom: 1.1rem;
}
.access-status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.access-status .lbl {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted, #64748b);
    margin-bottom: .15rem;
}
.access-username code {
    font-size: 1rem;
    font-weight: 600;
    background: rgba(0, 0, 0, .05);
    padding: .15rem .5rem;
    border-radius: 6px;
}
.access-badge {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
    padding: .28rem .6rem;
    border-radius: 999px;
    white-space: nowrap;
}
.access-badge.on { background: #dcfce7; color: #166534; }
.access-badge.off { background: #fee2e2; color: #991b1b; }
.access-badge.none { background: #e2e8f0; color: #475569; }
.access-company-list { list-style: none; margin: .5rem 0 .75rem; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.access-company-list li {
    display: flex; align-items: center; justify-content: space-between; gap: .75rem;
    padding: .5rem .7rem; background: var(--surface-2, #f8fafc);
    border: 1px solid var(--border, #e5e7eb); border-radius: 8px;
}
.access-company-name { min-width: 0; font-size: .875rem; font-weight: 600; color: var(--text, #1f2937); }
.access-company-name code { font-weight: 700; color: var(--text-muted, #6b7280); }
.access-pass-row {
    display: flex;
    gap: .5rem;
    align-items: stretch;
}
.access-pass-row input { flex: 1; }
.access-actions {
    display: flex;
    gap: .6rem;
    align-items: center;
    flex-wrap: wrap;
}
