/* Estilos Globales y Layout de la Aplicación */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
}

/* --- ESTRUCTURA GENERAL (LAYOUT) --- */

#sidebar {
    width: var(--sidebar-width);
    background-color: var(--primary-color);
    color: #ffffff;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    transition: all var(--transition-speed) ease;
    display: flex;
    flex-direction: column;
    box-shadow: var(--box-shadow-lg);
}

#main-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: all var(--transition-speed) ease;
}

#header {
    height: var(--header-height);
    background-color: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 99;
}

.content-container {
    padding: 2rem;
    flex: 1;
}

/* --- SIDEBAR --- */

.sidebar-logo {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-logo img {
    width: 40px;
    height: 40px;
    object-fit: contain;
    border-radius: 50%;
    background-color: #ffffff;
    padding: 2px;
}

.sidebar-logo h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-menu {
    list-style: none;
    padding: 1rem 0;
    flex: 1;
    overflow-y: auto;
}

.sidebar-menu li a {
    display: flex;
    align-items: center;
    padding: 0.9rem 1.5rem;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
    border-left: 4px solid transparent;
    gap: 12px;
}

.sidebar-menu li a:hover {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.1);
}

.sidebar-menu li.active a {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.15);
    border-left-color: var(--secondary-color);
}

.sidebar-menu li a i {
    font-size: 1.25rem;
    width: 24px;
    text-align: center;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.6);
}

/* --- HEADER --- */

.header-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-badge {
    background-color: rgba(30, 64, 175, 0.1);
    color: var(--primary-color);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.btn-logout {
    color: var(--danger-color);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: opacity 0.2s;
}

.btn-logout:hover {
    opacity: 0.8;
}

/* --- TARJETAS (CARDS) --- */

.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card {
    background-color: #ffffff;
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--box-shadow);
    transition: transform var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
    border: 1px solid rgba(0, 0, 0, 0.05);
    position: relative;
    overflow: hidden;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: var(--box-shadow-lg);
}

.card-header-icon {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    font-size: 2rem;
    color: rgba(0, 0, 0, 0.05);
}

.card-title {
    color: var(--text-light);
    font-size: 0.9rem;
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.card-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-color);
}

.card-subtext {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* --- FORMULARIOS --- */

.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid #cbd5e1;
    border-radius: var(--border-radius-sm);
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.15);
}

/* --- BOTONES --- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0.65rem 1.25rem;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    text-decoration: none;
}

.btn-primary {
    background-color: var(--primary-color);
    color: #ffffff;
}

.btn-primary:hover {
    filter: brightness(1.15);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: #ffffff;
}

.btn-secondary:hover {
    filter: brightness(1.15);
}

.btn-danger {
    background-color: var(--danger-color);
    color: #ffffff;
}

.btn-danger:hover {
    filter: brightness(1.15);
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--text-light);
    color: var(--text-color);
}

.btn-outline:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* --- TABLAS --- */

.table-responsive {
    width: 100%;
    overflow-x: auto;
    background-color: #ffffff;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.table th {
    background-color: #f1f5f9;
    color: var(--text-light);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e2e8f0;
}

.table td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.95rem;
    color: var(--text-color);
}

.table tr:last-child td {
    border-bottom: none;
}

.table tr:hover {
    background-color: #f8fafc;
}

/* --- BADGES (ETIQUETAS) --- */

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
}

.badge-danger {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

.badge-warning {
    background-color: rgba(245, 158, 11, 0.1);
    color: var(--warning-color);
}

.badge-info {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--info-color);
}

/* --- ALERTAS --- */

.alert {
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius-sm);
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
}

