/*
 * The windows of Cronum Work's one-document shell (windows.js): a grid of one to four columns,
 * each a window or two stacked, with 8 px bars between them; on a phone, one window and a bar of
 * tabs. Linked after kit.css, whose tokens it uses. Windows are placed by their grid column only
 * (windows.js writes it), so a module's page inside never moves in the document.
 */

.cw-desk {
  position: relative; display: grid; grid-template-rows: minmax(0, 1fr);
  min-width: 0; min-height: 0; padding: 8px; overflow: hidden;
}
.cw-desk[data-resizing], .cw-desk[data-reordering] { user-select: none; -webkit-user-select: none; }
/* Safari draws a field's text blank under -webkit-user-select: none (a list's name in Tasks is one). */
.cw-desk[data-resizing] :is(input, textarea), .cw-desk[data-reordering] :is(input, textarea) { user-select: text; -webkit-user-select: text; }
/* A frame under the pointer would swallow its moves. */
.cw-desk[data-resizing] iframe, .cw-desk[data-reordering] iframe { pointer-events: none; }

.cw-win {
  display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
  border: 1px solid var(--kit-border); border-radius: 12px; background: var(--kit-bg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}
.cw-win[hidden] { display: none; }
.cw-win[data-focus="true"] { border-color: color-mix(in srgb, var(--kit-accent) 45%, var(--kit-border)); }
.cw-win[data-carried] { position: relative; z-index: 5; box-shadow: var(--kit-shadow-high); cursor: grabbing; }

/*
 * Two windows in a column share its cell: the top one from its start, the bottom one to its end,
 * each its share of the height but the bar's (`--cw-share`, the column's `--cw-row-N`).
 */
.cw-win[data-stack] { align-self: start; height: calc((100% - 8px) * var(--cw-share, .5)); }
.cw-win[data-stack="bottom"] { align-self: end; height: calc((100% - 8px) * (1 - var(--cw-share, .5))); }

.cw-win__head {
  display: flex; align-items: center; gap: 8px; height: 32px; padding-inline: 10px; flex: none;
  border-block-end: 1px solid var(--kit-border); cursor: grab; user-select: none; -webkit-user-select: none;
  touch-action: none; font-size: 13px; font-weight: 500;
}
.cw-win__head:focus-visible { outline: 2px solid var(--kit-accent); outline-offset: -2px; }

/* Maximize and restore, at the end of the head. */
.cw-win__max {
  display: inline-grid; place-items: center; flex: none; width: 24px; height: 24px; margin-inline: auto -4px; padding: 0;
  border: 0; border-radius: 6px; background: none; color: var(--kit-muted); cursor: pointer;
}
.cw-win__max[hidden] { display: none; }
.cw-win__max:hover { background: var(--kit-hover); color: var(--kit-text); }
.cw-win__max:focus-visible { outline: 2px solid var(--kit-accent); outline-offset: -2px; }
.cw-win__max .kit-icon { width: 15px; height: 15px; }

/*
 * Maximized: the window over the whole desk, the others fading out under it (and back in as it
 * returns). Its place in the layout is kept: only the grid area changes.
 */
.cw-desk > .cw-win { transition: opacity .25s ease, visibility 0s; }
.cw-desk > .cw-win[data-max] {
  grid-column: 1 / -1 !important; grid-row: 1 / -1 !important; align-self: stretch; height: auto; z-index: 3;
}
.cw-desk[data-maxed] > .cw-win:not([data-max]) { opacity: 0; visibility: hidden; transition: opacity .25s ease, visibility 0s linear .25s; }
.cw-desk[data-maxed] > .cw-bar { visibility: hidden; }
/*
 * Maximize and restore (windows.js `crossfade`): the window's box grows or shrinks to its place,
 * and in it what it showed fades out as what it shows fades in, each drawn at its own size from
 * the top corner, cut by the box, never stretched. The others fade with the page (their own
 * fade waits), and nothing else on the page is named meanwhile.
 */
:root[data-cw-max-fade] .cw-desk > .cw-win { transition: none; }
:root[data-cw-max-fade] .kit-rail { view-transition-name: none; }
:root[data-cw-max-fade]::view-transition-old(root),
:root[data-cw-max-fade]::view-transition-new(root) { animation-duration: .28s; }
::view-transition-group(cw-win-max) {
  animation-duration: .28s; animation-timing-function: cubic-bezier(.4, .05, .2, 1.06);
  border-radius: 12px; background: var(--kit-bg); box-shadow: inset 0 0 0 1px var(--kit-border);
}
::view-transition-image-pair(cw-win-max) { clip-path: inset(0 round 12px); }
::view-transition-old(cw-win-max), ::view-transition-new(cw-win-max) {
  inline-size: auto; block-size: auto; object-fit: none; object-position: 0 0;
}
/* The new one comes in over the old, which stays as it is under it: no moment where both are faint. */
::view-transition-old(cw-win-max) { animation: none; mix-blend-mode: normal; }
::view-transition-new(cw-win-max) { animation: cw-win-fade-in .2s ease-out .03s both; mix-blend-mode: normal; }
@keyframes cw-win-fade-in { from { opacity: 0; } }

/* The module's page, inside its window: what was the viewport is the window's body. */
.cw-win__body { position: relative; flex: 1; min-height: 0; overflow: hidden; contain: layout paint; }
/*
 * A window is never at the screen's top or bottom: the shell's bar and a phone's tabs are, and keep
 * the room of the iPhone's notch and home bar. The module inside adds none of its own (the kit's
 * --kit-safe-*, and the module's env() through --cw-inset-*, scope-css.js).
 */
.cw-win__body { --kit-safe-top: 0px; --kit-safe-bottom: 0px; --cw-inset-top: 0px; --cw-inset-bottom: 0px; }
.cw-win__frame { display: block; width: 100%; height: 100%; border: 0; }

/* The bars: between two columns, and between the two windows of a column. */
.cw-bar { position: relative; cursor: col-resize; touch-action: none; }
.cw-bar[hidden] { display: none; }
.cw-bar[data-axis="row"] {
  align-self: start; height: 8px; cursor: row-resize;
  inset-block-start: calc((100% - 8px) * var(--cw-share, .5));
}
.cw-bar::after {
  content: ''; position: absolute; inset: 30% 3px; border-radius: 2px;
  background: transparent; transition: background .15s;
}
.cw-bar[data-axis="row"]::after { inset: 3px 30%; }
.cw-bar:hover::after, .cw-bar:focus-visible::after, .cw-desk[data-resizing] .cw-bar::after { background: var(--kit-muted); }
.cw-bar:focus-visible { outline: none; }

/* Where a carried window would land, when it isn't a column's place (that one is taken live): its
   left and top are the pointer's, physical on purpose (windows.js). */
.cw-drop {
  position: absolute; left: 0; top: 0; z-index: 4; pointer-events: none; box-sizing: border-box;
  border: 2px dashed color-mix(in srgb, var(--kit-accent) 60%, transparent); border-radius: 12px;
  background: color-mix(in srgb, var(--kit-accent) 8%, transparent);
}
.cw-drop[hidden] { display: none; }

/* ------------------------------------ phones ------------------------------------- */

/* The tabs are only a phone's. */
.cw-tabs { display: none; }

/*
 * One window filling the desk and the tabs under it, the one way to another module. The desk
 * only pans up and down, so the page never scrolls sideways.
 */
.cw-desk[data-screen="narrow"] {
  grid-template-rows: minmax(0, 1fr) auto; padding: 0; gap: 0;
  overflow-x: hidden; max-width: 100vw; touch-action: pan-y;
}
html:has(.cw-desk[data-screen="narrow"]), html:has(.cw-desk[data-screen="narrow"]) body { overflow-x: hidden; }
.cw-desk[data-screen="narrow"] > .cw-win { grid-row: 1; border: 0; border-radius: 0; box-shadow: none; }
/* Its module is in the tabs: the head would only take room from it. */
.cw-desk[data-screen="narrow"] .cw-win__head { display: none; }

.cw-desk[data-screen="narrow"] > .cw-tabs {
  display: flex; grid-row: 2; grid-column: 1 / -1; min-width: 0;
  border-block-start: 1px solid var(--kit-border); background: var(--kit-side);
  /* Half the home bar's room: with all of it the icons and names sat high in the bar (iPhone). */
  padding-block-end: calc(var(--kit-safe-bottom) / 2);
}
/* A keyboard that made the page shorter (Work's apps): the tabs would sit on it while typing, and their room is the module's. */
.cw-desk[data-screen="narrow"][data-keyboard] > .cw-tabs { display: none; }
.cw-tabs__tab {
  flex: 1 1 0; min-width: 0; min-height: 52px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; padding: 9px 2px 2px;
  border: 0; background: transparent; color: var(--kit-muted); font: inherit; font-size: 11px; cursor: pointer;
}
/* The icon on a pill, which the module in use fills; the others' icons and names step back. */
.cw-tabs__tab img {
  box-sizing: content-box; width: 22px; height: 22px; padding: 3px 18px; border-radius: 999px;
  opacity: .55; transition: opacity .15s ease, background-color .15s ease;
}
.cw-tabs__tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cw-tabs__tab[aria-current="true"] { color: var(--kit-text); font-weight: 600; }
.cw-tabs__tab[aria-current="true"] img { opacity: 1; background: color-mix(in srgb, var(--kit-text) 10%, transparent); }
.cw-tabs__tab:focus-visible { outline: 2px solid var(--kit-accent); outline-offset: -2px; }

@media (prefers-reduced-motion: reduce) {
  .cw-bar::after, .cw-tabs__tab img, .cw-desk > .cw-win { transition: none; }
}
