/* ========================================================================
   admin-ui.css — Design system partagé pour l'admin POEM
   Inclus globalement via head.php pour cohérence cross-modules.
   ======================================================================== */

/* === MODALES MODERNES =================================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: modal-fade 0.18s ease-out;
}
.modal-overlay.hidden { display: none; }

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

@keyframes modal-pop {
    from { opacity: 0; transform: translateY(20px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-card {
    background: white;
    border-radius: 1.25rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
    width: 100%;
    max-width: 32rem;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: modal-pop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}
.modal-card.lg { max-width: 42rem; }
.modal-card.xl { max-width: 56rem; }
.dark .modal-card { background: #1f2937; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
}
.dark .modal-header { border-bottom-color: rgba(255, 255, 255, 0.08); }

.modal-header-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.75rem;
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.12), rgba(59, 130, 246, 0.12));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ec4899;
    flex-shrink: 0;
}

.modal-title-block {
    flex: 1;
    min-width: 0;
}
.modal-title {
    font-size: 1.0625rem;
    font-weight: 700;
    background: linear-gradient(135deg, #ec4899, #3b82f6);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    line-height: 1.3;
}
.modal-subtitle {
    font-size: 0.75rem;
    color: #6b7280;
    margin-top: 0.125rem;
}
.dark .modal-subtitle { color: #9ca3af; }

.modal-close {
    width: 2rem;
    height: 2rem;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    transition: all 0.15s;
    flex-shrink: 0;
}
.modal-close:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #1f2937;
}
.dark .modal-close { color: #9ca3af; }
.dark .modal-close:hover { background: rgba(255, 255, 255, 0.08); color: #f3f4f6; }

.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
}
.modal-body.tight { padding: 1rem 1.25rem; }

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.875rem 1.25rem;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    background: rgba(249, 250, 251, 0.5);
    flex-shrink: 0;
}
.dark .modal-footer {
    border-top-color: rgba(255, 255, 255, 0.08);
    background: rgba(17, 24, 39, 0.4);
}
.modal-footer.spread { justify-content: space-between; }

/* === FILTER CHIPS (pills cliquables) ==================================== */
.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    align-items: center;
}
.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.3rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    background: white;
    border: 1px solid #e5e7eb;
    color: #4b5563;
    transition: all 0.15s;
    cursor: pointer;
    user-select: none;
}
.chip:hover {
    border-color: #ec4899;
    color: #ec4899;
    background: rgba(236, 72, 153, 0.05);
}
.chip.active {
    background: linear-gradient(90deg, #ec4899, #a855f7);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 10px -2px rgba(236, 72, 153, 0.4);
}
.chip.active:hover { color: white; }
.dark .chip {
    background: rgba(31, 41, 55, 0.6);
    border-color: #374151;
    color: #d1d5db;
}
.chip-count {
    background: rgba(0, 0, 0, 0.08);
    color: inherit;
    padding: 0 0.4rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
}
.chip.active .chip-count { background: rgba(255, 255, 255, 0.25); }

/* === EMPTY STATES ======================================================= */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: #6b7280;
}
.dark .empty-state { color: #9ca3af; }
.empty-state-icon {
    width: 4rem;
    height: 4rem;
    margin: 0 auto 0.75rem;
    border-radius: 9999px;
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.1), rgba(59, 130, 246, 0.1));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ec4899;
}
.empty-state-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 0.25rem;
}
.dark .empty-state-title { color: #f3f4f6; }
.empty-state-desc {
    font-size: 0.8125rem;
    max-width: 28rem;
    margin: 0 auto 1rem;
    line-height: 1.5;
}
.empty-state-cta {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 0.75rem;
    background: linear-gradient(135deg, #ec4899, #3b82f6);
    color: white !important;
    font-size: 0.8125rem;
    font-weight: 600;
    transition: all 0.15s;
    text-decoration: none;
}
.empty-state-cta:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 14px -4px rgba(236, 72, 153, 0.45);
}

/* === SKELETON LOADING =================================================== */
@keyframes shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}
.skeleton {
    background: linear-gradient(
        90deg,
        rgba(0, 0, 0, 0.05) 0%,
        rgba(0, 0, 0, 0.1) 50%,
        rgba(0, 0, 0, 0.05) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: 0.5rem;
}
.dark .skeleton {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.04) 0%,
        rgba(255, 255, 255, 0.08) 50%,
        rgba(255, 255, 255, 0.04) 100%
    );
    background-size: 200% 100%;
}
.skeleton-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}
.skeleton-avatar { width: 2.5rem; height: 2.5rem; border-radius: 9999px; flex-shrink: 0; }
.skeleton-line { height: 0.75rem; }

