/* ==========================================================================
   Tikvia — Surcouche applicative au design system ISITRAC
   Layout app (sidebar + topbar + contenu), adaptations spécifiques.
   ========================================================================== */

html, body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

/* --------------------------------------------------------------------------
   App shell : sidebar à gauche, zone content à droite
   -------------------------------------------------------------------------- */
.app-shell {
    display: flex;
    min-height: 100vh;
    background-color: var(--color-greyscale-light-white);
}

.app-sidebar {
    width: 260px;
    background-color: var(--color-greyscale-white);
    border-right: 1px solid var(--color-greyscale-dark-white);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    flex-shrink: 0;
    /* Nav longue (Home + Portail + Agent + Admin = 15+ liens) : sans overflow
       auto, la section Admin (en bas) devient inatteignable dès que la hauteur
       du contenu dépasse 100vh — typiquement sur téléphone en mode portrait. */
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.app-sidebar-brand {
    display: flex;
    flex-direction: column;
    padding: 20px 24px;
    border-bottom: 1px solid var(--color-greyscale-dark-white);
    line-height: 1.15;
}

.app-sidebar-brand .name {
    font-family: var(--font-family-primary);
    font-size: 22px;
    font-weight: 700;
    color: var(--color-primary-110);
    letter-spacing: 0.5px;
}

.app-sidebar-brand .tagline {
    font-size: var(--body-p3-size);
    color: var(--color-text-tertiary);
    margin-top: 2px;
}

.app-sidebar-section {
    padding: 12px 16px 6px;
    font-size: var(--body-p3-size);
    color: var(--color-text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.app-sidebar-nav {
    list-style: none;
    margin: 0;
    padding: 4px 0;
}

.app-sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 24px;
    color: var(--color-greyscale-dark-grey);
    font-size: var(--body-p2-size);
    text-decoration: none;
    transition: background-color 0.15s ease, color 0.15s ease;
    border-left: 3px solid transparent;
}

.app-sidebar-link:hover {
    background-color: var(--color-greyscale-light-white);
    color: var(--color-text-primary);
    text-decoration: none;
}

.app-sidebar-link.active {
    background-color: var(--color-primary-10);
    color: var(--color-primary-110);
    border-left-color: var(--color-primary-100);
    font-weight: 600;
}

.app-sidebar-link .ico {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: currentColor;
}

.app-sidebar-footer {
    margin-top: auto;
    padding: 16px 24px;
    border-top: 1px solid var(--color-greyscale-dark-white);
    font-size: var(--body-p3-size);
    color: var(--color-text-tertiary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.app-sidebar-legal {
    flex-basis: 100%;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    font-size: var(--body-p3-size);
}

.app-sidebar-legal a {
    color: var(--color-text-tertiary);
    text-decoration: none;
}

.app-sidebar-legal a:hover,
.app-sidebar-legal a:focus-visible {
    color: var(--color-text-primary);
    text-decoration: underline;
}

.legal-page h2 {
    margin-top: 32px;
}

.legal-page table.grid {
    margin: 12px 0;
}

/* --------------------------------------------------------------------------
   Topbar (à droite de la sidebar, au-dessus du contenu)
   -------------------------------------------------------------------------- */
.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 28px;
    background-color: var(--color-greyscale-white);
    border-bottom: 1px solid var(--color-greyscale-dark-white);
    position: sticky;
    top: 0;
    z-index: 10;
}

.app-topbar-title {
    font-family: var(--font-family-primary);
    font-size: var(--heading-h3-size);
    color: var(--color-text-primary);
    font-weight: 600;
    margin: 0;
}

.app-topbar-spacer {
    flex: 1;
}

.app-topbar-search {
    position: relative;
    min-width: 260px;
}

.app-content {
    padding: 28px;
    flex: 1;
}

/* --------------------------------------------------------------------------
   Language switcher
   -------------------------------------------------------------------------- */
.lang-switch {
    display: inline-flex;
    background: var(--color-greyscale-light-white);
    border: 1px solid var(--color-greyscale-dark-white);
    border-radius: var(--radius-button);
    padding: 2px;
    gap: 2px;
}

.lang-switch a {
    padding: 4px 10px;
    font-size: var(--body-p3-size);
    font-weight: 600;
    color: var(--color-text-tertiary);
    text-decoration: none;
    border-radius: 8px;
    transition: background 0.15s ease, color 0.15s ease;
}

.lang-switch a:hover {
    color: var(--color-text-primary);
    text-decoration: none;
}

.lang-switch a.active {
    background: var(--color-primary-100);
    color: var(--color-greyscale-white);
}

/* --------------------------------------------------------------------------
   Page headers & tiles
   -------------------------------------------------------------------------- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.page-header h1 {
    margin: 0;
    font-size: var(--heading-h2-size);
    font-weight: 600;
    color: var(--color-text-primary);
}

.page-header .subtitle {
    color: var(--color-text-tertiary);
    font-size: var(--body-p2-size);
    margin-top: 4px;
}

.page-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background-color: var(--color-greyscale-white);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-global);
    padding: 18px 20px;
}

.stat-card .label {
    display: block;
    font-size: var(--body-p3-size);
    color: var(--color-text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0;
    background: transparent;
    border-radius: 0;
    margin-bottom: 6px;
}

.stat-card .value {
    font-size: 28px;
    font-weight: 700;
    color: var(--color-text-primary);
}

.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

.tile {
    display: block;
    background: var(--color-greyscale-white);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-global);
    padding: 20px;
    color: inherit;
    text-decoration: none;
    border: 1px solid transparent;
    transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.tile:hover {
    border-color: var(--color-primary-60);
    transform: translateY(-1px);
    text-decoration: none;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
}

.tile h3 {
    margin: 0 0 6px 0;
    font-size: var(--heading-h4-size);
    color: var(--color-primary-110);
    font-weight: 600;
}

.tile p {
    margin: 0;
    color: var(--color-text-tertiary);
    font-size: var(--body-p2-size);
}

/* --------------------------------------------------------------------------
   Toolbar (filtres + recherche au-dessus d'une table)
   -------------------------------------------------------------------------- */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.toolbar .toolbar-left {
    display: flex;
    gap: 12px;
    flex: 1;
    min-width: 220px;
}

.toolbar .toolbar-right {
    display: flex;
    gap: 8px;
    align-items: center;
}

.grid-wrapper {
    background: var(--color-greyscale-white);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-global);
    overflow: hidden;
}

.grid-wrapper .grid {
    border: none;
    border-radius: 0;
    box-shadow: none;
}

.grid-actions {
    display: inline-flex;
    gap: 6px;
}

.grid-action-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px 6px;
    color: var(--color-text-tertiary);
    border-radius: 6px;
    font-size: var(--body-p2-size);
}

.grid-action-btn:hover {
    background: var(--color-greyscale-light-white);
    color: var(--color-primary-100);
}

.grid-action-btn.delete:hover {
    color: var(--color-error-110);
}

/* --------------------------------------------------------------------------
   Empty state
   -------------------------------------------------------------------------- */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--color-text-tertiary);
}

