/* asset-library.css — right-side asset library panel
 *
 * Mounts as a flex child of hermes' .layout (between .main and the
 * native .rightpanel), so it reflows the chat area instead of overlaying.
 * When the asset library is on, the hermes workspace panel is force-
 * hidden via the `body.al-active` class set by the bootstrap script.
 *
 * Drag the left edge to resize. Click the ✕ to collapse to a 36px rail
 * pinned to the right; click the rail to re-expand to last width.
 */

/* ---- Hide hermes' native workspace panel + its edge toggle when our
        asset library is mounted (we own the right slot). -------------- */
body.al-active .rightpanel,
body.al-active .workspace-panel-edge-toggle {
  display: none !important;
}

/* ---- Panel container ------------------------------------------------- */
#asset-library-mount {
  /* When parented under .layout we behave as a flex child. */
  flex: 0 0 var(--al-width, 340px);
  width: var(--al-width, 340px);
  min-width: 200px;
  max-width: 720px;
  background: var(--sidebar, var(--surface, #fafafa));
  border-left: 1px solid var(--border, #e5e5e5);
  display: flex;
  flex-direction: column;
  position: relative;
  font-size: 13px;
  overflow: hidden;
  transition: flex-basis 0.18s ease, width 0.18s ease;
}
#asset-library-mount.al-collapsed {
  flex: 0 0 36px;
  width: 36px;
  min-width: 36px;
}
#asset-library-mount.al-resizing {
  transition: none;
  user-select: none;
}

/* ---- Drag-to-resize handle ------------------------------------------- */
.al-resize-handle {
  position: absolute;
  left: -3px;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 2;
  background: transparent;
}
.al-resize-handle:hover,
#asset-library-mount.al-resizing .al-resize-handle {
  background: var(--accent, #4a7);
  opacity: 0.4;
}
#asset-library-mount.al-collapsed .al-resize-handle { display: none; }

