/* Window Base */
.window {
  position: absolute; display: flex; flex-direction: column;
  background: rgba(245, 245, 247, 0.92); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,0.5); border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.35), 0 0 0 1px rgba(0,0,0,0.05);
  overflow: hidden; min-width: 300px; min-height: 200px;
  transition: transform 0.15s, opacity 0.15s;
}
.window.dark { background: rgba(30, 30, 35, 0.92); color: #f5f5f7; }
.window.minimized { opacity: 0; transform: scale(0.9); pointer-events: none; }
/* macOS-style minimize/restore: window flies into/out of its Dock icon */
.window.minimizing { pointer-events: none; }
.window.restoring { pointer-events: none; }
.window.maximized { top: var(--menu-height) !important; left: 0 !important; width: 100vw !important; height: calc(100vh - var(--menu-height)) !important; border-radius: 0; }
.window.active { box-shadow: 0 25px 70px rgba(0,0,0,0.4), 0 0 0 1px rgba(0,0,0,0.08); }

.window-titlebar {
  height: 38px; display: flex; align-items: center; padding: 0 14px; gap: 10px;
  background: linear-gradient(to bottom, rgba(255,255,255,0.6), rgba(255,255,255,0.3));
  border-bottom: 1px solid rgba(0,0,0,0.05); cursor: grab;
}
.window.dark .window-titlebar { background: linear-gradient(to bottom, rgba(60,60,65,0.6), rgba(40,40,45,0.3)); border-bottom-color: rgba(255,255,255,0.05); }
.window-titlebar:active { cursor: grabbing; }
.window-controls { display: flex; gap: 10px; }
.control { width: 17px; height: 17px; border-radius: 50%; cursor: pointer; position: relative; display: flex; align-items: center; justify-content: center; }
.control.close { background: var(--control-red); }
.control.minimize { background: var(--control-yellow); }
.control.maximize { background: var(--control-green); }
.control::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  box-shadow: inset 0 0 0 0.5px rgba(0,0,0,0.15);
}
.control::before {
  content: ''; position: relative; z-index: 1; font-size: 14px; font-weight: 700; line-height: 1;
  color: rgba(0, 0, 0, 0.6); opacity: 0; transition: opacity 0.12s ease; user-select: none;
}
.control.close::before { content: '×'; }
.control.minimize::before { content: '−'; font-size: 16px; }
.control.maximize::before { content: '+'; }
.control:hover::before { opacity: 1; }
.control:hover { filter: brightness(0.92); }
.window-title { flex: 1; text-align: center; font-size: 13px; font-weight: 600; color: var(--text-primary); }
.window.dark .window-title { color: #f5f5f7; }
.window-spacer { width: 71px; }

.window-content {
  flex: 1; overflow: auto; padding: 16px; position: relative;
}
.resize-handle {
  position: absolute; width: 16px; height: 16px; right: 0; bottom: 0; cursor: se-resize;
  background: linear-gradient(135deg, transparent 50%, rgba(0,0,0,0.15) 50%);
  border-bottom-right-radius: var(--radius-lg);
}

/* Scrollbar */
.window-content::-webkit-scrollbar { width: 8px; }
.window-content::-webkit-scrollbar-track { background: transparent; }
.window-content::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 4px; }
.window.dark .window-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); }

/* Animations */
@keyframes windowOpen {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}
.window.opening { animation: windowOpen 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94); }

/* Classic fold-up close: window folds flat like paper, hinged at the titlebar */
@keyframes windowClose {
  0%   { opacity: 1; transform: perspective(1200px) rotateX(0deg); }
  100% { opacity: 0; transform: perspective(1200px) rotateX(-88deg) scaleY(0.9); }
}
.window.closing {
  transform-origin: top center;
  backface-visibility: hidden;
  animation: windowClose 0.35s cubic-bezier(0.55, 0, 0.55, 0.2) forwards;
}