.empty-state h3 {
    margin: 0 0 8px;
    color: var(--color-text-secondary);
    font-weight: 600;
}

.empty-state p {
    margin: 0 0 16px;
    font-size: var(--body-p2-size);
}

/* --------------------------------------------------------------------------
   Drawer / modal form
   -------------------------------------------------------------------------- */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(48, 48, 58, 0.3);
    z-index: 50;
    display: flex;
    justify-content: flex-end;
}

.drawer {
    width: 480px;
    max-width: 100vw;
    height: 100%;
    background: var(--color-greyscale-white);
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    animation: drawer-in 0.2s ease-out;
}

@keyframes drawer-in {
    from { transform: translateX(100%); }
    to   { transform: translateX(0); }
}

.drawer-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--color-greyscale-dark-white);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.drawer-header h2 {
    margin: 0;
    font-size: var(--heading-h3-size);
    font-weight: 600;
}

.drawer-close {
    background: transparent;
    border: none;
    color: var(--color-text-tertiary);
    cursor: pointer;
    font-size: 22px;
    padding: 4px 8px;
    border-radius: 8px;
}

.drawer-close:hover {
    background: var(--color-greyscale-light-white);
    color: var(--color-text-primary);
}

.drawer-body {
    padding: 24px;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.drawer-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--color-greyscale-dark-white);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* --------------------------------------------------------------------------
   Burger button (visible en mobile uniquement)
   -------------------------------------------------------------------------- */
.app-topbar-burger {
    display: none;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 6px;
    color: var(--color-text-primary);
    cursor: pointer;
    margin-right: 4px;
    position: relative;
}

