html {
    font-size: 14px !important;
}

:root {
    --bg-color: #f8fafc;
    --sidebar-bg: #1e293b;
    --card-bg: #ffffff;
    --primary-color: #3b82f6;
    --data-science-color: #0084D8;
    --dbms-color: #f43f5e;
    --scheduler-color: #10b981;
    --monitoring-color: #eab308;
    --text-color: #1e293b;
    --text-light: #64748b;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --radius: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    font-size: 1rem;
    line-height: 1.5;
}

body:not(.login-page) {
    display: flex;
}

body.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
}

.sidebar {
    width: 280px;
    background-color: var(--sidebar-bg);
    color: white;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    /* Not 100vh: on mobile it spans behind the browser toolbars and hides the footer. */
    top: 0;
    bottom: 0;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1000;
    transition: width 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
}

.sidebar.sidebar-hidden {
    width: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.sidebar-toggle {
    position: fixed;
    left: 280px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 48px;
    padding: 0;
    border: none;
    border-radius: 0 8px 8px 0;
    background-color: var(--sidebar-bg);
    color: white;
    font-size: 0.7rem;
    opacity: 0.35;
    cursor: pointer;
    z-index: 1001;
    transition: left 0.3s ease, opacity 0.2s ease;
}

.sidebar-toggle:hover,
.sidebar-toggle:focus-visible {
    opacity: 1;
}

.sidebar-toggle.sidebar-toggle-collapsed {
    left: 0;
}

.main-content-full {
    margin-left: 0 !important;
    width: 100% !important;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background-color: var(--primary-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.logo-img {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

/* Version label rendered next to the "Libre Data Hub" wordmark in the sidebar
   logo (and centered under the wordmark in the login card). Hardcoded value
   is kept in sync by bumpversion (see .bumpversion.cfg). */
.logo-version {
    font-size: 0.7rem;
    font-weight: 500;
    opacity: 0.6;
    letter-spacing: 0.02em;
    align-self: flex-end;
    padding-bottom: 0.25rem;
}

.login-card .logo .logo-version {
    align-self: center;
    padding-bottom: 0;
    font-size: 0.85rem;
}

.admin-btn {
    background-color: var(--primary-color);
    color: white;
    padding: 0.6rem 1rem;
    border-radius: var(--radius);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    transition: background-color 0.2s;
}

.admin-btn:hover {
    background-color: #2563eb;
}

.nav-section {
    margin-bottom: 1.5rem;
}

.nav-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 0.75rem;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.25rem;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    font-size: 1rem;
    transition: all 0.2s;
}

.nav-item:hover,
.nav-item:focus {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.nav-item.active {
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
    font-weight: 500;
}

.nav-item.admin {
    background-color: #ea580c;
    color: white;
    border-radius: var(--radius);
    font-weight: 500;
}

.nav-item.admin:hover {
    background-color: #c2410c;
    color: white;
}

.nav-icon {
    width: 1.25rem;
    margin-right: 0.75rem;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.admin-sidebar-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    background-color: #f97316;
    color: white;
    text-decoration: none;
    border-radius: var(--radius);
    font-weight: 500;
    transition: background-color 0.2s;
}

.admin-sidebar-btn:hover {
    background-color: #ea580c;
}

.admin-sidebar-btn i {
    font-size: 1.1rem;
}

.user-profile {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #3b82f6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
}

.user-info-container {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.user-info {
    flex: 1;
}

.user-name, .username {
    font-weight: 500;
    font-size: 1rem;
}

.user-role {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.6);
}

.logout-btn {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.9rem;
    text-decoration: none;
    transition: color 0.2s ease;
    display: block;
    margin-top: 4px;
}

.logout-btn:hover,
.logout-btn:focus {
    color: white;
    text-decoration: none;
}

.sidebar .logo span,
.sidebar .nav-section .nav-title,
.sidebar .nav-item > span:not(.nav-icon),
.sidebar .user-info-container {
    display: block;
    white-space: nowrap;
}

.main-content {
    flex: 1;
    margin-left: 280px;
    transition: margin-left 0.3s ease;
    position: relative;
}

/* App page - prevent scroll and make iframe fill the viewport */
#appPage .main-content {
    height: 100vh;
    overflow: hidden;
}

#appPage #shinyframe {
    width: 100%;
    height: 100vh !important;
    border: none;
}

.widgets-container {
    padding: 2rem;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.header-actions {
    display: flex;
    gap: 1rem;
    width: 100%;
}

.search-bar {
    position: relative;
    width: 100%;
}

.search-input {
    padding: 0.6rem 1rem 0.6rem 2.5rem;
    border-radius: var(--radius);
    border: 1px solid #e2e8f0;
    background-color: white;
    font-size: 0.9rem;
    width: 100%;
}

.search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    font-size: 1rem;
}

.category-section {
    margin-bottom: 2.5rem;
}

.section-header {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.25rem;
    margin-left: 5px;
    padding-bottom: 0.5rem;
    border-bottom: 3px solid #10b981;
}

.section-icon {
    color: #10b981;
    font-size: 1.2rem;
}

.section-title {
    font-size: 1.2rem !important;
    font-weight: 600;
    color: var(--text-color);
    margin: 0;
}

[data-section="code"] .section-header { border-bottom-color: #3b82f6; }
[data-section="code"] .section-icon { color: #3b82f6; }

[data-section="sql"] .section-header { border-bottom-color: #f43f5e; }
[data-section="sql"] .section-icon { color: #f43f5e; }

[data-section="scheduler"] .section-header { border-bottom-color: #10b981; }
[data-section="scheduler"] .section-icon { color: #10b981; }

[data-section="monitoring"] .section-header { border-bottom-color: #eab308; }
[data-section="monitoring"] .section-icon { color: #eab308; }

[data-section="other"] .section-header { border-bottom-color: #8b5cf6; }
[data-section="other"] .section-icon { color: #8b5cf6; }

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.category-filters {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 0.5rem 1rem;
    border: 1px solid #e2e8f0;
    background-color: white;
    border-radius: var(--radius);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-btn:hover {
    background-color: #f1f5f9;
}

.filter-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.category-title {
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.widgets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
    gap: 1.5rem;
}

.widget-card {
    background-color: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: visible;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    display: flex;
    flex-direction: column;
}

.widget-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.widget-header {
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid #f1f5f9;
    position: relative;
}

.widget-info-icon {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    color: var(--text-light);
    cursor: pointer;
    font-size: 0.9rem;
    transition: color 0.2s ease;
    z-index: 10;
}

.widget-info-icon:hover {
    color: var(--primary-color);
}

.widget-info-icon::after {
    content: attr(data-tooltip) "\A" "Cliquer pour voir sur Docker Hub";
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 8px;
    background-color: #000;
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    white-space: pre;
    text-align: left;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
    z-index: 1000;
}

.widget-info-icon:hover::after {
    opacity: 1;
    visibility: visible;
}

.widget-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.widget-icon img {
    max-width: 40px;
    max-height: 40px;
    object-fit: contain;
}

.data-science .widget-icon {
    color: var(--data-science-color);
}

.dbms .widget-icon {
    color: var(--dbms-color);
}

.scheduler .widget-icon {
    color: var(--scheduler-color);
}

.monitoring .widget-icon {
    color: var(--monitoring-color);
}

.other .widget-icon {
    color: #9333ea;
}

.widget-title-group {
    flex: 1;
}

.widget-title {
    font-weight: 600;
    font-size: 1rem;
    margin: 0;
    line-height: 1.2;
}

.widget-body {
    color: var(--text-light);
    font-size: 1rem;
    line-height: 1.5;
    margin: 10px 15px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.widget-description {
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.widget-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: auto;
    padding-bottom: 0.5rem;
}

.widget-actions a.action-button {
    text-decoration: none;
}

.action-button {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    border: none;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}

.launch-btn {
    background-color: var(--primary-color);
    color: white;
}

.launch-btn:hover,
.launch-btn:active,
.launch-btn:focus {
    background-color: #60a5fa;
    color: white;
}

.data-science .launch-btn, #appPage .launch-btn {
    background-color: var(--data-science-color);
    color: white;
}

.data-science .launch-btn:hover,
.data-science .launch-btn:active,
.data-science .launch-btn:focus,
#appPage .launch-btn:hover,
#appPage .launch-btn:active,
#appPage .launch-btn:focus {
    background-color: #2563eb;
    color: white;
}

.dbms .launch-btn {
    background-color: var(--dbms-color);
    color: white;
}

.dbms .launch-btn:hover,
.dbms .launch-btn:active,
.dbms .launch-btn:focus {
    background-color: #e11d48;
    color: white;
}

.scheduler .launch-btn {
    background-color: var(--scheduler-color);
    color: white;
}

.scheduler .launch-btn:hover,
.scheduler .launch-btn:active,
.scheduler .launch-btn:focus {
    background-color: #059669;
    color: white;
}

.monitoring .launch-btn {
    background-color: var(--monitoring-color);
    color: white;
}

.monitoring .launch-btn:hover,
.monitoring .launch-btn:active,
.monitoring .launch-btn:focus {
    background-color: #ca8a04;
    color: white;
}

.other .launch-btn {
    background-color: #9333ea;
    color: white;
}

.other .launch-btn:hover,
.other .launch-btn:active,
.other .launch-btn:focus {
    background-color: #7e22ce;
    color: white;
}

.docs-btn {
    background-color: #f1f5f9;
    color: var(--text-color);
}

.docs-btn:hover {
    background-color: #e2e8f0;
}

.btn-login {
    background-color: var(--primary-color);
    color: white;
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-top: 1rem;
}

.btn-login:hover {
    background-color: #2563eb;
}

#iframeinsert {
    width: 100%;
}

#iframeinsert iframe {
    width: 100%;
    height: 100%;
    min-height: 500px;
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.loading-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 500px;
    text-align: center;
}

.loading {
    display: none;
    background-color: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 3rem 0 2rem 0;
    text-align: center;
    min-width: 600px;
}

.loading-txt {
    font-size: 1.1rem;
    color: var(--text-color);
    margin-bottom: 1.5rem;
}

.loading-img {
    width: 50px;
    height: 50px;
    margin: 0 auto;
    border: 5px solid #f3f3f3;
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.retryingDetails {
    display: block;
    margin-top: 1rem;
    font-size: 0.9rem;
    color: var(--text-light);
}

.refreshButton {
    display: inline-block;
    margin-top: 1rem;
}

.alert {
    background-color: #fee2e2;
    color: #b91c1c;
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
}

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

.form-group label, .form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-color);
}

.form-label {
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    border-radius: var(--radius);
    border: 1px solid #e2e8f0;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-control.is-invalid {
    border-color: #dc2626;
}

.form-control.is-invalid ~ .invalid-feedback {
    display: block;
}

.invalid-feedback {
    display: none;
    color: #dc2626;
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.invalid-feedback.show {
    display: block;
}

.field-error {
    display: none;
    color: #dc2626;
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.form-control.is-invalid ~ .field-error {
    display: block;
}

.help-block {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-light);
}

.modal-content {
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.modal-header {
    background-color: var(--sidebar-bg);
    color: white;
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
    padding: 1rem 1.5rem;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: flex-start !important;
    border-bottom: 1px solid #f1f5f9;
    flex-wrap: nowrap !important;
}

.modal-header .modal-title {
    flex: 1 1 auto !important;
    text-align: left !important;
    margin: 0 !important;
    order: 1 !important;
}

.modal-header .close,
.modal-header button.close {
    flex: 0 0 auto !important;
    padding: 0 !important;
    margin: 0 0 0 1rem !important;
    font-size: 1.5rem !important;
    font-weight: 700 !important;
    color: white !important;
    opacity: 0.8;
    transition: opacity 0.2s;
    background: none !important;
    border: none !important;
    cursor: pointer;
    order: 2 !important;
    position: static !important;
    float: none !important;
}

.modal-header .close:hover,
.modal-header button.close:hover {
    opacity: 1;
    color: white !important;
}

.modal-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: white;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid #f1f5f9;
}

.modal-body .form-group {
    margin-bottom: 1.5rem;
}

.modal-body .form-label {
    margin-bottom: 0.5rem;
    font-size: 1rem;
    font-weight: 500;
}

.modal-body .form-control {
    padding: 0.75rem;
    border-radius: var(--radius);
    border: 1px solid #e2e8f0;
    font-size: 0.9rem;
    width: 100%;
}

.modal-body textarea.form-control {
    min-height: 120px;
    resize: vertical;
}

.modal-body .input-group {
    display: flex;
    width: 100%;
}

.modal-body .input-group-append {
    margin-left: 0.5rem;
}

.myApps {
    max-height: 300px;
    overflow-y: auto;
}

/* Footer of the inline "Mes applications" panel (my-apps-mode: inline). */
.myApps-footer {
    margin-top: 1rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.myApps .list-group {
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 0;
}

.myApps .list-group-item:first-child {
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
}

.myApps .list-group-item:last-child {
    border-bottom-left-radius: var(--radius);
    border-bottom-right-radius: var(--radius);
}

#appDetails {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background-color: #f8fafc;
    border-radius: var(--radius);
    font-size: 0.9rem;
}

.login-container {
    max-width: 500px;
    width: 100%;
    padding: 2rem;
    margin-top: -15vh;
}

.login-card {
    background-color: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 3rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

.login-card .logo {
    text-align: center;
    font-size: 1.8rem !important;
    font-weight: 700;
    margin-bottom: 2rem;
    color: var(--sidebar-bg);
    justify-content: center;
    flex-direction: column;
    gap: 0.5rem;
}

.login-card .logo-img {
    width: 60px;
    height: 60px;
}

.hidden {
    display: none;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-3 {
    margin-top: 1rem;
}

@media (max-width: 1024px) {
    /* Icon rail: wide enough for a .nav-item icon plus its padding. */
    .sidebar {
        width: 72px;
        padding: 1.5rem 0.25rem;
    }

    .user-avatar {
        display: none;
    }

    .logo {
        justify-content: center;
        margin-bottom: 1.5rem;
    }

    /* Same selectors as the global display:block rule, so specificity lets these win. */
    .sidebar .logo span,
    .sidebar .nav-section .nav-title,
    .sidebar .nav-item > span:not(.nav-icon),
    .sidebar .user-info-container .username {
        display: none;
    }

    .sidebar .logout-btn {
        text-align: center;
    }

    .nav-item {
        justify-content: center;
        padding: 0.75rem;
    }

    .nav-icon {
        margin-right: 0;
        font-size: 1.25rem;
    }

    .user-profile {
        justify-content: center;
    }

    .main-content {
        margin-left: 72px;
    }

    .sidebar-toggle {
        left: 72px;
    }
}

.mobile-topbar,
.mobile-backdrop,
.category-chips {
    display: none;
}

/* Dedicated phone layout: top bar + off-canvas drawer. Must follow the 1024px block,
   whose icon-rail rules it overrides at equal specificity. */
@media (max-width: 768px) {
    :root {
        --mobile-topbar-height: calc(56px + env(safe-area-inset-top));
    }

    /* ShinyProxy's setShinyFrameHeight() writes an inline body padding-top on every page. */
    body:not(.login-page) {
        display: block;
        padding-top: var(--mobile-topbar-height) !important;
    }

    body.mobile-nav-open {
        overflow: hidden;
    }

    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1002;
        height: var(--mobile-topbar-height);
        padding: env(safe-area-inset-top) calc(0.75rem + env(safe-area-inset-right)) 0 calc(0.25rem + env(safe-area-inset-left));
        background-color: var(--sidebar-bg);
        color: white;
    }

    .mobile-menu-btn {
        width: 44px;
        height: 44px;
        border: none;
        border-radius: var(--radius);
        background: transparent;
        color: white;
        font-size: 1.3rem;
    }

    .mobile-title,
    .mobile-title:hover,
    .mobile-title:focus {
        flex: 1;
        min-width: 0;
        color: white;
        font-size: 1.15rem;
        font-weight: 600;
        text-decoration: none;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-topbar .user-avatar {
        display: flex;
        flex: none;
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }

    .mobile-backdrop {
        display: block;
        position: fixed;
        top: var(--mobile-topbar-height);
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 999;
        background-color: rgba(0, 0, 0, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }

    body.mobile-nav-open .mobile-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar {
        top: var(--mobile-topbar-height);
        width: min(85vw, 300px);
        padding: 1.25rem 1rem calc(1rem + env(safe-area-inset-bottom));
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

    body.mobile-nav-open .sidebar {
        transform: none;
    }

    /* The desktop collapse preference must not hide the drawer. */
    .sidebar.sidebar-hidden {
        width: min(85vw, 300px) !important;
        padding: 1.25rem 1rem calc(1rem + env(safe-area-inset-bottom)) !important;
        overflow-y: auto !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }

    .sidebar-toggle,
    .sidebar .logo {
        display: none;
    }

    .sidebar .nav-section .nav-title,
    .sidebar .nav-item > span:not(.nav-icon),
    .sidebar .user-info-container .username {
        display: block;
    }

    .nav-item {
        justify-content: flex-start;
        min-height: 44px;
        padding: 0.75rem 1rem;
    }

    .nav-icon {
        margin-right: 0.75rem;
        font-size: 1.1rem;
    }

    .user-profile {
        justify-content: flex-start;
    }

    .sidebar .user-avatar {
        display: flex;
    }

    .sidebar .logout-btn {
        text-align: left;
        padding: 0.25rem 0;
    }

    .main-content {
        margin-left: 0;
    }

    .widgets-container {
        padding: 1rem;
    }

    .header {
        margin-bottom: 0.75rem;
    }

    /* 16px stops mobile browsers from zooming into the field on focus. */
    .search-input {
        font-size: 16px;
    }

    .category-chips {
        display: flex;
        gap: 0.5rem;
        margin: 0 -1rem 1.25rem;
        padding: 0 2rem 0 1rem;
        overflow-x: auto;
        scrollbar-width: none;
        /* Hints at hidden chips; the end padding keeps the last chip clear of the fade. */
        -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 2rem), transparent);
        mask-image: linear-gradient(to right, #000 calc(100% - 2rem), transparent);
    }

    .category-chips::-webkit-scrollbar {
        display: none;
    }

    .category-chip {
        flex: none;
        min-height: 36px;
        padding: 0.4rem 0.9rem;
        border: 1px solid #cbd5e1;
        border-radius: 999px;
        background-color: var(--card-bg);
        color: var(--text-color);
        font-size: 0.9rem;
        white-space: nowrap;
    }

    .category-chip.active {
        border-color: var(--sidebar-bg);
        background-color: var(--sidebar-bg);
        color: white;
    }

    .action-button {
        min-height: 44px;
    }

    /* 100dvh tracks the visible viewport as browser toolbars show and hide. */
    #appPage .main-content,
    #appPage #shinyframe {
        height: calc(100vh - var(--mobile-topbar-height)) !important;
        height: calc(100dvh - var(--mobile-topbar-height)) !important;
    }
}

@media (max-width: 768px) {
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .header-actions {
        width: 100%;
    }

    .modal-dialog {
        margin: 1rem;
        width: auto;
    }

    .modal-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .modal-footer button {
        margin-top: 0.5rem;
    }
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1050;
    overflow-x: hidden;
    overflow-y: auto;
    outline: 0;
}

.modal.show,
.modal.in {
    display: block !important;
}

.modal-open {
    overflow: hidden;
}

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1040;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-backdrop.in {
    opacity: 0.5;
}

.modal-dialog {
    position: relative;
    width: auto;
    margin: 10vh auto;
    max-width: 600px;
    pointer-events: none;
}

/* Hide all modal dialogs by default inside #modal */
#modal > .modal-dialog {
    display: none;
}

#appDetailsModal {
    margin: 5vh auto;
    max-width: 800px;
}

.modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    background-color: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    outline: 0;
    pointer-events: auto;
}

/* Admin page styles */
.admin-header {
    border-bottom-color: #ea580c;
    margin-bottom: 2rem;
}

.admin-header .section-icon {
    color: #ea580c;
}

.admin-section {
    background-color: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.admin-subtitle {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-color);
}

#admin .alert {
    margin-bottom: 1rem;
}

#admin .alert-warning {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}

#admin .alert-success {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

#admin .table {
    margin-bottom: 0;
}

#admin .table th {
    background-color: #f8fafc;
    font-weight: 600;
    font-size: 0.85rem !important;
    color: var(--text-color);
    border-bottom: 2px solid #e2e8f0;
}

#admin .table td {
    font-size: 0.85rem !important;
    vertical-align: middle;
}

#admin .dataTables_wrapper {
    font-size: 0.9rem;
}

#admin .dataTables_filter label,
#admin .dataTables_info {
    font-size: 0.9rem !important;
}

#admin .dataTables_filter input {
    font-size: 0.9rem !important;
}

#admin .btn {
    font-size: 0.9rem !important;
}

/* Column filters for admin table */
#admin .column-filters th {
    padding: 0.5rem;
    background-color: #f1f5f9;
}

