/* Drive Document Ingestion UI (tokens in shared.css) */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #f5f5f5;
  color: #111827;
  line-height: 1.5;
}

/* Unified Header styles are in header.css */

/* Main App Layout */
.drive-app {
  display: flex;
  flex-direction: column;
  padding-top: 48px;
  height: 100vh;
}

/* Tab Navigation */
.drive-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 24px;
  background: #ffffff;
  border-bottom: 1px solid #e5e5e5;
}

.drive-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  background: transparent;
  color: #6b7280;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.drive-tab:hover {
  background: #f3f4f6;
  color: #374151;
}

.drive-tab.active {
  background: var(--color-primary);
  color: #ffffff;
}

.drive-tab svg {
  flex-shrink: 0;
}

.tab-badge {
  display: none;
  background: #dc2626;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 6px;
}

.drive-tab.active .tab-badge {
  background: rgba(255, 255, 255, 0.2);
}

/* Content Views */
.drive-content {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.drive-content.hidden {
  display: none;
}

/* History View & Un-ingested View */
#view-history,
#view-uningested {
  flex-direction: column;
  padding: 0;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: #ffffff;
  border-bottom: 1px solid #e5e5e5;
}

.history-title {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.history-title h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}

.history-count {
  font-size: 13px;
  color: #6b7280;
}

.history-controls {
  display: flex;
  gap: 12px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box svg {
  position: absolute;
  left: 12px;
  color: #9ca3af;
  pointer-events: none;
}

.search-box .search-input {
  padding-left: 36px;
  width: 280px;
}

/* History Table */
.history-table-container {
  flex: 1;
  overflow: auto;
  padding: 0 24px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.history-table th,
.history-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid #e5e5e5;
}

.history-table th {
  background: #f9fafb;
  font-weight: 600;
  color: #374151;
  position: sticky;
  top: 0;
  z-index: 10;
  white-space: nowrap;
}

.history-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.history-table th.sortable:hover {
  background: #f3f4f6;
}

.history-table th .sort-icon::after {
  content: '';
  display: inline-block;
  margin-left: 4px;
  width: 0;
  height: 0;
  vertical-align: middle;
}

.history-table th.sortable.active.desc .sort-icon::after {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid #374151;
}

.history-table th.sortable.active.asc .sort-icon::after {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 5px solid #374151;
}

.history-table tbody tr:hover {
  background: #f9fafb;
}

.loading-cell {
  text-align: center;
  padding: 40px !important;
  color: #6b7280;
}

.loading-cell.error {
  color: #dc2626;
}

.file-name-cell {
  max-width: 300px;
}

.file-name-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.file-name-cell .tree-icon {
  flex-shrink: 0;
}

.file-link {
  color: #374151;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-link:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

.size-cell,
.date-cell,
.uploader-cell {
  white-space: nowrap;
  color: #6b7280;
}

.uploader-cell {
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.actions-cell {
  white-space: nowrap;
}

.actions-inner {
  display: flex;
  gap: 4px;
}

.action-btn {
  padding: 6px;
  color: #6b7280;
  border-radius: 4px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.action-btn:hover {
  background: #f3f4f6;
  color: #374151;
}

.action-btn[data-action="delete"]:hover {
  background: #fee2e2;
  color: #dc2626;
}

/* History Pagination */
.history-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: #ffffff;
  border-top: 1px solid #e5e5e5;
}

.pagination-info {
  font-size: 13px;
  color: #6b7280;
}

.pagination-buttons {
  display: flex;
  gap: 8px;
}

/* Delete Modal */
.delete-warning {
  margin-bottom: 8px;
  color: #374151;
}

.delete-info {
  font-size: 13px;
  color: #6b7280;
  margin-bottom: 16px;
}

.btn-danger {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: #dc2626;
  color: #ffffff;
  transition: all 0.15s;
}

.btn-danger:hover {
  background: #b91c1c;
}

/* Browse View Layout */
#view-browse {
  display: flex;
  flex: 1;
}

#view-browse.hidden {
  display: none;
}

/* Sidebar */
.drive-sidebar {
  width: 280px;
  background: #ffffff;
  border-right: 1px solid #e5e5e5;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.drive-sidebar.collapsed {
  display: none;
}

.folder-select {
  width: 100%;
  padding: 8px 12px;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #ffffff;
  color: #374151;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.folder-select:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* Override for folder selector in tab bar */
.folder-select.tab-folder-select {
  width: 180px;
  margin-left: auto;
  margin-bottom: 0;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid #e5e5e5;
}

.sidebar-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sidebar-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: #374151;
}

.sort-select {
  padding: 4px 8px;
  font-size: 11px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: #ffffff;
  color: #374151;
  cursor: pointer;
}

.sort-select:focus {
  outline: none;
  border-color: var(--color-primary);
}

.company-filter {
  padding: 8px 12px;
  font-size: 13px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #ffffff;
  color: #374151;
  cursor: pointer;
  min-width: 200px;
}

.company-filter:focus {
  outline: none;
  border-color: var(--color-primary);
}

.search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.search-input:focus {
  border-color: var(--color-primary);
}

.company-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.company-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 13px;
}

