:root {
    --mf-bg: #f4f7fb;
    --mf-surface: #ffffff;
    --mf-surface-muted: #f8fafc;
    --mf-border: #dbe3ef;
    --mf-border-strong: #c7d3e3;
    --mf-text: #132238;
    --mf-text-muted: #61748c;
    --mf-primary: #1f6feb;
    --mf-primary-dark: #184fb5;
    --mf-success: #159f6b;
    --mf-warning: #e0a100;
    --mf-danger: #d64545;
    --mf-dark: #0f172a;
    --mf-sidebar: #0f1d33;
    --mf-sidebar-soft: #152844;
    --mf-radius-sm: 12px;
    --mf-radius: 18px;
    --mf-radius-lg: 24px;
    --mf-shadow-sm: 0 8px 24px rgba(15, 23, 42, 0.06);
    --mf-shadow: 0 18px 42px rgba(15, 23, 42, 0.1);
    --mf-transition: 180ms ease;
    --mf-topbar-height: 64px;
    --mf-sidebar-width: 280px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    min-height: 100vh;
    background: var(--mf-bg);
    color: var(--mf-text);
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

a {
    color: inherit;
}

img,
canvas,
svg,
video {
    max-width: 100%;
}

.app-shell {
    min-height: 100vh;
}

.min-w-0 {
    min-width: 0;
}

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    min-height: var(--mf-topbar-height);
    backdrop-filter: blur(14px);
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid rgba(219, 227, 239, 0.95);
}

.app-topbar .navbar-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    margin-right: 0;
    color: var(--mf-text);
    font-weight: 700;
}

.app-brand-icon {
    width: 2.25rem;
    height: 2.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--mf-primary), #5aa3ff);
    color: #fff;
    box-shadow: 0 10px 18px rgba(31, 111, 235, 0.24);
}

.app-topbar-title {
    min-width: 0;
}

.app-topbar-title h1 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.15;
}

.app-topbar-title p {
    margin: 0.15rem 0 0;
    color: var(--mf-text-muted);
    font-size: 0.78rem;
}

.app-menu-btn,
.btn-icon-soft {
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    border: 1px solid var(--mf-border);
    background: #fff;
    color: var(--mf-text);
}

.app-menu-btn:hover,
.btn-icon-soft:hover {
    background: var(--mf-surface-muted);
    border-color: var(--mf-border-strong);
}

.app-status-pill,
.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.5rem;
    padding: 0 0.9rem;
    border-radius: 999px;
    border: 1px solid var(--mf-border);
    background: #fff;
    color: var(--mf-text);
    font-size: 0.88rem;
    white-space: nowrap;
}

.status-dot {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 999px;
    background: var(--mf-warning);
    box-shadow: 0 0 0 0.25rem rgba(224, 161, 0, 0.15);
}

.status-dot.is-online {
    background: var(--mf-success);
    box-shadow: 0 0 0 0.25rem rgba(21, 159, 107, 0.15);
}

.app-layout {
    display: flex;
    min-height: calc(100vh - var(--mf-topbar-height));
}