.app-topbar-burger:hover {
    background: var(--color-greyscale-light-white);
}

.app-topbar-burger:focus-visible {
    border-color: var(--color-primary-100);
    outline: none;
}

/* Pastille rouge style Outlook posée en haut-à-droite du burger : quand le drawer
   est fermé sur mobile, l'utilisateur voit quand même qu'il y a des mouvements.
   Additionne les mouvements portail + agent. */
.burger-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background: #EF4444;
    color: white;
    border: 2px solid var(--color-greyscale-white, white);
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    line-height: 12px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    pointer-events: none;
}

/* Backdrop mobile : invisible sauf quand la sidebar est ouverte */
.app-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(48, 48, 58, 0.45);
    border: none;
    padding: 0;
    cursor: pointer;
    z-index: 40;
    animation: isi-fade 0.2s ease-out;
}

@keyframes isi-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Le rôle de l'utilisateur est visible sauf sur mobile (gain de place) */
.app-topbar-role {
    margin-right: 12px;
}

.app-topbar-user {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.15;
    margin-right: 12px;
}

/* Bloc utilisateur + déconnexion visible uniquement dans le drawer en mobile.
   Caché en desktop (le drawer est également caché par la sidebar classique). */
.app-sidebar-user-mobile { display: none; }

.app-topbar-user-name {
    font-weight: 600;
    color: var(--color-text-primary);
    font-size: 14px;
}

.app-topbar-user-sub {
    font-size: 12px;
    color: var(--color-text-tertiary);
}

