/* The application frame: columns side by side, each scrolling on its own.
 *
 * Right of the rail the conversation and the document pane start level and
 * share the width by the ratio the separator between them sets. The ratio is
 * two custom properties written by `split.js` from the account's setting.
 * The minimums are in the track list, so no ratio can squeeze the chat below
 * its measure or the pane below something a document fits in.
 *
 * The two outer columns close down to a strip of icons: the rail by the
 * person's setting (`html[data-leiste]`), the file column by the Vorgang's
 * files and the person's setting (`body[data-dateien]`). Both are rendered by
 * the server, so the first paint is right, and kept by the scripts after. A
 * page without a Vorgang has no file column, and its track is zero wide.
 */

body.app-shell {
  height: 100dvh;
  overflow: hidden;
}

.app {
  height: 100%;
  display: grid;
  grid-template-columns:
    var(--rail-w)
    minmax(var(--chat-min), var(--chat-fr, 1fr))
    var(--split-w)
    minmax(var(--doc-min), var(--doc-fr, 1fr))
    var(--files-track);
  --files-track: 0px;
  background: var(--desk);
}

.app:has(> .col-files) { --files-track: var(--strip-w); }
body[data-dateien="auf"] .app:has(> .col-files) { --files-track: var(--files-w); }

/* Only the rail beside the columns can be narrowed; the rail laid across the
 * top on a small screen has no width to give. */
@media (min-width: 1001px) {
  html[data-leiste="schmal"] { --rail-w: var(--strip-w); }
}

/* `min-*: 0` is what actually lets a grid child scroll instead of stretching
 * its track. Without it every column grows to its content and the page scrolls
 * as a whole, which is the thing this layout exists to stop. */
.col {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--paper);
}

.col-rail { border-right: 1px solid var(--line); background: var(--rail-bg); }
.col-doc { background: var(--paper-2); }

/* -- separator ----------------------------------------------------------- */

/* A hairline in a hit area wide enough to find. The line is drawn by a
 * gradient rather than a border so that the grab area can be wider than what
 * is seen without taking width from either column's contents. */
.col-split {
  position: relative;
  cursor: col-resize;
  touch-action: none;
  background: linear-gradient(var(--line), var(--line)) center / 1px 100% no-repeat var(--paper);
}

.col-split:hover,
.col-split:focus-visible,
body.dragging .col-split {
  background-image: linear-gradient(var(--blue), var(--blue));
  background-size: 3px 100%;
}

/* The focus ring would be clipped by the columns either side; the thicker
 * blue line above is the focus indication instead. */
.col-split:focus-visible { outline: none; }

/* While a separator is dragged the pointer crosses the PDF viewer and the
 * framed page, and both would take the pointer events for themselves. */
body.dragging { cursor: col-resize; user-select: none; }
body.dragging .doc-object { pointer-events: none; }

/* -- rail ---------------------------------------------------------------- */

/* The wordmark, centred both ways, in a header the height of every other
 * column header. It used to be flush to the column's left edge and inset on
 * the right, which read as a rendering fault rather than as a layout. */
.rail-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  min-height: var(--head-h);
  padding: 0 .7rem 0 1rem;
  border-bottom: 1px solid var(--line);
}

.rail-logo { display: block; width: 100%; max-width: 12rem; }
.rail-logo img { width: 100%; height: auto; display: block; }

/* -- the two toggles ----------------------------------------------------- */

/* Icon-only, one control height, like the buttons in the document pane's
 * sub-header, but a bare grey glyph on white: they change the frame, not the
 * work, and a filled or framed block beside the wordmark outweighed
 * everything near it. The glyph is 5.7:1 on white, and the hover tint shows
 * the button's extent.
 * Each carries both glyphs and shows the one that says what a click will do,
 * so nothing has to swap them before the first paint. */
.rail-toggle,
.files-toggle {
  flex: none;
  justify-content: center;
  min-height: var(--control-h);
  padding: .3rem .45rem;
  color: var(--gray);
  background: var(--paper);
}

/* On the side columns' tint the toggles have no white block of their own. */
.rail-toggle,
.files-toggle { background: none; }

.rail-toggle:hover,
.files-toggle:hover {
  color: var(--blue);
  background: var(--tint-input);
}

