/* === 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;
    --error: #dc2626;
    --error-light: #fef2f2;
    --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;
    --white: #ffffff;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

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

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 20px;
}

/* === Header === */
.header {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    padding: 16px 0;
}

.header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.5rem;
    color: var(--gray-800);
}

.logo-img {
    height: 36px;
    width: auto;
}

.header-tagline {
    color: var(--gray-500);
    font-size: 0.9rem;
}

/* === Main === */
.main {
    flex: 1;
    padding: 32px 0;
}

/* === Footer === */
.footer {
    background: var(--gray-800);
    color: var(--gray-400);
    padding: 24px 0;
    text-align: center;
    font-size: 0.85rem;
    margin-top: auto;
}

/* === Stepper === */
.stepper {
    margin-bottom: 40px;
}

.stepper-track {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
}

.stepper-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    position: relative;
}

.stepper-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    background: var(--gray-200);
    color: var(--gray-500);
    transition: all 0.3s;
}

.stepper-step.active .stepper-circle {
    background: var(--primary);
    color: var(--white);
    box-shadow: 0 0 0 4px var(--primary-light);
}

.stepper-step.completed .stepper-circle {
    background: var(--success);
    color: var(--white);
}

.stepper-label {
    font-size: 0.8rem;
    color: var(--gray-500);
    font-weight: 500;
}

.stepper-step.active .stepper-label {
    color: var(--primary);
    font-weight: 600;
}

.stepper-step.completed .stepper-label {
    color: var(--success);
}

a.stepper-step {
    text-decoration: none;
    cursor: pointer;
}

a.stepper-step:hover .stepper-circle {
    box-shadow: 0 0 0 4px rgba(40, 167, 69, 0.2);
}

a.stepper-step:hover .stepper-label {
    text-decoration: underline;
}

.stepper-line {
    width: 60px;
    height: 3px;
    background: var(--gray-200);
    margin: 0 8px;
    margin-bottom: 28px;
    border-radius: 2px;
}

.stepper-line.completed {
    background: var(--success);
}

/* === Cards === */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px;
    margin-bottom: 24px;
}

.card-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 8px;
}

.card-subtitle {
    color: var(--gray-500);
    margin-bottom: 24px;
}

/* === Forms === */
.form-tarificateur {
    max-width: 480px;
}

.form-tarificateur:has(.regime-cards--inline) {
    max-width: 100%;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    color: var(--gray-800);
    background: var(--white);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-row {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.form-row .form-group {
    flex: 1;
    min-width: 180px;
}

.form-group-btn {
    flex: 0 !important;
    min-width: auto !important;
}

.form-inline {
    margin-top: 16px;
}

/* === Alerts === */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.alert-error {
    background: var(--error-light);
    color: var(--error);
    border: 1px solid #fecaca;
}

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

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
    line-height: 1.4;
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}

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

.btn-secondary {
    background: var(--gray-100);
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}

.btn-secondary:hover {
    background: var(--gray-200);
}

.btn-outline {
    background: var(--white);
    color: var(--primary);
    border: 2px solid var(--primary);
}

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

.btn-block {
    width: 100%;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.form-actions--right {
    justify-content: flex-end;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* === Département info === */
.departement-info {
    margin-top: 6px;
    font-size: 0.85rem;
    color: var(--success);
    min-height: 20px;
}

/* === Régime cards === */
.regime-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.regime-cards--inline {
    grid-template-columns: repeat(3, 1fr);
    margin-bottom: 70px;
}

.regime-card {
    display: block;
    cursor: pointer;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    transition: all 0.2s;
    position: relative;
}

.regime-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow);
}

.regime-card input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.regime-card:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.regime-card-content h3 {
    font-size: 1.1rem;
    margin: 0 0 4px;
    color: var(--gray-800);
}

.regime-card-content p {
    font-size: 0.85rem;
    color: var(--gray-500);
    margin: 0;
}

/* === Tarifs === */
.tarifs-header {
    text-align: center;
    margin-bottom: 32px;
}

.tarifs-header h2 {
    font-size: 1.8rem;
    color: var(--gray-900);
    margin-bottom: 8px;
}

.tarifs-resume {
    color: var(--gray-500);
    font-size: 0.9rem;
}

.niveaux-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 32px;
}