.alert-success {
    background-color: rgba(16, 185, 129, 0.1);
    color: #065f46;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.alert-danger {
    background-color: rgba(239, 68, 68, 0.1);
    color: #991b1b;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

/* --- MODAL --- */

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-backdrop.show {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background-color: #ffffff;
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 500px;
    box-shadow: var(--box-shadow-lg);
    transform: translateY(-20px);
    transition: transform 0.3s;
    overflow: hidden;
}

.modal-backdrop.show .modal {
    transform: translateY(0);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    background-color: #f1f5f9;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.15rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    background-color: #f1f5f9;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* --- RESPONSIVIDAD Y ADAPTACION MULTIDISPOSITIVO --- */

.menu-toggle {
    display: none;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--border-radius-sm);
    font-size: 1.35rem;
    cursor: pointer;
    color: var(--text-color);
}

.menu-toggle:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

@media (max-width: 1200px) {
    .content-container {
        padding: 1.5rem;
    }

    .grid-cards {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    }
}

@media (max-width: 992px) {
    body.sidebar-open {
        overflow: hidden;
    }

    #sidebar {
        width: min(var(--sidebar-width), 86vw);
        max-width: 320px;
        transform: translateX(-105%);
    }

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

    #main-content {
        margin-left: 0;
        width: 100%;
    }

    body.sidebar-open #main-content::before {
        content: "";
        position: fixed;
        inset: 0;
        background-color: rgba(15, 23, 42, 0.45);
        z-index: 98;
    }

    .menu-toggle {
        display: inline-flex !important;
    }

    #header {
        padding: 0.75rem 1.25rem;
        gap: 0.8rem;
    }

    .header-title {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .header-user {
        min-width: 0;
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .content-container {
        padding: 1.25rem;
    }

    .card:hover {
        transform: none;
    }
}

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

    #header {
        height: auto;
        min-height: var(--header-height);
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .header-title {
        font-size: 1.05rem;
        padding-top: 0.65rem;
    }

    .header-user {
        width: 100%;
        justify-content: space-between;
        gap: 8px;
    }

    .header-user > span:not(.user-badge) {
        max-width: 48%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .btn,
    .btn-logout {
        min-height: 42px;
    }

    .content-container {
        padding: 1rem;
    }

    .grid-cards {
        grid-template-columns: 1fr;
        gap: 1rem;
        margin-bottom: 1rem;
    }

    .card {
        padding: 1rem;
        border-radius: var(--border-radius-sm);
    }

    .card-value {
        font-size: 1.6rem;
    }

    .card-header-icon {
        top: 1rem;
        right: 1rem;
        font-size: 1.5rem;
    }

    .alert {
        align-items: flex-start;
        padding: 0.85rem 1rem;
    }

    .table-responsive {
        border-radius: var(--border-radius-sm);
        box-shadow: none;
    }

    .table {
        min-width: 680px;
    }

    .table th,
    .table td {
        padding: 0.8rem 0.9rem;
        font-size: 0.88rem;
    }

    .modal {
        width: calc(100vw - 2rem);
        max-height: calc(100dvh - 2rem);
        overflow-y: auto;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 1rem;
    }

    /* Override legacy inline grids/flex layouts in views on mobile. */
    .content-container [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    .content-container [style*="grid-column: span"] {
        grid-column: auto !important;
    }

    .content-container [style*="display: flex"] {
        flex-wrap: wrap;
    }

    .content-container [style*="justify-content: space-between"] {
        gap: 0.75rem;
    }

    .content-container form[style*="display: flex"],
    .content-container div[style*="display: flex"] > form[style*="display: flex"] {
        width: 100%;
    }

    .content-container input[type="file"],
    .content-container select,
    .content-container textarea,
    .content-container input {
        max-width: 100%;
    }
}

@media (max-width: 520px) {
    #sidebar {
        width: min(300px, 88vw);
    }

    .sidebar-logo {
        padding: 1rem;
    }

    .sidebar-logo h1 {
        font-size: 1rem;
        white-space: normal;
        line-height: 1.2;
    }

    .sidebar-menu li a {
        padding: 0.78rem 1rem;
        gap: 10px;
    }

    #header {
        padding: 0.65rem 0.85rem;
    }

    .header-title {
        font-size: 0.98rem;
    }

    .header-user {
        align-items: stretch;
    }

    .header-user > span:not(.user-badge) {
        display: none;
    }

    .btn-logout {
        margin-left: auto;
    }

    .user-badge {
        border-radius: var(--border-radius-sm);
        display: inline-flex;
        align-items: center;
    }

    .content-container {
        padding: 0.8rem;
    }

    .card {
        padding: 0.9rem;
    }

    .btn {
        width: 100%;
        padding: 0.75rem 1rem;
    }

    .card .btn,
    .content-container form .btn {
        width: 100%;
    }

    .form-control {
        padding: 0.7rem 0.85rem;
        font-size: 0.92rem;
    }

    .login-body {
        min-height: 100dvh;
        height: auto;
        padding: 1rem;
    }

    .login-card {
        padding: 1.4rem;
        max-width: 100%;
    }

    .login-logo h2 {
        font-size: 1.25rem;
    }
}

/* Vista de Autenticación Especial (Login) */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-color);
    height: 100vh;
}

.login-card {
    background-color: #ffffff;
    border-radius: var(--border-radius);
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--box-shadow-lg);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.login-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo img {
    width: 70px;
    height: 70px;
    margin-bottom: 1rem;
    background-color: #ffffff;
    padding: 4px;
    border-radius: 50%;
    box-shadow: var(--box-shadow);
}

.login-logo h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.login-logo p {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 4px;
}

/* --- MANUAL Y AYUDA --- */

.manual-page {
    max-width: 1180px;
    margin: 0 auto;
}

.manual-hero {
    background-color: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    padding: 1.6rem;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
}

.manual-hero h2 {
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--text-color);
    margin: 0.35rem 0 0.45rem;
}

.manual-hero p {
    color: var(--text-light);
    font-size: 0.98rem;
    line-height: 1.5;
    max-width: 760px;
}

.manual-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--secondary-color);
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
}

