/* OS 2026 Window System - Custom Design (Non-Apple) */

/* The Dialog/Modal Container */
.mm-os-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    background: transparent;
    pointer-events: none;
    padding: 20px;
    border: none;
    max-width: 100vw;
    max-height: 100dvh;
    width: 100vw;
    height: 100dvh;
}

/* Show modal when open - use flex for centering */
.mm-os-modal[open] {
    display: flex;
    pointer-events: auto;
}

/* Backdrop - covers full screen with subtle scale for depth */
.mm-os-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    /* Blur removed for performance - prevents scroll jank */
    opacity: 0;
    transform: scale(1.02);
    transition:
        opacity 0.4s ease-out,
        transform 0.4s ease-out;
    z-index: 1;
    cursor: pointer;
}

.mm-os-modal[open] .mm-os-backdrop {
    opacity: 1;
    transform: scale(1);
}

/* The Window Itself */
.mm-os-window {
    position: relative;
    margin: auto;
    width: 90vw;
    height: 85vh;
    max-width: 1400px;
    min-width: 400px;
    min-height: 300px;
    background: rgba(18, 18, 18, 0.98);
    /* Blur removed for performance - prevents scroll jank */
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow:
        0 25px 60px rgba(0, 0, 0, 0.5),
        0 0 100px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: scale(0.95) translateY(20px);
    transition:
        opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1),
        transform 0.4s cubic-bezier(0.16, 1, 0.3, 1),
        width 0.3s ease,
        height 0.3s ease;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 10;
    /* GPU Performance Hints */
    will-change: transform, opacity;
    transform: translateZ(0) scale(0.95) translateY(20px);
}

/* Bounce-in keyframe for premium feel */
@keyframes mm-window-bounce-in {
    0% {
        opacity: 0;
        transform: translateZ(0) scale(0.92) translateY(25px);
    }

    60% {
        opacity: 1;
        transform: translateZ(0) scale(1.02) translateY(-5px);
    }

    100% {
        opacity: 1;
        transform: translateZ(0) scale(1) translateY(0);
    }
}

.mm-os-modal[open] .mm-os-window {
    animation: mm-window-bounce-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Maximized State */
.mm-os-window.mm-maximized {
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    border-radius: 0 !important;
}

/* Minimized State (for tab functionality) */
.mm-os-window.mm-minimized {
    opacity: 0;
    transform: scale(0.8) translateY(50px);
    pointer-events: none;
}

.mm-os-modal.mm-window-minimized {
    pointer-events: none;
}

.mm-os-modal.mm-window-minimized .mm-os-backdrop {
    opacity: 0;
}

/* Window Header / Titlebar */
.mm-os-header {
    height: 48px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    user-select: none;
    cursor: grab;
    background: rgba(0, 0, 0, 0.2);
}

.mm-os-header:active {
    cursor: grabbing;
}

/* ===== Unified Modal Close Button (THE ARCHITECT Style) ===== */
/* Use this instead of Traffic Lights for dialog modals */
.mm-modal-close {
    width: 44px;
    height: 44px;
    margin-left: auto;
    /* Push to right */
    border-radius: 12px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--color-text-meta, rgba(255, 255, 255, 0.4));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
    flex-shrink: 0;
}

.mm-modal-close:hover {
    background: rgba(var(--color-signal-rgb), 0.1);
    border-color: rgba(var(--color-signal-rgb), 0.3);
    color: var(--color-signal);
}

.mm-modal-close:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(var(--color-signal-rgb), 0.5);
    background: rgba(var(--color-signal-rgb), 0.1);
    color: var(--color-signal);
}

.mm-modal-close:active {
    transform: scale(0.95);
    background: rgba(var(--color-signal-rgb), 0.2);
}

/* Light mode */
.light .mm-modal-close {
    color: var(--color-text-meta, rgba(0, 0, 0, 0.4));
}

.light .mm-modal-close:hover {
    background: rgba(var(--color-signal-rgb), 0.08);
}

/* ===== Header with Icon (New Unified Style) ===== */
.mm-os-header-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-signal);
    font-size: 1rem;
    flex-shrink: 0;
}