.app-sidebar {
    width: var(--mf-sidebar-width);
    flex: 0 0 var(--mf-sidebar-width);
    background: linear-gradient(180deg, var(--mf-sidebar) 0%, #122342 100%);
    color: #d9e3f0;
    padding: 1rem 0.9rem 1.1rem;
}

.app-sidebar-header {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.65rem 0.75rem 1rem;
}

.app-sidebar-header .brand-title {
    font-weight: 700;
    color: #fff;
}

.app-sidebar-header .brand-subtitle {
    color: rgba(217, 227, 240, 0.68);
    font-size: 0.82rem;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.sidebar-nav .nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    min-height: 2.95rem;
    padding: 0.75rem 0.9rem;
    color: rgba(233, 239, 247, 0.86);
    border-radius: 16px;
    transition: background var(--mf-transition), transform var(--mf-transition), color var(--mf-transition);
}

.sidebar-nav .nav-link i {
    width: 1.2rem;
    text-align: center;
}

.sidebar-nav .nav-link:hover,
.sidebar-nav .nav-link:focus {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    transform: translateX(2px);
}

.sidebar-nav .nav-link.active {
    background: linear-gradient(135deg, rgba(31, 111, 235, 0.95), rgba(90, 163, 255, 0.82));
    color: #fff;
    box-shadow: 0 16px 28px rgba(31, 111, 235, 0.25);
}

.sidebar-notification-badge {
    position: absolute;
    top: 7px;
    right: 10px;
    min-width: 1.35rem;
    height: 1.35rem;
    padding: 0 0.32rem;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    box-shadow: 0 0 0 3px rgba(15, 29, 51, 0.92);
}

.sidebar-footer {
    margin-top: 1rem;
    padding: 1rem 0.8rem 0;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(217, 227, 240, 0.7);
    font-size: 0.82rem;
}

.app-main {
    flex: 1 1 auto;
    min-width: 0;
    padding: 1rem;
}

.app-content {
    max-width: 1600px;
    margin: 0 auto;
}

.content-section {
    animation: fadeIn 0.22s ease;
}

.page-actions .btn,
.btn-toolbar .btn {
    min-height: 2.75rem;
}

.card {
    border: 1px solid rgba(219, 227, 239, 0.8);
    border-radius: var(--mf-radius);
    background: var(--mf-surface);
    box-shadow: var(--mf-shadow-sm);
}

.card:hover {
    box-shadow: var(--mf-shadow-sm);
    transform: none;
}

.card-header {
    background: transparent;
    border-bottom: 1px solid rgba(219, 227, 239, 0.8);
    padding: 1rem 1.15rem;
    font-weight: 700;
}

.card-body,
.card-footer {
    padding: 1rem 1.15rem;
}

.card-footer {
    background: transparent;
    border-top: 1px solid rgba(219, 227, 239, 0.7);
}

.card-dashboard,
.summary-card {
    border-radius: 22px;
    overflow: hidden;
}

.summary-card .card-body,
.card-dashboard .card-body {
    padding: 1rem 1.05rem;
}

.summary-card h2,
.summary-card h3,
.card-dashboard h2,
.card-dashboard h3 {
    margin-bottom: 0;
    font-size: clamp(1.4rem, 4vw, 2rem);
    font-weight: 800;
}

.summary-card h6,
.card-dashboard h6 {
    font-size: 0.82rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    opacity: 0.88;
}

.table-responsive {
    overflow-x: auto;
    border-radius: inherit;
}

.table {
    margin-bottom: 0;
    color: var(--mf-text);
    vertical-align: middle;
}

.table th {
    color: var(--mf-text-muted);
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    text-transform: uppercase;
    border-top: none;
}

.table td,
.table th {
    padding: 0.9rem 1rem;
}

.table-hover tbody tr:hover {
    background-color: rgba(31, 111, 235, 0.04);
    cursor: pointer;
}

.form-control,
.form-select,
.form-check-input {
    border-radius: 14px;
    border: 1px solid var(--mf-border-strong);
    min-height: 2.9rem;
    padding: 0.75rem 0.9rem;
}

input.form-control[type="number"] {
    color: var(--mf-text) !important;
    background-color: var(--mf-surface) !important;
    -webkit-text-fill-color: var(--mf-text);
    opacity: 1;
}

textarea.form-control {
    min-height: 7rem;
}

.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    border-color: rgba(31, 111, 235, 0.45);
    box-shadow: 0 0 0 0.25rem rgba(31, 111, 235, 0.12);
}

.form-label {
    margin-bottom: 0.45rem;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--mf-text);
}

.btn {
    border-radius: 14px;
    padding: 0.72rem 1rem;
    font-weight: 600;
    transition: transform var(--mf-transition), box-shadow var(--mf-transition), background var(--mf-transition), border-color var(--mf-transition);
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--mf-primary), #4d95ff);
    border: none;
    box-shadow: 0 12px 24px rgba(31, 111, 235, 0.2);
}

.btn-primary:hover {
    box-shadow: 0 16px 28px rgba(31, 111, 235, 0.26);
}

.btn-success {
    background: linear-gradient(135deg, var(--mf-success), #25bf84);
    border: none;
}

.btn-warning {
    color: #fff;
}

.alert {
    border: none;
    border-radius: 16px;
    box-shadow: var(--mf-shadow-sm);
}

.badge {
    border-radius: 999px;
    padding: 0.4rem 0.65rem;
}

/* Bootstrap 5.1 no incluye las utilidades text-bg-* de 5.2+. */
.text-bg-light {
    color: var(--mf-text) !important;
    background-color: var(--mf-surface-muted) !important;
}

.text-bg-primary {
    color: var(--mf-surface) !important;
    background-color: var(--mf-primary) !important;
}

.text-bg-secondary {
    color: var(--mf-surface) !important;
    background-color: var(--mf-text-muted) !important;
}

.text-bg-success {
    color: var(--mf-surface) !important;
    background-color: var(--mf-success) !important;
}

.text-bg-warning {
    color: var(--mf-dark) !important;
    background-color: var(--mf-warning) !important;
}

.text-bg-danger {
    color: var(--mf-surface) !important;
    background-color: var(--mf-danger) !important;
}

.text-bg-dark {
    color: var(--mf-surface) !important;
    background-color: var(--mf-dark) !important;
}

.modal-content {
    border: 1px solid rgba(219, 227, 239, 0.9);
    border-radius: 22px;
    box-shadow: var(--mf-shadow);
}

.modal-header,
.modal-footer {
    border-color: rgba(219, 227, 239, 0.8);
    padding: 1rem 1.15rem;
}

.modal-body {
    padding: 1rem 1.15rem;
}

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.56);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.spinner-custom {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.35);
    border-top: 4px solid #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.app-offcanvas {
    width: min(86vw, 320px);
    background: linear-gradient(180deg, var(--mf-sidebar) 0%, #122342 100%);
    color: #fff;
}

