/* documents-library.css - Document Library Styles */

.documents-library-container {
  height: 100%;
  min-height: 0; /* allow flex child to shrink so inner scroll works */
  display: flex;
  flex-direction: column;
  background: var(--surface-2, #f8fafc);
}

/* Header – never shrink so layout order is preserved */
.documents-header {
  flex-shrink: 0;
  background: var(--surface-1, white);
  border-bottom: 1px solid var(--border-subtle, #e2e8f0);
  padding: 16px 32px;
}

.documents-header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.documents-title-section {
  flex: 1;
}

.documents-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary, #1e293b);
  margin-bottom: 4px;
}

.documents-subtitle {
  font-size: 13px;
  color: var(--text-secondary, #64748b);
  margin: 0;
}

.documents-actions {
  display: flex;
  gap: 12px;
}

/* Stats Bar */
.documents-stats {
  display: flex;
  gap: 32px;
  padding: 12px 0;
  border-top: 1px solid var(--border-subtle, #e2e8f0);
  border-bottom: 1px solid var(--border-subtle, #e2e8f0);
  margin-bottom: 16px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary, #1e293b);
  line-height: 1;
}

.stat-label {
  font-size: 11px;
  color: var(--text-secondary, #64748b);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

/* Search & Controls */
.documents-controls {
  display: flex;
  gap: 16px;
  align-items: center;
}

.search-box {
  flex: 1;
  position: relative;
  max-width: 400px;
}

.search-box svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary, #94a3b8);
  pointer-events: none;
}

/* More specific selector to ensure padding wins */
.documents-library-container .search-box input {
  width: 100%;
  padding: 10px 48px 10px 40px !important;
  border: 1px solid var(--border-subtle, #e2e8f0);
  border-radius: 8px;
  font-size: 14px;
  transition: all 200ms ease;
  /* Ensure text starts where we want it */
  text-indent: 0;
  position: relative;
  z-index: 1;
  /* Ensure button area is clickable */
  pointer-events: auto;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent, #3b82f6);
  box-shadow: var(--focus);
}

.view-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.sort-select {
  padding: 8px 12px;
  border: 1px solid var(--border-subtle, #e2e8f0);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface-1, white);
  cursor: pointer;
  transition: all 200ms ease;
}

.sort-select:hover {
  border-color: var(--border-strong, #cbd5e1);
}

.sort-select:focus {
  outline: none;
  border-color: var(--accent, #3b82f6);
  box-shadow: var(--focus);
}

.view-toggle {
  padding: 8px;
  border: 1px solid var(--border-subtle, #e2e8f0);
  border-radius: 8px;
  background: var(--surface-1, white);
  cursor: pointer;
  transition: all 200ms ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.view-toggle:hover {
  background: var(--surface-2, #f8fafc);
  border-color: var(--border-strong, #cbd5e1);
}

.view-toggle.active {
  background: var(--accent, #3b82f6);
  border-color: var(--accent, #3b82f6);
  color: white;
}

.view-toggle.active svg {
  color: white;
}

/* Categories – never shrink; stack above content so list never covers tabs */
.documents-categories {
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  padding: 12px 32px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--surface-1, white);
  border-bottom: 1px solid var(--border-subtle, #e2e8f0);
  overflow-x: auto;
}

.category-chip {
  padding: 6px 14px;
  border: 1px solid var(--border-subtle, #e2e8f0);
  border-radius: 999px;
  background: var(--surface-1, white);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary, #64748b);
  cursor: pointer;
  transition: all 200ms ease;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}

.category-chip:hover {
  background: var(--surface-2, #f8fafc);
  border-color: var(--border-strong, #cbd5e1);
}

.category-chip.active {
  background: var(--accent, #3b82f6);
  border-color: var(--accent, #3b82f6);
  color: white;
}

.category-count {
  background: rgba(0, 0, 0, 0.1);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.category-chip.active .category-count {
  background: rgba(255, 255, 255, 0.25);
}

/* Content Area: flex row (list + sidebar). Do not scroll here; list and sidebar scroll. */
.documents-content {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

/* Main list/grid area – scrollable when many documents */
.documents-main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 32px;
  -webkit-overflow-scrolling: touch;
}

/* Preview/details sidebar – scrollable when content is long */
.documents-sidebar {
  flex-shrink: 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* Grid View */
.documents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
}

.document-card {
  background: var(--surface-1, white);
  border: 1px solid var(--border-subtle, #e2e8f0);
  border-radius: 12px;
  overflow: hidden;
  transition: all 250ms ease;
  cursor: pointer;
}

.document-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1);
  border-color: var(--border-strong, #cbd5e1);
}

.document-preview {
  position: relative;
  aspect-ratio: 4/3;
  background: linear-gradient(135deg, var(--surface-2, #f8fafc) 0%, var(--surface-hover, #f1f5f9) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.preview-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-icon {
  font-size: 64px;
  opacity: 0.6;
}

.document-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  opacity: 0;
  transition: opacity 200ms ease;
}

.document-card:hover .document-overlay {
  opacity: 1;
}

.doc-action-btn {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 200ms ease;
}

.doc-action-btn:hover {
  background: var(--surface-1, white);
  transform: scale(1.1);
}

.doc-action-btn svg {
  color: var(--text-primary, #1e293b);
}

.document-info {
  padding: 16px;
}

.document-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary, #1e293b);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.document-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-tertiary, #94a3b8);
  margin-bottom: 8px;
}

.meta-separator {
  opacity: 0.5;
}

.document-description {
  font-size: 13px;
  color: var(--text-secondary, #64748b);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Selection Checkboxes */
.selection-checkbox {
  display: flex;
  align-items: center;
  justify-content: center;
}

.item-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--accent, #3b82f6);
  border-radius: 4px;
  transition: all 150ms ease;
}

.item-checkbox:hover {
  transform: scale(1.1);
}

/* Selected state for cards and rows */
.document-card.selected,
.document-row.selected {
  background: #eff6ff !important;
  border-color: var(--accent, #3b82f6) !important;
}

/* Multi-select bulk bar: one horizontal line, light blue background (contacts/invoices style) */
#docsBulkBarMount {
  flex-shrink: 0;
  display: none;
  margin: 0 !important; /* full-width bar like contacts/invoices */
  padding: 0;
}

#docsBulkBarMount:not(.hidden) {
  display: flex;
}

.documents-library-container .bulkBar {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 24px;
  background: #eff6ff;
  border-bottom: 1px solid #bfdbfe;
  border-radius: 0;
  flex-wrap: nowrap;
}

.documents-library-container .bulkBar .bulkCount {
  font-weight: 600;
  font-size: 14px;
  color: var(--accent, #1e40af);
  margin: 0;
  white-space: nowrap;
}

.documents-library-container .bulkBar .bulkSpacer {
  flex: 1;
  min-width: 12px;
}

.documents-library-container .bulkBar .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  background: var(--surface-1, white);
  border: 1px solid var(--border-subtle, #e2e8f0);
  border-radius: 999px;
  color: var(--text-primary, #1e293b);
  white-space: nowrap;
  flex-shrink: 0;
}

.documents-library-container .bulkBar .btn:hover {
  background: var(--surface-2, #f8fafc);
  border-color: var(--border-strong, #cbd5e1);
}

.documents-library-container .bulkBar .btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.documents-library-container .bulkBar #docsBulkDelete.btn {
  color: #b91c1c;
  border-color: #fecaca;
  background: #fef2f2;
}

.documents-library-container .bulkBar #docsBulkDelete.btn:hover {
  background: #fee2e2;
  border-color: #fecaca;
}

/* List View */
.documents-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border-subtle, #e2e8f0);
  border-radius: 12px;
  overflow: hidden;
}

.document-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--surface-1, white);
  cursor: pointer;
  transition: all 150ms ease;
}

.document-row:hover {
  background: var(--surface-2, #f8fafc);
}

.doc-row-icon {
  font-size: 32px;
  width: 48px;
  flex-shrink: 0;
  text-align: center;
}

.doc-row-info {
  flex: 1;
  min-width: 0;
}

.doc-row-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary, #1e293b);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-row-description {
  font-size: 13px;
  color: var(--text-secondary, #64748b);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-row-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.doc-row-category,
.doc-row-size,
.doc-row-date {
  font-size: 13px;
  color: var(--text-secondary, #64748b);
  white-space: nowrap;
}

.doc-row-category {
  padding: 4px 12px;
  background: var(--surface-hover, #f1f5f9);
  border-radius: 999px;
  font-weight: 600;
}

.doc-row-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 200ms ease;
}

.document-row:hover .doc-row-actions {
  opacity: 1;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  text-align: center;
}

.empty-icon {
  font-size: 80px;
  margin-bottom: 24px;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary, #1e293b);
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 16px;
  color: var(--text-secondary, #64748b);
  max-width: 500px;
  margin-bottom: 32px;
  line-height: 1.6;
}

/* Upload Modal */
.upload-dropzone {
  border: 2px dashed var(--border-strong, #cbd5e1);
  border-radius: 12px;
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 250ms ease;
  margin-bottom: 24px;
}

.upload-dropzone:hover,
.upload-dropzone.dragover {
  border-color: var(--accent, #3b82f6);
  background: rgba(59, 130, 246, 0.05);
}

.dropzone-content svg {
  color: var(--text-tertiary, #94a3b8);
  margin-bottom: 16px;
}

.dropzone-text {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary, #1e293b);
  margin-bottom: 8px;
}

.dropzone-hint {
  font-size: 14px;
  color: var(--text-tertiary, #94a3b8);
  margin: 0;
}

.file-preview {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: var(--surface-2, #f8fafc);
  border: 1px solid var(--border-subtle, #e2e8f0);
  border-radius: 12px;
  margin-bottom: 24px;
}

.preview-icon-large {
  font-size: 48px;
  width: 64px;
  text-align: center;
  flex-shrink: 0;
}

.preview-details {
  flex: 1;
  min-width: 0;
}

.preview-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary, #1e293b);
  margin-bottom: 4px;
  word-break: break-all;
}

.preview-size {
  font-size: 13px;
  color: var(--text-secondary, #64748b);
}

/* Document Details Modal */
.document-details {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.detail-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 16px;
  align-items: start;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle, #e2e8f0);
}

.detail-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.detail-row-full {
  grid-template-columns: 1fr;
}

.detail-row strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary, #64748b);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.detail-row span,
.detail-row p {
  font-size: 15px;
  color: var(--text-primary, #1e293b);
  margin: 0;
  line-height: 1.6;
}

.tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.tag {
  padding: 4px 12px;
  background: var(--surface-hover, #f1f5f9);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary, #64748b);
}

.detail-actions {
  display: flex;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle, #e2e8f0);
}

/* Spinner */
.spinner {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Context Menu */
.doc-context-menu {
  position: fixed;
  background: var(--surface-1, white);
  border: 1px solid var(--border-subtle, #e2e8f0);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  padding: 6px 0;
  min-width: 180px;
  z-index: 1000;
  animation: fadeIn 100ms ease;
}

.menu-item {
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-primary, #1e293b);
  cursor: pointer;
  transition: background 150ms ease;
}

.menu-item:hover {
  background: var(--surface-hover, #f1f5f9);
}

.menu-item.delete {
  color: #ef4444;
}

.menu-item.delete:hover {
  background: #fef2f2;
}

.menu-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.menu-divider {
  height: 1px;
  background: var(--border-subtle, #e2e8f0);
  margin: 6px 0;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes slideInRight {
  from { 
    opacity: 0; 
    transform: translateX(100px);
  }
  to { 
    opacity: 1; 
    transform: translateX(0);
  }
}

/* Responsive */
@media (max-width: 768px) {
  .documents-header {
    padding: 16px 20px;
  }

  .documents-header-top {
    flex-direction: column;
    gap: 16px;
  }

  .documents-stats {
    gap: 20px;
    overflow-x: auto;
  }

  .stat-value {
    font-size: 24px;
  }

  .documents-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .search-box {
    max-width: none;
  }

  .view-controls {
    justify-content: space-between;
  }

  .documents-content {
    padding: 16px 20px;
  }

  .documents-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
  }

  .doc-row-meta {
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
  }

  .detail-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}

@media (max-width: 480px) {
  .documents-grid {
    grid-template-columns: 1fr;
  }

  .documents-stats {
    flex-direction: column;
    gap: 16px;
  }

  .stat-item {
    flex-direction: row;
    align-items: center;
    gap: 12px;
  }

  .stat-value {
    font-size: 20px;
  }

  .stat-label {
    font-size: 12px;
  }
}

