/* CSS Principal - Estilo de Plantilla Reusable */
/* Soporte integrado para múltiples temas de acento y modo oscuro */

:root,
[data-accent-theme="azul"] {
    --primary-color:    #0d6efd;
    --navbar-bg:        #002a5e;
    --accent-hover:     #0b5ed7;
    --accent-light:     rgba(13,110,253,0.1);
    --accent-gradient:  linear-gradient(135deg, #0d6efd, #6610f2);
    --footer-bg-start:  #002a5e;
    --footer-bg-end:    #001a3a;
    --bs-primary:       #0d6efd;
    --bs-primary-rgb:   13, 110, 253;
    --bs-link-color:           #0d6efd;
    --bs-link-hover-color:     #0b5ed7;
    --bs-focus-ring-color:     rgba(13, 110, 253, 0.25);
    
    --bg-body:          #f8f9fa;
    --bg-card:          #ffffff;
    --border-color:     #dee2e6;
    --card-shadow:      0 4px 12px rgba(0,0,0,0.05);
}

[data-accent-theme="verde"] {
    --primary-color:    #198754;
    --navbar-bg:        #064e29;
    --accent-hover:     #157347;
    --accent-light:     rgba(25,135,84,0.1);
    --accent-gradient:  linear-gradient(135deg, #198754, #20c997);
    --footer-bg-start:  #064e29;
    --footer-bg-end:    #032c17;
    --bs-primary:       #198754;
    --bs-primary-rgb:   25, 135, 84;
    --bs-link-color:           #198754;
    --bs-link-hover-color:     #157347;
    --bs-focus-ring-color:     rgba(25, 135, 84, 0.25);
}

[data-accent-theme="purpura"] {
    --primary-color:    #6f42c1;
    --navbar-bg:        #240d54;
    --accent-hover:     #5a32a3;
    --accent-light:     rgba(111,66,193,0.1);
    --accent-gradient:  linear-gradient(135deg, #6f42c1, #d63384);
    --footer-bg-start:  #240d54;
    --footer-bg-end:    #14072f;
    --bs-primary:       #6f42c1;
    --bs-primary-rgb:   111, 66, 193;
    --bs-link-color:           #6f42c1;
    --bs-link-hover-color:     #5a32a3;
    --bs-focus-ring-color:     rgba(111, 66, 193, 0.25);
}

[data-accent-theme="naranja"] {
    --primary-color:    #b45309;
    --navbar-bg:        #5c2800;
    --accent-hover:     #923f06;
    --accent-light:     rgba(180,83,9,0.1);
    --accent-gradient:  linear-gradient(135deg, #fd7e14, #dc3545);
    --footer-bg-start:  #5c2800;
    --footer-bg-end:    #341500;
    --bs-primary:       #b45309;
    --bs-primary-rgb:   180, 83, 9;
    --bs-link-color:           #b45309;
    --bs-link-hover-color:     #923f06;
}

[data-accent-theme="rojo"] {
    --primary-color:    #dc3545;
    --navbar-bg:        #5c0d17;
    --accent-hover:     #bb2d3b;
    --accent-light:     rgba(220,53,69,0.1);
    --accent-gradient:  linear-gradient(135deg, #dc3545, #fd7e14);
    --footer-bg-start:  #5c0d17;
    --footer-bg-end:    #32060d;
    --bs-primary:       #dc3545;
    --bs-primary-rgb:   220, 53, 69;
    --bs-link-color:           #dc3545;
    --bs-link-hover-color:     #bb2d3b;
}

[data-accent-theme="teal"] {
    --primary-color:    #0f766e;
    --navbar-bg:        #063a36;
    --accent-hover:     #0a5c56;
    --accent-light:     rgba(15,118,110,0.1);
    --accent-gradient:  linear-gradient(135deg, #0f766e, #2dd4bf);
    --footer-bg-start:  #063a36;
    --footer-bg-end:    #02211f;
    --bs-primary:       #0f766e;
    --bs-primary-rgb:   15, 118, 110;
    --bs-link-color:           #0f766e;
    --bs-link-hover-color:     #0a5c56;
}

[data-accent-theme="indigo"] {
    --primary-color:    #6610f2;
    --navbar-bg:        #200563;
    --accent-hover:     #520dc2;
    --accent-light:     rgba(102,16,242,0.1);
    --accent-gradient:  linear-gradient(135deg, #6610f2, #8f58ff);
    --footer-bg-start:  #200563;
    --footer-bg-end:    #14043e;
    --bs-primary:       #6610f2;
    --bs-primary-rgb:   102, 16, 242;
    --bs-link-color:           #6610f2;
    --bs-link-hover-color:     #520dc2;
}

/* Sobreescrituras de Bootstrap del tema oscuro */
[data-bs-theme="dark"] {
    --bg-body:          #0b0f19;
    --bg-card:          #111827;
    --border-color:     #1f2937;
    --card-shadow:      0 4px 20px rgba(0,0,0,0.25);
    --bs-body-bg:       #0b0f19;
    --bs-card-bg:       #111827;
    --bs-border-color:  #1f2937;
    --app-surface-soft: #192233;
    --app-surface-mid:  #243146;
    --app-text-soft:    #d1d9e8;
    --app-text-strong:  #e5e7eb;
}

[data-bs-theme="dark"] .bg-white {
    background-color: rgba(25, 34, 51, var(--bs-bg-opacity, 1)) !important;
}

[data-bs-theme="dark"] .bg-light {
    background-color: rgba(36, 49, 70, var(--bs-bg-opacity, 1)) !important;
}

[data-bs-theme="dark"] .text-dark,
[data-bs-theme="dark"] .text-dark-emphasis {
    color: var(--app-text-strong) !important;
}

[data-bs-theme="dark"] .text-muted {
    color: var(--app-text-soft) !important;
}

[data-bs-theme="dark"] .border,
[data-bs-theme="dark"] .border-top,
[data-bs-theme="dark"] .border-end,
[data-bs-theme="dark"] .border-bottom,
[data-bs-theme="dark"] .border-start {
    border-color: #334155 !important;
}

[data-bs-theme="dark"] .badge.bg-light.text-dark {
    background-color: #334155 !important;
    color: #f8fafc !important;
    border-color: #475569 !important;
}

[data-bs-theme="dark"] .modal-content,
[data-bs-theme="dark"] .dropdown-menu,
[data-bs-theme="dark"] .list-group-item {
    background-color: #111827;
    border-color: #334155;
}

[data-bs-theme="dark"] .dropdown-item {
    color: #e2e8f0;
}

[data-bs-theme="dark"] .dropdown-item:hover,
[data-bs-theme="dark"] .dropdown-item:focus {
    background-color: #1f2937;
    color: #f8fafc;
}

[data-bs-theme="dark"] .table-light {
    --bs-table-color: #e5e7eb;
    --bs-table-bg: #243146;
    --bs-table-border-color: #334155;
    --bs-table-striped-bg: #1f2937;
    --bs-table-striped-color: #f8fafc;
    --bs-table-active-bg: #334155;
    --bs-table-active-color: #f8fafc;
    --bs-table-hover-bg: #2b3a53;
    --bs-table-hover-color: #f8fafc;
    color: #e5e7eb;
}

[data-bs-theme="dark"] .table > :not(caption) > * > th {
    color: #e5e7eb;
    border-bottom-color: #334155;
}

[data-bs-theme="dark"] .form-control::placeholder,
[data-bs-theme="dark"] .form-select::placeholder,
[data-bs-theme="dark"] textarea::placeholder {
    color: #94a3b8 !important;
    opacity: 0.8;
}

[data-bs-theme="dark"] .sidebar .nav-link {
    color: #cbd5e1;
}

[data-bs-theme="dark"] .sidebar .nav-link:hover,
[data-bs-theme="dark"] .sidebar .nav-link.active {
    color: #f8fafc;
}

[data-bs-theme="dark"] .table-responsive {
    border-radius: 0.5rem;
}

body {
    background-color: var(--bg-body);
    color: var(--bs-body-color);
    font-family: 'Outfit', 'Inter', system-ui, -apple-system, sans-serif;
    min-height: 100vh;
}

/* Escala tipografica semantica */
.app-page-title {
    font-size: clamp(1.45rem, 2vw, 1.9rem);
    font-weight: 800;
    letter-spacing: 0.01em;
}

.app-page-subtitle {
    color: var(--bs-secondary-color);
    font-size: 0.95rem;
    line-height: 1.45;
}

.app-module-title {
    font-size: clamp(1.3rem, 1.6vw, 1.7rem);
    font-weight: 800;
    letter-spacing: 0.01em;
}

.app-module-subtitle {
    color: var(--bs-secondary-color);
    font-size: 0.9rem;
    line-height: 1.4;
}

.app-section-title {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    margin-bottom: 0.9rem;
}

.app-card-title {
    font-size: 1.02rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.app-helper-text {
    color: var(--bs-secondary-color);
    font-size: 0.82rem;
    line-height: 1.4;
}

.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color) !important;
    box-shadow: var(--card-shadow);
}

.card-header {
    padding-top: 1rem;
    padding-bottom: 0.7rem;
}

.card-header .fw-bold,
.card-header .card-title {
    letter-spacing: 0.01em;
}

.navbar-main {
    border-bottom: 1px solid var(--border-color) !important;
}

/* Estados de foco visibles para navegación por teclado */
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.form-check-input:focus-visible,
a:focus-visible,
button:focus-visible {
    outline: 3px solid var(--bs-focus-ring-color);
    outline-offset: 2px;
}

[data-bs-theme="dark"] .btn-outline-secondary:focus-visible {
    box-shadow: 0 0 0 0.25rem rgba(148, 163, 184, 0.35);
    border-color: #94a3b8;
}

.btn {
    transition: transform 0.16s ease, box-shadow 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

/* Validación visual consistente */
.was-validated .form-control:invalid,
.was-validated .form-select:invalid,
.form-control.is-invalid,
.form-select.is-invalid {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.15);
}

.was-validated .form-control:valid,
.was-validated .form-select:valid,
.form-control.is-valid,
.form-select.is-valid {
    border-color: #198754;
    box-shadow: 0 0 0 0.2rem rgba(25, 135, 84, 0.1);
}

input[readonly],
input:disabled,
textarea:disabled,
select:disabled {
    cursor: not-allowed;
}

.form-label {
    margin-bottom: 0.38rem;
    letter-spacing: 0.01em;
}

.form-control,
.form-select {
    min-height: 42px;
}

.form-text {
    font-size: 0.79rem;
}

.input-group-text {
    border-color: var(--border-color);
}

[data-bs-theme="dark"] input[readonly],
[data-bs-theme="dark"] input:disabled,
[data-bs-theme="dark"] textarea:disabled,
[data-bs-theme="dark"] select:disabled {
    background-color: #1f2937;
    color: #cbd5e1;
    border-color: #334155;
}

/* Clases de utilidad para transiciones y animaciones */
.card-hover-animation {
    transition: transform 0.25s ease, box-shadow 0.25s ease !important;
}
.card-hover-animation:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 24px rgba(0,0,0,0.08) !important;
}
[data-bs-theme="dark"] .card-hover-animation:hover {
    box-shadow: 0 10px 24px rgba(0,0,0,0.3) !important;
}

/* Modulo Plantillas */
.tpl-editor-textarea {
    font-size: 12pt;
    line-height: 1.5;
}

.tpl-sticky-help {
    top: 24px;
}

/* Modulo Fuentes de Tokens */
.token-sources-list {
    max-height: 500px;
    overflow-y: auto;
    padding-right: 0.15rem;
}

.token-badge-small {
    font-size: 7.5pt;
    letter-spacing: 0.03em;
}

.token-source-name {
    max-width: 180px;
}

.token-panel {
    border: 1px solid var(--border-color) !important;
    background: linear-gradient(180deg, rgba(var(--bs-primary-rgb), 0.03), rgba(var(--bs-primary-rgb), 0));
}

.token-metric-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.95rem;
    padding: 0.85rem 1rem;
    box-shadow: var(--card-shadow);
}

.token-metric-icon {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.7rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.token-metric-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--bs-secondary-color);
    font-weight: 700;
}

.token-metric-value {
    font-size: 1.25rem;
    line-height: 1;
    font-weight: 800;
    color: var(--bs-body-color);
}

.token-filter-card {
    border: 1px solid rgba(var(--bs-primary-rgb), 0.16) !important;
    background: linear-gradient(135deg, rgba(var(--bs-primary-rgb), 0.06), rgba(var(--bs-primary-rgb), 0.01));
}

.token-filter-group .btn {
    min-width: 92px;
}

.token-filter-group .btn.active {
    color: #fff;
    border-color: var(--bs-primary);
    background-color: var(--bs-primary);
}

.token-panel .card-header {
    border-bottom: 1px solid rgba(var(--bs-primary-rgb), 0.12) !important;
}

.token-count-pill {
    font-size: 0.76rem;
    letter-spacing: 0.01em;
}

.token-sources-table-wrap {
    border: 1px solid rgba(var(--bs-primary-rgb), 0.1);
    border-radius: 0.8rem;
    overflow: hidden;
}

.token-sources-table > :not(caption) > * > th {
    background-color: rgba(var(--bs-primary-rgb), 0.06);
}

.token-sources-table .token-col-label .text-truncate,
.token-sources-table .token-col-origin .text-truncate,
.token-sources-table .token-col-description .text-truncate {
    max-width: 100%;
}

.token-source-item {
    border-bottom: 1px dashed rgba(var(--bs-primary-rgb), 0.18);
}

.token-source-item:last-child {
    border-bottom: 0;
}

.token-empty-state {
    border: 1px dashed rgba(var(--bs-primary-rgb), 0.35);
    border-radius: 0.8rem;
    padding: 1rem;
    margin-top: 0.9rem;
    text-align: center;
    background-color: rgba(var(--bs-primary-rgb), 0.03);
}

[data-bs-theme="dark"] .token-panel {
    background: linear-gradient(180deg, rgba(148, 163, 184, 0.09), rgba(148, 163, 184, 0.02));
}

[data-bs-theme="dark"] .token-filter-card {
    border-color: #334155 !important;
    background: linear-gradient(135deg, rgba(51, 65, 85, 0.5), rgba(15, 23, 42, 0.25));
}

[data-bs-theme="dark"] .token-sources-table-wrap {
    border-color: #334155;
}

.token-fields-scroll {
    max-height: 250px;
    overflow-y: auto;
}

/* Modulo Reportes */
.reports-hero-card {
    background: linear-gradient(135deg, var(--accent-color, #1e4620), var(--accent-hover, #143016));
    color: #ffffff;
}

.reports-chart-canvas-320 {
    position: relative;
    height: 320px;
}

.reports-chart-canvas-300 {
    position: relative;
    height: 300px;
}

/* Utilidades de accesibilidad y reemplazo de estilos inline */
.app-visually-hidden-caption {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.sticky-top-24 {
    top: 24px;
}

.template-code-preview-html {
    max-height: 250px;
    overflow-y: auto;
    font-size: 9pt;
    white-space: pre-wrap;
}

.template-code-preview-css {
    max-height: 150px;
    overflow-y: auto;
    font-size: 9pt;
    white-space: pre-wrap;
}

.template-diff-block {
    font-size: 8.5pt;
    white-space: pre-wrap;
    text-align: left;
}

.template-diff-line-removed {
    border-left: 3px solid #ef4444;
}

.template-diff-line-added {
    border-left: 3px solid #22c55e;
}

.dashboard-metric-card {
    transition: transform 0.2s ease;
}

.app-kpi-card {
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    background-color: var(--bg-card);
    box-shadow: var(--card-shadow);
    transition: transform 0.22s ease, box-shadow 0.22s ease;
}

.app-kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 14px 28px rgba(15, 23, 42, 0.12);
}

[data-bs-theme="dark"] .app-kpi-card:hover {
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.34);
}

.app-kpi-icon {
    border-radius: 0.9rem;
    padding: 0.85rem;
}

.app-kpi-icon i {
    font-size: 1.35rem;
}

.app-kpi-label {
    font-size: 0.78rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--bs-secondary-color);
    font-weight: 700;
}

.table-col-id {
    width: 80px;
}

.table-col-date {
    width: 200px;
}

.table-col-actions {
    width: 150px;
}

.table > :not(caption) > * > th {
    font-size: 0.82rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.table > :not(caption) > * > td {
    padding-top: 0.72rem;
    padding-bottom: 0.72rem;
}

.table-responsive {
    border-radius: 0.75rem;
}

.table tbody tr {
    transition: background-color 0.18s ease;
}

.table tbody tr:hover {
    background-color: rgba(var(--bs-primary-rgb), 0.045);
}

[data-bs-theme="dark"] .table tbody tr:hover {
    background-color: rgba(148, 163, 184, 0.08);
}

.app-action-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.app-filter-card .card-body,
.app-table-card .card-body {
    padding: 1.25rem 1.25rem 1.1rem;
}

.app-filter-card .card-header,
.app-table-card .card-header {
    padding-left: 1.25rem;
    padding-right: 1.25rem;
}

[data-app-tooltip="true"] {
    cursor: help;
}

@media (max-width: 1400px) and (min-width: 992px) {
    .users-table .users-col-email {
        max-width: 215px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .users-table .users-col-role .badge {
        max-width: 165px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: inline-block;
        vertical-align: middle;
    }

    .users-table .table-col-actions {
        width: 120px;
    }

    .users-table .btn.btn-sm {
        padding: 0.2rem 0.42rem;
    }

    .templates-table > :not(caption) > * > th,
    .templates-table > :not(caption) > * > td {
        font-size: 0.88rem;
    }

    .templates-table td:last-child .btn {
        padding: 0.2rem 0.45rem;
        font-size: 0.76rem;
    }

    .templates-table .templates-col-name {
        max-width: 240px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .templates-table .templates-col-key {
        max-width: 170px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .token-sources-table > :not(caption) > * > th,
    .token-sources-table > :not(caption) > * > td {
        font-size: 0.88rem;
    }

    .token-sources-table .token-col-label {
        max-width: 220px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .token-sources-table .token-col-origin {
        max-width: 170px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .token-sources-table .token-col-description {
        max-width: 240px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .token-panel .card-header,
    .token-panel .card-body {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    .token-filter-group .btn {
        min-width: auto;
        padding-left: 0.65rem;
        padding-right: 0.65rem;
    }


@media (max-width: 991.98px) {
    .token-sources-layout {
        gap: 1rem;
    }

    .token-panel .card-header,
    .token-panel .card-body {
        padding-left: 0.9rem !important;
        padding-right: 0.9rem !important;
    }

    .token-sources-table > :not(caption) > * > th,
    .token-sources-table > :not(caption) > * > td {
        font-size: 0.81rem;
    }

    .token-sources-table .token-col-description {
        min-width: 200px;
    }

    .token-source-item {
        align-items: flex-start !important;
        flex-direction: column;
    }

    .token-source-item .btn-register-source {
        align-self: stretch;
        justify-content: center;
    }

    .token-metric-card {
        padding: 0.75rem 0.85rem;
    }

    .token-metric-value {
        font-size: 1.1rem;
    }
}
    .audit-table > :not(caption) > * > th,
    .audit-table > :not(caption) > * > td,
    .security-logs-table > :not(caption) > * > th,
    .security-logs-table > :not(caption) > * > td,
    .security-ips-table > :not(caption) > * > th,
    .security-ips-table > :not(caption) > * > td,
    .security-mini-table > :not(caption) > * > th,
    .security-mini-table > :not(caption) > * > td {
        font-size: 0.86rem;
    }

    .audit-table .audit-col-action .badge {
        max-width: 165px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: inline-block;
        vertical-align: middle;
    }

    .audit-table .audit-col-detail {
        max-width: 260px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .security-logs-table .security-col-endpoint {
        max-width: 205px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .security-logs-table .security-col-reason,
    .security-ips-table .security-col-reason {
        max-width: 240px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .security-ips-table .btn.btn-sm {
        padding: 0.2rem 0.45rem;
    }
}

@media (max-width: 1366px) and (min-width: 992px) {
    .security-logs-table .security-col-user,
    .security-logs-table th.security-col-user {
        display: none;
    }

    .security-ips-table .security-col-blocked-at,
    .security-ips-table th.security-col-blocked-at,
    .security-ips-table .security-col-expires,
    .security-ips-table th.security-col-expires {
        display: none;
    }

    .security-mini-table .security-col-detected,
    .security-mini-table th.security-col-detected,
    .security-mini-table .security-col-expires,
    .security-mini-table th.security-col-expires {
        display: none;
    }

    .security-mini-table .security-col-reason,
    .security-mini-table th.security-col-reason {
        max-width: 170px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

@media (max-width: 575.98px) {
    .table > :not(caption) > * > th {
        font-size: 0.74rem;
        letter-spacing: 0.01em;
        text-transform: none;
    }

    .table > :not(caption) > * > td {
        font-size: 0.92rem;
        padding-top: 0.62rem;
        padding-bottom: 0.62rem;
    }

    .app-table-card .card-header {
        flex-wrap: wrap;
        align-items: flex-start !important;
        gap: 0.75rem;
    }

    .app-table-card .card-header .app-card-title {
        flex: 1 1 100%;
        margin-right: 0;
        line-height: 1.25;
    }

    .app-table-card .card-header .app-action-group {
        width: 100%;
        justify-content: flex-start;
    }

    .app-table-card .card-header .app-action-group .btn {
        flex: 1 1 100%;
    }
}

[data-bs-theme="dark"] .app-page-subtitle,
[data-bs-theme="dark"] .app-helper-text {
    color: #cfd8e6;
}

.security-endpoint-cell {
    max-width: 200px;
}

.security-score-progress {
    height: 6px;
    width: 80px;
}

.app-col-checkbox {
    width: 40px;
}

/* Paginación de tablas (js/paginacion-tablas.js): filas fuera de la página actual */
.pg-oculta { display: none !important; }
.pg-barra:empty { display: none; }
