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

main {
    flex: 1 0 auto;
}

.table > :not(caption) > * > * {
    padding: 0.85rem 0.75rem;
}

.badge {
    font-weight: 500;
}

.form-check-label {
    cursor: pointer;
    user-select: none;
}

.admin-toolbar .btn {
    white-space: nowrap;
}

.admin-search {
    width: min(100%, 420px);
}

#search {
width: 100%;
min-width: 280px;
}

.admin-table {
    min-width: 760px;
}

.admin-table td,
.admin-table th {
    vertical-align: middle;
}

.admin-email a,
.translation-preview,
.translation-preview .text-truncate {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.role-badge-list .badge {
    margin-bottom: 0.25rem;
}

.admin-action-buttons {
    display: inline-flex;
    gap: 0.45rem;
    align-items: center;
    justify-content: flex-end;
}

/* =========================================================
 *  FIX MODALES EN MOVIL / PANTALLAS BAJAS
 *  ========================================================= */

.modal-header,
.modal-footer {
    flex-shrink: 0;
}

.modal-dialog-scrollable .modal-content {
    overflow: hidden;
}

.modal-dialog-scrollable .modal-body {
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* =========================================================
 *  MOBILE
 *  ========================================================= */

@media (max-width: 767.98px) {
    .admin-page.container {
        max-width: 100%;
        padding-left: 0.85rem;
        padding-right: 0.85rem;
    }

    .admin-toolbar {
        align-items: stretch !important;
    }

    .admin-search {
        width: 100%;
        margin-left: 0 !important;
    }

    #search {
    width: 100%;
    min-width: 0;
    }

    .card.shadow-sm {
        border-radius: 1rem;
        overflow: visible;
    }

    .table-responsive {
        overflow: visible;
    }

    .admin-table {
        display: block;
        width: 100%;
        min-width: 0;
        margin: 0;
        border-collapse: separate;
        border-spacing: 0;
    }

    .admin-table thead {
        display: none;
    }

    .admin-table tbody {
        display: block;
        padding: 0.65rem;
        background: var(--bs-tertiary-bg);
    }

    .admin-table tr {
        display: block;
        margin-bottom: 0.75rem;
        overflow: hidden;
        border: 1px solid var(--bs-border-color);
        border-radius: 0.9rem;
        background: var(--bs-body-bg);
        box-shadow: 0 0.125rem 0.35rem rgba(0, 0, 0, 0.12);
    }

    .admin-table tr:last-child {
        margin-bottom: 0;
    }

    .admin-table td {
        display: grid;
        grid-template-columns: minmax(88px, 34%) minmax(0, 1fr);
        gap: 0.75rem;
        align-items: start;
        width: 100%;
        padding: 0.7rem 0.85rem;
        border-bottom: 1px solid var(--bs-border-color-translucent);
        white-space: normal;
        text-align: left !important;
    }

    .admin-table td:last-child {
        border-bottom: 0;
    }

    .admin-table td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--bs-secondary-color);
    }

    .admin-table td:not([data-label]) {
        display: block;
        text-align: center !important;
    }

    .admin-table td:not([data-label])::before {
        content: none;
    }

    .admin-table td[colspan] {
        display: block;
        text-align: center !important;
    }

    .admin-table td[colspan]::before {
        content: none;
    }

    .admin-actions {
        align-items: center !important;
    }

    .admin-action-buttons {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        justify-content: flex-end;
    }

    .admin-action-buttons .btn {
        min-width: 2.35rem;
    }

    .translation-preview .text-truncate {
        max-width: 100% !important;
        white-space: normal;
    }

    /* Modal en móvil */
    .modal {
        --bs-modal-margin: 0.5rem;
    }

    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-dialog-centered {
        min-height: calc(100dvh - 1rem);
    }

    .modal-dialog-scrollable {
        height: calc(100dvh - 1rem);
        max-height: calc(100dvh - 1rem);
    }

    .modal-dialog-scrollable .modal-content {
        max-height: calc(100dvh - 1rem);
    }

    .modal-body {
        padding: 0.9rem;
    }

    .modal-footer {
        padding: 0.75rem 0.9rem;
    }

    .modal .row.g-3 {
        --bs-gutter-y: 0.85rem;
    }

    #rolesContainer > [class*="col-"] {
    width: 100%;
    }
}

/* =========================================================
 *  PANTALLAS BAJAS, INCLUSO EN DESKTOP
 *  ========================================================= */

@media (max-height: 720px) {
    .modal {
        --bs-modal-margin: 0.5rem;
    }

    .modal-dialog {
        margin-top: 0.5rem;
        margin-bottom: 0.5rem;
    }

    .modal-dialog-centered {
        min-height: calc(100dvh - 1rem);
    }

    .modal-dialog-scrollable {
        height: calc(100dvh - 1rem);
        max-height: calc(100dvh - 1rem);
    }

    .modal-dialog-scrollable .modal-content {
        max-height: calc(100dvh - 1rem);
    }

    .modal-body {
        overflow-y: auto;
    }
}

@media (max-width: 380px) {
    .admin-table td {
        grid-template-columns: 1fr;
        gap: 0.25rem;
    }

    .admin-action-buttons {
        justify-content: flex-start;
    }
}
/* =========================================================
 *  FIX SCROLL MODAL CON FORM DENTRO DE .modal-content
 *  ========================================================= */

