/* Staged profile photo upload widget */

.file-input-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Default (inline) layout — auth pages without dashboard styles.css */
.profile-photo-upload:not(.profile-photo-upload--dashboard) {
    display: flex;
    align-items: flex-start;
    gap: 1.25rem 1.75rem;
    flex-wrap: wrap;
    padding: 1rem 1.25rem;
    border: 1px dashed #cbd5e1;
    border-radius: 12px;
    background: #f8fafc;
}

.profile-photo-upload:not(.profile-photo-upload--dashboard) .upload-actions {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    flex: 1 1 12rem;
    min-width: 0;
    max-width: 14rem;
}

.profile-photo-upload:not(.profile-photo-upload--dashboard) .btn-upload,
.profile-photo-upload:not(.profile-photo-upload--dashboard) .btn-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    box-sizing: border-box;
    width: 100%;
}

.profile-photo-upload:not(.profile-photo-upload--dashboard) .btn-upload {
    padding: 0.625rem 1.125rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #fff;
    background: #4caf50;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
}

.profile-photo-upload:not(.profile-photo-upload--dashboard) .btn-remove {
    padding: 0.625rem 1.125rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #dc2626;
    background: #fff;
    border: 1.5px solid #fca5a5;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.profile-photo-upload:not(.profile-photo-upload--dashboard) .btn-upload:hover {
    background: #43a047;
}

.profile-photo-upload:not(.profile-photo-upload--dashboard) .btn-remove:hover {
    background: #fef2f2;
    border-color: #f87171;
}

.profile-photo-upload:not(.profile-photo-upload--dashboard) .preview-avatar {
    width: 6.5rem;
    height: 6.5rem;
    border-radius: 12px;
    object-fit: cover;
    border: 2px solid #e2e8f0;
    background: #fff;
}

.profile-photo-upload:not(.profile-photo-upload--dashboard) .preview-avatar-placeholder {
    width: 6.5rem;
    height: 6.5rem;
    border-radius: 12px;
    border: 2px dashed #cbd5e1;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: #94a3b8;
}

.profile-photo-upload:not(.profile-photo-upload--dashboard) .upload-hint {
    margin: 0;
    font-size: 0.8125rem;
    line-height: 1.45;
    color: #64748b;
}

.profile-photo-upload .current-photo {
    position: relative;
}

.profile-photo-upload.is-uploading .current-photo::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.65);
    pointer-events: none;
}

.profile-photo-upload.is-uploading .current-photo::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2rem;
    height: 2rem;
    margin: -1rem 0 0 -1rem;
    border: 3px solid rgba(76, 175, 80, 0.25);
    border-top-color: var(--accent-color, #4caf50);
    border-radius: 50%;
    animation: profile-photo-upload-spin 0.75s linear infinite;
    z-index: 1;
}

.profile-photo-upload--dashboard.is-uploading .current-photo::after,
.profile-photo-upload--dashboard.is-uploading .current-photo::before {
    display: none;
}

