/* ============ WEBIKOS MODAL SYSTEM - TWITTER/X STYLE ============ */

/* Modal Overlay - Perfect backdrop */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-modal);
    backdrop-filter: blur(8px) saturate(150%);
    -webkit-backdrop-filter: blur(8px) saturate(150%);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-medium);
    cursor: pointer;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-overlay.active .modal-content {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* Modal Content Container */
.modal-content {
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    transform: scale(0.95) translateY(20px);
    opacity: 0;
    transition: all var(--transition-medium);
    cursor: default;
    position: relative;
    border: 1px solid var(--border-primary);
}

.modal-content::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent,
        var(--x-blue-light),
        transparent
    );
}

/* Modal Header */
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-primary);
    background: var(--bg-primary);
    position: sticky;
    top: 0;
    z-index: 100;
}

.modal-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    margin: 0;
    line-height: var(--line-height-tight);
}

.modal-close {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-full);
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.modal-close::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-hover-strong);
    border-radius: var(--radius-full);
    transform: scale(0);
    transition: var(--transition-fast);
}

.modal-close:hover::before {
    transform: scale(1);
}

.modal-close:hover {
    color: var(--text-primary);
}

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

/* Modal Body */
.modal-body {
    padding: 20px 24px 24px;
    background: var(--bg-primary);
    overflow-y: auto;
    max-height: calc(90vh - 200px);
}

.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--border-secondary);
    border-radius: var(--radius-full);
}

/* Modal Footer */
.modal-footer {
    padding: 16px 24px 24px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-primary);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    position: sticky;
    bottom: 0;
}

/* ============ MODAL VARIANTS ============ */

/* Large Modal */
.modal-content.modal-large {
    max-width: 80vw;
    max-height: 80vh;
}

/* Small Modal */
.modal-content.modal-small {
    max-width: 400px;
}

/* Full Screen Modal (Mobile) */
.modal-content.modal-fullscreen {
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    border-radius: 0;
    transform: translateY(100%);
}

.modal-overlay.active .modal-content.modal-fullscreen {
    transform: translateY(0);
}

/* ============ TWEET COMPOSE MODAL ============ */
.tweet-modal .modal-content {
    max-width: 600px;
}

.tweet-modal .modal-body {
    padding: 0;
}

.tweet-modal .composer-content {
    padding: 20px 24px;
    border-bottom: none;
}

.tweet-modal .composer-avatar {
    width: 48px;
    height: 48px;
}

.tweet-modal .composer-textarea {
    min-height: 120px;
    font-size: var(--font-size-xl);
    border: none;
    outline: none;
    resize: none;
}

.tweet-modal .composer-actions {
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border-primary);
    background: var(--bg-primary);
    position: sticky;
    bottom: 0;
}

/* ============ EDIT PROFILE MODAL ============ */
.edit-profile-modal .modal-content {
    max-width: 600px;
}

.edit-profile-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.edit-profile-form .form-group {
    margin-bottom: 0;
}

.edit-profile-form .form-group label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--text-secondary);
    margin-bottom: 6px;
    display: block;
}

.edit-profile-form .form-group input,
.edit-profile-form .form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-primary);
    border-radius: var(--radius-lg);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: var(--font-size-base);
    transition: var(--transition-fast);
    font-family: inherit;
}

.edit-profile-form .form-group input:focus,
.edit-profile-form .form-group textarea:focus {
    outline: none;
    border-color: var(--x-blue);
    box-shadow: 0 0 0 3px var(--x-blue-light);
}

.edit-profile-form .form-group textarea {
    resize: vertical;
    min-height: 80px;
    max-height: 200px;
    line-height: var(--line-height-relaxed);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding-top: 20px;
    border-top: 1px solid var(--border-primary);
    margin-top: 20px;
}

/* ============ CONFIRMATION MODALS ============ */
.confirmation-modal .modal-content {
    max-width: 320px;
    text-align: center;
}

.confirmation-modal .modal-body {
    padding: 32px 24px;
}

.confirmation-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    background: var(--x-red-light);
    color: var(--x-red);
}

.confirmation-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    margin-bottom: 8px;
}

.confirmation-text {
    font-size: var(--font-size-base);
    color: var(--text-secondary);
    line-height: var(--line-height-relaxed);
    margin-bottom: 24px;
}

.confirmation-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.btn-danger {
    background: var(--x-red);
    color: var(--text-inverse);
    border: none;
    padding: 12px 24px;
    border-radius: var(--radius-full);
    font-weight: var(--font-weight-bold);
    cursor: pointer;
    transition: var(--transition-fast);
}