.toggle-narrow { display: none; }
html[data-leiste="schmal"] .rail-toggle .toggle-wide,
body:not([data-dateien="auf"]) .files-toggle .toggle-wide { display: none; }
html[data-leiste="schmal"] .rail-toggle .toggle-narrow,
body:not([data-dateien="auf"]) .files-toggle .toggle-narrow { display: block; }

.rail-new {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  margin: .8rem 1.1rem;
  padding: .55rem .7rem;
  color: var(--paper);
  background: var(--blue);
  font-weight: bold;
  text-decoration: none;
}

.rail-nav {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 .6rem 1rem;
  scroll-padding-block: 1rem;
}

.rail-group + .rail-group { margin-top: 1.2rem; }

/* Under *Neuer Vorgang*: what is found rather than worked on. Outlined in
 * the same blue, so the one filled button stays the first thing to do. */
.rail-tools {
  display: flex;
  gap: .5rem;
  margin: -.3rem 1.1rem .8rem;
}

.rail-tool {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .45rem .6rem;
  border: 1px solid var(--blue);
  color: var(--blue);
  background: var(--paper);
  font-weight: bold;
  text-decoration: none;
}

.rail-tool:hover { background: var(--tint-input); }
.rail-tool[aria-current="page"] { color: var(--paper); background: var(--blue); }

.rail-heading {
  margin: 0 .5rem .4rem;
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--gray);
}

.rail-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* The row is the hover surface for both the link and the bin beside it, so the
 * bin does not appear out of a patch of nothing, and the tint of the current
 * Vorgang runs under the bin as well. */
.rail-row {
  display: flex;
  align-items: center;
}

.rail-row:hover,
.rail-row:focus-within,
.rail-row-current { background: var(--tint-input); }

.rail-item {
  display: block;
  flex: 1;
  min-width: 0;
  padding: .45rem .5rem;
  color: inherit;
  text-decoration: none;
}

/* A row without a bin (under "Aktiv") keeps the bin's width free, so what
 * sits at the right end of a row, the chat count, lines up down the rail. */
html:not([data-leiste="schmal"]) .rail-row:not(:has(> .rail-delete)) > .rail-item {
  padding-right: calc(.5rem + 1.25em + .8rem);
}

/* Quiet until the row is under the pointer, and never quieter than a keyboard
 * can find: it is a destructive control, so it is not hidden from focus. */
.rail-delete {
  flex: none;
  padding: .4rem;
  color: var(--gray);
  background: none;
  opacity: 0;
}

.rail-row:hover .rail-delete,
.rail-row-current .rail-delete,
.rail-delete:focus-visible { opacity: 1; }
.rail-delete:hover { color: var(--red); }

.rail-item[aria-current="page"] { font-weight: bold; }

/* The icon sits on the first line of the title, not in the middle of a title
 * that wraps: the offset centres the 1.25em icon on a 1.55 line. */
.rail-item-title {
  display: flex;
  align-items: flex-start;
  gap: .4rem;
  overflow: hidden;
}

.rail-item-title .icon { color: var(--gray); margin-top: .15em; }

.rail-item[aria-current="page"] .rail-item-title .icon { color: var(--blue); }

.rail-item-meta {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding-left: 1.65rem;
  font-size: .8rem;
  font-weight: normal;
  color: var(--gray);
}

/* How many chats the Vorgang has, from two on: a glyph and a number at the
 * right end of the second line, where it costs no height. */
.rail-chats {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  margin-left: auto;
  padding-right: .2rem;
}

.rail-chats .icon { width: 1em; height: 1em; }

/* One day under "Zuletzt": a hairline, then the date in the quiet mixed case
 * that keeps it below the uppercase group heading. */
.rail-day {
  margin-top: .5rem;
  border-top: 1px solid var(--line);
}

.rail-day-heading {
  margin: 0;
  padding: .45rem .5rem .2rem;
  font-size: .78rem;
  font-weight: normal;
  color: var(--gray);
}

.rail-empty {
  margin: 0 .5rem;
  font-size: .85rem;
  color: var(--gray);
}

.rail-foot {
  border-top: 1px solid var(--line);
  padding: .8rem 1.1rem 1rem;
}

/* The way to the settings, as quiet as the credit line under it, and marked
 * like the current Vorgang while the settings are open. */
.rail-settings {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin: 0 -.5rem .6rem;
  padding: .35rem .5rem;
  color: var(--anthracite);
  font-size: .9rem;
  text-decoration: none;
}

