/* ============================================================
   Blackbox Command Center, docs.css
   Docs screen (js/docs.js) and block editor (js/doceditor.js).
   Existing tokens only (css/main.css :root and its dark block), so both
   themes come for free. Monochrome, no accent hues.
   ============================================================ */

/* ============ Shell: list left, doc right ============ */
.docs-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 36px;
  align-items: start;
}

.docs-side {
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 48px);
  min-width: 0;
}
.docs-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}
.docs-new-btn { padding: 7px 13px; font-size: 12.5px; border-radius: 9px; white-space: nowrap; }

.docs-filters { display: flex; flex-direction: column; gap: 8px; }
.docs-search-wrap { display: flex; width: 100%; }
.docs-search-wrap .task-search { width: 100%; min-width: 0; }
.docs-filters .sort-select { width: 100%; }
/* main.css gives .sort-select flex: 1 1 140px under 900px (row toolbars);
   in this column that basis would become a 140px tall select. */
.docs-filters > * { flex: 0 0 auto; }
.docs-filters .sort-select[hidden] { display: none; }

.docs-list-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--faint);
  margin: 8px 2px 0;
}

.docs-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  min-height: 0;
  margin: 0 -6px;
  padding: 0 6px 4px;
}
.docs-row {
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: var(--radius-sm);
  transition: background var(--dur-fast) var(--ease);
}
.docs-row:hover { background: var(--hover-bg); }
.docs-row.active { background: var(--tint-active); }
.docs-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
  padding: 9px 10px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--ink);
  cursor: pointer;
}
.docs-row-main:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--focus-ring), inset 0 0 0 1px var(--input-focus-border); }
.docs-row-title {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.docs-row.active .docs-row-title { color: var(--tint-active-ink); }
.docs-row-meta {
  font-size: 11.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.docs-row-game {
  display: inline-block;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--ink-soft);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 16px;
}
.docs-row-snippet {
  font-size: 11.5px;
  color: var(--faint);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.docs-row-restore { margin-right: 6px; flex-shrink: 0; }
.docs-row-skel { padding: 10px; display: block; }
.docs-row-skel:hover { background: transparent; }
.docs-empty-note { text-align: left; padding: 10px 4px; }

.docs-trash-link {
  align-self: flex-start;
  border: none;
  background: none;
  padding: 4px 2px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease);
}
.docs-trash-link:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }

/* ============ Main pane ============ */
.docs-main { min-width: 0; }

.docs-placeholder {
  margin-top: 64px;
  max-width: 420px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}
.docs-placeholder-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}
.docs-placeholder p { margin: 0 0 16px; }

.docs-doc { min-width: 0; }
.docs-doc-inner { max-width: 740px; }

.docs-topline {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
  margin-bottom: 6px;
}
.docs-topline-spacer { flex: 1; }
.docs-back {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 5px 8px 5px 4px;
  border: none;
  background: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}
.docs-back:hover { background: var(--tint-active); color: var(--ink); }
.docs-trash-pill {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--ink-soft);
  font-size: 11.5px;
  font-weight: 600;
}
.docs-status {
  font-size: 12px;
  color: var(--faint);
  white-space: nowrap;
  transition: color var(--dur) var(--ease);
}
.docs-status[data-state="offline"],
.docs-status[data-state="reconnecting"] { color: var(--warn); }
.docs-status[data-state="failed"] { color: var(--danger); }
/* Live: the socket is up. Subtle on purpose, a small dot plus the word. */
.docs-status[data-state="live"] { display: inline-flex; align-items: center; gap: 5px; }
.docs-status[data-state="live"]::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.8;
}
.docs-presence { display: inline-flex; align-items: center; gap: 4px; min-width: 0; }
.docs-presence:empty { display: none; }
.docs-avatars { display: inline-flex; align-items: center; flex-shrink: 0; }
.docs-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  color: var(--page);
  font-size: 10.5px;
  font-weight: 700;
  box-shadow: 0 0 0 2px var(--page);
}
.docs-avatar + .docs-avatar { margin-left: -8px; }
/* Someone typing: a thin ink ring outside the page-coloured gap. */
.docs-avatar.is-editing { box-shadow: 0 0 0 2px var(--page), 0 0 0 3px var(--ink-soft); }
.docs-presence-note {
  font-size: 12px;
  color: var(--muted);
  margin-left: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
@media (max-width: 600px) {
  .docs-presence-note { display: none; }
}

.docs-menu-wrap { position: relative; display: inline-flex; }
.docs-menu-wrap .docs-menu { top: 32px; right: 0; min-width: 210px; }
.docs-menu-game {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.docs-menu-game .sort-select { width: 100%; text-transform: none; letter-spacing: 0; }

.docs-title-input {
  display: block;
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  padding: 0;
  margin: 0;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--ink);
}
.docs-title-input::placeholder { color: var(--faint); }
.docs-title-input[readonly] { cursor: default; }

.docs-meta {
  margin: 8px 0 26px;
  font-size: 12.5px;
  color: var(--muted);
}
.docs-meta-game {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 600;
}

.docs-fallback p { margin: 0 0 10px; white-space: pre-wrap; color: var(--ink-soft); }

/* ============ Narrow screens: list and doc take turns ============ */
@media (max-width: 767px) {
  .docs-shell { display: block; }
  .docs-side { position: static; max-height: none; }
  .docs-list { overflow: visible; }
  .docs-shell.has-doc .docs-side { display: none; }
  .docs-shell:not(.has-doc) .docs-main { display: none; }
  .docs-back { display: inline-flex; }
  .docs-title-input { font-size: 25px; }
  .docs-meta { margin-bottom: 20px; }
}

/* ============================================================
   Block editor
   ============================================================ */
.doc-editor {
  position: relative;
  padding-bottom: 120px; /* room to click below the last block */
  color: var(--ink);
  font-size: 15px;
  line-height: 1.65;
}
.doc-blocks { display: flex; flex-direction: column; }

.doc-block {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0;
  padding: 2px 0;
  padding-left: calc(var(--indent, 0) * 26px);
  border-radius: 6px;
}

.doc-marker { flex-shrink: 0; display: none; user-select: none; }
.doc-block[data-type="bullet"] .doc-marker,
.doc-block[data-type="number"] .doc-marker,
.doc-block[data-type="todo"] .doc-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 1.65em;
}

