/* QuoteTek / CoOptek — Animation de chiffrage (V7 spotlight + liste) */

:root {
    --qt-co-blue-dark: #00233c;
    --qt-co-blue-mid:  #003d6a;
    --qt-co-blue:      #007cd5;
    --qt-co-orange:    #f97316;
}

.chiffrage-page {
    margin: 0;
    font-family: 'Ubuntu', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f3f4f6;
    color: #111;
    min-height: 100vh;
}

.chiffrage-stage {
    padding: 40px 20px;
    min-height: calc(100vh - 80px);
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.chiffrage-variant {
    width: 100%;
    max-width: 960px;
}

.ch-card {
    background: #fff;
    border-radius: 20px;
    padding: 32px 36px 28px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, .08);
}

.ch-head { text-align: center; margin-bottom: 24px; }
.ch-head h2 { margin: 0 0 4px; font-size: 1.35rem; font-weight: 700; }
.ch-head .sub { color: #6b7280; font-size: .95rem; }

.ch-spotlight {
    position: relative;
    padding: 24px 28px;
    border-radius: 16px;
    background: linear-gradient(135deg, #e8f4fb 0%, #f2faff 100%);
    border: 1px solid #b6dff5;
    margin-bottom: 20px;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 24px;
    min-height: 110px;
}

.ch-spot-main .ch-spot-label {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--qt-co-blue-mid);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.ch-spot-main .ch-spot-label .dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--qt-co-orange);
    animation: ch-pulse-live 1s ease infinite;
}
.ch-spot-ref-line { display: flex; align-items: baseline; gap: 14px; margin-bottom: 4px; flex-wrap: wrap; }
.ch-spot-ref { font-size: 1.6rem; font-weight: 800; color: #111; font-family: 'Fira Code', Consolas, Monaco, monospace; }
.ch-spot-mpn { font-family: 'Fira Code', Consolas, Monaco, monospace; color: #374151; font-size: .92rem; word-break: break-all; }
.ch-spot-desc { color: #6b7280; font-size: .88rem; min-height: 1.3em; }

.ch-spot-loader { display: flex; align-items: center; justify-content: center; padding: 0 12px; }
.ch-loader-ring {
    display: inline-block;
    width: 32px; height: 32px; border-radius: 50%;
    border: 3px solid #ffe2c2;
    border-top-color: var(--qt-co-orange);
    animation: ch-spin 0.9s linear infinite;
}

.ch-stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 18px;
}
.ch-stat {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    padding: 12px 14px;
    border-radius: 10px;
}
.ch-stat-label {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #9ca3af;
    margin-bottom: 2px;
}
.ch-stat-value { font-size: 1.25rem; font-weight: 700; color: #111; }
.ch-stat.ok .ch-stat-value { color: #16a34a; }
.ch-stat.status .ch-status-val {
    font-size: .88rem;
    color: var(--qt-co-orange);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.ch-stat.status .ch-status-val::before {
    content: '';
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--qt-co-orange);
    animation: ch-pulse-live 1s ease infinite;
    flex-shrink: 0;
}

.ch-progress-wrap { margin-bottom: 18px; }
.ch-progress-label {
    display: flex;
    justify-content: space-between;
    font-size: .78rem;
    color: #6b7280;
    margin-bottom: 6px;
    font-weight: 500;
}
.ch-progress-label span:last-child { color: var(--qt-co-blue); font-weight: 700; }
.ch-progress-bar {
    height: 6px;
    background: #e5e7eb;
    border-radius: 3px;
    overflow: hidden;
}
.ch-progress-bar > div {
    height: 100%;
    background: linear-gradient(90deg, var(--qt-co-blue-dark), var(--qt-co-blue-mid) 45%, var(--qt-co-blue));
    width: 0;
    transition: width .3s ease;
}

.ch-list-title {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #9ca3af;
    margin-bottom: 10px;
}
.ch-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 240px;
    overflow: hidden;
}
.ch-list-item {
    display: grid;
    grid-template-columns: 32px 55px 180px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 9px 14px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    animation: ch-fade-in .4s ease;
    font-size: .85rem;
}
.ch-list-item.found { border-left: 3px solid #22c55e; }
.ch-list-item.nf    { border-left: 3px solid #dc2626; }
.ch-list-item .ch-status-icon {
    width: 22px; height: 22px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: .75rem; font-weight: 700;
}
.ch-list-item.found .ch-status-icon { background: #dcfce7; color: #16a34a; }
.ch-list-item.nf    .ch-status-icon { background: #fee2e2; color: #dc2626; }
.ch-list-item .ch-ref { font-weight: 700; font-family: 'Fira Code', Consolas, monospace; color: #111; }
.ch-list-item .ch-mpn { font-family: 'Fira Code', Consolas, monospace; color: #6b7280; font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-list-item .ch-desc { color: #9ca3af; font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-list-item .ch-price { font-weight: 700; color: #16a34a; font-family: 'Fira Code', Consolas, monospace; font-size: .85rem; text-align: right; }
.ch-list-item.nf .ch-price { color: #dc2626; font-weight: 500; font-style: italic; }

/* Fade progressif du 4ème item (dégradé vers le bas — effet "disparition") */
.ch-list .ch-list-item:nth-child(4) {
    opacity: .45;
    -webkit-mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0) 100%);
            mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0) 100%);
    pointer-events: none;
}

.ch-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: .66rem;
    font-weight: 600;
    margin-right: 6px;
}
.ch-badge.farnell { background: #fef3c7; color: #92400e; }
.ch-badge.mouser  { background: #dbeafe; color: #1e40af; }
.ch-badge.digikey { background: #fce7f3; color: #9f1239; }
.ch-badge.lcsc    { background: #dcfce7; color: #166534; }
.ch-badge.nexar   { background: #ede9fe; color: #5b21b6; }
.ch-badge.tme     { background: #fee2e2; color: #991b1b; }

/* État final / mode manuel */
.ch-done {
    display: none;
    text-align: center;
    padding: 48px 20px;
    animation: ch-fade-in .6s ease;
}
.ch-done.show { display: block; }
.ch-done-icon {
    width: 96px; height: 96px;
    border-radius: 50%;
    margin: 0 auto 24px;
    background: linear-gradient(135deg, #22c55e, #16a34a);
    display: flex; align-items: center; justify-content: center;
    font-size: 3rem;
    color: #fff;
    box-shadow: 0 20px 40px rgba(34, 197, 94, .3);
    animation: ch-pop-in .6s cubic-bezier(.34, 1.56, .64, 1);
}
.ch-done-icon.manual {
    background: linear-gradient(135deg, var(--qt-co-blue-mid), var(--qt-co-blue));
    box-shadow: 0 20px 40px rgba(0, 124, 213, .3);
}
.ch-done h2 { margin: 0 0 12px; font-size: 1.8rem; color: #111; }
.ch-done .ch-msg {
    color: #6b7280;
    font-size: 1.05rem;
    max-width: 560px;
    margin: 0 auto 24px;
    line-height: 1.6;
}
.ch-done .ch-ref-box {
    display: inline-block;
    padding: 16px 32px;
    background: #f9fafb;
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    margin-bottom: 24px;
}
.ch-done .ch-ref-box .label {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: #9ca3af;
}
.ch-done .ch-ref-box .value {
    font-family: 'Fira Code', Consolas, monospace;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--qt-co-blue);
    margin-top: 4px;
}
.ch-done .ch-actions { margin-top: 12px; display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.ch-done .ch-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    background: #fff;
    color: #374151;
    text-decoration: none;
    font-weight: 500;
    font-size: .95rem;
    transition: all .2s;
}
.ch-done .ch-btn:hover { background: #f3f4f6; }
.ch-done .ch-btn.primary {
    background: var(--qt-co-blue);
    color: #fff;
    border-color: var(--qt-co-blue);
}
.ch-done .ch-btn.primary:hover { background: var(--qt-co-blue-mid); }

/* Animations */
@keyframes ch-spin        { to { transform: rotate(360deg); } }
@keyframes ch-pulse-live  { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .4; transform: scale(1.3); } }
@keyframes ch-fade-in     { from { opacity: 0; } to { opacity: 1; } }
@keyframes ch-pop-in      { 0% { transform: scale(.5); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes ch-check-draw  { 0% { stroke-dashoffset: 60; } 100% { stroke-dashoffset: 0; } }
@keyframes ch-ring-fill   { 0% { stroke-dashoffset: 188.5; } 100% { stroke-dashoffset: 0; } }
@keyframes ch-finalize-spin { to { transform: rotate(360deg); } }

/* ─── Transition douce animation → état final (ticket #48) ────────
   Phase 1 : fade-out de la liste + stats + progress (500 ms)
   Phase 2 : morph du spotlight vers un bloc synthèse centré (≈ 500 ms)
   Phase 3 : apparition du bloc #ch-finish (gérée via .ch-finish-animate)
*/

/* Phase 1 : efface liste + stats + progression, spotlight conservé */
.ch-card.ch-transition-phase-1 .ch-list,
.ch-card.ch-transition-phase-1 .ch-list-title,
.ch-card.ch-transition-phase-1 .ch-stats-bar,
.ch-card.ch-transition-phase-1 .ch-progress-wrap,
.ch-card.ch-transition-phase-1 .ch-head {
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity .45s ease, transform .45s ease;
    pointer-events: none;
}

/* Le spotlight se recentre doucement */
.ch-card.ch-transition-phase-1 .ch-spotlight {
    transition: transform .5s ease, background .5s ease, border-color .5s ease, box-shadow .5s ease;
    transform: translateY(-4px) scale(1.01);
}

/* Phase 2 : morph du spotlight → progress-ring + checkmark */
.ch-card.ch-transition-phase-2 .ch-spotlight {
    background: linear-gradient(135deg, #e8f4fb 0%, #f2faff 100%);
    border-color: var(--qt-co-blue);
    box-shadow: 0 20px 40px rgba(0, 124, 213, .18);
    transform: translateY(-4px) scale(1.01);
}

.ch-card.ch-transition-phase-2 .ch-spot-main {
    opacity: 0;
    transition: opacity .3s ease;
}

/* Le loader orange fait place à un check bleu CoOptek qui scale-in */
.ch-card.ch-transition-phase-2 .ch-spot-loader .ch-loader-ring {
    animation: none;
    border-color: rgba(0, 124, 213, .18);
    border-top-color: var(--qt-co-blue);
    transform: scale(2.4);
    transition: transform .45s cubic-bezier(.34, 1.56, .64, 1), border-color .3s ease;
}

/* Petit check qui apparaît dans le ring agrandi (pseudo-élément) */
.ch-card.ch-transition-phase-2 .ch-spot-loader {
    position: relative;
}
.ch-card.ch-transition-phase-2 .ch-spot-loader::after {
    content: '✓';
    position: absolute;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%) scale(0);
    color: var(--qt-co-blue);
    font-weight: 700;
    font-size: 1.4rem;
    animation: ch-pop-in .4s cubic-bezier(.34, 1.56, .64, 1) .2s forwards;
}

/* Phase 3 : bloc final apparaît avec un léger slide + fade */
.ch-done.ch-finish-animate {
    animation: ch-fade-in .5s ease, ch-finish-slide-in .5s ease;
}
@keyframes ch-finish-slide-in {
    from { transform: translateY(10px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

/* Petit label "Chiffrage en finalisation" avec spinner dans le bloc final */
.ch-finalize {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    border-radius: 99px;
    background: rgba(0, 124, 213, .08);
    border: 1px solid rgba(0, 124, 213, .25);
    color: var(--qt-co-blue-mid);
    font-size: .85rem;
    font-weight: 600;
    margin: 4px auto 20px;
}
.ch-finalize .ch-finalize-spinner {
    display: inline-block;
    width: 14px; height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(0, 124, 213, .25);
    border-top-color: var(--qt-co-blue);
    animation: ch-finalize-spin .9s linear infinite;
    flex-shrink: 0;
}
[data-bs-theme="dark"] .ch-finalize {
    background: rgba(0, 124, 213, .14);
    border-color: rgba(0, 124, 213, .4);
    color: #8fc6ec;
}
[data-bs-theme="dark"] .ch-finalize .ch-finalize-spinner {
    border-color: rgba(0, 124, 213, .3);
    border-top-color: #4fa7e3;
}

/* Fade simple pour prefers-reduced-motion (pas de transform / pas de morph) */
.ch-card.ch-card-fade-out {
    opacity: 0;
    transition: opacity .25s linear;
}

@media (prefers-reduced-motion: reduce) {
    .ch-card.ch-transition-phase-1,
    .ch-card.ch-transition-phase-1 .ch-list,
    .ch-card.ch-transition-phase-1 .ch-list-title,
    .ch-card.ch-transition-phase-1 .ch-stats-bar,
    .ch-card.ch-transition-phase-1 .ch-progress-wrap,
    .ch-card.ch-transition-phase-1 .ch-head,
    .ch-card.ch-transition-phase-1 .ch-spotlight,
    .ch-card.ch-transition-phase-2 .ch-spotlight,
    .ch-card.ch-transition-phase-2 .ch-spot-main,
    .ch-card.ch-transition-phase-2 .ch-spot-loader .ch-loader-ring {
        transition: opacity .2s linear;
        transform: none;
        animation: none;
    }
    .ch-card.ch-transition-phase-2 .ch-spot-loader::after {
        animation: ch-fade-in .2s linear forwards;
        transform: translate(-50%, -50%) scale(1);
    }
    .ch-done.ch-finish-animate {
        animation: ch-fade-in .3s linear;
    }
    .ch-finalize .ch-finalize-spinner {
        animation: none;
    }
}

/* ─── Dark mode overrides ──────────────────────────────────── */
[data-bs-theme="dark"] .chiffrage-page {
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .ch-card {
    background: var(--bs-tertiary-bg);
    box-shadow: 0 20px 50px rgba(0, 0, 0, .45);
    border: 1px solid rgba(255, 255, 255, .06);
}

[data-bs-theme="dark"] .ch-head .sub {
    color: var(--bs-secondary-color);
}

[data-bs-theme="dark"] .ch-spotlight {
    background: linear-gradient(135deg, rgba(0, 124, 213, .12) 0%, rgba(0, 124, 213, .05) 100%);
    border: 1px solid rgba(0, 124, 213, .35);
}

[data-bs-theme="dark"] .ch-spot-main .ch-spot-label {
    color: #69b8ec;
}

[data-bs-theme="dark"] .ch-spot-ref {
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .ch-spot-mpn {
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .ch-spot-desc {
    color: var(--bs-secondary-color);
}

[data-bs-theme="dark"] .ch-loader-ring {
    border-color: rgba(249, 115, 22, .2);
    border-top-color: var(--qt-co-orange);
}

[data-bs-theme="dark"] .ch-stat {
    background: rgba(255, 255, 255, .04);
    border: 1px solid rgba(255, 255, 255, .08);
}

[data-bs-theme="dark"] .ch-stat-label {
    color: var(--bs-secondary-color);
}

[data-bs-theme="dark"] .ch-stat-value {
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .ch-stat.ok .ch-stat-value {
    color: #4ade80;
}

[data-bs-theme="dark"] .ch-progress-label {
    color: var(--bs-secondary-color);
}

[data-bs-theme="dark"] .ch-progress-label span:last-child {
    color: #4fa7e3;
}

[data-bs-theme="dark"] .ch-progress-bar {
    background: rgba(255, 255, 255, .08);
}

[data-bs-theme="dark"] .ch-list-title {
    color: var(--bs-secondary-color);
}

[data-bs-theme="dark"] .ch-list-item {
    background: rgba(255, 255, 255, .04);
    border: 1px solid rgba(255, 255, 255, .08);
}

[data-bs-theme="dark"] .ch-list-item .ch-ref {
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .ch-list-item .ch-mpn {
    color: var(--bs-secondary-color);
}

[data-bs-theme="dark"] .ch-list-item .ch-desc {
    color: var(--bs-secondary-color);
}

[data-bs-theme="dark"] .ch-list-item .ch-price {
    color: #4ade80;
}

[data-bs-theme="dark"] .ch-list-item.nf .ch-price {
    color: #f87171;
}

[data-bs-theme="dark"] .ch-list-item.found .ch-status-icon {
    background: rgba(34, 197, 94, .18);
    color: #4ade80;
}

[data-bs-theme="dark"] .ch-list-item.nf .ch-status-icon {
    background: rgba(220, 38, 38, .18);
    color: #f87171;
}

/* Supplier badges — dark variants (translucent tints) */
[data-bs-theme="dark"] .ch-badge.farnell { background: rgba(251, 191, 36, .18); color: #fcd34d; }
[data-bs-theme="dark"] .ch-badge.mouser  { background: rgba(59, 130, 246, .22); color: #93c5fd; }
[data-bs-theme="dark"] .ch-badge.digikey { background: rgba(236, 72, 153, .20); color: #f9a8d4; }
[data-bs-theme="dark"] .ch-badge.lcsc    { background: rgba(34, 197, 94, .20); color: #86efac; }
[data-bs-theme="dark"] .ch-badge.nexar   { background: rgba(139, 92, 246, .22); color: #c4b5fd; }
[data-bs-theme="dark"] .ch-badge.tme     { background: rgba(239, 68, 68, .20); color: #fca5a5; }

/* Done / manual finish state */
[data-bs-theme="dark"] .ch-done h2 {
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .ch-done .ch-msg {
    color: var(--bs-secondary-color);
}

[data-bs-theme="dark"] .ch-done .ch-ref-box {
    background: rgba(255, 255, 255, .04);
    border: 2px dashed rgba(255, 255, 255, .15);
}

[data-bs-theme="dark"] .ch-done .ch-ref-box .label {
    color: var(--bs-secondary-color);
}

[data-bs-theme="dark"] .ch-done .ch-ref-box .value {
    color: #4fa7e3;
}

[data-bs-theme="dark"] .ch-done .ch-btn {
    background: rgba(255, 255, 255, .04);
    border: 1px solid rgba(255, 255, 255, .15);
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .ch-done .ch-btn:hover {
    background: rgba(255, 255, 255, .08);
}

[data-bs-theme="dark"] .ch-done .ch-btn.primary {
    background: var(--qt-co-blue);
    border-color: var(--qt-co-blue);
    color: #fff;
}

[data-bs-theme="dark"] .ch-done .ch-btn.primary:hover {
    background: var(--qt-co-blue-mid);
    border-color: var(--qt-co-blue-mid);
}

@media (max-width: 640px) {
    .ch-card { padding: 20px 16px; }
    .ch-stats-bar { grid-template-columns: repeat(2, 1fr); }
    .ch-list-item { grid-template-columns: 28px 50px 1fr auto; gap: 8px; font-size: .78rem; }
    .ch-list-item .ch-mpn { display: none; }
    .ch-spotlight { grid-template-columns: 1fr; }
    .ch-spot-loader { justify-content: flex-start; }
}

/* ─── BOM complète client (#59) ─────────────────────────────────────────── */
.qt-bom-view { max-width: 100%; }
.qt-bom-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height .35s ease;
}
.qt-bom-body.open {
    max-height: 3000px; /* large enough for ~500 rows w/ scroll */
    overflow: auto;
}
.qt-bom-table { font-size: .85rem; }
.qt-bom-table th.sortable:hover { background: rgba(0,0,0,.03); }
.qt-bom-cards { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.qt-bom-card {
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 8px;
    padding: 10px 12px;
    background: var(--bs-body-bg, #fff);
}
.qt-bom-card.not-priced {
    border-left: 3px solid #ffc107;
    background: rgba(255, 193, 7, .06);
}