/* === Carte niveau === */
.carte-niveau {
    background: var(--white);
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    position: relative;
    display: flex;
    flex-direction: column;
    transition: all 0.2s;
}

.carte-niveau:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.carte-niveau--recommended {
    border-color: var(--primary);
    box-shadow: var(--shadow-lg);
}

.carte-niveau-badge {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: var(--white);
    padding: 2px 16px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.carte-niveau-header h3 {
    font-size: 1.2rem;
    color: var(--gray-800);
    margin-bottom: 2px;
}

.carte-niveau-label {
    font-size: 0.8rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.carte-niveau-price {
    margin: 20px 0;
    padding: 16px 0;
    border-top: 1px solid var(--gray-100);
    border-bottom: 1px solid var(--gray-100);
}

.price-before {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 4px;
}

.price-striked {
    font-size: 0.9rem;
    color: var(--gray-400);
    text-decoration: line-through;
    font-weight: 500;
}

.price-discount-badge {
    display: inline-block;
    background: var(--success);
    color: var(--white);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 10px;
    line-height: 1.5;
}

.price-amount {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.price-unit {
    font-size: 0.9rem;
    color: var(--gray-500);
}

.carte-niveau-details {
    flex: 1;
    margin-bottom: 16px;
}

.detail-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 0.82rem;
    color: var(--gray-600);
    gap: 8px;
}

.detail-line > span:first-child {
    white-space: nowrap;
}

.detail-amount {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    flex-shrink: 0;
}

.carte-niveau-price {
    position: relative;
}

/* Info trigger (i) icon */
.info-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--gray-200);
    color: var(--gray-500);
    font-size: 0.6rem;
    font-weight: 700;
    font-style: italic;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}

.info-trigger:hover {
    background: var(--primary);
    color: white;
}

/* Info popup */
.info-popup {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 100;
    background: var(--gray-900);
    color: white;
    border-radius: 8px;
    padding: 12px 14px;
    width: 260px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    font-size: 0.78rem;
    line-height: 1.5;
}

.info-popup.is-visible {
    display: block;
}

.info-popup-title {
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--gray-400);
}

.info-popup-formula {
    font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
    font-size: 0.75rem;
    color: white;
    margin-bottom: 6px;
}

.info-popup-formula strong {
    color: #a5d8ff;
}

.info-popup-detail {
    font-size: 0.7rem;
    color: var(--gray-400);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 6px;
}

.detail-striked {
    font-size: 0.8rem;
    color: var(--gray-400);
    text-decoration: line-through;
    font-weight: 400;
}

.detail-line--total {
    border-top: 1px solid var(--gray-200);
    margin-top: 8px;
    padding-top: 10px;
    font-weight: 600;
    color: var(--gray-800);
}

/* === Options section (legacy) === */
.options-section {
    margin-top: 16px;
}

.options-section h3 {
    margin-bottom: 12px;
    font-size: 1.1rem;
}

/* === Profil résumé === */
.profil-resume {
    color: var(--gray-600);
    font-size: 0.95rem;
    margin-bottom: 28px;
}

.tarifs-options-section {
    margin-top: 24px;
    margin-bottom: 0;
}

.tarifs-options-section h3 {
    font-size: 1.1rem;
    color: var(--gray-800);
    margin-bottom: 16px;
}

.profil-options-form {
    display: block;
}

.profil-options-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
}

.profil-options-fields .form-group {
    flex: 1;
    min-width: 160px;
}

.profil-options-fields .form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--gray-600);
    margin-bottom: 4px;
    font-weight: 500;
}

