/* ================================================================= DOCS == */
/* Docs panel (Q, task queue #28). Same tokens and primitives as style.css:
   the projects down the left (a chip row when narrower), the documents in one
   card per project on the right. The one new colour rule: each format keeps
   the hue people already know it by (Sheets green, Docs blue, PDF red...),
   muted to sit on the dark canvas, and only on the format's own icon. */

#docs-panel {
  --f-sheet: #5fd38d;
  --f-doc: #72a5ff;
  --f-slides: #f2bf4f;
  --f-form: #b394ff;
  --f-pdf: #ff7b72;
  --f-markdown: #d4d4dc;
  --f-text: #a8a8b3;
  --f-data: #5eead4;
  --f-diagram: #fb9a4b;
  --f-script: #c792ff;
  --f-page: #4cc3f5;
  --f-repo: #d4d4dc;
  --f-archive: #b8a99a;
  --f-media: #f47fb8;
  --f-image: #7fd4c1;
  --f-link: #a0a0ab;
}
#docs-panel .fmt-sheet { --f: var(--f-sheet); }
#docs-panel .fmt-doc { --f: var(--f-doc); }
#docs-panel .fmt-slides { --f: var(--f-slides); }
#docs-panel .fmt-form { --f: var(--f-form); }
#docs-panel .fmt-pdf { --f: var(--f-pdf); }
#docs-panel .fmt-markdown { --f: var(--f-markdown); }
#docs-panel .fmt-text { --f: var(--f-text); }
#docs-panel .fmt-data { --f: var(--f-data); }
#docs-panel .fmt-diagram { --f: var(--f-diagram); }
#docs-panel .fmt-script { --f: var(--f-script); }
#docs-panel .fmt-page { --f: var(--f-page); }
#docs-panel .fmt-repo { --f: var(--f-repo); }
#docs-panel .fmt-archive { --f: var(--f-archive); }
#docs-panel .fmt-media { --f: var(--f-media); }
#docs-panel .fmt-image { --f: var(--f-image); }
#docs-panel .fmt-link { --f: var(--f-link); }

/* ------------------------------------------------------- search + filters -- */
.docs-find { display: flex; gap: 8px; margin-bottom: 12px; }
.docs-search {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  height: 38px;
  padding: 0 10px 0 12px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: 11px;
  cursor: text;
  transition: border-color 0.16s, box-shadow 0.16s;
}
.docs-search:focus-within { border-color: var(--accent-line); box-shadow: 0 0 0 3px rgba(139, 142, 255, 0.1); }
.docs-search .ic { width: 16px; height: 16px; color: var(--text-3); }
.docs-search input { flex: 1; min-width: 0; height: 100%; background: none; border: 0; outline: none; font-size: var(--fs); color: var(--text); }
.docs-search input::placeholder { color: var(--text-3); }
.docs-search:focus-within kbd { visibility: hidden; }
#docs-tag { width: 210px; flex: none; height: 38px; border-radius: 11px; text-overflow: ellipsis; }
#docs-tag.picked { border-color: var(--line-3); color: var(--text); }

#docs-formats .filter-btn { display: inline-flex; align-items: center; gap: 6px; }
#docs-formats .filter-btn.empty { opacity: 0.45; }
.docs-fmt-ic { width: 14px; height: 14px; color: var(--f); }
.docs-n { font-family: var(--mono); font-size: 10.5px; color: var(--text-3); }

/* ---------------------------------------------------------------- layout -- */
.docs-layout {
  display: grid;
  grid-template-columns: 204px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.docs-projects { display: flex; flex-direction: column; gap: 2px; padding: 6px; max-height: calc(100vh - 250px); overflow-y: auto; position: sticky; top: 16px; }
.docs-projects-title { padding: 8px 10px 6px; font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); }
.docs-project {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border-radius: 9px;
  border: 1px solid transparent;
  text-align: left;
  font-size: var(--fs-sm);
  color: var(--text-2);
  transition: background 0.16s var(--ease), border-color 0.16s var(--ease), color 0.16s var(--ease);
}
.docs-project .ic { width: 15px; height: 15px; color: var(--text-3); }
.docs-project-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.docs-project-n { font-family: var(--mono); font-size: 10.5px; color: var(--text-3); }
.docs-project:hover { background: var(--surface-2); color: var(--text); }
.docs-project.active { background: var(--surface-2); border-color: var(--line-2); color: var(--text); }
.docs-project.active .ic { color: var(--accent-2); }
.docs-project.empty { opacity: 0.5; }

.docs-group + .docs-group { margin-top: 22px; }
.docs-group-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 8px 4px;
  font-size: var(--fs-sm);
  font-weight: 560;
  color: var(--text-2);
}
.docs-rows { padding: 4px; }
.docs-empty { padding: 36px 8px; text-align: center; }

