/* ChallengeHub Design System — Retail SaaS Premium */

:root {
    --ch-bg: #f8fafc;
    --ch-bg-muted: #f1f5f9;
    --ch-surface: #ffffff;
    --ch-border: #e2e8f0;
    --ch-border-strong: #cbd5e1;
    --ch-text: #0f172a;
    --ch-text-muted: #64748b;
    --ch-primary: #4f46e5;
    --ch-primary-hover: #4338ca;
    --ch-accent: #06b6d4;
    --ch-fsm: #7c3aed;
    --ch-fsm-bg: #f5f3ff;
    --ch-fsm-border: #ddd6fe;
    --ch-trade-in: #059669;
    --ch-trade-in-bg: #ecfdf5;
    --ch-trade-in-border: #a7f3d0;
    --ch-discount: #ea580c;
    --ch-discount-bg: #fff7ed;
    --ch-discount-border: #fed7aa;
    --ch-bundle: #0891b2;
    --ch-bundle-bg: #ecfeff;
    --ch-bundle-border: #a5f3fc;
    --ch-success: #16a34a;
    --ch-success-bg: #f0fdf4;
    --ch-danger: #dc2626;
    --ch-danger-bg: #fef2f2;
    --ch-radius-sm: 0.5rem;
    --ch-radius: 0.75rem;
    --ch-radius-lg: 1rem;
    --ch-radius-xl: 1.25rem;
    --ch-shadow-sm: 0 1px 2px 0 rgb(15 23 42 / 0.04);
    --ch-shadow-card: 0 4px 6px -1px rgb(15 23 42 / 0.06), 0 2px 4px -2px rgb(15 23 42 / 0.04);
    --ch-shadow-hover: 0 12px 24px -8px rgb(15 23 42 / 0.1);
    --ch-header-h: 3.5rem;
    --ch-transition: 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-reduced-motion: reduce) {
    :root {
        --ch-transition: 0s;
    }
}

html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color: var(--ch-text);
    background-color: var(--ch-bg);
}

:focus-visible {
    outline: 2px solid var(--ch-primary);
    outline-offset: 2px;
}

/* Cards */
.ch-card {
    background: var(--ch-surface);
    border: 1px solid var(--ch-border);
    border-radius: var(--ch-radius-xl);
    box-shadow: var(--ch-shadow-sm);
}

.ch-card-hover {
    transition: box-shadow var(--ch-transition), transform var(--ch-transition), border-color var(--ch-transition);
}

.ch-card-hover:hover {
    box-shadow: var(--ch-shadow-hover);
    border-color: var(--ch-border-strong);
    transform: translateY(-2px);
}

.ch-card-hover:active {
    transform: translateY(0);
    transition-duration: 0.08s;
}

.ch-surface-muted {
    background: var(--ch-bg-muted);
}

/* Buttons */
.ch-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.25;
    border-radius: var(--ch-radius-lg);
    border: 1px solid transparent;
    transition: background-color var(--ch-transition), color var(--ch-transition), border-color var(--ch-transition), transform var(--ch-transition), box-shadow var(--ch-transition);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

.ch-btn:active {
    transform: scale(0.98);
}

.ch-btn,
.ch-nav-link,
a.ch-card-hover {
    touch-action: manipulation;
}

.ch-btn-primary {
    background: var(--ch-primary);
    color: #fff;
}

.ch-btn-primary:hover {
    background: var(--ch-primary-hover);
}

.ch-btn-secondary {
    background: var(--ch-surface);
    color: var(--ch-primary);
    border-color: var(--ch-border-strong);
}

.ch-btn-secondary:hover {
    background: var(--ch-bg-muted);
    border-color: var(--ch-primary);
}

.ch-btn-ghost {
    background: transparent;
    color: var(--ch-text-muted);
}

.ch-btn-ghost:hover {
    background: var(--ch-bg-muted);
    color: var(--ch-text);
}

.ch-btn-danger {
    background: var(--ch-danger-bg);
    color: var(--ch-danger);
    border-color: #fecaca;
}

.ch-btn-danger:hover {
    background: #fee2e2;
}

.ch-btn-block {
    width: 100%;
}

.ch-btn-sm {
    min-height: 2.25rem;
    padding: 0.375rem 0.875rem;
    font-size: 0.8125rem;
}

/* Form controls */
.ch-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--ch-text);
    margin-bottom: 0.375rem;
}

.ch-input,
.ch-select,
.ch-textarea {
    width: 100%;
    min-height: 2.75rem;
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    color: var(--ch-text);
    background: var(--ch-surface);
    border: 1px solid var(--ch-border-strong);
    border-radius: var(--ch-radius-lg);
    transition: border-color var(--ch-transition), box-shadow var(--ch-transition);
}

.ch-textarea {
    min-height: 5rem;
    resize: vertical;
}