.manual-search {
    background-color: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: var(--border-radius-sm);
    box-shadow: var(--box-shadow);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0.8rem 1rem;
    margin-bottom: 1.5rem;
}

.manual-search i {
    color: var(--text-light);
}

.manual-search input {
    border: 0;
    outline: 0;
    width: 100%;
    font-size: 0.98rem;
    color: var(--text-color);
}

.manual-layout {
    display: grid;
    grid-template-columns: 250px 1fr;
    gap: 1.5rem;
    align-items: start;
}

.manual-index {
    position: sticky;
    top: calc(var(--header-height) + 1rem);
    background-color: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    padding: 0.8rem;
}

.manual-index a {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 0.7rem 0.75rem;
    color: var(--text-color);
    text-decoration: none;
    border-radius: var(--border-radius-sm);
    font-weight: 500;
    font-size: 0.92rem;
}

.manual-index a:hover {
    background-color: #f1f5f9;
    color: var(--primary-color);
}

.manual-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.manual-section {
    background-color: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    padding: 1.5rem;
    scroll-margin-top: calc(var(--header-height) + 1.5rem);
}

.manual-section h3 {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-color);
    font-size: 1.18rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #f1f5f9;
}

.manual-section h4 {
    font-size: 1rem;
    color: var(--text-color);
    margin-bottom: 0.3rem;
}

.manual-section p,
.manual-section li {
    color: var(--text-light);
    line-height: 1.6;
}

.manual-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 1rem;
}

.manual-note {
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: var(--border-radius-sm);
    padding: 1rem;
}

.manual-note strong {
    display: block;
    color: var(--text-color);
    margin-bottom: 0.45rem;
}

.manual-note ol,
.manual-list {
    padding-left: 1.2rem;
}

.manual-list li {
    margin-bottom: 0.55rem;
}

.manual-mini-title {
    margin-top: 1.35rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0;
    border-bottom: 0;
}

.manual-checklist {
    display: grid;
    gap: 0.65rem;
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: var(--border-radius-sm);
    padding: 1rem;
    margin: 0.75rem 0 1rem;
}

.manual-checklist label {
    display: grid;
    grid-template-columns: 18px 1fr;
    gap: 0.6rem;
    align-items: start;
    color: var(--text-light);
    line-height: 1.5;
}

.manual-checklist input {
    width: 16px;
    height: 16px;
    margin-top: 3px;
    accent-color: var(--primary-color);
}

.manual-code {
    background-color: #0f172a;
    color: #f8fafc;
    border-radius: var(--border-radius-sm);
    padding: 0.9rem 1rem;
    font-family: Consolas, Monaco, monospace;
    font-size: 0.9rem;
    line-height: 1.5;
    overflow-x: auto;
    margin: 0.75rem 0 1rem;
}

.manual-table-wrap {
    overflow-x: auto;
}

.manual-table td {
    vertical-align: top;
}

.manual-steps {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.manual-steps article {
    display: grid;
    grid-template-columns: 36px 1fr;
    gap: 0.9rem;
    align-items: start;
}

.manual-steps span {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: #ffffff;
    font-weight: 700;
}

.manual-flow {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.manual-flow div {
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: var(--border-radius-sm);
    padding: 1rem;
}

.manual-flow i {
    color: var(--primary-color);
    font-size: 1.4rem;
    margin-bottom: 0.65rem;
}

.manual-flow strong {
    display: block;
    color: var(--text-color);
    margin-bottom: 0.35rem;
}

.manual-warning {
    border-left: 4px solid var(--warning-color);
    background-color: rgba(245, 158, 11, 0.09);
    color: var(--text-color);
    padding: 1rem;
    border-radius: var(--border-radius-sm);
    line-height: 1.55;
}

.manual-faq {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.manual-faq details {
    border: 1px solid #e2e8f0;
    border-radius: var(--border-radius-sm);
    background-color: #f8fafc;
    padding: 0.85rem 1rem;
}

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

.manual-faq p {
    margin-top: 0.65rem;
}

@media (max-width: 900px) {
    .manual-hero {
        align-items: flex-start;
        flex-direction: column;
    }

    .manual-layout {
        grid-template-columns: 1fr;
    }

    .manual-index {
        position: static;
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }
}

@media (max-width: 520px) {
    .manual-hero,
    .manual-section {
        padding: 1rem;
    }

    .manual-hero h2 {
        font-size: 1.35rem;
    }

    .manual-index {
        grid-template-columns: 1fr;
    }
}

/* --- RESPONSIVE OVERRIDES Y MEJORAS MÓVILES (FASE 3) --- */
@media (max-width: 768px) {
    /* Forzar colapso de grids inline a 1 columna en pantallas de celulares */
    div[style*="grid-template-columns"],
    form[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    
    /* Asegurar botones touch mínimos de 44px */
    .btn,
    .btn-logout,
    .menu-toggle {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Reducir padding de tarjetas para maximizar espacio */
    .card {
        padding: 1rem !important;
    }
}

