/* Modal styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1080;  /* Above primary nav (1070) */
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1075;  /* Between nav and modal dialog */
}

.modal-dialog {
    position: relative;
    width: auto;
    max-width: 500px;
    margin: 0.5rem;
    z-index: 1090;  /* Above backdrop and nav */
    animation: slideDown 0.3s ease-out;
}

.modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.5;
    color: var(--text-primary);
}

.modal-body {
    position: relative;
    flex: 1 1 auto;
    padding: 1.5rem;
}

.modal-body p {
    margin: 0;
    color: var(--text-secondary);
    line-height: 1.6;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
}

/* Close button */
.button-close {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    margin: -4px -8px -4px 0;
    border: 0;
    background: transparent;
    border-radius: 6px;
    color: var(--text-secondary, #6b7280);
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
}

.button-close::before,
.button-close::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 2px;
    background-color: currentColor;
    border-radius: 2px;
    transition: all 0.2s ease;
}

.button-close::before {
    transform: rotate(45deg);
}

.button-close::after {
    transform: rotate(-45deg);
}

.button-close:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--text-primary, #111827);
    transform: scale(1.05);
}

.button-close:active {
    transform: scale(0.95);
}

.button-close:focus {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Dark theme close button */
.button-close {
    color: rgba(255, 255, 255, 0.6);
}

.button-close:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
}

.button-close:focus {
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.2);
}

/* Auto dark mode based on system preference */
@media (prefers-color-scheme: dark) {
    .button-close {
        color: rgba(255, 255, 255, 0.6);
    }
    
    .button-close:hover {
        background-color: rgba(255, 255, 255, 0.1);
        color: rgba(255, 255, 255, 0.9);
    }
    
    .button-close:focus {
        box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.2);
    }
}

/* Modal open body state */
body.modal-open {
    overflow: hidden;
}

/* Button variants for modal */
.modal-footer .button {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.5;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease-in-out;
    border: 1px solid transparent;
}

.modal-footer .button-secondary {
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
}

.modal-footer .button-secondary:hover {
    background-color: var(--bg-tertiary);
}

/* Modal buttons inherit from their respective button classes */

.modal-footer .button-danger {
    color: white;
    background-color: #dc3545;
    border-color: #dc3545;
}

.modal-footer .button-danger:hover {
    background-color: #c82333;
    border-color: #bd2130;
}

.modal-footer .button:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

/* Spinner for processing state */
.spinner-border {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    vertical-align: text-bottom;
    border: 0.15em solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spinner-border 0.75s linear infinite;
}

.spinner-border-sm {
    width: 0.875rem;
    height: 0.875rem;
    border-width: 0.125em;
}

@keyframes spinner-border {
    to {
        transform: rotate(360deg);
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

/* Dark theme adjustments - Match dropdown styling */
.modal-content {
    background:
        /* Subtle metallic sheen overlay */
        linear-gradient(
            110deg,
            transparent 0%,
            transparent 40%,
            rgba(255, 255, 255, 0.03) 50%,
            transparent 60%,
            transparent 100%
        ),
        /* Vertical highlight for polish effect */
        linear-gradient(
            to bottom,
            rgba(255, 255, 255, 0.02) 0%,
            transparent 15%,
            transparent 85%,
            rgba(0, 0, 0, 0.02) 100%
        ),
        /* Base dark purple gradient */
        linear-gradient(
            to bottom,
            rgba(45, 38, 62, 0.98),
            rgba(35, 30, 48, 0.98)
        );
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 
        0 10px 25px rgba(0, 0, 0, 0.4),
        inset 0 -1px 0 0 rgba(255, 255, 255, 0.1);
}

.modal-header {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

.modal-footer {
    border-top-color: rgba(255, 255, 255, 0.1);
}

.modal-backdrop {
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.btn-secondary {
    background-color: #2a2a2a;
    border-color: #333;
    color: #e0e0e0;
}

.btn-secondary:hover {
    background-color: #333;
}

/* Modal Success State */
.modal-success-icon {
    display: flex;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.modal-success-icon svg {
    width: 64px;
    height: 64px;
    color: #10b981;
}

.modal-success-title {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0 0 1rem;
    color: var(--text-primary);
}

.modal-description {
    text-align: center;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0 0 1.5rem;
}

.modal-content-wrapper {
    padding: 1.5rem;
}

.modal-content-wrapper .form-actions {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
}

/* Responsive adjustments */
@media (min-width: 576px) {
    .modal-dialog {
        max-width: 500px;
        margin: 1.75rem auto;
    }
}

/* Small screens - full screen modal with scrollable content */
@media (max-width: 767px), (max-height: 600px) {
    .modal {
        align-items: flex-start;
    }

    .modal-dialog {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        margin: 0;
        display: flex;
        flex-direction: column;
    }

    .modal-content {
        flex: 1;
        display: flex;
        flex-direction: column;
        height: 100%;
        border-radius: 0;
        border: none;
        max-height: 100vh;
    }

    .modal-header {
        flex-shrink: 0;
        padding: 1rem 1.25rem;
    }

    .modal-title {
        font-size: 1.125rem;
    }

    .modal-body {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        padding: 1.25rem;
    }

    .modal-footer {
        flex-shrink: 0;
        padding: 1rem 1.25rem;
    }

    .modal-backdrop {
        display: none;
    }
}

/* Very small height screens - ensure critical content visible */
@media (max-height: 500px) {
    .modal-header {
        padding: 0.75rem 1rem;
    }

    .modal-title {
        font-size: 1rem;
    }

    .modal-body {
        padding: 1rem;
    }

    .modal-footer {
        padding: 0.75rem 1rem;
    }
}
