/* Base */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f5f5f5;
    margin: 0;
    padding: 0;
    color: #333;
}

/* Header */
.site-header {
    text-align: center;
    padding: 1rem;
    background: #48ABA3;
    border-bottom: none;
}
.site-header h1 {
    margin: 0;
    font-size: 1.5rem;
    color: #ffffff;
}
.site-header__logo {
    display: block;
    height: 32px;
    width: auto;
    margin: 0 auto 0.5rem;
    filter: brightness(0) invert(1);
}

/* Form container (D-11 centered card) */
.form-container {
    max-width: 540px;
    margin: 1rem;
    padding: 1rem;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Section grouping (D-03) */
.form-section {
    margin-bottom: 2rem;
}
.form-section__title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e0e0e0;
    color: #1a1a1a;
}

/* Form fields */
.form-field {
    margin-bottom: 1rem;
}
.form-field label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
    font-size: 0.9rem;
}
.form-field input,
.form-field select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
    box-sizing: border-box;
}
.form-field input:focus,
.form-field select:focus {
    outline: none;
    border-color: #48ABA3;
    box-shadow: 0 0 0 2px rgba(72, 171, 163, 0.2);
}
.optional {
    font-weight: 400;
    color: #6b7280;
    font-size: 0.85rem;
}

/* Input group for $ prefix (D-04) */
.input-group {
    display: flex;
    align-items: stretch;
}
.input-group__prefix {
    display: flex;
    align-items: center;
    padding: 0 0.75rem;
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    border-right: none;
    border-radius: 4px 0 0 4px;
    font-weight: 600;
    font-size: 1rem;
    color: #333;
}
.input-group input {
    border-radius: 0 4px 4px 0;
    flex: 1;
}

/* Card container -- Square SDK iframe renders here */
#card-container {
    min-height: 89px;
    margin-bottom: 0.5rem;
    padding: 0;
}

/* Card section styling */
#section-card {
    margin-bottom: 1.5rem;
}

/* Card error message */
#card-errors {
    display: none;
    color: #dc2626;
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

/* Submit button (D-13) */
#pay-button {
    width: 100%;
    padding: 0.75rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: #fff;
    background-color: #48ABA3;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.15s;
}
#pay-button:hover:not(:disabled) {
    background-color: #3d918a;
}
#pay-button:disabled {
    background-color: #9ca3af;
    cursor: not-allowed;
}

/* Validation error styles */
.form-field__error {
    display: none;
    color: #dc2626;
    font-size: 0.8rem;
    margin-top: 0.25rem;
}
.form-field__input--error,
input.form-field__input--error,
select.form-field__input--error {
    border-color: #dc2626;
    box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.2);
}

/* Amount Summary (FORM-09, D-03) */
.amount-summary {
    background-color: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 6px;
    padding: 12px 16px;
    margin: 0 0 16px 0;
    text-align: center;
    font-size: 16px;
    color: #166534;
}

.amount-summary strong {
    font-size: 20px;
    color: #15803d;
}

/* Desktop enhancement */
@media (min-width: 600px) {
    .form-container {
        margin: 2rem auto;
        padding: 2rem;
    }
    .site-header {
        padding: 1.5rem 1rem;
    }
    .site-header__logo {
        height: 40px;
    }
}

/* === Phase 6: Payment Result States === */

/* Loading spinner (UX-06) */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e0e0e0;
    border-top-color: #48ABA3;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Processing overlay (UX-06) */
.result-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 100;
    font-size: 1.1rem;
    color: #333;
}

/* Hidden by default — toggled via JS (avoids inline style CSP violations) */
.hidden {
    display: none;
}

/* Processing button state (UX-06) */
.pay-button--processing {
    background-color: #6b7280 !important;
    cursor: wait !important;
}

