/* ==========================================================================
   Shared Modal and Form Styles
   ========================================================================== */

/* Modal Overlay & Content
   -------------------------------------------------------------------------- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    display: none;
    justify-content: center;
    align-items: center;
    padding: 10px;
    box-sizing: border-box;
}

.modal-overlay.visible {
    display: flex;
}

.modal-content {
    background-color: #fff;
    padding: 20px 30px;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}


.modal-content h2 {
    margin-top: 0;
    margin-bottom: 25px;
    text-align: center;
}



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

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 0.9rem;
}

.form-group input[type="text"],
.form-group input[type="search"],
.form-group input[type="datetime-local"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;

    box-sizing: border-box;
}

.form-row {
    display: flex;
    gap: 20px;
}

.form-row .form-group {

    flex: 1;
}

/* Checkbox & Radio Groups
   -------------------------------------------------------------------------- */
.checkbox-group {
    display: flex;

    flex-wrap: wrap;
    gap: 8px;
    max-height: 150px;
    overflow-y: auto;
}

.checkbox-group label {
    /* This is now the pill */
    display: inline-block;

    padding: 6px 14px;
    border-radius: 18px;
    background-color: #e9ecef;
    color: #495057;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;

    border: 1px solid #e9ecef;
    user-select: none; /* Prevent text selection on click */
}

.checkbox-group label:hover {
    background-color: #dee2e6;
}

.checkbox-group input[type="checkbox"] {

    display: none; /* Hide the actual checkbox */
}

.checkbox-group input[type="checkbox"]:checked + label {
    background-color: #007bff;

    color: #ffffff;
    border-color: #0056b3;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.radio-group label {

    font-weight: normal;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

/* Form Actions & Buttons
   -------------------------------------------------------------------------- */
.form-actions {

    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 25px;
}

.form-actions button {
    padding: 10px 20px;

    border-radius: 5px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.2s;
}
.form-actions .btn-primary { background-color: #007bff; color: white; }

.form-actions .btn-primary:hover { background-color: #0056b3; }

.form-actions .btn-secondary { background-color: #6c757d; color: white; }

.form-actions .btn-secondary:hover { background-color: #5a6268; }

.form-actions button:disabled { background-color: #ccc; cursor: not-allowed; }

/* Form Validation
   -------------------------------------------------------------------------- */
.error-message { color: #dc3545; font-size: 0.8rem; margin-top: 4px; }

.form-group .is-invalid,
.form-group input.is-invalid,
.form-group textarea.is-invalid,
.form-group select.is-invalid {
    border-color: #dc3545;

}

/* Character Counter for textareas
   -------------------------------------------------------------------------- */
.char-counter {
    text-align: right;
    font-size: 0.8rem;
    color: #6c757d;
    margin-top: 4px;
    transition: color 0.2s;
}
.char-counter.warning {
    color: #ffc107; /* Amber */
}
.char-counter.error {
    color: #dc3545; /* Red */
    font-weight: 600;
}

/* --- Multi-Photo Upload Previews --- */
#photo-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
    min-height: 100px; /* Give it some height to contain the 80px items + gap */
    align-items: flex-start;
    justify-content: flex-start;
}

.photo-preview-item {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    border: 2px dashed #ccc;
    background-color: #f0f0f0;
    padding: 2px;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

/* When an image is inside, make the border solid and remove padding */
.photo-preview-item:has(img) {
    border-style: solid;
    border-color: #ddd;
    padding: 0;
}

.photo-preview-item:hover {

    border-color: #007bff; /* Highlight on hover */
}

.photo-preview-item .image-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.spinner-small {
    width: 24px;
    height: 24px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.photo-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Ensures the image covers the area without distortion */
    border-radius: 6px; /* Match parent's border-radius minus a bit */
}

.remove-photo-btn {
    position: absolute;
    bottom: 5px;
    right: 5px;
    width: 22px;
    height: 22px;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
    padding: 0;
    transition: all 0.2s ease-in-out;
    /* Hidden by default */
    opacity: 0;
    visibility: hidden;
    transform: scale(0.8) translateY(5px);
}

/* Show button on hover of the parent item */
.photo-preview-item:hover .remove-photo-btn {
    opacity: 1;
    visibility: visible;
    transform: scale(1) translateY(0);
}

.remove-photo-btn:hover {
    background-color: #dc3545;
    border-color: #fff;
    transform: scale(1.1);
}

.upload-photo-btn {
    width: 80px;
    height: 80px;
    border: 2px dashed #ccc;
    border-radius: 8px;
    background-color: #f9f9f9;
    color: #555;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 5px;
    box-sizing: border-box;
    font-family: inherit;
    transition: all 0.2s ease-in-out;
    font-size: 0.8rem;
    text-align: center;
}

.upload-photo-btn:hover {
    border-color: #007bff;
    color: #007bff;
    background-color: #f0f5ff;
}

.upload-btn-text {
    font-weight: 600;
}

.upload-btn-counter {
    font-size: 0.9rem;
    font-weight: bold;
    margin-top: 4px;
}

/* --- Optional Flexbox Layout for Modals --- */
/* This provides a sticky header/footer layout */
.modal-content--layout-flex {
    display: flex;
    flex-direction: column;
    overflow: hidden; /* This is key to contain the scrolling area */
    padding: 0; /* Override default padding to manage it internally */
}

.modal-content--layout-flex > h2 {
    flex-shrink: 0;
    padding: 20px 30px 15px;
    margin: 0;
    border-bottom: 1px solid #eee;
    background-color: #fff; /* Ensure it covers scrolled content */
    z-index: 1; /* Keep above scrolling content */
}

.modal-content--layout-flex > form {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-content--layout-flex .form-scroll-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px 30px;
}

.modal-content--layout-flex .form-actions {
    flex-shrink: 0;
    border-top: 1px solid #eee;
    background-color: #fff; /* Ensure it covers scrolled content */
    padding: 15px 30px;
    margin-top: 0;
}
