/* ========================
   CLOUD ZERO — TÉLÉPHONE ET APPLI ANDROID
   Chargé en dernier sur toutes les pages : rend l'interface compacte,
   lisible et « comme une appli » sous 700 px de large.
======================== */

@media (max-width: 700px) {

    /* ---------- Lisibilité ----------
       Les grands espacements de lettres sont élégants sur ordinateur
       mais gênent la lecture sur un petit écran. */
    body,
    body * {
        letter-spacing: normal !important;
    }

    html {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    /* Rien ne doit élargir la page : sinon le téléphone dézoome et la
       barre du bas n'est plus collée en bas de l'écran. */
    html,
    body {
        max-width: 100%;
        overflow-x: clip;
    }

    .main-content,
    .main-content > *,
    .dashboard-panel,
    .dashboard-columns > * {
        min-width: 0;
    }

    /* Pas de surbrillance bleue au toucher, boutons nets. */
    a,
    button,
    label,
    .files-item {
        -webkit-tap-highlight-color: transparent;
    }

    .main-content {
        padding-top: calc(14px + env(safe-area-inset-top));
        padding-right: 12px;
        padding-left: 12px;
    }

    /* ---------- En-têtes de page compacts ---------- */

    .files-eyebrow,
    .dashboard-eyebrow,
    .files-header-content > p,
    .dashboard-header-content > p {
        display: none !important;
    }

    .files-header,
    .dashboard-header {
        flex-direction: row !important;
        flex-wrap: wrap;
        align-items: center !important;
        justify-content: space-between;
        gap: 10px !important;
        min-height: 0 !important;
        margin: 0 0 14px !important;
        padding: 4px 2px !important;
    }

    .files-header h1,
    .dashboard-header h1 {
        margin: 0 !important;
        font-size: 24px !important;
        line-height: 1.2 !important;
    }

    .files-header-content,
    .dashboard-header-content {
        flex: 1 1 auto;
        min-width: 0;
    }

    .files-header .files-button,
    .files-header-actions .files-button,
    .admin-header-actions .files-button,
    .server-header-actions .files-button {
        min-height: 36px;
        padding: 0 12px;
        font-size: 12px;
    }

    .admin-header-actions,
    .server-header-actions {
        gap: 8px;
    }

    .server-live {
        display: none;
    }

    .dashboard-avatar {
        width: 40px !important;
        height: 40px !important;
        font-size: 16px !important;
        border-radius: 12px !important;
    }

    /* Mes fichiers : « Importer » et « Nouveau dossier » sont dans le bouton +. */
    body:has(.cz-fab) .files-header-actions {
        display: none !important;
    }

    /* La jauge d'espace est sur l'accueil : on gagne la moitié de l'écran. */
    .files-page:has(.files-browser) > section.files-storage-card:not(#upload-progress) {
        display: none;
    }

    /* ---------- Cartes et chiffres en 2 colonnes ---------- */

    .dashboard-stats,
    .admin-summary,
    .server-tiles {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px !important;
        margin-bottom: 14px !important;
    }

    .stat-card,
    .admin-summary .files-storage-card,
    .server-tile {
        padding: 14px !important;
        border-radius: var(--radius-md) !important;
    }

    .stat-card:hover {
        transform: none;
    }

    .stat-card-header {
        margin-bottom: 8px !important;
    }

    .stat-card-icon {
        display: none !important;
    }

    .stat-card-label,
    .files-storage-label {
        font-size: 12px !important;
    }

    .stat-card-value,
    .admin-big,
    .server-big {
        margin: 4px 0 !important;
        font-size: 21px !important;
        line-height: 1.2 !important;
        overflow-wrap: anywhere;
    }

    .server-big-small {
        font-size: 14px !important;
    }

    .stat-card-description,
    .files-storage-description {
        font-size: 12px !important;
        line-height: 1.45 !important;
    }

    .files-storage-card {
        margin-bottom: 12px !important;
        padding: 16px !important;
        border-radius: var(--radius-md) !important;
    }

    .dashboard-alert,
    .server-alert {
        font-size: 13px;
    }

    .dashboard-panel,
    .server-panel {
        border-radius: var(--radius-md) !important;
    }

    .server-panel {
        padding: 16px !important;
    }

    .dashboard-panel-header {
        padding: 14px 16px !important;
    }

    .dashboard-panel-header h2 {
        font-size: 16px !important;
    }

    .dashboard-list-item {
        min-height: 44px;
    }

    /* ---------- Explorateur ---------- */

    .files-explorer,
    .files-browser {
        border-radius: var(--radius-md) !important;
    }

    .files-toolbar {
        gap: 10px !important;
        padding: 12px !important;
    }

    .files-breadcrumb {
        font-size: 13px;
    }

    .files-toolbar-right,
    .files-search {
        width: 100%;
    }

    .files-search input {
        min-height: 42px;
        font-size: 15px;
    }

    /* Onglets : les 5 visibles d'un coup (icône + nom), Partages compris. */
    .files-views {
        flex-wrap: wrap !important;
        gap: 8px !important;
        padding: 10px 12px !important;
    }

    .files-view-tabs {
        display: grid !important;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        flex: 1 1 100%;
        gap: 4px !important;
        min-width: 0;
    }

    .files-view-tab {
        position: relative;
        flex-direction: column;
        justify-content: center;
        gap: 3px !important;
        min-width: 0;
        min-height: 54px;
        padding: 6px 2px !important;
        border-radius: 12px !important;
        font-size: 11px !important;
        text-align: center;
    }

    .files-view-tab span:not(.nav-badge) {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .files-view-tab .files-tab-badge {
        position: absolute;
        top: 4px;
        right: 8px;
    }

    .files-layout-toggle {
        flex: none;
    }

    .files-list-header {
        padding: 10px 12px !important;
    }

    .files-browser .files-item {
        min-height: 64px;
        padding: 10px 6px 10px 12px !important;
        gap: 6px 10px !important;
    }

    .files-item-link {
        font-size: 14px;
    }

    .files-item-info small {
        font-size: 12px;
    }

    /* Noms longs : une ligne avec « … » plutôt que coupés au milieu. */
    .files-browser .files-item-info {
        min-width: 0;
    }

    .files-browser .files-item-link {
        display: block;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        text-align: left;
    }

    /* Grille : bouton ⋯ en haut à droite de la vignette. */
    .files-browser.is-grid .files-more-button {
        top: 14px;
        right: 14px;
        bottom: auto !important;
        width: 36px;
        height: 36px;
        border-radius: 10px;
        background: color-mix(in srgb, var(--bg-surface) 85%, transparent);
        box-shadow: var(--shadow-sm);
    }

    .files-browser.is-grid .files-shared-badge {
        top: 18px !important;
        right: 56px !important;
    }

    .files-search-banner,
    .files-filters {
        padding: 10px 12px !important;
        font-size: 13px;
    }

    .files-filter-label {
        min-width: 100%;
    }

    .files-shortcuts {
        display: none;
    }

    .files-empty {
        padding: 36px 16px !important;
    }

    /* ---------- Fenêtres : en bas de l'écran, pleine largeur ---------- */

    .files-modal {
        align-items: flex-end !important;
        padding: 0 !important;
    }

    .files-modal-content {
        max-width: none !important;
        max-height: 88vh;
        padding: 20px 16px calc(18px + env(safe-area-inset-bottom)) !important;
        overflow-y: auto;
        border-radius: 18px 18px 0 0 !important;
        border-bottom: 0 !important;
    }

    .files-modal-header {
        margin-bottom: 16px !important;
    }

    .files-modal-header h2 {
        font-size: 18px !important;
        overflow-wrap: anywhere;
    }

    .files-modal-actions {
        gap: 10px;
    }

    .files-modal-actions .files-button {
        flex: 1;
        min-height: 46px;
    }

    .files-field-input,
    select.files-field-input {
        min-height: 46px;
        font-size: 16px; /* évite le zoom automatique au focus */
    }

    /* ---------- Aperçu plein écran ---------- */

    .preview-modal {
        align-items: stretch !important;
    }

    .preview-content {
        width: 100vw !important;
        height: 100% !important;
        max-height: none !important;
        border: 0 !important;
        border-radius: 0 !important;
    }

    .preview-header {
        flex-wrap: wrap;
        gap: 8px !important;
        padding: calc(10px + env(safe-area-inset-top)) 12px 10px !important;
    }

    .preview-header h2 {
        flex: 1 1 calc(100% - 52px) !important;
        order: 0;
        overflow: hidden;
        font-size: 15px !important;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow-wrap: normal !important;
    }

    .preview-header .files-modal-close {
        order: 1;
    }

    .preview-nav {
        order: 2;
        flex: 1 1 auto;
        margin-left: 0 !important;
    }

    #preview-chat,
    #preview-download {
        order: 3;
    }

    /* Sur mobile, le bouton « Chat » de l'aperçu n'affiche que son icône. */
    .preview-chat span {
        display: none;
    }

    .preview-nav [data-step],
    .preview-header .files-action-button,
    .preview-header .files-modal-close {
        min-width: 40px;
        min-height: 40px;
    }

    .preview-body {
        padding: 8px !important;
    }

    /* ---------- Formulaires (connexion, compte) ---------- */

    .account-grid {
        gap: 12px !important;
    }

    .account-card {
        padding: 16px !important;
    }

    .account-details div {
        flex-wrap: wrap;
        gap: 4px;
    }

    .account-details dd {
        overflow-wrap: anywhere;
    }

    .account-form-actions .files-button,
    .account-form-actions button {
        width: 100%;
        min-height: 46px;
    }

    /* ---------- Tableaux larges : défilement horizontal propre ---------- */

    .server-table-wrap,
    .server-panel:has(> .server-table) {
        overflow-x: auto;
    }

    .server-table {
        min-width: 520px;
    }

    .server-facts div {
        flex-wrap: wrap;
    }

    .server-charts {
        gap: 14px !important;
    }

    .server-chart-area {
        height: 120px !important;
    }

    /* ---------- Admin : lignes des comptes ---------- */

    .admin-row {
        padding: 14px 12px !important;
    }

    .admin-actions {
        flex-wrap: wrap;
        gap: 6px;
    }

    .admin-action {
        min-height: 36px;
    }

    /* ---------- Messages (toasts) : en haut, pleine largeur ----------
       Toujours entièrement dans l'écran (ni sous la barre du bas,
       ni au-delà du bord droit), et ils glissent depuis le haut. */
    .toast-container {
        top: calc(10px + env(safe-area-inset-top));
        right: 10px;
        bottom: auto;
        left: 10px;
        width: auto;
        max-width: none;
        align-items: stretch;
    }

    .toast {
        width: 100%;
        max-width: 100%;
        border-radius: var(--radius-md);
        animation-name: toast-enter-top;
    }

    .toast.is-leaving {
        animation-name: toast-exit-top;
    }
}

@keyframes toast-enter-top {
    from { opacity: 0; transform: translateY(-12px); }
    to { opacity: 1; transform: none; }
}

@keyframes toast-exit-top {
    from { opacity: 1; transform: none; }
    to { opacity: 0; transform: translateY(-12px); }
}

/* ---------- Appli Android : tirer vers le bas pour actualiser ---------- */

.cz-pull {
    position: fixed;
    top: 0;
    left: 50%;
    z-index: 1500;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-surface);
    box-shadow: var(--shadow-md);
    color: var(--accent);
    font-size: 20px;
    opacity: 0;
    transform: translate(-50%, -48px);
    pointer-events: none;
}

.cz-pull.is-ready {
    background: var(--accent);
    color: var(--text-white);
}

.cz-pull.is-loading {
    animation: cz-spin 0.8s linear infinite;
}

@keyframes cz-spin {
    to { transform: translate(-50%, 24px) rotate(360deg); }
}