#admin .column-search {
    width: 100%;
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    background-color: white;
}

#admin .column-search:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

#admin .column-search::placeholder {
    color: #94a3b8;
    font-size: 0.75rem;
}

/* Stop all button */
.stop-all-btn {
    background-color: #dc2626 !important;
    border-color: #dc2626 !important;
    color: white !important;
}

.stop-all-btn:hover {
    background-color: #b91c1c !important;
    border-color: #b91c1c !important;
}

/* Fix DataTables buttons container */
#admin .dt-buttons {
    position: relative;
    z-index: 1;
}

#admin .dataTables_wrapper .dt-buttons .btn {
    position: relative;
    z-index: 2;
}

/* Kept after the #admin rules above, which it overrides at equal specificity. */
@media (max-width: 768px) {
    #admin .dataTables_filter label {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        width: 100%;
    }

    /* 16px stops mobile browsers from zooming into the field on focus. */
    #admin .dataTables_filter input {
        flex: 1;
        min-width: 0;
        margin-left: 0;
        font-size: 16px !important;
    }
}

/* Action buttons styling */
#admin .btn-group,
#allApps .btn-group,
#appInstances .btn-group,
#myApps .btn-group {
    gap: 2px;
}

#admin .btn-stop,
#allApps .btn-stop,
#appInstances .btn-stop,
#myApps .btn-stop {
    background-color: #dc2626 !important;
    border-color: #dc2626 !important;
    color: white !important;
}

