/* Workspace components — shared classes used by vault_browser,
   paper_detail, and any future page that needs a tabbed editor /
   file tree / collapsible side panels / drag-resizable splits.

   Convention: light theme by default. Pages that want a dark editor
   shell (paper_detail's center column, vault_browser's editor frame)
   wrap the tab system in a `.ws-dark` class which flips the colors
   via CSS custom properties.

   Owned by app/static/css/workspace.css; loaded from base.html so
   every page gets it without per-template <link>. Duplicating any
   of these rules in a template is wrong — change them here. */


/* ── Score badge (papers list / detail / inbox) ───────────────── */
/* Existing rule from app.css if any takes precedence on conflict;
   keep this one as the single source of truth going forward.   */
.score-badge {
  display: inline-block;
  min-width: 30px;
  padding: 2px 8px;
  border-radius: 4px;
  text-align: center;
  font-weight: 600;
  font-size: 13px;
  font-family: monospace;
  flex-shrink: 0;
}
.score-badge.star { background: #fef3c7; color: #92400e; border: 1px solid #f59e0b; }
.score-badge.high { background: #dcfce7; color: #15803d; }
.score-badge.mid  { background: #e5e7eb; color: #374151; }
.score-badge.none { background: #f3f4f6; color: #9ca3af; }


/* ── State chip (paper state, future use elsewhere) ──────────── */
.state-chip {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-family: monospace;
}
.state-chip.state-new        { background: #e5e7eb; color: #374151; }
.state-chip.state-summarized { background: #dbeafe; color: #1e40af; }
.state-chip.state-scored     { background: #dcfce7; color: #15803d; }
.state-chip.state-archived   { background: #f3f4f6; color: #6b7280; }


/* ── Tight buttons (compact toolbar usage) ────────────────────── */
.btn-tight { padding: 3px 9px; font-size: 12px; }
.btn-tight.active { box-shadow: inset 0 0 0 2px currentColor; }


/* ── Workspace panel (head + body + collapse) ─────────────────── */
.ws-panel {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
.ws-panel-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}
.ws-panel-head strong { font-size: 13px; }
.ws-panel-head .ws-btn,
.ws-panel-head .ws-collapse {
  background: transparent;
  border: 1px solid #d1d5db;
  padding: 2px 7px;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  color: #4b5563;
}
.ws-panel-head .ws-btn:hover,
.ws-panel-head .ws-collapse:hover { background: #e5e7eb; color: #111; }
.ws-panel-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.ws-panel-body.scrollable {
  overflow-y: auto;
  padding: 12px 14px;
}


/* ── Tab system (multi-tab editor / PDF viewer) ───────────────── */
/* Default light. Use .ws-dark wrapper for dark-shell editor. */
.ws-tabs {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.tab-bar {
  display: flex;
  align-items: flex-end;
  background: var(--ws-bar-bg, #f3f4f6);
  border-bottom: 1px solid var(--ws-bar-border, #e5e7eb);
  padding: 4px 4px 0;
  min-height: 32px;
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
}
.tab-bar::-webkit-scrollbar { height: 4px; }
.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px 6px 10px;
  min-width: 0;
  max-width: 220px;
  cursor: pointer;
  background: var(--ws-tab-bg, #e5e7eb);
  color: var(--ws-tab-fg, #4b5563);
  border: 1px solid var(--ws-tab-border, #e5e7eb);
  border-bottom: none;
  border-radius: 5px 5px 0 0;
  font: inherit;
  font-size: 12px;
  white-space: nowrap;
  margin-right: 2px;
  flex-shrink: 0;
}
.tab:hover {
  background: var(--ws-tab-hover-bg, #d5d7db);
  color: var(--ws-tab-hover-fg, #1f2937);
}
.tab.active {
  background: var(--ws-tab-active-bg, #fff);
  color: var(--ws-tab-active-fg, #111);
  border-color: var(--ws-tab-active-border, #e5e7eb);
  margin-bottom: -1px;
}
.tab-name {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
  max-width: 180px;
}
.tab-name .tab-dir {
  color: var(--ws-tab-dir, #9ca3af);
  font-size: 11px;
}
.tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  font-size: 13px;
  color: var(--ws-tab-close, #6b7280);
  line-height: 1;
  flex-shrink: 0;
}
.tab:hover .tab-close { color: var(--ws-tab-close-hover, #374151); }
.tab-close:hover { background: #b91c1c; color: white; }
.tab-add {
  border: 1px dashed transparent;
  background: transparent;
  padding: 4px 10px 5px;
  cursor: pointer;
  color: var(--ws-tab-add, #6b7280);
  font: inherit;
  font-size: 14px;
  margin-bottom: 0;
  flex-shrink: 0;
}
.tab-add:hover {
  color: var(--ws-tab-add-hover, #111);
  background: var(--ws-tab-add-hover-bg, #e5e7eb);
  border-radius: 5px 5px 0 0;
}

/* Stacked iframes — all positioned absolute at the same place; only
   the active one is visible. Keeping inactive iframes in the DOM
   preserves CodeMirror state, scroll position, WebSocket
   connections — no flash on tab switch. */
.tab-iframes {
  flex: 1;
  min-height: 0;
  position: relative;
  background: var(--ws-iframes-bg, #fff);
}
.tab-iframes iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  visibility: hidden;
  pointer-events: none;
}
.tab-iframes iframe.active {
  visibility: visible;
  pointer-events: auto;
  z-index: 1;
}

/* Dark editor shell (paper_detail center, vault_browser editor) */
.ws-dark {
  --ws-bar-bg: #161b22;
  --ws-bar-border: #30363d;
  --ws-tab-bg: #21262d;
  --ws-tab-fg: #8b949e;
  --ws-tab-border: #30363d;
  --ws-tab-hover-bg: #30363d;
  --ws-tab-hover-fg: #c9d1d9;
  --ws-tab-active-bg: #0d1117;
  --ws-tab-active-fg: #e6edf3;
  --ws-tab-active-border: #30363d;
  --ws-tab-dir: #6e7681;
  --ws-tab-close: #6e7681;
  --ws-tab-close-hover: #c9d1d9;
  --ws-tab-add: #8b949e;
  --ws-tab-add-hover: #e6edf3;
  --ws-tab-add-hover-bg: #21262d;
  --ws-iframes-bg: #0d1117;
}


/* ── Empty state (inside tab-iframes or panel body) ───────────── */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ws-empty-fg, #6b7280);
  text-align: center;
  padding: 40px;
  background: var(--ws-empty-bg, #f9fafb);
}
.empty-state h2 {
  margin: 0 0 8px;
  font-size: 16px;
  color: var(--ws-empty-h-fg, #374151);
  font-weight: 500;
}
.empty-state p { margin: 4px 0; }
.ws-dark .empty-state {
  --ws-empty-fg: #8b949e;
  --ws-empty-bg: #161b22;
  --ws-empty-h-fg: #c9d1d9;
}


/* ── File tree (vault list + filter) ──────────────────────────── */
.tree-toolbar {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid #e5e7eb;
  background: #fff;
  flex-shrink: 0;
}
.tree-toolbar input[type="search"] {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font: inherit;
  font-size: 12px;
}
.tree-toolbar button {
  padding: 4px 8px;
  border: 1px solid #d1d5db;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.tree-toolbar button:hover { background: #f3f4f6; }

ul.tree-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
ul.tree-list ul.tree-list { margin-left: 14px; }
.tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  cursor: pointer;
  color: #374151;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tree-row:hover { background: #eef2ff; }
.tree-row.tree-folder { color: #1f2937; font-weight: 500; }
.tree-row.tree-file.active { background: #e0e7ff; color: #1e3a8a; }
.tree-row.tree-file.already-open { color: #9ca3af; }
.tree-row.tree-file.already-open .tree-name::after {
  content: ' (已开)';
  font-size: 11px;
}
.tree-toggle {
  width: 10px;
  font-size: 9px;
  color: #9ca3af;
  flex-shrink: 0;
}
.tree-icon { width: 14px; flex-shrink: 0; }
.tree-name {
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.tree-meta {
  margin-left: auto;
  font-size: 10px;
  color: #9ca3af;
  flex-shrink: 0;
}


/* ── Tree as modal overlay (paper_detail) ─────────────────────── */
.ws-tree-modal { display: none; }
.ws-tree-modal.open { display: block; }
.ws-tree-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 100;
  backdrop-filter: blur(2px);
}
.ws-tree-modal-panel {
  position: fixed;
  top: 60px;
  left: 24px;
  bottom: 24px;
  width: 360px;
  max-width: 80vw;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  z-index: 101;
  display: flex;
  flex-direction: column;
}
.ws-tree-modal-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
  font-size: 13px;
}
.ws-tree-modal-hint {
  padding: 6px 12px;
  border-top: 1px solid #e5e7eb;
  background: #fafafa;
}


/* ── Drag-to-resize handles ──────────────────────────────────── */
/* Horizontal resizer (vertical bar between two columns). 6px wide,
   transparent hit area, 2px gray spine, indigo on hover/dragging. */
.col-resizer,
.col-resizer-v,
.browser-resizer {
  width: 6px;
  cursor: col-resize;
  background: transparent;
  position: relative;
  flex-shrink: 0;
}
.col-resizer::before,
.col-resizer-v::before,
.browser-resizer::before {
  content: "";
  position: absolute;
  inset: 0;
  background: #e5e7eb;
  width: 2px;
  left: 50%;
  transform: translateX(-50%);
}
.col-resizer:hover::before,
.col-resizer.dragging::before,
.col-resizer-v:hover::before,
.col-resizer-v.dragging::before,
.browser-resizer:hover::before,
.browser-resizer.dragging::before {
  background: #6366f1;
  width: 3px;
}

/* Vertical resizer (horizontal bar between two stacked panels) */
.row-resizer {
  height: 5px;
  cursor: row-resize;
  background: #161b22;
  border-bottom: 1px solid #30363d;
  flex-shrink: 0;
}
.row-resizer:hover, .row-resizer.dragging { background: #21262d; }


/* ── Bottom CLI panel (vault_browser style) ───────────────────── */
.ws-cli-panel {
  border-top: 1px solid #30363d;
  background: #0d1117;
  color: #c9d1d9;
  display: none;
  flex-direction: column;
  height: 280px;
  min-height: 80px;
  max-height: 75vh;
}
.ws-cli-panel.open { display: flex; }
.ws-cli-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  background: #161b22;
  border-bottom: 1px solid #30363d;
  font-size: 11px;
  color: #8b949e;
  flex-shrink: 0;
}
.ws-cli-toolbar .ws-cli-label { font-weight: 600; color: #e6edf3; }
.ws-cli-toolbar .ws-cli-cwd {
  flex: 1;
  font-family: "SF Mono", monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ws-cli-toolbar button {
  background: transparent;
  border: 1px solid #30363d;
  color: #8b949e;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  font-size: 11px;
}
.ws-cli-toolbar button:hover { background: #21262d; color: #e6edf3; }
.ws-cli-toolbar button.danger:hover {
  background: #3d1d1d; color: #f85149; border-color: #5d2d2d;
}
.ws-cli-iframe { flex: 1; width: 100%; border: 0; background: #0d1117; }
.ws-cli-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: #8b949e;
  font-size: 12px;
  padding: 20px;
  text-align: center;
}
.ws-cli-toggle-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 10px;
  background: #161b22;
  color: #8b949e;
  border-top: 1px solid #30363d;
  font-size: 11px;
  flex-shrink: 0;
}
.ws-cli-toggle-bar button {
  background: #21262d;
  color: #c9d1d9;
  border: 1px solid #30363d;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  font-size: 11px;
}
.ws-cli-toggle-bar button:hover { background: #30363d; }
