/*
 * App windows: frame, title bar, caption buttons, resize handles, snapping.
 */

.windows {
  position: absolute;
  inset: 0 0 var(--taskbar-h) 0;
  z-index: 10;
  overflow: clip;
  pointer-events: none;
}

.window {
  position: absolute;
  min-width: 7.6rem;
  min-height: 2rem;
  pointer-events: auto;
}

.window.is-minimized {
  visibility: hidden;
  pointer-events: none;
}

.window-frame {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--stroke-window);
  border-radius: var(--radius-lg);
  background: var(--bg-solid);
  box-shadow: var(--shadow-window-inactive);
  transition: box-shadow .15s linear;
}

/* The active window gets the "Mica" material: tinted, blurred backdrop. */
.window.is-active .window-frame {
  background: var(--mica);
  -webkit-backdrop-filter: blur(3.8rem) saturate(2);
  backdrop-filter: blur(3.8rem) saturate(2);
  box-shadow: var(--shadow-window);
}

.no-transparency .window.is-active .window-frame {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.window.is-maximized .window-frame {
  border-width: 0;
  border-radius: 0;
  box-shadow: none;
}

/* --------------------------------------------------------------- titlebar */

/* the icon at the start, the name in the middle of the window, the buttons at the end */
.window-titlebar {
  display: grid;
  flex: none;
  grid-template-columns: 1fr minmax(0, auto) 1fr;
  align-items: center;
  gap: 0.6rem;
  height: 2rem;
  padding-inline: 0.8rem; /* the same at both ends, so the name sits in the middle of the window */
  touch-action: none;
}

.window-icon {
  flex: none;
  justify-self: start;
  width: 1rem;
  height: 1rem;
  pointer-events: none;
}

.window-title {
  min-width: 0;
  text-align: center;
  overflow: hidden;
  color: var(--text-3);
  font-size: 0.8rem;
  line-height: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.window.is-active .window-title {
  color: var(--text);
}

/*
 * The window buttons are three coloured dots at the end of the title bar: minimize (yellow),
 * maximize (green), close (red). Their symbols show while the pointer is over the group.
 */
.window-controls {
  display: flex;
  flex: none;
  justify-self: end;
  align-items: center;
  gap: 0.6rem;
  height: 100%;
  padding-inline: 0.6rem 0;
}

.window-btn {
  display: grid;
  place-items: center;
  width: 0.8rem;
  height: 0.8rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--shade-5); /* a window that is not in front: grey dots */
  color: var(--caption-glyph);
  transition: background-color .1s linear, filter .1s linear;
}

.window.is-active .window-min,
.window-controls:hover .window-min {
  background: var(--caption-min);
}

.window.is-active .window-max,
.window-controls:hover .window-max {
  background: var(--caption-max);
}

.window.is-active .window-close,
.window-controls:hover .window-close {
  background: var(--caption-close);
}

.window-btn:active {
  filter: brightness(.8);
}

.window-btn .icon {
  --icon-size: 0.6rem;
  opacity: 0;
  transition: opacity .1s linear;
}

.window-controls:hover .window-btn .icon,
.window-btn:focus-visible .icon {
  opacity: 1;
}

/* ---------------------------------------------------------------- content */

.window-body {
  position: relative;
  flex: 1;
  min-height: 0;
}

.window-content {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  opacity: 0;
  transition: opacity .12s linear;
}

.window.is-ready .window-content {
  opacity: 1;
}

/* while a window is dragged or resized the pages must not swallow the pointer */
.windows.is-busy .window-content {
  pointer-events: none;
}

/* ---------------------------------------------------------------- resizing */

.window-resize {
  position: absolute;
  z-index: 2;
  touch-action: none;
}

.window-resize-n,
.window-resize-s {
  left: 0.8rem;
  right: 0.8rem;
  height: 0.6rem;
  cursor: ns-resize;
}

.window-resize-e,
.window-resize-w {
  top: 0.8rem;
  bottom: 0.8rem;
  width: 0.6rem;
  cursor: ew-resize;
}

.window-resize-n {
  top: -0.4rem;
  height: 0.4rem;
}

.window-resize-s {
  bottom: -0.4rem;
}

.window-resize-e {
  right: -0.4rem;
}

.window-resize-w {
  left: -0.4rem;
}

.window-resize-ne,
.window-resize-nw,
.window-resize-se,
.window-resize-sw {
  width: 1rem;
  height: 1rem;
}

.window-resize-ne {
  top: -0.4rem;
  right: -0.4rem;
  cursor: nesw-resize;
}

.window-resize-nw {
  top: -0.4rem;
  left: -0.4rem;
  cursor: nwse-resize;
}

.window-resize-se {
  right: -0.4rem;
  bottom: -0.4rem;
  cursor: nwse-resize;
}

.window-resize-sw {
  bottom: -0.4rem;
  left: -0.4rem;
  cursor: nesw-resize;
}

.window.is-maximized .window-resize {
  display: none;
}

/* ---------------------------------------------------------------- snapping */

.snap-preview {
  position: absolute;
  opacity: 0;
  scale: .97;
  pointer-events: none;
  transition: opacity .15s linear, scale .22s var(--ease-out), left .18s var(--ease-out), top .18s var(--ease-out), width .18s var(--ease-out), height .18s var(--ease-out);
}

.snap-preview::before {
  content: "";
  position: absolute;
  inset: 0.6rem;
  border: 1px solid var(--stroke-window);
  border-radius: var(--radius-lg);
  background: var(--acrylic);
  -webkit-backdrop-filter: blur(1.6rem);
  backdrop-filter: blur(1.6rem);
  box-shadow: var(--shadow-flyout);
}

.snap-preview.is-visible {
  opacity: 1;
  scale: 1;
}
