/* ============================================================
 * Estilos personalizados - Sistema Ley 21.719
 * Paleta: Navy + Gold (Estilo Legal)
 * ============================================================ */

/* ─── Google Fonts ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ─── Variables CSS ────────────────────────────────────────── */
:root {
    /* Layout */
    --sidebar-width: 232px;
    --navbar-height: 60px;

    /* Bootstrap 5.3 overrides - se heredan a TODOS los componentes */
    --bs-primary: #1B2A4A;
    --bs-primary-rgb: 27, 42, 74;
    --bs-primary-bg-subtle: #E8ECF3;
    --bs-primary-border-subtle: #C5CDDB;
    --bs-primary-text: #1B2A4A;

    --bs-dark: #0F1B3D;
    --bs-dark-rgb: 15, 27, 61;

    --bs-success: #219653;
    --bs-success-rgb: 33, 150, 83;
    --bs-danger: #D63031;
    --bs-danger-rgb: 214, 48, 49;
    --bs-warning: #E67E22;
    --bs-warning-rgb: 230, 126, 34;
    --bs-info: #2C6BED;
    --bs-info-rgb: 44, 107, 237;

    /* Tipografía */
    --bs-font-sans-serif: 'Inter', system-ui, -apple-system, sans-serif;
    --bs-body-font-family: 'Inter', system-ui, -apple-system, sans-serif;

    /* Paleta Navy + Gold */
    --gold: #C9A84C;
    --gold-rgb: 201, 168, 76;
    --gold-light: #E8D5A0;
    --navy-dark: #0F1B3D;
    --navy: #1B2A4A;
    --navy-hover: #253C6B;

    /* Neutros */
    --bg-page: #F0F2F6;
    --text-body: #2C3E50;
    --text-muted: #7F8C8D;
    --border-color: #E1E5EB;
    --card-shadow: 0 1px 4px rgba(0,0,0,.06);
    --card-shadow-hover: 0 4px 16px rgba(0,0,0,.1);
}

/* ─── Reset & Base ─────────────────────────────────────────── */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-page);
    padding-top: var(--navbar-height);
    color: var(--text-body);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

code, pre, .codigo, code[class*="language-"] {
    font-family: 'JetBrains Mono', 'Courier New', monospace !important;
    font-size: .875em;
}

/* ─── Navbar Navy + Gold ───────────────────────────────────── */
.navbar-navy {
    background: linear-gradient(135deg, #1B2A4A 0%, #0F1B3D 100%) !important;
    border-bottom: 3px solid var(--gold);
    box-shadow: 0 2px 16px rgba(0,0,0,.2);
    height: var(--navbar-height);
    padding-top: 0;
    padding-bottom: 0;
}

.navbar-navy .navbar-brand {
    font-weight: 700;
    letter-spacing: .5px;
    font-size: 1.1rem;
}

.navbar-navy .navbar-brand i {
    color: var(--gold);
}

/* ─── Avatar ───────────────────────────────────────────────── */
.avatar-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    background: rgba(201, 168, 76, .15) !important;
    color: var(--gold) !important;
    border: 2px solid rgba(201, 168, 76, .3);
    transition: all .2s;
}

.avatar-circle:hover {
    border-color: var(--gold);
    background: rgba(201, 168, 76, .25) !important;
}

