/* ==================== VARIABLES CSS ==================== */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
}

/* ==================== RESET & BASE ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* ==================== CONTAINER ==================== */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* ==================== HEADER ==================== */
.header {
    background: var(--surface);
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-content h1 {
    font-size: 2rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

.header-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* ==================== BUTTONS ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #475569;
    transform: translateY(-1px);
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover {
    background: #059669;
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ==================== SEARCH & FILTERS ==================== */
.search-section {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
}

.search-box {
    margin-bottom: 1rem;
}

.search-box input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    transition: border-color 0.2s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.filter-section {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.filter-select {
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    background: white;
    cursor: pointer;
    transition: border-color 0.2s;
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* ==================== STATS CARDS ==================== */
.stats-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-icon {
    font-size: 2.5rem;
}

.stat-content {
    flex: 1;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: bold;
    color: var(--text-primary);
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* ==================== TABLE ==================== */
.table-container {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.attestations-table {
    width: 100%;
    border-collapse: collapse;
}

.attestations-table thead {
    background: var(--primary-color);
    color: white;
}

.attestations-table th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.attestations-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.attestations-table tbody tr {
    transition: background-color 0.2s;
}

.attestations-table tbody tr:hover {
    background: #f1f5f9;
}

.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-brouillon {
    background: #fef3c7;
    color: #92400e;
}

.status-validee {
    background: #d1fae5;
    color: #065f46;
}

.status-envoyee {
    background: #dbeafe;
    color: #1e40af;
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
}

.action-btn {
    padding: 0.5rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1.25rem;
    transition: transform 0.2s;
    border-radius: var(--radius-sm);
}

.action-btn:hover {
    transform: scale(1.1);
    background: var(--background);
}

.loading-cell {
    text-align: center;
    padding: 3rem !important;
}

.loading-spinner {
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ==================== EMPTY STATE ==================== */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.empty-state h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.empty-state p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

/* ==================== FORMS ==================== */
.config-container,
.create-container {
    background: var(--surface);
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.form-section {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 2px solid var(--border-color);
}

.form-section:last-of-type {
    border-bottom: none;
}

.section-title {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    transition: border-color 0.2s;
    font-family: inherit;
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group small {
    margin-top: 0.25rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    flex-wrap: wrap;
    margin-top: 2rem;
}

/* ==================== UPLOAD SECTION ==================== */
.upload-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.upload-preview {
    width: 300px;
    height: 200px;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: var(--background);
}

.upload-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.upload-placeholder {
    text-align: center;
    color: var(--text-secondary);
}

.upload-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 0.5rem;
}

.upload-controls {
    display: flex;
    gap: 1rem;
}

.upload-info {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* ==================== SERVICE ITEM ==================== */
.service-item {
    background: var(--background);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    border: 2px solid var(--border-color);
}

.service-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.service-title {
    font-weight: 600;
    color: var(--text-primary);
}

.remove-service-btn {
    background: var(--danger-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    transition: background 0.2s;
}

.remove-service-btn:hover {
    background: #dc2626;
}

/* ==================== TOTAL SECTION ==================== */
.total-section {
    background: var(--primary-color);
    color: white;
    padding: 1.5rem;
    border-radius: var(--radius-md);
}

.total-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.25rem;
    font-weight: 600;
}

.total-amount {
    font-size: 2rem;
}

/* ==================== MESSAGES ==================== */
.success-message,
.error-message {
    position: fixed;
    top: 2rem;
    right: 2rem;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
    z-index: 1000;
    animation: slideIn 0.3s ease-out;
}

.success-message {
    background: var(--success-color);
    color: white;
}

.error-message {
    background: var(--danger-color);
    color: white;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ==================== MODAL ==================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 2px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
    padding: 0;
    width: 2rem;
    height: 2rem;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 2px solid var(--border-color);
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

.warning-text {
    color: var(--danger-color);
    font-weight: 600;
    margin-top: 0.5rem;
}

.info-box {
    background: #e0f2fe;
    border-left: 4px solid #0284c7;
    padding: 1rem;
    border-radius: var(--radius-md);
    margin: 1rem 0;
    font-size: 0.875rem;
    line-height: 1.6;
}

.info-box strong {
    color: #0c4a6e;
}

.section-description {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
    font-style: italic;
}

/* ==================== PREVIEW PAGE ==================== */
.preview-container {
    min-height: 100vh;
    background: var(--background);
    padding: 2rem;
}

.preview-header {
    background: var(--surface);
    padding: 1.5rem 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.preview-instructions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.instruction-card {
    background: var(--surface);
    padding: 1rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.instruction-icon {
    font-size: 2rem;
}

.preview-workspace {
    display: flex;
    justify-content: center;
    padding: 2rem;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.attestation-preview {
    position: relative;
    width: 210mm;
    min-height: 594mm; /* 2 pages A4 */
    background: white;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

.attestation-page {
    width: 210mm;
    min-height: 297mm;
    padding: 20mm;
    background: white;
    position: relative;
    page-break-after: always;
}

.attestation-page#page2 {
    border-top: 2px dashed #ccc;
    margin-top: 20px;
}

/* ==================== ATTESTATION STYLES ==================== */
.attestation-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 30px;
}

.logo-section {
    width: 150px;
}

.logo-association {
    max-width: 100%;
    height: auto;
}

.title-section {
    text-align: center;
    flex: 1;
}

.attestation-title {
    font-size: 24px;
    font-weight: bold;
    color: #000;
    margin-bottom: 5px;
}

.attestation-subtitle {
    font-size: 14px;
    margin-bottom: 5px;
}

.attestation-date {
    font-size: 14px;
    font-weight: bold;
}

.sap-logo-section {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 30px;
}

.sap-badge {
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
    color: white;
    padding: 15px 25px;
    border-radius: 10px;
    font-weight: bold;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.sap-text {
    font-size: 14px;
}

.client-info-box {
    text-align: right;
    font-weight: bold;
}

.client-name {
    font-size: 16px;
    margin-bottom: 5px;
}

.client-address,
.client-city {
    font-size: 14px;
    margin-bottom: 3px;
}

.client-number-section {
    margin-bottom: 20px;
    font-size: 13px;
}

.prestataire-info {
    font-style: italic;
    margin: 10px 0 5px 0;
}

.prestataire-name {
    font-weight: bold;
}

.summary-table {
    margin-bottom: 20px;
}

.summary-table table {
    width: 100%;
    border-collapse: collapse;
    border: 2px solid #000;
}

.summary-table td {
    padding: 15px;
    border: 2px solid #000;
}

.summary-label {
    width: 70%;
    font-size: 13px;
}

.summary-amount {
    width: 30%;
    text-align: center;
    font-size: 18px;
    font-weight: bold;
}

.services-table {
    margin-bottom: 20px;
}

.services-table table {
    width: 100%;
    border-collapse: collapse;
    border: 2px solid #000;
}

.services-table th {
    background: #f0f0f0;
    padding: 10px;
    border: 2px solid #000;
    font-size: 13px;
    text-align: left;
}

.services-table td {
    padding: 10px;
    border: 2px solid #000;
    font-size: 12px;
}

.legal-info {
    font-size: 10px;
    line-height: 1.4;
    margin-bottom: 20px;
}

.legal-title {
    font-weight: bold;
    margin-top: 10px;
    margin-bottom: 5px;
}

.legal-text {
    margin-bottom: 8px;
}

.legal-list {
    margin-left: 20px;
    margin-bottom: 8px;
}

.legal-list li {
    margin-bottom: 5px;
}

.footer-info {
    font-size: 10px;
    text-align: center;
    border-top: 1px solid #ccc;
    padding-top: 10px;
    margin-top: 20px;
}

.footer-info p {
    margin-bottom: 3px;
}

/* ==================== TAMPON ==================== */
.tampon {
    position: absolute;
    top: 0;
    left: 0;
    background: white;
    border: 2px solid #000;
    padding: 15px;
    border-radius: 5px;
    cursor: move;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    z-index: 10;
    min-width: 200px;
}

.tampon:hover {
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
    border-color: var(--primary-color);
}

.tampon-content {
    text-align: center;
}

.tampon-lieu {
    font-size: 12px;
    margin-bottom: 10px;
    font-weight: bold;
}

.tampon-signature-label {
    font-size: 11px;
    margin-bottom: 5px;
    font-style: italic;
}

.tampon-signature {
    max-width: 150px;
    max-height: 60px;
    margin: 10px auto;
    display: block;
}

.tampon-nom {
    font-size: 12px;
    font-weight: bold;
    margin-top: 5px;
}

/* ==================== LOADING OVERLAY ==================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-content {
    text-align: center;
    color: white;
}

.loading-spinner-large {
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-top: 5px solid white;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

.loading-text {
    font-size: 1.25rem;
    font-weight: 500;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
    }

    .header-actions {
        width: 100%;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .stats-section {
        grid-template-columns: 1fr;
    }

    .table-container {
        overflow-x: auto;
    }

    .attestations-table {
        min-width: 800px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .attestation-preview {
        transform: scale(0.5);
        transform-origin: top center;
    }
}

@media print {
    body {
        background: white;
    }

    .preview-header,
    .preview-instructions,
    .tampon {
        display: none !important;
    }

    .attestation-page {
        box-shadow: none;
        margin: 0;
        padding: 20mm;
    }
}
