/* A normal window leaves the workspace visible; maximize is a separate mode. */
html:root {
  --window-size-small: 520px;
  --window-size-form: 820px;
  --window-size-workspace: 1080px;
  --window-width-limit: calc(100vw - clamp(48px, 12vw, 240px));
  --window-height-limit: calc(100dvh - 160px);
  --window-normal-top: calc(50% + 24px);
}
html:root :is(#operations-dialog,#invoice-route-dialog,#invoice-dialog,#hr-create-dialog,#structure-view,#messenger-view,#chat-dialog,#project-dialog,#employee-dialog,#department-dialog,#profile-dialog,#task-drawer,#calendar-event-dialog,#calendar-room-dialog).managed-window:not(.window-maximized) {
  position: fixed; inset: var(--window-normal-top) auto auto 50vw;
  width: min(var(--window-normal-width,var(--window-size-small)),var(--window-width-limit));
  max-width: var(--window-width-limit);
  height: auto; min-height: 0; min-width: 0;
  max-height: min(var(--window-normal-height,720px),var(--window-height-limit));
  margin: 0; transform: translate(-50%,-50%); border-radius: var(--radius-modal,16px);
}
html:root :is(#calendar-event-dialog,#messenger-view,#structure-view) { --window-normal-width: var(--window-size-workspace); }
html:root #task-drawer { --window-normal-width: 1040px; --window-normal-height: 700px; }
html:root #profile-dialog { --window-normal-width: 860px; }
html:root :is(#invoice-dialog,#hr-create-dialog) { --window-normal-width: 1020px; }
html:root :is(#project-dialog,#operations-dialog) { --window-normal-width: var(--window-size-form); }
html:root :is(#employee-dialog,#invoice-route-dialog) { --window-normal-width: 780px; }
html:root :is(#task-drawer,#calendar-event-dialog,#messenger-view,#structure-view).managed-window:not(.window-maximized):not(.calendar-preview) {
  height: min(var(--window-normal-height,700px),var(--window-height-limit));
}
html:root #calendar-event-dialog.calendar-preview { --window-normal-width: 680px; --window-normal-height: 660px; }
/* Growing a form must not recenter its title and controls on every field change. */
html:root :is(#employee-dialog,#department-dialog,#profile-dialog,#project-dialog,#hr-create-dialog,#chat-dialog,#invoice-route-dialog,#invoice-dialog,#calendar-room-dialog,#operations-dialog).managed-window:not(.window-maximized) {
  top:80px; transform:translateX(-50%);
}
/* Small screens keep readable fields and visible controls with an outer gap. */
@media (max-width:800px) {
  html:root {
    --window-width-limit: calc(100vw - 24px);
    --window-height-limit: 92dvh;
    --window-normal-top: 50%;
  }
  html:root :is(#employee-dialog,#department-dialog,#profile-dialog,#project-dialog,#hr-create-dialog,#chat-dialog,#invoice-route-dialog,#invoice-dialog,#calendar-room-dialog,#operations-dialog).managed-window:not(.window-maximized) { top:16px; }
}
@media (max-width:700px) {
  html:root #task-drawer.managed-window .task-detail-actions {
    position: sticky; bottom: 0; z-index: 3;
  }
}
/* Short laptop screens still leave room around the window. */
@media (min-width:801px) and (max-height:600px) {
  html:root { --window-height-limit: calc(100dvh - 96px); --window-normal-top: 50%; }
  html:root :is(#employee-dialog,#department-dialog,#profile-dialog,#project-dialog,#hr-create-dialog,#chat-dialog,#invoice-route-dialog,#invoice-dialog,#calendar-room-dialog,#operations-dialog).managed-window:not(.window-maximized) { top:48px; }
}
