/* ═══════════════════════════════════════════════════════════════
   FEDERAL CROWN BANK — RESPONSIVE DESIGN SYSTEM
   "Threadneedle Editorial" — Mobile-First
   Breakpoints : 320px → 480px → 640px → 768px → 1024px → 1440px
   ═══════════════════════════════════════════════════════════════ */

/* ── BASE : anti-overflow global ── */
*, *::before, *::after { box-sizing: border-box; }
html { overflow-x: hidden; -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; min-height: 100vh; min-height: 100dvh; }
#main-content { overflow-x: hidden; }
img, video, canvas, svg { max-width: 100%; height: auto; }
/* Wrap long words (URLs, IBANs, emails) sans casser les mots courants */
p, h1, h2, h3, h4, h5, h6, li, td, th, label { overflow-wrap: break-word; word-wrap: break-word; }
table { max-width: 100%; }
pre, code { overflow-x: auto; white-space: pre-wrap; }
/* Permettre aux flex/grid items de rétrécir sous leur largeur intrinsèque */
.grid > *, [class*="grid-cols-"] > *,
.boa-grid-4 > *, .boa-grid-3 > *, .boa-grid-2 > *,
.boa-grid-2-1 > *, .boa-grid-1-2 > *, .boa-grid-6 > * { min-width: 0; }

