/* Document Layout */
body {
    font-family: serif;
    line-height: 1.6;
    max-width: 800px;
    margin: 20px auto;
    padding: 20px;
    border: 1px solid #ccc;
}

h1 {
    text-align: center;
}

/* Form Inputs */
.fill-in {
    border: none;
    border-bottom: 1px solid #000;
    padding: 8px 5px;
    font-family: inherit;
    font-size: inherit;
    min-height: 44px; /* Mobile touch target minimum */
    box-sizing: border-box;
}

.fill-in[readonly] {
    background-color: #f5f5f5;
    color: #555;
    cursor: not-allowed;
}

/* Required field indicator */
.fill-in:invalid {
    border-bottom-color: #dc3545;
}

.fill-in:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* Agreement Sections */
.agreement-section {
    margin-bottom: 1em;
}

/* Signature Box */
.signature-box {
    border: 1px dashed #aaa;
    min-height: 60px;
    cursor: pointer;
    background-color: #f9f9f9;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #888;
    padding: 10px;
    transition: border-color 0.2s, background-color 0.2s;
}

.signature-box:active {
    background-color: #e9e9e9;
    border-color: #888;
}

.signature-box[data-signed="true"] {
    border-color: #28a745;
    border-style: solid;
}

.signature-box img {
    height: 100%;
    width: 100%;
    object-fit: contain;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: fit-content;
    text-align: center;
}

.modal-content h4 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #333;
}

/* Signature Pad Canvas */
#signature-pad {
    border: 2px solid #333;
    cursor: crosshair;
    touch-action: none;
    width: 100%;
    max-width: 500px;
    height: 200px;
    border-radius: 4px;
}

/* Modal Buttons */
.modal-content button {
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    min-height: 48px;
    min-width: 100px;
    padding: 12px 24px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.modal-content button:active {
    transform: scale(0.98);
}

#clear-signature {
    background-color: #6c757d;
}

#cancel-signature {
    background-color: #dc3545;
}

/* Compensation Lock Feature */
.field-lock-icon {
    display: inline-block;
    margin-left: 5px;
    font-size: 14px;
    user-select: none;
    transition: color 0.2s;
}

.field-lock-icon.unlocked {
    color: #28a745;
}

#compensation-field.unlocked {
    border-bottom-color: #28a745;
    background-color: transparent;
    cursor: text;
}

/* Authorization Modal */
.auth-modal-content {
    min-width: 320px;
}

.auth-code-input {
    width: 100%;
    max-width: 200px;
    padding: 12px;
    font-size: 18px;
    text-align: center;
    border: 2px solid #333;
    border-radius: 4px;
    font-family: monospace;
    letter-spacing: 3px;
}

.auth-code-input:focus {
    outline: 2px solid #007bff;
    border-color: #007bff;
}

.auth-error-message {
    color: #dc3545;
    font-size: 14px;
    min-height: 20px;
    margin: 10px 0 0 0;
    font-weight: 600;
}

/* Responsive Design */
@media (max-width: 600px) {
    body {
        margin: 10px;
        padding: 15px;
    }

    h1 {
        font-size: 1.5em;
    }

    /* Stack address fields vertically on mobile for better usability */
    .agreement-section p > div {
        margin-bottom: 10px;
    }

    /* Ensure inputs are easily tappable */
    .fill-in {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 10px 5px;
    }

    /* Make signature boxes more prominent on mobile */
    .signature-box {
        min-height: 80px;
        font-size: 16px;
    }

    .modal-content {
        width: 95%;
        max-width: 95vw;
        padding: 15px;
        margin: 10px;
    }

    #signature-pad {
        width: 100%;
        height: 250px; /* Larger on mobile */
        max-width: none;
    }

    .modal-content button {
        font-size: 18px;
        min-height: 52px;
        width: 100%;
        margin: 5px 0 !important;
    }

    .modal-content > div {
        display: flex;
        flex-direction: column;
        gap: 5px;
    }
}

/* Landscape orientation optimization for signatures */
@media (max-width: 900px) and (orientation: landscape) {
    .modal-content {
        width: 90%;
        max-width: 90vw;
        padding: 10px;
    }

    #signature-pad {
        height: 60vh;
        max-height: 300px;
    }
}

/* Form Action Buttons */
.form-actions {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 2px solid #ccc;
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.form-action-btn {
    background-color: #007bff;
    color: white;
    border: 2px solid #007bff;
    border-radius: 4px;
    font-size: 16px;
    font-weight: 600;
    min-height: 48px;
    min-width: 150px;
    padding: 12px 30px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: sans-serif;
}

.form-action-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.form-action-btn:active {
    transform: translateY(0);
}

#submit-form-btn {
    background-color: #28a745;
    border-color: #28a745;
}

#submit-form-btn:hover {
    background-color: #218838;
    border-color: #218838;
}

#download-pdf-btn {
    background-color: #007bff;
    border-color: #007bff;
}

#download-pdf-btn:hover {
    background-color: #0056b3;
    border-color: #0056b3;
}

#clear-form-btn {
    background-color: #dc3545;
    border-color: #dc3545;
}

#clear-form-btn:hover {
    background-color: #c82333;
    border-color: #c82333;
}

/* Mobile responsive buttons */
@media (max-width: 600px) {
    .form-actions {
        flex-direction: column;
        gap: 10px;
    }

    .form-action-btn {
        width: 100%;
        font-size: 18px;
        min-height: 52px;
    }
}

/* PDF Export Styles */
@media print {
    .form-actions {
        display: none !important;
    }

    .field-lock-icon {
        display: none !important;
    }

    body {
        border: 1px solid #000;
        margin: 0;
        padding: 5px !important;
        max-width: 100%;
        line-height: 1.4 !important;
        font-size: 14px !important;
    }

    .signature-box {
        border: 1px solid #000;
        background-color: white;
        min-height: 40px !important;
        max-height: 40px !important;
        height: 40px !important;
        padding: 2px !important;
    }

    .signature-box img {
        max-height: 36px !important;
        height: auto !important;
    }

    .fill-in {
        border-bottom: 1px solid #000;
    }

    /* Tighter spacing to fit content on fewer pages */
    .agreement-section {
        page-break-inside: avoid;
        margin-bottom: 0.5em !important;
    }

    h1 {
        margin-bottom: 0.5em !important;
    }
}

/* PDF generation specific class */
.pdf-generating {
    .form-actions {
        display: none !important;
    }

    .field-lock-icon {
        display: none !important;
    }
}
