:root {
    --primary: #1e4ea1;
    --primary-strong: #16408a;
    --primary-soft: #e8eef9;
    --accent: #d71920;
    --accent-soft: #fdebed;
    --whatsapp: #25D366;
    --mail: #6b7280;
    --ink: #1f2937;
    --text: #374151;
    --muted: #6b7280;
    --line: #d8dee9;
    --card: rgba(255,255,255,.88);
    --card-solid: #ffffff;
    --bg: #eef2f7;
    --shadow: 0 22px 50px rgba(15, 23, 42, .08);
    --radius: 26px;
    --radius-sm: 16px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(30, 78, 161, .10), transparent 28rem),
        radial-gradient(circle at 100% 0%, rgba(215, 25, 32, .08), transparent 22rem),
        linear-gradient(135deg, #f2f5fb 0%, #eff3f8 46%, #f7f8fb 100%);
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button, input, select { font: inherit; }

h1, h2, h3 { margin: 0; line-height: 1.08; letter-spacing: -.03em; }
h1 { font-size: clamp(1.9rem, 4vw, 2.4rem); color: var(--primary); }
h2 { font-size: clamp(1.25rem, 3vw, 1.7rem); color: var(--primary); }
h3 { font-size: 1.05rem; color: #111827; }

.muted { color: var(--muted); line-height: 1.55; }
.eyebrow {
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: .12em;
    font-size: .78rem;
    font-weight: 800;
    margin: 0 0 10px;
}

/* Login */
.login-body {
    display: grid;
    place-items: center;
    padding: 24px;
}
.login-shell-compact { width: min(460px, 100%); }
.login-card {
    background: rgba(255,255,255,.92);
    border-radius: 34px;
    padding: 36px 36px 28px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(255,255,255,.85);
    text-align: left;
}
.login-card-reference {
    background: linear-gradient(180deg, rgba(255,255,255,.96), rgba(249,250,252,.96));
}
.login-logo-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}
.login-logo-wrap img {
    width: 110px;
    height: 110px;
    object-fit: contain;
}
.login-title {
    text-align: center;
    color: var(--primary);
    font-weight: 900;
    margin-bottom: 8px;
}
.login-title span { display: inline-block; margin-top: 2px; }
.login-subtitle {
    text-align: center;
    color: #5b6f91;
    margin: 0 0 20px;
    font-size: 1.05rem;
}
.login-submit {
    background: linear-gradient(135deg, #1f57b7, #1e4ea1);
    box-shadow: 0 16px 30px rgba(30, 78, 161, .18);
}
.login-footer {
    margin: 20px 0 0;
    text-align: center;
    color: #61708a;
    line-height: 1.45;
}

/* Forms + buttons */
.form-stack, .grid-form {
    display: grid;
    gap: 16px;
}
label {
    display: grid;
    gap: 8px;
    font-size: .95rem;
    font-weight: 800;
    color: #1f2937;
}
input, select {
    width: 100%;
    min-width: 0;
    border: 1px solid #cfd8e5;
    background: #eef3fb;
    color: var(--ink);
    border-radius: 16px;
    padding: 13px 14px;
    outline: none;
    transition: .2s ease;
}
input::placeholder { color: #8fa0ba; }
input:focus, select:focus {
    border-color: rgba(30, 78, 161, .45);
    box-shadow: 0 0 0 4px rgba(30, 78, 161, .10);
    background: #fff;
}
.btn {
    appearance: none;
    border: 0;
    border-radius: 15px;
    padding: 11px 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 800;
    transition: .2s ease;
    white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary {
    color: #fff;
    background: linear-gradient(135deg, #1f57b7, #1e4ea1);
    box-shadow: 0 14px 28px rgba(30, 78, 161, .18);
}
.btn.ghost {
    color: var(--primary);
    background: #fff;
    border: 1px solid #d6e0ef;
}
.btn.mini {
    padding: 8px 12px;
    border-radius: 12px;
    font-size: .87rem;
    background: #f8fafc;
    border: 1px solid #dde5f0;
}
.btn.danger { color: #b91c1c; background: #fff1f2; }
.btn.full { width: 100%; }

.alert {
    border-radius: 16px;
    padding: 13px 15px;
    margin-bottom: 16px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
}
.alert.danger {
    background: #fff1f2;
    border-color: #fecdd3;
    color: #991b1b;
}
.alert.success {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1d4ed8;
}

/* App layout */
.page-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 10px 18px;
    background: rgba(255,255,255,.82);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid rgba(31, 41, 55, .08);
    position: sticky;
    top: 0;
    z-index: 30;
}
.site-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.brand-badge {
    width: 58px;
    height: 58px;
    border-radius: 18px;
    background: #fff;
    display: grid;
    place-items: center;
    box-shadow: 0 10px 25px rgba(30, 78, 161, .10);
    flex: 0 0 auto;
}
.brand-badge img {
    width: 42px;
    height: 42px;
    object-fit: contain;
}
.site-brand strong {
    display: block;
    color: var(--primary-strong);
    font-size: 1.35rem;
    line-height: 1.1;
}
.site-brand span {
    display: block;
    color: #6b7280;
    font-size: .97rem;
}
.site-user-pill {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    padding: 10px 16px;
    border-radius: 999px;
    border: 1px solid rgba(31, 41, 55, .10);
    background: rgba(255,255,255,.88);
    color: var(--text);
    font-weight: 600;
}
.site-user-pill a {
    color: var(--accent);
    font-weight: 800;
}
.layout-shell {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 22px;
    width: min(1600px, 100%);
    margin: 0 auto;
    padding: 20px;
}
.sidebar {
    align-self: start;
    position: sticky;
    top: 88px;
    background: rgba(255,255,255,.82);
    border: 1px solid rgba(31, 41, 55, .08);
    border-radius: 26px;
    padding: 16px;
    box-shadow: var(--shadow);
}
.nav {
    display: grid;
    gap: 8px;
}
.nav a {
    padding: 13px 14px;
    border-radius: 16px;
    color: #1f2937;
    font-weight: 800;
    border: 1px solid transparent;
}
.nav a:hover {
    background: #f7f9fc;
    border-color: #e5ebf4;
}
.nav a.active {
    color: var(--primary-strong);
    background: linear-gradient(135deg, #edf3ff, #f8fbff);
    border-color: #d9e6fb;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.7);
}
.content { min-width: 0; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 11px 14px;
    border-radius: 999px;
    background: #fff;
    border: 1px solid #dbe3ef;
    color: var(--muted);
    font-weight: 800;
    white-space: nowrap;
}

.panel {
    background: rgba(255,255,255,.85);
    border: 1px solid rgba(255,255,255,.9);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
    margin-bottom: 22px;
}
.hero-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}
.section-head {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}
.section-head.compact { align-items: start; }
.toolbar {
    display: flex;
    align-items: end;
    gap: 12px;
    flex-wrap: wrap;
}
.search-row { display: grid; gap: 14px; }
.search-box input {
    font-size: 1.05rem;
    padding: 15px 16px;
    border-radius: 18px;
}

/* Directory cards */
.directory-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 16px;
}
.person-card {
    background: #fff;
    border: 1px solid rgba(31, 41, 55, .12);
    border-top: 6px solid #d8e0eb;
    border-radius: 24px;
    padding: 18px;
    display: grid;
    gap: 12px;
    transition: .2s ease;
}
.person-card.delegado { border-top-color: var(--accent); }
.person-card.subcomisionado { border-top-color: var(--primary); }
.person-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 18px 40px rgba(15, 23, 42, .08);
}
.person-card-header {
    display: grid;
    gap: 3px;
}
.person-card-role {
    color: var(--muted);
    font-weight: 600;
}
.person-meta {
    display: grid;
    gap: 7px;
    color: var(--text);
    line-height: 1.45;
}
.person-meta b { color: #374151; }
.contact-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    padding-top: 2px;
}
.contact-actions a {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: #fff;
    border: 1px solid #d8e0eb;
    transition: .2s ease;
}
.contact-actions a:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(15, 23, 42, .08);
}
.contact-actions .wa { color: var(--whatsapp); }
.contact-actions .phone { color: var(--primary); }
.contact-actions .mail { color: var(--mail); }
.contact-actions svg { width: 22px; height: 22px; }

/* Forms */
.form-panel .grid-form {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
.modern-form .span-2 { grid-column: span 2; }
.grid-form .permissions,
.grid-form .form-actions,
.grid-form .checkbox-row { grid-column: 1 / -1; }
.permissions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
    align-items: center;
}
.permissions strong { width: 100%; }
.permissions label, .checkbox-row {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
}
.permissions input, .checkbox-row input { width: auto; }
.form-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.helper-note {
    width: 100%;
    margin: -4px 0 2px;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}
.kpi {
    background: rgba(255,255,255,.85);
    border: 1px solid rgba(255,255,255,.95);
    border-radius: 24px;
    padding: 20px;
    box-shadow: var(--shadow);
}
.kpi span { display:block; color: var(--muted); font-weight: 800; margin-bottom: 8px; }
.kpi strong { font-size: clamp(2rem, 6vw, 3.1rem); letter-spacing: -.06em; color: var(--primary); }
.charts-grid {
    display: grid;
    grid-template-columns: 1.2fr .8fr;
    gap: 22px;
}
canvas { width: 100%; max-height: 360px; }

.table-wrap { overflow: auto; border-radius: 18px; border: 1px solid #d9e1ec; }
table { width: 100%; border-collapse: collapse; background: rgba(255,255,255,.86); }
th, td {
    padding: 12px 13px;
    border-bottom: 1px solid #e4e9f1;
    text-align: left;
    vertical-align: top;
}
th {
    background: #f5f8fc;
    color: #46566f;
    font-size: .82rem;
    text-transform: uppercase;
    letter-spacing: .08em;
}
td { color: #374151; }
.actions-cell {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.actions-cell form { margin: 0; }
.small-text { font-size: .78rem; color: var(--muted); max-width: 260px; }

details summary {
    cursor: pointer;
    color: var(--primary);
    font-weight: 800;
}
pre {
    white-space: pre-wrap;
    max-width: 460px;
    background: #f8fafc;
    border-radius: 12px;
    padding: 12px;
    overflow: auto;
}
.app-footer {
    text-align: center;
    color: #61708a;
    font-weight: 600;
    font-size: .92rem;
    line-height: 1.45;
    padding: 8px 10px 24px;
}
.print-footer {
    margin-top: 18px;
    padding-top: 12px;
    border-top: 1px solid #e5e7eb;
    text-align: center;
    color: #64748b;
    font-size: .85rem;
}

.empty-state {
    text-align: center;
    padding: 28px;
    color: var(--muted);
    background: rgba(255,255,255,.78);
    border: 1px dashed #d6deea;
    border-radius: 18px;
}

/* Print */
.print-body {
    background: #f4f4f5;
    padding: 18px;
}
.print-page {
    width: min(980px, 100%);
    margin: 0 auto;
    background: #fff;
    padding: 26px;
    border-radius: 18px;
    box-shadow: 0 18px 50px rgba(0,0,0,.10);
}
.print-page.compact { min-height: 930px; }
.print-header {
    display: flex;
    align-items: center;
    gap: 16px;
    border-bottom: 2px solid #f1f5f9;
    padding-bottom: 16px;
    margin-bottom: 18px;
}
.print-header img { width: 72px; height: 72px; object-fit: contain; }
.print-header p { margin: 4px 0 0; color: #64748b; }
.print-table th, .print-table td { font-size: .75rem; padding: 7px; }
.print-kpis {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 18px 0;
}
.print-kpis div {
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    padding: 14px;
}
.print-kpis strong { display:block; font-size: 2rem; color: var(--primary); }
.print-kpis span { color: var(--muted); font-weight: 800; }
.print-bars { margin-top: 20px; }
.print-bars p { display:flex; justify-content:space-between; margin: 12px 0 6px; font-weight: 800; }
.bar { height: 14px; border-radius: 99px; background: #eef2f7; overflow: hidden; }
.bar i { display:block; height:100%; background: linear-gradient(90deg, #1f57b7, #d71920); border-radius: inherit; }

@media (max-width: 1100px) {
    .layout-shell {
        grid-template-columns: 1fr;
    }
    .sidebar {
        position: relative;
        top: 0;
    }
    .nav {
        display: flex;
        overflow-x: auto;
        padding-bottom: 4px;
    }
    .nav a { flex: 0 0 auto; }
    .hero-panel,
    .section-head {
        flex-direction: column;
        align-items: stretch;
    }
    .form-panel .grid-form {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 760px) {
    .site-header {
        flex-direction: column;
        align-items: stretch;
    }
    .site-user-pill {
        justify-content: space-between;
    }
    .layout-shell {
        padding: 14px;
        gap: 14px;
    }
    .panel { padding: 18px; border-radius: 22px; }
    .kpi-grid, .charts-grid { grid-template-columns: 1fr; }
    .form-panel .grid-form { grid-template-columns: 1fr; }
    .modern-form .span-2 { grid-column: span 1; }
    .toolbar { align-items: stretch; }
    .toolbar label, .toolbar .btn { width: 100%; }
}

@media (max-width: 560px) {
    .login-card { padding: 28px 24px 24px; border-radius: 26px; }
    .login-logo-wrap img { width: 92px; height: 92px; }
    .site-brand strong { font-size: 1.1rem; }
    .site-brand span { font-size: .88rem; }
    .directory-grid { grid-template-columns: 1fr; }
    .site-header { padding: 10px 12px; }
    .layout-shell { padding: 12px; }
    .pill { width: 100%; }
    .topbar-actions { width: 100%; }
}

.search-status {
    color: #64748b;
    font-weight: 800;
    font-size: .92rem;
    min-height: 1.2rem;
}
.person-card[hidden] {
    display: none !important;
}
.directory-empty-filter {
    grid-column: 1 / -1;
}

.person-card.is-hidden {
    display: none !important;
}
.search-actions-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.search-actions-row .search-status {
    margin-left: 4px;
}
@media (max-width: 760px) {
    .search-actions-row .btn { width: auto; }
}

/* =========================================================
   AJUSTE RESPONSIVO FINAL PARA TELÉFONOS
   Evita desplazamiento horizontal y reacomoda todo el directorio.
   ========================================================= */
html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}
.page-shell,
.site-header,
.layout-shell,
.sidebar,
.content,
.panel,
.section-head,
.hero-panel,
.directory-grid,
.person-card,
.search-row,
.search-box,
.form-stack,
.grid-form,
.table-wrap,
.app-footer {
    max-width: 100%;
    min-width: 0;
}
.site-brand > div:last-child,
.site-user-pill span,
.person-card-header,
.person-meta,
.person-meta span,
.person-card h3,
.person-card-role,
.muted,
.eyebrow,
label,
input,
select {
    min-width: 0;
    max-width: 100%;
}
.person-card h3,
.person-card-role,
.person-meta span,
.site-brand strong,
.site-brand span,
.muted {
    overflow-wrap: anywhere;
    word-break: normal;
}

@media (max-width: 900px) {
    body {
        background: linear-gradient(135deg, #edf2f8 0%, #f7f9fc 100%);
    }
    .site-header {
        position: relative;
        width: 100%;
        padding: 10px 12px;
        gap: 10px;
        align-items: stretch;
        overflow: hidden;
    }
    .site-brand {
        width: 100%;
        min-width: 0;
        gap: 10px;
    }
    .brand-badge {
        width: 54px;
        height: 54px;
        border-radius: 16px;
    }
    .brand-badge img {
        width: 42px;
        height: 42px;
    }
    .site-brand strong {
        font-size: 1.08rem;
        line-height: 1.12;
    }
    .site-brand span {
        font-size: .88rem;
        line-height: 1.24;
    }
    .site-user-pill {
        width: 100%;
        max-width: 100%;
        justify-content: space-between;
        gap: 10px;
        padding: 9px 12px;
        overflow: hidden;
    }
    .site-user-pill span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .layout-shell {
        display: block;
        width: 100%;
        padding: 10px;
        margin: 0;
    }
    .sidebar {
        position: relative;
        top: auto;
        width: 100%;
        padding: 10px;
        border-radius: 22px;
        margin: 0 0 14px;
        overflow: hidden;
    }
    .nav {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 8px;
        padding: 2px 2px 8px;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
    }
    .nav a {
        flex: 0 0 auto;
        max-width: 74vw;
        padding: 12px 14px;
        white-space: normal;
        line-height: 1.18;
        scroll-snap-align: start;
    }
    .content {
        width: 100%;
        overflow: hidden;
    }
    .hero-panel,
    .section-head {
        display: grid;
        grid-template-columns: 1fr;
        align-items: stretch;
        gap: 14px;
    }
    .hero-panel h1,
    .section-head h2 {
        font-size: clamp(1.45rem, 7vw, 1.9rem);
    }
    .topbar-actions,
    .toolbar,
    .toolbar label,
    .toolbar .btn,
    .toolbar select,
    .search-box,
    .search-box input,
    .search-actions-row {
        width: 100%;
        max-width: 100%;
    }
    .pill {
        width: 100%;
        justify-content: center;
        white-space: normal;
        text-align: center;
    }
    .panel {
        width: 100%;
        padding: 18px;
        border-radius: 22px;
        margin-bottom: 14px;
        overflow: hidden;
    }
    .search-box input {
        font-size: 1rem;
        padding: 14px 16px;
    }
    .search-actions-row {
        display: grid;
        grid-template-columns: auto auto 1fr;
        align-items: center;
        gap: 8px;
    }
    .search-actions-row .btn {
        width: auto;
        min-width: 0;
        padding: 10px 14px;
    }
    .search-actions-row .search-status {
        min-width: 0;
        overflow-wrap: anywhere;
    }
    .directory-grid {
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 14px;
        width: 100%;
    }
    .person-card {
        width: 100%;
        min-width: 0;
        padding: 16px;
        border-radius: 22px;
        overflow: hidden;
    }
    .person-card h3 {
        font-size: 1rem;
        line-height: 1.22;
    }
    .person-card-role {
        font-size: .95rem;
        line-height: 1.25;
    }
    .person-meta {
        gap: 8px;
        line-height: 1.42;
        font-size: .94rem;
    }
    .person-meta span {
        display: block;
    }
    .contact-actions {
        gap: 9px;
    }
    .contact-actions a {
        width: 42px;
        height: 42px;
        border-radius: 14px;
    }
    .kpi-grid,
    .charts-grid,
    .form-panel .grid-form,
    .grid-form {
        grid-template-columns: minmax(0, 1fr) !important;
    }
    .modern-form .span-2 {
        grid-column: auto;
    }
    .app-footer {
        padding: 8px 14px 22px;
        font-size: .82rem;
    }
}

@media (max-width: 430px) {
    .layout-shell { padding: 8px; }
    .site-header { padding: 8px; }
    .panel { padding: 16px; }
    .sidebar { padding: 8px; border-radius: 20px; }
    .nav a { max-width: 78vw; padding: 11px 13px; }
    .search-actions-row {
        grid-template-columns: 1fr 1fr;
    }
    .search-actions-row .search-status {
        grid-column: 1 / -1;
        margin-left: 0;
    }
    .person-card { padding: 15px; }
}
