/* =========================
   TSP Select — Modal system
   ========================= */

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

:root {
    --modal-ease: cubic-bezier(0.16, 1, 0.3, 1);
    --modal-duration: 0.42s;
    --modal-glass: rgba(10, 22, 40, 0.92);
    --modal-glass-border: rgba(61, 181, 166, 0.22);
    --modal-glow: 0 0 0 1px rgba(42, 157, 143, 0.12),
        0 0 48px rgba(42, 157, 143, 0.08),
        0 24px 64px rgba(0, 0, 0, 0.45);
    --modal-field-bg: rgba(255, 255, 255, 0.04);
    --modal-field-border: rgba(255, 255, 255, 0.1);
    --modal-text: rgba(255, 255, 255, 0.92);
    --modal-text-muted: rgba(255, 255, 255, 0.62);
    --modal-label: rgba(255, 255, 255, 0.78);
}

body.modal-open {
    overflow: hidden;
}

/* Overlay */
.tsp-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(0.75rem, 3vw, 1.5rem);
    visibility: hidden;
    pointer-events: none;
}

.tsp-modal.is-open {
    visibility: visible;
    pointer-events: auto;
}

.tsp-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(5, 12, 24, 0.72);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    opacity: 0;
    transition: opacity var(--modal-duration) var(--modal-ease);
}

.tsp-modal.is-open .tsp-modal__backdrop,
.tsp-modal.is-closing .tsp-modal__backdrop {
    opacity: 1;
}

.tsp-modal.is-closing .tsp-modal__backdrop {
    opacity: 0;
}

/* Dialog */
.tsp-modal__dialog {
    position: relative;
    z-index: 1;
    width: min(100%, 40rem);
    max-height: min(92vh, 52rem);
    display: flex;
    flex-direction: column;
    background: var(--modal-glass);
    border: 1px solid var(--modal-glass-border);
    border-radius: 1.125rem;
    box-shadow: var(--modal-glow);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    opacity: 0;
    transform: scale(0.94) translateY(12px);
    transition:
        opacity var(--modal-duration) var(--modal-ease),
        transform var(--modal-duration) var(--modal-ease);
}

.tsp-modal--candidate .tsp-modal__dialog {
    width: min(100%, 38rem);
}

.tsp-modal.is-open .tsp-modal__dialog {
    opacity: 1;
    transform: scale(1) translateY(0);
}

.tsp-modal.is-closing .tsp-modal__dialog {
    opacity: 0;
    transform: scale(0.96) translateY(8px);
}

.tsp-modal__dialog::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    background: linear-gradient(
        135deg,
        rgba(61, 181, 166, 0.35) 0%,
        rgba(255, 255, 255, 0.06) 40%,
        rgba(42, 157, 143, 0.15) 100%
    );
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
}

/* Header */
.tsp-modal__header {
    flex-shrink: 0;
    padding: clamp(1.25rem, 3vw, 1.625rem) clamp(1.25rem, 3vw, 1.75rem) 0;
}

.tsp-modal__close {
    position: absolute;
    top: clamp(0.875rem, 2vw, 1.125rem);
    right: clamp(0.875rem, 2vw, 1.125rem);
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    color: var(--modal-text-muted);
    cursor: pointer;
    transition:
        color 0.2s ease,
        background 0.2s ease,
        border-color 0.2s ease;
}

.tsp-modal__close:hover,
.tsp-modal__close:focus-visible {
    color: var(--modal-text);
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(61, 181, 166, 0.35);
    outline: none;
}

.tsp-modal__eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.625rem;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-teal-400);
}

.tsp-modal__eyebrow-dot {
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 50%;
    background: var(--color-teal-500);
    box-shadow: 0 0 8px rgba(42, 157, 143, 0.6);
}

.tsp-modal__title {
    font-family: var(--font-display);
    font-size: clamp(1.375rem, 3.5vw, 1.625rem);
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -0.02em;
    color: var(--modal-text);
    padding-right: 2.5rem;
}

.tsp-modal__lead {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    line-height: 1.55;
    color: var(--modal-text-muted);
    max-width: 34rem;
}

/* Body / form */
.tsp-modal__body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: clamp(1rem, 2.5vw, 1.375rem) clamp(1.25rem, 3vw, 1.75rem);
    scrollbar-width: thin;
    scrollbar-color: rgba(42, 157, 143, 0.35) transparent;
}

.tsp-modal__body::-webkit-scrollbar {
    width: 6px;
}

.tsp-modal__body::-webkit-scrollbar-thumb {
    background: rgba(42, 157, 143, 0.35);
    border-radius: 3px;
}

.tsp-modal__form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.tsp-modal__grid {
    display: grid;
    gap: 1rem;
}

@media (min-width: 540px) {
    .tsp-modal__grid--2 {
        grid-template-columns: 1fr 1fr;
    }
}

.tsp-modal__field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.tsp-modal__field--full {
    grid-column: 1 / -1;
}

