/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 33, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-backdrop.hidden { display: none; }

.modal {
  background: white;
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  width: 460px;
  max-width: 92vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-sm { width: 360px; padding: 20px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-header h2 { font-size: 15px; margin: 0; }
.modal-header-actions { display: flex; align-items: center; gap: 2px; }

.icon-btn {
  width: 28px; height: 28px;
  border: none; background: transparent;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--ink-soft);
}
.icon-btn:hover { background: #f2f4f7; color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }

/* Wider than the base .modal — a folder tree + breadcrumb needs a bit more
   horizontal room than the plain flat list this used to be. */
.load-modal { width: 560px; }

.load-modal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.load-modal-breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
  font-size: 13px;
}
.load-modal-breadcrumb-sep { color: var(--ink-soft); padding: 0 3px; }
.load-modal-breadcrumb-segment {
  border: none;
  background: transparent;
  padding: 3px 6px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.load-modal-breadcrumb-segment:last-child { color: var(--ink); font-weight: 600; }
.load-modal-breadcrumb-segment:hover { background: #f2f4f7; }
/* A map dragged over a breadcrumb segment can drop there to jump it
   straight up to that ancestor folder, same as dropping on a folder row
   below — this is just the hover feedback for that. */
.load-modal-breadcrumb-segment.drag-over { background: var(--accent-soft); color: var(--accent); }

.map-list { overflow-y: auto; padding: 8px; }
.map-list-empty { padding: 30px 10px; text-align: center; color: var(--ink-soft); font-size: 13px; }

.folder-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  border: 1.5px solid transparent;
}
.folder-row:hover { background: #f4f6f9; }
.folder-row.drag-over { background: var(--accent-soft); border-color: var(--accent); }
.folder-row-icon { flex-shrink: 0; color: var(--accent); display: flex; }
.folder-row-icon svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.folder-row-name { font-size: 13.5px; font-weight: 500; }

.map-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.map-row:hover { background: #f4f6f9; }
/* Dragging feedback on the row being picked up — the actual drop targets
   (folder rows/breadcrumb segments) get their own .drag-over instead. */
.map-row.dragging { opacity: 0.5; }
.map-row-name { font-size: 13.5px; font-weight: 500; }
.map-row-meta { font-size: 11.5px; color: var(--ink-soft); margin-top: 2px; }
.map-row-delete, .map-row-copy, .map-row-move {
  width: 28px; height: 28px; border: none; background: transparent; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; color: var(--ink-soft); cursor: pointer; flex-shrink: 0;
}
.map-row-delete:hover { background: #fdeaea; color: var(--danger); }
.map-row-delete svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.map-row-copy:hover, .map-row-move:hover { background: var(--accent-soft); color: var(--accent); }
.map-row-copy svg, .map-row-move svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.8; }

.confirm-message { font-size: 13.5px; margin: 0 0 16px; color: var(--ink); }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Shared by the PDF-link and web-link dialogs (pdf-link.js / web-link.js) —
   a labeled text/number field in a small one-off form dialog. */
.link-dialog-field {
  display: block;
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-bottom: 12px;
}
.link-dialog-input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 7px 9px;
  border: 1px solid var(--node-border);
  border-radius: 7px;
  font-size: 13.5px;
  color: var(--ink);
}

/* pdf-link.js's cloud-mode file picker — a small folder browser (breadcrumb
   + list) standing in for a flat <select>, since the shared Drive folder
   can itself hold subfolders. Reuses .load-modal-breadcrumb's own styling
   for the breadcrumb row (same look, smaller container). */
.drive-picker {
  margin-top: 5px;
  border: 1px solid var(--node-border);
  border-radius: 7px;
  overflow: hidden;
}
.drive-picker .load-modal-breadcrumb {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  background: #f9fafb;
}
.drive-picker-list { max-height: 160px; overflow-y: auto; padding: 4px; }
.drive-picker-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
  text-align: left;
}
.drive-picker-row:hover { background: #f4f6f9; }
.drive-picker-row.selected { background: var(--accent-soft); color: var(--accent); }
.drive-picker-row-icon { flex-shrink: 0; display: flex; color: var(--ink-soft); }
[data-drive-folder] .drive-picker-row-icon { color: var(--accent); }
.drive-picker-row-icon svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.drive-picker-row-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drive-picker-selected {
  padding: 6px 8px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-soft);
  background: #f9fafb;
}

/* The manage-links dialogs' list view (pdf-link.js / web-link.js) — every
   currently-attached link as its own row, each with its own Open/Edit/
   Remove, so several can live on one bubble without a separate dialog per
   link. */
.link-list { max-height: 220px; overflow-y: auto; margin-bottom: 10px; }
.link-list.hidden, .link-form.hidden, .confirm-actions.hidden, .link-dialog-field.hidden { display: none; }
.link-list-empty { font-size: 12.5px; color: var(--ink-soft); padding: 8px 2px; }
.link-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 2px;
  border-bottom: 1px solid var(--line);
}
.link-row:last-child { border-bottom: none; }
.link-row-label {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.link-row-btn {
  flex-shrink: 0;
  padding: 4px 7px;
  border: 1px solid var(--node-border);
  border-radius: 6px;
  background: var(--panel);
  font-size: 11.5px;
  color: var(--ink);
  cursor: pointer;
}
.link-row-btn:hover { background: var(--accent-soft); border-color: var(--accent); }

/* ---------- "Manage images" dialog (image-manage.js) ---------- */
.image-manage-modal { padding: 0; }
.image-manage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
  padding: 16px 18px;
  overflow-y: auto;
}
.image-manage-item { position: relative; }
.image-manage-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid var(--node-border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: #fafbfc;
}
.image-manage-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-manage-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid white;
  background: var(--danger);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.image-manage-remove svg { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 2.5; }
.image-manage-remove:hover { background: #c93d41; }
.image-manage-edit {
  position: absolute;
  top: -6px;
  left: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid white;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.image-manage-edit svg { width: 11px; height: 11px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.image-manage-edit:hover { background: #2f5fe0; }
.image-manage-caption {
  margin-top: 4px;
  font-size: 11px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Full-resolution image lightbox ---------- */
.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(15, 17, 23, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.image-lightbox.hidden { display: none; }
.image-lightbox img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  border-radius: 4px;
  box-shadow: var(--shadow-md);
  cursor: default;
}
.image-lightbox-close {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.image-lightbox-close:hover { background: rgba(255, 255, 255, 0.22); }
.image-lightbox-close svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }

/* ---------- Full-size table lightbox (read-only; editing happens in the
   separate table-editor popup window, not here) ---------- */
.table-lightbox {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(15, 17, 23, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.table-lightbox.hidden { display: none; }
.table-lightbox-inner {
  max-width: 100%;
  max-height: 100%;
  overflow: auto;
  background: white;
  border-radius: 8px;
  padding: 20px;
  box-shadow: var(--shadow-md);
  cursor: default;
}
.table-lightbox-inner table { font-size: 14px; }
.table-lightbox-close {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.table-lightbox-close:hover { background: rgba(255, 255, 255, 0.22); }
.table-lightbox-close svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  z-index: 200;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.hidden { opacity: 0; transform: translate(-50%, 8px); pointer-events: none; }
