/* ===========================
   Variables & Reset
   =========================== */
:root {
    --primary-color: #4A90E2;
    --primary-dark: #357ABD;
    --secondary-color: #E8F4FD;
    --text-dark: #2C3E50;
    --text-light: #6C757D;
    --gray-light: #F5F7FA;
    --gray-border: #DEE2E6;
    --white: #FFFFFF;
    --success: #28A745;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, var(--secondary-color) 0%, var(--white) 100%);
    color: var(--text-dark);
    line-height: 1.6;
    min-height: 100vh;
    padding: 20px;
}

/* ===========================
   Container & Layout
   =========================== */
.container {
    max-width: 900px;
    margin: 0 auto;
    background: var(--white);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* ===========================
   Header & Logo
   =========================== */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: var(--white);
    padding: 30px;
    text-align: center;
}

.logo-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.logo {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: 3px;
    margin: 0;
}

.company-info {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* ===========================
   Sections
   =========================== */
.api-config-section,
.invoice-form-section,
.invoice-preview {
    padding: 30px;
}

.api-config-section h2,
.invoice-form-section h2,
.invoice-preview h2 {
    color: var(--primary-color);
    margin-bottom: 20px;
    font-size: 1.5rem;
    font-weight: 600;
}

/* ===========================
   Info Box
   =========================== */
.info-box {
    background: var(--secondary-color);
    border-left: 4px solid var(--primary-color);
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 6px;
}

.info-box p {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-dark);
}

/* ===========================
   Form Elements
   =========================== */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-dark);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--gray-border);
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.form-group small {
    display: block;
    margin-top: 5px;
    color: var(--text-light);
    font-size: 0.85rem;
}

/* Input avec bouton */
.input-with-button {
    display: flex;
    gap: 10px;
}

.input-with-button input {
    flex: 1;
}

.btn-icon {
    background: var(--gray-light);
    border: 2px solid var(--gray-border);
    border-radius: 6px;
    padding: 12px 15px;
    cursor: pointer;
    transition: background 0.3s;
    font-size: 1.2rem;
}

.btn-icon:hover {
    background: var(--gray-border);
}

/* ===========================
   Buttons
   =========================== */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    font-family: inherit;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.3);
}

.btn-secondary {
    background: var(--gray-light);
    color: var(--text-dark);
    border: 2px solid var(--gray-border);
}

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

.form-actions {
    display: flex;
    gap: 15px;
    margin-top: 25px;
    flex-wrap: wrap;
}

/* ===========================
   Loading Spinner
   =========================== */
.loading {
    text-align: center;
    padding: 40px;
}

.spinner {
    border: 4px solid var(--gray-border);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===========================
   Invoice Document
   =========================== */
.invoice-document {
    background: var(--white);
    border: 2px solid var(--gray-border);
    border-radius: 8px;
    padding: 40px;
    margin-bottom: 20px;
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--gray-border);
}

.invoice-logo h1 {
    color: var(--primary-color);
    font-size: 2rem;
    margin-bottom: 5px;
}

.invoice-logo p {
    margin: 2px 0;
    color: var(--text-light);
    font-size: 0.9rem;
}

.invoice-info {
    text-align: right;
}

.invoice-info h2 {
    color: var(--text-dark);
    font-size: 1.3rem;
    margin-bottom: 5px;
}

.invoice-info p {
    color: var(--text-light);
    font-size: 0.9rem;
}

.invoice-client {
    background: var(--gray-light);
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 25px;
}

.invoice-client h3 {
    color: var(--primary-color);
    font-size: 1rem;
    margin-bottom: 5px;
}

.invoice-client p {
    font-weight: 600;
    color: var(--text-dark);
}

/* ===========================
   Invoice Table
   =========================== */
.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 25px;
}

.invoice-table thead {
    background: var(--primary-color);
    color: var(--white);
}

.invoice-table th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    font-size: 0.9rem;
}

.invoice-table td {
    padding: 12px;
    border-bottom: 1px solid var(--gray-border);
}

.invoice-table tbody tr:hover {
    background: var(--secondary-color);
}

.invoice-table th:last-child,
.invoice-table td:last-child {
    text-align: right;
}

/* ===========================
   Invoice Totals
   =========================== */
.invoice-totals {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    margin-bottom: 25px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    min-width: 300px;
    padding: 8px 0;
}

.total-row span:first-child {
    font-weight: 600;
}

.total-row span:last-child {
    font-weight: 600;
    color: var(--primary-color);
}

.total-final {
    background: var(--primary-color);
    color: var(--white);
    padding: 15px;
    border-radius: 6px;
    margin-top: 10px;
}

.total-final span {
    color: var(--white) !important;
    font-size: 1.2rem;
}

/* ===========================
   Payment Status
   =========================== */
.invoice-payment-status {
    text-align: center;
    padding: 15px;
    background: #D4EDDA;
    border: 2px solid #28A745;
    border-radius: 6px;
    margin-bottom: 20px;
}

.invoice-payment-status p {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: #155724;
}

/* ===========================
   Legal Mentions
   =========================== */
.invoice-legal-mentions {
    background: var(--gray-light);
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 20px;
    border-left: 4px solid var(--primary-color);
}

.invoice-legal-mentions h4 {
    color: var(--primary-color);
    font-size: 0.95rem;
    margin-bottom: 10px;
    font-weight: 600;
}

.invoice-legal-mentions p {
    margin: 5px 0;
    font-size: 0.75rem;
    color: var(--text-dark);
    line-height: 1.4;
}

/* ===========================
   Invoice Footer
   =========================== */
.invoice-footer {
    text-align: center;
    padding: 20px;
    background: var(--secondary-color);
    border-radius: 6px;
}

.invoice-footer p {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    margin: 0;
}

/* ===========================
   Responsive Design
   =========================== */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .container {
        border-radius: 0;
    }

    .header {
        padding: 20px;
    }

    .logo {
        font-size: 2rem;
    }

    .api-config-section,
    .invoice-form-section,
    .invoice-preview {
        padding: 20px;
    }

    .invoice-document {
        padding: 20px;
    }

    .invoice-header {
        flex-direction: column;
        gap: 20px;
    }

    .invoice-info {
        text-align: left;
    }

    .invoice-table {
        font-size: 0.85rem;
    }

    .invoice-table th,
    .invoice-table td {
        padding: 8px 5px;
    }

    .total-row {
        min-width: 100%;
    }

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

    .form-actions .btn {
        width: 100%;
    }

    .input-with-button {
        flex-direction: column;
    }

    .input-with-button input {
        width: 100%;
    }
}

@media print {
    body {
        background: white;
    }

    .container {
        box-shadow: none;
    }

    .form-actions,
    .api-config-section,
    .invoice-form-section,
    .invoice-preview h2 {
        display: none !important;
    }
}
