/* Knihovna: the document grid, category chips, the toolbar and the upload dialog.
   Moved out of base.css, shared-components.css and features.css in their
   original cascade order; loaded after features.css and before type.css. */

.library-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  /* Room on both sides: the cards used to run to the frame, which is what
     made the section feel like a table rather than a page. */
  padding: 0 var(--library-gutter) var(--main-pad) calc(var(--rail-width) + var(--library-gutter));
  display: none;
}

/* A grid of covers, not prose, so it takes the whole width: a wider window
   buys another column rather than wider margins. The cards keep their own
   minimum width, so nothing stretches. */
.library-wrap {
  width: 100%;
  margin: 0 auto;
}

/* The dark slate pill this used to be was already stripped back to nothing by
   features.css; what was left read as a toolbar bolted above the page. It is
   a page header now: room above it, the name at display size, the controls on
   its line. */
/* One row: the search field finishes against the right edge and the
   category chips take what is left, handing the overflow to "Další"
   rather than pushing the search onto a line of its own. */
.library-toolbar-shell {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
  margin: 0 0 22px;
  padding: 32px 0 18px;
  background: transparent;
  border-bottom: 1px solid var(--border-soft);
}

.library-toolbar {
  display: flex;
  align-items: center;
  gap: 18px;
  flex: 0 1 18rem;
  min-width: 12rem;
  margin-left: auto;
}

.library-toolbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex: 1 1 auto;
  min-width: 0;
}

.library-upload-btn {
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: var(--r-md);
  font-size: 0;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  transition: background .15s, border-color .15s, color .15s, transform .15s;
}

.library-upload-btn:hover {
  border-color: rgba(34, 197, 94, 0.58);
  transform: translateY(-1px);
}

.library-upload-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Compact on a desktop toolbar, but still allowed to shrink when a long
   category heading needs the room. */
/* The magnifier is a background so the field stays a single element for
   the layouts that resize it. */
.library-filter {
  width: min(20rem, 100%);
  flex: 0 1 20rem;
  max-width: 20rem;
  padding: 9px 12px 9px 34px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-input);
  font: inherit;
  font-size: var(--text-sm);
  outline: none;
  background-image: var(--search-icon);
  background-repeat: no-repeat;
  background-position: 12px center;
  background-size: 15px 15px;
}

/* Left to the browser default until now, which washes out on the flax
   ground. The app's other search fields all name this colour. */
.library-filter::placeholder {
  color: var(--faint);
}

.library-list {
	      /* Column count follows the width rather than being fixed at four: at a
	         1280 window four made 229px cards, so every title wrapped to three
	         lines and the cards grew tall and mostly empty. */
	      grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
	      gap: 14px;
	      align-items: stretch;
	      padding-top: 0;
	    }

.library-item {
  position: relative;
  padding: 16px 40px 16px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 88px;
  transition: border-color .15s, background .15s, box-shadow .15s, transform .15s;
}

.library-text {
  min-width: 0;
  flex: 1;
}

.library-name {
  font-size: var(--text-md);
  font-weight: 450;
  line-height: 1.34;
  display: block;
  max-height: 4.2em;
  overflow: hidden;
  word-break: break-word;
}

.library-empty {
  grid-column: 1 / -1;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: var(--r-xl);
  padding: 28px;
  font-size: var(--text-md);
  text-align: center;
}

.library-empty strong {
  font-weight: 600;
  color: inherit;
}

.library-empty.compact-loader {
  min-height: 64px;
  padding: 14px 4px;
  display: grid;
  align-content: center;
  gap: 11px;
  text-align: left;
  border: 0;
  border-radius: 0;
}

.library-empty.compact-loader::before,
.library-empty.compact-loader::after {
  content: "";
  display: block;
  height: 13px;
  border-radius: var(--r-pill);
  background: var(--skeleton);
  background-size: 220% 100%;
  animation: subtleSkeleton 1.8s ease-in-out infinite;
}

.library-empty.compact-loader::after {
  width: 46%;
  animation-delay: 0.16s;
}

.library-empty.library-empty-state {
  min-height: 120px;
  padding: 44px 16px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--faint);
}

