/* ── Links / Bookmarks ───────────────────────────────────── */

/* ── Combobox (searchable select) ────────────────────────── */
.combobox-wrap {
  position: relative;
}
.combobox-input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  padding-right: 28px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  min-height: 38px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  cursor: text;
}
.combobox-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.combobox-arrow {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  transition: transform var(--transition-fast);
}
.combobox-wrap.open .combobox-arrow { transform: translateY(-50%) rotate(180deg); }

.combobox-dropdown {
  position: fixed;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  max-height: 220px;
  max-width: calc(100vw - 16px);
  overflow-y: auto;
  display: none;
  padding: var(--space-1) 0;
  min-width: 200px;
}
.combobox-wrap.open .combobox-dropdown { display: block; animation: slideUp 0.15s ease; }

.combobox-option {
  display: flex;
  align-items: center;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: var(--font-sans);
  gap: var(--space-2);
}
.combobox-option:hover,
.combobox-option.focused { background: var(--accent-light); color: var(--text-primary); }
.combobox-option.selected { color: var(--accent); font-weight: 500; }
.combobox-option mark { background: rgba(88,101,242,0.2); color: var(--accent); border-radius: 2px; padding: 0; font-weight: 600; font-style: normal; }
.combobox-no-results { padding: var(--space-3); font-size: var(--text-sm); color: var(--text-muted); text-align: center; }
.combobox-create { color: var(--accent); font-style: italic; }

/* ── Tag Autocomplete ─────────────────────────────────────── */
.tag-input-wrap {
  position: relative;
}
.tag-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-bottom: var(--space-2);
  min-height: 0;
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px var(--space-2);
  background: var(--accent-light);
  border: 1px solid rgba(88,101,242,0.3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  color: var(--accent);
  font-weight: 500;
  cursor: default;
}
.tag-chip-remove {
  cursor: pointer;
  color: var(--accent);
  opacity: 0.7;
  display: flex;
  align-items: center;
  line-height: 1;
  background: none;
  border: none;
  padding: 0;
}
.tag-chip-remove:hover { opacity: 1; }

.tag-suggestions {
  position: fixed;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  max-height: 160px;
  max-width: calc(100vw - 16px);
  overflow-y: auto;
  display: none;
  padding: var(--space-1) 0;
  min-width: 200px;
}
.tag-suggestions.open { display: block; animation: slideUp 0.15s ease; }
.tag-suggestion-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast);
  border: none; background: transparent;
  width: 100%; text-align: left; font-family: var(--font-sans);
}
.tag-suggestion-item:hover,
.tag-suggestion-item.focused { background: var(--accent-light); color: var(--text-primary); }
.tag-suggestion-count { font-size: var(--text-xs); color: var(--text-muted); }


.links-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
  min-width: 0;             /* prevent flex item from overflowing parent */
}

/* ── Search bar with icon inside (global) ────────────────── */
.search-bar {
  position: relative;
  display: flex;
  align-items: center;
}
.search-bar .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  display: flex;
  align-items: center;
  z-index: 1;
}
.search-bar .input {
  flex: 1;
  min-width: 0;
  padding-left: 34px;
}
/* Links toolbar — search stretches to fill */
.links-toolbar .search-bar {
  flex: 1;
  min-width: 0;
}

/* ── Shared page toolbar (Notes, Snippets) ────────────────── */
.page-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
  min-width: 0;
}
.page-toolbar .search-bar {
  flex: 1;
  min-width: 0;
}

/* ── Filter bar — horizontal scroll carousel ─────────────── */
.filter-bar-wrap {
  position: relative;
  margin-bottom: var(--space-5);
  overflow: hidden;         /* clipping context so filter-bar can actually scroll */
}
.filter-bar-wrap::before,
.filter-bar-wrap::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 32px;
  pointer-events: none;
  z-index: 1;
}
.filter-bar-wrap::before {
  left: 0;
  background: linear-gradient(to right, var(--bg-primary), transparent);
}
.filter-bar-wrap::after {
  right: 0;
  background: linear-gradient(to left, var(--bg-primary), transparent);
}
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;              /* force it to be exactly the wrapper's width */
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-pill {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  flex-shrink: 0;
  scroll-snap-align: start;
}
.filter-pill:hover,
.filter-pill:focus-visible { border-color: var(--accent); color: var(--accent); }
.filter-pill.active { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.filter-pill-count { background: var(--bg-hover); border-radius: var(--radius-full); padding: 1px 5px; font-size: 10px; }

/* Bulk action bar */
.bulk-bar {
  display: none;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--accent-light);
  border: 1px solid rgba(88,101,242,0.3);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
  animation: slideUp 0.2s ease;
}
.bulk-bar.visible { display: flex; }
.bulk-count { font-size: var(--text-sm); font-weight: 600; color: var(--accent); flex: 1; }
.bulk-actions { display: flex; align-items: center; gap: var(--space-2); }

/* Card Grid */
.links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}
.links-grid.list-view { grid-template-columns: 1fr; gap: var(--space-2); }

