/* ========================================
   MODAL OVERLAYS (GENERIC)
   ======================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    display: block;
    /* changed from flex to allow absolute positioning of children */
    /* align-items: center;  Removed */
    /* justify-content: center; Removed */
    padding-top: 0;
    z-index: 5000;
    /* Higher than nav */
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 20px;
    width: 600px;
    max-width: 90vw;
    max-height: 90vh;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.3s, transform 0.3s;
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    background: linear-gradient(135deg, #be123c 0%, #f472b6 100%);
    padding: 20px 25px;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
}

.form-scroll-area {
    padding: 25px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    /* Take remaining space */
    min-height: 0;
    /* Critical for flex scrolling */
}

/* Ensure form takes full height of parent and flexes its child */
#manage-person-form {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    width: 100%;
}

/* ========================================
   FORM STYLING
   ======================================== */

.form-section-box {
    margin-bottom: 25px;
    padding: 20px;
    border: 1px solid #eef2f7;
    border-radius: 15px;
    background: #ffffff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.02);
}

.form-section-box h3 {
    font-size: 16px;
    color: #4a5568;
    margin-bottom: 20px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-left: 4px solid #be123c;
    padding-left: 12px;
}

.required {
    color: #e53e3e;
    font-weight: bold;
    margin-left: 2px;
}

.privacy-group {
    background: #f7fafc;
    padding: 10px;
    border-radius: 10px;
    border: 1px dashed #cbd5e0;
}

.privacy-group.compact {
    margin-top: -10px;
}

.form-group.privacy-group select {
    background: #fff;
    border-color: #cbd5e0;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #4a5568;
    margin-bottom: 8px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-size: 14px;
    transition: all 0.2s;
    background: #fdfdfd;
    color: #1e293b;
    /* Fix white-on-white issue */
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #be123c;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(190, 18, 60, 0.1);
}

.form-check-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 15px 0;
    padding: 12px;
    background: #f0fff4;
    border: 1px solid #c6f6d5;
    border-radius: 10px;
}

.form-check-row input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: #38a169;
}

.form-check-row label {
    font-weight: 600;
    color: #2f855a;
    cursor: pointer;
    margin-bottom: 0;
}

.read-only-field {
    background-color: #f1f5f9 !important;
    color: #64748b !important;
    cursor: not-allowed;
    border-style: dashed !important;
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding: 20px 25px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: transparent;
}

.btn-save,
.btn-create-new {
    background: #be123c;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.btn-create-new {
    display: block;
    width: calc(100% - 50px);
    margin: 25px auto;
    background: #b91c1c;
    padding: 14px;
    border-radius: 10px;
    text-align: center;
}

.btn-cancel {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-cancel:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ========================================
   SEARCH STYLING (In Modal)
   ======================================== */

.search-container {
    padding: 25px;
}

#relation-search-input {
    width: 100%;
    padding: 14px;
    border: 2px solid #f0f0f0;
    border-radius: 10px;
    font-size: 15px;
    margin-bottom: 15px;
}

.search-results {
    max-height: 250px;
    overflow-y: auto;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    color: #1e293b;
    /* Ensure text is dark on white background */
}

.search-result-item:hover {
    background: #f1f5f9;
    transform: translateX(5px);
}

.search-result-item strong {
    color: #0f172a;
}

.search-result-item small {
    color: #64748b;
}

/* Modal specific badge adjustments */
.search-result-item .badge-registered {
    background: rgba(22, 163, 74, 0.1);
    color: #166534;
    border: 1px solid rgba(22, 163, 74, 0.2);
}

.search-result-item .badge-unregistered {
    background: rgba(71, 85, 105, 0.1);
    color: #334155;
    border: 1px solid rgba(71, 85, 105, 0.2);
}

.search-result-item img {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #be123c;
}

.result-info {
    flex: 1;
}

.result-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}

.result-meta {
    font-size: 12px;
    color: #777;
    margin-bottom: 4px;
}

.view-profile-link {
    font-size: 11px;
    color: #be123c;
    text-decoration: none;
    font-weight: 600;
}

.view-profile-link:hover {
    text-decoration: underline;
}

.search-divider {
    display: flex;
    align-items: center;
    text-align: center;
    padding: 0 25px;
    color: #999;
}

.search-divider::before,
.search-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid #eee;
}

.search-divider span {
    padding: 0 15px;
    font-size: 12px;
    font-weight: 600;
}

