/*
 * Améliorations responsive mobile initiales (itération 1)
 * Portée : affiner lisibilité < 768px, compacter header, améliorer scroll tables.
 * Prochaines itérations possibles : tables empilées (stack), masquage conditionnel de colonnes,
 * regroupement actions dans un menu, optimisation performance (prefers-reduced-motion).
 */

/* Règles génériques */
html, body {
    -webkit-text-size-adjust: 100%;
}

table.table.table-secrets .secrets-heading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

table.table.table-secrets .secrets-title {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
}

table.table.table-secrets .secrets-key {
    font-size: 0.78rem;
}

table.table.table-secrets .secrets-description {
    font-size: 0.78rem;
    color: var(--tblr-secondary-color);
}

table.table.table-secrets .secrets-label {
    display: none;
}

table.table.table-secrets .secrets-scope--inline {
    display: none;
}

/* Scroll doux + inertie mobile pour wrappers horizontaux */
.table-responsive, .timeline-content, .timeline-week {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.table-responsive::-webkit-scrollbar {
    height: 8px;
}
.table-responsive::-webkit-scrollbar-track {
    background: transparent;
}
.table-responsive::-webkit-scrollbar-thumb {
    background: var(--tblr-border-color);
    border-radius: 20px;
}

/* Utilitaire edge-fade pour scroll horizontal (à appliquer sur wrappers si besoin) */
.edge-fade {
    position: relative;
    --fade-color: var(--tblr-body-bg);
    mask-image: linear-gradient(90deg, transparent 0, #000 28px, #000 calc(100% - 28px), transparent 100%);
}

/* < 900px : resserrer les paddings principaux */
@media (max-width: 900px) {
    .main {
        padding: 1.25rem clamp(0.8rem, 3vw, 1.6rem);
    }
}

/* < 768px : cartes en grille 2 colonnes auto au lieu de row-deck horizontale serrée */
@media (max-width: 768px) {
    .row.row-deck {
        --gap: 0.9rem;
        display: grid;
        gap: var(--gap);
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    }
    .page-header .row.align-items-center {
        row-gap: 0.75rem;
    }
    .page-header .col-auto {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .card.card-sm .h2 { /* réduire taille sur mini-cartes */
        font-size: 1.35rem;
    }
}

/* < 640px : déjà partiellement couvert dans main.css, on complète */
@media (max-width: 640px) {
    .topbar {
        height: 56px;
    }
    .topbar__actions .btn, #logout-btn.btn {
        min-width: 38px;
    }
    .page-header h2.page-title {
        font-size: 1.15rem;
    }
    .page-header .text-secondary {
        font-size: 0.78rem;
    }
    /* Formulaire filtres runs : une seule colonne */
    #runs-filter.row.g-3 > [class^="col-"],
    #runs-filter.row.g-3 > [class*=" col-"] {
        flex: 1 1 100%;
        max-width: 100%;
    }
    #runs-filter .btn.w-100 { margin-top: 0.25rem; }
    /* Portfolio résumé : passer en grille 2 colonnes si suffisamment de largeur */
    #portfolio-summary .row, #portfolio-summary.row {
        display: grid;
        gap: 0.75rem;
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}

/* < 520px : empiler totalement certains ensembles d'actions */
@media (max-width: 520px) {
    .page-header .col-auto {
        width: 100%;
        justify-content: flex-start;
    }
    .page-header .col-auto .btn {
        flex: 1 1 auto;
    }
    /* Boutons multiples → largeur égale */
    .page-header .col-auto.d-flex.gap-2 .btn {
        min-width: 0;
    }
    /* Tableaux : réduire padding cellules */
    table.table td, table.table th {
        padding: 0.4rem 0.55rem;
        font-size: 0.72rem;
    }
    /* Code erreurs runs : wrap */
    #runs-table code { white-space: pre-wrap; word-break: break-word; }
}

/* Mode stack tables administratives (<768px) : chaque ligne devient une carte */
@media (max-width: 768px) {
    table.table.table-stack thead { display: none; }
    table.table.table-stack tbody tr {
        display: block;
        margin-bottom: 0.75rem;
        border: 1px solid var(--tblr-border-color);
        border-radius: 0.75rem;
        padding: 0.55rem 0.75rem;
        background: var(--tblr-bg-surface);
        box-shadow: var(--tblr-shadow-xs, 0 1px 2px rgba(0,0,0,0.06));
    }
    table.table.table-stack tbody tr:last-child { margin-bottom: 0; }
    table.table.table-stack tbody td {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 1rem;
        padding: 0.25rem 0 !important;
        border: 0;
        font-size: 0.72rem;
    }
    table.table.table-stack tbody td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        font-weight: 600;
        color: var(--tblr-secondary-color);
        text-transform: none;
        letter-spacing: 0;
        max-width: 50%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    table.table.table-stack tbody td[data-label='Erreur'] code {
        white-space: pre-wrap;
        word-break: break-word;
    }
    /* Accent status badge: étirer à droite */
    table.table.table-stack tbody td .badge { margin-left: auto; }
    /* Actions en bas : pleine largeur */
    table.table.table-stack tbody td[data-label="Actions"] {
        padding-top: 0.45rem !important;
        border-top: 1px dashed var(--tblr-border-color);
        justify-content: flex-start;
        gap: 0.4rem;
    }

    /* Secrets : mise en page verticale pour exploiter toute la largeur */
    table.table.table-secrets tbody tr {
        display: flex;
        flex-direction: column;
        gap: 0.6rem;
        padding: 0.65rem 0.75rem;
    }
    table.table.table-secrets tbody tr + tr {
        margin-top: 0.35rem;
    }
    table.table.table-secrets tbody td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.45rem;
        padding: 0;
        border: 0;
        font-size: 0.74rem;
    }
    table.table.table-secrets tbody td::before {
        display: none;
    }
    table.table.table-secrets .secrets-label {
        display: inline-flex;
        font-size: 0.63rem;
        letter-spacing: 0.05em;
        text-transform: uppercase;
        color: var(--tblr-secondary-color);
    }
    table.table.table-secrets .secrets-cell--name {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }
    table.table.table-secrets .secrets-heading {
        width: 100%;
        align-items: flex-start;
        justify-content: space-between;
        gap: 0.6rem;
    }
    table.table.table-secrets .secrets-title {
        font-size: 0.82rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.15rem;
    }
    table.table.table-secrets .secrets-key {
        font-size: 0.7rem;
        word-break: break-word;
    }
    table.table.table-secrets .secrets-description {
        font-size: 0.68rem;
    }
    table.table.table-secrets .secrets-scope--inline {
        display: inline-flex;
        font-size: 0.68rem;
    }
    table.table.table-secrets .secrets-cell--scope {
        display: none !important;
    }
    table.table.table-secrets .secrets-cell--status {
        justify-content: flex-start;
    }
    table.table.table-secrets .secrets-cell--status .badge {
        margin-left: auto;
    }
    table.table.table-secrets .secrets-cell--actions {
        flex-direction: column;
        align-items: stretch;
        gap: 0.4rem;
        text-align: left;
    }
    table.table.table-secrets .secrets-cell--actions .btn {
        width: 100%;
    }
    table.table.table-secrets .badge {
        font-size: 0.66rem;
        padding: 0.3rem 0.55rem;
    }
}

/* < 450px : masquer textes secondaires non essentiels */
@media (max-width: 450px) {
    .brand-title { font-size: 1rem; }
    .timeline-axis span:nth-child(2),
    .timeline-axis span:nth-child(4) { /* ne garder que 00h 12h 24h */
        display: none;
    }
    .timeline-axis { font-size: 0.65rem; }
    .timeline-legend { font-size: 0.7rem; }
    .timeline-bar { font-size: 0.62rem; }
    /* Diff JSON trop large -> scroll auto */
    #config-diff, #config-version-diff {
        max-height: 300px;
        font-size: 0.62rem;
    }
}

/* < 380px : fallback ultra compact */
@media (max-width: 380px) {
    .topbar__brand .brand-icon { font-size: 1.4rem; }
    .topbar__brand { gap: 0.4rem; }
    .topbar { padding: 0 0.6rem; }
    .sidebar { width: 230px; }
    .card .card-title { font-size: 0.95rem; }
    .card.card-sm .h2 { font-size: 1.15rem; }
}

/* Accessibilité : contraste focus amélioré */
:focus-visible {
    outline: 2px solid var(--tblr-primary);
    outline-offset: 2px;
}
