/* Document Library (NyayaDoc client-side layer) — self-contained styles */

/* Full-width: the library doesn't need the shell's input pane */
#toolShell[data-slug="document-library"] .tool-panes {
  grid-template-columns: 1fr;
}
#toolShell[data-slug="document-library"] .tool-pane:first-child {
  display: none;
}

.dl-app {
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: var(--text-sm, 0.875rem);
}

/* ---------- header ---------- */
.dl-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.dl-title {
  margin: 0 0 4px;
  font-size: var(--text-lg, 1.1rem);
  font-weight: 800;
}
.dl-sub {
  margin: 0;
  color: var(--text-2, #64748b);
  font-size: var(--text-xs, 0.8rem);
  line-height: 1.5;
  max-width: 720px;
}
.dl-stats {
  display: flex;
  gap: 8px;
}
.dl-head-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.dl-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 14px;
  border: 1px solid var(--border, rgba(127, 127, 127, 0.25));
  border-radius: 10px;
  background: var(--surface-2, rgba(127, 127, 127, 0.06));
  min-width: 84px;
}
.dl-stat-value {
  font-weight: 800;
  font-size: var(--text-md, 0.95rem);
  color: var(--accent, #6366f1);
}
.dl-stat-label {
  font-size: var(--text-2xs, 0.7rem);
  color: var(--text-3, #94a3b8);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---------- body layout ---------- */
.dl-body {
  display: grid;
  grid-template-columns: 230px 1fr;
  gap: 14px;
  align-items: start;
}

/* ---------- sidebar ---------- */
.dl-side {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--border, rgba(127, 127, 127, 0.25));
  border-radius: 12px;
  background: var(--surface, #fff);
}
.dl-side-title {
  font-size: var(--text-2xs, 0.7rem);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3, #94a3b8);
  margin: 6px 0 2px;
}
.dl-side-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-1, #0f172a);
  font-size: var(--text-sm, 0.85rem);
  font-weight: 600;
  cursor: pointer;
}
.dl-side-item:hover {
  background: var(--surface-2, rgba(127, 127, 127, 0.08));
}
.dl-side-item.is-active {
  background: var(--accent-soft, rgba(99, 102, 241, 0.12));
  border-color: var(--accent, #6366f1);
  color: var(--accent, #6366f1);
}
.dl-side-project {
  position: relative;
}
.dl-side-proj-actions {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  gap: 2px;
}
.dl-side-project:hover .dl-side-proj-actions {
  display: flex;
}
.dl-side-proj-actions button {
  border: none;
  background: transparent;
  color: var(--text-3, #94a3b8);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 4px;
  border-radius: 5px;
}
.dl-side-proj-actions button:hover {
  background: var(--surface-3, rgba(127, 127, 127, 0.14));
  color: var(--text-1, #0f172a);
}
.dl-count {
  font-size: var(--text-2xs, 0.7rem);
  color: var(--text-3, #94a3b8);
  font-weight: 700;
}
.dl-side-add {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}
.dl-tagcloud {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.dl-chip {
  border: 1px solid var(--border, rgba(127, 127, 127, 0.25));
  background: var(--surface-2, rgba(127, 127, 127, 0.06));
  color: var(--text-2, #64748b);
  font-size: var(--text-2xs, 0.72rem);
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  cursor: pointer;
}
.dl-chip:hover {
  border-color: var(--accent, #6366f1);
}
.dl-chip.is-active {
  background: var(--accent-soft, rgba(99, 102, 241, 0.14));
  border-color: var(--accent, #6366f1);
  color: var(--accent, #6366f1);
}
.dl-chip-clear {
  color: var(--text-3, #94a3b8);
}

/* ---------- main ---------- */
.dl-main {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.dl-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.dl-input {
  border: 1px solid var(--border, rgba(127, 127, 127, 0.3));
  background: var(--surface, #fff);
  color: var(--text-1, #0f172a);
  border-radius: 9px;
  padding: 8px 12px;
  font-size: var(--text-sm, 0.85rem);
  min-width: 0;
}
.dl-input:focus {
  outline: 2px solid var(--accent, #6366f1);
  outline-offset: 0;
  border-color: var(--accent, #6366f1);
}
.dl-search {
  flex: 1 1 280px;
}
.dl-btn {
  border: 1px solid var(--border, rgba(127, 127, 127, 0.3));
  background: var(--surface-2, rgba(127, 127, 127, 0.06));
  color: var(--text-1, #0f172a);
  font-size: var(--text-sm, 0.85rem);
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
}
.dl-btn:hover {
  border-color: var(--border-strong, rgba(127, 127, 127, 0.5));
  background: var(--surface-3, rgba(127, 127, 127, 0.12));
}
.dl-btn-primary {
  background: var(--accent-gradient, linear-gradient(135deg, #6366f1, #8b5cf6));
  border-color: transparent;
  color: var(--accent-contrast, #fff);
}
.dl-btn-primary:hover {
  filter: brightness(1.06);
  background: var(--accent-gradient, linear-gradient(135deg, #6366f1, #8b5cf6));
}
.dl-btn-danger:hover {
  border-color: #ef4444;
  color: #ef4444;
  background: rgba(239, 68, 68, 0.08);
}
.dl-upload {
  position: relative;
  overflow: hidden;
}
.dl-status {
  padding: 8px 12px;
  border-radius: 9px;
  background: var(--accent-soft, rgba(99, 102, 241, 0.1));
  color: var(--accent, #6366f1);
  font-size: var(--text-sm, 0.85rem);
  font-weight: 600;
}
.dl-drop {
  border: 1.5px dashed var(--border-strong, rgba(127, 127, 127, 0.45));
  border-radius: 12px;
  padding: 14px 16px;
  text-align: center;
  color: var(--text-2, #64748b);
  font-size: var(--text-xs, 0.8rem);
  cursor: pointer;
  background: var(--bg-subtle, rgba(127, 127, 127, 0.04));
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dl-drop:hover {
  border-color: var(--accent, #6366f1);
  background: var(--accent-soft, rgba(99, 102, 241, 0.06));
}

/* ---------- results ---------- */
.dl-results {
  min-height: 120px;
}
.dl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 10px;
}
.dl-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border, rgba(127, 127, 127, 0.25));
  border-radius: 12px;
  background: var(--surface, #fff);
}
.dl-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.dl-card-icon {
  font-size: 1.05rem;
}
.dl-card-title {
  flex: 1;
  font-weight: 700;
  font-size: var(--text-sm, 0.86rem);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dl-card-meta {
  font-size: var(--text-2xs, 0.72rem);
  color: var(--text-3, #94a3b8);
}
.dl-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.dl-tag {
  border: none;
  background: var(--surface-2, rgba(127, 127, 127, 0.08));
  color: var(--text-2, #64748b);
  font-size: var(--text-2xs, 0.7rem);
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  cursor: pointer;
}
.dl-tag:hover {
  color: var(--accent, #6366f1);
  background: var(--accent-soft, rgba(99, 102, 241, 0.12));
}
.dl-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.dl-select {
  border: 1px solid var(--border, rgba(127, 127, 127, 0.3));
  background: var(--surface, #fff);
  color: var(--text-1, #0f172a);
  border-radius: 9px;
  padding: 7px 9px;
  font-size: var(--text-xs, 0.8rem);
}
.dl-move {
  max-width: 130px;
}
.dl-badge {
  font-size: var(--text-2xs, 0.66rem);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}
.dl-badge-ok {
  background: rgba(16, 185, 129, 0.14);
  color: #10b981;
}
.dl-badge-warn {
  background: rgba(245, 158, 11, 0.14);
  color: #f59e0b;
}

/* ---------- notes ---------- */
.dl-note {
  padding: 18px;
  text-align: center;
  color: var(--text-2, #64748b);
  border: 1px dashed var(--border-strong, rgba(127, 127, 127, 0.35));
  border-radius: 12px;
  font-size: var(--text-sm, 0.85rem);
}
.dl-note-error {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.05);
  text-align: left;
  line-height: 1.6;
}

/* ---------- search results ---------- */
.dl-sr-head {
  font-weight: 800;
  font-size: var(--text-sm, 0.86rem);
  margin-bottom: 8px;
}
.dl-sr-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.dl-sr-item {
  border: 1px solid var(--border, rgba(127, 127, 127, 0.25));
  border-radius: 12px;
  background: var(--surface, #fff);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dl-sr-name {
  display: flex;
  align-items: center;
  gap: 8px;
}
.dl-link {
  border: none;
  background: none;
  color: var(--accent, #6366f1);
  font-weight: 800;
  font-size: var(--text-sm, 0.88rem);
  cursor: pointer;
  text-align: left;
  padding: 0;
}
.dl-link:hover {
  text-decoration: underline;
}
.dl-sr-count {
  font-size: var(--text-2xs, 0.7rem);
  color: var(--text-3, #94a3b8);
  font-weight: 700;
}
.dl-sr-match {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: var(--surface-2, rgba(127, 127, 127, 0.05));
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
}
.dl-sr-match:hover {
  border-color: var(--accent, #6366f1);
  background: var(--accent-soft, rgba(99, 102, 241, 0.07));
}
.dl-sr-page {
  font-size: var(--text-2xs, 0.68rem);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent, #6366f1);
}
.dl-sr-snippet {
  font-size: var(--text-xs, 0.8rem);
  color: var(--text-2, #64748b);
  line-height: 1.45;
}
.dl-sr-more {
  font-size: var(--text-2xs, 0.72rem);
  color: var(--text-3, #94a3b8);
  font-weight: 700;
}

/* ---------- viewer modal ---------- */
.dl-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.dl-modal {
  width: min(860px, 96vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--surface, #fff);
  border: 1px solid var(--border, rgba(127, 127, 127, 0.3));
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
.dl-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border, rgba(127, 127, 127, 0.25));
}
.dl-modal-title {
  font-weight: 800;
  font-size: var(--text-md, 0.95rem);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dl-modal-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 16px 0;
  border-bottom: 1px solid var(--border, rgba(127, 127, 127, 0.25));
}
.dl-tab {
  border: none;
  background: none;
  color: var(--text-2, #64748b);
  font-weight: 700;
  font-size: var(--text-sm, 0.85rem);
  padding: 8px 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.dl-tab.is-active {
  color: var(--accent, #6366f1);
  border-bottom-color: var(--accent, #6366f1);
}
.dl-modal-body {
  flex: 1;
  overflow: auto;
  padding: 16px;
}
.dl-modal-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border, rgba(127, 127, 127, 0.25));
}
.dl-pages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.dl-page {
  border: 1px solid var(--border, rgba(127, 127, 127, 0.25));
  border-radius: 10px;
  background: var(--surface-2, rgba(127, 127, 127, 0.04));
  overflow: hidden;
}
.dl-page-num {
  font-size: var(--text-2xs, 0.7rem);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent, #6366f1);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border, rgba(127, 127, 127, 0.2));
  background: var(--surface, #fff);
}
.dl-page-text {
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: var(--text-sm, 0.85rem);
  line-height: 1.65;
  color: var(--text-1, #0f172a);
}

/* ---------- OCR ---------- */
.dl-ocr {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.dl-ocr-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.dl-ocr-status {
  font-size: var(--text-sm, 0.85rem);
  color: var(--text-2, #64748b);
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 22px;
}
.dl-spin {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-strong, rgba(127, 127, 127, 0.4));
  border-top-color: var(--accent, #6366f1);
  border-radius: 50%;
  display: inline-block;
  animation: dl-spin 0.8s linear infinite;
}
@keyframes dl-spin {
  to { transform: rotate(360deg); }
}

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .dl-body {
    grid-template-columns: 1fr;
  }
  .dl-side {
    order: 2;
  }
  .dl-stats {
    width: 100%;
  }
  .dl-head-right {
    width: 100%;
    align-items: stretch;
  }
  .dl-stat {
    flex: 1;
    min-width: 0;
  }
  .dl-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .dl-search {
    flex: none;
  }
}
