/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --success-light: #dcfce7;
    --danger: #dc2626;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
    --transition: .2s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
}

/* === App container === */
.app {
    max-width: 860px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

/* === Progress bar === */
.progress-bar { margin-bottom: 2rem; }

.progress-steps {
    display: flex;
    justify-content: space-between;
    margin-bottom: .75rem;
}

.step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .25rem;
    flex: 1;
    opacity: .4;
    transition: opacity var(--transition);
}
.step.active, .step.done { opacity: 1; }

.step-num {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--gray-300);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .85rem;
    transition: background var(--transition);
}
.step.active .step-num { background: var(--primary); }
.step.done .step-num { background: var(--success); }

.step-label { font-size: .75rem; color: var(--gray-500); white-space: nowrap; }
.step.active .step-label { color: var(--primary); font-weight: 600; }
.step.done .step-label { color: var(--success); }

.progress-track {
    height: 4px; background: var(--gray-200); border-radius: 2px; overflow: hidden;
}
.progress-fill {
    height: 100%; background: var(--primary); border-radius: 2px;
    transition: width .4s ease; width: 0%;
}

/* === Form steps === */
.form-step { display: none; animation: fadeIn .3s ease; }
.form-step.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.form-step h2 {
    font-size: 1.5rem; font-weight: 700; margin-bottom: .25rem; color: var(--gray-900);
}
.step-desc { color: var(--gray-500); margin-bottom: 1.5rem; }

/* === Form grid === */
.form-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;
}
.field { display: flex; flex-direction: column; gap: .35rem; }
.field.full { grid-column: 1 / -1; }

label { font-size: .875rem; font-weight: 500; color: var(--gray-700); }
.req { color: var(--danger); }
.opt { font-weight: 400; color: var(--gray-400); font-size: .8rem; }

input[type="text"], input[type="email"], input[type="tel"], input[type="url"],
input[type="number"], textarea, select {
    padding: .6rem .75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: .9rem;
    background: #fff;
    color: var(--gray-800);
    transition: border-color var(--transition), box-shadow var(--transition);
    width: 100%;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.small-input { width: 80px; display: inline-block; }
.unit { font-size: .85rem; color: var(--gray-500); }

/* === Buttons === */
.btn {
    padding: .65rem 1.5rem;
    border: none; border-radius: var(--radius-sm);
    font-size: .9rem; font-weight: 600;
    cursor: pointer; transition: all var(--transition);
    display: inline-flex; align-items: center; gap: .4rem;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--gray-200); color: var(--gray-700); }
.btn-secondary:hover:not(:disabled) { background: var(--gray-300); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; }

.step-actions {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--gray-200);
}

/* === Audit === */
.audit-loading { text-align: center; padding: 3rem 1rem; }
.spinner {
    width: 48px; height: 48px;
    border: 4px solid var(--gray-200); border-top-color: var(--primary);
    border-radius: 50%; animation: spin .8s linear infinite;
    margin: 0 auto 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
.audit-sub { font-size: .85rem; color: var(--gray-400); }

.audit-cards {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem; margin-bottom: 1.5rem;
}
.audit-card {
    background: #fff; border: 1px solid var(--gray-200);
    border-radius: var(--radius); padding: 1.25rem;
    text-align: center; box-shadow: var(--shadow);
}
.audit-icon { font-size: 1.5rem; margin-bottom: .5rem; }
.audit-metric { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.audit-label { font-size: .8rem; color: var(--gray-500); margin-top: .25rem; }

.audit-meta {
    background: var(--gray-100); border-radius: var(--radius-sm);
    padding: 1rem; font-size: .85rem; margin-bottom: 1rem;
}
.audit-meta p { margin-bottom: .3rem; }
.audit-meta strong { color: var(--gray-700); }

.audit-keywords-list {
    font-size: .85rem; color: var(--gray-600);
}
.audit-keywords-list .kw-tag {
    display: inline-block; background: var(--primary-light); color: var(--primary-dark);
    padding: .2rem .6rem; border-radius: 20px; margin: .2rem; font-size: .8rem;
}

.audit-error {
    background: var(--warning-light); border: 1px solid var(--warning);
    border-radius: var(--radius-sm); padding: 1rem; text-align: center;
    color: var(--gray-700);
}

/* === Category tabs === */
.category-tabs {
    display: flex; gap: .5rem; margin-bottom: 1.5rem; flex-wrap: wrap;
}
.cat-tab {
    padding: .5rem 1.25rem; border: 2px solid var(--gray-200);
    background: #fff; border-radius: 30px; cursor: pointer;
    font-size: .85rem; font-weight: 600; color: var(--gray-500);
    transition: all var(--transition);
}
.cat-tab:hover { border-color: var(--primary-light); color: var(--primary); }
.cat-tab.active { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }

.cat-panel { display: none; margin-bottom: 1.5rem; }
.cat-panel.active { display: block; animation: fadeIn .2s ease; }

.toggle-label {
    display: flex; align-items: center; gap: .5rem;
    font-weight: 600; margin-bottom: 1rem; cursor: pointer;
}
.toggle-label input { width: 18px; height: 18px; accent-color: var(--primary); }

.cat-content { padding-left: .5rem; }
.cat-hint { font-size: .85rem; color: var(--gray-500); margin-bottom: .75rem; }

.checkbox-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: .5rem; margin-bottom: 1rem;
}
.cb { display: flex; align-items: center; gap: .5rem; font-size: .875rem; cursor: pointer; }
.cb input { accent-color: var(--primary); width: 16px; height: 16px; }

.radio-group { display: flex; flex-direction: column; gap: .4rem; }
.rb { display: flex; align-items: center; gap: .5rem; font-size: .875rem; cursor: pointer; }
.rb input { accent-color: var(--primary); }

.detected-info {
    background: var(--primary-light); border-radius: var(--radius-sm);
    padding: .75rem 1rem; margin-bottom: 1rem; font-size: .85rem;
    color: var(--primary-dark);
}

/* === Options grid === */
.options-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}
.option-card {
    background: #fff; border: 1px solid var(--gray-200);
    border-radius: var(--radius); padding: 1.25rem;
    box-shadow: var(--shadow); transition: border-color var(--transition);
}
.option-card:has(input:checked) { border-color: var(--primary); background: var(--primary-light); }
.option-card p { font-size: .85rem; color: var(--gray-500); margin-top: .5rem; }
.sub-options { margin-top: .75rem; padding-top: .75rem; border-top: 1px solid var(--gray-200); }