/* Title - Fluid scaling, never truncated */
.mm-os-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: clamp(10px, 2.5vw, 14px);
    font-weight: 600;
    color: rgba(255, 255, 255, 0.5);
    letter-spacing: 0.02em;
    pointer-events: none;
    font-family: var(--font-body), sans-serif;
    /* Prevent text cutoff */
    max-width: 60%;
    text-align: center;
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    -webkit-hyphens: auto;
    line-height: 1.3;
}

/* Content Area - Smooth Scrolling + Fluid Text */
.mm-os-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    background: rgba(0, 0, 0, 0.15);
    scrollbar-gutter: stable;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    /* Fluid text - never truncate */
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    -webkit-hyphens: auto;
}

/* Content headings - fluid scaling */
.mm-os-content h1,
.mm-os-content h2,
.mm-os-content h3 {
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    -webkit-hyphens: auto;
}

.mm-os-content h1 {
    font-size: clamp(1.5rem, 5vw, 2.5rem);
}

.mm-os-content h2 {
    font-size: clamp(1.25rem, 4vw, 2rem);
}

.mm-os-content h3 {
    font-size: clamp(1rem, 3vw, 1.5rem);
}

/* ===== Always Visible Scrollbars (Desktop with Mouse) ===== */
@media (pointer: fine) {
    .mm-os-content {
        scrollbar-width: auto;
    }

    .mm-os-content::-webkit-scrollbar {
        width: 12px;
        display: block;
    }

    .mm-os-content::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.03);
        border-radius: 6px;
        margin: 4px;
    }

    .mm-os-content::-webkit-scrollbar-thumb {
        background: rgba(var(--color-signal-rgb), 0.25);
        border-radius: 6px;
        border: 3px solid transparent;
        background-clip: padding-box;
        min-height: 40px;
    }

    .mm-os-content::-webkit-scrollbar-thumb:hover {
        background: rgba(var(--color-signal-rgb), 0.4);
        border: 3px solid transparent;
        background-clip: padding-box;
    }

    .mm-os-content::-webkit-scrollbar-thumb:active {
        background: rgba(var(--color-signal-rgb), 0.55);
        border: 3px solid transparent;
        background-clip: padding-box;
    }
}

/* ===== Resize Functionality (Desktop Only) ===== */
@media (min-width: 769px) {
    .mm-os-window:not(.mm-maximized) {
        resize: both;
        overflow: auto;
    }

    /* Custom resize corner indicator */
    .mm-os-window:not(.mm-maximized)::after {
        content: '';
        position: absolute;
        bottom: 4px;
        right: 4px;
        width: 12px;
        height: 12px;
        background: linear-gradient(135deg,
                transparent 50%,
                rgba(var(--color-signal-rgb), 0.3) 50%);
        border-radius: 0 0 4px 0;
        pointer-events: none;
        opacity: 0.5;
        transition: opacity 0.2s ease;
    }

    .mm-os-window:not(.mm-maximized):hover::after {
        opacity: 1;
    }
}

/* ===== Mobile Adjustments ===== */
@media (max-width: 768px) {
    .mm-os-modal {
        padding: 0;
    }

    /* Mobile backdrop: No blur for smooth scrolling performance */

    .mm-os-window {
        width: 100vw;
        height: 100dvh;
        /* True fullscreen */
        max-height: 100dvh;
        max-width: none;
        min-width: 0;
        min-height: 0;
        border-radius: 0;
        /* No radius for fullscreen */
        border: none;
        resize: none;
        display: flex;
        flex-direction: column;
        /* Blur removed for performance */
        /* Start from bottom */
        transform: translateZ(0) translateY(100%);
    }

    /* Mobile slide-up with overshoot bounce - MUST include opacity */
    @keyframes mm-window-slide-bounce {
        0% {
            opacity: 0;
            transform: translateZ(0) translateY(100%);
        }

        50% {
            opacity: 1;
        }

        70% {
            opacity: 1;
            transform: translateZ(0) translateY(-2%);
        }

        100% {
            opacity: 1;
            transform: translateZ(0) translateY(0);
        }
    }

    .mm-os-modal[open] .mm-os-window {
        opacity: 1;
        animation: mm-window-slide-bounce 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    }

    /* Ensure content is reachable */
    .mm-os-modal {
        align-items: flex-end;
        /* Align to bottom */
        padding: 0;
    }

    .mm-os-header {
        height: auto;
        min-height: 56px;
        padding: env(safe-area-inset-top, 0px) 12px 0;
        display: flex;
        align-items: center;
    }


    .mm-os-title {
        font-size: 11px;
    }

    /* Touch-friendly scrollbar */
    .mm-os-content::-webkit-scrollbar {
        width: 4px;
    }
}

