:root {
    --app-bg: #f5f7fb;
    --app-border: #d9e0ea;
    --sidebar-width: 330px;
    --sidebar-collapsed-width: 84px;
}

html,
body {
    min-height: 100%;
    font-size: 12px;
}

body {
    font-family: "Montserrat", system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--app-bg);
}

body,
h1,
h2,
h3,
h4,
h5,
h6,
.h1,
.h2,
.h3,
.h4,
.h5,
.h6,
p,
label,
small,
.small,
.btn,
.badge,
.form-control,
.form-select,
.form-check-label,
.table,
.dropdown-menu,
.breadcrumb,
.card,
.alert {
    font-size: 1rem !important;
}

button,
input,
select,
textarea,
.btn,
.form-control,
.form-select,
.dropdown-menu,
.table,
.dataTable-wrapper,
.swal2-popup {
    font-family: "Montserrat", system-ui, -apple-system, "Segoe UI", sans-serif;
}

.app-shell {
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
}

.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    min-height: 100vh;
    position: sticky;
    top: 0;
    background: #ffffff;
    border-right: 1px solid var(--app-border);
    transition: width .2s ease;
    overflow: visible;
    padding: 1rem;
    z-index: 20;
}

.sidebar-brand {
    min-height: 4rem;
    color: #172033;
    justify-content: center;
}

.brand-logo {
    display: block;
    width: 176px;
    max-width: 100%;
    height: auto;
}

.brand-logo-collapsed {
    display: none;
}

.brand-logo-mobile {
    width: 210px;
}

.brand-mark {
    flex: 0 0 2.25rem;
    width: 2.25rem;
    height: 2.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: .65rem;
    border-radius: .5rem;
    color: #ffffff;
    background: #0d6efd;
}

.sidebar-text {
    white-space: nowrap;
    transition: opacity .15s ease;
}

.btn-toggle {
    width: 100%;
    min-height: 2.5rem;
    gap: .65rem;
    padding: .55rem .75rem;
    font-weight: 600;
    color: #263246;
    background-color: transparent;
    text-align: left;
}

.menu-icon {
    width: 1.25rem;
    min-width: 1.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-toggle:hover,
.btn-toggle:focus,
.sidebar-link.active {
    color: #0d6efd;
    background-color: #eef5ff;
}

.btn-toggle::after {
    width: 1.25em;
    line-height: 0;
    margin-left: auto;
    content: "\F285";
    font-family: bootstrap-icons;
    transition: transform .2s ease;
}

.btn-toggle[aria-expanded="true"]::after {
    transform: rotate(90deg);
}

.sidebar-link::after {
    display: none;
}

.btn-toggle-nav a {
    width: calc(100% - 1.5rem);
    padding: .45rem .75rem;
    margin: .125rem 0 .125rem 2.25rem;
    color: #4d5a6d;
}

.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
    padding-left: .75rem;
    padding-right: .75rem;
}

.sidebar-collapsed .sidebar .sidebar-text,
.sidebar-collapsed .sidebar .btn-toggle::after,
.sidebar-collapsed .sidebar .btn-toggle-nav {
    display: none !important;
    pointer-events: none;
}

.sidebar-collapsed .sidebar .sidebar-brand .sidebar-text {
    display: none !important;
}

.sidebar-collapsed .sidebar .sidebar-brand,
.sidebar-collapsed .sidebar .btn-toggle,
.sidebar-collapsed .sidebar .user-menu {
    justify-content: center;
}

.sidebar-collapsed .sidebar .brand-mark,
.sidebar-collapsed .sidebar .avatar {
    margin-right: 0 !important;
}

.sidebar-collapsed .sidebar .sidebar-brand {
    margin-bottom: 1.25rem !important;
    width: 100%;
}

.sidebar-collapsed .sidebar .brand-logo-full {
    display: none;
}

.sidebar-collapsed .sidebar .brand-logo-collapsed {
    display: block;
    width: 3.1rem;
    height: 3.1rem;
    object-fit: contain;
    object-position: center center;
}

.sidebar-collapsed .sidebar .sidebar-menu {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
}