/* ─── Sidebar ──────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    padding-top: var(--navbar-height);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-bg-dark {
    background: #121d2f !important;
}

.sidebar .sidebar-header {
    border-bottom: 1px solid rgba(148, 163, 184, .16);
    padding: 12px 13px;
}

.sidebar-brand {
    align-items: center;
    display: flex;
    gap: 10px;
}

.sidebar-brand-icon {
    align-items: center;
    background: #138a3d;
    border-radius: 8px;
    color: #fff;
    display: inline-flex;
    flex: 0 0 36px;
    height: 36px;
    justify-content: center;
    width: 36px;
}

.sidebar-brand-title {
    color: #fff;
    display: block;
    font-size: .88rem;
    font-weight: 700;
    line-height: 1.1;
}

.sidebar-brand-subtitle {
    color: #41d27d;
    display: block;
    font-size: .68rem;
    font-weight: 600;
    line-height: 1.2;
}

.sidebar .nav-link {
    align-items: center;
    border-left: 0;
    border-radius: 5px;
    color: #c6d0df;
    display: flex;
    font-size: .78rem;
    font-weight: 750;
    gap: 2px;
    margin: 2px 11px;
    padding: 9px 11px;
    transition: all .2s ease;
}

.sidebar .nav-link:hover {
    color: #fff;
    background: rgba(255,255,255,.07);
}

.sidebar .nav-link.active {
    color: #fff;
    background: #14883c !important;
}

.sidebar .nav-link.active i {
    color: #fff !important;
}

.sidebar .nav-link i {
    color: #91a0b5;
    font-size: .95rem;
    width: 18px;
    text-align: center;
    transition: color .2s;
}

.sidebar-menu-list {
    padding: 8px 0;
}

.sidebar-direct-link {
    display: flex;
    align-items: center;
    width: auto;
}

.sidebar-nav {
    overflow-x: hidden;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    flex-wrap: nowrap;
}

.sidebar-nav::-webkit-scrollbar {
    width: 3px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, .24);
    border-radius: 3px;
}

.sidebar-footer {
    border-top: 1px solid rgba(148, 163, 184, .16) !important;
    flex-shrink: 0;
    padding: 12px 13px;
}

.sidebar-user {
    align-items: center;
    display: flex;
    gap: 10px;
}

.sidebar-user-avatar {
    align-items: center;
    background: #17a34a;
    border-radius: 8px;
    color: #fff;
    display: inline-flex;
    flex: 0 0 36px;
    font-size: .72rem;
    font-weight: 800;
    height: 36px;
    justify-content: center;
    width: 36px;
}

.sidebar-user-meta {
    min-width: 0;
}

.sidebar-user-name {
    color: #fff;
    display: block;
    font-size: .8rem;
    font-weight: 750;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user-role {
    color: #41d27d;
    display: block;
    font-size: .67rem;
    font-weight: 600;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-logout {
    align-items: center;
    border-radius: 7px;
    color: #c8d2df;
    display: inline-flex;
    font-size: .7rem;
    font-weight: 700;
    gap: 4px;
    height: 30px;
    justify-content: center;
    margin-left: auto;
    padding: 0 8px;
    text-decoration: none;
    white-space: nowrap;
}

.sidebar-logout:hover {
    background: rgba(255,255,255,.08);
    color: #fff;
}

.mobile-sidebar-bar {
    align-items: center;
    background: #121d2f;
    border-bottom: 1px solid rgba(148, 163, 184, .16);
    display: flex;
    height: var(--navbar-height);
    justify-content: space-between;
    left: 0;
    padding: 10px 13px;
    position: fixed;
    right: 0;
    top: 0;
    z-index: 1030;
}

.mobile-sidebar-brand {
    align-items: center;
    display: flex;
    gap: 10px;
}

.mobile-menu-button {
    align-items: center;
    background: #14883c;
    border: 0;
    border-radius: 7px;
    color: #fff;
    display: inline-flex;
    font-size: .78rem;
    font-weight: 750;
    gap: 6px;
    min-height: 36px;
    padding: 0 12px;
}

.mobile-menu-button:hover,
.mobile-menu-button:focus {
    background: #17a34a;
}

@media (max-width: 991.98px) {
    .sidebar {
        display: none !important;
    }
}

/* ─── Offcanvas (mobile) ────────────────────────────────────── */
.offcanvas {
    background: #121d2f;
    color: #c6d0df;
}

.offcanvas-header {
    background: #121d2f !important;
    border-bottom: 1px solid rgba(148, 163, 184, .16);
    min-height: var(--navbar-height);
    padding: 10px 13px;
}

.offcanvas-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.offcanvas .sidebar-nav {
    flex: 1;
    min-height: 0;
}

.offcanvas .sidebar-footer {
    margin-top: auto;
}

/* ─── Main Content ─────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    padding: 24px;
    min-height: calc(100vh - var(--navbar-height));
}

@media (max-width: 991.98px) {
    .main-content {
        margin-left: 0;
        padding: 16px;
        padding-top: calc(var(--navbar-height) + 16px);
    }
}

/* ─── Cards ────────────────────────────────────────────────── */
.card {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: var(--card-shadow);
    transition: all .25s ease;
}

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

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    padding: 16px 20px;
    color: var(--text-body);
}

.card-header i {
    color: var(--navy);
}

.card-footer {
    background: transparent;
    border-top: 1px solid var(--border-color);
    padding: 12px 20px;
}

/* ─── KPI Cards ────────────────────────────────────────────── */
.kpi-icon {
    font-size: 2.2rem;
}

.kpi-value {
    font-size: 1.8rem;
    font-weight: 800;
    line-height: 1.2;
}

.kpi-label {
    font-size: .8rem;
    opacity: .85;
}

/* KPI con borde lateral */
.kpi-border-navy {
    border-left: 4px solid var(--navy) !important;
}

.kpi-border-gold {
    border-left: 4px solid var(--gold) !important;
}