.company-item:hover {
  background: #f3f4f6;
}

.company-item.active {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.company-item .folder-icon {
  width: 16px;
  height: 16px;
  color: #9ca3af;
  flex-shrink: 0;
}

.company-item.active .folder-icon {
  color: var(--color-primary);
}

.company-item .company-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.company-item .company-date {
  font-size: 10px;
  color: #9ca3af;
  flex-shrink: 0;
  margin-left: 8px;
}

.company-item.active .company-date {
  color: #f9a8b4;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid #e5e5e5;
}

.btn-all-docs {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: 1px dashed #d1d5db;
  border-radius: 6px;
  background: transparent;
  color: #6b7280;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-all-docs:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
  color: #374151;
}

.btn-all-docs.active {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
  border-style: solid;
  color: var(--color-primary);
}

/* Main Content */
.drive-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: #ffffff;
  border-bottom: 1px solid #e5e5e5;
}

.header-info h1 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 2px;
}

.file-count {
  font-size: 13px;
  color: #6b7280;
}

/* Date Filters */
.date-filters {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: #f3f4f6;
  border-radius: 6px;
  font-size: 12px;
  color: #374151;
}

.date-filters.hidden {
  display: none;
}

.date-filters label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.date-input {
  padding: 4px 8px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 12px;
}

.btn-small {
  padding: 4px 10px !important;
  font-size: 11px !important;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* Drive-specific button overrides (base in shared.css) */
.btn-primary:disabled {
  background: #f9a8b4;
}

.btn-secondary:disabled {
  color: #9ca3af;
}

.btn-icon {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: #6b7280;
  border-radius: 4px;
}

.btn-icon:hover {
  background: #f3f4f6;
  color: #374151;
}

/* Files Container */
.files-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #9ca3af;
}

.empty-state svg {
  margin-bottom: 16px;
}

.empty-state p {
  font-size: 14px;
}

.loading-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: #6b7280;
  font-size: 14px;
}

/* File Tree */
.file-tree {
  font-size: 13px;
}

.tree-item {
  display: flex;
  align-items: flex-start;
  padding: 6px 8px;
  border-radius: 4px;
  margin-bottom: 2px;
}

.tree-item:hover {
  background: #f9fafb;
}

.tree-item.folder {
  font-weight: 500;
  color: #374151;
}

.tree-item.file {
  color: #4b5563;
}

.tree-item.not-extractable {
  color: #9ca3af;
}

.tree-checkbox {
  margin-right: 8px;
  margin-top: 2px;
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.tree-checkbox:disabled {
  cursor: not-allowed;
}

.tree-icon {
  width: 16px;
  height: 16px;
  margin-right: 8px;
  flex-shrink: 0;
}

.tree-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-link {
  color: inherit;
  text-decoration: none;
}

.tree-link:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

.tree-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: 8px;
  font-size: 12px;
  color: #9ca3af;
  flex-shrink: 0;
}

.file-type-badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  background: #f3f4f6;
  color: #6b7280;
}

.file-type-badge.extractable {
  background: #dcfce7;
  color: #166534;
}

/* Uploaded indicator */
.uploaded-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 500;
  background: #dbeafe;
  color: #1e40af;
}

.uploaded-badge svg {
  width: 12px;
  height: 12px;
}

/* Company badge in all docs view */
.company-badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 500;
  background: #f3e8ff;
  color: #7c3aed;
  white-space: nowrap;
}

.indent-1 { padding-left: 24px; }
.indent-2 { padding-left: 48px; }
.indent-3 { padding-left: 72px; }
.indent-4 { padding-left: 96px; }
.indent-5 { padding-left: 120px; }

/* Global Job Bar */
.job-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #1a1a1a;
  color: #e5e5e5;
  z-index: 900;
  font-size: 13px;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.15);
}

.job-bar.hidden {
  display: none;
}

.drive-app.has-job-bar {
  padding-bottom: 40px;
}

.job-bar-collapsed {
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0 16px;
  gap: 16px;
}

.job-bar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-shrink: 1;
}

.job-bar-spinner {
  flex-shrink: 0;
  animation: spin 1s linear infinite;
  color: #60a5fa;
}

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

.job-bar-file {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #d1d5db;
  max-width: 300px;
}