.sidebar-collapsed .sidebar .sidebar-menu li {
    width: 100%;
}

.sidebar-collapsed .sidebar .btn-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    min-height: 3rem;
    padding: 0;
    margin: 0 auto;
    gap: 0;
}

.sidebar-collapsed .sidebar .menu-icon {
    width: 1.25rem;
    min-width: 1.25rem;
    margin: 0;
    line-height: 1;
    text-align: center;
}

.sidebar-collapsed .sidebar .sidebar-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.sidebar-collapsed .sidebar .user-menu {
    width: 3rem;
    height: 3rem;
}

.sidebar-collapsed .sidebar .user-menu::after {
    display: none;
}

.sidebar-collapsed .sidebar .collapse.show {
    display: none;
}

.btn-toggle-nav a:hover,
.btn-toggle-nav a.active {
    color: #0d6efd;
    background-color: #eef5ff;
}

.user-menu {
    min-height: 3rem;
    gap: .65rem;
    color: #263246;
}

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

.sidebar-footer .dropdown-menu {
    min-width: 12rem;
}

.sidebar-collapsed .sidebar .sidebar-footer hr {
    width: 100%;
}

.avatar {
    width: 2rem;
    height: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #ffffff;
    background: #172033;
    font-weight: 700;
}

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

.topbar {
    min-height: 72px;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: rgba(255, 255, 255, .92);
    border-bottom: 1px solid var(--app-border);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 1030;
}

.content {
    padding: 1.5rem;
}

.login-split {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(360px, 40%) minmax(0, 1fr);
    background: #f6f7f9;
}

.login-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: #ffffff;
    box-shadow: 8px 0 32px rgba(23, 32, 51, .08);
    z-index: 1;
}

.login-card {
    width: min(100%, 380px);
    padding: 3rem 2.5rem 2.5rem;
    background: #ffffff;
    border: 1px solid rgba(217, 224, 234, .85);
    box-shadow: 0 10px 32px rgba(15, 23, 42, .11);
}

.login-logo {
    display: block;
    width: min(100%, 260px);
    height: auto;
    margin: 0 auto 2rem;
}

.login-field {
    margin-bottom: 1.35rem;
}

.login-field .form-label {
    margin-bottom: .55rem;
    font-weight: 600;
    color: #4d4d4d;
}

.login-input,
.login-password-toggle,
.login-submit {
    border-radius: 0 !important;
}

.login-input {
    height: 3.35rem;
    padding: .75rem 1rem;
    border: 1px solid #cfd8dc;
    background: #f7f8fa;
    color: #222222;
}

.login-input:focus {
    border-color: #4f8cff;
    box-shadow: 0 0 0 .15rem rgba(79, 140, 255, .16);
}

.login-password-row {
    display: flex;
}

.login-password-row .login-input {
    border-right: 0;
}

.login-password-toggle {
    width: 3.35rem;
    min-width: 3.35rem;
    border: 1px solid #cfd8dc;
    background: #f7f8fa;
    color: #7b8794;
}

.login-password-toggle:hover,
.login-password-toggle:focus {
    color: #4f8cff;
    background: #eef5ff;
}

.login-submit {
    width: 100%;
    min-height: 3.35rem;
    margin-top: .4rem;
    border: 0;
    background: #4f8cff;
    color: #ffffff;
    font-weight: 700;
    letter-spacing: .03em;
}

.login-submit:hover,
.login-submit:focus {
    background: #295fc7;
}

.login-error {
    width: 100%;
    margin-bottom: 1.25rem;
    padding: .85rem 1rem;
    background: #e13d4b;
    color: #ffffff;
    font-weight: 600;
    text-align: center;
}

.login-visual {
    min-height: 100vh;
    background:
        linear-gradient(rgba(8, 24, 40, .18), rgba(8, 24, 40, .18)),
        url("../img/login-fondo.jpg") center center / cover no-repeat;
}

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