.doc-text {
  flex: 1;
  min-width: 0;
  position: relative;
  outline: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  caret-color: var(--ink);
  min-height: 1.65em;
}
.doc-text.is-empty::before {
  content: attr(data-placeholder);
  position: absolute;
  left: 0;
  top: 0;
  color: var(--faint);
  pointer-events: none;
  display: none;
  white-space: nowrap;
}
.doc-text.is-empty:focus::before,
.doc-block.is-sole .doc-text.is-empty::before,
.doc-block[data-type="h1"] .doc-text.is-empty::before,
.doc-block[data-type="h2"] .doc-text.is-empty::before,
.doc-block[data-type="h3"] .doc-text.is-empty::before { display: block; }
.doc-editor.is-readonly .doc-text.is-empty::before { display: none; }

/* inline tokens (unfocused blocks) */
.doc-text a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--faint);
  text-underline-offset: 3px;
  cursor: pointer;
}
.doc-text a:hover { text-decoration-color: var(--ink); }
.doc-text code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--surface-3);
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  padding: 1px 5px;
}

/* headings */
.doc-block[data-type="h1"] { margin-top: 22px; }
.doc-block[data-type="h2"] { margin-top: 18px; }
.doc-block[data-type="h3"] { margin-top: 12px; }
.doc-blocks > .doc-block:first-child { margin-top: 0; }
.doc-block[data-type="h1"] .doc-text {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.3;
}
.doc-block[data-type="h2"] .doc-text {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.35;
}
.doc-block[data-type="h3"] .doc-text { font-size: 16px; font-weight: 700; line-height: 1.45; }
.doc-block[data-type="h1"] .doc-text,
.doc-block[data-type="h2"] .doc-text,
.doc-block[data-type="h3"] .doc-text { min-height: 1.3em; }

/* lists */
.doc-bullet {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink);
}
.doc-block[data-indent="1"] .doc-bullet { background: transparent; box-shadow: inset 0 0 0 1.3px var(--ink); width: 6px; height: 6px; }
.doc-block[data-indent="2"] .doc-bullet { border-radius: 1px; }
.doc-block[data-indent="3"] .doc-bullet { background: transparent; box-shadow: inset 0 0 0 1.3px var(--ink); border-radius: 1px; }
.doc-num {
  width: 100%;
  padding-right: 6px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

/* checklist */
.doc-check {
  width: 16px;
  height: 16px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--done-btn-border);
  border-radius: 5px;
  background: var(--card);
  color: transparent;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease-spring);
}
.doc-check:hover { border-color: var(--ink-soft); }
.doc-check:active { transform: scale(0.9); }
.doc-check[aria-checked="true"] { background: var(--ink); border-color: var(--ink); color: var(--page); }
.doc-check:disabled { cursor: default; }
.doc-block.is-checked .doc-text {
  color: var(--faint);
  text-decoration: line-through;
  text-decoration-color: var(--strike);
}

/* code */
.doc-block[data-type="code"] { margin: 6px 0; }
.doc-block[data-type="code"] .doc-text {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  background: var(--surface-3);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 12px 14px;
  tab-size: 2;
}
.doc-block[data-type="code"] .doc-text.is-empty::before { left: 14px; top: 12px; }

/* non-text blocks: selectable rows */
.doc-block[tabindex] { outline: none; cursor: default; }
.doc-block[tabindex]:focus-visible,
.doc-block.is-selected { box-shadow: 0 0 0 2px var(--input-focus-border); }
.doc-hr {
  flex: 1;
  border: none;
  height: 1px;
  background: var(--border);
  margin: 14px 0;
}
.doc-block[data-type="divider"] { padding: 2px 0; }

