﻿/* Hygiène tactile */
:where(a, button, summary, label, [role="button"]) {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

:where(a, button, summary, .row-action, .link-button, .pager__link,
       .sidebar-link, .kebab__item, .clickable-row):active {
    opacity: 0.75;
}

/* Composants et points de bascule */

/* En-tête mince (mobile uniquement) */
.topbar {
    display: none;
    align-items: center;
    gap: 0.6rem;
    min-height: var(--topbar-h);
    padding: 0 16px;
    padding-top: env(safe-area-inset-top);
    background: var(--night);
    color: var(--night-text-strong);
}

.topbar__title {
    font-weight: 600;
    letter-spacing: 0.2px;
}

/* Barre d'onglets du bas */
.tabbar {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    background: var(--night);
    border-top: 1px solid var(--night-line);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.tabbar__link {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: var(--tabbar-h);
    padding: 6px 2px;
    color: var(--night-text);
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 500;
    line-height: 1.2;
    text-align: center;
    -webkit-user-select: none;
    user-select: none;
    transition: color var(--ease);
}

    .tabbar__link .icon {
        width: 22px;
        height: 22px;
    }

    .tabbar__label {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .tabbar__link.is-active {
        color: #fff;
        box-shadow: inset 0 3px 0 var(--brand-light);
    }

/* Le bouton central « Nouveau » */
.tabbar__link--primary .icon {
    width: 46px;
    height: 46px;
    padding: 11px;
    border-radius: var(--r-pill);
    background: var(--brand);
    color: #fff;
    box-shadow: var(--shadow-brand);
    margin-top: -18px;
    margin-bottom: -4px;
    transition: background var(--ease);
}

.tabbar__link--primary.is-active {
    box-shadow: none;
}

    .tabbar__link--primary.is-active .icon {
        background: var(--brand-dark);
    }

/* Tiroir « Plus » */
.more-sheet {
    flex: 1 1 0;
    display: flex;
}

    .more-sheet > summary {
        list-style: none;
        cursor: pointer;
    }

        .more-sheet > summary::-webkit-details-marker {
            display: none;
        }

    .more-sheet[open] > summary {
        color: #fff;
    }

.more-sheet__panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--line);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    box-shadow: var(--shadow-lg);
    padding: 0.5rem 0 0.75rem;
    max-height: 70vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.more-sheet__list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.more-sheet__item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    min-height: var(--tap);
    padding: 0.7rem 1.1rem;
    border: 0;
    background: none;
    color: var(--ink-soft);
    font: inherit;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

    .more-sheet__item .icon {
        width: 20px;
        height: 20px;
        color: var(--ink-faint);
    }

    .more-sheet__item.is-active {
        color: var(--brand);
        font-weight: 600;
        background: var(--brand-tint);
    }

        .more-sheet__item.is-active .icon {
            color: var(--brand);
        }

    .more-sheet__item--logout {
        color: var(--danger);
    }

        .more-sheet__item--logout .icon {
            color: var(--danger);
        }

.more-sheet__user {
    padding: 0.75rem 1.1rem 0.5rem;
    margin-top: 0.35rem;
    border-top: 1px solid var(--line-soft);
}

.more-sheet__name {
    font-weight: 600;
    color: var(--ink);
}

.more-sheet__role {
    font-size: 0.8rem;
    color: var(--ink-muted);
}


/* Écrans tactiles : agrandir les cibles */
@media (pointer: coarse) {
    /* Le zoom automatique d'iOS */
    input,
    select,
    textarea {
        font-size: 16px;
    }

    /* Cibles de 44px */
    .row-action,
    .link-button,
    .link-button--neutral,
    .button-primary,
    .button-danger,
    .button-link,
    .pager__size,
    .pager__link,
    .file-field__button,
    .segmented-picker__option,
    .state-picker__pill,
    .kebab__item,
    .search-bar button,
    .form-actions button {
        min-height: var(--tap);
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .equipment-check {
        min-height: var(--tap);
    }

    .kebab__button {
        width: var(--tap);
        height: var(--tap);
    }

    .kebab__item {
        justify-content: flex-start;
    }

    .state-picker__pill {
        padding: 0 14px;
        font-size: 0.82rem;
    }

    .field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
    .field select,
    .search-bar input[type="search"],
    .search-bar select {
        min-height: var(--tap);
    }

    /* Cases à cocher */
    .field input[type="checkbox"],
    .import-check {
        width: 24px;
        height: 24px;
    }

    .import-preview label,
    .field label:has(input[type="checkbox"]) {
        min-height: var(--tap);
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
    }
}

/* Coquille mobile : en-tête mince + barre d'onglets en bas */
@media (max-width: 900px) {
    .sidebar {
        display: none;
    }

    .topbar {
        display: flex;
    }

    .tabbar {
        display: flex;
    }

    .app-main main {
        padding: 20px 18px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 1.5rem);
    }

    .app-shell {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    .app-footer {
        padding-bottom: 0.5rem;
    }
}


/* Téléphone */
@media (max-width: 640px) {
    body {
        font-size: 14.5px;
    }

    .page-title {
        font-size: 1.35rem;
        margin-bottom: 1rem;
    }

    /* Tableau de bord */
    .stat-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.6rem;
        margin-bottom: 1.25rem;
    }

    .stat-card {
        padding: 0.8rem 0.85rem;
        border-radius: var(--r-lg);
        gap: 0.1rem;
    }

    .stat-card__icon {
        width: 30px;
        height: 30px;
        margin-bottom: 0.4rem;
    }

        .stat-card__icon svg {
            width: 16px;
            height: 16px;
        }

    .stat-card__value {
        font-size: 1.6rem;
    }

    .stat-card__label {
        font-size: 0.75rem;
    }

    /* Les trois raccourcis */
    .addshome-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.6rem;
        margin-bottom: 1.25rem;
    }

    .addshome-grid .dashboard-cta {
        margin: 0;
    }

        .addshome-grid .dashboard-cta:first-child {
            grid-column: 1 / -1;
        }

    .addshome-grid .button-primary {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: var(--tap);
        width: 100%;
        padding: 8px 10px;
        font-size: 12.5px;
        text-align: center;
    }

    .section-title {
        font-size: 1.05rem;
        margin: 1.5rem 0 0.75rem;
    }

    /* Barre de filtres */
    .search-bar {
        flex-wrap: wrap;
        column-gap: 0.5rem;
        row-gap: 0.55rem;
        margin-bottom: 1rem;
    }

    .search-bar__field,
    .search-bar__field--sort {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
        flex: 1 1 calc(50% - 0.5rem);
        min-width: 0;
    }

        .search-bar__field--wide {
            flex: 1 1 100%;
        }

        .search-bar__caption {
            display: block;
            color: var(--ink-soft);
            font-size: 0.75rem;
            font-weight: 600;
        }

        .search-bar__field input[type="search"],
        .search-bar__field select {
            flex: 0 0 auto;
            width: 100%;
        }

    .search-bar__legend {
        display: block;
        flex: 1 1 100%;
        margin: 0;
        color: var(--ink-soft);
        font-size: 0.8rem;
        font-weight: 700;
    }

    /* Barre de filtres repliée en trois icônes */
    .filter-tool__toggle {
        display: block;
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        padding: 0;
        border: 0;
        overflow: hidden;
        clip-path: inset(50%);
    }

    .filter-tool__button {
        order: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
        width: var(--tap);
        height: var(--tap);
        border: 1px solid var(--line);
        border-radius: var(--r-sm);
        background: var(--surface);
        color: var(--ink-soft);
        font-size: 1.25rem;
        cursor: pointer;
    }

        .filter-tool__button.is-active {
            border-color: var(--brand);
            background: var(--brand-tint);
            color: var(--brand);
        }

        .filter-tool__toggle:focus-visible + .filter-tool__button {
            outline: 2px solid var(--brand);
            outline-offset: 2px;
        }

        .filter-tool__toggle:checked + .filter-tool__button {
            border-color: var(--ink-soft);
            color: var(--ink);
        }

    .filter-tool__panel {
        order: 2;
        display: none;
        flex: 1 1 100%;
        flex-wrap: wrap;
        gap: 0.4rem 0.5rem;
    }

    .filter-tool:has(.filter-tool__toggle:checked) .filter-tool__panel {
        display: flex;
    }

        .search-bar button,
        .search-bar .button-link {
            order: 3;
            flex: 1 1 0;
        }

        .search-bar:has(.filter-tool):not(:has(.filter-tool__toggle:checked)) button,
        .search-bar:has(.filter-tool):not(:has(.filter-tool__toggle:checked)) .button-link {
            display: none;
        }

    /* Pagination */
    .pager {
        flex-direction: column;
        align-items: stretch;
        gap: 0.85rem;
    }

    .pager__info {
        text-align: center;
    }

    .pager__sizes {
        justify-content: center;
    }

    .pager__pages {
        margin-left: 0;
        justify-content: center;
        flex-wrap: wrap;
    }

    /* Tableaux : comportement par défaut */
    .fleet-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    /* Grandes listes en cartes */
    .fleet-table.fleet-table--cards {
        display: block;
        border: 0;
        background: none;
        box-shadow: none;
        overflow: visible;
        white-space: normal;
    }

        .fleet-table--cards thead {
            display: none;
        }

        .fleet-table--cards tbody,
        .fleet-table--cards tr,
        .fleet-table--cards td {
            display: block;
        }

        .fleet-table--cards tr {
            display: flex;
            flex-direction: column;
            background: var(--surface);
            border: 1px solid var(--line);
            border-radius: var(--r-lg);
            box-shadow: var(--shadow-sm);
            padding: 0.85rem 1rem;
            margin-bottom: 0.75rem;
        }

        .fleet-table--cards td {
            display: flex;
            align-items: baseline;
            justify-content: space-between;
            gap: 1rem;
            padding: 0.3rem 0;
            border: 0;
            text-align: right;
        }

            .fleet-table--cards td::before {
                content: attr(data-label);
                flex: 0 0 auto;
                text-align: left;
                color: var(--ink-faint);
                font-size: 0.72rem;
                font-weight: 600;
                text-transform: uppercase;
                letter-spacing: 0.4px;
            }

        /* La cellule TITRE */
        .fleet-table--cards td[data-card="title"] {
            order: -1;
            display: block;
            text-align: left;
            font-size: 1.05rem;
            font-weight: 600;
            color: var(--ink);
            padding-bottom: 0.5rem;
        }

        /* La cellule ACTIONS */
        .fleet-table--cards td[data-card="actions"] {
            order: 1;
            justify-content: flex-end;
            gap: 0.5rem;
            border-top: 1px solid var(--line-soft);
            margin-top: 0.5rem;
            padding-top: 0.6rem;
        }

        .fleet-table--cards td[data-card="title"]::before,
        .fleet-table--cards td[data-card="actions"]::before {
            content: none;
        }

        .fleet-table--cards tr.clickable-row:active {
            border-color: var(--brand);
            background: var(--brand-tint);
        }

    /* Cartes repliables */
    .fleet-table--collapsible tr {
        position: relative;
    }

    .fleet-table--collapsible .row-toggle__button {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: 0.35rem;
        right: 0.35rem;
        width: var(--tap);
        height: var(--tap);
        border-radius: var(--r-md);
        color: var(--ink-muted);
        font-size: 1.15rem;
        cursor: pointer;
    }

        .fleet-table--collapsible .row-toggle__button .icon {
            transition: transform var(--ease);
        }

        .fleet-table--collapsible tr:has(.row-toggle:checked) .row-toggle__button .icon {
            transform: rotate(180deg);
        }

    .fleet-table--collapsible tr:not(:has(.row-toggle:checked)) td:not([data-card]) {
        display: none;
    }

    .fleet-table--collapsible td[data-card="title"] {
        padding-right: var(--tap);
    }

    /* La cellule SOUS-TITRE */
    .fleet-table--cards td[data-card="subtitle"] {
        order: -1;
        display: block;
        text-align: left;
        padding-top: 0;
        color: var(--ink-muted);
        font-size: 0.85rem;
    }

        .fleet-table--cards td[data-card="subtitle"]::before {
            content: none;
        }

    .form-card,
    .detail-header {
        padding: 1.1rem;
        border-radius: var(--r-lg);
    }

    .detail-header__top {
        flex-direction: column;
    }

    .form-actions,
    .detail-actions {
        flex-wrap: wrap;
    }

        .detail-actions > form,
        .detail-actions > .button-link,
        .detail-actions > .button-primary,
        .form-actions > form,
        .form-actions > button {
            flex: 1 1 auto;
        }

            .detail-actions > form > button,
            .form-actions > form > button {
                width: 100%;
            }

    /* Fiches de détail */
    .detail-meta-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem 1rem;
    }

    .sign-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Galerie de photos */
    .photo-gallery {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }

    .photo-gallery__thumb {
        width: 100%;
        height: auto;
        aspect-ratio: 1;
    }

    /* Progression : la barre remplace les pastilles */
    .stepper {
        display: none;
    }

    .stepper-progress,
    .stepper-legend {
        display: block;
    }

    .stepper-head {
        margin-bottom: 1.1rem;
    }

    /* Le tableau des 20 zones (Condition/Create) */
    .fleet-table.zone-table {
        display: block;
        overflow: visible;
        white-space: normal;
    }

        .zone-table thead {
            display: none;
        }

        .zone-table tbody,
        .zone-table tr,
        .zone-table td {
            display: block;
        }

        .zone-table tr {
            padding: 0.9rem 1.1rem;
            border-top: 1px solid var(--line-soft);
        }

            .zone-table tbody tr:first-child {
                border-top: 0;
            }

        .zone-table td {
            border: 0;
            padding: 0 0 0.55rem;
        }

            .zone-table td:last-child {
                padding-bottom: 0;
            }

            .zone-table td:first-child {
                font-size: 1rem;
                font-weight: 600;
                color: var(--ink);
            }

        /* Les 7 pastilles d'état */
        .zone-table .state-picker {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 6px;
        }

        .zone-table input[type="text"] {
            width: 100%;
            padding: 0.55rem 0.8rem;
            border: 1px solid var(--line);
            border-radius: var(--r-sm);
            background: var(--surface);
            font: inherit;
        }

        .zone-table .file-field--compact .file-field__button {
            width: 100%;
            padding: 9px 15px;
            font-size: 13.5px;
        }

    /* Barre d'envoi collante (formulaires longs) */
    .form-actions--sticky {
        position: sticky;
        bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
        z-index: 20;
        background: var(--surface);
        border-top: 1px solid var(--line);
        border-radius: 0 0 var(--r-lg) var(--r-lg);
        margin: 1rem -1.1rem -1.1rem;
        padding: 0.85rem 1.1rem;
    }

    /* La modale devient une feuille du bas */
    .modal-root {
        align-items: flex-end;
    }

    .modal-root .form-card {
        width: 100%;
        max-width: none;
        max-height: 88vh;
        overflow-y: auto;
        overscroll-behavior: contain;
        border-radius: var(--r-xl) var(--r-xl) 0 0;
        padding-bottom: calc(1.1rem + env(safe-area-inset-bottom));
    }

    .app-main main {
        padding: 16px 14px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 1.5rem);
    }
}