.profil-options-fields .form-group-btn {
    flex: 0 0 auto;
    min-width: auto;
}

.profil-options-fields .form-group-btn .btn {
    white-space: nowrap;
}

/* === Résultat === */
.resultat-card {
    max-width: 700px;
    margin: 0 auto;
}

.resultat-header {
    text-align: center;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 24px;
}

.resultat-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.resultat-header h2 {
    font-size: 1.5rem;
    color: var(--gray-900);
}

.resultat-reference {
    color: var(--primary);
    font-size: 1.1rem;
    margin-top: 8px;
}

.resultat-date {
    color: var(--gray-500);
    font-size: 0.85rem;
    margin-top: 4px;
}

.resultat-section {
    margin-bottom: 24px;
}

.resultat-section h3 {
    font-size: 1rem;
    color: var(--gray-700);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--gray-100);
}

.resultat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.resultat-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.resultat-item .label {
    font-size: 0.8rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.resultat-item .value {
    font-weight: 600;
    color: var(--gray-800);
}

.resultat-item--total .value {
    color: var(--primary);
    font-size: 1.2rem;
}

.resultat-tarifs {
    background: var(--gray-50);
    padding: 20px;
    border-radius: var(--radius-sm);
}

/* === Tableau de garanties === */
.garanties-wrapper {
    margin-bottom: 32px;
}

/* Collapsible categories */
.garantie-categorie {
    margin-bottom: 12px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.garantie-categorie[open] {
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.garantie-categorie-titre {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--white);
    padding: 12px 16px;
    background: var(--gray-900);
    cursor: pointer;
    user-select: none;
    list-style: none;
}

.garantie-categorie-titre::-webkit-details-marker {
    display: none;
}

.categorie-titre-text {
    flex: 1;
}

.categorie-badge {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--gray-300);
    background: rgba(255, 255, 255, 0.12);
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

.categorie-chevron {
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--gray-400);
    border-bottom: 2px solid var(--gray-400);
    transform: rotate(45deg);
    transition: transform 0.2s;
    flex-shrink: 0;
}

.garantie-categorie[open] .categorie-chevron {
    transform: rotate(-135deg);
}

/* Table */
.garantie-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.garantie-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.garantie-table thead {
    background: var(--gray-50);
    position: sticky;
    top: 0;
    z-index: 1;
}

.garantie-th-libelle {
    text-align: left;
    padding: 10px 14px;
    font-weight: 600;
    color: var(--gray-600);
    border-bottom: 2px solid var(--gray-200);
    min-width: 280px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.garantie-th-niveau {
    text-align: center;
    padding: 8px 6px;
    border-bottom: 2px solid var(--gray-200);
    min-width: 115px;
}

.niveau-num {
    display: block;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--gray-800);
}

.garantie-th-n1 .niveau-num { color: var(--gray-600); }
.garantie-th-n2 .niveau-num { color: var(--primary); }
.garantie-th-n3 .niveau-num { color: #7c3aed; }
.garantie-th-n4 .niveau-num { color: #b45309; }

.niveau-label {
    display: block;
    font-weight: 500;
    color: var(--gray-400);
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 1px;
}

/* Body rows */
.garantie-table tbody tr {
    border-bottom: 1px solid var(--gray-100);
    transition: background 0.1s;
}

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

.garantie-table tbody tr:hover {
    background: #f8fafc;
}

.garantie-libelle {
    padding: 10px 14px;
    color: var(--gray-700);
    line-height: 1.45;
}

.garantie-valeur {
    text-align: center;
    padding: 10px 8px;
    color: var(--gray-800);
    font-weight: 500;
    white-space: nowrap;
}

/* Section title rows */
.garantie-row-titre td {
    padding: 8px 14px;
    font-weight: 600;
    color: var(--gray-700);
    background: linear-gradient(to right, var(--gray-50), transparent);
    font-size: 0.8rem;
    border-left: 3px solid var(--primary);
}

/* Réseau / Hors-réseau split cells */
.garantie-valeur-split {
    line-height: 1.5;
    font-size: 0.78rem;
    padding: 6px 8px;
}

.reseau-label,
.hors-reseau-label {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.6rem;
    font-weight: 700;
    vertical-align: middle;
    min-width: 20px;
    text-align: center;
}

.reseau-label {
    background: var(--success);
    color: var(--white);
}

.hors-reseau-label {
    background: var(--gray-400);
    color: var(--white);
}

/* Footnotes */
.garanties-footnotes {
    margin-top: 24px;
    padding: 16px 20px;
    background: var(--gray-50);
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-100);
}

.footnotes-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 24px;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--gray-200);
}

