/*
 * Page entreprise — couche mobile.
 * Chargée APRÈS analyse-styles.css : elle reprend la main sur les blocs
 * @media dispersés de ce fichier. Les correctifs mobiles vont ici.
 */

/* Unité collée au chiffre (« 59.7 % » et non « 59.7      % ») */
.ratio-value .number {
    min-width: 0;
}

/* ---------- Bandeau des chiffres clés (sous le H1) ---------- */
.kpi-band {
    display: flex;
    gap: 12px;
    margin: 16px 0 20px;
}

.kpi-band-item {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 14px;
    border: 1px solid var(--color-border, rgba(0, 0, 0, 0.08));
    border-radius: 10px;
    background: var(--color-bg-primary, #ffffff);
}

.kpi-band-label {
    font-size: 13px;
    color: var(--color-text-secondary, #5f6368);
}

.kpi-band-value {
    font-size: 22px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #1a1a1a;
}

.kpi-band-value.is-negative {
    color: #c5221f;
}

.kpi-band-var {
    font-size: 12px;
    font-weight: 600;
}

.kpi-band-var.is-up {
    color: #137333;
}

.kpi-band-var.is-down {
    color: #c5221f;
}

/* ---------- Avertissements regroupés et repliables ---------- */
.data-notices {
    margin: 0 0 24px;
    border: 1px solid #f0d58c;
    background: #fffaeb;
    border-radius: 8px;
    color: #6b5200;
    font-size: 14px;
    line-height: 1.5;
}

.data-notices > summary {
    cursor: pointer;
    padding: 10px 14px;
    list-style: none;
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
}

.data-notices > summary::-webkit-details-marker {
    display: none;
}

.data-notices > summary::after {
    content: "\25BE";
    margin-left: auto;
    transition: transform 0.2s;
}

.data-notices[open] > summary::after {
    transform: rotate(180deg);
}

.data-notices-title {
    font-weight: 600;
}

.data-notices > p {
    margin: 0;
    padding: 0 14px 10px 36px;
    position: relative;
}

.data-notices > p > i {
    position: absolute;
    left: 14px;
    top: 4px;
}

/* ---------- Actions des graphiques : pastilles compactes avec icône ---------- */
.chart-controls .button-container {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    width: auto;
}

.chart-controls button.action-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    width: auto;
    padding: 6px 12px;
    border-radius: 999px;
    background: #ffffff;
    border: 1px solid var(--color-border, rgba(0, 0, 0, 0.12));
    color: #3c4043;
    font-size: 13px;
    line-height: 1.2;
    white-space: nowrap;
}

.chart-controls button.action-button:hover {
    background: #f1f3f4;
    transform: none;
}

.chart-controls button.action-button::before {
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    font-size: 12px;
    color: #5f6368;
}

.chart-controls button[id^="export"]::before { content: "\f019"; }
.chart-controls button.toggle-button::before { content: "\f0ce"; }
.chart-controls #toggleViewButton::before { content: "\f00a"; }
.chart-controls #sectorYearSelectorToggle::before { content: "\f073"; }
.chart-controls #showSectorMeanButton::before { content: "\f201"; }

/* ---------- Historique financier : défilement propre, 1re colonne figée ---------- */
.seo-financial-wrap {
    margin-bottom: 24px;
}

.seo-financial-wrap .seo-financial-table {
    display: table;
    width: 100%;
    margin: 0;
    overflow: visible;
}

.seo-financial-table td.is-negative {
    color: #c5221f;
}

.seo-financial-table th[scope="row"],
.seo-financial-table thead th:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: #ffffff;
    box-shadow: 1px 0 0 var(--color-border, rgba(0, 0, 0, 0.08));
}