.upload-btn {
  border: none;
  border-radius: var(--r-sm);
  padding: 9px 18px;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}

.upload-btn:disabled {
  cursor: not-allowed;
}

/* ── Upload modal ─── */
.upload-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.upload-modal-overlay.open { display: flex; }

.upload-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-pop);
  width: 560px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.upload-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
}

.upload-modal-title { font-size: var(--text-lg); font-weight: 650; }

.upload-modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--r-sm);
  transition: background var(--dur), color var(--dur);
}

.upload-modal-close:hover { background: var(--hover-bg); color: var(--ink); }

.upload-modal-body { padding: 20px; overflow-y: auto; flex: 1; }

/* Holds current access and how to set it up, so it needs more room than a
   plain confirmation dialog. */
.upload-modal-wide { width: 640px; }

.upload-modal-dropzone {
  border: 1px dashed var(--border-card-hover);
  border-radius: var(--r-lg);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--dur), background var(--dur);
}

.upload-modal-dropzone-icon { margin-bottom: 8px; }

.upload-modal-filelist { flex-direction: column; gap: 8px; }

.upload-modal-file-item {
  align-items: flex-start;
  gap: 12px;
}

.upload-modal-file-docname {
  font-size: var(--text-sm);
  outline: none;
  transition: border-color var(--dur), background var(--dur);
}

.upload-modal-file-docname:focus { background: var(--surface); }

.upload-modal-footer {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.library-filter:focus {
  border-color: var(--border-input);
  box-shadow: none;
}

.library-filter::selection {
  background: rgba(15, 23, 42, 0.14);
  color: inherit;
}

.upload-modal-title {
  color: var(--ink);
}

.library-filter {
  /* The colour only: the library search draws its magnifier as a
     background image, which the shorthand would wipe. */
  background-color: var(--surface);
  border-color: var(--border-input);
  color: var(--ink);
}

.upload-modal-file-item {
  background: var(--surface);
  border-color: var(--border);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}

/* The page ground runs behind the toolbar too; a white band across the
   top made the header look like a separate sheet laid on the page. */
.library-toolbar-shell::before { display: none; }

/* Every area lets the flax page ground through, the way #chat-area does.
   Warm white is reserved for what sits on top of it -- cards, panels,
   the composer -- so those read as raised rather than as the norm. */
.library-area {
  background: transparent;
}

/* Quiet, like the day arrows in Zprávy: a header control earns attention by
   being where it is expected, not by being tinted. */
.library-upload-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}

.library-upload-btn[hidden] {
  display: none !important;
}

.library-upload-btn:hover {
  background: var(--hover-bg);
  color: var(--ink);
}

/* Category chips, leading the header row. Quiet at rest, the selected one
   filled with ink: the same weight as a pressed toggle, without spending
   the brand green on a filter. */
.library-cats {
  order: -1;
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 0;
  min-width: 0;
}

.library-cat-chips {
  display: flex;
  gap: 6px;
  min-width: 0;
  flex-wrap: nowrap;
}

.library-cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
  height: 30px;
  padding: 0 13px;
  border: 1px solid var(--border-input);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 450;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}

.library-cat-chip[hidden] { display: none; }

.library-cat-chip:hover {
  border-color: var(--border-focus);
  color: var(--ink);
}

.library-cat-chip.active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--surface);
}

.library-cat-more[hidden] { display: none; }

.library-cat-chip .ds-type-dd-chev {
  width: 14px;
  height: 14px;
  margin-right: -3px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform .18s;
}

.library-cat-chip[aria-expanded="true"] .ds-type-dd-chev {
  transform: rotate(180deg);
}

@media (prefers-reduced-motion: reduce) {
  .library-cat-chip,
    .library-cat-chip .ds-type-dd-chev {
      transition: none;
    }
}
.library-meta {
  margin-top: 3px;
  font-size: var(--text-xs);
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.library-list {
  display: block;
}

/* The library shows publications and then everything else. A heading over the
   second group named what the cards under it plainly are, and it was the
   first thing on the page; a rule draws the same boundary without spending a
   line on it. */
.library-section + .library-section {
  margin-top: 28px;
  padding-top: 28px;
  border-top: 1px solid var(--border-soft);
}

.library-publication-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
  align-items: stretch;
}