/* === Devis table === */
.devis-table {
    width: 100%; border-collapse: collapse; margin-bottom: 2rem;
    background: #fff; border-radius: var(--radius); overflow: hidden;
    box-shadow: var(--shadow);
}
.devis-table th {
    background: var(--gray-800); color: #fff;
    padding: .75rem 1rem; text-align: left; font-size: .8rem;
    text-transform: uppercase; letter-spacing: .5px;
}
.devis-table td {
    padding: .75rem 1rem; border-bottom: 1px solid var(--gray-100);
    font-size: .875rem; vertical-align: top;
}
.devis-table .amount { text-align: right; white-space: nowrap; }
.devis-table tbody tr:hover { background: var(--gray-50); }
.total-row td { border-top: 2px solid var(--gray-800); background: var(--gray-50); }
.total-row .amount { font-size: 1.1rem; }

.consultant-note {
    background: var(--primary-light); border-left: 4px solid var(--primary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: 1rem 1.25rem; margin-bottom: 1.5rem;
    font-size: .9rem; color: var(--gray-700); line-height: 1.6;
}

/* === Payment === */
.payment-options {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem; margin-bottom: 1.5rem;
}
.payment-option { cursor: pointer; }
.payment-option input { display: none; }
.payment-card {
    border: 2px solid var(--gray-200); border-radius: var(--radius);
    padding: 1rem; text-align: center; transition: all var(--transition);
    background: #fff;
}
.payment-card strong { display: block; margin-bottom: .25rem; }
.payment-card p { font-size: .8rem; color: var(--gray-500); }
.payment-option input:checked + .payment-card {
    border-color: var(--primary); background: var(--primary-light);
}

.mensualites-config { margin-bottom: 1.5rem; }

.schedule-preview {
    background: #fff; border: 1px solid var(--gray-200);
    border-radius: var(--radius); padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}
.schedule-preview h4 { margin-bottom: .5rem; font-size: .9rem; }
.schedule-line {
    display: flex; justify-content: space-between;
    padding: .3rem 0; font-size: .875rem;
    border-bottom: 1px dashed var(--gray-100);
}
.schedule-line:last-child { border-bottom: none; }

/* === Success screen === */
.success-screen { text-align: center; padding: 3rem 1rem; }
.success-icon {
    width: 72px; height: 72px; border-radius: 50%;
    background: var(--success-light); color: var(--success);
    font-size: 2.5rem; display: flex; align-items: center; justify-content: center;
    margin: 0 auto 1.5rem;
}
.success-screen h2 { color: var(--success); margin-bottom: .75rem; }
.success-screen p { margin-bottom: .5rem; }
.success-actions {
    display: flex; flex-direction: column; align-items: center;
    gap: .75rem; margin-top: 1.75rem;
}
.success-actions .btn {
    min-width: 300px; text-align: center;
    padding: .85rem 1.5rem; font-size: 1rem;
    text-decoration: none; display: inline-block;
}

/* === Admin === */
.admin-login { max-width: 360px; margin: 3rem auto; text-align: center; }
.admin-login h2 { margin-bottom: 1rem; }
.admin-login .field { margin-bottom: 1rem; }

.admin-header {
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 1rem; margin-bottom: 1.5rem;
}
.admin-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.stats-row {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem; margin-bottom: 1.5rem;
}
.stat-card {
    background: #fff; border: 1px solid var(--gray-200);
    border-radius: var(--radius); padding: 1rem; text-align: center;
    box-shadow: var(--shadow);
}
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: .8rem; color: var(--gray-500); }

