/*
  window.css, app window chrome (frosted glass) + resize handles + states
  ---------------------------------------------------------------------------
  A window is: a frosted titlebar (icon, title, min/max/close), a full-bleed
  body (hosts the iframe or native content), and eight invisible resize grips.
  The frame is the "Bodach dark + orange" glass; the active window gets an
  orange focus ring so it's obvious which one has focus.
*/

.os-window {
  position: absolute;
  min-width: 200px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  border-radius: var(--os-radius);
  overflow: hidden; /* clip the body + iframe to the rounded corners */
  background: var(--os-glass);
  -webkit-backdrop-filter: blur(var(--os-blur));
  backdrop-filter: blur(var(--os-blur));
  border: 1px solid var(--os-border);
  box-shadow: var(--os-shadow-window);
  /* Snappy open pop. */
  animation: os-window-open 160ms var(--os-ease-out);
  /* Only animate geometry when snapping/maximising, NOT during live drag
     (the is-dragging/is-resizing classes remove the transition). */
  transition: box-shadow var(--os-dur-fast) var(--os-ease-out);
}

.os-window.is-active {
  box-shadow: var(--os-shadow-focus);
  border-color: var(--os-border-strong);
}

/* Maximise/snap transitions animate; live drag/resize do not (perf + feel). */
.os-window.is-maximised { border-radius: 0; }
.os-window:not(.is-dragging):not(.is-resizing).is-maximised,
.os-window.is-snapping {
  transition: left var(--os-dur) var(--os-ease-out), top var(--os-dur) var(--os-ease-out),
    width var(--os-dur) var(--os-ease-out), height var(--os-dur) var(--os-ease-out);
}

.os-window.is-minimised {
  /* Collapse toward the taskbar and drop out of interaction. */
  transform: scale(0.85) translateY(40px);
  opacity: 0;
  pointer-events: none;
  transition: transform 180ms var(--os-ease-out), opacity 180ms var(--os-ease-out);
}

.os-window.is-closing {
  transform: scale(0.9);
  opacity: 0;
  transition: transform 150ms var(--os-ease-out), opacity 150ms var(--os-ease-out);
}

/* --- Titlebar ------------------------------------------------------------- */
.os-window__titlebar {
  flex: 0 0 auto;
  height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 0 12px;
  background: var(--os-glass-titlebar);
  border-bottom: 1px solid var(--os-border);
  cursor: default;
  user-select: none;
  touch-action: none; /* let the pointer drag handler own the gesture */
}

.os-window__icon {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  flex: 0 0 auto;
}
.os-window__icon:not([src]) { display: none; }

.os-window__title {
  flex: 1 1 auto;
  font-size: 13px;
  font-weight: 600;
  color: var(--os-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.os-window__controls {
  flex: 0 0 auto;
  display: flex;
  gap: 2px;
}

.os-window__btn {
  width: 30px;
  height: 26px;
  border-radius: var(--os-radius-sm);
  display: grid;
  place-items: center;
  color: var(--os-text-muted);
  transition: background var(--os-dur-fast) var(--os-ease-out),
    color var(--os-dur-fast) var(--os-ease-out);
}
.os-window__btn:hover { background: var(--os-fill-hover); color: var(--os-text); }
.os-window__btn.is-close:hover { background: var(--os-danger); color: #fff; }

/* --- Body ----------------------------------------------------------------- */
.os-window__body {
  flex: 1 1 auto;
  position: relative;
  min-height: 0; /* allow the body to shrink so the iframe can fill it */
  background: var(--os-navy-600);
}
:root[data-theme="light"] .os-window__body { background: #fff; }

/* Native app bodies scroll internally and get comfortable default padding via
   their own module; here we just make them fill + scroll. */
.os-native-body {
  overflow: auto;
  color: var(--os-text);
}

/* iframe fills the body edge-to-edge. */
.os-app-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #fff;
}
:root[data-theme="dark"] .os-app-frame { background: #0d1526; }

/* --- Resize handles (invisible grips) ------------------------------------ */
.os-window__resize { position: absolute; z-index: 5; }
.os-window.is-fixed .os-window__resize { display: none; }

/* Edges */
.os-window__resize--n { top: -3px; left: 8px; right: 8px; height: 8px; cursor: ns-resize; }
.os-window__resize--s { bottom: -3px; left: 8px; right: 8px; height: 8px; cursor: ns-resize; }
.os-window__resize--e { right: -3px; top: 8px; bottom: 8px; width: 8px; cursor: ew-resize; }
.os-window__resize--w { left: -3px; top: 8px; bottom: 8px; width: 8px; cursor: ew-resize; }
/* Corners (bigger hit area) */
.os-window__resize--ne { top: -4px; right: -4px; width: 14px; height: 14px; cursor: nesw-resize; }
.os-window__resize--nw { top: -4px; left: -4px; width: 14px; height: 14px; cursor: nwse-resize; }
.os-window__resize--se { bottom: -4px; right: -4px; width: 14px; height: 14px; cursor: nwse-resize; }
.os-window__resize--sw { bottom: -4px; left: -4px; width: 14px; height: 14px; cursor: nesw-resize; }

@keyframes os-window-open {
  from { opacity: 0; transform: scale(0.97) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* --- Mobile: windows are near-fullscreen, no chrome grips ----------------- */
@media (max-width: 640px) {
  .os-window {
    border-radius: 0;
    border: 0;
    animation: os-window-open-mobile 180ms var(--os-ease-out);
  }
  .os-window__resize { display: none; }
  .os-window__titlebar { height: 44px; } /* thumb-friendly */
  .os-window__btn { width: 40px; height: 34px; }
}

@keyframes os-window-open-mobile {
  from { opacity: 0; transform: translateY(3%); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .os-window { animation: none; }
}
