/* Route library drawer (assets/library_panel.js).  Floats on the right
   under the topbar, same floating-card look as the topbar / chips. */
.library-drawer {
  position: fixed;
  top: 68px;
  right: 12px;
  bottom: 12px;
  width: 400px;
  max-width: calc(100vw - 24px);
  z-index: 1760;                 /* over the stats bar (1750), under popovers */
  display: flex;
  flex-direction: column;
  background: var(--floating-bg, #fff);
  color: var(--fg, #1a1a2e);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 12px;
  box-shadow: var(--shadow-md, 0 4px 10px rgba(15, 23, 42, 0.08));
  backdrop-filter: blur(8px) saturate(1.1);
  font-size: 0.875rem;
  overflow: hidden;
}
.library-drawer:not(.open) { display: none; }

/* Tabs: Routes (the library) / Import / Export (the former menus). */
.lib-tabs {
  display: flex;
  gap: 0.2rem;
  padding: 0 0.8rem;
  border-bottom: 1px solid var(--border, #e5e7eb);
}
.lib-tab {
  border: 0;
  background: none;
  padding: 0.45rem 0.6rem;
  color: var(--fg-muted, #6b7280);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.lib-tab:hover { color: var(--fg, #1a1a2e); }
.lib-tab.active { color: var(--fg, #1a1a2e); border-bottom-color: var(--accent, #00a870); }

.lib-pane { display: none; flex: 1 1 auto; min-height: 0; }
.library-drawer[data-tab="routes"] .lib-pane-routes { display: flex; flex-direction: column; }
.library-drawer[data-tab="import"] .lib-pane-import,
.library-drawer[data-tab="export"] .lib-pane-export {
  display: block;
  overflow-y: auto;
  padding: 0.6rem 0.8rem 0.8rem;
}

.lib-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0.7rem 0.8rem 0.5rem;
  border-bottom: 1px solid var(--border, #e5e7eb);
}
.lib-title { font-weight: 600; font-size: 0.95rem; }
.lib-head { border-bottom: 0; padding-bottom: 0.3rem; }
/* The library button (library_panel.js libChip): what's open, a dot for
   unsaved changes, Save beside it; its menu = the libraries. */
.lib-source { padding: 0 0.8rem 0.6rem; border-bottom: 1px solid var(--border, #e5e7eb); }
.lib-chip-wrap { position: relative; display: flex; gap: 0.4rem; align-items: center; }
.lib-chip { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 0.45rem; text-align: left;
  border: 1px solid var(--border, #d1d5db); background: var(--bg, #fff); color: var(--fg, #1a1a2e); border-radius: 8px;
  padding: 0.35rem 0.6rem; font-size: 0.85rem; }
.lib-chip:hover { border-color: #9ca3af; }
.lib-chip-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-chip-dirty { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: #d97706; }
.lib-chip-caret { color: var(--fg-muted, #6b7280); }
.lib-chip-menu { position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; right: 0; display: flex; flex-direction: column;
  padding: 6px; background: var(--bg, #fff); border: 1px solid var(--border, #e5e7eb); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18); }
.lib-chip-h { font-size: 0.72rem; color: var(--fg-muted, #6b7280); padding: 4px 6px 0; }
.lib-chip-sep { height: 1px; background: var(--border, #e5e7eb); margin: 4px 0; }
.lib-chip-note { font-size: 0.78rem; color: var(--fg-muted, #6b7280); padding: 4px 6px; white-space: normal; }

/* Browse: search + sort, Routes | Sets + In map view, the count with ⋯. */
.lib-filters { display: flex; flex-direction: column; gap: 0.4rem; }
.lib-filter-row { display: flex; align-items: center; gap: 0.5rem; }
.lib-filter-row .lib-search { flex: 1 1 auto; min-width: 0; }
.lib-filter-row .lib-sort { flex: 0 0 auto; width: auto; }
.lib-view { display: inline-flex; background: var(--panel-bg, #f1f3f5); border-radius: 8px; padding: 2px; }
.lib-view-btn { border: 0; background: transparent; border-radius: 6px; padding: 3px 10px; font-size: 0.82rem; color: var(--fg, #1a1a2e); }
.lib-view-btn.on { background: var(--bg, #fff); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); font-weight: 600; }
.lib-view-n { color: var(--fg-muted, #6b7280); font-weight: 400; }
.lib-inview-wrap { margin: 0; font-size: 0.8rem; white-space: nowrap; }
/* Darkly's close cross is white: dark on the light drawer. */
.library-drawer .btn-close { filter: invert(1) grayscale(1); opacity: 0.55; }
.library-drawer .btn-close:hover { opacity: 0.85; }
.lib-count-row { display: flex; align-items: center; gap: 0.4rem; }
.lib-count-row .lib-count { flex: 1 1 auto; }
.lib-list-more-wrap, .lib-prev-more-wrap { position: relative; }
.lib-list-more, .lib-prev-more { padding: 0 0.45rem; line-height: 1.5; }
.lib-set-ico { font-size: 1.3rem; color: #2b6cff; width: 40px; text-align: center; flex: 0 0 auto; }
.lib-set-routes { margin: 0.4rem 0 0; padding-left: 1.1rem; font-size: 0.82rem; color: var(--fg, #1a1a2e); }
.lib-preview-head .lib-preview-name { flex: 1 1 auto; }
.lib-preview-actions > .btn { flex: 1 1 auto; }

/* Add / Save & share: one card per job. */
.lib-card { border: 1px solid var(--border, #e5e7eb); border-radius: 10px; padding: 0.7rem; margin-bottom: 0.7rem;
  display: flex; flex-direction: column; gap: 0.5rem; }
.library-drawer .lib-pane .lib-card-title { font-weight: 600; color: var(--fg, #1a1a2e) !important; font-size: 0.9rem; margin: 0; }
.lib-card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.4rem; }
.lib-card-links { display: flex; gap: 1rem; flex-wrap: wrap; }
.library-drawer .lib-pane .lib-card-check { display: flex; align-items: center; gap: 0.4rem; font-size: 0.82rem; margin: 0; }
.lib-addto { display: flex; flex-direction: column; gap: 0.4rem; }
.library-drawer .lib-pane .lib-addto-opt { display: flex; align-items: flex-start; gap: 0.55rem; border: 1.5px solid var(--border, #e5e7eb);
  border-radius: 10px; padding: 0.5rem 0.6rem; cursor: pointer; color: var(--fg, #1a1a2e) !important; margin: 0; }
.library-drawer .lib-pane .lib-addto-opt.on { border-color: var(--accent, #00a870); background: var(--accent-soft, #e6f6f0); }
.lib-addto-opt input { margin-top: 0.2rem; accent-color: var(--accent, #00a870); }
.lib-addto-opt span { display: flex; flex-direction: column; gap: 2px; }
.lib-addto-opt b { font-size: 0.85rem; }
.lib-addto-opt small { color: var(--fg-muted, #6b7280); font-size: 0.78rem; }
.lib-save-slot .lib-save-form { border: 0; padding: 0; background: transparent; }
.lib-save-note { font-size: 0.82rem; color: #0f7a4f; margin-bottom: 0.3rem; }

.lib-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0.6rem 0.8rem 0.8rem;
  gap: 0.5rem;
}
.lib-intro { color: var(--fg-muted, #6b7280); }
.lib-src-menu { display: flex; flex-direction: column; }
.lib-busy { color: var(--fg-muted, #6b7280); font-style: italic; }

/* Status line (save mode, unsaved changes) above an even grid of buttons + ⋯. */
.lib-toolbar { display: flex; flex-direction: column; gap: 0.35rem; }
.lib-status { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; min-height: 1.1rem; }
.lib-toolbar-row { display: flex; align-items: flex-start; gap: 0.4rem; }
.lib-toolbar-btns { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; }
.lib-toolbar-btns .btn { width: 100%; white-space: nowrap; }
.lib-dirty { color: var(--warn, #f6a821); font-size: 0.78rem; }

.lib-count { color: var(--fg-muted, #6b7280); font-size: 0.75rem; }

.lib-list {
  flex: 1 1 auto;
  min-height: 80px;
  overflow-y: auto;
  overflow-x: hidden;
  margin: 0 -0.4rem;
}
.lib-empty { color: var(--fg-muted, #6b7280); padding: 0.6rem 0.4rem; }
.lib-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.4rem;
  border-radius: 8px;
  cursor: pointer;
}
.lib-row:hover, .lib-row:focus-visible { background: var(--hover-bg, #eef1f4); outline: none; }
.lib-row.selected { background: var(--accent-soft, rgba(0, 168, 112, 0.1)); }
.lib-row-text { min-width: 0; flex: 1 1 auto; }
.lib-row-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-row-meta { color: var(--fg-muted, #6b7280); font-size: 0.75rem;
                white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-row-editable { color: var(--accent, #00a870); }

.lib-shape {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  border-radius: 6px;
  background: var(--panel-bg, #f7f7f9);
}
.lib-shape polyline {
  fill: none;
  stroke: #7c3aed;
  stroke-width: 1.6;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.lib-preview {
  flex: 0 0 auto;
  border-top: 1px solid var(--border, #e5e7eb);
  padding-top: 0.6rem;
}
.lib-preview-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.lib-preview-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0.3rem; margin: 0.5rem 0; }
.lib-stat-v { font-weight: 600; }
.lib-stat-l { color: var(--fg-muted, #6b7280); font-size: 0.72rem; }
.lib-profile { width: 100%; height: 56px; display: block; }
.lib-profile polygon { fill: rgba(124, 58, 237, 0.18); stroke: #7c3aed; stroke-width: 1.2;
                       vector-effect: non-scaling-stroke; }
.lib-noele { color: var(--fg-muted, #6b7280); font-size: 0.78rem; }
.lib-preview-file { color: var(--fg-subtle, #9ca3af); font-size: 0.72rem; margin-top: 0.3rem;
                    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-preview-actions { display: flex; gap: 0.4rem; margin-top: 0.5rem; }
.lib-preview-actions .lib-load { flex: 1 1 auto; }

.lib-save-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.6rem;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
  background: var(--panel-bg, #f7f7f9);
}
.lib-save-title { font-weight: 600; }
.lib-save-actions { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.lib-save-conflict { color: var(--danger, #e04f4f); font-size: 0.78rem; flex-basis: 100%; }
.library-drawer .btn-primary {
  background: var(--accent, #00a870);
  border-color: var(--accent, #00a870);
}
.library-drawer .btn-primary:hover:not(:disabled) {
  background: var(--accent-hover, #00915f);
  border-color: var(--accent-hover, #00915f);
}

/* Former menu content inside the Import / Export tabs. */
.library-drawer .lib-pane label,
.library-drawer .lib-pane .text-muted { color: var(--fg-muted, #6b7280) !important; }
.library-drawer .lib-pane .route-name-input { width: 100%; }
.lib-readonly { color: var(--fg-muted, #6b7280); font-size: 0.78rem; }

/* ⋯ menu (whole-library actions) and the copy-to panel. */
.lib-more-wrap { position: relative; }
.lib-more-menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 10; min-width: 220px;
  background: var(--bg, #fff); border: 1px solid var(--border, #ddd); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15); padding: 4px; display: flex; flex-direction: column;
}
.lib-copy { border: 1px solid var(--border, #ddd); border-radius: 8px; padding: 8px; margin: 6px 0; }
.lib-copy-title { font-weight: 600; margin-bottom: 6px; }
.lib-copy-bar { height: 8px; border-radius: 4px; background: var(--border, #e5e7eb); overflow: hidden; }
.lib-copy-bar-fill { height: 100%; background: var(--accent, #00a870); transition: width 0.2s; }
.lib-copy-count { margin-top: 6px; font-size: 0.85em; color: var(--fg-muted, #6b7280); font-variant-numeric: tabular-nums; }
.lib-del { border-color: rgba(220, 53, 69, 0.45); }
.lib-del-note { font-size: 0.85em; color: var(--fg-muted, #6b7280); margin-bottom: 6px; }
.lib-del-type { margin-bottom: 6px; }
.lib-del-fill { background: #dc3545; }
.lib-copy-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.lib-notice { display: flex; align-items: center; gap: 0.5rem; margin: 6px 0; padding: 6px 8px;
  border-radius: 8px; background: var(--accent-soft, #e6f6f0); font-size: 0.9em; }
.lib-notice span { flex: 1 1 auto; }

/* Saves by itself (folder, browser, Drive) or only on Save file (a library file). */
.lib-savemode { display: inline-flex; align-items: center; font-size: 0.78rem; color: var(--fg-muted, #6b7280); white-space: nowrap; }
.lib-savemode.manual { color: var(--warn, #b7791f); }

/* Several routes open: pick routes to open alongside the planned one. */
.lib-row .lib-pick { flex: 0 0 auto; margin: 0 2px 0 0; }
.lib-pickbar { display: flex; align-items: center; gap: 8px; padding: 8px 2px; border-top: 1px solid var(--border, #e5e7eb);
  position: sticky; bottom: 0; background: var(--floating-bg, #fff); }
.lib-pick-count { font-size: 12px; color: var(--fg-muted, #6b7280); }

/* The libraries, in the library button's menu. */
.lib-libs-row { display: flex; align-items: center; gap: 8px; padding: 6px; font-size: 13px; }
.lib-libs-all { font-weight: 600; border-bottom: 1px solid var(--border, #e5e7eb); }
.lib-libs-name { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }
.lib-libs-name small { color: var(--fg-muted, #6b7280); }
.lib-libs-count { color: var(--fg-muted, #6b7280); font-size: 12px; }
.lib-libs-close { padding: 0 4px; }


.lib-set-text { flex: 1 1 auto; min-width: 0; }
.lib-set-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Tags (library_tags.js): filter chips over the list, the selected route's tags. */
.lib-tag-filter, .lib-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.lib-tags { margin: 0.35rem 0 0; }
.lib-tag { display: inline-flex; align-items: center; gap: 3px; border: 1px solid var(--border, #d1d5db); background: var(--bg, #fff);
  color: var(--fg, #1a1a2e); border-radius: 999px; padding: 1px 9px; font-size: 0.76rem; line-height: 1.5; }
button.lib-tag:hover { border-color: #9ca3af; }
.lib-tag.on { background: #eaf6ee; border-color: var(--accent, #00a870); font-weight: 600; }
.lib-tag-n { color: var(--fg-muted, #6b7280); font-weight: 400; }
.lib-tag.folder { background: var(--panel-bg, #f3f4f6); }
.lib-tag.suggest { border-style: dashed; color: #0f7a4f; }
.lib-tag.add { color: var(--fg-muted, #6b7280); }
.lib-tag-x { border: 0; background: transparent; padding: 0 0 0 2px; line-height: 1; color: var(--fg-muted, #6b7280); }

/* Save to library: the folder box's list (app-styled, not the browser's datalist). */
.lib-folder-combo { position: relative; }
.lib-folder-menu { position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; right: 0; max-height: 240px; overflow-y: auto;
  padding: 4px; background: var(--bg, #fff); border: 1px solid var(--border, #e5e7eb); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18); }
.lib-folder-opt { display: flex; align-items: center; padding: 5px 8px; border-radius: 6px; font-size: 0.85rem; cursor: pointer;
  color: var(--fg, #1a1a2e); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-folder-opt i { color: var(--fg-muted, #6b7280); }
.lib-folder-opt:hover, .lib-folder-opt.on { background: #eaf6ee; }
.lib-save-tags { display: flex; flex-direction: column; gap: 4px; }
.lib-tag.suggested { border-style: dashed; border-color: var(--accent, #00a870); color: #0f7a4f; }
.lib-more-mark { height: 1px; }
