/* Split View (static/js/workspace.js): two desktop tabs side by side.
 *
 * On its own a page is unchanged: the host (.ws), its pane (.ws-pane), the
 * frame (.ws-frame) and the scroller (.ws-body) are display: contents, so
 * the page lays out on <body> exactly as it always has. Once a split opens,
 * <html> takes .ws-on and the host becomes a fixed grid: pane a | divider |
 * pane b. Panes are never moved in the DOM -- swapping sides, expanding and
 * closing only change data-slot, the grid columns, visibility and inert.
 */

html:not(.ws-on) .ws,
html:not(.ws-on) .ws-pane,
html:not(.ws-on) .ws-frame,
html:not(.ws-on) .ws-body { display: contents !important; }
html:not(.ws-on) .ws-head,
html:not(.ws-on) .ws-div { display: none !important; }

:root {
  --ws-bg: #ffffff;
  --ws-ink: #0e0e0e;
  --ws-dim: #6b6b72;
  --ws-line: #e6e6e6;
  --ws-soft: #f2f2f2;
  --ws-grip: #d4d4d4;
}
:root[data-theme="dark"] {
  --ws-bg: #0b0b0c;
  --ws-ink: #f4f4f5;
  --ws-dim: #8a8a90;
  --ws-line: #1f1f22;
  --ws-soft: #1c1c1f;
  --ws-grip: #3a3a3e;
}

html.ws-on,
html.ws-on body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ws-bg);
}

html.ws-on .ws {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  grid-template-columns: minmax(0, var(--ws-a, 60fr)) 9px minmax(0, var(--ws-b, 40fr));
  background: var(--ws-bg);
}
html.ws-on .ws[data-layout="solo"] { grid-template-columns: minmax(0, 1fr) 0 0; }

.ws-on .ws-pane {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  grid-row: 1;
  background: var(--ws-bg);
}
.ws-on .ws-pane[data-slot="a"] { grid-column: 1; }
.ws-on .ws-pane[data-slot="b"] { grid-column: 3; }
.ws-on .ws[data-layout="solo"] .ws-pane[data-slot="a"] { grid-column: 1 / -1; }

/* Off screen, not gone: a pane that is not shown keeps its nodes (and its
   width, so nothing re-lays out) but is invisible and inert. Never
   display: none -- a playing iframe would be torn down. */
.ws-on .ws-pane.is-off {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--ws-off-w, 50vw);
  height: 100%;
  visibility: hidden;
  pointer-events: none;
  z-index: -1;
}

.ws-on .ws-frame {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  container: pane / inline-size;
  /* A pane's own fixed sheets and overlays stay inside the pane (a size
     container alone is not a containing block for position: fixed). */
  contain: layout;
}
.ws-on .ws-body {
  position: absolute;
  inset: 0;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  min-height: 0 !important;
  height: auto !important;
  margin: 0 !important;
}

.ws-load {
  display: grid;
  place-items: center;
  height: 100%;
  font: 600 12px/1 "JetBrains Mono", ui-monospace, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ws-dim);
  background: var(--ws-bg);
}

/* ------------------------------------------------------------ pane head */

