/* ============================================================
   OUTILS D'ANALYSES AVANCÉES — #section-advanced
   S'appuie sur les variables de dashboard-v3.css
   ============================================================ */
#section-advanced {
    --at-radius: 14px;
    --at-border: var(--border-color, #E5E7EB);
    --at-text: var(--text-dark, #1F2937);
    --at-muted: var(--text-gray, #6B7280);
    --at-orange: var(--ci-orange, #FF8200);
    --at-green: var(--ci-green, #009A44);
    --at-navy: #1E3A8A;
    --at-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--at-text);
}
.at-root { max-width: 1440px; margin: 0 auto; min-width: 0; }
.at-root *, .at-root *::before, .at-root *::after { box-sizing: border-box; }

/* ---------- En-tête ---------- */
.at-header {
    display: flex; gap: 1.5rem; align-items: flex-end; justify-content: space-between;
    flex-wrap: wrap; margin-bottom: 1.25rem;
}
.at-header-text { flex: 1 1 420px; min-width: 0; }
.at-eyebrow {
    display: inline-flex; align-items: center; gap: .4rem; font-size: .72rem; font-weight: 700;
    letter-spacing: .06em; text-transform: uppercase; color: var(--at-orange);
    background: #FFF4E6; border-radius: 999px; padding: .25rem .65rem;
}
.at-title { font-size: 1.6rem; font-weight: 800; margin: .55rem 0 .3rem; letter-spacing: -.01em; }
.at-subtitle { margin: 0; color: var(--at-muted); font-size: .9rem; line-height: 1.5; max-width: 720px; }
.at-presets { flex: 1 1 380px; min-width: 0; }
.at-presets-label { display: block; font-size: .72rem; font-weight: 600; color: var(--at-muted); margin-bottom: .4rem; text-transform: uppercase; letter-spacing: .05em; }
.at-presets-list { display: flex; flex-wrap: wrap; gap: .4rem; }
.at-chip {
    display: inline-flex; align-items: center; gap: .45rem; border: 1px solid var(--at-border);
    background: #fff; color: var(--at-text); font: 500 .8rem/1.2 'Inter', sans-serif;
    padding: .45rem .75rem; border-radius: 999px; cursor: pointer; transition: all .15s; text-align: left;
}
.at-chip i { color: var(--at-orange); font-size: .78rem; }
.at-chip:hover { border-color: #FDBA74; background: #FFF7ED; color: #9A3412; }

/* ---------- Onglets d'outils ---------- */
.at-tools {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .5rem;
    background: #fff; border: 1px solid var(--at-border); border-radius: var(--at-radius);
    padding: .4rem; box-shadow: var(--at-shadow); margin-bottom: 1.25rem;
}
.at-tool {
    display: flex; align-items: center; gap: .7rem; border: 0; background: transparent; cursor: pointer;
    padding: .65rem .8rem; border-radius: 10px; text-align: left; color: var(--at-text);
    font-family: inherit; transition: background .15s, color .15s; min-width: 0;
}
.at-tool > i {
    width: 34px; height: 34px; flex: 0 0 34px; border-radius: 9px; display: grid; place-items: center;
    background: #F3F4F6; color: var(--at-muted); font-size: .9rem; transition: all .15s;
}
.at-tool span { display: flex; flex-direction: column; min-width: 0; }
.at-tool b { font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.at-tool small { font-size: .7rem; color: var(--at-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.at-tool:hover { background: #F9FAFB; }
.at-tool.active { background: #FFF7ED; }
.at-tool.active > i { background: var(--at-orange); color: #fff; box-shadow: 0 4px 10px rgba(255, 130, 0, .3); }
.at-tool.active b { color: #9A3412; }

/* ---------- Espace de travail ---------- */
.at-workspace { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.at-panel {
    background: #fff; border: 1px solid var(--at-border); border-radius: var(--at-radius);
    box-shadow: var(--at-shadow); position: sticky; top: 0; min-width: 0;
}
.at-panel-inner { padding: 1rem; display: flex; flex-direction: column; gap: 1rem; }
.at-panel-sec + .at-panel-sec { border-top: 1px solid #F3F4F6; padding-top: 1rem; }
.at-panel-sec:empty { display: none; }
.at-slot-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--at-muted); margin-bottom: .5rem; display: flex; align-items: center; justify-content: space-between; }
.at-count { font-weight: 600; color: var(--at-orange); text-transform: none; letter-spacing: 0; }
.at-slot + .at-swap { margin: .4rem 0; }
.at-slot-card:empty { display: none; }
.at-slot-card { margin-bottom: .5rem; }
.at-swap {
    display: inline-flex; align-items: center; gap: .4rem; border: 1px dashed #D1D5DB; background: #fff;
    border-radius: 8px; padding: .3rem .6rem; font: 500 .75rem 'Inter', sans-serif; color: var(--at-muted); cursor: pointer;
}
.at-swap:hover { color: var(--at-orange); border-color: #FDBA74; }

/* Carte indicateur */
.at-ind {
    border: 1px solid var(--at-border); border-radius: 10px; padding: .65rem .75rem; background: #FAFAFB;
    position: relative; min-width: 0;
}
.at-ind.has-dot { border-left: 4px solid var(--dot); }
.at-ind + .at-ind { margin-top: .5rem; }
.at-ind-top { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; margin-bottom: .35rem; padding-right: 1.4rem; }
.at-ind-role { font-size: .68rem; font-weight: 700; color: var(--at-text); }
.at-ind-name { font-size: .84rem; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.at-ind-meta { font-size: .72rem; color: var(--at-muted); margin-top: .3rem; line-height: 1.5; overflow-wrap: anywhere; }
.at-ind-meta code, .at-dd-meta code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .68rem; background: #F3F4F6; padding: .05rem .3rem; border-radius: 4px; color: #4B5563; }
.at-ind-unit { font-style: italic; }
.at-ind-x { position: absolute; top: .45rem; right: .45rem; border: 0; background: transparent; color: #9CA3AF; cursor: pointer; width: 24px; height: 24px; border-radius: 6px; }
.at-ind-x:hover { background: #FEE2E2; color: #DC2626; }
.at-ind-loading { display: grid; place-items: center; min-height: 64px; }
.at-warn-txt { color: #B45309; }
.at-cmp-list { margin-bottom: .6rem; }

/* Badges source */
.at-badge {
    display: inline-flex; align-items: center; font-size: .64rem; font-weight: 700; letter-spacing: .02em;
    color: var(--b, #0071BC); background: color-mix(in srgb, var(--b, #0071BC) 11%, #fff);
    border: 1px solid color-mix(in srgb, var(--b, #0071BC) 25%, #fff);
    padding: .08rem .42rem; border-radius: 999px; white-space: nowrap;
}
.at-badge-proj { --b: #9333EA; }

/* Sélecteur */
.at-picker { position: relative; }
.at-picker-field { position: relative; }
.at-picker-field i { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: #9CA3AF; font-size: .8rem; }
.at-picker-field input {
    width: 100%; border: 1px solid #D1D5DB; border-radius: 10px; padding: .6rem .75rem .6rem 2.1rem;
    font: 400 .85rem 'Inter', sans-serif; color: var(--at-text); background: #fff; outline: none; transition: border .15s, box-shadow .15s;
}
.at-picker-field input:focus { border-color: var(--at-orange); box-shadow: 0 0 0 3px rgba(255, 130, 0, .15); }
.at-picker-field input:disabled { background: #F9FAFB; cursor: not-allowed; }
.at-picker-dd {
    position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 60; background: #fff;
    border: 1px solid var(--at-border); border-radius: 12px; box-shadow: 0 12px 32px rgba(16, 24, 40, .14);
    max-height: 360px; overflow-y: auto; padding: .3rem; width: max(100%, min(520px, calc(100vw - 2rem)));
}
.at-dd-title { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--at-muted); padding: .4rem .55rem .2rem; }
.at-dd-item {
    display: block; width: 100%; text-align: left; border: 0; background: transparent; cursor: pointer;
    padding: .5rem .55rem; border-radius: 8px; font-family: inherit;
}
.at-dd-item:hover, .at-dd-item.active { background: #FFF7ED; }
.at-dd-name { display: block; font-size: .82rem; font-weight: 500; color: var(--at-text); line-height: 1.35; }
.at-dd-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin-top: .25rem; }
.at-dd-unit { font-size: .68rem; color: var(--at-muted); }
.at-dd-empty { padding: .9rem; font-size: .82rem; color: var(--at-muted); text-align: center; }

/* Champs */
.at-field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .8rem; min-width: 0; }
.at-field > span { font-size: .76rem; font-weight: 600; color: #374151; }
.at-field select {
    width: 100%; border: 1px solid #D1D5DB; border-radius: 9px; padding: .5rem .6rem; font: 400 .83rem 'Inter', sans-serif;
    background: #fff; color: var(--at-text); outline: none;
}
.at-field select:focus { border-color: var(--at-orange); box-shadow: 0 0 0 3px rgba(255, 130, 0, .15); }
.at-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.at-seg { display: flex; background: #F3F4F6; border-radius: 9px; padding: 3px; gap: 2px; }
.at-seg button {
    flex: 1; border: 0; background: transparent; padding: .42rem .4rem; border-radius: 7px; cursor: pointer;
    font: 500 .76rem 'Inter', sans-serif; color: var(--at-muted); white-space: nowrap; transition: all .15s;
}
.at-seg button.active { background: #fff; color: var(--at-text); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.at-check { display: flex; gap: .55rem; align-items: flex-start; font-size: .8rem; cursor: pointer; margin-bottom: .6rem; }
.at-check input { accent-color: var(--at-orange); margin-top: .15rem; width: 15px; height: 15px; flex: 0 0 15px; }
.at-check small { display: block; color: var(--at-muted); font-size: .72rem; margin-top: .1rem; }
.at-hint { font-size: .74rem; color: var(--at-muted); line-height: 1.45; margin: .2rem 0 0; }
.at-hint i { color: #9CA3AF; margin-right: .2rem; }

/* ---------- Résultats ---------- */
.at-results { min-width: 0; display: flex; flex-direction: column; gap: 1rem; }
.at-res-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.at-res-head h3 { margin: 0; font-size: 1.15rem; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.at-res-head p { margin: .25rem 0 0; font-size: .78rem; color: var(--at-muted); line-height: 1.5; }
.at-tag-proj { display: inline-block; margin-left: .3rem; color: #6B21A8; background: #F5F3FF; border-radius: 6px; padding: 0 .4rem; }
.at-btn {
    display: inline-flex; align-items: center; gap: .45rem; border-radius: 9px; padding: .5rem .8rem; cursor: pointer;
    font: 600 .78rem 'Inter', sans-serif; white-space: nowrap; flex-shrink: 0;
}
.at-btn-ghost { background: #fff; border: 1px solid var(--at-border); color: var(--at-text); }
.at-btn-ghost i { color: var(--at-green); }
.at-btn-ghost:hover { border-color: #86EFAC; background: #F0FDF4; }

.at-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; }
.at-kpi {
    background: #fff; border: 1px solid var(--at-border); border-radius: 12px; padding: .8rem .9rem;
    display: flex; flex-direction: column; gap: .15rem; box-shadow: var(--at-shadow); border-top: 3px solid #E5E7EB; min-width: 0;
}
.at-kpi.pos { border-top-color: var(--at-green); }
.at-kpi.neg { border-top-color: var(--at-orange); }
.at-kpi.navy { border-top-color: var(--at-navy); }
.at-kpi.violet { border-top-color: #9333EA; }
.at-kpi.green { border-top-color: var(--at-green); }
.at-kpi-label { font-size: .72rem; font-weight: 600; color: var(--at-muted); }
.at-kpi-value { font-size: 1.3rem; font-weight: 800; letter-spacing: -.01em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.at-kpi-sub { font-size: .7rem; color: var(--at-muted); line-height: 1.35; }

.at-card { background: #fff; border: 1px solid var(--at-border); border-radius: var(--at-radius); box-shadow: var(--at-shadow); padding: 1rem 1rem .6rem; min-width: 0; }
.at-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .4rem; }
.at-card-head h4 { margin: 0; font-size: .88rem; font-weight: 700; }
.at-chart { width: 100%; height: 280px; }
.at-card-lg .at-chart { height: 380px; }
.at-grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.at-grid2 .at-card-lg .at-chart { height: 360px; }

.at-table-wrap { overflow-x: auto; margin: 0 -.25rem .4rem; }
.at-table { width: 100%; border-collapse: collapse; font-size: .8rem; font-variant-numeric: tabular-nums; }
.at-table th { text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--at-muted); font-weight: 700; padding: .5rem; border-bottom: 1px solid var(--at-border); white-space: nowrap; }
.at-table td { padding: .5rem; border-bottom: 1px solid #F3F4F6; vertical-align: top; }
.at-table tr:last-child td { border-bottom: 0; }
.at-muted { color: var(--at-muted); font-size: .9em; }
.at-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--dot); margin-right: .45rem; vertical-align: 1px; }

.at-interpret {
    display: flex; gap: .9rem; background: linear-gradient(135deg, #FFF7ED 0%, #FFFFFF 70%);
    border: 1px solid #FED7AA; border-radius: var(--at-radius); padding: 1rem 1.1rem;
}
.at-interpret-icon { width: 34px; height: 34px; flex: 0 0 34px; border-radius: 10px; background: var(--at-orange); color: #fff; display: grid; place-items: center; }
.at-interpret h5 { margin: .35rem 0 .45rem; font-size: .9rem; font-weight: 700; color: #9A3412; }
.at-interpret p { margin: 0 0 .55rem; font-size: .86rem; line-height: 1.6; color: #374151; }
.at-interpret p:last-child { margin-bottom: 0; }

.at-method { background: #fff; border: 1px solid var(--at-border); border-radius: var(--at-radius); }
.at-method summary { cursor: pointer; padding: .8rem 1rem; font-size: .84rem; font-weight: 600; color: #374151; list-style: none; display: flex; align-items: center; gap: .5rem; }
.at-method summary::-webkit-details-marker { display: none; }
.at-method summary::after { content: '\f078'; font-family: 'Font Awesome 6 Free'; font-weight: 900; margin-left: auto; font-size: .7rem; color: #9CA3AF; transition: transform .2s; }
.at-method[open] summary::after { transform: rotate(180deg); }
.at-method summary i { color: var(--at-green); }
.at-method-body { padding: 0 1rem 1rem; font-size: .8rem; line-height: 1.6; color: #4B5563; }
.at-method-body ul { margin: 0; padding-left: 1.1rem; }
.at-method-body li { margin-bottom: .45rem; }

.at-alert { display: flex; gap: .7rem; padding: .75rem .9rem; border-radius: 12px; font-size: .82rem; line-height: 1.55; border: 1px solid; }
.at-alert > i { margin-top: .2rem; }
.at-alert-warn { background: #FFFBEB; border-color: #FDE68A; color: #78350F; }
.at-alert-warn > i { color: #D97706; }
.at-alert-info { background: #F0F9FF; border-color: #BAE6FD; color: #0C4A6E; }
.at-alert-info > i { color: #0284C7; }
.at-alert-danger { background: #FEF2F2; border-color: #FECACA; color: #7F1D1D; }
.at-alert-danger > i { color: #DC2626; }
.at-banner {
    display: flex; gap: .7rem; align-items: flex-start; padding: .75rem .9rem; border-radius: 12px; font-size: .82rem; line-height: 1.5;
    background: repeating-linear-gradient(-45deg, #F8FAFC, #F8FAFC 10px, #F1F5F9 10px, #F1F5F9 20px); border: 1px dashed #94A3B8; color: #334155;
}
.at-banner i { color: var(--at-navy); margin-top: .15rem; }

.at-empty { background: #fff; border: 1px dashed #D1D5DB; border-radius: var(--at-radius); padding: 2.5rem 1.5rem; text-align: center; }
.at-empty-icon { width: 60px; height: 60px; border-radius: 18px; background: #FFF7ED; color: var(--at-orange); display: grid; place-items: center; margin: 0 auto 1rem; font-size: 1.4rem; }
.at-empty h3 { margin: 0 0 .4rem; font-size: 1.05rem; }
.at-empty p { margin: 0 auto 1.1rem; max-width: 520px; color: var(--at-muted); font-size: .86rem; line-height: 1.55; }
.at-empty-presets { display: flex; flex-wrap: wrap; gap: .45rem; justify-content: center; }
.at-loading { display: flex; align-items: center; gap: .6rem; justify-content: center; padding: 3rem; color: var(--at-muted); font-size: .86rem; background: #fff; border-radius: var(--at-radius); border: 1px solid var(--at-border); }
.at-spinner { width: 18px; height: 18px; border: 2.5px solid #FED7AA; border-top-color: var(--at-orange); border-radius: 50%; animation: at-spin .8s linear infinite; display: inline-block; }
@keyframes at-spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
    .at-tools { grid-template-columns: repeat(5, minmax(0, 1fr)); }
    .at-tool small { display: none; }
    .at-workspace { grid-template-columns: 290px minmax(0, 1fr); }
}
@media (max-width: 1100px) {
    .at-grid2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 960px) {
    .at-workspace { grid-template-columns: minmax(0, 1fr); }
    .at-panel { position: static; }
    .at-panel-inner { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
    .at-panel-sec + .at-panel-sec { border-top: 0; padding-top: 0; }
}
@media (max-width: 768px) {
    .at-header { gap: 1rem; margin-bottom: 1rem; }
    .at-title { font-size: 1.25rem; }
    .at-subtitle { font-size: .82rem; }
    .at-presets-list { flex-wrap: nowrap; overflow-x: auto; padding-bottom: .25rem; scrollbar-width: none; margin: 0 -.75rem; padding-left: .75rem; padding-right: .75rem; }
    .at-presets-list::-webkit-scrollbar { display: none; }
    .at-chip { white-space: nowrap; flex-shrink: 0; }
    .at-tools { display: flex; overflow-x: auto; scrollbar-width: none; padding: .3rem; gap: .25rem; }
    .at-tools::-webkit-scrollbar { display: none; }
    .at-tool { flex: 0 0 auto; padding: .5rem .65rem; gap: .5rem; }
    .at-tool > i { width: 28px; height: 28px; flex-basis: 28px; font-size: .8rem; }
    .at-tool b { font-size: .8rem; }
    .at-panel-inner { grid-template-columns: minmax(0, 1fr); }
    .at-panel-sec + .at-panel-sec { border-top: 1px solid #F3F4F6; padding-top: 1rem; }
    .at-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
    .at-kpi { padding: .65rem .7rem; }
    .at-kpi-value { font-size: 1.05rem; }
    .at-card { padding: .8rem .7rem .4rem; }
    .at-chart { height: 250px; }
    .at-card-lg .at-chart, .at-grid2 .at-card-lg .at-chart { height: 310px; }
    .at-res-head { flex-direction: column; gap: .6rem; }
    .at-interpret { padding: .85rem; gap: .6rem; }
    .at-interpret-icon { width: 28px; height: 28px; flex-basis: 28px; font-size: .8rem; }
    .at-interpret p { font-size: .82rem; }
    .at-picker-dd { width: 100%; }
}
.at-hint-tight { margin: -.55rem 0 .8rem; }