.doc-figure { flex: 1; min-width: 0; margin: 6px 0; }
.doc-img-frame {
  position: relative;
  display: inline-block;
  max-width: 100%;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
  line-height: 0;
}
.doc-img-frame.is-loading { width: 100%; min-height: 160px; }
.doc-img-frame.is-loading .doc-img { opacity: 0; }
.doc-img-frame.is-broken { width: 100%; min-height: 72px; }
.doc-img-frame.is-broken::after {
  content: attr(data-msg);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.4;
}
.doc-img {
  display: block;
  max-width: 100%;
  height: auto;
  cursor: zoom-in;
  transition: opacity var(--dur) var(--ease);
}
.doc-caption {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 2px 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 12.5px;
  color: var(--muted);
}
.doc-caption::placeholder { color: var(--faint); opacity: 0; transition: opacity var(--dur-fast) var(--ease); }
.doc-block:hover .doc-caption::placeholder,
.doc-block.is-selected .doc-caption::placeholder,
.doc-caption:focus::placeholder { opacity: 1; }
.doc-caption[readonly] { cursor: default; }

.doc-chart {
  flex: 1;
  min-height: 90px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 6px 0;
}
.doc-chart-placeholder { font-size: 12.5px; color: var(--muted); }

/* A real chart (live or data) fills the dashed box's width instead of
   sitting centered inside it - the box's own flex centering only kicks in
   for the plain "Chart"/"Loading..." placeholder spans above. */
.doc-chart-inner { width: 100%; }
.doc-chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.doc-chart-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-chart-live {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.doc-chart-notice {
  padding: 26px 4px;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
}
.doc-chart-canvas-wrap { position: relative; width: 100%; height: 240px; }
.doc-chart-canvas-wrap canvas { display: block; width: 100% !important; height: 100% !important; }
@media (max-width: 767px) {
  .doc-chart-canvas-wrap { height: 200px; }
}

/* ============ Insert-chart picker ============
   Reuses css/main.css's .tools-gate-modal/-backdrop/-card/-title/-actions
   chrome (same overlay every on-theme dialog in this app already uses,
   see js/toolsgate.js) - only the form content below is new. */
.docchart-picker-card { width: 420px; max-width: 100%; max-height: 85vh; overflow-y: auto; }
.docchart-field { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; }
.docchart-field:first-of-type { margin-top: 16px; }
.docchart-field label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.docchart-field[hidden] { display: none; }
.docchart-input,
.docchart-csv {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  font-size: 13px;
}
.docchart-input:focus,
.docchart-csv:focus { outline: none; border-color: var(--input-focus-border); }
.docchart-csv {
  min-height: 120px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  resize: vertical;
}
.docchart-error {
  margin-top: 2px;
  font-size: 12px;
  color: var(--danger);
}
.docchart-error[hidden] { display: none; }

.doc-uploading {
  margin: 6px 0;
  min-height: 72px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
}
.doc-uploading-text { font-size: 12.5px; color: var(--muted); }
@media (prefers-reduced-motion: no-preference) {
  .doc-uploading { animation: doc-pulse 1.4s ease-in-out infinite; }
}
@keyframes doc-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* drop target line */
.doc-block.drop-before::before,
.doc-block.drop-after::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  border-radius: 2px;
  background: var(--ink);
  pointer-events: none;
}
.doc-block.drop-before::before { top: -2px; }
.doc-block.drop-after::after { bottom: -2px; }

/* author + lease tags */
.doc-ai-tag,
.doc-lease-tag {
  position: absolute;
  top: 4px;
  right: -4px;
  transform: translateX(100%);
  padding: 0 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 16px;
  user-select: none;
  pointer-events: auto;
}
.doc-ai-tag {
  background: var(--chip-bg);
  color: var(--muted);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease);
}
.doc-block:hover .doc-ai-tag { opacity: 1; }
.doc-lease-tag { background: var(--ink); color: var(--page); }
.doc-block[data-lease-name] .doc-text { color: var(--ink-soft); }
@media (max-width: 900px) {
  .doc-ai-tag,
  .doc-lease-tag { right: 0; transform: none; top: -6px; }
  .doc-ai-tag { opacity: 0.8; }
}

/* slash menu */
.doc-slash {
  position: absolute;
  z-index: 40;
  width: 220px;
  max-height: 300px;
  overflow-y: auto;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
}
.doc-slash[hidden] { display: none; }
.doc-slash-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
}
.doc-slash-item.active,
.doc-slash-item:hover { background: var(--tint-active); }
.doc-slash-badge {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--card);
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
}
.doc-slash-box { width: 10px; height: 10px; border: 1.5px solid currentColor; border-radius: 3px; }
.doc-slash-rule { width: 12px; height: 1.5px; background: currentColor; }