.rail-settings .icon { color: var(--gray); }
.rail-settings:hover,
.rail-settings[aria-current="page"] { background: var(--tint-input); }
.rail-settings[aria-current="page"] { font-weight: bold; }
.rail-settings[aria-current="page"] .icon { color: var(--blue); }

.rail-credit {
  margin-bottom: .5rem;
  font-size: .78rem;
  color: var(--gray);
}

.rail-account {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.rail-user {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .9rem;
}

.rail-account form { margin: 0; }
.rail-account .link-button { display: inline-flex; align-items: center; gap: .3rem; }

/* -- the narrow rail ----------------------------------------------------- */

/* Icons only: the wordmark, the headings, the times and the bins go, and the
 * words are hidden from sight but not from a screen reader. Each Vorgang keeps
 * its icon, with a `title` for its name, and a waiting or working one keeps
 * its dot, on the icon's corner. The day separators stay as hairlines. */
@media (min-width: 1001px) {
  html[data-leiste="schmal"] .rail-brand { padding: 0; }
  html[data-leiste="schmal"] .rail-logo,
  html[data-leiste="schmal"] .rail-heading,
  html[data-leiste="schmal"] .rail-day-heading,
  html[data-leiste="schmal"] .rail-empty,
  html[data-leiste="schmal"] .rail-delete,
  html[data-leiste="schmal"] .rail-credit,
  html[data-leiste="schmal"] .rail-user { display: none; }

  html[data-leiste="schmal"] .rail-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }

  html[data-leiste="schmal"] .rail-new { margin: .8rem .45rem; padding: .55rem 0; }
  html[data-leiste="schmal"] .rail-tools { flex-direction: column; margin: -.3rem .45rem .8rem; }
  html[data-leiste="schmal"] .rail-tool { padding: .5rem 0; }
  html[data-leiste="schmal"] .rail-nav { padding: 0 .35rem 1rem; scrollbar-width: none; }
  html[data-leiste="schmal"] .rail-group + .rail-group { margin-top: .5rem; }
  html[data-leiste="schmal"] .rail-item { position: relative; padding: .55rem 0; }
  html[data-leiste="schmal"] .rail-item-title { justify-content: center; }
  html[data-leiste="schmal"] .rail-item-title .icon { margin-top: 0; }
  /* Narrow, the row is an icon with its state dot; the count is in the
   * tooltip instead. */
  html[data-leiste="schmal"] .rail-chats { display: none; }
  html[data-leiste="schmal"] .rail-item-meta {
    position: absolute;
    top: .35rem;
    right: .45rem;
    padding: 0;
  }
  html[data-leiste="schmal"] .rail-foot { padding: .8rem 0 1rem; }
  html[data-leiste="schmal"] .rail-account { justify-content: center; }
  html[data-leiste="schmal"] .rail-settings { justify-content: center; margin: 0 .35rem .6rem; padding: .45rem 0; }
}

/* -- narrower screens ---------------------------------------------------- */

/* Below this the document pane stops being a column and lies over the chat
 * instead; two columns of half a screen each are worse than one of each. The
 * file column stays where it is, and the pane opens to the left of it, so a
 * click in the tree still changes what the pane shows. */
@media (max-width: 1400px) {
  .app { grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--files-track); }
  .col-split { display: none; }
  .col-doc {
    position: fixed;
    inset: 0 var(--files-track) 0 auto;
    width: min(46rem, 70vw);
    z-index: 20;
    border-left: 1px solid var(--line-strong);
    transform: translateX(100%);
    visibility: hidden;
  }
  body[data-doc="on"] .col-doc { transform: none; visibility: visible; }
}

@media (max-width: 1000px) {
  .app {
    grid-template-columns: minmax(0, 1fr) var(--files-track);
    grid-template-rows: auto minmax(0, 1fr);
  }
  .col-rail {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    gap: 1rem;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
  }
  .rail-brand { flex-direction: row; align-items: center; border: 0; padding: .6rem 1rem; }
  .rail-logo img { width: 120px; }
  .rail-new { margin: 0 1rem; }
  .rail-tools { margin: 0 1rem 0 0; }
  .rail-nav { display: none; }
  .rail-foot { border: 0; margin-left: auto; padding: .6rem 1rem; }
  .rail-credit,
  .rail-settings,
  .rail-toggle { display: none; }
  .col-doc { left: 0; width: auto; }
}