/* ---------------------------------------------------------- one document -- */
.doc-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 2px 6px 2px 2px;
  border-radius: 12px;
  transition: background 0.16s var(--ease);
}
/* A hairline between rows, starting after the icon, gone around the hovered row. */
.doc-row + .doc-row::before, .doc-edit + .doc-row::before {
  content: '';
  position: absolute;
  top: 0;
  left: 60px;
  right: 10px;
  height: 1px;
  background: var(--line);
  transition: opacity 0.16s var(--ease);
}
.doc-row:hover::before, .doc-row:hover + .doc-row::before { opacity: 0; }
.doc-row:hover { background: var(--surface-2); }
.doc-row.flash { animation: docFlash 1.6s var(--ease) both; }
@keyframes docFlash { from { background: var(--accent-soft); } to { background: transparent; } }
.doc-link { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 10px; color: inherit; text-decoration: none; border-radius: 10px; }
.doc-link:focus-visible { outline: 2px solid var(--accent-line); outline-offset: -2px; }
.doc-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 10px;
  color: var(--f, var(--text-2));
  background: color-mix(in srgb, var(--f, var(--text-2)) 13%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--f, var(--text-2)) 22%, transparent);
}
.doc-icon .ic { width: 19px; height: 19px; }
.doc-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.doc-title { font-size: var(--fs); font-weight: 520; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-link:hover .doc-title { color: #fff; }
.doc-note { font-size: var(--fs-sm); color: var(--text-2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }
.doc-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 1px; font-family: var(--mono); font-size: 10.5px; color: var(--text-3); }
.doc-fmt { color: var(--f); }
.doc-naming { display: inline-flex; align-items: center; gap: 5px; color: var(--text-2); }
.doc-naming .working-dot { width: 10px; height: 10px; -webkit-mask: radial-gradient(circle, transparent 2.5px, #000 3px); mask: radial-gradient(circle, transparent 2.5px, #000 3px); }
#docs-panel mark { background: rgba(255, 255, 255, 0.14); color: var(--text); border-radius: 3px; padding: 0 1px; }

.doc-tags { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 5px; max-width: 280px; }
.doc-tag {
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  font-size: 11.5px;
  color: var(--text-2);
  white-space: nowrap;
  transition: all 0.16s var(--ease);
}
.doc-tag::before { content: '#'; color: var(--text-3); margin-right: 1px; }
.doc-tag:hover { color: var(--text); border-color: var(--line-3); }
.doc-tag.picked { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-2); }

.doc-actions { display: flex; gap: 2px; opacity: 0; transition: opacity 0.16s var(--ease); }
.doc-row:hover .doc-actions, .doc-row:focus-within .doc-actions { opacity: 1; }
.doc-remove:hover { background: var(--danger-soft); color: var(--danger); }

/* ------------------------------------------------------------ edit + add -- */
.doc-edit { display: flex; gap: 12px; padding: 12px 12px 12px 12px; border-radius: 12px; background: var(--surface-2); animation: rise 0.22s var(--ease) both; }
.doc-edit-fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.doc-edit textarea.task-input { height: auto; padding: 8px 11px; resize: vertical; font-family: inherit; line-height: 1.45; }
.docs-form-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.docs-form-grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.docs-form-row { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 2px; }
.docs-form-row .muted { margin-right: auto; font-size: var(--fs-sm); }
#docs-add-form { margin-bottom: 14px; animation: rise 0.22s var(--ease) both; }
#docs-add-form .docs-form-row { margin-top: 10px; }

/* ---------------------------------------------------------------- narrow -- */
@media (max-width: 1100px) {
  .doc-row { grid-template-columns: minmax(0, 1fr) auto; }
  .doc-tags { grid-column: 1; grid-row: 2; justify-content: flex-start; max-width: none; padding: 0 10px 10px 60px; margin-top: -6px; }
  .doc-tags:empty { display: none; }
  .doc-actions { grid-column: 2; grid-row: 1; }
  .docs-form-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .docs-layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .docs-projects { flex-direction: row; align-items: center; max-height: none; overflow-x: auto; position: static; padding: 4px; }
  .docs-projects-title { display: none; }
  .docs-project { width: auto; flex: none; }
}
@media (max-width: 760px) {
  .docs-find { flex-direction: column; }
  #docs-tag { width: 100%; }
  .docs-search kbd { display: none; }
  #docs-formats { flex-wrap: nowrap; overflow-x: auto; margin-right: -20px; padding-right: 20px; }
  #docs-formats .filter-btn { flex: none; }
  .doc-actions { opacity: 1; }
  .doc-link { gap: 10px; padding: 9px 6px; }
  .doc-tags { padding-left: 54px; }
  .docs-form-grid, .docs-form-grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (hover: none) { .doc-actions { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .doc-row.flash, .doc-edit, #docs-add-form { animation: none; }
}