/* Bookmark Card */
.bookmark-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  transition: border-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
  position: relative;
  animation: scaleIn 0.2s ease forwards;
  cursor: default;
}
.bookmark-card:hover,
.bookmark-card:focus-within { border-color: var(--bg-hover); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.bookmark-card.selected { border-color: var(--accent); background: var(--accent-light); }
.bookmark-card.dead-link { border-color: rgba(218,55,60,0.4); }

.bookmark-card-header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.bookmark-favicon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  border: 1px solid var(--border);
}
.bookmark-favicon img { width: 20px; height: 20px; object-fit: contain; }

.bookmark-card-meta { flex: 1; min-width: 0; }
.bookmark-title { font-size: var(--text-sm); font-weight: 600; color: var(--text-primary); line-height: 1.4; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.bookmark-category { font-size: var(--text-xs); color: var(--accent); margin-top: 2px; font-weight: 500; }

.bookmark-card-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition-fast);
  flex-shrink: 0;
}
.bookmark-card:hover .bookmark-card-actions,
.bookmark-card:focus-within .bookmark-card-actions { opacity: 1; }

.bookmark-url {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: var(--space-3);
  display: block;
  text-decoration: none;
}
.bookmark-url:hover { color: var(--text-link); }

/* GitHub extra info */
.github-meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-hover);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}
.github-stat { display: flex; align-items: center; gap: 4px; }
.github-lang { display: flex; align-items: center; gap: 4px; }
.lang-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.bookmark-desc {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: var(--space-3);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.bookmark-tags { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.bookmark-tag {
  padding: 2px var(--space-2);
  background: var(--bg-hover);
  border-radius: var(--radius-full);
  font-size: 11px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.bookmark-tag:hover { background: var(--accent-light); color: var(--accent); }

.bookmark-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}
.bookmark-date { font-size: var(--text-xs); color: var(--text-muted); }
.bookmark-open-btn { display: flex; align-items: center; gap: var(--space-1); font-size: var(--text-xs); color: var(--accent); text-decoration: none; font-weight: 500; transition: opacity var(--transition-fast); }
.bookmark-open-btn:hover { opacity: 0.8; }

.dead-link-badge { display: flex; align-items: center; gap: 4px; font-size: var(--text-xs); color: var(--danger); background: var(--danger-light); padding: 2px 6px; border-radius: var(--radius-sm); }

/* List view */
.links-grid.list-view .bookmark-card { border-radius: var(--radius-md); }
.links-grid.list-view .bookmark-card { padding: var(--space-3) var(--space-4); }
.links-grid.list-view .bookmark-card-header { margin-bottom: 0; }
.links-grid.list-view .bookmark-url,
.links-grid.list-view .bookmark-desc,
.links-grid.list-view .bookmark-tags,
.links-grid.list-view .bookmark-footer,
.links-grid.list-view .github-meta { display: none; }
.links-grid.list-view .bookmark-card:hover .bookmark-url { display: block; }

/* Select checkbox */
.bookmark-select {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.bookmark-card.selected .bookmark-select,
.bookmark-card:hover .bookmark-select,
.bookmark-card:focus-within .bookmark-select { opacity: 1; }

/* Pin indicator */
.pin-icon {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  color: var(--warning);
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.bookmark-card.pinned .pin-icon { opacity: 1; }

/* Import dropzone */
.import-dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-12) var(--space-8);
  text-align: center;
  color: var(--text-muted);
  transition: border-color var(--transition-fast), background var(--transition-fast);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}
.import-dropzone:hover,
.import-dropzone.drag-over { border-color: var(--accent); background: var(--accent-light); color: var(--text-secondary); }
.import-dropzone h3 { font-size: var(--text-lg); color: var(--text-secondary); }
.import-dropzone p  { font-size: var(--text-sm); }

/* Duplicate warning */
.dup-warning {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--warning-light);
  border: 1px solid rgba(240,178,50,0.3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--warning);
}
.dup-warning a { color: var(--text-link); text-decoration: underline; }

/* Health check */
.health-bar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.health-progress { flex: 1; height: 6px; background: var(--bg-hover); border-radius: var(--radius-full); overflow: hidden; }
.health-progress-bar { height: 100%; background: var(--accent); border-radius: var(--radius-full); transition: width 0.3s ease; }

@media (max-width: 768px) {
  .page-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .page-toolbar .search-bar {
    flex: unset;
    width: 100%;
  }
  .links-toolbar { flex-wrap: nowrap; }
  .links-toolbar .search-bar { flex: 1; min-width: 0; }
  .bulk-bar { align-items: stretch; flex-direction: column; }
  .bulk-actions { flex-wrap: wrap; }
  .bulk-actions .input { flex: 1 1 160px; }
}
@media (max-width: 640px) {
  .links-grid { grid-template-columns: minmax(0, 1fr); }
  .bookmark-card { padding: var(--space-3); }
  .bookmark-card-actions,
  .bookmark-select { opacity: 1; }
  .bookmark-card-header { align-items: flex-start; }
  .bookmark-url { white-space: normal; overflow-wrap: anywhere; }
  .github-meta,
  .bookmark-footer { flex-wrap: wrap; gap: var(--space-2); }
}

@media (hover: none), (pointer: coarse) {
  .bookmark-card-actions,
  .bookmark-select {
    opacity: 1;
  }
  .bookmark-card:hover {
    transform: none;
  }
}