/* Result sections -- success and failure (UX-01, UX-02) */
.result-section {
    max-width: 540px;
    margin: 2rem auto;
    padding: 2rem;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.result-section h2 {
    margin: 0 0 1rem 0;
    font-size: 1.4rem;
    color: #1a1a1a;
}

.result-section__icon {
    font-size: 2rem;
    width: 64px;
    height: 64px;
    line-height: 64px;
    border-radius: 50%;
    margin: 0 auto 1rem;
}

.result-section__icon--success {
    background: #f0fdf4;
    color: #16a34a;
    border: 2px solid #bbf7d0;
}

.result-section__icon--error {
    background: #fef2f2;
    color: #dc2626;
    border: 2px solid #fecaca;
}

/* Warning icon for duplicate payment (PAY-06) */
.result-section__icon--warning {
    background: #fffbeb;
    color: #d97706;
    border: 2px solid #fde68a;
}

/* Result details definition list (UX-01) */
.result-details {
    text-align: left;
    max-width: 300px;
    margin: 1.5rem auto;
}

.result-details dt {
    font-size: 0.85rem;
    color: #6b7280;
    margin-top: 0.75rem;
}

.result-details dd {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0.25rem 0 0 0;
}

/* Error message (UX-02) */
.result-section__message {
    color: #6b7280;
    margin: 0 0 1.5rem 0;
}

/* Retry button (UX-02) */
.result-section__retry {
    display: inline-block;
    padding: 0.75rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background-color: #48ABA3;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.15s;
}

.result-section__retry:hover {
    background-color: #3d918a;
}

/* Cancel button for duplicate warning (PAY-06) */
.result-section__cancel {
    display: inline-block;
    padding: 0.75rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    color: #6b7280;
    background-color: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    cursor: pointer;
    margin-left: 0.5rem;
    transition: background-color 0.15s;
}

.result-section__cancel:hover {
    background-color: #e5e7eb;
}

/* Actions row for buttons (PAY-06) */
.result-section__actions {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* Print receipt button (UX-05) */
.result-section__print {
    display: inline-block;
    margin-top: 0.75rem;
    padding: 0.5rem 1.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: #48ABA3;
    background: transparent;
    border: 1px solid #48ABA3;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.15s;
}

.result-section__print:hover {
    background-color: rgba(72, 171, 163, 0.1);
}

/* Make Another Payment link (UX-01) */
.result-section__link {
    display: inline-block;
    margin-top: 1.5rem;
    color: #48ABA3;
    text-decoration: none;
    font-weight: 500;
}

.result-section__link:hover {
    text-decoration: underline;
}

/* === Phase 8: Print Stylesheet (UX-05) === */

@media print {
    /* Hide non-receipt elements */
    .site-header,
    #payment-form,
    .amount-summary,
    #payment-processing,
    #payment-failure,
    #payment-duplicate,
    .result-section__link,
    .result-section__retry,
    .result-section__cancel,
    .result-section__actions,
    .result-section__print,
    #print-button {
        display: none !important;
    }

    /* Clean body for print */
    body {
        background: #fff !important;
        color: #000 !important;
        margin: 0;
        padding: 0;
        font-size: 12pt;
    }

    /* Remove card styling from result section */
    .result-section {
        box-shadow: none !important;
        border: none !important;
        margin: 0 !important;
        padding: 1cm 0 !important;
        max-width: 100% !important;
        background: #fff !important;
    }

    .result-section h2 {
        color: #000 !important;
        font-size: 16pt;
    }

    /* Success icon: black border on white for print */
    .result-section__icon--success {
        border: 2px solid #000 !important;
        color: #000 !important;
        background: #fff !important;
    }

    /* Transaction details: clean black text */
    .result-details dt {
        color: #555 !important;
        font-size: 10pt;
    }

    .result-details dd {
        color: #000 !important;
        font-size: 12pt;
    }

    /* Add printed receipt footer */
    .result-section::after {
        content: "QCS Invoice Payment Receipt";
        display: block;
        margin-top: 2cm;
        padding-top: 0.5cm;
        border-top: 1px solid #ccc;
        font-size: 9pt;
        color: #999;
        text-align: center;
    }

    /* Form container: remove card styling */
    .form-container {
        box-shadow: none !important;
        border: none !important;
        margin: 0 !important;
        padding: 0 !important;
        max-width: 100% !important;
        background: #fff !important;
    }
}