.btn-danger:hover {
    background: var(--x-red-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* ============ IMAGE VIEWER MODAL ============ */
.image-modal .modal-content {
    max-width: 90vw;
    max-height: 90vh;
    background: rgba(0, 0, 0, 0.9);
    border: none;
    border-radius: var(--radius-lg);
}

.image-modal .modal-body {
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
}

.modal-image {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: var(--radius-md);
}

.image-modal .modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    width: 40px;
    height: 40px;
    z-index: 1001;
}

.image-modal .modal-close:hover {
    background: rgba(0, 0, 0, 0.9);
}

/* ============ LOADING MODAL ============ */
.loading-modal .modal-content {
    max-width: 300px;
    text-align: center;
    border: none;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
}

.loading-modal .modal-body {
    padding: 40px 24px;
}

.loading-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 16px;
    border: 4px solid var(--border-primary);
    border-top: 4px solid var(--x-blue);
    border-radius: var(--radius-full);
    animation: spin 1s linear infinite;
}

.loading-text {
    font-size: var(--font-size-base);
    color: var(--text-secondary);
    margin: 0;
}

/* ============ ANIMATIONS ============ */
@keyframes modalFadeIn {
    from {
        opacity: 0;
        backdrop-filter: blur(0px);
    }
    to {
        opacity: 1;
        backdrop-filter: blur(8px) saturate(150%);
    }
}

@keyframes modalSlideUp {
    from {
        transform: scale(0.9) translateY(60px);
        opacity: 0;
    }
    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

@keyframes modalSlideDown {
    from {
        transform: translateY(-100%);
    }
    to {
        transform: translateY(0);
    }
}

@keyframes shake {
    0%,
    100% {
        transform: translateX(0);
    }
    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-2px);
    }
    20%,
    40%,
    60%,
    80% {
        transform: translateX(2px);
    }
}

/* Apply animations */
.modal-overlay.active {
    animation: modalFadeIn var(--transition-medium) var(--ease-out-cubic);
}

.modal-content {
    animation: modalSlideUp var(--transition-medium) var(--ease-out-cubic);
}

.modal-content.modal-fullscreen {
    animation: modalSlideDown var(--transition-medium) var(--ease-out-cubic);
}

.modal-content.shake {
    animation: shake 0.5s var(--ease-out-cubic);
}

/* ============ MODAL BACKDROP CLICK ============ */
.modal-overlay[data-backdrop="true"] {
    cursor: pointer;
}

.modal-content {
    cursor: default;
}

/* ============ RESPONSIVE MODAL DESIGN ============ */
@media (max-width: 768px) {
    .modal-overlay {
        padding: 0;
        align-items: flex-end;
    }

    .modal-content:not(.modal-fullscreen) {
        width: 100%;
        max-width: none;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        max-height: 90vh;
        transform: translateY(100%);
    }

    .modal-overlay.active .modal-content:not(.modal-fullscreen) {
        transform: translateY(0);
    }

    .modal-header {
        padding: 16px 20px;
    }

    .modal-body {
        padding: 16px 20px 20px;
    }

    .modal-footer {
        padding: 12px 20px 20px;
    }

    .tweet-modal .composer-content {
        padding: 16px 20px;
    }

    .tweet-modal .composer-actions {
        padding: 12px 20px 16px;
    }
}

@media (max-width: 480px) {
    .modal-content:not(.modal-fullscreen) {
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }

    .modal-header {
        padding: 12px 16px;
    }

    .modal-title {
        font-size: var(--font-size-lg);
    }

    .modal-body {
        padding: 12px 16px 16px;
    }

    .modal-footer {
        padding: 8px 16px 16px;
    }

    .form-actions {
        flex-direction: column-reverse;
        gap: 8px;
    }

    .btn,
    .btn-secondary,
    .btn-danger {
        width: 100%;
        justify-content: center;
    }
}

/* ============ MODAL FOCUS MANAGEMENT ============ */
.modal-overlay[aria-hidden="true"] {
    pointer-events: none;
}

.modal-overlay[aria-hidden="false"] {
    pointer-events: all;
}

.modal-content:focus {
    outline: none;
}

/* Trap focus within modal */
.modal-overlay.active .modal-content {
    outline: none;
}

/* ============ MODAL BUTTON STYLING ============ */
.modal-body .btn,
.modal-footer .btn {
    padding: 12px 24px;
    border-radius: var(--radius-full);
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-base);
    cursor: pointer;
    transition: var(--transition-fast);
    border: none;
    position: relative;
    overflow: hidden;
}

.modal-body .btn::before,
.modal-footer .btn::before {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.2),
        transparent
    );
    transition: var(--transition-medium);
}

.modal-body .btn:hover::before,
.modal-footer .btn:hover::before {
    left: 100%;
}

/* Primary button in modals */
.modal-body .btn:not(.btn-secondary):not(.btn-danger),
.modal-footer .btn:not(.btn-secondary):not(.btn-danger) {
    background: var(--x-blue);
    color: var(--text-inverse);
}