.kpi-border-success {
    border-left: 4px solid #219653 !important;
}

.kpi-border-danger {
    border-left: 4px solid #D63031 !important;
}

.kpi-border-info {
    border-left: 4px solid #2C6BED !important;
}

.kpi-border-warning {
    border-left: 4px solid #E67E22 !important;
}

/* ─── Badges ───────────────────────────────────────────────── */
.badge {
    font-weight: 500;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: .8rem;
}

.badge.bg-gold {
    background: var(--gold) !important;
    color: var(--navy-dark) !important;
    font-weight: 600;
}

/* ─── Botones ──────────────────────────────────────────────── */
.btn {
    border-radius: 8px;
    font-weight: 500;
    padding: 8px 20px;
    transition: all .2s ease;
}

.btn-primary {
    background-color: var(--navy);
    border-color: var(--navy);
    color: #fff;
}

.btn-primary:hover, .btn-primary:focus {
    background-color: var(--navy-hover);
    border-color: var(--navy-hover);
    color: #fff;
}

.btn-outline-primary {
    color: var(--navy);
    border-color: var(--navy);
}

.btn-outline-primary:hover, .btn-outline-primary:focus {
    background-color: var(--navy);
    border-color: var(--navy);
    color: #fff;
}

/* ─── Tablas ───────────────────────────────────────────────── */
.table th {
    font-weight: 600;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    border-bottom-width: 2px;
    border-bottom-color: var(--border-color);
    padding: 12px 8px;
}

.table td {
    vertical-align: middle;
    padding: 10px 8px;
}

.table-hover tbody tr:hover {
    background-color: rgba(27, 42, 74, .03);
}

/* DataTables pagination */
.page-item.active .page-link {
    background-color: var(--navy) !important;
    border-color: var(--navy) !important;
}

.page-link {
    color: var(--navy);
}

.page-link:hover {
    color: var(--navy-hover);
}

/* ─── Formularios ──────────────────────────────────────────── */
.form-label {
    font-weight: 500;
    font-size: .875rem;
    color: var(--text-body);
    margin-bottom: 4px;
}

.form-control, .form-select {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: .9rem;
    transition: all .2s;
}

.form-control:focus, .form-select:focus {
    border-color: var(--navy);
    box-shadow: 0 0 0 3px rgba(27, 42, 74, .12);
}

.form-control-lg {
    padding: 12px 16px;
    font-size: 1rem;
}

.input-group-text {
    border: 1px solid var(--border-color);
    background: #f8f9fa;
}

/* ─── Navs/Tabs ────────────────────────────────────────────── */
.nav-tabs .nav-link {
    color: var(--text-muted);
    font-weight: 500;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 10px 16px;
    transition: all .2s;
}

.nav-tabs .nav-link:hover {
    color: var(--navy);
    border-bottom-color: var(--border-color);
}

.nav-tabs .nav-link.active {
    color: var(--navy);
    font-weight: 600;
    border-bottom: 2px solid var(--gold);
    background: transparent;
}