/* === KPI CARD AVEC TREND ================================================ */
.kpi-card {
    background: white;
    border-radius: 1rem;
    padding: 1rem;
    border: 1px solid #f0f2f5;
    transition: all 0.2s;
}
.dark .kpi-card { background: #1f2937; border-color: #374151; }
.kpi-card:hover { transform: translateY(-2px); box-shadow: 0 12px 20px -8px rgba(236, 72, 153, 0.18); }

.kpi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}
.kpi-icon-wrap {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
}
.kpi-trend {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 9999px;
}
.kpi-trend-up { background: rgba(16, 185, 129, 0.12); color: #047857; }
.kpi-trend-down { background: rgba(239, 68, 68, 0.12); color: #b91c1c; }
.kpi-trend-flat { background: rgba(107, 114, 128, 0.12); color: #4b5563; }

.kpi-value {
    font-size: 1.875rem;
    font-weight: 800;
    line-height: 1.1;
    background: linear-gradient(135deg, #ec4899, #3b82f6);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.kpi-label {
    font-size: 0.75rem;
    color: #6b7280;
    margin-top: 0.125rem;
}
.dark .kpi-label { color: #9ca3af; }

/* === FORM POLISH ======================================================== */
.form-section {
    margin-bottom: 1.25rem;
}
.form-section-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #6b7280;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.dark .form-section-title { color: #9ca3af; }
.form-input, .form-textarea, .form-select {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.625rem;
    background: white;
    font-size: 0.875rem;
    transition: all 0.15s;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
    outline: none;
    border-color: #ec4899;
    box-shadow: 0 0 0 3px rgba(236, 72, 153, 0.12);
}
.dark .form-input, .dark .form-textarea, .dark .form-select {
    background: #374151;
    border-color: #4b5563;
    color: #f3f4f6;
}
.form-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    margin-bottom: 0.3rem;
    color: #374151;
}
.dark .form-label { color: #d1d5db; }
.form-help {
    font-size: 0.7rem;
    color: #9ca3af;
    margin-top: 0.25rem;
}

/* === DROPZONE UPLOAD ==================================================== */
.dropzone {
    border: 2px dashed #d1d5db;
    border-radius: 0.875rem;
    padding: 1.5rem;
    text-align: center;
    transition: all 0.15s;
    cursor: pointer;
}
.dropzone:hover, .dropzone.drag-over {
    border-color: #ec4899;
    background: rgba(236, 72, 153, 0.04);
}
.dark .dropzone { border-color: #4b5563; }
.dark .dropzone:hover, .dark .dropzone.drag-over {
    border-color: #ec4899;
    background: rgba(236, 72, 153, 0.08);
}
.dropzone-icon {
    width: 3rem;
    height: 3rem;
    margin: 0 auto 0.5rem;
    color: #9ca3af;
}
.dropzone:hover .dropzone-icon, .dropzone.drag-over .dropzone-icon {
    color: #ec4899;
}

/* === BUTTON VARIANTS ==================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.btn-md { padding: 0.55rem 1.1rem; font-weight: 600; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8125rem; }
.btn-ghost { color: #6b7280; }
.btn-ghost:hover { background: rgba(0, 0, 0, 0.05); color: #1f2937; }
.dark .btn-ghost { color: #9ca3af; }
.dark .btn-ghost:hover { background: rgba(255, 255, 255, 0.06); color: #f3f4f6; }
.btn-outline {
    border: 1px solid #d1d5db;
    color: #374151;
    background: white;
}
.btn-outline:hover { border-color: #ec4899; color: #ec4899; }
.dark .btn-outline {
    background: rgba(31, 41, 55, 0.6);
    border-color: #4b5563;
    color: #d1d5db;
}
.btn-danger { color: #dc2626; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.08); }
.btn-disabled, .btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* === BOUTON PRIMARY (gradient signature) =============================== */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.55rem 1.1rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: white !important;
    background: linear-gradient(135deg, #ec4899, #3b82f6);
    box-shadow: 0 2px 8px -2px rgba(236, 72, 153, 0.35);
    transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
    cursor: pointer;
    user-select: none;
    border: 0;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}
.btn-primary:hover {
    transform: translateY(-1px) scale(1.015);
    box-shadow: 0 8px 18px -4px rgba(236, 72, 153, 0.55);
}
.btn-primary:active {
    transform: translateY(0) scale(0.99);
    animation: btn-ripple 0.45s ease-out;
}
.btn-primary[disabled], .btn-primary.is-loading {
    opacity: 0.7;
    cursor: not-allowed;
    pointer-events: none;
    transform: none;
}
@keyframes btn-ripple {
    0%   { box-shadow: 0 0 0 0 rgba(236, 72, 153, 0.5), 0 8px 18px -4px rgba(236, 72, 153, 0.55); }
    100% { box-shadow: 0 0 0 14px rgba(236, 72, 153, 0), 0 8px 18px -4px rgba(236, 72, 153, 0.55); }
}
/* Loading spinner intégré : ajoute class is-loading + l'icône lucide loader-2 dans le bouton */
.btn-primary.is-loading .lucide-icon,
.btn.is-loading .lucide-icon { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* === BOUTON ICON SEUL (action ronde compacte) ========================== */
.btn-icon {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    background: transparent;
    transition: all 0.15s;
    cursor: pointer;
    border: 0;
}
.btn-icon:hover { background: rgba(0, 0, 0, 0.06); color: #1f2937; }
.dark .btn-icon { color: #9ca3af; }
.dark .btn-icon:hover { background: rgba(255, 255, 255, 0.08); color: #f3f4f6; }
.btn-icon.btn-icon-primary { color: #ec4899; }
.btn-icon.btn-icon-primary:hover { background: rgba(236, 72, 153, 0.1); }
.btn-icon.btn-icon-danger { color: #dc2626; }
.btn-icon.btn-icon-danger:hover { background: rgba(239, 68, 68, 0.1); }

/* === TAB NAVIGATION (onglets unifiés) ================================== */
.tab-nav {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.25rem 0;
    margin: 0 -0.25rem;
    scrollbar-width: none;
}
.tab-nav::-webkit-scrollbar { display: none; }
.tab-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.95rem;
    border-radius: 0.875rem;
    font-size: 0.8125rem;
    font-weight: 600;
    background: white;
    color: #4b5563;
    border: 1px solid #e5e7eb;
    transition: all 0.18s ease;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    flex-shrink: 0;
}
.dark .tab-pill {
    background: rgba(31, 41, 55, 0.6);
    border-color: #374151;
    color: #d1d5db;
}
.tab-pill:hover:not(.active) {
    background: rgba(236, 72, 153, 0.06);
    color: #ec4899;
    border-color: rgba(236, 72, 153, 0.3);
    transform: translateY(-1px);
}
.tab-pill.active {
    background: linear-gradient(135deg, #ec4899, #3b82f6);
    color: white;
    border-color: transparent;
    box-shadow: 0 6px 14px -4px rgba(236, 72, 153, 0.45);
}
.tab-pill .tab-count {
    background: rgba(0, 0, 0, 0.08);
    padding: 0.05rem 0.45rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 700;
}
.tab-pill.active .tab-count { background: rgba(255, 255, 255, 0.25); }

/* === PAGE HEADER (titre + sous-titre + actions) ======================== */
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.page-header-title {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, #ec4899, #3b82f6);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    line-height: 1.2;
}
.page-header-subtitle {
    font-size: 0.8125rem;
    color: #6b7280;
    margin-top: 0.2rem;
}
.dark .page-header-subtitle { color: #9ca3af; }
.page-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* === TABLE MODERNE (hover, sticky head, zebra) ========================= */
.table-modern {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.table-modern thead {
    position: sticky;
    top: 0;
    background: rgba(249, 250, 251, 0.95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 5;
}
.dark .table-modern thead { background: rgba(31, 41, 55, 0.95); }
.table-modern thead th {
    text-align: left;
    padding: 0.7rem 0.75rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
    white-space: nowrap;
}
.dark .table-modern thead th { border-bottom-color: #374151; color: #9ca3af; }
.table-modern tbody tr {
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    transition: background 0.15s, transform 0.15s;
}
.dark .table-modern tbody tr { border-bottom-color: rgba(255, 255, 255, 0.04); }
.table-modern tbody tr:hover {
    background: linear-gradient(90deg, rgba(236, 72, 153, 0.05), rgba(59, 130, 246, 0.03));
}
.table-modern tbody td { padding: 0.7rem 0.75rem; vertical-align: middle; }

/* === TOAST SYSTEM (notifications globales) ============================= */
.toast-stack {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 22rem;
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    padding: 0.75rem 0.95rem;
    border-radius: 0.875rem;
    font-size: 0.8125rem;
    background: white;
    border: 1px solid #e5e7eb;
    box-shadow: 0 12px 24px -8px rgba(0, 0, 0, 0.18);
    animation: toast-in 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.dark .toast { background: #1f2937; border-color: #374151; color: #f3f4f6; }
.toast-icon {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
    margin-top: 0.05rem;
}
.toast.toast-success { border-left: 3px solid #10b981; }
.toast.toast-success .toast-icon { color: #10b981; }
.toast.toast-error   { border-left: 3px solid #ef4444; }
.toast.toast-error   .toast-icon { color: #ef4444; }
.toast.toast-info    { border-left: 3px solid #3b82f6; }
.toast.toast-info    .toast-icon { color: #3b82f6; }
.toast.toast-warn    { border-left: 3px solid #f59e0b; }
.toast.toast-warn    .toast-icon { color: #f59e0b; }
@keyframes toast-in {
    from { opacity: 0; transform: translateX(20px) scale(0.95); }
    to   { opacity: 1; transform: translateX(0) scale(1); }
}
.toast.toast-out { animation: toast-out 0.18s ease-in forwards; }
@keyframes toast-out {
    to { opacity: 0; transform: translateX(20px); }
}

/* === HOVER LIFT POUR CARDS CLIQUABLES ================================== */
.card-hover-lift {
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.card-hover-lift:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 22px -8px rgba(236, 72, 153, 0.18);
    border-color: rgba(236, 72, 153, 0.3);
}

/* === STATUS PILL (statuts avec couleur) ================================ */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.15rem 0.55rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.4;
}
.status-pill::before {
    content: '';
    width: 0.4rem;
    height: 0.4rem;
    border-radius: 9999px;
    background: currentColor;
}
.status-pill.is-success { background: rgba(16, 185, 129, 0.12); color: #047857; }
.status-pill.is-warn    { background: rgba(245, 158, 11, 0.12); color: #b45309; }
.status-pill.is-error   { background: rgba(239, 68, 68, 0.12);  color: #b91c1c; }
.status-pill.is-info    { background: rgba(59, 130, 246, 0.12); color: #1d4ed8; }
.status-pill.is-neutral { background: rgba(107, 114, 128, 0.12); color: #4b5563; }

/* === MODAL : ferme automatiquement au click sur backdrop ================ */
/* Helper JS-friendly : ajoute data-close-on-backdrop sur .modal-overlay */
.modal-overlay[data-close-on-backdrop] { cursor: pointer; }
.modal-overlay[data-close-on-backdrop] .modal-card { cursor: auto; }

/* === SCROLL-TO-TOP FAB =================================================== */
.fab-scroll-top {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 9999px;
    background: linear-gradient(135deg, #ec4899, #3b82f6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 18px -4px rgba(236, 72, 153, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 30;
    cursor: pointer;
    border: 0;
}
.fab-scroll-top.visible { opacity: 1; pointer-events: auto; }
.fab-scroll-top:hover { transform: scale(1.08); }

/* ============================================================================
   MOBILE RESPONSIVE — focus iPhone (390-430px viewport)
   ============================================================================ */

/* === iOS zoom fix : forcer 16px sur tous les inputs/textarea/select ===
   Safari iOS zoom in dès qu'un input a un font-size < 16px. On garantit min 16px
   pour les contrôles de formulaire — visible seulement à l'utilisateur (les
   form-input gardent leur look). */
@media (max-width: 768px) {
    input[type="text"], input[type="email"], input[type="password"],
    input[type="tel"], input[type="url"], input[type="search"],
    input[type="number"], input[type="date"], input[type="time"],
    textarea, select,
    .form-input, .form-textarea, .form-select {
        font-size: 16px !important;
    }
}

/* === Touch targets : min 44x44px (Apple HIG) sur boutons utilitaires === */
@media (max-width: 768px) {
    .btn-icon, button.btn-icon {
        min-width: 44px;
        min-height: 44px;
    }
    .btn, .btn-primary, button.btn-primary {
        min-height: 44px;
    }
    /* Tabs en pills : agrandir le padding pour facilité touch */
    .tab-pill {
        padding: 0.65rem 1rem;
        font-size: 0.875rem;
    }
}

/* === Modals : pleine largeur sur mobile, plus respirables === */
@media (max-width: 640px) {
    .modal-overlay { padding: 0; align-items: flex-end; }
    .modal-card {
        max-width: 100vw;
        width: 100%;
        max-height: 95vh;
        border-radius: 1.25rem 1.25rem 0 0;
        margin: 0;
        animation: modal-slide-up 0.25s ease-out;
    }
    @keyframes modal-slide-up {
        from { transform: translateY(100%); }
        to   { transform: translateY(0); }
    }
    .modal-header { padding: 0.875rem 1rem; }
    .modal-body   { padding: 1rem; }
    .modal-footer {
        padding: 0.75rem 1rem;
        flex-direction: column-reverse;
        gap: 0.5rem;
    }
    .modal-footer button, .modal-footer a {
        width: 100%;
        justify-content: center;
    }
    /* Modal generic Tailwind : inset-0 z-50 pattern */
    .fixed.inset-0.z-50 > div:first-child {
        max-width: 100vw !important;
        max-height: 95vh;
        border-radius: 1.25rem 1.25rem 0 0 !important;
    }
}

/* === Tables : sur mobile, transformer en cards verticales ===
   Utilise data-label sur les <td> pour afficher le titre de colonne au-dessus.
   Si data-label absent, fallback : juste empile les cellules sans label.
   À OPT-IN via .table-responsive sur le <table>. */
@media (max-width: 640px) {
    .table-responsive,
    .table-responsive thead,
    .table-responsive tbody,
    .table-responsive tr,
    .table-responsive td {
        display: block;
        width: 100%;
    }
    .table-responsive thead {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }
    .table-responsive tr {
        margin-bottom: 0.875rem;
        border: 1px solid rgba(0, 0, 0, 0.08);
        border-radius: 0.875rem;
        padding: 0.75rem;
        background: white;
    }
    .dark .table-responsive tr {
        background: rgba(31, 41, 55, 0.5);
        border-color: rgba(255, 255, 255, 0.08);
    }
    .table-responsive td {
        padding: 0.4rem 0;
        border: 0;
        text-align: left !important;
        position: relative;
    }
    .table-responsive td[data-label]::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.7rem;
        text-transform: uppercase;
        color: #6b7280;
        display: block;
        margin-bottom: 0.15rem;
    }
}

/* === Tables non-opt-in : forcer overflow-x: auto pour le scroll horizontal ===
   C'est le fallback pour les tables qui n'ont pas .table-responsive — au moins
   on évite l'écrasement et on permet le swipe horizontal. */
@media (max-width: 768px) {
    .dashboard-card .overflow-x-auto,
    table:not(.table-responsive) {
        -webkit-overflow-scrolling: touch;
    }
    /* Fallback : si un table parent n'a pas de wrapper scroll, on en ajoute */
    table:not(.table-responsive):not([class*="overflow"]) {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

/* === Page-header : empile titre+actions sur mobile + actions full-width === */
@media (max-width: 640px) {
    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    .page-header-actions {
        width: 100%;
        flex-wrap: wrap;
    }
    .page-header-actions > .btn-primary,
    .page-header-actions > .btn {
        flex: 1 1 auto;
    }
    .page-header-title {
        font-size: 1.25rem;
    }
}

/* === Stats cards 4-up : 2x2 sur mobile === */
@media (max-width: 640px) {
    .grid.grid-cols-2.md\:grid-cols-4,
    .grid.grid-cols-2.md\:grid-cols-5 {
        gap: 0.5rem;
    }
    .grid.md\:grid-cols-4 > .dashboard-card,
    .grid.md\:grid-cols-5 > .dashboard-card {
        padding: 0.625rem !important;
    }
    .stat-number, .kpi-value {
        font-size: 1.4rem !important;
    }
}

/* === Sidebar drawer : full-screen sur mobile, swipe-to-close-friendly === */
@media (max-width: 1024px) {
    #mobile-sidebar-container {
        max-width: 85vw;
        width: 320px;
    }
}

/* === Compose email : padding bottom + footer actions plus larges === */
@media (max-width: 640px) {
    .compose-stage { max-width: 100%; padding: 0 0.5rem; }
    .compose-letter { border-radius: 0.875rem; }
    .compose-header { padding: 16px 12px; }
    .compose-header img { max-width: 140px; max-height: 50px; }
    .compose-field { padding: 10px 14px; }
    .compose-field-label { width: 40px; font-size: 11px; }
    .editor-content { padding: 16px 14px; font-size: 16px; }
    .editor-toolbar { padding: 6px 10px; gap: 1px; }
    .editor-toolbar button { width: 30px; height: 30px; }
    /* Padding-bottom pour ne pas que le footer sticky cache du contenu */
    main { padding-bottom: 80px; }
}

/* === FAB scroll-top : décale au-dessus du footer mobile sticky === */
@media (max-width: 640px) {
    .fab-scroll-top {
        bottom: 5rem;
        right: 0.875rem;
    }
}

/* === Toast stack : largeur réduite + position safe sur iPhone notch === */
@media (max-width: 640px) {
    .toast-stack {
        bottom: env(safe-area-inset-bottom, 1rem);
        right: 0.5rem;
        left: 0.5rem;
        max-width: none;
    }
    .toast { width: 100%; }
}

/* === Picker prospects (modal énorme) : full-height sur mobile === */
@media (max-width: 640px) {
    #prospectsPickerModal > div {
        max-width: 100vw !important;
        max-height: 100vh !important;
        height: 100vh;
        border-radius: 0 !important;
    }
}

/* === Chip rows : scrollables horizontalement sur mobile === */
@media (max-width: 640px) {
    .chip-row, .tab-nav {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
        scrollbar-width: none;
    }
    .chip-row::-webkit-scrollbar, .tab-nav::-webkit-scrollbar { display: none; }
    .chip { flex-shrink: 0; }
}

/* === Canvas Chart.js : ne doit jamais déborder du conteneur ===
   Sur visiteurs/dashboard, les canvases Chart.js peuvent forcer le body à >viewport.
   On limite max-width: 100% partout. */
canvas {
    max-width: 100% !important;
    height: auto !important;
}

/* === Grid items : empêche les enfants de grow au-delà de leur cellule === */
@media (max-width: 768px) {
    .dashboard-card,
    .grid > * {
        min-width: 0;
    }
    /* Force les valeurs numériques à se truncate au lieu de pousser la largeur */
    .stat-number, .kpi-value, .text-2xl.font-bold {
        max-width: 100%;
        overflow-wrap: anywhere;
    }
}

/* === Anti-débordement global admin === */
@media (max-width: 768px) {
    main {
        max-width: 100vw;
        overflow-x: hidden;
    }
}