.ws-head {
  display: none;
  position: relative;
  z-index: 90;
  flex: 0 0 auto;
  height: 30px;
  align-items: center;
  gap: 8px;
  padding: 0 8px 0 14px;
  border-bottom: 1px solid var(--ws-line);
  background: var(--ws-bg);
  color: var(--ws-dim);
  font: 600 11px/1 "JetBrains Mono", ui-monospace, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.ws-on .ws[data-layout="split"] .ws-head { display: flex; }
.ws-head__name { flex: 1 1 auto; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ws-head__name::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 8px;
  border-radius: 50%;
  vertical-align: 1px;
  background: transparent;
  box-shadow: inset 0 0 0 1.5px currentColor;
}
.ws-pane.is-focused .ws-head { color: var(--ws-ink); }
.ws-pane.is-focused .ws-head__name::before { background: currentColor; }
.ws-head button {
  display: inline-grid;
  place-items: center;
  height: 22px;
  min-width: 22px;
  padding: 0 6px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.ws-head button:hover { background: var(--ws-soft); color: var(--ws-ink); }
.ws-head button:focus-visible { outline: 2px solid var(--ws-ink); outline-offset: -2px; }
.ws-head__acts { display: flex; align-items: center; gap: 2px; }
.ws-head__menu {
  position: absolute;
  top: 32px;
  right: 8px;
  min-width: 190px;
  padding: 6px;
  border: 1.5px solid var(--ws-ink);
  border-radius: 12px;
  background: var(--ws-bg);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ws-head__menu[hidden] { display: none; }
.ws-head__menu button { justify-content: start; height: 32px; padding: 0 10px; color: var(--ws-ink); text-align: left; }
.ws-head__menu button:disabled { color: var(--ws-dim); cursor: default; background: none; }

/* -------------------------------------------------------------- divider */

.ws-div {
  display: none;
  grid-column: 2;
  grid-row: 1;
  position: relative;
  cursor: col-resize;
  background: var(--ws-bg);
  touch-action: none;
}
.ws-on .ws[data-layout="split"] .ws-div { display: block; }
.ws-div::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 4px;
  width: 1px;
  background: var(--ws-line);
}
.ws-div::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 2px;
  width: 5px;
  height: 36px;
  margin-top: -18px;
  border-radius: 3px;
  background: var(--ws-grip);
}
.ws-div:hover::after,
.ws-div.is-drag::after,
.ws-div:focus-visible::after { background: var(--ws-ink); }
.ws-div:focus-visible { outline: none; }
.ws.is-dragging { cursor: col-resize; user-select: none; }
.ws.is-dragging .ws-pane { pointer-events: none; }

/* -------------------------------------------------------- the tab picker */

.ws-pick {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 48px 32px;
  color: var(--ws-ink);
  font-family: "Archivo", system-ui, sans-serif;
}
.ws-pick h2 { margin: 0; font-size: 22px; font-weight: 900; letter-spacing: -0.01em; }
.ws-pick p { margin: 0; color: var(--ws-dim); font-size: 14px; }
.ws-pick__list { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.ws-pick__list button {
  height: 46px;
  padding: 0 14px;
  border: 1.5px solid var(--ws-line);
  border-radius: 12px;
  background: none;
  color: inherit;
  font: 800 15px/1 "Archivo", system-ui, sans-serif;
  text-align: left;
  cursor: pointer;
}
.ws-pick__list button:hover { border-color: var(--ws-ink); }

/* Below 900px there is room for one pane: the focused one fills the window
   (workspace.js marks the other .is-off). */
@media (max-width: 899px) {
  html.ws-on .ws[data-layout="split"] { grid-template-columns: minmax(0, 1fr) 0 0; }
  html.ws-on .ws[data-layout="split"] .ws-pane:not(.is-off) { grid-column: 1 / -1; }
  html.ws-on .ws[data-layout="split"] .ws-div { display: none; }
}

/* ------------------------------------------------ MENU rows (desktop-tabs) */

.dt-row { position: relative; display: block; }
.dt-row.has-split > a,
.dt-row.has-split > button:not(.dt-split) { padding-right: 46px !important; }
.dt-split {
  position: absolute;
  top: 50%;
  right: 6px;
  width: 30px;
  height: 30px;
  margin-top: -15px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: inherit;
  font: 400 17px/1 system-ui, sans-serif;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease;
}
.dt-split[hidden] { display: none; }
.dt-row:hover .dt-split,
.dt-row:focus-within .dt-split,
.dt-row.is-current .dt-split { opacity: 1; }
.dt-split:hover { background: rgba(127, 127, 127, 0.2); }
.dt-split:disabled { cursor: default; opacity: 0.35 !important; background: none; }
.dt-split:focus-visible { outline: 2px solid currentColor; outline-offset: -2px; }
/* On the current row the button sits on the dark bar; it reads off it. */
.dt-row.is-current .dt-split { color: var(--white, #ffffff); }

/* Split View is a desktop thing: no controls on a narrow window or a
   touch screen. */
@media (max-width: 1099px), (hover: none) {
  .dt-split { display: none !important; }
  .dt-row.has-split > a,
  .dt-row.has-split > button:not(.dt-split) { padding-right: 14px !important; }
}
