/* 
 * PWA Window Controls Overlay Styles
 * Makes the PWA look more like a native desktop app
 */

/* Default state - hide title bar completely */
.app-title-bar {
    display: none !important;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: var(--background-secondary);
    border-bottom: 1px solid var(--border-color);
    user-select: none;
    -webkit-app-region: drag;
}

/* Hide title bar in browser mode explicitly */
body.pwa-browser .app-title-bar {
    display: none !important;
}

/* Ensure no padding in browser mode */
body.pwa-browser .pwa-container {
    padding-top: 0 !important;
}

/* Detect when Window Controls Overlay is active */
@media (display-mode: standalone) {
    /* Only show in standalone mode */
    body.pwa-standalone .app-title-bar {
        display: flex !important;
        align-items: center;
        justify-content: flex-start;
        height: 32px;
        width: 100vw;
        padding: 0;
    }
    
    body.pwa-standalone .app-title-bar .app-title {
        font-size: 14px;
        font-weight: 500;
        color: var(--text-primary);
        margin: 0;
        flex: 1;
        text-align: center;
        padding: 0 16px;
        min-width: 0; /* Allow text to shrink */
    }
    
    body.pwa-standalone .app-title-bar .app-controls {
        display: none; /* Hide by default, show only when no system controls */
        gap: 8px;
        -webkit-app-region: no-drag;
        position: absolute;
        right: 16px;
        top: 50%;
        transform: translateY(-50%);
    }
    
    body.pwa-standalone .app-title-bar .control-btn {
        width: 24px;
        height: 24px;
        border: none;
        background: transparent;
        border-radius: 4px;
        color: var(--text-secondary);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        transition: all 0.2s ease;
    }
    
    body.pwa-standalone .app-title-bar .control-btn:hover {
        background: var(--background-tertiary);
        color: var(--text-primary);
    }
    
    /* Adjust content to account for custom title bar - only in standalone */
    body.pwa-standalone .pwa-container {
        padding-top: 32px;
    }
    
    /* Hide default browser UI elements in PWA mode */
    body.pwa-standalone .pwa-status-bar {
        margin-top: 0;
    }
}

/* Force show title bar when body has pwa-standalone class (JavaScript detection) */
body.pwa-standalone .app-title-bar {
    display: flex !important;
}

/* Window Controls Overlay Support - Modern browsers */
@supports (top: env(titlebar-area-height)) {
    .app-title-bar {
        position: fixed !important;
        top: env(titlebar-area-y) !important;
        left: env(titlebar-area-x) !important;
        width: env(titlebar-area-width) !important;
        height: env(titlebar-area-height) !important;
        background: var(--background-secondary) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0 16px !important;
        border-bottom: 1px solid var(--border-color);
        z-index: 9999;
        -webkit-app-region: drag;
    }
    
    .app-title-bar .app-title {
        text-align: center !important;
        flex: 1 !important;
        font-size: 14px !important;
        font-weight: 500 !important;
        color: var(--text-primary) !important;
        margin: 0 !important;
        padding: 0 16px !important;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .app-title-bar .app-controls {
        display: none !important;
    }
    
    .pwa-container {
        padding-top: env(titlebar-area-height) !important;
    }
}

/* Fallback for when window controls overlay geometry is not available */
@media (display-mode: standalone) and (not (top: env(titlebar-area-height))) {
    .app-title-bar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100vw;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--background-secondary);
        border-bottom: 1px solid var(--border-color);
        z-index: 9999;
    }
    
    .app-title-bar .app-title {
        flex: 1;
        text-align: center;
        margin: 0 120px; /* Space for controls on both sides */
    }
    
    .app-title-bar .app-controls {
        position: absolute;
        right: 8px;
        display: flex;
        gap: 4px;
    }
    
    .pwa-container {
        padding-top: 40px;
    }
}

/* Native-like window appearance */
.pwa-window {
    border-radius: 12px 12px 0 0;
    overflow: hidden;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
}

/* Frameless window effect */
.frameless-window {
    border: none;
    border-radius: 12px;
    overflow: hidden;
}

/* Custom scrollbars for app-like feel */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background-secondary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
    border: 2px solid var(--background-secondary);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Custom selection colors */
::selection {
    background: var(--primary-color);
    color: #000;
}

::-moz-selection {
    background: var(--primary-color);
    color: #000;
}

/* App-like focus styles */
button:focus,
input:focus,
textarea:focus,
select:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Native-like form controls */
input, textarea, select {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 12px;
    background: var(--background-secondary);
    color: var(--text-primary);
    font-family: inherit;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(247, 147, 26, 0.1);
}

/* App-like buttons */
.btn-native {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 16px;
    background: var(--background-secondary);
    color: var(--text-primary);
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-native:hover {
    background: var(--background-tertiary);
    border-color: var(--primary-color);
}

.btn-native:active {
    transform: translateY(1px);
}

.btn-native.primary {
    background: var(--primary-color);
    color: #000;
    border-color: var(--primary-color);
}

.btn-native.primary:hover {
    background: #e6840f;
    border-color: #e6840f;
}

/* Context menu styling */
.context-menu {
    background: var(--background-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    padding: 4px 0;
    min-width: 180px;
}

.context-menu-item {
    padding: 8px 16px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 14px;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.context-menu-item:hover {
    background: var(--background-tertiary);
}

.context-menu-separator {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

/* Notification styling for app-like feel */
.app-notification {
    position: fixed;
    top: 48px;
    right: 16px;
    background: var(--background-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    max-width: 320px;
    animation: slideInFromRight 0.3s ease;
}

@keyframes slideInFromRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Touch-friendly interactive elements */
@media (hover: none) and (pointer: coarse) {
    .control-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    .btn-native {
        min-height: 44px;
        padding: 12px 20px;
    }
    
    .context-menu-item {
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}

/* Prevent text selection on UI elements */
.app-title-bar,
.control-btn,
.btn-native {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* High DPI display optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .app-title-bar {
        border-bottom-width: 0.5px;
    }
    
    .context-menu {
        border-width: 0.5px;
    }
}