/* Modal Overlay */
.modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.6);
    /* Slate 900 with opacity */
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

/* Modal Visible State */
.modal.is-visible {
    display: flex;
}

/* Modal Content Box */
.modal-content {
    background-color: white;
    padding: var(--spacing-lg);
    border-radius: var(--radius-md);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
    position: relative;
    animation: slideDown 0.3s ease-out;
    margin: var(--spacing-md);
}

.modal-content.modal-lg {
    max-width: 600px;
}

@media (max-width: 768px) {
    .modal-content {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
        display: flex;
        flex-direction: column;
        padding: 0;
        /* Handled by header/body/footer */
        animation: slideUp 0.3s ease-out;
        /* Slide from bottom for mobile */
    }

    .modal-content.modal-lg {
        max-width: 100%;
    }

    .modal-header {
        padding: var(--spacing-md);
        margin-bottom: 0;
        border-bottom: 1px solid var(--border-color);
        background: var(--bg-surface);
        position: sticky;
        top: 0;
        z-index: 10;
        flex-shrink: 0;
    }

    .close-btn {
        position: absolute;
        top: 10px;
        right: 10px;
        margin-left: 0;
    }

    .modal-title {
        font-size: 1.25rem;
        padding-top: var(--spacing-xs);
        padding-right: 40px;
        /* Prevent overlap with absolute close btn */
    }

    .modal-form {
        flex: 1;
        overflow-y: auto;
        padding: var(--spacing-md);
        margin-bottom: 0 !important;
        gap: var(--spacing-lg);
    }
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-md);
    border-bottom: 2px solid var(--border-color);
}

.modal-header>div {
    flex: 1;
}

.modal-title {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--color-primary);
    margin: 0 0 0.5rem 0;
}

.modal-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.4;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 8px;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    flex-shrink: 0;
    margin-left: var(--spacing-md);
}

@media (max-width: 480px) {
    .close-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        padding: 10px;
    }
}

.close-btn:hover {
    background-color: var(--bg-hover);
    color: var(--color-danger);
}

/* Form Styles */
.modal-form {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.form-section {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.form-section-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
    padding-top: var(--spacing-sm);
}

.form-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: block;
    margin-top: 4px;
    line-height: 1.3;
}

.required-asterisk {
    color: var(--color-danger);
}

.checkbox-group {
    gap: var(--spacing-xs);
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-sm);
    cursor: pointer;
    user-select: none;
}

.form-checkbox {
    width: 20px;
    height: 20px;
    min-width: 20px;
    margin-top: 2px;
    cursor: pointer;
    accent-color: var(--color-primary);
}

@media (max-width: 480px) {
    .form-checkbox {
        width: 22px;
        height: 22px;
        min-width: 22px;
        margin-top: 3px;
    }
}

.checkbox-text {
    font-size: 0.95rem;
    color: var(--text-main);
    flex: 1;
}

.modal-footer {
    margin-top: var(--spacing-lg);
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-sm);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--border-color);
}

.modal-footer button {
    min-height: 40px;
    padding: 0.6rem 1.25rem;
    display: inline-flex;
    align-items: center;
}

@media (max-width: 768px) {
    .modal-footer {
        position: sticky;
        bottom: 0;
        background: var(--bg-surface);
        padding: var(--spacing-md);
        margin-top: auto;
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        flex-shrink: 0;
        flex-direction: column-reverse;
        /* Stack vertically, primary button on top */
        gap: var(--spacing-sm);
    }

    .modal-footer button {
        width: 100%;
        min-height: 48px;
        /* Larger touch target for mobile thumb */
        justify-content: center;
        margin-left: 0 !important;
    }
}

@keyframes slideDown {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }

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