/* ============================================================================
   PR-SHARED-SERVICES.CSS
   Header + Rail desktop + Bottom-sheet mobile + tuiles services
   Partage entre tous les modules BURAPRINT (pr4, pr-photo, pr4-A3, pr-cadastre, etc.)
   La couleur de division est lue depuis la variable CSS --module-primary
   ============================================================================ */

:root {
    --module-primary: #0EA5E9;        /* defaut sky blue (pr4) */
    --module-primary-dark: #0284C7;
}

/* ============================================================================
   HEADER : bandeau couleur de division
   ============================================================================ */
.bp-main-header {
    background: linear-gradient(135deg, var(--module-primary) 0%, var(--module-primary-dark) 100%);
    padding: 12px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    transition: background 250ms ease-in-out;
}

.bp-header-content {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    min-height: 48px;
}

.bp-language-selector {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    display: flex;
    align-items: center;
}

.bp-current-flag {
    width: 38px;
    height: 28px;
    border-radius: 6px;
    object-fit: cover;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
    transition: transform 0.15s;
}

.bp-current-flag:hover {
    transform: scale(1.05);
}

.bp-logo-trigger {
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    padding: 4px 6px;
    border-radius: 12px;
    transition: background 0.15s;
    outline: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.bp-logo-trigger:hover {
    background: rgba(255, 255, 255, 0.12);
}

.bp-logo-trigger:active {
    transform: scale(0.98);
}

.bp-logo-trigger:focus-visible {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.7);
}

.bp-logo-main {
    max-height: 46px;
    max-width: 200px;
    object-fit: contain;
}