.config-option {
    min-height: 112px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border: 1px solid var(--app-border);
    border-radius: .45rem;
    background: #ffffff;
    color: #172033;
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.config-option:hover,
.config-option:focus {
    border-color: #9cc3ff;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .08);
    transform: translateY(-1px);
}

.config-option-icon {
    width: 3rem;
    height: 3rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: .45rem;
    color: #0d6efd;
    background: #eef5ff;
}

.config-option-title,
.config-option-text {
    display: block;
}

.config-option-title {
    font-weight: 700;
    color: #172033;
}

.config-option-text {
    margin-top: .25rem;
    color: #64748b;
}

.config-option-arrow {
    color: #0d6efd;
    font-size: 1.5rem !important;
}

.hero-panel,
.content-panel,
.metric-card {
    background: #ffffff;
    border: 1px solid var(--app-border);
    border-radius: .5rem;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .05);
}

.hero-panel {
    padding: 2rem;
}

.content-panel {
    padding: 1.25rem;
}

.form-section-card {
    padding: 1rem;
    border: 1px solid var(--app-border);
    border-radius: .45rem;
    background: #ffffff;
}

.form-label {
    font-weight: 500;
    color: #263246;
}

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

.table.dataTable,
.table.datatable {
    width: max-content !important;
    min-width: 100%;
    table-layout: auto !important;
}

.table.dataTable thead th,
.table.dataTable tbody td,
.table.datatable thead th,
.table.datatable tbody td {
    width: auto !important;
    min-width: max-content;
    white-space: nowrap !important;
}

.table.dataTable thead th,
.table.datatable thead th {
    font-weight: 700;
    color: #263246;
}

.table.dataTable thead th.dt-type-numeric,
.table.dataTable thead td.dt-type-numeric,
.table.dataTable tbody th.dt-type-numeric,
.table.dataTable tbody td.dt-type-numeric {
    text-align: left !important;
}

.table.dataTable thead .dt-column-header,
.table.datatable thead .dt-column-header {
    width: 100%;
    min-width: max-content;
    display: grid !important;
    grid-template-columns: max-content auto;
    align-items: center;
    column-gap: .75rem;
    justify-content: stretch;
    flex-direction: row !important;
}

.table.dataTable thead .dt-column-title,
.table.datatable thead .dt-column-title {
    grid-column: 1;
    white-space: nowrap !important;
}

.table.dataTable thead .dt-column-order,
.table.datatable thead .dt-column-order {
    grid-column: 2;
    justify-self: end;
    margin-left: 0 !important;
}

.metric-card {
    min-height: 112px;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
}

.metric-icon {
    width: 3rem;
    height: 3rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: .5rem;
}

.home-metrics-grid,
.home-status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 1rem;
}

.home-report-card {
    min-height: 96px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    text-align: center;
    background: #ffffff;
    border: 1px solid rgba(217, 224, 234, .75);
    border-radius: .45rem;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .06);
}

.home-card-label {
    font-weight: 500;
    color: #172033;
    white-space: nowrap;
}

.home-card-value {
    margin-top: .45rem;
    font-weight: 700;
    line-height: 1;
    color: #172033;
}

.home-section-title {
    margin-bottom: .75rem;
    font-weight: 600;
    color: #263246;
}

.dashboard-section {
    padding-top: .15rem;
}

.dashboard-section-heading {
    margin-bottom: .9rem;
    padding-bottom: .65rem;
    border-bottom: 1px solid var(--app-border);
}

.dashboard-divider {
    height: 1px;
    margin: 1.25rem 0;
    background: var(--app-border);
}

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

.home-document-card {
    min-height: 104px;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: #ffffff;
    border: 1px solid rgba(217, 224, 234, .75);
    border-radius: .45rem;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .06);
}

.home-document-icon {
    width: 2.75rem;
    height: 2.75rem;
    flex: 0 0 2.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: .45rem;
    color: #0d6efd;
    background: #eef5ff;
}

.home-map-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 260px;
    gap: 1rem;
}

.home-map {
    min-height: 560px;
    position: relative;
    z-index: 0;
    border: 1px solid var(--app-border);
    border-radius: .45rem;
    overflow: hidden;
}