.modal-body .btn:not(.btn-secondary):not(.btn-danger):hover,
.modal-footer .btn:not(.btn-secondary):not(.btn-danger):hover {
    background: var(--x-blue-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* Secondary button in modals */
.modal-body .btn-secondary,
.modal-footer .btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-secondary);
}

.modal-body .btn-secondary:hover,
.modal-footer .btn-secondary:hover {
    background: var(--bg-hover-strong);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

/* ============ FORM ELEMENTS IN MODALS ============ */
.modal-body .form-group {
    margin-bottom: 20px;
}

.modal-body .form-group:last-child {
    margin-bottom: 0;
}

.modal-body label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-primary);
    font-weight: var(--font-weight-medium);
    font-size: var(--font-size-sm);
}

.modal-body input,
.modal-body textarea,
.modal-body select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-primary);
    border-radius: var(--radius-lg);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: var(--font-size-base);
    font-family: inherit;
    transition: var(--transition-fast);
}

.modal-body input:focus,
.modal-body textarea:focus,
.modal-body select:focus {
    outline: none;
    border-color: var(--x-blue);
    box-shadow: 0 0 0 3px var(--x-blue-light);
}

.modal-body input::placeholder,
.modal-body textarea::placeholder {
    color: var(--text-tertiary);
}

.modal-body textarea {
    resize: vertical;
    min-height: 80px;
    line-height: var(--line-height-relaxed);
}

/* ============ ERROR STATES ============ */
.modal-body .error {
    background: var(--x-red-light);
    color: var(--x-red);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    border-left: 4px solid var(--x-red);
    font-size: var(--font-size-sm);
    margin-top: 8px;
    animation: slideInLeft 0.3s var(--ease-out-cubic);
}

.modal-body .success {
    background: var(--x-green-light);
    color: var(--x-green);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    border-left: 4px solid var(--x-green);
    font-size: var(--font-size-sm);
    margin-top: 8px;
    animation: slideInLeft 0.3s var(--ease-out-cubic);
}

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

/* ============ DARK MODE MODAL ADJUSTMENTS ============ */
:root[data-theme="dark"] .modal-overlay {
    background: rgba(91, 112, 131, 0.6);
    backdrop-filter: blur(8px) saturate(150%) brightness(0.8);
}

:root[data-theme="dark"] .modal-content {
    box-shadow:
        rgba(255, 255, 255, 0.1) 0px 0px 15px,
        rgba(255, 255, 255, 0.05) 0px 0px 3px 1px;
    border-color: var(--border-secondary);
}

:root[data-theme="dark"] .image-modal .modal-close {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
}

:root[data-theme="dark"] .image-modal .modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ============ ACCESSIBILITY ENHANCEMENTS ============ */
.modal-overlay[role="dialog"] {
    isolation: isolate;
}

.modal-content[role="document"] {
    position: relative;
}

/* Focus trap indicator */
.modal-overlay.active .modal-content {
    box-shadow:
        var(--shadow-lg),
        inset 0 0 0 2px var(--x-blue-ultra-light);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .modal-content {
        border: 2px solid var(--text-primary);
    }

    .modal-header {
        border-bottom: 2px solid var(--text-primary);
    }

    .modal-footer {
        border-top: 2px solid var(--text-primary);
    }
}

/* ============ MODAL STACK MANAGEMENT ============ */
.modal-overlay.stacked {
    z-index: 10001;
}

.modal-overlay.stacked .modal-content {
    transform: scale(0.98);
    filter: brightness(0.95);
}

.modal-overlay.stacked.active .modal-content {
    transform: scale(1);
    filter: brightness(1);
}

/* ============ SPECIAL EFFECTS ============ */
.modal-content.glow {
    box-shadow:
        var(--shadow-lg),
        0 0 40px var(--x-blue-light);
}

.modal-content.bounce {
    animation: modalBounce 0.6s var(--ease-bounce);
}

@keyframes modalBounce {
    0% {
        transform: scale(0.3);
    }
    50% {
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        transform: scale(1);
    }
}

/* ============ MODAL CLOSE ANIMATIONS ============ */
.modal-overlay.closing {
    opacity: 0;
    visibility: hidden;
}

.modal-overlay.closing .modal-content {
    transform: scale(0.95) translateY(20px);
    opacity: 0;
}

.modal-overlay.closing .modal-content.modal-fullscreen {
    transform: translateY(100%);
}

/* ============ Z-INDEX MANAGEMENT ============ */
.modal-overlay {
    z-index: 10000;
}
.modal-overlay.priority {
    z-index: 10001;
}
.modal-overlay.urgent {
    z-index: 10002;
}
.modal-overlay.critical {
    z-index: 10003;
}