.job-bar-center {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.job-bar-progress-track {
  flex: 1;
  height: 4px;
  background: #374151;
  border-radius: 2px;
  overflow: hidden;
  max-width: 200px;
}

.job-bar-progress-fill {
  height: 100%;
  background: var(--color-primary);
  transition: width 0.3s;
  border-radius: 2px;
}

.job-bar-stats {
  white-space: nowrap;
  color: #9ca3af;
  font-size: 12px;
}

.job-bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.job-bar-elapsed {
  color: #6b7280;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.job-bar-cancel {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid #dc2626;
  color: #f87171;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
}

.job-bar-cancel:hover {
  background: rgba(220, 38, 38, 0.15);
}

.job-bar-toggle {
  display: flex;
  align-items: center;
  padding: 4px;
  background: transparent;
  border: none;
  color: #6b7280;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.15s;
}

.job-bar-toggle:hover {
  color: #d1d5db;
  background: rgba(255, 255, 255, 0.1);
}

.job-bar-toggle.expanded svg {
  transform: rotate(180deg);
}

.job-bar-expanded {
  border-top: 1px solid #374151;
  max-height: 260px;
  overflow: hidden;
}

.job-bar-expanded.hidden {
  display: none;
}

.job-bar-logs {
  max-height: 260px;
  overflow-y: auto;
  padding: 10px 16px;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 11px;
  line-height: 1.6;
  color: #d1d5db;
}

.job-bar-logs .log-line {
  margin-bottom: 1px;
}

.job-bar-logs .log-error {
  color: #f87171;
}

/* Modal (drive-specific overrides — base in shared.css) */
.modal {
  z-index: 2000;
}

.modal-content {
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
}

.progress-info {
  margin-bottom: 16px;
}

.progress-bar {
  height: 8px;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-fill {
  height: 100%;
  background: var(--color-primary);
  transition: width 0.3s;
}

.progress-text {
  text-align: center;
  font-size: 13px;
  color: #6b7280;
}

.progress-logs {
  background: #1a1a1a;
  border-radius: 8px;
  padding: 12px;
  max-height: 200px;
  overflow-y: auto;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 11px;
  line-height: 1.6;
  color: #d1d5db;
}

.progress-logs .log-line {
  margin-bottom: 2px;
}

.progress-logs .log-error {
  color: #f87171;
}

.modal-actions {
  margin-top: 16px;
}

/* Excluded View */
#view-excluded {
  flex-direction: column;
  padding: 0;
}

.excluded-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.excluded-section {
  background: #ffffff;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  padding: 20px;
}

.excluded-section-header {
  margin-bottom: 16px;
}

.excluded-section-header h2 {
  font-size: 15px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 4px;
}

.excluded-section-desc {
  font-size: 13px;
  color: #6b7280;
}

/* Pattern chips */
.pattern-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.no-patterns {
  font-size: 13px;
  color: #9ca3af;
  padding: 8px 0;
}

.pattern-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  color: #92400e;
}

.pattern-text {
  line-height: 1;
}

.pattern-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  color: #92400e;
  border-radius: 50%;
  transition: all 0.15s;
}

.pattern-delete:hover {
  background: rgba(146, 64, 14, 0.15);
}

/* Company exclusion chips */
.company-exclusion-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0;
}

.company-chip {
  background: #e0e7ff;
  border-color: #a5b4fc;
  color: #3730a3;
}

.company-chip .pattern-delete {
  color: #3730a3;
}

.company-chip .pattern-delete:hover {
  background: rgba(55, 48, 163, 0.15);
}

/* Inline exclude-company button next to company badge */
.btn-icon-inline {
  background: none;
  border: none;
  padding: 2px;
  margin-left: 4px;
  cursor: pointer;
  color: #d1d5db;
  border-radius: 4px;
  vertical-align: middle;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

tr:hover .btn-icon-inline,
.btn-icon-inline:focus {
  opacity: 1;
}

.btn-icon-inline:hover {
  color: #3730a3;
}

/* Add pattern row */
.add-pattern-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.add-pattern-row .search-input {
  flex: 1;
  max-width: 400px;
}

/* Failed View */
#view-failed {
  flex-direction: column;
  padding: 0;
}

/* Error type badges */
.error-type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.error-type-badge.unsupported_type {
  background: #f3f4f6;
  color: #6b7280;
}

.error-type-badge.no_text_extracted,
.error-type-badge.too_short,
.error-type-badge.no_chunks {
  background: #fef3c7;
  color: #92400e;
}

.error-type-badge.extraction_error,
.error-type-badge.embedding_mismatch {
  background: #fee2e2;
  color: #991b1b;
}

.error-message-text {
  font-size: 12px;
  color: #6b7280;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Autocomplete dropdown */
.autocomplete-wrapper {
  position: relative;
  flex: 1;
  max-width: 400px;
}

.autocomplete-wrapper .search-input {
  width: 100%;
  max-width: none;
}

.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-top: none;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 100;
}

.autocomplete-dropdown.hidden {
  display: none;
}

.autocomplete-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  color: #374151;
  transition: background 0.1s;
}

.autocomplete-item:hover,
.autocomplete-item.highlighted {
  background: #f3f4f6;
}

.autocomplete-item .company-name {
  font-weight: 500;
}

.autocomplete-item .file-count {
  font-size: 12px;
  color: #9ca3af;
}

.autocomplete-no-results {
  padding: 10px 12px;
  font-size: 13px;
  color: #9ca3af;
  text-align: center;
}

/* Exclude button styling */
.btn-exclude {
  color: #9ca3af !important;
}

.btn-exclude:hover {
  background: #fef3c7 !important;
  color: #92400e !important;
}

/* Restore button */
.restore-btn {
  font-size: 12px;
}

/* Responsive */
@media (max-width: 768px) {
  .drive-sidebar {
    width: 220px;
  }

  .header-actions {
    flex-wrap: wrap;
  }
}