.library-document-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 14px;
  align-items: stretch;
}

.library-item.library-publication-item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

.library-publication-cover {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 210 / 297;
  overflow: hidden;
  background: var(--surface-inset);
}

.library-publication-cover img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}

/* Stands in for the cover when it cannot be rendered. It now carries the
   whole document name rather than the series, so it needs room to wrap. */
.library-publication-cover-fallback {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 7;
  overflow: hidden;
  padding: 0 16px;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 17px;
  line-height: 1.22;
  text-align: center;
}

/* `object-fit: contain` letterboxes anything that is not A4, and the bars
   are transparent -- without this the placeholder would read through them.
   The image is removed on error, which reveals the placeholder again. */
.library-publication-cover img + .library-publication-cover-fallback {
  display: none;
}

.library-publication-item .library-summary-btn {
  background: rgb(var(--surface-page-rgb) / .88);
}

@media (max-width: 1100px) {
  .library-wrap {
      max-width: 100%;
    }

  .library-list {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
@media (max-width: 720px) {
  .library-area {
      padding-left: var(--main-pad);
    }

  .library-area {
      padding: 18px;
    }

  .library-toolbar-shell {
  	        margin-bottom: 20px;
  	      }

  .library-toolbar {
      flex-direction: column;
      align-items: stretch;
      flex-wrap: wrap;
      gap: 10px;
    }

  .library-toolbar-actions {
      width: 100%;
      flex-basis: 100%;
      flex-wrap: wrap;
    }

  .library-filter {
      width: 100%;
      flex: 1 1 100%;
    }

  .library-upload-btn {
      width: 40px;
    }

  .library-list {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
@media (max-width: 520px) {
  .library-list {
      grid-template-columns: 1fr;
    }

  /* A cover is a picture, not text to read: two to a row on a phone keeps
       each one recognisable without one filling the whole screen. */
  .library-publication-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 12px;
    }
}
.library-item:focus-visible {
  outline: 2px solid #172033;
  outline-offset: 3px;
}

.library-empty {
  background:
    radial-gradient(circle at 50% 0%, rgba(34, 197, 94, 0.12), transparent 48%),
    linear-gradient(180deg, #ffffff, #f8fbff);
  border-color: var(--border);
  color: var(--muted);
  box-shadow: 0 16px 42px rgba(15, 23, 42, 0.08);
}

.library-empty.compact-loader {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.upload-modal-dropzone-text,
.upload-modal-dropzone-hint,
.upload-modal-file-name {
  color: var(--muted) !important;
}

.library-name {
  color: var(--ink);
}

.upload-btn {
  background: var(--green);
  border-color: var(--green);
  color: var(--on-accent);
}

.upload-btn:hover {
	      background: var(--green-hover);
	      border-color: var(--green-hover);
	    }

.upload-btn:disabled {
  background: var(--border-soft);
  color: var(--faint);
}

.upload-modal-dropzone {
  background: var(--surface-inset);
  border-color: var(--border-card-hover);
  color: var(--muted);
}

.upload-modal-dropzone:hover,
.upload-modal-dropzone.drag-over {
  background: var(--green-soft);
  border-color: var(--green);
}

.upload-modal-overlay {
  background: rgba(15, 23, 42, .36);
}

.upload-modal-header,
.upload-modal-footer,
.upload-modal-file-item {
  border-color: var(--border);
}

.upload-modal-file-item {
  background: var(--surface);
  border-color: var(--border);
}

.upload-modal-file-docname {
  border-color: var(--border-card-hover);
}

.upload-modal-file-docname::placeholder {
  color: var(--faint);
}

/* One selected PDF becomes a small form, not a one-item upload queue. */
#upload-modal-overlay .upload-modal {
  width: min(540px, calc(100vw - 32px));
  font-family: var(--font-sans);
  color: var(--text);
}

#upload-modal-overlay .upload-modal-header { padding: 18px 20px 14px; border-bottom: 0; }

#upload-modal-overlay .upload-modal-title { font-size: var(--text-base); font-weight: 600; letter-spacing: -.01em; }

#upload-modal-overlay .upload-modal-close {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: var(--r-md);
}

#upload-modal-overlay .upload-modal-close svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
}

#upload-modal-overlay .upload-modal-body { padding: 4px 20px 8px; }

.upload-modal-dropzone { padding: 26px 20px; margin-bottom: 14px; }

.upload-modal-dropzone[hidden] { display: none; }

.upload-modal-dropzone-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  margin: 0 auto 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-size: 0;
}

.upload-modal-dropzone-icon svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.upload-modal-dropzone-text { color: var(--ink) !important; font-size: var(--text-sm); font-weight: 500; }

.upload-modal-dropzone-hint { margin-top: 3px; font-size: var(--text-xs); }

.upload-modal-filelist { display: block; }

.upload-modal-file-item {
  display: block;
  padding: 2px 0 6px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.upload-modal-selected-file {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: var(--surface-inset);
}

.upload-modal-file-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--muted);
}