/* ── GRID SYSTEM — desktop defaults ── */
.boa-grid-4     { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.boa-grid-3     { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.boa-grid-2     { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.boa-grid-2-1   { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.boa-grid-1-2   { display: grid; grid-template-columns: 1fr 2fr; gap: 20px; }
.boa-grid-6     { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
.boa-grid-form  { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 12px; }
.boa-grid-settings { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }

/* ── TOPBAR — responsive ── */
header[class*="flex"] { min-height: 0; }

/* ── SIDEBAR overlay ── */
#sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(6,20,41,0.6);
    -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
    z-index: 90; opacity: 0; transition: opacity 0.3s ease;
}
#sidebar-overlay.sidebar-overlay-visible {
    display: block !important; opacity: 1;
}

/* ── TABLES — scroll wrapper ── */
.boa-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.boa-table-wrap table { min-width: 580px; }

/* ── TABLES STANDARDS — scroll horizontal sur mobile ── */
.rate-table, .doc-table {
    width: 100%;
    border-collapse: collapse;
}
@media (max-width: 767px) {
    /* Toutes les tables standards : scroll horizontal */
    .rate-table, .doc-table, .glba-table,
    table.boa-table, table.standard-table {
        display: block !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        max-width: 100% !important;
    }
    .rate-table thead, .rate-table tbody, .rate-table tr,
    .doc-table thead, .doc-table tbody, .doc-table tr,
    .glba-table thead, .glba-table tbody, .glba-table tr {
        display: table !important;
        width: max-content !important;
        min-width: 100% !important;
    }
    .rate-table th, .rate-table td,
    .doc-table th, .doc-table td,
    .glba-table th, .glba-table td {
        white-space: nowrap !important;
        font-size: 12px !important;
    }
}

/* ── KPI CARD VALUE — fluid typography ── */
.kpi-value { font-size: clamp(18px, 4vw, 28px); font-weight: 700; margin: 0 0 4px; line-height: 1.1; }

/* ── DASHBOARD CARD — base ── */
.dash-card {
    background: #fff; border: 1px solid #E5E2DA; border-radius: 4px;
    padding: 20px; margin-bottom: 0;
    transition: box-shadow 0.2s cubic-bezier(0.2,0.7,0.2,1);
}
.dash-card:hover { box-shadow: 0 4px 12px rgba(11,31,58,0.06); }
.dash-card-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px; gap: 8px; flex-wrap: wrap;
}
.dash-card-title {
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: 16px; font-weight: 500; color: #061429;
    letter-spacing: -0.01em; margin: 0;
}
.dash-card-sub {
    font-size: 11px; color: #8A8A8A; letter-spacing: 0.1em;
    text-transform: uppercase; font-weight: 600; margin-top: 4px;
}

/* ═══════════════════════════════════════════════════════════
   BREAKPOINT : LARGE DESKTOP (≥ 1440px)
   ═══════════════════════════════════════════════════════════ */
/* ═══════════════════════════════════════════════════════════
   BREAKPOINT : DESKTOP STANDARD (≥ 1024px)
   <main> en pleine largeur pour que les fonds de section s'étendent
   bord à bord. Les conteneurs internes restent centrés et limités.
   ═══════════════════════════════════════════════════════════ */
@media (min-width: 1024px) {
    /* main = pleine largeur (les fonds de hero/sections couvrent tout) */
    #main-content {
        padding: 0 !important;
        max-width: none !important;
        margin: 0 !important;
        width: 100% !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   BREAKPOINT : LARGE DESKTOP (≥ 1440px)
   On élargit légèrement les conteneurs internes pour mieux
   exploiter les grands écrans tout en gardant la lisibilité.
   ═══════════════════════════════════════════════════════════ */
@media (min-width: 1440px) {
    .nav-inner,
    .alert-inner,
    .section-inner,
    .hero-inner,
    .page-hero-inner,
    .offer-inner,
    .stats-inner,
    .security-inner,
    .cta-strip-inner,
    .footer-top,
    .footer-bottom {
        max-width: 1440px !important;
        margin-left: auto !important;
        margin-right: auto !important;
        padding-left: 32px !important;
        padding-right: 32px !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   BREAKPOINT : EXTRA LARGE (≥ 1680px)
   Sur très grands écrans : 1500px max pour un peu plus de respiration
   ═══════════════════════════════════════════════════════════ */
@media (min-width: 1680px) {
    .nav-inner,
    .alert-inner,
    .section-inner,
    .hero-inner,
    .page-hero-inner,
    .offer-inner,
    .stats-inner,
    .security-inner,
    .cta-strip-inner,
    .footer-top,
    .footer-bottom {
        max-width: 1500px !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   BREAKPOINT : DESKTOP (≥ 1024px)
   ═══════════════════════════════════════════════════════════ */
@media (min-width: 1024px) {
    #sidebar {
        position: sticky !important; top: 0 !important;
        transform: none !important; z-index: 50 !important;
    }
    #sidebar .lg-hidden-btn { display: none !important; }
    #sidebar-overlay { display: none !important; }
    #topbar-menu-btn { display: none !important; }
}

/* ═══════════════════════════════════════════════════════════
   BREAKPOINT : TABLETTE (< 1024px)
   Sidebar → drawer, grilles 4→2, 2-1→1
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 1023px) {
    /* Sidebar en drawer mobile */
    #sidebar {
        position: fixed !important; top: 0 !important; left: 0 !important;
        height: 100vh !important; height: 100dvh !important;
        transform: translateX(-100%) !important;
        z-index: 100 !important;
        transition: transform 0.3s cubic-bezier(0.2,0.7,0.2,1) !important;
    }
    #sidebar.sidebar-open { transform: translateX(0) !important; }
    #sidebar .lg-hidden-btn { display: flex !important; align-items: center !important; justify-content: center !important; }
    #topbar-menu-btn { display: flex !important; }

    /* Main content */
    #main-content { padding: 20px 16px !important; }

    /* Grilles tablette */
    .boa-grid-4 { grid-template-columns: repeat(2, 1fr) !important; }
    .boa-grid-3 { grid-template-columns: repeat(2, 1fr) !important; }
    .boa-grid-6 { grid-template-columns: repeat(3, 1fr) !important; }
    .boa-grid-2-1 { grid-template-columns: 1fr !important; }
    .boa-grid-1-2 { grid-template-columns: 1fr !important; }
    .boa-grid-form { grid-template-columns: 1fr 1fr !important; }
    .boa-grid-settings { grid-template-columns: 1fr !important; }

    /* Footer tablette */
    .boa-footer-grid { grid-template-columns: repeat(2, 1fr) !important; padding: 28px 16px 20px !important; }
    .boa-footer-bottom { flex-direction: column !important; align-items: flex-start !important; padding: 16px !important; }

    /* Topbar — réduire padding */
    header[class*="flex"] { padding: 0 16px !important; gap: 12px !important; }
}

/* ═══════════════════════════════════════════════════════════
   BREAKPOINT : PHABLET (< 768px)
   Grilles 4→2 KPI horizontal scroll
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 767px) {
    /* KPI cards en scroll horizontal */
    .boa-grid-4 {
        grid-template-columns: none !important;
        display: flex !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        gap: 12px !important;
        padding-bottom: 8px;
        margin-left: -16px !important;
        margin-right: -16px !important;
        padding-left: 16px !important;
        padding-right: 16px !important;
    }
    .boa-grid-4 > * {
        flex: 0 0 75%;
        min-width: 260px;
        max-width: 320px;
        scroll-snap-align: start;
    }
    /* Premier KPI (Total Balance) pleine largeur */
    .boa-grid-4 > *:first-child {
        flex: 0 0 calc(100% - 32px);
        max-width: none;
    }
}

/* ═══════════════════════════════════════════════════════════
   BREAKPOINT : MOBILE (< 640px)
   Empilage complet, typographie compacte
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 639px) {
    /* Main content — padding compact */
    #main-content { padding: 14px 12px !important; }

    /* Toutes les grilles → 1 colonne */
    .boa-grid-4 {
        display: grid !important;
        grid-template-columns: 1fr !important;
        overflow-x: visible !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
    .boa-grid-4 > * {
        flex: none; min-width: 0; max-width: none;
    }
    .boa-grid-3 { grid-template-columns: 1fr !important; }
    .boa-grid-2 { grid-template-columns: 1fr !important; }
    .boa-grid-2-1 { grid-template-columns: 1fr !important; }
    .boa-grid-1-2 { grid-template-columns: 1fr !important; }
    .boa-grid-6 { grid-template-columns: repeat(2, 1fr) !important; }
    .boa-grid-form { grid-template-columns: 1fr !important; }
    .boa-grid-settings { grid-template-columns: 1fr !important; }

    /* Typographie responsive */
    h1, [style*="font-size:22px"][style*="font-weight:700"],
    [style*="font-size:22px"][style*="font-weight:700"] {
        font-size: 20px !important;
    }

    /* KPI montants — empêcher le débordement */
    [style*="font-size:24px"] { font-size: 20px !important; }
    [style*="font-size:28px"] { font-size: 22px !important; }

    /* Cards — padding réduit */
    [style*="padding:20px"] { padding: 16px !important; }
    [style*="padding:24px"] { padding: 16px !important; }
    .dash-card { padding: 16px; }

    /* Topbar mobile */
    header[class*="flex"] {
        height: 48px !important; padding: 0 12px !important; gap: 8px !important;
    }
    #topbar-search { max-width: 140px !important; }
    #topbar-search input { font-size: 12px !important; padding: 6px 8px 6px 30px !important; }
    #topbar-search i { width: 12px !important; height: 12px !important; left: 8px !important; }

    /* Notification/Profile boutons */
    header [style*="width:34px"][style*="height:34px"] {
        width: 30px !important; height: 30px !important;
    }
    header [style*="width:32px"][style*="height:32px"][style*="border-radius:50%"] {
        width: 28px !important; height: 28px !important; font-size: 10px !important;
    }

    /* Panels pleine largeur mobile */
    #notif-panel {
        position: fixed !important; left: 8px !important; right: 8px !important;
        width: auto !important; top: 56px !important;
        max-height: calc(100vh - 70px) !important;
    }
    #profile-panel {
        position: fixed !important; right: 8px !important;
        width: 260px !important; top: 56px !important;
    }

    /* Footer mobile */
    .boa-footer-grid { grid-template-columns: 1fr !important; gap: 20px !important; padding: 24px 12px 16px !important; }
    .boa-footer-bottom { flex-direction: column !important; align-items: flex-start !important; gap: 8px !important; padding: 12px !important; }

    /* Tables — scroll horizontal */
    .boa-table-wrap { margin: 0 -12px; padding: 0 12px; }
    table:not(.boa-table-wrap table) { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* Boutons — pleine largeur */
    a[style*="display:inline-flex"][style*="padding:10px 20px"],
    a[style*="display:inline-flex"][style*="padding:10px 18px"] {
        width: 100% !important; justify-content: center !important;
    }

    /* Listes type "accounts.php / transactions.php" — empiler info + montant */
    /* Le wrapper flex de la ligne devient column sur mobile */
    a[style*="border-left:4px solid"] > div[style*="display:flex"][style*="gap:16px"] {
        flex-wrap: wrap !important;
        gap: 12px !important;
    }
    /* Bloc info — pleine largeur après l'icône */
    a[style*="border-left:4px solid"] > div > div[style*="flex:1"] {
        flex: 1 1 calc(100% - 64px) !important;
        min-width: 0 !important;
    }
    /* Tous les blocs "right" : passer à gauche, pleine largeur, ordre suivant */
    a[style*="border-left:4px solid"] [style*="text-align:right"] {
        text-align: left !important;
        flex: 1 1 100% !important;
        min-width: 0 !important;
        padding-left: 64px !important; /* aligné avec contenu après icône */
        margin-top: 0 !important;
    }
    /* Chevron : caché sur mobile (le tap target = toute la carte) */
    a[style*="border-left:4px solid"] > div > i[data-lucide="chevron-right"] {
        display: none !important;
    }
    /* Titre du compte : ellipsis propre, jamais cassé lettre par lettre */
    h3[style*="white-space:nowrap"] {
        max-width: 100% !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    /* Tailwind cards — empêcher l'overflow par contenu intrinsèque */
    [class*="rounded-2xl"][class*="p-5"],
    [class*="rounded-xl"][class*="p-5"],
    [class*="rounded-2xl"][class*="p-6"],
    [class*="rounded-xl"][class*="p-6"] {
        max-width: 100% !important;
        min-width: 0 !important;
    }
    /* Padding Tailwind p-12 trop grand sur mobile */
    [class*="p-12"] { padding: 1.5rem !important; }
    [class*="p-8"] { padding: 1rem !important; }

    /* Flex containers — wrap */
    [style*="display:flex"][style*="justify-content:space-between"] {
        flex-wrap: wrap !important;
    }

    /* Grilles Tailwind → 1 colonne */
    .grid-cols-2, .sm\:grid-cols-2, .grid-cols-3, .sm\:grid-cols-3,
    .lg\:grid-cols-3, .grid-cols-4, .lg\:grid-cols-4 {
        grid-template-columns: 1fr !important;
    }

    /* Flex row → column sur mobile */
    .sm\:flex-row { flex-direction: column !important; }

    /* Rounded corners Tailwind → plus petit */
    .rounded-2xl { border-radius: 4px !important; }
    .rounded-xl { border-radius: 4px !important; }
}

/* ═══════════════════════════════════════════════════════════
   BREAKPOINT : PETIT MOBILE (< 480px)
   iPhone SE, vieux Android — ultra compact
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 479px) {
    #main-content { padding: 10px 8px !important; }

    /* Typographie ultra compacte */
    h1 { font-size: 18px !important; }
    [style*="font-size:24px"] { font-size: 18px !important; }
    [style*="font-size:22px"] { font-size: 17px !important; }

    /* Cards — padding minimal */
    [style*="padding:20px"] { padding: 12px !important; }
    [style*="padding:24px"] { padding: 12px !important; }
    [style*="padding:16px"] { padding: 10px !important; }

    /* Gap réduit */
    .boa-grid-4, .boa-grid-3, .boa-grid-2 { gap: 10px !important; }
    .boa-grid-2-1, .boa-grid-1-2 { gap: 12px !important; }

    /* KPI label */
    [style*="font-size:11px"][style*="text-transform:uppercase"] {
        font-size: 10px !important; letter-spacing: 0.5px !important;
    }

    /* Mini icônes */
    [style*="width:32px"][style*="height:32px"][style*="border-radius:3px"] {
        width: 28px !important; height: 28px !important;
    }

    /* Topbar ultra compact */
    header[class*="flex"] { height: 44px !important; padding: 0 8px !important; }
    #topbar-search { max-width: 120px !important; }
    #topbar-menu-btn { padding: 4px !important; }

    /* 6-col → 1 colonne */
    .boa-grid-6 { grid-template-columns: 1fr !important; }

    /* Bouton New Transfer — compact */
    a[style*="background:#C8102E"][style*="border-radius:3px"] {
        padding: 8px 14px !important; font-size: 12px !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   BREAKPOINT : MICRO MOBILE (< 360px)
   Galaxy Fold, très petits écrans
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 359px) {
    #main-content { padding: 8px 6px !important; }
    h1 { font-size: 16px !important; }
    [style*="font-size:24px"] { font-size: 16px !important; }
    [style*="padding:20px"], [style*="padding:16px"] { padding: 8px !important; }
    .boa-grid-4, .boa-grid-3, .boa-grid-2 { gap: 8px !important; }

    /* Cacher la barre de recherche sur très petit écran */
    #topbar-search { display: none !important; }
}

/* ═══════════════════════════════════════════════════════════
   PRINT — masquer navigation
   ═══════════════════════════════════════════════════════════ */
@media print {
    #sidebar, header, footer, #topbar-menu-btn, .no-print { display: none !important; }
    #main-content { padding: 0 !important; }
    body { background: #fff !important; color: #000 !important; }
    .dash-card { break-inside: avoid; border: 1px solid #ccc; }
}

/* ═══════════════════════════════════════════════════════════
   ANIMATIONS RESPONSIVE
   Réduire les animations sur mobile pour les performances
   ═══════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Réduire les animations sur mobile */
@media (max-width: 639px) {
    .boa-anim { animation: none !important; opacity: 1 !important; transform: none !important; }
    .boa-lift:hover { transform: none !important; }
    .hover-scale:hover { transform: none !important; }
}

/* ═══════════════════════════════════════════════════════════
   SAFE AREA — iPhone notch, bords arrondis
   ═══════════════════════════════════════════════════════════ */
@supports (padding: env(safe-area-inset-bottom)) {
    body { padding-bottom: env(safe-area-inset-bottom); }
    footer { padding-bottom: calc(16px + env(safe-area-inset-bottom)) !important; }
    #sidebar { padding-bottom: env(safe-area-inset-bottom); }
}

/* ═══════════════════════════════════════════════════════════
   TOUCH TARGET — accessibilité mobile
   Minimum 44px tap targets
   ═══════════════════════════════════════════════════════════ */
@media (pointer: coarse) {
    a, button { min-height: 44px; }
    .boa-nav-item, .boa-nav-active { min-height: 44px !important; padding-top: 12px !important; padding-bottom: 12px !important; }
    select, input[type="text"], input[type="email"], input[type="tel"],
    input[type="date"], input[type="number"], textarea {
        min-height: 44px; font-size: 16px !important; /* Empêche le zoom iOS */
    }
}