.bp-logo-title-row {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.bp-logo-title {
    color: #fff;
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.5px;
    line-height: 1;
}

.bp-logo-chev {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
    transition: transform 0.25s ease, background 0.2s ease;
}

.bp-logo-trigger:hover .bp-logo-chev {
    background: rgba(255, 255, 255, 0.35);
}

.bp-logo-trigger[aria-expanded="true"] .bp-logo-chev {
    transform: rotate(180deg);
    background: #fff;
    color: var(--module-primary);
    animation: none;
}

.bp-logo-chev.pulse-once {
    animation: bpChevPulseOnce 1.6s cubic-bezier(.36, .07, .19, .97) 1;
}

@keyframes bpChevPulseOnce {
    0%   { transform: translateY(0) scale(1); background: rgba(255, 255, 255, 0.22); }
    20%  { transform: translateY(4px) scale(1.15); background: #fff; color: var(--module-primary); }
    35%  { transform: translateY(-2px) scale(1.05); background: rgba(255, 255, 255, 0.5); }
    50%  { transform: translateY(4px) scale(1.15); background: #fff; color: var(--module-primary); }
    70%  { transform: translateY(0) scale(1); background: rgba(255, 255, 255, 0.22); color: #fff; }
    100% { transform: translateY(0) scale(1); background: rgba(255, 255, 255, 0.22); color: #fff; }
}

.bp-header-right-btns {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
}

.bp-header-info-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.bp-header-info-btn:hover {
    transform: scale(1.06);
}

.bp-header-info-btn:active {
    transform: scale(0.92);
}

.bp-header-info-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

/* ============================================================================
   SERVICES POPUP : bottom-sheet mobile + dropdown desktop (mobile fallback)
   ============================================================================ */
.bp-modules-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(13, 27, 42, 0.42);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 9998;
}

.bp-modules-popup {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    transform: none;
    width: 100%;
    max-width: 100%;
    max-height: 88vh;
    border-radius: 22px 22px 0 0;
    background: #fff;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.18);
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 9999;
    transform-origin: top center;
    animation: bpSheetSlideUp 200ms ease-out;
    transition: transform 0.25s cubic-bezier(.32, .72, 0, 1);
    padding-bottom: env(safe-area-inset-bottom);
}

/* Mobile : bottom-sheet emerge du bas + scale legere */
@keyframes bpSheetSlideUp {
    from { transform: translateY(100%) scale(0.96); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
}

/* Fermeture : 140ms ease-in (toujours plus rapide que l'ouverture) */
.bp-modules-popup.closing {
    animation: bpSheetSlideDown 140ms ease-in forwards;
}
@keyframes bpSheetSlideDown {
    from { transform: translateY(0) scale(1); opacity: 1; }
    to   { transform: translateY(20%) scale(0.96); opacity: 0; }
}

.bp-modules-popup-handle {
    width: 40px;
    height: 4px;
    margin: 8px auto 4px;
    background: #cbd5e1;
    border-radius: 999px;
    cursor: grab;
    flex-shrink: 0;
}

.bp-modules-popup-header {
    padding: 12px 56px 12px 18px;
    position: relative;
}

.bp-modules-popup-title {
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 18px;
    font-weight: 700;
    color: #0D1B2A;
    line-height: 1.1;
}

.bp-modules-popup-subtitle {
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 12px;
    font-weight: 400;
    color: #64748b;
    margin-top: 4px;
    line-height: 1.2;
}

.bp-modules-popup-subtitle strong {
    color: #0D1B2A;
    font-weight: 700;
}

.bp-modules-popup-close {
    position: absolute;
    right: 8px;
    top: 8px;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    transition: background 80ms linear, transform 50ms linear;
}
.bp-modules-popup-close:hover { background: #f4f7fa; }
.bp-modules-popup-close:active { background: #1260A8; color: #fff; transform: scale(0.94); }
.bp-modules-popup-close svg { width: 26px !important; height: 26px !important; }

.bp-modules-popup-close:hover {
    background: #e5e7eb;
}

.bp-modules-search-wrap {
    position: relative;
    padding: 4px 16px 12px;
}

.bp-modules-search-icon {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    pointer-events: none;
}

.bp-modules-search-input {
    width: 100%;
    height: 44px;
    padding: 0 12px 0 38px;
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 14px;
    color: #0D1B2A;
    background: #f4f7fa;
    border: 1px solid transparent;
    border-radius: 12px;
    outline: none;
    transition: border-color 80ms linear, background 80ms linear;
}

.bp-modules-search-input:focus {
    background: #fff;
    border-color: var(--module-primary);
    box-shadow: 0 0 0 3px rgba(18, 96, 168, 0.12);
}

/* Results count (recherche active) */
.bp-modules-results-count {
    display: none;
    padding: 4px 18px 6px;
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 11px;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.bp-modules-results-count.show {
    display: block;
}

/* Highlight match dans la recherche */
.bp-module-tile mark {
    background: #FEF3C7;
    color: #92400E;
    padding: 0 2px;
    border-radius: 3px;
    font-weight: 800;
}

/* "Aucun resultat" enrichi avec porte de sortie */
.bp-modules-no-results {
    display: none;
    padding: 32px 24px 24px;
    text-align: center;
    font-family: 'Calibri', Arial, sans-serif;
    color: #94a3b8;
    font-size: 13px;
}

.bp-modules-no-results.show {
    display: block;
}

.bp-modules-no-results-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #F4F7FA;
    color: #94a3b8;
    margin: 0 auto 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bp-modules-no-results-title {
    font-size: 14px;
    font-weight: 700;
    color: #0D1B2A;
    margin-bottom: 4px;
}

.bp-modules-no-results-text {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 14px;
    line-height: 1.4;
}

.bp-modules-no-results-text strong {
    color: #0D1B2A;
}

.bp-modules-no-results-suggest {
    display: inline-block;
    color: #1260A8;
    font-weight: 600;
    font-size: 13px;
    text-decoration: underline;
    cursor: pointer;
}

.bp-modules-no-results-suggest:hover {
    color: #0F4A82;
}

/* Banner hors-ligne */
.bp-modules-offline-banner {
    display: none;
    margin: 0 18px 10px;
    padding: 8px 12px;
    background: #FEF3C7;
    border: 1px solid #FBBF24;
    border-radius: 8px;
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 12px;
    color: #92400E;
    text-align: center;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.bp-modules-offline-banner.show {
    display: flex;
}

/* Service reseau grise hors-ligne */
.bp-module-tile-offline {
    opacity: 0.4 !important;
    cursor: not-allowed !important;
    pointer-events: none !important;
}

/* Skeleton loading (rare, lors d'un refresh dynamique) */
.bp-modules-skeleton {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 6px 12px 12px;
}

.bp-skeleton-tile {
    height: 64px;
    border-radius: 14px;
    background: linear-gradient(90deg, #f4f7fa 0%, #e2e8f0 50%, #f4f7fa 100%);
    background-size: 200% 100%;
    animation: bpSkeletonShimmer 1.5s ease-in-out infinite;
}

@keyframes bpSkeletonShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Focus clavier visible (accessibilite) */
.bp-module-tile:focus-visible {
    outline: 2px dashed #1260A8;
    outline-offset: 3px;
    background: #fff;
    z-index: 1;
}

.bp-modules-popup-close:focus-visible,
.bp-modules-search-input:focus-visible {
    outline: 2px dashed #1260A8;
    outline-offset: 2px;
}

/* Hints clavier en bas du popup (desktop uniquement) */
.bp-modules-popup-keyhints {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 4px 16px 6px;
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 10px;
    color: #cbd5e1;
    font-weight: 600;
    letter-spacing: 0.4px;
}

.bp-modules-popup-keyhints kbd {
    display: inline-block;
    background: #f4f7fa;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 10px;
    color: #475569;
    font-family: 'Calibri', Arial, sans-serif;
    margin-right: 4px;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.05);
}

@media (min-width: 768px) {
    .bp-modules-popup-keyhints {
        display: flex;
    }
}

.bp-modules-popup-list {
    padding: 0 12px 16px;
}

.bp-modules-section {
    padding: 6px 0 10px;
}

.bp-modules-section-title {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 4px 8px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.4px;
    color: #94a3b8;
}

.bp-modules-section-title::before {
    content: '';
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid #cbd5e1;
    flex-shrink: 0;
}

.bp-modules-section-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.bp-module-tile {
    position: relative;
    display: grid;
    grid-template-columns: 40px 1fr;
    grid-template-rows: auto auto;
    column-gap: 10px;
    row-gap: 2px;
    align-items: center;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid #f1f5f9;
    border-radius: 14px;
    text-decoration: none;
    transition: transform 80ms linear, box-shadow 80ms linear, border-color 80ms linear, background 80ms linear;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    min-height: 72px;
}

.bp-module-tile:hover {
    background: #f8fafc;
    transform: translateY(-2px);
    border-color: #e2e8f0;
}

/* Tap : bleu plein 50ms (feedback "j'ai tape") */
.bp-module-tile:active {
    transform: translateY(0);
    background: #DBEAFE !important;
    border-color: #1260A8 !important;
    transition: background 50ms linear, border-color 50ms linear;
}

.bp-module-tile-icon {
    grid-row: 1 / 3;
    grid-column: 1;
    align-self: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.bp-module-tile-name {
    grid-row: 1;
    grid-column: 2;
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 13px;
    font-weight: 700;
    color: #0D1B2A;
    line-height: 1.2;
    /* Wrap sur 2 lignes max avec ellipsis (les titres longs comme
       "Impression de documents A3" doivent tenir entierement) */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}

.bp-module-tile-desc {
    grid-row: 2;
    grid-column: 2;
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 11px;
    font-weight: 400;
    color: #475569;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
    margin-top: 2px;
}

/* Active : fond jaune + ombre noire signature + nom souligne */
.bp-module-tile-active {
    background: #FEF3C7;
    border-color: #FDE68A;
    box-shadow: 0 6px 20px rgba(13, 27, 42, 0.32), 0 2px 4px rgba(13, 27, 42, 0.18);
}

.bp-module-tile-active:hover {
    background: #FEF3C7;
    transform: translateY(-2px);
    border-color: #FBBF24;
}

.bp-module-tile-active .bp-module-tile-name {
    text-decoration: underline;
    text-decoration-color: #B45309;
    text-decoration-thickness: 2px;
    text-underline-offset: 2px;
}

.bp-module-tile-active .bp-module-tile-desc {
    color: #92400E;
}

/* Bientot : opacite 55% + desc remplacee par "Bientot" en italique */
.bp-module-tile-soon {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}

.bp-module-tile-soon .bp-module-tile-desc {
    color: #D4760A;
    font-style: italic;
    font-weight: 600;
}

/* Badge NEW (coin haut-droit) */
.bp-module-tile-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 9px;
    font-weight: 700;
    color: #fff;
    background: #DC2626;
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: 0.6px;
    line-height: 1;
}

/* Footer du popup : aide + version */
.bp-modules-popup-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 18px 14px;
    margin-top: 4px;
    border-top: 1px solid #f1f5f9;
    font-family: 'Calibri', Arial, sans-serif;
}

.bp-modules-popup-footer-help {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 6px 4px;
    color: #1260A8;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: color 80ms linear;
}

.bp-modules-popup-footer-help:hover {
    color: #0F4A82;
    text-decoration: underline;
}

.bp-modules-popup-footer-version {
    color: #cbd5e1;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* ============================================================================
   SERVICES RAIL (desktop only >=768px) - style Notion/Linear/VS Code
   ============================================================================ */
.bp-services-rail {
    display: none;
}

@media (min-width: 768px) {
    .bp-services-rail {
        display: flex;
        flex-direction: column;
        align-items: center;
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 60px;
        background: #fff;
        border-right: 1px solid #e5e7eb;
        padding: 14px 0 12px;
        z-index: 95;
        overflow-y: auto;
        overflow-x: visible;
        box-shadow: 1px 0 6px rgba(0, 0, 0, 0.04);
    }

    /* Decale toute l'app pour faire de la place au rail */
    body.bp-with-rail {
        padding-left: 60px;
    }

    /* Sur desktop : on cache le chevron du logo (le rail le remplace) */
    .bp-logo-chev {
        display: none;
    }

    .bp-logo-trigger {
        cursor: default;
    }

    .bp-logo-trigger:hover {
        background: transparent;
    }

    /* Popup desktop : dropdown emergeant du logo (transform-origin = top center) */
    .bp-modules-popup {
        position: fixed;
        bottom: auto;
        top: 78px;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: min(420px, calc(100vw - 24px));
        max-height: calc(100vh - 100px);
        border-radius: 18px;
        box-shadow: 0 16px 50px rgba(0, 0, 0, 0.18);
        transform-origin: top center;
        animation: bpModulesEmerge 200ms ease-out;
    }

    /* Emerge du bouton grille : scale 0.85 -> 1, opacity 0 -> 1 */
    @keyframes bpModulesEmerge {
        from { opacity: 0; transform: translateX(-50%) scale(0.85); }
        to   { opacity: 1; transform: translateX(-50%) scale(1); }
    }

    .bp-modules-popup.closing {
        animation: bpModulesCollapse 140ms ease-in forwards;
    }
    @keyframes bpModulesCollapse {
        from { opacity: 1; transform: translateX(-50%) scale(1); }
        to   { opacity: 0; transform: translateX(-50%) scale(0.9); }
    }

    .bp-modules-popup-handle { display: none; }
    .bp-modules-popup-header { padding: 16px 56px 12px 18px; }
}

.bp-rail-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 0;
}

.bp-rail-section + .bp-rail-section {
    border-top: 1px solid #f1f5f9;
}

.bp-rail-item {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    transition: transform 0.15s ease, box-shadow 0.18s ease;
    -webkit-tap-highlight-color: transparent;
}

.bp-rail-item-icon {
    width: 100%;
    height: 100%;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: inherit;
}

.bp-rail-item:hover {
    transform: translateX(2px);
}

.bp-rail-item:hover .bp-rail-item-icon {
    box-shadow: 0 3px 8px rgba(13, 27, 42, 0.15);
}

.bp-rail-item-active .bp-rail-item-icon {
    box-shadow: 0 4px 14px rgba(13, 27, 42, 0.32);
}

.bp-rail-item-active {
    transform: translateX(2px);
}

.bp-rail-item-active::before {
    content: '';
    position: absolute;
    left: -10px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 22px;
    background: #0D1B2A;
    border-radius: 0 3px 3px 0;
}

.bp-rail-item-soon .bp-rail-item-icon {
    opacity: 0.78;
}

.bp-rail-item-soon:hover .bp-rail-item-icon {
    opacity: 1;
}

.bp-rail-item-soon::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #D4760A;
    box-shadow: 0 0 0 2px #fff;
}

.bp-rail-item::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 14px);
    top: 50%;
    transform: translateY(-50%) translateX(-4px);
    background: #0D1B2A;
    color: #fff;
    padding: 6px 10px;
    border-radius: 8px;
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s, transform 0.15s;
    z-index: 110;
}

.bp-rail-item:hover::after {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

.bp-rail-footer {
    margin-top: auto;
    padding: 8px 0 4px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: #cbd5e1;
}

/* ============================================================================
   DYNAMIC TYPE : adaptation au zoom systeme utilisateur
   .bp-zoom-large  : >=150% -> grille 1 col, descriptions optionnelles
   .bp-zoom-xlarge : >=200% -> popup pleine page, mode liste verticale
   ============================================================================ */

.bp-zoom-large .bp-modules-section-grid {
    grid-template-columns: 1fr !important;
}

.bp-zoom-large .bp-module-tile-desc {
    /* descriptions optionnelles : reduites mais visibles */
    font-size: 11px;
}

.bp-zoom-xlarge .bp-modules-popup {
    /* Pleine page sur mobile et desktop */
    top: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    transform: none !important;
}

.bp-zoom-xlarge .bp-modules-section-grid {
    grid-template-columns: 1fr !important;
}

.bp-zoom-xlarge .bp-module-tile {
    min-height: 80px;
    padding: 14px 16px !important;
}

.bp-zoom-xlarge .bp-module-tile-name {
    font-size: 16px !important;
    white-space: normal;
}

.bp-zoom-xlarge .bp-module-tile-desc {
    font-size: 13px;
    white-space: normal;
}

.bp-zoom-xlarge .bp-modules-popup-handle { display: none; }