.app-offcanvas .offcanvas-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.app-offcanvas .btn-close {
    filter: invert(1) grayscale(1);
}

.page-kicker {
    color: var(--mf-text-muted);
    font-size: 0.86rem;
}

.mobile-only {
    display: block;
}

.desktop-only {
    display: none !important;
}

.table-stack-card {
    display: none;
}

.notification-toast {
    border-radius: 18px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: #eef2f7;
}

::-webkit-scrollbar-thumb {
    background: #c8d3e1;
    border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
    background: #aebdce;
}

@media (min-width: 992px) {
    .desktop-only {
        display: initial !important;
    }

    .mobile-only {
        display: none !important;
    }

    .app-main {
        padding: 1.25rem 1.5rem;
    }
}

@media (max-width: 991.98px) {
    .app-main {
        padding: 0.85rem;
    }

    .app-topbar .container-fluid {
        padding-left: 0.85rem;
        padding-right: 0.85rem;
    }

    .btn-toolbar {
        width: 100%;
        gap: 0.65rem;
    }

    .btn-toolbar .btn {
        flex: 1 1 calc(50% - 0.65rem);
        margin: 0 !important;
    }

    .card-header .form-control.float-end {
        float: none !important;
        width: 100% !important;
        margin-top: 0.85rem;
    }
}


.modal-footer {
    gap: 0.65rem;
}

.input-group > .form-control,
.input-group > .form-select {
    min-width: 0;
}

.modal-body .table-responsive {
    overflow-x: auto;
}

@media (max-width: 767.98px) {
    body {
        font-size: 0.95rem;
    }

    .app-topbar-title p,
    .user-chip span,
    .app-status-pill span:last-child {
        display: none;
    }

    .app-topbar-title h1 {
        font-size: 0.95rem;
    }

    .app-main {
        padding: 0.75rem;
    }

    .content-section > .container-fluid,
    .content-section > .container {
        padding-left: 0;
        padding-right: 0;
    }

    .content-section .border-bottom {
        padding-top: 0 !important;
        margin-bottom: 0.9rem !important;
    }

    .content-section h1.h2 {
        font-size: 1.15rem;
        margin-bottom: 0.25rem;
    }

    .content-section .fs-6 {
        display: block;
        margin-top: 0.2rem;
        font-size: 0.8rem !important;
    }

    .btn-toolbar .btn,
    .page-actions .btn,
    .content-section .btn-group > .btn {
        width: 100%;
        flex: 1 1 100%;
    }

    .card,
    .modal-content {
        border-radius: 18px;
    }

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

    .table-responsive {
        overflow: visible;
    }

    .table.table-mobile-stack thead {
        display: none;
    }

    .table.table-mobile-stack,
    .table.table-mobile-stack tbody,
    .table.table-mobile-stack tr,
    .table.table-mobile-stack td {
        display: block;
        width: 100%;
    }

    .table.table-mobile-stack tbody tr {
        margin: 0 0 0.9rem;
        padding: 0.95rem;
        background: #fff;
        border: 1px solid rgba(219, 227, 239, 0.95);
        border-radius: 16px;
        box-shadow: var(--mf-shadow-sm);
    }

    .table.table-mobile-stack tbody tr:last-child {
        margin-bottom: 0;
    }

    .table.table-mobile-stack tbody td {
        position: relative;
        border: none;
        padding: 0.2rem 0 0.2rem 8.25rem;
        min-height: 1.7rem;
        text-align: left !important;
    }

    .table.table-mobile-stack tbody td::before {
        content: attr(data-label);
        position: absolute;
        left: 0;
        top: 0.2rem;
        width: 7.5rem;
        color: var(--mf-text-muted);
        font-size: 0.76rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.02em;
    }

    .table.table-mobile-stack tbody td[data-label=""] {
        padding-left: 0;
    }

    .table.table-mobile-stack tbody td[data-label=""]::before {
        display: none;
    }

    .table.table-mobile-stack .btn,
    .table.table-mobile-stack .btn-group {
        width: 100%;
    }

    .table.table-mobile-stack .btn + .btn {
        margin-top: 0.45rem;
    }
}

@media print {
    .app-topbar,
    .app-sidebar,
    .btn-toolbar,
    .btn,
    .modal,
    .mobile-only {
        display: none !important;
    }

    .app-main {
        padding: 0;
    }
}