.tsp-modal__label {
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    color: var(--modal-label);
}

.tsp-modal__label .tsp-modal__required {
    color: var(--color-teal-400);
    margin-left: 0.125rem;
}

.tsp-modal__input,
.tsp-modal__select,
.tsp-modal__textarea {
    width: 100%;
    padding: 0.6875rem 0.875rem;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    color: var(--modal-text);
    background: var(--modal-field-bg);
    border: 1px solid var(--modal-field-border);
    border-radius: 0.5rem;
    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        background 0.2s ease;
}

.tsp-modal__input::placeholder,
.tsp-modal__textarea::placeholder {
    color: rgba(255, 255, 255, 0.32);
}

.tsp-modal__input:hover,
.tsp-modal__select:hover,
.tsp-modal__textarea:hover {
    border-color: rgba(61, 181, 166, 0.28);
}

.tsp-modal__input:focus,
.tsp-modal__select:focus,
.tsp-modal__textarea:focus {
    outline: none;
    border-color: rgba(42, 157, 143, 0.55);
    box-shadow: 0 0 0 3px rgba(42, 157, 143, 0.12);
    background: rgba(255, 255, 255, 0.06);
}

.tsp-modal__select {
    appearance: none;
    padding-right: 2.25rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%237a8a9e' d='M1.41 0L6 4.58 10.59 0 12 1.41l-6 6-6-6z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.875rem center;
    cursor: pointer;
}

.tsp-modal__select option {
    background: var(--color-navy-900);
    color: var(--color-white);
}

.tsp-modal__textarea {
    min-height: 5.5rem;
    resize: vertical;
}

/* File upload */
.tsp-modal__file {
    position: relative;
}

.tsp-modal__file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.tsp-modal__file-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    font-size: 0.8125rem;
    color: var(--modal-text-muted);
    background: var(--modal-field-bg);
    border: 1px dashed rgba(61, 181, 166, 0.35);
    border-radius: 0.5rem;
    cursor: pointer;
    transition:
        border-color 0.2s ease,
        background 0.2s ease,
        color 0.2s ease;
}

.tsp-modal__file-label:hover {
    border-color: rgba(42, 157, 143, 0.5);
    background: rgba(42, 157, 143, 0.06);
    color: var(--modal-text);
}

.tsp-modal__file-label i {
    font-size: 1.125rem;
    color: var(--color-teal-400);
}

.tsp-modal__file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tsp-modal__file-input:focus-visible + .tsp-modal__file-label {
    outline: 2px solid rgba(42, 157, 143, 0.5);
    outline-offset: 2px;
}

.tsp-modal__file-input.is-invalid + .tsp-modal__file-label {
    border-color: rgba(220, 80, 80, 0.6);
}

/* Footer */
.tsp-modal__footer {
    flex-shrink: 0;
    padding: 0 clamp(1.25rem, 3vw, 1.75rem) clamp(1.25rem, 3vw, 1.625rem);
}

.tsp-modal__submit {
    width: 100%;
    --btn-bg: linear-gradient(135deg, var(--color-teal-600) 0%, var(--color-teal-500) 100%);
    --btn-color: var(--color-white);
    --btn-border: 1px solid rgba(61, 181, 166, 0.4);
    box-shadow: 0 4px 20px rgba(42, 157, 143, 0.25);
}

.tsp-modal__submit:hover {
    box-shadow: 0 6px 28px rgba(42, 157, 143, 0.35);
}

.tsp-modal__submit:disabled {
    opacity: 0.85;
    cursor: wait;
}

.tsp-modal__submit-spinner {
    display: none;
}

.tsp-modal__submit.is-loading .tsp-modal__submit-icon {
    display: none;
}

.tsp-modal__submit.is-loading .tsp-modal__submit-spinner {
    display: inline-block;
}

.tsp-modal__feedback {
    margin-top: 0.75rem;
    font-size: 0.75rem;
    line-height: 1.45;
    text-align: center;
    color: rgba(255, 255, 255, 0.72);
}

.tsp-modal__feedback.is-success {
    color: rgba(120, 220, 180, 0.95);
}

.tsp-modal__feedback.is-error {
    color: rgba(255, 160, 160, 0.95);
}

.tsp-modal__note {
    margin-top: 0.75rem;
    font-size: 0.6875rem;
    line-height: 1.45;
    text-align: center;
    color: rgba(255, 255, 255, 0.4);
}

.tsp-modal__field.is-invalid .tsp-modal__input,
.tsp-modal__field.is-invalid .tsp-modal__select,
.tsp-modal__field.is-invalid .tsp-modal__textarea {
    border-color: rgba(220, 80, 80, 0.65);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .tsp-modal__backdrop,
    .tsp-modal__dialog {
        transition-duration: 0.01ms;
    }

    .tsp-modal.is-open .tsp-modal__dialog {
        transform: none;
    }
}
