/* Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
}

body {
    font-family: 'Heebo', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    direction: rtl;
    text-align: right;
    color: #333;
    line-height: 1.6;
}

/* Container */
.container {
    max-width: 800px;
    margin: 0 auto;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

/* Header */
header {
    background: linear-gradient(135deg, #1a365d 0%, #2c5282 100%);
    color: #fff;
    padding: 30px;
    text-align: center;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 8px;
}

header h2 {
    font-size: 1.1rem;
    font-weight: 400;
    opacity: 0.9;
}

/* Main Content */
main {
    padding: 30px;
}

/* Form Sections */
.form-section {
    margin-bottom: 30px;
    padding-bottom: 30px;
    border-bottom: 1px solid #e2e8f0;
}

.form-section:last-of-type {
    border-bottom: none;
    margin-bottom: 20px;
}

.form-section h3 {
    color: #1a365d;
    font-size: 1.25rem;
    margin-bottom: 20px;
    padding-right: 15px;
    border-right: 4px solid #667eea;
}

/* Form Groups */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 8px;
    color: #4a5568;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="tel"] {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.3s, box-shadow 0.3s;
    direction: rtl;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.form-group input::placeholder {
    color: #a0aec0;
}

.field-hint {
    display: block;
    font-size: 0.85rem;
    color: #718096;
    margin-top: 4px;
}

/* Date Display */
.date-display {
    background: #f7fafc;
    padding: 15px 20px;
    border-radius: 8px;
    font-size: 1.1rem;
    color: #2d3748;
    text-align: center;
    border: 1px solid #e2e8f0;
}

/* Signature Section */
.signature-section {
    background: #f7fafc;
    margin: 0 -30px;
    padding: 30px;
    border-radius: 0;
}

.signature-instructions {
    color: #718096;
    margin-bottom: 15px;
    font-size: 0.95rem;
}

.signature-wrapper {
    background: #fff;
    border: 2px dashed #cbd5e0;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 15px;
}

#signatureCanvas {
    width: 100%;
    height: 200px;
    display: block;
    background: #fff;
    border-radius: 4px;
    touch-action: none; /* Prevent scrolling while signing on mobile */
    -webkit-user-select: none;
    user-select: none;
    cursor: crosshair;
}

.signature-actions {
    text-align: center;
    padding-top: 10px;
}

/* Agreement Text */
.agreement-text {
    background: #fffbeb;
    margin: 0 -30px;
    padding: 30px;
}

.agreement-content {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 20px;
    max-height: 400px;
    overflow-y: auto;
    font-size: 0.95rem;
    line-height: 1.8;
    margin-bottom: 20px;
}

.agreement-content p {
    margin-bottom: 15px;
}

.agreement-content ol {
    padding-right: 25px;
    margin-bottom: 15px;
}

.agreement-content ol li {
    margin-bottom: 15px;
}

/* Checkbox */
.checkbox-group {
    margin-top: 20px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-weight: 500;
}

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-left: 10px;
    cursor: pointer;
    accent-color: #667eea;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 14px 28px;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #e2e8f0;
    color: #4a5568;
}

.btn-secondary:hover:not(:disabled) {
    background: #cbd5e0;
}

.btn-success {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: #fff;
}

.btn-success:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(72, 187, 120, 0.4);
}

/* Form Actions */
.form-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
    padding-top: 20px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    padding: 20px;
    overflow-y: auto;
}

.modal.active {
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.modal-content {
    background: #fff;
    border-radius: 16px;
    width: 100%;
    max-width: 700px;
    margin: 40px auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 1px solid #e2e8f0;
}

.modal-header h2 {
    font-size: 1.3rem;
    color: #1a365d;
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.8rem;
    color: #718096;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.close-modal:hover {
    color: #e53e3e;
}

.modal-body {
    padding: 25px;
    max-height: 60vh;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    gap: 15px;
    justify-content: center;
    padding: 20px 25px;
    border-top: 1px solid #e2e8f0;
    background: #f7fafc;
    border-radius: 0 0 16px 16px;
}

/* Preview Content */
.preview-document {
    font-size: 0.9rem;
    line-height: 1.8;
}

.preview-document h4 {
    text-align: center;
    margin-bottom: 20px;
    color: #1a365d;
    text-decoration: underline;
}

.preview-field {
    background: #fff3cd;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 600;
}

.preview-signature {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #e2e8f0;
}

.preview-signature img {
    max-width: 250px;
    height: auto;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
}

/* Loading Overlay */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    z-index: 2000;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid #e2e8f0;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-overlay p {
    font-size: 1.2rem;
    color: #4a5568;
}

/* Success Message */
.success-message {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.success-content {
    background: #fff;
    border-radius: 16px;
    padding: 50px;
    text-align: center;
    max-width: 500px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.success-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: #fff;
    font-size: 3rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 25px;
}

.success-content h2 {
    color: #1a365d;
    margin-bottom: 15px;
}

.success-content p {
    color: #718096;
    margin-bottom: 10px;
}

.success-content .submitted-note {
    font-size: 0.9rem;
    color: #a0aec0;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e2e8f0;
}

.success-content .btn {
    margin-top: 25px;
}

/* Required Field Indicator */
.required {
    color: #e53e3e;
    font-weight: 700;
    margin-right: 2px;
}

/* Error Styles */
.error-message {
    background: #fed7d7;
    color: #c53030;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid #fc8181;
}

.form-group.error input {
    border-color: #e53e3e;
    background-color: #fff5f5;
}

.form-group.error input:focus {
    border-color: #e53e3e;
    box-shadow: 0 0 0 3px rgba(229, 62, 62, 0.2);
}

.form-group.error .field-hint {
    color: #e53e3e;
}

.error-hint {
    display: block;
    font-size: 0.85rem;
    color: #e53e3e;
    margin-top: 4px;
    font-weight: 500;
}

/* Signature wrapper error state */
.signature-wrapper.error {
    border-color: #e53e3e;
    background-color: #fff5f5;
}

/* Checkbox error state */
.checkbox-group.error .checkbox-label {
    color: #e53e3e;
}

.checkbox-group.error .checkbox-label input[type="checkbox"] {
    accent-color: #e53e3e;
}

/* Responsive Design */
@media (max-width: 600px) {
    body {
        padding: 10px;
    }

    header {
        padding: 20px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    header h2 {
        font-size: 1rem;
    }

    main {
        padding: 20px;
    }

    .form-section h3 {
        font-size: 1.1rem;
    }

    .signature-section,
    .agreement-text {
        margin: 0 -20px;
        padding: 20px;
    }

    .agreement-content {
        max-height: 300px;
        padding: 15px;
    }

    #signatureCanvas {
        height: 150px;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
    }

    .modal-content {
        margin: 20px auto;
    }

    .modal-body {
        max-height: 50vh;
    }

    .modal-footer {
        flex-direction: column;
    }

    .modal-footer .btn {
        width: 100%;
    }
}

/* Print Styles */
@media print {
    body {
        background: #fff;
        padding: 0;
    }

    .container {
        box-shadow: none;
        border-radius: 0;
    }

    .signature-section,
    .agreement-text {
        background: #fff;
    }

    .form-actions,
    .modal,
    .loading-overlay,
    .success-message {
        display: none !important;
    }
}