.modal-dialog-scrollable .modal-content {
    max-height: calc(100vh - 1rem);
    overflow: hidden;
}

.modal-dialog-scrollable .modal-content > form {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-height: calc(100vh - 1rem);
    min-height: 0;
}

.modal-dialog-scrollable .modal-header,
.modal-dialog-scrollable .modal-footer {
    flex: 0 0 auto;
}

.modal-dialog-scrollable .modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 767.98px) {
    .modal {
        padding: 0 !important;
    }

    .modal-dialog.modal-dialog-scrollable {
        width: calc(100% - 1rem);
        max-width: calc(100% - 1rem);
        height: calc(100dvh - 1rem);
        max-height: calc(100dvh - 1rem);
        margin: 0.5rem auto;
    }

    .modal-dialog-scrollable .modal-content {
        height: calc(100dvh - 1rem);
        max-height: calc(100dvh - 1rem);
    }

    .modal-dialog-scrollable .modal-content > form {
        height: calc(100dvh - 1rem);
        max-height: calc(100dvh - 1rem);
    }

    .modal-dialog-scrollable .modal-body {
        overflow-y: auto !important;
    }
}
/* =========================================================
 *  ROLES GRID - MODAL USER
 *  ========================================================= */

#rolesContainer.role-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 0.65rem;
}

.role-option {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr);
    align-items: center;
    gap: 0.45rem;
    width: 100%;
    min-height: 44px;
    padding: 0.65rem 0.75rem;
    margin: 0;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.65rem;
    background: var(--bs-body-bg);
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.role-option:hover {
    background: var(--bs-tertiary-bg);
    border-color: var(--bs-primary);
}

.role-option .form-check-input {
    margin: 0;
}

.role-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.55rem;
    height: 1.55rem;
    padding: 0 0.35rem;
    border-radius: 0.45rem;
    background: #6c757d;
    color: #fff;
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1;
}

.role-name {
    min-width: 0;
    font-size: 0.86rem;
    font-weight: 600;
    line-height: 1.25;
    color: var(--bs-body-color);
    word-break: normal;
    overflow-wrap: anywhere;
}

/* Desktop ancho: 3 columnas limpias */
@media (min-width: 992px) {
    #rolesContainer.role-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* Tablet: 2 columnas */
@media (max-width: 991.98px) {
    #rolesContainer.role-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Móvil: 1 columna */
@media (max-width: 575.98px) {
    #rolesContainer.role-grid {
    grid-template-columns: 1fr;
    }

    .role-option {
        min-height: 42px;
        padding: 0.6rem 0.7rem;
    }

    .role-name {
        font-size: 0.84rem;
    }
}


/* =========================================================
 *  MODO CLARO / OSCURO
 *  ========================================================= */

[data-bs-theme="dark"] .navbar.bg-primary {
    box-shadow: 0 0.25rem 1rem rgba(0, 0, 0, 0.35) !important;
}

[data-bs-theme="dark"] .card,
[data-bs-theme="dark"] .modal-content,
[data-bs-theme="dark"] .role-option {
    border-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .table-light {
    --bs-table-bg: var(--bs-tertiary-bg);
    --bs-table-color: var(--bs-body-color);
    --bs-table-border-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .badge.text-bg-light.text-muted {
    color: var(--bs-body-color) !important;
    background-color: var(--bs-tertiary-bg) !important;
    border-color: var(--bs-border-color) !important;
}

[data-bs-theme="dark"] code {
    color: #ffb3d1;
}

[data-bs-theme="dark"] .admin-table tr {
    box-shadow: 0 0.125rem 0.45rem rgba(0, 0, 0, 0.25);
}

/* Permisos Admin/Usuario */
.permission-choice {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem 1.5rem;
    align-items: center;
}

.permission-choice .form-text {
    flex-basis: 100%;
}

[data-bs-theme="dark"] .permission-choice {
    background-color: rgba(255,255,255,.04) !important;
    border-color: rgba(255,255,255,.16) !important;
}


/* Language selector compact: flag + code only */
.language-dropdown-menu {
    min-width: 6.5rem;
}

.language-dropdown-menu .dropdown-item {
    display: flex;
    align-items: center;
    gap: .35rem;
}
/* =========================================================
 *  ADMIN PAGE - CARD COMPLETA
 *  ========================================================= */

.admin-page-full {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.admin-card {
    width: 100%;
}

.admin-card-fill {
    flex: 1 1 auto;
    min-height: clamp(360px, 55vh, 900px);
}

/* =========================================================
 *  ROLE PAGE - RELLENAR PANTALLA SIN SCROLL EXTRA
 *  ========================================================= */

html,
body {
    min-height: 100%;
}

body {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1 1 auto;
    min-height: 0;
}

.role-page-fill {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-height: 0;
}

.role-title-card {
    flex: 0 0 auto;
}

.role-content-card {
    flex: 1 1 0;
    min-height: 0;
    overflow: auto;
}
/* Footer con el mismo color que el header */
.app-footer {
    background-color: var(--bs-primary) !important;
    border-top: 1px solid rgba(255, 255, 255, 0.18);
}

.app-footer .container {
    color: rgba(255, 255, 255, 0.72) !important;
}