.seo-financial-table thead th:first-child {
    background: var(--color-bg-secondary, #fafafa);
}

.seo-financial-table caption {
    padding: 0 0 8px;
}

.seo-financial-note {
    display: none;
    margin: 0 0 6px;
    font-size: 12px;
    color: var(--color-text-muted, #666666);
}

/* ---------- Recherche mobile (loupe dans l'en-tête) ---------- */
.mobile-search-toggle {
    display: none;
}

@media (max-width: 768px) {
    .mobile-search-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        margin-right: 4px;
        border: none;
        border-radius: 50%;
        background: transparent;
        color: #1a1a1a;
        font-size: 18px;
        cursor: pointer;
    }

    .mobile-search-toggle:active {
        background: #f1f3f4;
    }

    /* Nom d'entreprise long : tronqué pour laisser la place à la loupe */
    .header-right {
        min-width: 0;
        flex: 1 1 auto;
        justify-content: flex-end;
    }

    .header .company-info {
        min-width: 0;
        overflow: hidden;
    }

    .header .company-name {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .more-info-btn,
    .mobile-search-toggle {
        flex-shrink: 0;
    }

    /* La barre de recherche s'ouvre sous l'en-tête fixe */
    .header.search-open .search-container {
        display: block;
        position: fixed;
        top: var(--nf-header-h, 64px);
        left: 0;
        right: 0;
        padding: 10px 12px;
        background: #ffffff;
        border-bottom: 1px solid rgba(0, 0, 0, 0.08);
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
        z-index: 1001;
    }

    .header.search-open .search-input-wrapper {
        display: flex;
        width: 100%;
        margin: 0;
    }

    .header.search-open .search-input {
        flex: 1 1 auto;
        min-width: 0;
        font-size: 16px; /* évite le zoom auto d'iOS */
    }

    .header.search-open .autocomplete-items {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        max-height: 60vh;
        overflow-y: auto;
    }
}

/* ---------- Onglets de sections (mobile) ---------- */
.section-tabs {
    display: none;
}

.smart-analysis-more {
    display: none;
}

@media (max-width: 768px) {
    .section-tabs {
        display: flex;
        gap: 4px;
        position: sticky;
        top: var(--nf-header-h, 56px);
        z-index: 900;
        margin: 0 -12px 12px;
        padding: 8px 12px;
        background: rgba(255, 255, 255, 0.97);
        border-bottom: 1px solid rgba(0, 0, 0, 0.08);
        overflow-x: auto;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    .section-tabs::-webkit-scrollbar {
        display: none;
    }

    .section-tabs a {
        flex: 0 0 auto;
        padding: 9px 13px;
        border-radius: 999px;
        font-size: 13px;
        font-weight: 500;
        color: #3c4043;
        text-decoration: none;
        white-space: nowrap;
    }

    .section-tabs a.active {
        background: #1a1a1a;
        color: #ffffff;
    }

    /* overflow-x: hidden sur html/body/main en fait des conteneurs de scroll
       et casse position: sticky ; clip coupe pareil sans ce défaut */
    @supports (overflow-x: clip) {
        html,
        body,
        .main-content {
            overflow-x: clip !important;
            overflow-y: visible !important;
        }
    }

    /* Les ancres ne passent plus sous l'en-tête + les onglets */
    main section[id] {
        scroll-margin-top: calc(var(--nf-header-h, 56px) + 56px);
    }
}

@media (max-width: 600px) {
    /* ---------- Gabarit : on rend la largeur au contenu ---------- */
    .main-content {
        width: 100%;
        padding: 12px 12px 24px;
        box-sizing: border-box;
    }

    .chart-container,
    .table-container,
    #compte-resultat > .chart-container {
        padding-left: 10px;
        padding-right: 10px;
    }

    /* ---------- Bandeaux d'alerte compacts ---------- */
    .data-quality-banner {
        padding: 10px 12px;
        margin-bottom: 14px;
        font-size: 13px;
        line-height: 1.45;
        gap: 8px;
    }

    .kpi-band {
        gap: 6px;
        margin: 12px 0 14px;
    }

    .kpi-band-item {
        padding: 8px 6px;
        text-align: center;
    }

    .kpi-band-label {
        font-size: 12px;
        line-height: 1.25;
    }

    .kpi-band-value {
        font-size: 16px;
    }

    .kpi-band-var {
        font-size: 12px;
    }

    .data-notices {
        font-size: 13px;
    }

    .seo-financial-table th,
    .seo-financial-table td {
        padding: 8px 8px;
        font-size: 13px;
    }

    /* La légende suit la largeur du tableau (qui défile) : on la masque
       visuellement et on affiche la note placée au-dessus */
    .seo-financial-table caption {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .seo-financial-note {
        display: block;
    }

    .seo-intro h1 {
        font-size: 22px;
        line-height: 1.25;
    }

    /* ---------- Textes d'analyse repliés ---------- */
    .smart-analysis {
        padding: 12px 14px;
    }

    .smart-analysis.is-clamped p {
        display: -webkit-box;
        -webkit-line-clamp: 4;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .smart-analysis-more {
        display: inline-block;
        margin-top: 4px;
        padding: 10px 0;
        min-height: 40px;
        border: none;
        background: none;
        color: var(--color-accent-blue, #2563eb);
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
    }

    /* ---------- KPI : 2 colonnes, cartes denses ---------- */
    .ratio-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .ratio-card {
        padding: 10px 8px;
        min-height: 0;
    }

    .ratio-card h3 {
        font-size: 13px;
        line-height: 1.3;
        margin-bottom: 4px;
    }

    .ratio-value {
        font-size: 17px;
        font-weight: 600;
        margin-top: 4px;
        word-break: break-word;
    }

    .ratio-value.ratio-na {
        font-size: 13px;
    }

    /* ---------- Tableaux P&L / bilan : tiennent dans l'écran ---------- */
    .table-scroll {
        margin: 0;
        padding: 0;
    }

    .pl-table {
        width: 100%;
        font-size: 13px;
    }

    .pl-table th,
    .pl-table td {
        padding: 7px 5px;
    }

    .pl-table th.pl-label,
    .pl-table td.pl-label {
        min-width: 0;
        max-width: none;
        font-size: 13px;
        white-space: normal;
        word-break: normal;
        overflow-wrap: anywhere;
        hyphens: auto;
    }

    .pl-table .pl-code {
        display: none;
    }

    .pl-table .pl-value {
        min-width: 0;
        font-size: 13px;
        white-space: nowrap;
    }

    .pl-table .pl-pct {
        min-width: 0;
        max-width: none;
        font-size: 12px;
    }

    /* Sparkline et variation : illisibles à cette taille */
    .pl-table .pl-sparkline,
    .pl-table .pl-sparkline-header,
    .pl-table .pl-var {
        display: none;
    }

    /* Encadré « En 2024, le compte de résultat détaillé n'est pas disponible » :
       les enfants flex ne rétrécissaient pas et sortaient de l'écran */
    .cr-recent-summary {
        padding: 10px 12px;
        gap: 8px;
    }

    .cr-recent-summary > * {
        flex: 1 1 100%;
        min-width: 0;
    }

    /* ---------- Graphiques ---------- */
    .chart-controls {
        flex-wrap: wrap;
        gap: 8px;
    }

    .chart-controls select {
        flex: 1 1 100%;
        max-width: 100%;
    }

    /* analyse-styles.css étire les boutons en pleine largeur sur mobile */
    .chart-controls .button-container {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        width: 100%;
        gap: 6px !important;
    }

    .chart-controls button.action-button {
        flex: 0 0 auto !important;
        width: auto !important;
        min-height: 0 !important;
        margin: 0 !important;
        padding: 7px 12px !important;
        font-size: 13px !important;
    }

    .chart-canvas-wrapper {
        height: 260px !important;
        min-height: 0 !important;
    }

    .chart-header h3 {
        font-size: 16px;
    }

    /* ---------- Cibles tactiles et petits textes ---------- */
    .gauge-tick-label {
        font-size: 12px !important;
    }

    .header .company-siren {
        font-size: 12px;
    }

    .liasse-badge {
        font-size: 12px;
    }

    .chart-controls button.action-button {
        min-height: 36px !important;
    }

    /* Curseurs de valorisation : piste de 6px et pouce de 18px, trop petits au doigt */
    .valorisation-slider {
        height: 10px;
        border-radius: 5px;
        margin: 12px 0;
    }

    .valorisation-slider::-webkit-slider-thumb {
        width: 28px;
        height: 28px;
    }

    .valorisation-slider::-moz-range-thumb {
        width: 28px;
        height: 28px;
    }

    .breadcrumb a,
    footer a {
        display: inline-block;
        padding: 6px 0;
    }
}