.ch-input:focus,
.ch-select:focus,
.ch-textarea:focus {
    outline: none;
    border-color: var(--ch-primary);
    box-shadow: 0 0 0 3px rgb(79 70 229 / 0.15);
}

.ch-input::placeholder,
.ch-textarea::placeholder {
    color: #94a3b8;
}

/* Section titles */
.ch-section-title {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem 1rem;
    margin-bottom: 1rem;
    padding-left: 0.875rem;
    border-left: 4px solid var(--ch-primary);
}

.ch-section-title--discount {
    border-left-color: var(--ch-discount);
}

.ch-section-title--muted {
    border-left-color: #94a3b8;
}

.ch-section-title--fsm {
    border-left-color: var(--ch-fsm);
}

.ch-section-title--bundle {
    border-left-color: var(--ch-bundle);
}

.ch-section-title--trade-in {
    border-left-color: var(--ch-trade-in);
}

.ch-section-title h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--ch-text);
    line-height: 1.3;
}

.ch-section-title .ch-section-count {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ch-text-muted);
}

.ch-section-title .ch-section-desc {
    width: 100%;
    font-size: 0.875rem;
    color: var(--ch-text-muted);
    margin-top: 0.25rem;
    padding-left: 0;
    border: none;
}

/* Alerts */
.ch-alert {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-radius: var(--ch-radius-lg);
    font-size: 0.875rem;
    line-height: 1.5;
    margin-bottom: 1rem;
}

.ch-alert-success {
    background: var(--ch-success-bg);
    color: #166534;
    border: 1px solid #bbf7d0;
}

.ch-alert-error {
    background: var(--ch-danger-bg);
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* Article card variants */
.ch-article-card {
    border-radius: var(--ch-radius-xl);
    padding: 1rem 1rem 1rem 1.125rem;
    box-shadow: var(--ch-shadow-sm);
    transition: box-shadow var(--ch-transition);
}

.ch-article-card--discounted {
    background: var(--ch-surface);
    border: 1px solid var(--ch-discount-border);
    border-left: 4px solid var(--ch-discount);
}

.ch-article-card--not-discounted {
    background: var(--ch-bg-muted);
    border: 1px solid var(--ch-border);
    border-left: 4px solid #94a3b8;
}

/* FSM / Trade-in blocks */
.ch-fsm-block {
    border-radius: var(--ch-radius-xl);
    border: 1px solid var(--ch-fsm-border);
    border-left: 4px solid var(--ch-fsm);
    background: linear-gradient(135deg, var(--ch-fsm-bg) 0%, #ede9fe 100%);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--ch-shadow-sm);
}

.ch-trade-in-block {
    border-radius: var(--ch-radius-xl);
    border: 1px solid var(--ch-trade-in-border);
    border-left: 4px solid var(--ch-trade-in);
    background: linear-gradient(135deg, var(--ch-trade-in-bg) 0%, #d1fae5 100%);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--ch-shadow-sm);
}

.ch-bundle-block {
    border-radius: var(--ch-radius-xl);
    border: 1px solid var(--ch-bundle-border);
    border-left: 4px solid var(--ch-bundle);
    background: linear-gradient(135deg, var(--ch-bundle-bg) 0%, #cffafe 100%);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--ch-shadow-sm);
}

/* Nav */
.ch-nav-link {
    display: inline-flex;
    align-items: center;
    min-height: 2.75rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ch-text-muted);
    border-radius: var(--ch-radius);
    text-decoration: none;
    transition: color var(--ch-transition), background-color var(--ch-transition);
}

.ch-nav-link:hover {
    color: var(--ch-primary);
    background: rgb(79 70 229 / 0.06);
}

.ch-nav-link.is-active {
    color: var(--ch-primary);
    font-weight: 600;
    background: rgb(79 70 229 / 0.1);
}

.ch-nav-link-admin {
    color: #94a3b8;
    font-size: 0.8125rem;
}

.ch-sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #cbd5e1;
    border-radius: var(--ch-radius-lg);
    border-left: 3px solid transparent;
    text-decoration: none;
    transition: background-color var(--ch-transition), color var(--ch-transition), border-color var(--ch-transition);
}

.ch-sidebar-link:hover {
    background: rgb(255 255 255 / 0.08);
    color: #fff;
}

.ch-sidebar-link.is-active {
    background: rgb(255 255 255 / 0.12);
    color: #fff;
    border-left-color: #818cf8;
    font-weight: 600;
}

/* Grilles : rendu différé hors écran */
.ch-card,
.ch-article-card,
.ch-bundle-block,
.ch-fsm-block,
.ch-trade-in-block {
    content-visibility: auto;
    contain-intrinsic-size: auto 120px;
}

/* Logos marques */
.ch-brand-logo {
    position: relative;
    display: inline-block;
}

.ch-brand-logo__img {
    opacity: 0;
    transition: opacity 0.2s ease-out;
}

.ch-brand-logo__img.is-loaded,
.ch-brand-logo.has-logo .ch-brand-logo__img {
    opacity: 1;
}

.ch-brand-logo__img.hidden {
    display: none;
}

/* Reveal animation */
.ch-reveal {
    opacity: 0;
    transform: translate3d(0, 10px, 0);
    transition: opacity 0.35s ease-out, transform 0.35s ease-out;
}

.ch-reveal.is-visible {
    opacity: 1;
    transform: translate3d(0, 0, 0);
}

@media (prefers-reduced-motion: reduce) {
    .ch-reveal {
        opacity: 1;
        transform: none;
        transition: none;
    }
}

/* Tables admin */
.ch-table-wrap {
    overflow-x: auto;
    border-radius: var(--ch-radius-xl);
    border: 1px solid var(--ch-border);
    background: var(--ch-surface);
    box-shadow: var(--ch-shadow-sm);
}

.ch-table {
    width: 100%;
    font-size: 0.875rem;
    border-collapse: collapse;
}

.ch-table thead {
    background: var(--ch-bg-muted);
    position: sticky;
    top: 0;
    z-index: 1;
}

.ch-table th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-weight: 600;
    color: var(--ch-text-muted);
    border-bottom: 1px solid var(--ch-border);
}

.ch-table td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--ch-border);
    vertical-align: middle;
}