.devis-list { display: flex; flex-direction: column; gap: .75rem; }
.devis-item {
    background: #fff; border: 1px solid var(--gray-200);
    border-radius: var(--radius); padding: 1rem 1.25rem;
    box-shadow: var(--shadow); cursor: pointer;
    transition: border-color var(--transition);
}
.devis-item:hover { border-color: var(--primary); }
.devis-item-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: .5rem;
}
.devis-item-company { font-weight: 700; font-size: 1rem; }
.devis-item-amount { font-weight: 700; color: var(--primary); }
.devis-item-meta { font-size: .8rem; color: var(--gray-500); }
.devis-item-meta span { margin-right: 1rem; }

.devis-detail {
    background: #fff; border: 1px solid var(--gray-200);
    border-radius: var(--radius); padding: 1.5rem;
    margin-bottom: 1.5rem; box-shadow: var(--shadow);
}
.devis-detail h3 { margin-bottom: 1rem; }

.badge {
    display: inline-block; padding: .15rem .5rem;
    border-radius: 20px; font-size: .75rem; font-weight: 600;
}
.badge-blue { background: var(--primary-light); color: var(--primary-dark); }

/* === Admin : selection bar === */
.selection-bar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; flex-wrap: wrap;
    background: var(--primary-light); border: 1px solid var(--primary);
    border-radius: var(--radius); padding: .75rem 1.25rem;
    margin-bottom: 1rem; font-size: .9rem; font-weight: 600;
    color: var(--primary-dark);
}
.selection-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.btn-sm { padding: .4rem .9rem; font-size: .8rem; }
.btn-danger {
    background: #dc3545; color: #fff; border: none;
    border-radius: var(--radius-sm); cursor: pointer;
    font-weight: 600; transition: background var(--transition);
}
.btn-danger:hover { background: #b02a37; }

/* === Admin : devis item checkbox === */
.devis-item { position: relative; }
.devis-item-check {
    position: absolute; top: 1rem; right: 1rem;
    width: 20px; height: 20px; cursor: pointer;
    accent-color: var(--primary);
}
.devis-item.selected {
    border-color: var(--primary);
    background: var(--primary-light);
}

/* === Analyse preliminaire === */
.prelim-block {
    background: #fff; border: 2px solid var(--primary);
    border-radius: var(--radius); padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem; box-shadow: var(--shadow);
}
.prelim-toggle { font-size: 1rem; margin-bottom: .75rem; }
.prelim-detail { padding-left: .25rem; }
.prelim-detail p { font-size: .9rem; color: var(--gray-600); margin-bottom: .5rem; }
.prelim-price {
    display: inline-block; background: var(--primary-light); color: var(--primary-dark);
    padding: .3rem .75rem; border-radius: 20px; font-size: .85rem; font-weight: 600;
    margin-bottom: .75rem;
}
.prelim-notice {
    background: var(--warning-light); border-left: 4px solid var(--warning);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: .75rem 1rem; font-size: .85rem; color: var(--gray-700); line-height: 1.5;
}

/* === Field hints === */
.field-hint {
    font-size: .8rem; color: var(--gray-500); margin-top: .35rem;
    padding-left: 1.5rem;
}

/* === Responsive === */
@media (max-width: 640px) {
    .app { padding: 1rem .75rem 2rem; }
    .form-grid { grid-template-columns: 1fr; }
    .step-label { font-size: .65rem; }
    .step-num { width: 28px; height: 28px; font-size: .75rem; }
    .audit-cards { grid-template-columns: 1fr 1fr; }
    .category-tabs { gap: .35rem; }
    .cat-tab { padding: .4rem .75rem; font-size: .8rem; }
    .options-grid { grid-template-columns: 1fr; }
    .payment-options { grid-template-columns: 1fr; }
    .devis-table { font-size: .8rem; }
    .devis-table th, .devis-table td { padding: .5rem .6rem; }
    .admin-actions { width: 100%; }
    .admin-actions .btn { flex: 1; justify-content: center; font-size: .8rem; }
}