.home-map .leaflet-pane,
.home-map .leaflet-top,
.home-map .leaflet-bottom {
    z-index: 1;
}

.home-map-filter {
    padding: 1rem;
    border: 1px solid var(--app-border);
    border-radius: .45rem;
    background: #ffffff;
}

.home-map-filter-item {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: .45rem .5rem;
    border: 1px solid #eef1f6;
    border-radius: .4rem;
    font-weight: 500;
    color: #263246;
    cursor: pointer;
}

.home-map-dot {
    width: .75rem;
    height: .75rem;
    flex: 0 0 .75rem;
    border-radius: 50%;
}

#establecimientosTable th:nth-child(1),
#establecimientosTable td:nth-child(1) {
    text-align: center;
}

#establecimientosTable th:nth-child(2),
#establecimientosTable td:nth-child(2) {
    text-align: center;
}

#establecimientosTable th:nth-child(3),
#establecimientosTable td:nth-child(3) {
    min-width: 26rem;
}

#establecimientosTable th:nth-child(4),
#establecimientosTable td:nth-child(4) {
    white-space: normal;
}

.estaciones-table {
    width: max-content !important;
    min-width: 100%;
}

.estaciones-table th,
.estaciones-table td {
    white-space: nowrap;
}

.table-actions {
    width: 1%;
    min-width: 5rem;
    text-align: center;
    white-space: nowrap;
}

.guia-desechos-table {
    width: max-content;
    min-width: 100%;
}

.guia-desechos-table th,
.guia-desechos-table td {
    white-space: nowrap;
}

.guia-desechos-table th {
    font-weight: 700;
    line-height: 1.15;
    color: #263246;
}

.guia-desechos-table .form-select,
.guia-desechos-table .form-control {
    min-width: 10rem;
}

.guia-desechos-table .descripcion-desecho {
    min-width: 22rem;
}

.clientes-select-table tbody tr {
    cursor: pointer;
}

.clientes-select-table tbody tr.table-active td {
    background-color: #eaf2ff;
}

.estaciones-select-table tbody tr {
    cursor: pointer;
}

.estaciones-select-table tbody tr.table-active td {
    background-color: #eaf2ff;
}

table.dataTable.table.datatable {
    width: max-content !important;
    min-width: 100% !important;
    table-layout: auto !important;
}

table.dataTable.table.datatable > thead > tr > th {
    width: auto !important;
    min-width: max-content !important;
    white-space: nowrap !important;
    font-weight: 700 !important;
}

table.dataTable.table.datatable > tbody > tr > td {
    width: auto !important;
}

table.dataTable.table.datatable > thead > tr > th div.dt-column-header,
table.dataTable.table.datatable > thead > tr > th.dt-type-numeric div.dt-column-header {
    width: 100% !important;
    min-width: max-content !important;
    display: grid !important;
    grid-template-columns: max-content auto !important;
    align-items: center !important;
    column-gap: .75rem !important;
    flex-direction: row !important;
    direction: ltr !important;
}

table.dataTable.table.datatable > thead > tr > th span.dt-column-title,
table.dataTable.table.datatable > thead > tr > th.dt-type-numeric span.dt-column-title {
    grid-column: 1 !important;
    white-space: nowrap !important;
    text-align: left !important;
}

table.dataTable.table.datatable > thead > tr > th span.dt-column-order,
table.dataTable.table.datatable > thead > tr > th.dt-type-numeric span.dt-column-order {
    grid-column: 2 !important;
    justify-self: end !important;
    margin-left: 0 !important;
}

@media (max-width: 575.98px) {
    .topbar {
        padding: .85rem 1rem;
    }

    .content {
        padding: 1rem;
    }

    .hero-panel {
        padding: 1.25rem;
    }
}

@media (max-width: 991.98px) {
    .login-split {
        grid-template-columns: 1fr;
    }

    .login-panel {
        min-height: 100vh;
        padding: 1.5rem;
    }

    .login-card {
        padding: 2rem 1.5rem;
    }

    .login-visual {
        display: none;
    }

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

    .home-map {
        min-height: 420px;
    }
}