#admin .btn-stop:hover,
#allApps .btn-stop:hover,
#appInstances .btn-stop:hover,
#myApps .btn-stop:hover {
    background-color: #b91c1c !important;
    border-color: #b91c1c !important;
}

#admin .btn-restart,
#allApps .btn-restart,
#appInstances .btn-restart,
#myApps .btn-restart {
    background-color: #f97316 !important;
    border-color: #f97316 !important;
    color: white !important;
}

#admin .btn-restart:hover,
#allApps .btn-restart:hover,
#appInstances .btn-restart:hover,
#myApps .btn-restart:hover {
    background-color: #ea580c !important;
    border-color: #ea580c !important;
}

/* Inline "Mes applications": the running-app rows expose a green "Up"/uptime
   status badge (ShinyProxy formatStatus -> label-success). We hide that badge
   and instead reuse the green for the explicit "Ouvrir" button. The id-scoped
   selectors below beat the native `#myApps .btn-primary` specificity. */
#myApps .app-status,
#myApps .status-label {
    display: none;
}

#myApps .btn-group .app-open-btn,
#myApps .app-open-btn {
    background-color: #10b981 !important;
    border-color: #10b981 !important;
    color: white !important;
}

#myApps .btn-group .app-open-btn:hover,
#myApps .btn-group .app-open-btn:active,
#myApps .btn-group .app-open-btn:focus,
#myApps .app-open-btn:hover,
#myApps .app-open-btn:active,
#myApps .app-open-btn:focus {
    background-color: #059669 !important;
    border-color: #059669 !important;
    color: white !important;
}

/* Logo cliquable: forcer le blanc (fond sidebar sombre) car sur l'accueil le
   lien n'hérite pas du blanc de .sidebar comme sur app.html/admin.html. */
.logo .logo-link {
    color: white;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
}
.logo .logo-link:hover {
    color: white;
    opacity: 0.85;
}