/* ========================================
   PROFILE MODAL SPECIFIC
   ======================================== */

#profile-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 20px;
    padding: 0;
    width: 500px;
    max-width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 0 25px 70px rgba(0, 0, 0, 0.4);
    z-index: 6000;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#profile-modal.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0.9);
}

.profile-header {
    background: linear-gradient(135deg, #be123c 0%, #f472b6 100%);
    padding: 30px;
    border-radius: 20px 20px 0 0;
    display: flex;
    align-items: center;
    gap: 20px;
    color: white;
}

.profile-header img {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid white;
}

.profile-info h3 {
    font-size: 24px;
    margin-bottom: 4px;
}

.profile-info .nickname {
    font-size: 14px;
    opacity: 0.85;
    margin-bottom: 4px;
}

.profile-info .nickname span {
    font-weight: 600;
    font-style: italic;
    font-size: 16px;
    opacity: 1;
}

.profile-info .age {
    font-size: 14px;
    opacity: 0.8;
}

.profile-body {
    padding: 30px;
}

.profile-section {
    margin-bottom: 24px;
}

.profile-section h4 {
    font-size: 16px;
    color: #be123c;
    margin-bottom: 12px;
    font-weight: 600;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 8px;
}

.profile-section p {
    font-size: 14px;
    color: #555;
    line-height: 1.6;
    margin-bottom: 8px;
}

.profile-section .status {
    font-style: italic;
    color: #be123c;
    font-size: 15px;
}

.profile-footer {
    padding: 20px 30px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    justify-content: flex-end;
}

.btn-edit {
    background: #be123c;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-edit:hover {
    background: #9f1239;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(190, 18, 60, 0.3);
}

/* ========================================
   GALLERY STYLING
   ======================================== */

.photo-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.gallery-photo {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 8px;
    cursor: zoom-in;
    transition: transform 0.2s;
}

.gallery-photo:hover {
    transform: scale(1.05);
}

.gallery-upload-zone {
    border: 2px dashed #e2e8f0;
    padding: 15px;
    text-align: center;
    border-radius: 12px;
    margin-bottom: 15px;
    background: #f8fafc;
    transition: all 0.2s;
    /* Ensure input is visible and clickable */
    position: relative;
    cursor: pointer;
}

.gallery-upload-zone input[type="file"] {
    display: block;
    margin: 0 auto;
    padding: 10px;
    width: 100%;
    cursor: pointer;
}

.gallery-upload-zone:hover {
    border-color: #be123c;
    background: #fff1f2;
}

.gallery-edit-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    max-height: 300px;
    overflow-y: auto;
    padding: 5px;
}

.gallery-item {
    position: relative;
    aspect-ratio: 1;
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 10px;
    border: 2px solid transparent;
}

.gallery-item.primary img {
    border-color: #be123c;
    box-shadow: 0 0 10px rgba(190, 18, 60, 0.4);
}

.gallery-item-actions {
    position: absolute;
    bottom: 5px;
    left: 5px;
    right: 5px;
    display: flex;
    gap: 4px;
    opacity: 0.85;
    transition: opacity 0.2s;
}

.gallery-item-delete {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: white;
    background: rgba(0, 0, 0, 0.3);
    border: none;
    cursor: pointer;
}

.gallery-item-delete:hover {
    transform: scale(1.1);
    background: #ef4444;
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.btn-mini {
    padding: 4px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-size: 10px;
    flex: 1;
    color: white;
}

.btn-mini.set-primary {
    background: #be123c;
}



/* Prevent background scrolling when modal is open */
.body-no-scroll {
    overflow: hidden !important;
    height: 100vh;
    /* Lock height */
}

/* Lightbox Enhancements */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.lightbox.hidden {
    display: none;
}

.lightbox img {
    max-width: 90%;
    max-height: 90vh;
    border-radius: 4px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 30px;
    color: white;
    font-size: 40px;
    cursor: pointer;
    z-index: 2001;
    transition: color 0.2s;
}

.lightbox-close:hover {
    color: #ccc;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
    font-size: 40px;
    padding: 10px 20px;
    cursor: pointer;
    transition: background 0.3s;
    border-radius: 4px;
    user-select: none;
    z-index: 2001;
}

.lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.3);
}

.lightbox-nav.prev {
    left: 20px;
}

.lightbox-nav.next {
    right: 20px;
}

.upload-progress {
    font-size: 12px;
    color: #be123c;
    margin-top: 8px;
    font-weight: 600;
}