.windows-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

.snap-preview {
  position: absolute;
  top: 8px;
  bottom: 84px;
  border-radius: 14px;
  background: rgba(10, 132, 255, 0.22);
  border: 2px solid rgba(10, 132, 255, 0.72);
  backdrop-filter: blur(8px);
  z-index: 15;
  pointer-events: none;
  transition: all 0.14s var(--ease-spring);
}

.app-window {
  position: absolute;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-window);
  background: var(--surface-app);
  color: var(--text-primary);
  backdrop-filter: blur(32px) saturate(180%);
  -webkit-backdrop-filter: blur(32px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-window-inactive);
  overflow: hidden;
  transition: box-shadow 0.2s ease, opacity 0.2s ease, transform 0.24s var(--ease-spring);
  will-change: transform, left, top, width, height;
}

html[data-theme="light"] .app-window {
  border-color: rgba(15, 23, 42, 0.14);
}

html[data-glass="opaque"] .app-window {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.app-window.focused {
  box-shadow: var(--shadow-window), inset 0 1px 0 var(--glass-highlight);
}

.app-window.opening {
  animation: windowOpen 0.24s var(--ease-spring);
}

.app-window.minimized {
  opacity: 0;
  transform: scale(0.75) translateY(140px);
  pointer-events: none;
}

.app-window.snapping {
  transition: left 0.22s var(--ease-spring), top 0.22s var(--ease-spring), width 0.22s var(--ease-spring), height 0.22s var(--ease-spring);
}

.app-window.fullscreen-mode {
  border-radius: 0 !important;
  border: none !important;
}

/* Titlebar */
.window-titlebar {
  height: 38px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 13px;
  border-bottom: 1px solid var(--divider);
  background: var(--glass-bg-subtle);
  color: var(--text-primary);
  cursor: grab;
  touch-action: none;
  position: relative;
}

html[data-theme="light"] .window-titlebar {
  background: rgba(236, 241, 249, 0.85);
}

.window-titlebar:active {
  cursor: grabbing;
}

.window-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 2;
}

.traffic-btn {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 0.5px solid rgba(0, 0, 0, 0.22);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: transform 0.12s ease, filter 0.12s ease, background 0.15s ease;
}

.traffic-btn::after {
  content: "";
  position: absolute;
  inset: -7px;
}

.traffic-btn:hover {
  transform: scale(1.1);
}

.traffic-close {
  background: #ff5f57;
}
.traffic-min {
  background: #febc2e;
}
.traffic-max {
  background: #28c840;
}

.app-window:not(.focused) .traffic-btn {
  background: rgba(148, 163, 184, 0.36);
  border-color: rgba(148, 163, 184, 0.3);
}

.app-window:not(.focused) .window-controls:hover .traffic-close {
  background: #ff5f57;
}
.app-window:not(.focused) .window-controls:hover .traffic-min {
  background: #febc2e;
}
.app-window:not(.focused) .window-controls:hover .traffic-max {
  background: #28c840;
}

.traffic-glyph {
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  color: rgba(0, 0, 0, 0.68);
  opacity: 0;
  transition: opacity 0.12s ease;
}

.window-controls:hover .traffic-glyph {
  opacity: 1;
}

.window-title-wrap {
  position: absolute;
  left: 96px;
  right: 112px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  pointer-events: none;
  overflow: hidden;
}

.window-title-icon {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.window-title-icon svg {
  width: 16px;
  height: 16px;
}

.window-title {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.app-window:not(.focused) .window-title-wrap {
  opacity: 0.72;
}

.window-actions-right {
  display: flex;
  align-items: center;
  gap: 4px;
  z-index: 2;
}

.window-snap-btn {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

.window-snap-btn:hover {
  background: var(--glass-bg-subtle);
  color: var(--text-primary);
}

.window-content {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Resize Handles (8-way + touch friendly corners) */
.resize-handle {
  position: absolute;
  z-index: 5;
  touch-action: none;
}

.resize-n { top: -3px; left: 10px; right: 10px; height: 7px; cursor: ns-resize; }
.resize-s { bottom: -3px; left: 10px; right: 10px; height: 7px; cursor: ns-resize; }
.resize-e { right: -3px; top: 10px; bottom: 10px; width: 7px; cursor: ew-resize; }
.resize-w { left: -3px; top: 10px; bottom: 10px; width: 7px; cursor: ew-resize; }
.resize-ne { top: -4px; right: -4px; width: 16px; height: 16px; cursor: nesw-resize; }
.resize-nw { top: -4px; left: -4px; width: 16px; height: 16px; cursor: nwse-resize; }
.resize-se { bottom: -4px; right: -4px; width: 20px; height: 20px; cursor: nwse-resize; }
.resize-sw { bottom: -4px; left: -4px; width: 16px; height: 16px; cursor: nesw-resize; }

.resize-se::after {
  content: "";
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  border-bottom-right-radius: 2px;
  opacity: 0.5;
}

@keyframes windowOpen {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@media (max-width: 720px) {
  .window-titlebar {
    height: 44px;
  }
  .traffic-btn {
    width: 15px;
    height: 15px;
  }
  .window-snap-btn {
    display: none;
  }
  .resize-se {
    width: 26px;
    height: 26px;
  }
}
