/* Gallery folders (library_ui.rs) and the black-and-white print preview (bw.rs).
   Tokens come from style.css. The preview is a display and print transform only: the document's
   colours are never touched. */

/* ---------- Folder browser ---------- */

.gc-library { display: flex; flex-direction: column; gap: var(--s-3); margin-bottom: var(--s-4); }

.gc-crumbs ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 2px; }
.gc-crumb-item { display: flex; align-items: center; }
.gc-crumb-item + .gc-crumb-item::before { content: "/"; color: var(--text-3); padding: 0 2px; }
.gc-crumb {
  display: inline-flex; align-items: center; gap: var(--s-2); max-width: 22ch;
  padding: 4px 10px; border: 1px solid transparent; border-radius: var(--r-md);
  background: transparent; color: var(--text-2); font-size: var(--fs-sm); font-weight: 600; cursor: pointer;
}
.gc-crumb span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gc-crumb:hover { background: var(--sunken); color: var(--text); }
.gc-crumb[aria-current="page"] { color: var(--text); background: var(--sunken); cursor: default; }
.gc-crumb:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.gc-crumb.drop-over, .gc-folder.drop-over {
  border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent);
}

.gc-lib-tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.gc-lib-btn { gap: var(--s-2); }
.gc-search { position: relative; display: inline-flex; align-items: center; flex: 0 1 200px; min-width: 140px; }
.gc-search svg { position: absolute; left: 10px; color: var(--text-3); pointer-events: none; }
.gc-search-input { padding: 6px 10px 6px 32px; font-size: var(--fs-sm); }
.gc-lib-notice {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin: 0;
  padding: var(--s-2) var(--s-3); border-radius: var(--r-sm);
  background: var(--accent-soft); color: var(--accent-text); font-size: var(--fs-sm);
}

.gc-folders { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-3); grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); }
.gc-folders:empty { display: none; }
.gc-folder {
  display: flex; align-items: stretch; justify-content: space-between; gap: var(--s-1);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: var(--shadow-1); transition: box-shadow var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
.gc-folder:hover, .gc-folder:focus-within { box-shadow: var(--shadow-2); border-color: var(--border-strong); }
.gc-folder-open {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--s-3); text-align: left;
  padding: var(--s-3); border: 0; border-radius: var(--r-md); background: transparent; color: var(--accent-text); cursor: pointer;
}
.gc-folder-open:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.gc-folder-text { display: flex; flex-direction: column; min-width: 0; }
.gc-folder-name { color: var(--text); font-weight: 600; font-size: var(--fs-md, 1rem); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gc-folder-meta { color: var(--text-3); font-size: var(--fs-xs); }
.gc-folder-actions { display: flex; align-items: center; padding-right: var(--s-1); }
.gc-folder-actions .gc-btn { opacity: 0.55; }
.gc-folder:hover .gc-folder-actions .gc-btn, .gc-folder:focus-within .gc-folder-actions .gc-btn { opacity: 1; }
@media (hover: none) { .gc-folder-actions .gc-btn { opacity: 1; } }
.gc-folder-empty { margin: var(--s-4) 0; color: var(--text-2); }
.gc-print-title { display: none; }

/* card drag handle */
.gc-grip {
  display: inline-grid; place-items: center; flex: 0 0 auto; width: 18px; height: 28px; margin-left: -6px;
  color: var(--text-3); cursor: grab; border-radius: var(--r-sm);
}
.gc-grip:hover { color: var(--text); background: var(--sunken); }
.gc-grip:active { cursor: grabbing; }

/* ---------- Dialogs ---------- */

.lib-modal { max-width: 28rem; }
.lib-dlg-title { margin: 0; font-family: var(--font-display); font-size: var(--fs-xl); font-weight: 600; }
.gc-dlg-sub { margin: 0; color: var(--text-2); }
.gc-dlg-field { display: flex; flex-direction: column; gap: var(--s-1); font-size: var(--fs-sm); font-weight: 600; }
.gc-dlg-error { margin: 0; padding: var(--s-2) var(--s-3); border-radius: var(--r-sm); background: var(--danger-soft); color: var(--danger); font-size: var(--fs-sm); }
.gc-dlg-stack { flex-wrap: wrap; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); }
.gc-dest { border: 1px solid var(--border); border-radius: var(--r-md); margin: 0; padding: var(--s-1); max-height: 40vh; overflow-y: auto; }
.gc-dest-opt { display: flex; align-items: center; gap: var(--s-2); padding: 8px; border-radius: var(--r-sm); cursor: pointer; }
.gc-dest-opt:hover { background: var(--sunken); }
.gc-dest-opt.off { opacity: 0.45; cursor: not-allowed; }
.gc-dest-opt input { accent-color: var(--accent); }