.upload-modal-file-icon svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.55;
  stroke-linecap: round;
}

.upload-modal-file-name {
  min-width: 0;
  overflow: hidden;
  color: var(--text) !important;
  font-size: var(--text-sm);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-modal-file-change {
  padding: 5px 7px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font: 12px var(--font-sans);
  cursor: help;
}

.upload-modal-file-change:hover {
  background: var(--hover-bg);
  color: var(--ink);
}

.upload-modal-file-fields {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.upload-modal-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 500;
}

.upload-modal-field[hidden] { display: none; }

.upload-modal-file-series,
.upload-modal-file-edition,
.upload-modal-file-date input,
.upload-modal-file-docname {
  min-width: 0;
  width: 100%;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
  font: 13px var(--font-sans);
}

.upload-modal-file-series:focus,
.upload-modal-file-edition:focus,
.upload-modal-file-date input:focus,
.upload-modal-file-docname:focus {
  border-color: var(--border-focus);
  outline: 0;
}

#upload-modal-overlay .upload-modal-footer { justify-content: flex-end; padding: 12px 20px 18px; border-top: 0; }

.library-card-actions {
  position: absolute;
  top: 9px;
  right: 9px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 4px;
}

.library-summary-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: opacity var(--dur) var(--ease-out), background var(--dur) var(--ease-out);
}

.library-summary-btn { opacity: 0; }

.library-summary-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
}

.library-item:hover .library-summary-btn,
.library-item:focus-within .library-summary-btn,
.library-summary-btn:focus-visible { opacity: 1; }

.library-summary-btn:hover,
.library-summary-btn:focus-visible { background: var(--hover-bg); color: var(--ink); }

/* An upload belongs where the document will live. It occupies the first
   grid slot as a quiet, non-interactive card and is replaced by the real
   card as soon as the refreshed catalogue contains it. */
.library-item.library-upload-item,
.library-item.library-upload-item:hover {
  position: relative;
  overflow: hidden;
  cursor: default;
  border-color: var(--border-soft);
  background: var(--surface-inset);
  box-shadow: none;
  transform: none;
}

.library-upload-item .library-name { color: var(--muted); }

.library-upload-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  color: var(--faint);
  font-size: var(--text-xs);
  line-height: 1.25;
}

.library-upload-spinner {
  flex: 0 0 9px;
  width: 9px;
  height: 9px;
  border: 1.5px solid var(--border-card-hover);
  border-top-color: var(--green-deep);
  border-radius: 50%;
  animation: spin 850ms linear infinite;
}

.library-upload-progress {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 2px;
  overflow: hidden;
  background: var(--border-soft);
}

.library-upload-progress span {
  display: block;
  height: 100%;
  border-radius: 0 var(--r-pill) var(--r-pill) 0;
  background: var(--green);
  transition: width .45s var(--ease-out);
}

.library-upload-status.error { color: var(--red); }

.library-upload-error-mark { font-weight: 700; }

.library-upload-done-mark { color: var(--green-deep); font-weight: 700; }

.library-upload-dismiss {
  position: absolute;
  top: 9px;
  right: 9px;
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
}

.library-upload-dismiss:hover { background: var(--hover-bg); color: var(--ink); }