.profile-photo-upload__preview-signature {
    max-height: 280px;
    max-width: min(100%, 420px);
    width: auto;
    object-fit: contain;
    border: 1px solid var(--border-color, #dee2e6);
    border-radius: 8px;
    padding: 0.75rem;
    /* Checkerboard is CSS-only (UI preview). It is NOT baked into the exported PNG. */
    background-color: #fff;
    background-image:
        linear-gradient(45deg, #e9ecef 25%, transparent 25%),
        linear-gradient(-45deg, #e9ecef 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e9ecef 75%),
        linear-gradient(-45deg, transparent 75%, #e9ecef 75%);
    background-size: 12px 12px;
    background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}

.profile-photo-upload--signature [data-preview-wrap] {
    position: relative;
    display: block;
    min-width: 12rem;
    max-width: 100%;
}

.profile-photo-upload--signature .profile-photo-upload__preview-overlay {
    border-radius: 8px;
}

.profile-photo-upload--signature .profile-photo-upload__status {
    max-width: none;
}

.profile-photo-upload--signature [data-warning][hidden] {
    display: none !important;
}

.profile-photo-upload__sig-compare {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem 1.25rem;
    justify-content: center;
    align-items: flex-start;
}

.profile-photo-upload__sig-compare[hidden] {
    display: none !important;
}

.profile-photo-upload__sig-pane {
    margin: 0;
    flex: 1 1 14rem;
    max-width: 100%;
    text-align: center;
}

.profile-photo-upload__sig-pane .profile-photo-upload__preview-signature {
    display: block;
    margin: 0 auto;
    max-height: 320px;
    max-width: min(100%, 520px);
    min-height: 8rem;
}

/* Original photo: solid plate (no checkerboard). */
.profile-photo-upload__sig-pane--before .profile-photo-upload__preview-signature {
    background-color: #f1f3f5;
    background-image: none;
}

.profile-photo-upload .btn-upload.disabled,
.profile-photo-upload .btn-upload[aria-disabled='true'] {
    opacity: 0.65;
    pointer-events: none;
    transform: none;
}

.profile-photo-upload-form-busy button[type='submit'],
.profile-photo-upload-form-busy input[type='submit'] {
    cursor: wait;
}

.profile-photo-upload__error[hidden] {
    display: none !important;
}

@keyframes profile-photo-upload-spin {
    to {
        transform: rotate(360deg);
    }
}

/* —— Dashboard card layout (add/edit staff & student) —— */

.profile-photo-upload--dashboard {
    display: block;
    width: 100%;
}

.profile-photo-upload--dashboard .profile-photo-upload__card {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 1.5rem 2rem;
    padding: 1.25rem 1.5rem;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 12px;
    background: var(--bg-secondary, #f8faf9);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.light-theme .profile-photo-upload--dashboard .profile-photo-upload__card {
    background: #f8faf9;
}

.profile-photo-upload--dashboard.is-dragover .profile-photo-upload__card {
    border-color: var(--accent-color, #4caf50);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.15);
}

.profile-photo-upload--dashboard.is-ready .profile-photo-upload__card {
    border-color: rgba(76, 175, 80, 0.45);
}

.profile-photo-upload__preview-col {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    min-width: 8.5rem;
}

.profile-photo-upload__preview-frame {
    position: relative;
    flex-shrink: 0;
}

.profile-photo-upload__avatar,
.profile-photo-upload--dashboard .preview-avatar {
    width: 7.5rem;
    height: 7.5rem;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid #fff;
    box-shadow: 0 2px 12px rgba(15, 23, 42, 0.1);
    display: block;
    transition: opacity 0.2s ease;
}

.profile-photo-upload__placeholder,
.profile-photo-upload--dashboard .preview-avatar-placeholder {
    width: 7.5rem;
    height: 7.5rem;
    border-radius: 50%;
    border: 2px dashed var(--border-color, #cbd5e1);
    background: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    font-size: 2.25rem;
    color: var(--text-secondary, #94a3b8);
    margin: 0;
}

.profile-photo-upload__placeholder-label {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-secondary, #94a3b8);
}

.profile-photo-upload__preview-overlay {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.82);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.profile-photo-upload__preview-overlay[hidden] {
    display: none !important;
}

.profile-photo-upload__spinner {
    width: 2rem;
    height: 2rem;
    border: 3px solid rgba(76, 175, 80, 0.2);
    border-top-color: var(--accent-color, #4caf50);
    border-radius: 50%;
    animation: profile-photo-upload-spin 0.7s linear infinite;
}

.profile-photo-upload__status {
    margin: 0;
    font-size: 0.75rem;
    font-weight: 500;
    text-align: center;
    min-height: 1.125rem;
    color: var(--text-secondary, #64748b);
    max-width: 8.5rem;
}

.profile-photo-upload--dashboard.is-uploading .profile-photo-upload__status {
    color: var(--accent-color, #4caf50);
}

.profile-photo-upload--dashboard.is-ready .profile-photo-upload__status {
    color: #15803d;
}

.profile-photo-upload__actions-col {
    flex: 1 1 14rem;
    min-width: 0;
    gap: 0.65rem !important;
}

.profile-photo-upload__title {
    margin: 0 0 0.15rem;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary, #1e293b);
}

.profile-photo-upload__extra {
    margin-bottom: 0.25rem;
}

.profile-photo-upload__extra .text-muted {
    margin-bottom: 0 !important;
    line-height: 1.45;
}

.profile-photo-upload__btn-row {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 0.5rem;
}

.profile-photo-upload__btn-row .btn-upload,
.profile-photo-upload__btn-row .btn-remove,
.profile-photo-upload__btn-row .profile-photo-upload__btn-primary,
.profile-photo-upload__btn-row .profile-photo-upload__btn-remove {
    flex: 1 1 10.5rem;
    min-width: 10.5rem;
}

/* Primary upload CTA — must be self-contained (auth/signup pages lack styles.css) */
.profile-photo-upload--dashboard .btn-upload,
.profile-photo-upload__btn-primary {
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6875rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.2;
    color: #ffffff !important;
    background: linear-gradient(180deg, #4caf50 0%, #43a047 100%) !important;
    border: 1px solid #3d9140 !important;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.35);
    cursor: pointer;
    text-decoration: none !important;
    transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
    width: fit-content;
    min-width: 10.5rem;
}

.profile-photo-upload--dashboard .btn-upload:hover,
.profile-photo-upload__btn-primary:hover {
    color: #ffffff !important;
    background: linear-gradient(180deg, #43a047 0%, #388e3c 100%) !important;
    border-color: #2e7d32 !important;
    box-shadow: 0 4px 14px rgba(76, 175, 80, 0.4);
    transform: translateY(-1px);
}

.profile-photo-upload--dashboard .btn-upload:active,
.profile-photo-upload__btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(76, 175, 80, 0.3);
}

.profile-photo-upload--dashboard .btn-upload i,
.profile-photo-upload__btn-primary i {
    font-size: 1.125rem;
    line-height: 1;
}

.profile-photo-upload__btn-primary:focus-visible,
.profile-photo-upload--dashboard .btn-upload:focus-visible {
    outline: 2px solid #4caf50;
    outline-offset: 2px;
}

.profile-photo-upload__btn-remove {
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #dc2626 !important;
    background: #ffffff !important;
    border: 1.5px solid #fca5a5 !important;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    min-width: 10.5rem;
    box-sizing: border-box;
}

.profile-photo-upload__btn-remove:hover {
    background: #fef2f2 !important;
    border-color: #f87171 !important;
}

.profile-photo-upload__btn-remove:focus-visible {
    outline: 2px solid #dc3545;
    outline-offset: 2px;
}

.profile-photo-upload__btn-remove:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.profile-photo-upload__hint {
    margin: 0.15rem 0 0 !important;
    font-size: 0.8125rem;
    line-height: 1.45;
    color: var(--text-secondary, #64748b);
}

.profile-photo-upload__formats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.15rem;
}

.profile-photo-upload__format-chip {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--text-secondary, #64748b);
    background: #fff;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 999px;
}

.profile-photo-upload--dashboard .profile-photo-upload__error {
    margin-top: 0.35rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    line-height: 1.4;
    color: #b91c1c;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
}

.profile-photo-upload--dashboard .profile-photo-upload__error[hidden] {
    display: none !important;
}

.profile-photo-upload--dashboard .selected-file-name {
    display: none !important;
}

.profile-photo-upload .file-input-hidden + .selected-file-name {
    display: none !important;
}

@media (max-width: 576px) {
    .profile-photo-upload.is-uploading .current-photo::before {
        width: 1.75rem;
        height: 1.75rem;
        margin: -0.875rem 0 0 -0.875rem;
    }

    .profile-photo-upload--dashboard .profile-photo-upload__card {
        flex-direction: column;
        align-items: stretch;
        padding: 1rem;
    }

    .profile-photo-upload__preview-col {
        align-items: center;
        width: 100%;
    }

    .profile-photo-upload__btn-row {
        flex-direction: column;
        align-items: stretch;
    }

    .profile-photo-upload__btn-row .btn-upload,
    .profile-photo-upload__btn-row .btn-remove,
    .profile-photo-upload--dashboard .btn-upload {
        width: 100%;
        justify-content: center;
        min-width: 0;
    }
}

/* —— School / brand logo (square preview, contain) —— */

.profile-photo-upload--logo .profile-photo-upload__avatar,
.profile-photo-upload--logo .preview-avatar,
.profile-photo-upload--logo .profile-photo-upload__placeholder,
.profile-photo-upload--logo .preview-avatar-placeholder {
    width: 7rem;
    height: 7rem;
    border-radius: 16px;
}

.profile-photo-upload--logo .profile-photo-upload__avatar,
.profile-photo-upload--logo .preview-avatar {
    object-fit: contain;
    padding: 0.35rem;
    background: #fff;
}

.profile-photo-upload--logo .profile-photo-upload__preview-overlay {
    border-radius: 16px;
}

.profile-photo-upload--logo .profile-photo-upload__placeholder-label {
    font-size: 0.625rem;
}

/* School registration form */
.school-logo-upload-field .profile-photo-upload--dashboard {
    margin-top: 0.25rem;
}

.school-logo-upload-field .profile-photo-upload--dashboard .profile-photo-upload__card {
    background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
}

.school-logo-upload-field .form-label {
    margin-bottom: 0.5rem;
}

@media (max-width: 576px) {
    .profile-photo-upload:not(.profile-photo-upload--dashboard) {
        flex-direction: column;
        align-items: stretch;
    }

    .profile-photo-upload:not(.profile-photo-upload--dashboard) .current-photo {
        align-self: center;
    }

    .profile-photo-upload:not(.profile-photo-upload--dashboard) .btn-upload,
    .profile-photo-upload:not(.profile-photo-upload--dashboard) .btn-remove {
        width: 100%;
        max-width: none;
    }

    .profile-photo-upload:not(.profile-photo-upload--dashboard) .upload-actions {
        max-width: none;
    }
}
