/* ================================================================
   MOBILE.CSS — Optimisations iPhone & Mobile
   ================================================================
   Objectifs :
   ① Safe-area insets (encoche, barre home iPhone X+)
   ② Taille minimum 44px pour tous les éléments tactiles
   ③ Pas d'auto-zoom iOS sur focus (font-size ≥ 16px)
   ④ Smooth scroll natif iOS (-webkit-overflow-scrolling)
   ⑤ Bannière d'installation PWA
   ⑥ Améliorations form UX sur mobile
   ================================================================ */

/* ── Corrections globales iOS ──────────────────────────────────── */

/* Empêche l'overscroll "rubber-band" sur le body */
html { height: 100%; }
body { min-height: 100%; -webkit-text-size-adjust: 100%; }

/* Smooth scroll natif */
.app-shell, .sidebar {
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
}

/* ── Safe Area Insets ──────────────────────────────────────────── */

/* Topbar : évite l'encoche Dynamic Island / TrueDepth */
.topbar, .public-header {
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(72px + env(safe-area-inset-top, 0px));
}

/* Bottom nav : évite la barre de navigation iPhone */
.bottom-nav {
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* App shell : tient compte de la bottom nav + safe area */
.app-shell {
    padding-bottom: calc(110px + env(safe-area-inset-bottom, 0px));
    padding-top: calc(96px + env(safe-area-inset-top, 0px));
}

/* Sidebar : full height en tenant compte de l'encoche */
.sidebar {
    padding-top: calc(24px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}

/* ── Zones tactiles minimum 44×44px ───────────────────────────── */

.btn {
    min-height: 44px;
    min-width: 44px;
}

.input {
    min-height: 44px;
    /* ⚠ iOS auto-zoom si font-size < 16px */
    font-size: 16px !important;
}

select.input {
    font-size: 16px !important;
    /* Flèche native sur iOS */
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

textarea.input { min-height: 80px; font-size: 16px !important; }

/* Labels : zone de touch élargie */
label { min-height: 22px; padding: 2px 0; }

/* Liens d'action dans les cartes */
.doc-actions a, .danger-link, .sidebar-link {
    min-height: 44px;
    display: flex;
    align-items: center;
}

/* Burger button */
.burger-btn {
    min-width: 44px;
    min-height: 44px;
}

/* ── Bottom nav : icônes SVG ──────────────────────────────────── */
.bottom-nav a {
    flex-direction: column;
    gap: 4px;
    min-width: 44px;
    min-height: 52px;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bottom-nav svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.bottom-nav a.active svg { stroke: var(--primary); }
.bottom-nav a.active span { color: var(--primary); }

.bottom-nav-plus {
    width: 56px !important;
    height: 56px !important;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    border-radius: 20px !important;
    color: #fff !important;
    display: grid !important;
    place-items: center !important;
    margin-top: -20px;
    box-shadow: 0 12px 28px rgba(37, 99, 235, .35);
    flex-direction: row !important;
    padding: 0 !important;
}

.bottom-nav-plus svg {
    stroke: #fff;
    width: 26px;
    height: 26px;
    stroke-width: 2.5;
}

/* ── Sidebar : icônes ─────────────────────────────────────────── */
.nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 14px;
    border-radius: 14px;
    color: #334155;
    font-weight: 700;
    min-height: 44px;
    transition: background .15s, color .15s;
}
.sidebar-link:hover, .sidebar-link.active {
    background: #eff6ff;
    color: var(--primary);
}
.sidebar-link.active .nav-icon { stroke: var(--primary); }
.sidebar-link-create { color: var(--primary); background: #eff6ff; }
.sidebar-link-logout { color: var(--danger); margin-top: 8px; }

/* ── Champ mot de passe avec bouton afficher/masquer ─────────── */
.input-password-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.input-password-wrap .input {
    padding-right: 50px;
}
.show-pass-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: 0;
    cursor: pointer;
    color: var(--muted);
    padding: 6px;
    border-radius: 8px;
    min-width: 36px;
    min-height: 36px;
    display: grid;
    place-items: center;
}
.show-pass-btn:hover { color: var(--primary); }

/* ── Alertes ──────────────────────────────────────────────────── */
.alert {
    border-radius: 14px;
    padding: 13px 16px;
    font-weight: 700;
    margin-bottom: 14px;
    border: 1px solid transparent;
}
.alert-error   { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-info    { background: #eff6ff; border-color: #bfdbfe; color: #1e3a8a; }

/* ── Lien "Mot de passe oublié" dans login ───────────────────── */
.login-links {
    text-align: right;
    margin: -4px 0 12px;
    font-size: .88rem;
}
.login-links a { color: var(--primary); font-weight: 700; }

/* ── Bannière PWA Install ─────────────────────────────────────── */
#pwa-install-bar {
    position: fixed;
    bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    left: 14px;
    right: 14px;
    background: linear-gradient(135deg, #1e3a8a, #2563eb);
    color: #fff;
    border-radius: 20px;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 80;
    box-shadow: 0 18px 50px rgba(15, 23, 42, .25);
    animation: slideUp .35s ease;
}
#pwa-install-bar p { margin: 0; font-weight: 700; flex: 1; font-size: .9rem; }
#pwa-install-bar .btn { flex-shrink: 0; }
#pwa-install-bar .btn-soft { background: rgba(255,255,255,.15); color: #fff; }

@keyframes slideUp {
    from { transform: translateY(40px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

/* ── Stat cards : plus grand sur mobile ──────────────────────── */
@media (max-width: 680px) {
    .stat-card strong { font-size: 1.6rem; }

    /* Form grid : toujours 1 colonne sur mobile */
    .form-grid { grid-template-columns: 1fr !important; }
    .span-2    { grid-column: span 1 !important; }

    /* Page head vertical sur mobile */
    .page-head { flex-direction: column; align-items: flex-start; gap: 12px; }
    .page-head .btn { width: 100%; justify-content: center; }

    /* Panel padding réduit */
    .panel { padding: 16px; }
    .auth-card { padding: 22px 18px; }

    /* filter-bar : 2 colonnes sur mobile */
    .filter-bar,
    .filter-bar-5 {
        grid-template-columns: 1fr 1fr !important;
    }
    .filter-bar button,
    .filter-bar-5 button {
        grid-column: 1 / -1;
    }

    /* Public header : visible tout le temps */
    .public-header { position: sticky; top: 0; z-index: 50; }

    /* Topbar : brand-name masqué si sidebar ouverte */
    .topbar .brand-name { display: none; }

    /* Invoice template scale correcte */
    .print-page .invoice-template {
        transform: scale(0.42);
        transform-origin: top center;
    }
}

/* ── Très petit écran (iPhone SE) ─────────────────────────────── */
@media (max-width: 375px) {
    .hero-content h1 { font-size: 2.2rem; }
    .bottom-nav a span { font-size: .68rem; }
}

/* ── Haute résolution / iPad ──────────────────────────────────── */
@media (min-width: 768px) and (max-width: 1100px) {
    .bottom-nav { display: flex; }
    .sidebar    { transform: translateX(-105%); }
}

/* ── Système de préférence de couleur (Dark mode préparé) ─────── */
@media (prefers-color-scheme: dark) {
    /* Décommentez et personnalisez si vous souhaitez activer le dark mode */
    /*
    :root {
        --bg: #0f172a;
        --surface: #1e293b;
        --surface-2: #1e293b;
        --text: #f1f5f9;
        --muted: #94a3b8;
        --border: #334155;
        --shadow: 0 18px 50px rgba(0,0,0,.3);
    }
    .topbar, .sidebar, .bottom-nav { background: rgba(15,23,42,.92); }
    */
}

/* ── Accessibilité : focus visible ───────────────────────────── */
:focus-visible {
    outline: 3px solid rgba(37, 99, 235, .5);
    outline-offset: 2px;
    border-radius: 8px;
}

/* ── Reduced motion ──────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}

@media (max-width: 680px) {
    .doc-form .items-table { min-width: 0 !important; }
    .doc-form .items-table-wrap { overflow: visible !important; }
    .a4-doc { width: 100% !important; min-height: auto !important; }
}

/* ── Bottom nav stable iPhone / Android ───────────────────────── */
@media (max-width: 1100px) {
    .app-shell {
        padding-bottom: calc(var(--bottom-nav-height, 74px) + 72px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .bottom-nav {
        left: max(12px, env(safe-area-inset-left, 0px));
        right: max(12px, env(safe-area-inset-right, 0px));
        bottom: max(8px, env(safe-area-inset-bottom, 0px));
        height: var(--bottom-nav-height, 74px);
        padding: 7px 12px;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        align-items: center;
        justify-items: center;
        gap: 0;
        overflow: visible;
    }

    .bottom-nav a {
        width: 100%;
        height: 58px;
        min-height: 58px;
        min-width: 0;
        padding: 4px 2px;
        line-height: 1;
        align-self: center;
    }

    .bottom-nav a span {
        display: block;
        width: 100%;
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: clip;
        font-size: .74rem;
        line-height: 1.15;
    }

    .bottom-nav svg {
        width: 23px;
        height: 23px;
    }

    .bottom-nav-plus {
        width: 58px !important;
        height: 58px !important;
        min-width: 58px !important;
        min-height: 58px !important;
        margin: -22px auto 0 !important;
        align-self: center;
        justify-self: center;
        padding: 0 !important;
    }

    .bottom-nav-plus svg {
        width: 28px;
        height: 28px;
    }

    #pwa-install-bar {
        bottom: calc(var(--bottom-nav-height, 74px) + 28px + env(safe-area-inset-bottom, 0px));
    }

    #offline-bar {
        bottom: calc(var(--bottom-nav-height, 74px) + 26px + env(safe-area-inset-bottom, 0px));
    }

    .pwa-install-shortcut {
        bottom: calc(var(--bottom-nav-height, 74px) + 24px + env(safe-area-inset-bottom, 0px));
    }
}

@media (max-width: 375px) {
    .bottom-nav {
        left: 8px;
        right: 8px;
        padding-left: 8px;
        padding-right: 8px;
    }

    .bottom-nav a span {
        font-size: .68rem;
    }
}