.library-upload-dismiss svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
}

@media (max-width: 640px) {
  .upload-modal-file-item { grid-template-columns: 28px minmax(0, 1fr) 30px; gap: 9px; }
}
/* Knihovna: card grid */
.library-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  color: var(--ink);
  box-shadow: var(--shadow-card);
}

.library-item:hover {
  background: var(--card-hover-bg);
  border-color: var(--border-card-hover);
  box-shadow: 0 2px 8px rgba(27, 30, 22, .055);
  transform: none;
}

@media (max-width: 720px) {
  body[data-mode="library"] .library-toolbar-shell {
      padding-left: var(--rail-toggle-slot);
    }

  /* On a phone these are thumb controls, so they sit below the content.
       The rail toggle remains at the top and the lists reserve just enough
       room for it instead of repeating the current section as a title. */
  .library-area {
      padding-top: 0;
      padding-bottom: 0;
      overflow: hidden;
    }

  .library-wrap {
      height: 100%;
      min-height: 0;
      display: flex;
      flex-direction: column;
    }

  .library-toolbar-shell {
      position: static;
      order: 2;
      flex: 0 0 auto;
      margin: 0 calc(var(--main-pad) * -1);
      padding: 10px var(--main-pad) calc(10px + env(safe-area-inset-bottom, 0px));
      border-top: 1px solid var(--border-soft);
      border-bottom: 0;
      background: rgb(var(--surface-page-rgb) / .96);
      -webkit-backdrop-filter: blur(10px);
      backdrop-filter: blur(10px);
      flex-direction: column;
      flex-wrap: nowrap;
      align-items: stretch;
      gap: 10px;
    }

  /* In the bottom bar the chips ride above the search, so the rail toggle
       still shares a row with the search field. They have that
       row to themselves, so they start where the toggle does, not after
       its slot. */
  .library-cats {
      flex: 0 0 auto;
      margin: 0 0 0 calc(12px + env(safe-area-inset-left, 0px) - var(--rail-toggle-slot));
    }

  .library-list {
      order: 1;
      flex: 1 1 auto;
      min-height: 0;
      overflow-y: auto;
      align-content: start;
      /* Let the native scroll track sit on the phone edge while preserving
         the same inset for the cards themselves. */
      margin-inline: calc(var(--main-pad) * -1);
      padding-inline: var(--main-pad);
      padding-top: 12px;
      padding-bottom: 18px;
    }

  .library-toolbar {
      flex-direction: row;
      flex-wrap: nowrap;
      align-items: center;
      gap: 10px;
      flex: 0 0 auto;
      max-width: none;
      margin-left: 0;
      padding: 0;
    }

  /* Tighter on a phone, where the whole column is the measure. */
  .library-section + .library-section {
      margin-top: 22px;
      padding-top: 22px;
    }

  .library-toolbar-actions {
      width: auto;
      /* Widened for the category dropdown: at the old 328px the search field
         was squeezed to a stub once the filter sat beside it. */
      max-width: none;
      min-width: 0;
      flex: 1 1 auto;
      margin-left: 0;
      display: flex;
      flex-direction: row;
      flex-wrap: nowrap;
      align-items: center;
      gap: 8px;
    }

  /* The wider breakpoint gives the filter a 100% basis, which on a wrapping
       row puts the button on a line of its own. */
  .library-toolbar-actions .library-filter {
      width: auto;
      flex: 1 1 auto;
      max-width: none;
      min-width: 0;
    }

  /* On the desktop row the upload button leads, so the search field and the
       category filter finish against the edge. The phone row wraps the search
       onto its own line, where the button belongs beside the filter instead. */
  .library-toolbar-actions .library-upload-btn {
      flex: 0 0 auto;
      order: 1;
    }
}
/* The "Další" popup in Knihovna: the categories that did not fit the chip
   row. Anchored to its chip, wide enough for the longest category name. */
#library-cat-dd {
  position: relative;
}

#library-cat-menu {
  min-width: 240px;
}

@media (max-width: 720px) {
  /* On a phone it only needs to stay inside the viewport. */
  #library-cat-menu {
      min-width: 0;
      max-width: calc(100vw - 20px);
    }
}