.legend-item {
    font-size: 0.75rem;
    color: var(--gray-600);
    display: flex;
    align-items: center;
    gap: 4px;
}

.legend-item strong {
    color: var(--gray-800);
    font-weight: 700;
}

.footnotes-notes {
    color: var(--gray-400);
    font-size: 0.72rem;
    line-height: 1.5;
}

.footnotes-notes p {
    margin: 2px 0;
}

/* === Form errors === */
.form-group ul {
    list-style: none;
    padding: 0;
    margin: 4px 0 0;
}

.form-group ul li {
    color: var(--error);
    font-size: 0.85rem;
}

/* === Tarifs — garanties recap === */
.tarifs-garanties-recap {
    margin-top: 24px;
}

.tarifs-garanties-recap .card-title {
    font-size: 1.2rem;
    margin-bottom: 16px;
}

/* === Inline editable cells === */
.edit-hint {
    color: var(--primary);
    font-weight: 500;
}

[data-editable] {
    border-radius: 3px;
    transition: background 0.15s, box-shadow 0.15s;
}

[data-editable].has-number {
    cursor: pointer;
}

[data-editable].has-number:hover {
    background: var(--primary-light);
    box-shadow: inset 0 0 0 1px var(--primary);
}

[data-editable].editing {
    background: var(--white) !important;
    box-shadow: none !important;
}

[data-editable].saving {
    opacity: 0.6;
}

[data-editable].saved {
    background: var(--success-light) !important;
    box-shadow: inset 0 0 0 1px var(--success) !important;
}

[data-editable].save-error {
    background: var(--error-light) !important;
    box-shadow: inset 0 0 0 2px var(--error) !important;
}

/* Number-only inline input */
.cell-editor-num {
    border: none;
    border-bottom: 2px solid var(--primary);
    background: var(--primary-light);
    font-size: inherit;
    font-family: inherit;
    font-weight: 700;
    color: var(--primary-dark);
    padding: 1px 2px;
    outline: none;
    text-align: center;
    border-radius: 2px;
    min-width: 2.5ch;
}

.cell-static {
    color: var(--gray-500);
}

/* Split line for réseau/hors-réseau editable */
.split-line {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 0;
    justify-content: center;
}

.split-line + .split-line {
    border-top: 1px dashed var(--gray-200);
    margin-top: 2px;
    padding-top: 5px;
}

.split-line .editable-value {
    padding: 2px 4px;
    flex: 1;
    text-align: center;
}

/* Toast notifications */
.edit-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 9999;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
}

.edit-toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.edit-toast--error {
    background: var(--error);
    color: var(--white);
}

/* === Responsive === */
@media (max-width: 900px) {
    .niveaux-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .niveaux-grid {
        grid-template-columns: 1fr;
    }

    .stepper-line {
        width: 20px;
    }

    .stepper-label {
        font-size: 0.7rem;
    }

    .stepper-circle {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }

    .card {
        padding: 20px;
    }

    .header-tagline {
        display: none;
    }

    .regime-cards {
        grid-template-columns: 1fr;
    }

    .form-row {
        flex-direction: column;
    }
}