.app-topbar-searchbtn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(0,0,0,0.04);
    border: 1px solid var(--color-greyscale-dark-white, #E5E7EB);
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    color: var(--color-text-tertiary);
    font-size: 13px;
    margin-right: 12px;
}
.app-topbar-searchbtn:hover { background: rgba(0,0,0,0.07); }
.app-topbar-searchbtn kbd {
    background: white;
    border: 1px solid var(--color-greyscale-dark-white, #E5E7EB);
    border-radius: 3px;
    padding: 1px 6px;
    font-size: 11px;
    font-family: inherit;
    margin-left: 2px;
}
@media (max-width: 720px) {
    .app-topbar-searchbtn-txt { display: none; }
}

.global-search-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 2000;
    display: flex; justify-content: center; align-items: flex-start;
    padding-top: 12vh;
}
.global-search-panel {
    background: white;
    border-radius: 10px;
    width: min(640px, 92vw);
    max-height: 70vh;
    overflow: auto;
    padding: 0;
    box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.global-search-input {
    width: 100%;
    border: none;
    outline: none;
    padding: 18px 20px;
    font-size: 16px;
    border-bottom: 1px solid var(--color-greyscale-dark-white, #E5E7EB);
    box-sizing: border-box;
}
.global-search-section {
    padding: 8px 16px 4px;
    font-size: 11px;
    color: var(--color-text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    background: #FAFBFC;
}
.global-search-item {
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--color-greyscale-dark-white, #F3F4F6);
    font-size: 14px;
}
.global-search-item:hover { background: var(--color-primary-20, #EEF3FF); }
.global-search-hint {
    padding: 18px 20px;
    text-align: center;
    color: var(--color-text-tertiary);
    font-size: 14px;
}

/* Badge style Outlook : rond rouge avec nombre, aligné à droite de l'item de nav. */
.nav-badge-red {
    background: #EF4444;
    color: white;
    border-radius: 999px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    font-size: 11px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    margin-left: auto;
    box-shadow: 0 0 0 2px var(--app-sidebar-bg, white);
    animation: nav-badge-pulse 1.8s ease-in-out;
}

@keyframes nav-badge-pulse {
    0%   { transform: scale(1); }
    30%  { transform: scale(1.15); }
    60%  { transform: scale(1); }
}

/* --------------------------------------------------------------------------
   Responsive — Tablette : sidebar compactée en icônes
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
    .app-sidebar {
        width: 72px;
    }

    .app-sidebar-brand .tagline,
    .app-sidebar-section,
    .app-sidebar-link span.txt,
    .app-sidebar-footer {
        display: none;
    }

    .app-sidebar-link {
        justify-content: center;
        padding: 12px;
    }

    .app-content { padding: 20px; }
    .app-topbar { padding: 12px 20px; }
}

/* --------------------------------------------------------------------------
   Responsive — Mobile : sidebar off-canvas (drawer) + burger button
   -------------------------------------------------------------------------- */
@media (max-width: 720px) {
    .app-topbar-burger {
        display: inline-flex;
        flex-shrink: 0;
        padding: 8px;
        background: var(--color-primary-10, #EDF2FF);
        border: 1px solid var(--color-primary-100, #487AFF);
        color: var(--color-primary-110, #1454FF);
    }
    .app-topbar-role { display: none; }
    .app-topbar-user-sub { display: none; }
    /* On dégage la topbar sur mobile : le nom d'utilisateur et le bouton se-déconnecter
       partent dans le footer du drawer (via .app-topbar-mobile-hide). Il ne reste que :
       [burger] [titre] [recherche]. Ainsi on garantit que le burger est toujours visible. */
    .app-topbar-mobile-hide { display: none; }
    .app-topbar-spacer { min-width: 0; }
    .app-topbar-searchbtn { margin-right: 0; }

    .app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 260px;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.22s ease-out;
        z-index: 50;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
        overflow-y: auto;
    }

    /* quand ouverte, on rétablit toute la nav (texte + sections) */
    .app-shell--nav-open .app-sidebar {
        transform: translateX(0);
    }

    .app-shell--nav-open .app-sidebar-brand .tagline,
    .app-shell--nav-open .app-sidebar-section,
    .app-shell--nav-open .app-sidebar-link span.txt,
    .app-shell--nav-open .app-sidebar-footer {
        display: revert;
    }

    .app-shell--nav-open .app-sidebar-link {
        justify-content: flex-start;
        padding: 10px 24px;
    }

    .app-shell--nav-open .app-sidebar-backdrop {
        display: block;
    }

    /* Bloc utilisateur + déconnexion cloné dans le drawer mobile.
       On retire margin-top:auto du footer en mobile pour que user-mobile soit
       collé au footer en bas du drawer. */
    .app-sidebar-user-mobile {
        display: block;
        padding: 16px 20px;
        border-top: 1px solid var(--color-greyscale-dark-white);
        margin-top: auto;
    }
    .app-sidebar-footer { margin-top: 0; }
    .app-sidebar-user-mobile .name {
        display: block;
        font-weight: 600;
        color: var(--color-text-primary);
        margin-bottom: 4px;
    }
    .app-sidebar-user-mobile .role {
        display: block;
        color: var(--color-text-tertiary);
        font-size: 12px;
        margin-bottom: 10px;
    }
    .app-sidebar-user-mobile .btn { width: 100%; }

    .app-content { padding: 16px 14px; }
    .app-topbar { padding: 10px 14px; gap: 10px; }
    .app-topbar-title {
        font-size: var(--heading-h4-size);
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .drawer { width: 100%; }

    /* Les stats/tiles : une colonne */
    .stats-row,
    .tile-grid {
        grid-template-columns: 1fr;
    }

    /* Page header : empilé, les actions passent sous le titre */
    .page-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .page-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .page-actions .btn {
        flex: 1 1 auto;
    }

    /* Toolbar filtres : full width, empilée */
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar .toolbar-left,
    .toolbar .toolbar-right {
        width: 100%;
        flex-wrap: wrap;
    }
}

/* --------------------------------------------------------------------------
   Tableaux / grilles — scroll horizontal sur écran étroit
   Ajouter la classe .grid-scroll au wrapper pour l'activer.
   -------------------------------------------------------------------------- */
.grid-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 900px) {
    .grid-wrapper { overflow-x: auto; }
    .grid-wrapper .grid { min-width: 640px; }

    /* Les tables .grid qui ne sont PAS dans un .grid-wrapper
       (dashboards, login, détail ticket) gagnent un scroll sur leur parent direct. */
    *:has(> table.grid) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table.grid { min-width: 520px; }
}

/* Zone drop pour pièces jointes : feedback visuel pendant un drag. Le drop est géré
   en JS par wireDropZone (wwwroot/js/attachments.js) ; on ajoute .drop-over pendant
   dragenter et on la retire sur dragleave/drop. */
.attachments-drop {
    border: 1px dashed var(--color-greyscale-mid, #C6CED5);
    border-radius: 8px;
    padding: 12px;
    transition: background 120ms ease, border-color 120ms ease;
}

.attachments-drop.drop-over {
    border-color: var(--color-primary-100, #405FD3);
    background: var(--color-primary-10, #F1F5FF);
}