/* ---- Collapsed rail -------------------------------------------------- */
.al-rail {
  width: 36px;
  height: 100%;
  background: var(--sidebar, #fafafa);
  border: 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 16px 0;
  gap: 12px;
  font-size: 14px;
  color: var(--muted, #666);
  writing-mode: vertical-rl;
  text-orientation: mixed;
}
.al-rail:hover {
  background: var(--hover-bg, #f0f0f0);
  color: var(--text, #111);
}
.al-rail-badge {
  writing-mode: horizontal-tb;
  background: var(--accent, #4a7);
  color: #fff;
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 8px;
  min-width: 16px;
  text-align: center;
}

/* ---- Header --------------------------------------------------------- */
.al-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border, #e5e5e5);
  background: var(--surface, #fff);
  flex-shrink: 0;
}
.al-title { font-weight: 600; font-size: 14px; color: var(--text, #111); }

/* ---- Segmented tabs -------------------------------------------------- */
.al-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border, #e5e5e5);
  background: var(--surface, #fff);
  flex-shrink: 0;
}
.al-tab {
  flex: 1;
  padding: 6px 4px;
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  color: var(--muted, #666);
  transition: color 0.12s, background-color 0.12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.al-tab:hover { color: var(--text, #111); background: var(--hover-bg, #f0f0f0); }
.al-tab.is-active {
  color: var(--text, #111);
  background: var(--accent-bg, #e9f4ec);
  font-weight: 500;
}
.al-tab.al-add { flex: 0 0 30px; font-weight: 600; font-size: 16px; padding: 4px; }

/* ---- Body ----------------------------------------------------------- */
.al-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px;
  min-height: 0;
}
.al-body::-webkit-scrollbar { width: 6px; }
.al-body::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }
.al-body::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }

.al-skel {
  height: 56px;
  margin-bottom: 6px;
  background: linear-gradient(90deg, var(--hover-bg, #eee) 0%, var(--surface, #f8f8f8) 50%, var(--hover-bg, #eee) 100%);
  background-size: 200% 100%;
  border-radius: 6px;
  animation: al-shimmer 1.4s linear infinite;
}
@keyframes al-shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

.al-empty {
  padding: 36px 18px;
  color: var(--muted, #666);
  text-align: center;
  font-size: 12px;
  line-height: 1.7;
}

.al-error {
  padding: 10px 12px;
  color: #b00;
  background: #fee;
  border: 1px solid #fcc;
  border-radius: 6px;
  font-size: 12px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* ---- Item rows ------------------------------------------------------ */
.al-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background-color 0.1s;
}
.al-item:hover { background: var(--hover-bg, #f0f0f0); }
.al-item.is-checked { background: var(--accent-bg, #e9f4ec); }
.al-cb {
  width: 16px; height: 16px; margin-top: 4px;
  flex-shrink: 0; cursor: pointer;
}
.al-thumb {
  width: 40px; height: 40px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  background: linear-gradient(135deg, var(--hover-bg, #e0e0e0), var(--surface, #f5f5f5));
  flex-shrink: 0;
}
.al-thumb-script   { background: linear-gradient(135deg, #d1e7d1, #f5fff5); }
.al-thumb-media    { background: linear-gradient(135deg, #d1d1e7, #f5f5ff); }
.al-thumb-template { background: linear-gradient(135deg, #e7d1c1, #fff5e5); }
html.dark .al-thumb-script   { background: linear-gradient(135deg, #2a4a2a, #1a3a1a); }
html.dark .al-thumb-media    { background: linear-gradient(135deg, #2a2a4a, #1a1a3a); }
html.dark .al-thumb-template { background: linear-gradient(135deg, #4a3a2a, #3a2a1a); }

.al-item-body { flex: 1; min-width: 0; }
.al-item-title {
  font-weight: 500;
  font-size: 13px;
  color: var(--text, #111);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.al-item-meta {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted, #888);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.al-item-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}
.al-item:hover .al-item-actions,
.al-item:focus-within .al-item-actions { opacity: 1; }
/* always-visible variant — used by the new layout so the delete button
   stays discoverable while the row body is the preview target. */
.al-item-actions.al-actions-visible { opacity: 1; }

/* ---- Upload-in-progress ghost row ---------------------------------- */
.al-item-ghost {
  background: var(--hover-bg, #f5f5f5);
  opacity: 0.85;
  cursor: default;
}
.al-item-ghost:hover { background: var(--hover-bg, #f5f5f5); }
.al-item-ghost.is-error { background: #fef0f0; opacity: 1; }
.al-progress-track {
  margin-top: 6px;
  width: 100%;
  height: 4px;
  background: rgba(0,0,0,0.08);
  border-radius: 2px;
  overflow: hidden;
}
.al-progress-bar {
  height: 100%;
  background: var(--accent, #4a7);
  transition: width 0.2s ease;
}
.al-progress-bar.is-error { background: #c33; }

/* ---- Preview modal ------------------------------------------------- */
.al-preview-body {
  flex: 1;
  overflow: auto;
  padding: 16px;
  background: var(--hover-bg, #fafafa);
}
.al-preview-fullwidth {
  background: var(--surface, #fff);
  padding: 16px;
  border-radius: 6px;
  max-height: 100%;
  overflow-y: auto;
}
.al-preview-media {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 200px;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
}
.al-preview-media video,
.al-preview-media audio,
.al-preview-media img {
  max-width: 100%;
  max-height: 60vh;
  display: block;
}
.al-preview-media audio { width: 100%; min-height: 60px; background: var(--surface, #fff); }
.al-preview-meta {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted, #666);
  text-align: center;
}
.al-preview-json {
  margin-top: 12px;
  background: var(--hover-bg, #f5f5f5);
  padding: 10px;
  border-radius: 4px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  overflow: auto;
  white-space: pre;
}

.al-icon {
  width: 24px; height: 24px;
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 4px;
  font-size: 13px;
  color: var(--muted, #666);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.al-icon:hover { background: var(--hover-strong, #e0e0e0); color: var(--text, #111); }
.al-icon-danger:hover { background: #fee; color: #b00; }

/* ---- Bottom toolbar ------------------------------------------------- */
.al-toolbar {
  padding: 8px 12px;
  border-top: 1px solid var(--border, #e5e5e5);
  background: var(--surface, #fff);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  flex-shrink: 0;
}
.al-toolbar-count { flex: 1; color: var(--muted, #666); }
.al-btn-link {
  background: transparent;
  border: 0;
  cursor: pointer;
  color: var(--accent, #4a7);
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 3px;
}
.al-btn-link:hover:not(:disabled) { background: var(--hover-bg, #f0f0f0); }
.al-btn-link:disabled { color: var(--muted, #bbb); cursor: default; }
.al-hint  { color: #c80; font-size: 11px; }
.al-warn  { color: #c00; font-size: 11px; font-weight: 600; }

/* ---- Markdown editor modal ------------------------------------------ */
.al-modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.al-modal {
  background: var(--surface, #fff);
  color: var(--text, #111);
  width: min(900px, 92vw);
  height: min(640px, 90vh);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 48px rgba(0,0,0,0.3);
}
.al-modal-wide {
  width: min(1100px, 95vw);
  height: min(760px, 92vh);
}
.al-md-grid-single {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.al-vditor-mount {
  flex: 1;
  min-height: 300px;
}
.al-vditor-mount .vditor {
  height: 100% !important;
  border: 0 !important;
  border-radius: 0 !important;
}
.al-vditor-loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted, #888);
  font-size: 13px;
}
.al-modal-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border, #e5e5e5);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.al-modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border, #e5e5e5);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.al-md-title {
  padding: 10px 16px;
  border: 0;
  border-bottom: 1px solid var(--border, #e5e5e5);
  font-size: 15px;
  font-weight: 600;
  background: var(--surface, #fff);
  color: var(--text, #111);
}
.al-md-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
}
.al-md-editor {
  border: 0;
  border-right: 1px solid var(--border, #e5e5e5);
  padding: 12px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  resize: none;
  outline: none;
  background: var(--surface, #fff);
  color: var(--text, #111);
}
.al-md-preview {
  padding: 12px 16px;
  overflow-y: auto;
  font-size: 13px;
  background: var(--hover-bg, #fafafa);
  color: var(--text, #111);
  white-space: pre-wrap;
}
/* When the preview pane holds rendered HTML (from window.renderMd),
   drop the pre-wrap so <h1>/<p>/<ul>/<code> etc render natively. */
.al-md-rendered { white-space: normal; }
.al-md-rendered h1,
.al-md-rendered h2,
.al-md-rendered h3,
.al-md-rendered h4 {
  margin: 1em 0 0.5em;
  font-weight: 600;
  line-height: 1.3;
}
.al-md-rendered h1 { font-size: 22px; }
.al-md-rendered h2 { font-size: 18px; }
.al-md-rendered h3 { font-size: 16px; }
.al-md-rendered h4 { font-size: 14px; }
.al-md-rendered p,
.al-md-rendered ul,
.al-md-rendered ol,
.al-md-rendered blockquote {
  margin: 0.6em 0;
  line-height: 1.6;
}
.al-md-rendered ul,
.al-md-rendered ol { padding-left: 1.4em; }
.al-md-rendered li { margin: 0.25em 0; }
.al-md-rendered blockquote {
  border-left: 3px solid var(--accent, #4a7);
  padding-left: 12px;
  color: var(--muted, #666);
}
.al-md-rendered code {
  background: var(--hover-strong, #efefef);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, monospace;
}
.al-md-rendered pre {
  background: var(--hover-strong, #efefef);
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0.6em 0;
}
.al-md-rendered pre code {
  background: transparent;
  padding: 0;
  font-size: 12px;
}
.al-md-rendered a {
  color: var(--accent, #4a7);
  text-decoration: underline;
}
.al-md-rendered img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}
.al-md-rendered table {
  border-collapse: collapse;
  margin: 0.6em 0;
}
.al-md-rendered th,
.al-md-rendered td {
  border: 1px solid var(--border, #ddd);
  padding: 4px 10px;
}
.al-md-rendered hr {
  border: 0;
  border-top: 1px solid var(--border, #e5e5e5);
  margin: 1em 0;
}
.al-btn {
  padding: 6px 14px;
  border-radius: 4px;
  border: 1px solid var(--border, #ddd);
  background: var(--surface, #fff);
  color: var(--text, #111);
  cursor: pointer;
  font-size: 13px;
}
.al-btn-primary {
  background: var(--accent, #4a7);
  color: #fff;
  border-color: transparent;
}
.al-btn-primary:hover:not(:disabled) { background: var(--accent-hover, #3a6); }
.al-btn-secondary:hover { background: var(--hover-bg, #f0f0f0); }
.al-btn:disabled { opacity: 0.6; cursor: default; }

/* ---- Drag-drop file upload hover state ------------------------------ */
#asset-library-mount.al-drop-hover {
  outline: 2px dashed var(--accent, #4a7);
  outline-offset: -6px;
  background: color-mix(in srgb, var(--accent, #4a7) 8%, var(--surface, #fff));
  position: relative;
}
#asset-library-mount.al-drop-hover::after {
  content: '松开鼠标上传到媒体库';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  padding: 12px 20px;
  border-radius: 8px;
  background: var(--accent, #4a7);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  z-index: 10;
}

/* ---- Narrow viewport — overlay on top of chat ----------------------- */
@media (max-width: 1100px) {
  #asset-library-mount:not(.al-collapsed) {
    position: fixed;
    top: 56px; right: 0; bottom: 0;
    width: min(360px, 90vw);
    z-index: 90;
    box-shadow: -2px 0 12px rgba(0,0,0,0.18);
  }
}