.ch-table tbody tr:last-child td {
    border-bottom: none;
}

.ch-table tbody tr:nth-child(even) {
    background: rgb(248 250 252 / 0.6);
}

.ch-table tbody tr:hover {
    background: rgb(79 70 229 / 0.04);
}

/* Tabular numbers for prices */
.tabular-nums {
    font-variant-numeric: tabular-nums;
}

.min-touch {
    min-height: 2.75rem;
}

/* Legacy compat */
.card-hover {
    transition: box-shadow var(--ch-transition), transform var(--ch-transition);
}

.card-hover:hover {
    box-shadow: var(--ch-shadow-hover);
}

.ch-inline-edit {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
}

@media (max-width: 640px) {
    .admin-table-wrap {
        display: none;
    }
    .admin-cards-mobile {
        display: block;
    }
}

@media (min-width: 641px) {
    .admin-cards-mobile {
        display: none;
    }
}

@media (min-width: 1024px) {
    .admin-table-wrap {
        display: block;
    }
}

/* Scanner EAN (html5-qrcode) */
.ch-ean-scanner__viewport video {
    width: 100% !important;
    height: auto !important;
    object-fit: cover;
    border-radius: var(--ch-radius-lg);
}

.ch-ean-scanner__viewport #seller-ean-scanner-reader__scan_region,
.ch-ean-scanner__viewport #admin-ean-scanner-reader__scan_region,
.ch-ean-scanner__viewport [id$='__scan_region'] {
    border-radius: var(--ch-radius-lg);
}

.ch-ean-scanner__viewport img[alt='Info icon'] {
    display: none;
}

/* Plateau conseiller */
body.ch-tray-open {
    overflow: hidden;
}

body:has(.ch-tray.has-items) main {
    padding-bottom: 5.5rem;
}

.ch-tray__bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 45;
    display: flex;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem calc(0.5rem + env(safe-area-inset-bottom, 0px));
    background: var(--ch-surface);
    border-top: 1px solid var(--ch-border);
    box-shadow: 0 -8px 24px rgb(15 23 42 / 0.08);
}

.ch-tray__bar.has-items {
    border-top-color: var(--ch-primary);
}

.ch-tray__toggle {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 2.75rem;
    padding: 0.5rem 0.75rem;
    background: var(--ch-bg-muted);
    border: 1px solid var(--ch-border);
    border-radius: var(--ch-radius-lg);
    cursor: pointer;
    text-align: left;
}

.ch-tray__bar.has-items .ch-tray__toggle {
    background: rgb(79 70 229 / 0.08);
    border-color: rgb(79 70 229 / 0.25);
}

.ch-tray__icon {
    color: var(--ch-primary);
}

.ch-tray__label {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.ch-tray__count {
    font-size: 0.75rem;
    color: var(--ch-text-muted);
    font-weight: 500;
}

.ch-tray__total {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--ch-primary);
}

.ch-tray__open {
    align-self: center;
    flex-shrink: 0;
}

.ch-tray__backdrop {
    position: fixed;
    inset: 0;
    background: rgb(15 23 42 / 0.4);
    z-index: 46;
}

.ch-tray__panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 47;
    max-height: 70vh;
    background: var(--ch-surface);
    border-radius: var(--ch-radius-xl) var(--ch-radius-xl) 0 0;
    box-shadow: var(--ch-shadow-hover);
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.ch-tray__panel.hidden,
.ch-tray__backdrop.hidden {
    display: none;
}

.ch-tray__panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--ch-border);
}

.ch-tray__panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
}

.ch-tray__panel-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--ch-border);
}

.ch-tray-add-btn.is-added {
    background: var(--ch-success-bg);
    border-color: #86efac;
    color: #166534;
}