/* ---------- Save in folder (workspace, chat) ---------- */

.lib-row { padding: 0 var(--s-3) var(--s-2); }
.lib-select { display: inline-flex; align-items: center; gap: var(--s-2); font-size: var(--fs-xs); color: var(--text-2); max-width: 100%; }
.lib-select-label { white-space: nowrap; font-weight: 600; }
.lib-select-box { min-width: 0; max-width: 16rem; padding: 5px 8px; font-size: var(--fs-sm); }
.ws-save-folder[hidden] { display: none; }
.ws-menu-field { padding: var(--s-2) var(--s-3); border-top: 1px solid var(--border); display: flex; }
.ws-menu-field .lib-select { flex-direction: column; align-items: stretch; width: 100%; }
@container (max-width: 820px) { .ws-save-folder { display: none; } }

/* ---------- Black-and-white preview toggle ---------- */

.bw-toggle { display: inline-flex; align-items: center; gap: 2px; padding: 3px; background: var(--sunken); border-radius: var(--r-md); }
.bw-icon { margin: 0 var(--s-1) 0 var(--s-2); color: var(--text-3); flex: none; }
.bw-btn {
  padding: 4px 10px; border: 0; border-radius: 8px; background: transparent; cursor: pointer;
  font-size: var(--fs-xs); font-weight: 700; color: var(--text-2); white-space: nowrap;
}
.bw-btn:hover:not([aria-pressed="true"]) { background: var(--border); color: var(--text); }
.bw-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-1); }
.bw-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.ws-bw-note { margin: 0; padding: var(--s-1) var(--s-3); font-size: var(--fs-xs); color: var(--warn-text); background: var(--warn-soft); }
@media (pointer: coarse) {
  .bw-btn, .gc-crumb { min-height: var(--touch); }
  .gc-search-input { min-height: var(--touch); }
}

/* The preview: graph cards, the workspace graph, the prepared print pictures and the variation
   thumbnails are shown the way a black-and-white printer will give them. Filters apply to the
   WebGL canvases too (the filter is on the container). */
html[data-bw="gray"] .graph-card, html[data-bw="gray"] .ws-stage, html[data-bw="gray"] .ws-print,
html[data-bw="gray"] .number-line-card, html[data-bw="gray"] .vt-card { filter: grayscale(1); }
html[data-bw="contrast"] .graph-card, html[data-bw="contrast"] .ws-stage, html[data-bw="contrast"] .ws-print,
html[data-bw="contrast"] .number-line-card, html[data-bw="contrast"] .vt-card { filter: grayscale(1) contrast(1.8); }
/* A white card ground and the plate stay white under the filter; nothing else needs a change. */

/* ---------- Print ---------- */

@media print {
  .gc-library, .gc-grip, .gc-folder-empty { display: none !important; }
  .gc-print-title { display: block; margin: 0 0 12px; font-size: 14pt; color: #000; }
  /* Keep the preview's look on paper: do not let the browser drop backgrounds or re-tint. */
  html[data-bw] body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  /* The print pictures are composed in colour (WebGL cannot print directly); the same filter
     the preview uses turns them gray. Put on the picture itself, so nothing is filtered twice. */
  html[data-bw="gray"] .graph-card, html[data-bw="gray"] .ws-stage, html[data-bw="gray"] .ws-print,
  html[data-bw="gray"] .number-line-card { filter: none; }
  html[data-bw="contrast"] .graph-card, html[data-bw="contrast"] .ws-stage, html[data-bw="contrast"] .ws-print,
  html[data-bw="contrast"] .number-line-card { filter: none; }
  html[data-bw="gray"] .gc-print, html[data-bw="gray"] .ws-print, html[data-bw="gray"] .gc-nl { filter: grayscale(1); }
  html[data-bw="contrast"] .gc-print, html[data-bw="contrast"] .ws-print, html[data-bw="contrast"] .gc-nl { filter: grayscale(1) contrast(1.8); }
  /* Text is black on white either way. */
  html[data-bw] .graph-card { color: #000; border-color: #000; }
}

/* In the chat panel the folder row lines up with the provider pill and the suggestion cards. */
.chat-panel .lib-row { padding: var(--s-3) var(--s-4) 0; }
.chat-panel .lib-select { width: 100%; }
.chat-panel .lib-select-box { flex: 1 1 auto; }
.ws-ask .lib-row { padding: 0 var(--s-1); }

/* Folder tiles: wide enough that the name is not squeezed to an ellipsis by the three actions. */
.gc-folders { grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr)); }
.gc-folder-actions .gc-btn { width: 30px; height: 30px; }
/* Panel bar: count on the left, the tools grouped on the right. */
.gc-panel-bar { justify-content: flex-end; }
.gc-panel-bar .gc-count { margin-right: auto; }
