/**
 * WebOS — Estilos del Gestor de Ventanas
 * 
 * Ventanas flotantes, titlebar, controles, redimensionado, animaciones.
 */

/* ===== Window Base ===== */
.window {
    position: absolute;
    min-width: 300px;
    min-height: 200px;
    background: var(--window-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--window-radius);
    box-shadow: var(--window-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: box-shadow var(--transition-normal);
    animation: window-open 0.25s ease;
}

.window.focused {
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5), 0 4px 12px rgba(0, 0, 0, 0.3);
    border-color: var(--color-border-hover);
}

.window.minimizing {
    animation: window-minimize 0.25s ease forwards;
}

.window.closing {
    animation: window-close 0.2s ease forwards;
}

.window.maximized {
    border-radius: 0 !important;
    transition: left 0.2s ease, top 0.2s ease, width 0.2s ease, height 0.2s ease;
}

/* ===== Animations ===== */
@keyframes window-open {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes window-minimize {
    to {
        opacity: 0;
        transform: scale(0.5) translateY(100px);
    }
}

@keyframes window-close {
    to {
        opacity: 0;
        transform: scale(0.92);
    }
}

/* ===== Titlebar ===== */
.window-titlebar {
    height: var(--titlebar-height);
    min-height: var(--titlebar-height);
    background: var(--titlebar-bg);
    display: flex;
    align-items: center;
    padding: 0 12px;
    cursor: default;
    border-bottom: 1px solid var(--color-border);
    -webkit-app-region: drag;
}

.window-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: 12px;
}

.window-controls button {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    transition: opacity var(--transition-fast), transform var(--transition-fast);
    padding: 0;
}

.window-controls button:hover {
    transform: scale(1.15);
}

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

.btn-close {
    background: #ff5f57;
}

.btn-minimize {
    background: #febc2e;
}

.btn-maximize {
    background: #28c840;
}

.window-title {
    flex: 1;
    text-align: center;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 60px;
}

/* ===== Window Body ===== */
.window-body {
    flex: 1;
    overflow: auto;
    position: relative;
}

/* ===== Resize Handles ===== */
.resize-handle {
    position: absolute;
    z-index: 10;
}

.resize-handle-n {
    top: -4px;
    left: 8px;
    right: 8px;
    height: 8px;
    cursor: n-resize;
}

.resize-handle-s {
    bottom: -4px;
    left: 8px;
    right: 8px;
    height: 8px;
    cursor: s-resize;
}

.resize-handle-e {
    right: -4px;
    top: 8px;
    bottom: 8px;
    width: 8px;
    cursor: e-resize;
}

.resize-handle-w {
    left: -4px;
    top: 8px;
    bottom: 8px;
    width: 8px;
    cursor: w-resize;
}

.resize-handle-ne {
    top: -4px;
    right: -4px;
    width: 14px;
    height: 14px;
    cursor: ne-resize;
}

.resize-handle-nw {
    top: -4px;
    left: -4px;
    width: 14px;
    height: 14px;
    cursor: nw-resize;
}

.resize-handle-se {
    bottom: -4px;
    right: -4px;
    width: 14px;
    height: 14px;
    cursor: se-resize;
}

.resize-handle-sw {
    bottom: -4px;
    left: -4px;
    width: 14px;
    height: 14px;
    cursor: sw-resize;
}

/* ===== Window in focus ===== */
.window.focused .window-titlebar {
    background: var(--titlebar-bg);
}

.window:not(.focused) .window-controls button {
    opacity: 0.4;
}

.window:not(.focused) .window-title {
    opacity: 0.6;
}

/* ===== Scrollbar Styling ===== */
.window-body::-webkit-scrollbar {
    width: 8px;
}

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

.window-body::-webkit-scrollbar-thumb {
    background: var(--color-glass-hover);
    border-radius: 4px;
}

.window-body::-webkit-scrollbar-thumb:hover {
    background: var(--color-glass-active);
}

/* ===== Selection ===== */
.window-body ::selection {
    background: var(--color-primary);
    color: #fff;
}

/* ===== Common Window Components ===== */
.window-body button {
    font-family: var(--font-family);
    cursor: pointer;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: var(--font-size-sm);
    transition: background var(--transition-fast), transform var(--transition-fast);
}

.window-body button:active {
    transform: scale(0.96);
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
}

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

.btn-danger {
    background: var(--color-danger);
    color: #fff;
}

.btn-danger:hover {
    background: #ff6b7a;
}

.btn-secondary {
    background: var(--color-glass);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-glass-hover);
}

/* ===== Loading State ===== */
.window-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 150px;
}

.window-loading .spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