/* ===== Close Animation ===== */
/* Desktop Default */
.mm-os-modal:not([open]) .mm-os-window {
    opacity: 0;
    transform: scale(0.95) translateY(20px);
    transition:
        opacity 0.25s cubic-bezier(0.4, 0, 1, 1),
        transform 0.25s cubic-bezier(0.4, 0, 1, 1);
}

/* Mobile Slide Down on Close */
@media (max-width: 768px) {
    .mm-os-modal:not([open]) .mm-os-window {
        opacity: 1;
        /* Keep opacity for slide out */
        transform: translateY(100%);
        transition: transform 0.25s cubic-bezier(0.4, 0, 1, 1);
    }
}

.mm-os-modal:not([open]) .mm-os-backdrop {
    opacity: 0;
    transition: opacity 0.3s ease-out;
}

/* ===== Window Tab (Minimized in OS Bar) ===== */
.mm-window-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(var(--color-signal-rgb), 0.1);
    border: 1px solid rgba(var(--color-signal-rgb), 0.2);
    border-radius: 8px;
    color: var(--color-text-dim);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    max-width: 150px;
    overflow: hidden;
}

.mm-window-tab:hover {
    background: rgba(var(--color-signal-rgb), 0.2);
    border-color: rgba(var(--color-signal-rgb), 0.4);
    color: var(--color-text);
}

.mm-window-tab .mm-tab-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mm-window-tab .mm-tab-close {
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    opacity: 0.5;
    transition: all 0.15s ease;
}

.mm-window-tab:hover .mm-tab-close {
    opacity: 1;
}

.mm-window-tab .mm-tab-close:hover {
    background: rgba(239, 68, 68, 0.3);
    color: rgb(239, 68, 68);
}

/* ===== Light Theme Support ===== */
.light .mm-os-window {
    background: rgba(255, 255, 255, 0.92);
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow:
        0 25px 60px rgba(0, 0, 0, 0.15),
        0 0 100px rgba(0, 0, 0, 0.05);
}

.light .mm-os-backdrop {
    background: rgba(255, 255, 255, 0.5);
}

.light .mm-os-header {
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    background: rgba(255, 255, 255, 0.3);
}

.light .mm-os-title {
    color: rgba(0, 0, 0, 0.5);
}

.light .mm-os-content {
    background: rgba(255, 255, 255, 0.3);
}

.light .mm-os-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.03);
}

.light .mm-os-content::-webkit-scrollbar-thumb {
    background: rgba(var(--color-signal-rgb), 0.3);
}

.light .mm-os-content::-webkit-scrollbar-thumb:hover {
    background: rgba(var(--color-signal-rgb), 0.45);
}

.light .mm-window-tab {
    background: rgba(var(--color-signal-rgb), 0.08);
    border-color: rgba(var(--color-signal-rgb), 0.15);
}

.light .mm-window-tab:hover {
    background: rgba(var(--color-signal-rgb), 0.15);
}

/* ===== Reduced Motion Support ===== */
@media (prefers-reduced-motion: reduce) {

    .mm-os-modal .mm-os-window,
    .mm-os-modal .mm-os-backdrop,
    .mm-os-modal:not([open]) .mm-os-window,
    .mm-os-modal:not([open]) .mm-os-backdrop,
    .mm-modal-close,
    .mm-window-tab {
        transition-duration: 0.01ms !important;
    }
}

.mm-reduce-motion .mm-os-modal .mm-os-window,
.mm-reduce-motion .mm-os-modal .mm-os-backdrop,
.mm-reduce-motion .mm-modal-close {
    transition-duration: 0.01ms !important;
}