/* ─── Login Page ───────────────────────────────────────────── */
.login-page {
    background: linear-gradient(135deg, #0F1B3D 0%, #1B2A4A 50%, #253C6B 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    padding: 24px 16px;
}

.login-card {
    border-radius: 14px;
    overflow: hidden;
    border: none;
    box-shadow: 0 18px 45px rgba(0,0,0,.28);
}

.login-card .card-body {
    padding: 2.5rem 2.25rem;
}

.login-logo {
    width: 68px;
    height: 68px;
    background: linear-gradient(135deg, var(--navy), var(--navy-dark));
    border-radius: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.25rem;
    border: 2px solid var(--gold);
    box-shadow: 0 10px 24px rgba(15, 27, 61, .18);
}

.login-logo i {
    font-size: 2.15rem;
    color: var(--gold);
}

.login-footer {
    background: #f8f9fa;
    padding: .95rem 2rem;
    text-align: center;
    font-size: .85rem;
    color: var(--text-muted);
    border-top: 3px solid var(--gold);
}

.auth-page {
    justify-content: center;
}

.auth-shell {
    width: 100%;
    max-width: 430px;
}

.auth-card {
    width: 100%;
}

.auth-logo {
    display: flex;
}

.auth-eyebrow {
    color: var(--gold);
    font-size: .75rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.auth-title {
    color: var(--navy);
    font-size: 1.35rem;
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: .5rem;
}

.auth-subtitle {
    color: var(--text-muted);
    font-size: .92rem;
    line-height: 1.45;
}

.auth-alert {
    border-radius: 10px;
    font-size: .9rem;
}

.auth-form .form-control,
.auth-form .btn {
    min-height: 48px;
}

.password-field .btn {
    border-color: var(--border-color);
    color: var(--text-muted);
    padding-left: 14px;
    padding-right: 14px;
}

.password-field .btn:hover,
.password-field .btn:focus {
    background: rgba(27, 42, 74, .06);
    color: var(--navy);
}

.auth-options {
    align-items: center;
    display: flex;
    gap: 12px;
    justify-content: space-between;
}

.auth-options .form-check-label {
    color: var(--text-body);
    font-size: .9rem;
}

.auth-link {
    color: var(--navy);
    font-size: .9rem;
    font-weight: 600;
    text-decoration: none;
}

.auth-link:hover {
    color: var(--navy-hover);
    text-decoration: underline;
}

.auth-submit {
    font-weight: 700;
}

.auth-footer {
    border-top-width: 2px;
}

@media (max-width: 575.98px) {
    .login-card .card-body {
        padding: 2rem 1.35rem;
    }

    .auth-options {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
    }
}

/* ─── Welcome Section ──────────────────────────────────────── */
.welcome-section {
    background: linear-gradient(135deg, var(--navy) 0%, var(--navy-dark) 100%) !important;
    border: none !important;
    border-bottom: 3px solid var(--gold) !important;
}

/* ─── Alertas ──────────────────────────────────────────────── */
.alert-flash-container {
    position: fixed;
    top: 70px;
    right: 20px;
    z-index: 9999;
    max-width: 400px;
}

/* ─── Select2 ──────────────────────────────────────────────── */
.select2-container--bootstrap-5 .select2-selection {
    border: 1px solid var(--border-color) !important;
    border-radius: 8px !important;
}

.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice {
    background: rgba(27, 42, 74, .08) !important;
    border: 1px solid rgba(27, 42, 74, .2) !important;
    color: var(--navy) !important;
}

/* ─── SweetAlert2 ──────────────────────────────────────────── */
.swal2-confirm.swal2-styled {
    background-color: var(--navy) !important;
}

/* ─── Timeline ─────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 30px; }
.timeline::before {
    content: '';
    position: absolute;
    left: 10px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border-color);
}
.timeline-item { position: relative; margin-bottom: 20px; }
.timeline-item::before {
    content: '';
    position: absolute;
    left: -24px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--navy);
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px var(--navy);
}
.timeline-item.pending::before { background: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.timeline-item.completed::before { background: #219653; box-shadow: 0 0 0 2px #219653; }
.timeline-item.rejected::before { background: #D63031; box-shadow: 0 0 0 2px #D63031; }

/* ─── Scrollbar global ─────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(201, 168, 76, .25); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(201, 168, 76, .4); }

/* ─── Print ────────────────────────────────────────────────── */
@media print {
    .sidebar, .navbar, .btn, .no-print { display: none !important; }
    .main-content { margin-left: 0 !important; }
}

/* ─── Responsive ───────────────────────────────────────────── */
.table-responsive { border-radius: 8px; }

/* ─── Loading spinner ──────────────────────────────────────── */
.spinner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255,255,255,.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
}

/* ─── Misc ─────────────────────────────────────────────────── */
.section-title {
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--gold);
    font-weight: 600;
}

.card .card-header i:first-child {
    margin-right: 8px;
}

a {
    color: var(--navy);
}

a:hover {
    color: var(--navy-hover);
}

.text-primary {
    color: var(--navy) !important;
}

.bg-primary {
    background-color: var(--navy) !important;
}

.border-primary {
    border-color: var(--navy) !important;
}

.markdown-viewer {
    color: #24324a;
    line-height: 1.65;
}

.markdown-viewer > *:last-child {
    margin-bottom: 0;
}

.markdown-viewer h1,
.markdown-viewer h2,
.markdown-viewer h3,
.markdown-viewer h4,
.markdown-viewer h5,
.markdown-viewer h6 {
    color: var(--navy);
    font-weight: 700;
    margin-top: 1.4rem;
    margin-bottom: .65rem;
}

.markdown-viewer h1:first-child,
.markdown-viewer h2:first-child,
.markdown-viewer h3:first-child {
    margin-top: 0;
}

.markdown-viewer p,
.markdown-viewer ul,
.markdown-viewer ol,
.markdown-viewer .table-responsive,
.markdown-viewer pre {
    margin-bottom: 1rem;
}

.markdown-viewer code {
    background: rgba(18, 29, 47, .06);
    border-radius: 4px;
    color: var(--navy);
    padding: .12rem .32rem;
}

.markdown-viewer pre code {
    background: transparent;
    padding: 0;
}
