@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #f4efe7;
  --surface: #ebe4d8;
  --surface-alt: #f1eadf;
  --surface-hover: #f8f3ed;
  --fg: #1a1816;
  --fg-secondary: #5a5550;
  --fg-tertiary: #8b857e;
  --border: #d9cfc1;
  --border-subtle: #e5dccf;
  --accent: #4548e2;
  --accent-hover: #3d40d1;
  --accent-soft: #e7e8fb;
  --error: #c2410c;
  --focus-ring: rgba(69, 72, 226, 0.45);
  --shadow-card: 0 10px 28px rgba(26, 24, 22, 0.08);
  --sidebar-w: 260px;
  --mobile-nav-h: 64px;
}

/* Mobile-only widgets — hidden by default, revealed in the mobile media query. */
.mobile-nav { display: none; }
.drawer { display: none; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Layout ---------- */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-top { display: flex; flex-direction: column; gap: 16px; }
.sidebar-bottom {
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* brand */
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 4px 12px; }
.brand img { width: 32px; height: 32px; object-fit: contain; border-radius: 6px; }
.brand-text { line-height: 1.1; }
.brand-title { font-size: 15px; font-weight: 600; color: var(--fg); }
.brand-subtitle { font-size: 13px; color: var(--fg-secondary); }

/* sync button */
.sync-btn {
  width: 100%;
  height: 40px;
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 8px;
  font-weight: 500;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  box-shadow: 0 6px 16px rgba(69, 72, 226, 0.22);
}
.sync-btn:hover:not(:disabled) { background: var(--accent-hover); }
.sync-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* user avatar menu (mobile) */
.user-menu-wrap { position: relative; display: none; }
.user-menu-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: white;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  box-shadow: 0 4px 12px rgba(69, 72, 226, 0.22);
  transition: background 0.15s, transform 0.1s;
  padding: 0;
}
.user-menu-btn:hover { background: var(--accent-hover); }
.user-menu-btn:active { transform: scale(0.96); }
.user-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(26, 24, 22, 0.14);
  padding: 6px;
  min-width: 220px;
  z-index: 30;
}
.user-menu-header {
  padding: 10px 12px 12px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 6px;
}
.user-menu-email {
  font-size: 13px;
  font-weight: 500;
  color: var(--fg);
  word-break: break-all;
  line-height: 1.3;
}
.user-menu-role {
  font-size: 11px;
  color: var(--fg-tertiary);
  margin-top: 2px;
}
.user-menu-logout {
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg);
  cursor: pointer;
}
.user-menu-logout:hover { background: var(--surface-hover); color: var(--error); }

.status {
  font-size: 11px;
  color: var(--fg-tertiary);
  padding: 0 4px;
  line-height: 1.4;
  min-height: 14px;
}

/* tag list in sidebar — stacked, not horizontal */
.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.sidebar-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 4px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--fg-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.sidebar-link-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
  padding: 2px 0;
}
.sidebar-link-btn:hover { text-decoration: underline; }
nav.tags,
.collections-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
nav.tags:empty::before {
  content: "No tags yet. Add tags on any pin.";
  font-size: 12px;
  color: var(--fg-tertiary);
  padding: 4px;
  display: block;
}
.collections-nav:empty::before {
  content: "No collections yet.";
  font-size: 12px;
  color: var(--fg-tertiary);
  padding: 4px;
  display: block;
}
.collection-nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--fg);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 12px;
  cursor: pointer;
  text-align: left;
}
.collection-nav-item span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.collection-nav-item span:last-child {
  color: var(--fg-tertiary);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.collection-nav-item:hover { background: var(--surface-hover); }
.collection-nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.chip-wrap {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: 6px;
  transition: background 0.12s;
}
.chip-wrap:hover { background: var(--surface-hover); }
.chip-wrap.active { background: var(--accent-soft); }
.chip {
  flex: 1;
  min-width: 0;
  padding: 7px 12px;
  padding-right: 28px;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg);
  text-decoration: none;
  border-radius: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip-wrap.active .chip { color: var(--accent); }
.chip-del {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 0;
  color: var(--fg-tertiary);
  font-size: 15px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  opacity: 0;
  transition: opacity 0.12s, background 0.12s, color 0.12s;
}
.chip-wrap:hover .chip-del,
.chip-del:focus { opacity: 1; }
.chip-del:hover { background: #fde0d1; color: var(--error); }

/* user at bottom */
.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
}
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  text-transform: uppercase;
}
.user-meta {
  flex: 1;
  min-width: 0;
  line-height: 1.25;
}
.user-email {
  font-size: 13px;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
.user-role { font-size: 11px; color: var(--fg-tertiary); }
.logout {
  width: 100%;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg-secondary);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.15s;
}
.logout:hover { background: var(--surface-hover); color: var(--fg); }

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

.topbar {
  display: flex;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.search { display: flex; gap: 8px; flex: 1; max-width: 640px; }
.search input {
  flex: 1;
  height: 40px;
  padding: 0 14px;
  background: white;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search input::placeholder { color: var(--fg-tertiary); }
.search input:focus {
  outline: none; border-color: var(--fg);
  box-shadow: 0 0 0 2px var(--focus-ring);
}
.search button {
  height: 40px;
  padding: 0 18px;
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}
.search button:hover { background: var(--accent-hover); }
.clear {
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  color: var(--fg-tertiary);
  text-decoration: none;
  font-size: 13px;
}
.sort-btn, .process-btn, .upload-btn {
  margin-left: 12px;
  height: 40px;
  padding: 0 14px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.sort-btn:hover { background: var(--surface-hover); }
.upload-btn {
  background: var(--fg);
  color: white;
  border-color: var(--fg);
}
.upload-btn:hover { background: #2b2825; border-color: #2b2825; }
.process-btn {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-soft);
}
.process-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }
.topbar-muted .search, .topbar-muted .sort-btn { opacity: 0.5; pointer-events: none; }

.filter-panel {
  padding: 12px 24px 14px;
  border-bottom: 1px solid var(--border-subtle);
  background: color-mix(in srgb, var(--bg) 92%, white);
}
.filter-grid {
  display: grid;
  grid-template-columns: minmax(130px, 0.8fr) minmax(180px, 1.35fr) minmax(132px, 0.8fr) minmax(132px, 0.8fr) minmax(160px, 0.95fr);
  gap: 10px;
  align-items: end;
}
.filter-field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-tertiary);
}
.filter-field select,
.filter-field input {
  width: 100%;
  min-width: 0;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--fg);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  padding: 0 10px;
}
.filter-field input::placeholder { color: var(--fg-tertiary); }
.filter-field select:focus,
.filter-field input:focus {
  outline: none;
  border-color: var(--fg);
  box-shadow: 0 0 0 2px var(--focus-ring);
}
.filter-foot {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}
.results-summary {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  color: var(--fg-tertiary);
  font-size: 12.5px;
  white-space: nowrap;
}
.active-filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
  min-width: 0;
}
.active-filter {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 240px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.active-filter span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.active-filter:hover {
  border-color: var(--fg);
  color: var(--fg);
}
.empty-results {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  max-width: 520px;
  margin: 40px auto;
  line-height: 1.5;
}
.empty-results strong {
  color: var(--fg);
  font-size: 15px;
}
.empty-clear-filters {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}
.empty-clear-filters:hover { background: var(--surface-hover); }

@media (max-width: 1180px) {
  .filter-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .filter-field-wide { grid-column: span 2; }
  .filter-foot {
    align-items: stretch;
    flex-direction: column;
  }
  .active-filters { justify-content: flex-start; }
}

/* ---------- Infinite scroll sentinel ---------- */
.scroll-sentinel {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 72px;
  padding: 20px 16px 40px;
}
.scroll-spinner {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.scroll-end {
  font-size: 12px;
  color: var(--fg-tertiary);
  letter-spacing: 0.02em;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Grid ----------
   Columns are built in JS (see app.js), not with CSS column-count, so new
   cards appended at the bottom never reshuffle the cards already placed. */
.grid {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 16px;
  padding: 20px 24px;
}
.grid-col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-card);
  transition: box-shadow 0.2s;
}
.card:hover { box-shadow: 0 14px 34px rgba(26, 24, 22, 0.12); }
.card .img { display: block; background: var(--bg); position: relative; }
.card img { width: 100%; height: auto; display: block; }
.card video { width: 100%; height: auto; display: block; background: #000; }
.card .img--video { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.video-audio {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 50%;
  background: rgba(20, 18, 15, 0.78);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.video-audio:hover { background: rgba(20, 18, 15, 0.95); }
.video-audio:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.video-audio[data-muted="true"] .video-audio__playing,
.video-audio[data-muted="false"] .video-audio__muted { display: none; }
.play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease;
}
.play-overlay__icon,
.play-overlay__loading { display: none; align-items: center; justify-content: center; }
.play-overlay__loading { flex-direction: column; gap: 8px; }
/* Default paused state shows nothing — the card reads as a plain thumbnail
   so the Videos tab feels just like the Images tab while you're browsing. */
.img--video.is-user-paused .play-overlay { opacity: 1; }
.img--video.is-user-paused .play-overlay__icon { display: flex; }
.img--video.is-loading .play-overlay { opacity: 1; }
.img--video.is-loading .play-overlay__loading { display: flex; }
/* When loading and the user-paused tag both race, loading wins (the
   spinner is the more informative state). */
.img--video.is-loading.is-user-paused .play-overlay__icon { display: none; }
.play-overlay__icon svg {
  width: 56px;
  height: 56px;
  color: #fff;
  background: rgba(20, 18, 15, 0.55);
  border-radius: 50%;
  padding: 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.play-spinner {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.28);
  border-top-color: #fff;
  animation: spin 0.85s linear infinite;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
}
.play-loading-text {
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
  background: rgba(20, 18, 15, 0.45);
  padding: 3px 10px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.media-badge {
  position: absolute;
  top: 8px; left: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: rgba(20, 18, 15, 0.78);
  color: #fff;
  font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.04em;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}
.media-badge--video { font-size: 11px; padding-left: 8px; padding-right: 8px; }
.media-badge--hls { background: rgba(194, 65, 12, 0.86); }
.media-badge--gif { background: rgba(69, 72, 226, 0.86); }
.meta { padding: 12px 14px; }
.title {
  font-size: 14px; font-weight: 500; line-height: 1.4;
  color: var(--fg); margin-bottom: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.board { font-size: 12px; color: var(--fg-tertiary); margin-bottom: 10px; }
.tags-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  margin: 10px 0;
  align-items: center;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
.tags-row::-webkit-scrollbar { height: 4px; }
.tags-row::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.tags-row::-webkit-scrollbar-track { background: transparent; }

.tag-chip {
  flex: 0 0 auto;
  display: inline-flex; align-items: center;
  background: white;
  color: var(--fg-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 11px;
  font-size: 11px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.tag-chip:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.tag-chip.selected {
  background: #dff5e3;
  color: #1e6b31;
  border-color: #86ddaa;
}
.tag-chip.selected:hover:not(:disabled) {
  background: #c9eed2;
  border-color: #5bc082;
  color: #17572a;
}
.tag-chip:disabled { opacity: 0.6; cursor: wait; }
.tag-chip { gap: 0; }
.tag-chip-text { display: inline-block; }
.tag-chip-del {
  display: inline-flex; align-items: center; justify-content: center;
  width: 0; height: 14px;
  margin-left: 0;
  border-radius: 999px;
  overflow: hidden;
  opacity: 0;
  font-size: 13px;
  line-height: 1;
  color: var(--error, #c0392b);
  transition: width 0.15s ease, margin-left 0.15s ease, opacity 0.15s ease, background 0.12s;
  cursor: pointer;
  user-select: none;
  pointer-events: none;
}
.tag-chip.show-delete { padding-right: 4px; }
.tag-chip.show-delete .tag-chip-del {
  width: 14px;
  margin-left: 4px;
  opacity: 1;
  pointer-events: auto;
  background: rgba(192, 57, 43, 0.12);
}
.tag-chip.show-delete .tag-chip-del:hover {
  background: rgba(192, 57, 43, 0.24);
  color: #8a2317;
}
.ai-tag-chip {
  background: transparent;
  color: var(--fg-tertiary, #888);
  border-style: dashed;
  font-style: italic;
  cursor: default;
}
.ai-tag-chip:hover { color: var(--fg-tertiary, #888); border-color: var(--border); }

.tag-add {
  flex: 0 0 auto;
  display: inline-flex; align-items: center;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--fg-tertiary);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.6;
  transition: border-color 0.15s, color 0.15s;
}
.tag-add:hover { border-color: var(--fg); color: var(--fg); }

.tag-add-input {
  flex: 0 0 auto;
  background: white;
  border: 1px solid var(--accent);
  color: var(--fg);
  border-radius: 999px;
  padding: 3px 11px;
  font-size: 11px;
  font-family: inherit;
  outline: none;
  min-width: 160px;
  box-shadow: 0 0 0 2px var(--focus-ring);
}
.tag-add-input::placeholder { color: var(--fg-tertiary); }
.collections-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  align-items: center;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
  margin: 2px 0 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.collections-row:empty { display: none; }
.collection-chip,
.collection-add {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 10px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  cursor: pointer;
}
.collection-chip {
  background: #fff8dc;
  border: 1px solid #eadc90;
  color: #6d5b00;
}
.collection-chip.selected {
  background: #fff1a8;
  border-color: #dfc747;
  color: #493d00;
}
.collection-chip:hover:not(:disabled) {
  border-color: var(--fg);
  color: var(--fg);
}
.collection-chip:disabled { opacity: 0.6; cursor: wait; }
.collection-add {
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--fg-tertiary);
}
.collection-add:hover { border-color: var(--fg); color: var(--fg); }
.collection-add-select {
  flex: 0 0 auto;
  max-width: 180px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: white;
  color: var(--fg);
  font-family: inherit;
  font-size: 11px;
  padding: 4px 10px;
  outline: none;
}
.row {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
  gap: 10px;
}
.row-actions { display: inline-flex; align-items: center; gap: 12px; }
.src { font-size: 11px; color: var(--fg-tertiary); text-decoration: none; }
.src:hover { color: var(--accent); }
.del, .describe, .copy-gcs, .open-detail {
  background: none; border: 0; padding: 0;
  cursor: pointer;
  font-size: 12px; font-weight: 500; font-family: inherit;
}
.open-detail { color: var(--fg); }
.open-detail:hover { color: var(--accent); text-decoration: underline; }
.del { color: var(--error); }
.del:hover { text-decoration: underline; }
.describe { color: var(--accent); }
.describe:hover:not(:disabled) { text-decoration: underline; }
.describe:disabled { color: var(--fg-tertiary); cursor: not-allowed; }
.copy-gcs { color: var(--fg-tertiary); }
.copy-gcs.generated { color: var(--accent); }
.copy-gcs:hover:not(:disabled) { color: var(--accent); text-decoration: underline; }
.copy-gcs:disabled { cursor: default; }
.empty {
  padding: 80px 24px; text-align: center;
  color: var(--fg-tertiary); font-size: 14px;
  /* The grid is now a flex row; let the empty placeholder span the full width. */
  flex: 1 1 100%;
  width: 100%;
}

/* ---------- Mobile layout: hide sidebar + topbar, show bottom nav ---------- */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { display: none; }
  .topbar { display: none; }
  .filter-panel { display: none; }
  .main {
    padding-bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom, 0px) + 8px);
  }
  .grid { padding: 12px 14px; }
  .scroll-sentinel { padding: 16px 12px 32px; }
  .tasks-view { padding: 16px; }
  .task-meta { gap: 10px; }
  .task-counts { gap: 10px; font-size: 11.5px; }
  .tasks-header h2 { font-size: 17px; }
  .tasks-sub { font-size: 12px; }
  .tasks-header { flex-direction: column; }
  .tasks-header .btn-secondary { width: 100%; min-height: 44px; }
  .activity-summary { grid-template-columns: 1fr; }
  .activity-tabs { width: 100%; }
  .activity-tab { min-height: 44px; }
  .task-head { align-items: flex-start; gap: 10px; }
  .task-actions { justify-content: stretch; }
  .task-actions .btn-secondary { flex: 1; min-height: 40px; }
  .sync-run-counts { gap: 10px; font-size: 11.5px; }
  .dialog-body { padding: 18px 16px 16px; }
  .dialog-body-wide { max-width: 100%; }
  .description-content { font-size: 11.5px; padding: 12px 14px; max-height: 55vh; }
  .mobile-nav { display: flex; }
}

/* ---------- Mobile bottom nav — always pinned to the viewport's bottom edge ---------- */
.mobile-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  /* explicit reset of top/transform so nothing can push the bar upward */
  top: auto;
  transform: none;
  height: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(244, 239, 231, 0.94);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--border-subtle);
  z-index: 60;
  align-items: stretch;
  /* hardware-accelerated so iOS Safari's collapsing chrome doesn't jitter it */
  will-change: transform;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  -webkit-transform: translateZ(0);
  /* keep the bar visible even when page is rubber-band-scrolled past its edges */
  contain: layout paint;
}
.mobile-nav-item {
  flex: 1;
  position: relative;
  background: transparent;
  border: 0;
  font-family: inherit;
  color: var(--fg-tertiary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 4px 2px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s, transform 0.08s;
}
.mobile-nav-item svg { opacity: 0.85; transition: opacity 0.15s, transform 0.15s; }
.mobile-nav-item span:not(.nav-badge) { font-size: 10.5px; font-weight: 500; letter-spacing: 0.01em; line-height: 1.1; }
.mobile-nav-item.active { color: var(--accent); }
.mobile-nav-item.active svg { opacity: 1; transform: translateY(-1px); }
.mobile-nav-item:active { transform: scale(0.95); }
.mobile-nav-badge {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(4px);
  font-size: 10px;
  padding: 0 5px;
  min-width: 16px;
  line-height: 1.6;
}

/* ---------- Bottom-sheet drawer (opens above the mobile nav) ---------- */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 24, 22, 0.44);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: fadeInOverlay 0.18s ease;
}
.drawer-sheet {
  position: relative;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  max-height: calc(100vh - 64px - var(--mobile-nav-h) - env(safe-area-inset-bottom, 0px));
  max-height: calc(100dvh - 64px - var(--mobile-nav-h) - env(safe-area-inset-bottom, 0px));
  margin-bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -16px 42px rgba(26, 24, 22, 0.2);
  display: flex;
  flex-direction: column;
  animation: drawerSlideUp 0.22s cubic-bezier(0.2, 0.8, 0.25, 1);
  overflow: hidden;
}
@keyframes drawerSlideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.drawer-handle {
  width: 44px;
  height: 4px;
  background: var(--border);
  border: 0;
  border-radius: 999px;
  margin: 10px auto 2px;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  display: block;
}
.drawer-content {
  overflow-y: auto;
  padding: 10px 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  -webkit-overflow-scrolling: touch;
}
.drawer-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 2px 14px;
  border-bottom: 1px solid var(--border-subtle);
}
.drawer-user .user-avatar {
  width: 44px;
  height: 44px;
  font-size: 16px;
}
.drawer-user-meta { flex: 1; min-width: 0; line-height: 1.25; }
.drawer-user-email {
  font-size: 14px;
  font-weight: 500;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.drawer-user-role { font-size: 11px; color: var(--fg-tertiary); margin-top: 2px; }
.drawer-logout {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-secondary);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.drawer-logout:hover, .drawer-logout:active { background: var(--surface-hover); color: var(--error); }

.drawer-section { display: flex; flex-direction: column; gap: 8px; }
.drawer-label {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--fg-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 2px;
}
.drawer-active-tag {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}
.drawer-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  color: var(--fg);
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.drawer-action:hover { background: var(--surface-hover); }
.drawer-action:active { transform: scale(0.995); }
.drawer-action-label { font-weight: 500; }
.drawer-action-value { font-size: 13px; color: var(--fg-tertiary); }
.drawer-action-chev { color: var(--fg-tertiary); font-size: 22px; line-height: 1; font-weight: 400; }
.drawer-action-right { display: inline-flex; align-items: center; gap: 10px; }

.drawer-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.drawer-tags:empty::before {
  content: "No tags yet. Add tags on any pin from its card.";
  font-size: 12.5px;
  color: var(--fg-tertiary);
  padding: 2px;
}
.drawer-collections:empty::before {
  content: "No collections yet.";
}
.drawer-tag {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 8px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.drawer-tag:active { transform: scale(0.97); }
.drawer-tag.active {
  background: var(--accent-soft);
  border-color: var(--accent-soft);
  color: var(--accent);
}

.drawer-status {
  background: var(--surface-alt);
  border: 1px solid var(--border-subtle);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 12.5px;
  color: var(--fg-secondary);
  line-height: 1.5;
  white-space: pre-line;
  min-height: 40px;
}

body.drawer-open { overflow: hidden; }

/* ---------- Sync view (mobile tab) ---------- */
.sync-view {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 28px 18px 16px;
}
.sync-card {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.sync-brand { display: flex; align-items: center; gap: 14px; }
.sync-brand img { width: 46px; height: 46px; border-radius: 10px; object-fit: contain; }
.sync-brand-title { font-size: 18px; font-weight: 600; color: var(--fg); line-height: 1.2; }
.sync-brand-subtitle { font-size: 13px; color: var(--fg-secondary); margin-top: 3px; line-height: 1.4; }
.sync-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.sync-stat {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 12px 8px;
  text-align: center;
}
.sync-stat-label {
  font-size: 10px;
  color: var(--fg-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
  font-weight: 600;
}
.sync-stat-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  word-break: break-word;
  line-height: 1.2;
}
.sync-big-btn {
  height: 54px;
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 12px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(69, 72, 226, 0.24);
  transition: background 0.15s, transform 0.08s;
}
.sync-big-btn:hover:not(:disabled) { background: var(--accent-hover); }
.sync-big-btn:active:not(:disabled) { transform: scale(0.98); }
.sync-big-btn:disabled { opacity: 0.65; cursor: not-allowed; }
.sync-view-status {
  font-size: 13px;
  color: var(--fg-secondary);
  text-align: center;
  min-height: 18px;
  line-height: 1.45;
}

/* ---------- Search view (mobile tab) ---------- */
.search-view {
  padding: 14px 14px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 4;
}
.mobile-search {
  display: flex;
  align-items: center;
  gap: 10px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 12px;
  height: 46px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.mobile-search:focus-within {
  border-color: var(--fg);
  box-shadow: 0 0 0 2px var(--focus-ring);
}
.mobile-search-icon { color: var(--fg-tertiary); flex-shrink: 0; }
.mobile-search input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: none;
  font-family: inherit;
  font-size: 16px;
  color: var(--fg);
  min-width: 0;
  padding: 0;
}
.mobile-search input::placeholder { color: var(--fg-tertiary); }
.mobile-search-clear {
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--fg-tertiary);
  cursor: pointer;
  padding: 4px 8px;
  font-family: inherit;
}
.mobile-search-clear:hover { color: var(--fg); }
.mobile-search-hint {
  margin-top: 10px;
  font-size: 12px;
  color: var(--fg-tertiary);
  padding: 0 2px;
}
.mobile-filter-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}
.mobile-filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.mobile-filter-full { grid-column: 1 / -1; }
.mobile-filter-panel .filter-field select,
.mobile-filter-panel .filter-field input {
  height: 44px;
  font-size: 14px;
}
.mobile-filter-panel .results-summary {
  min-height: 22px;
}
.mobile-filter-panel .active-filters {
  justify-content: flex-start;
}

/* ---------- Tag scope chooser dialog ---------- */
.dialog-body-compact { max-width: 380px; }
.tag-scope-name {
  color: var(--accent);
  font-weight: 600;
}
.tag-scope-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
.tag-scope-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 22px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}
.tag-scope-btn svg { color: var(--fg-secondary); transition: color 0.15s; }
.tag-scope-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.tag-scope-btn:hover svg { color: var(--accent); }
.tag-scope-btn:active { transform: scale(0.98); }

/* ---------- Sidebar nav (Pins / Tasks) ---------- */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}
.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-secondary);
  text-decoration: none;
  border-radius: 6px;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--surface-hover); color: var(--fg); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-badge {
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
  line-height: 1.4;
}

/* ---------- Reference detail overlay ---------- */
body.detail-open { overflow: hidden; }
.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: flex;
  justify-content: flex-end;
  padding: 16px;
}
.detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 24, 22, 0.48);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.detail-panel {
  position: relative;
  width: min(1180px, calc(100vw - 32px));
  height: calc(100vh - 32px);
  height: calc(100dvh - 32px);
  background: white;
  border-radius: 12px;
  box-shadow: 0 28px 80px rgba(26, 24, 22, 0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.detail-top {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.detail-nav { display: inline-flex; align-items: center; gap: 6px; }
.detail-icon-btn,
.detail-close {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--fg);
  font-family: inherit;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.detail-icon-btn:hover:not(:disabled),
.detail-close:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }
.detail-icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.detail-loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-tertiary);
  font-size: 14px;
}
.detail-content {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(320px, 1.12fr) minmax(380px, 0.88fr);
  overflow: hidden;
}
.detail-media-column {
  min-width: 0;
  min-height: 0;
  background: #171513;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}
.detail-media {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  position: relative;
}
.detail-media img,
.detail-media video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
  object-fit: contain;
  border-radius: 8px;
  background: #000;
}
.detail-poster-only {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.detail-poster-note {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(26, 24, 22, 0.78);
  color: white;
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
}
.detail-media-error {
  flex-shrink: 0;
  padding: 10px 14px;
  background: #fde0d1;
  color: var(--error);
  font-size: 12px;
  text-align: center;
}
.detail-info {
  min-width: 0;
  overflow-y: auto;
  padding: 20px 22px 24px;
}
.detail-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.detail-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.detail-input,
.detail-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--fg);
  font-family: inherit;
  font-size: 14px;
  padding: 9px 11px;
  resize: vertical;
}
.detail-input { height: 38px; }
.detail-textarea { min-height: 86px; line-height: 1.45; }
.detail-note { min-height: 112px; }
.detail-input:focus,
.detail-textarea:focus {
  outline: none;
  border-color: var(--fg);
  box-shadow: 0 0 0 2px var(--focus-ring);
}
.detail-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}
.detail-save-state {
  margin-right: auto;
  min-height: 18px;
  font-size: 12px;
  color: var(--fg-tertiary);
}
.detail-section {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border-subtle);
}
.detail-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.detail-section-head h4 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--fg);
}
.detail-section-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.detail-tags,
.detail-collections {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.detail-collections .collection-chip {
  font-size: 12px;
  padding: 5px 12px;
}
.detail-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.detail-fact {
  min-width: 0;
  padding: 10px 11px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--surface-alt);
}
.detail-fact span {
  display: block;
  font-size: 10px;
  font-weight: 700;
  color: var(--fg-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 3px;
}
.detail-fact strong {
  display: block;
  min-width: 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.detail-copy-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.detail-source-history {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 10px;
}
.detail-source-link {
  display: block;
  min-width: 0;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: white;
  color: var(--fg);
  text-decoration: none;
}
.detail-source-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.detail-source-link span {
  display: block;
  font-size: 10px;
  font-weight: 700;
  color: var(--fg-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 2px;
}
.detail-source-link strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 500;
}
.detail-copy-grid .btn-secondary,
.detail-section-actions .btn-secondary {
  padding: 0 11px;
  font-size: 12px;
}
/* Take: what the reference was saved for (app/takes.py). Rows follow .detail-source-link. */
.detail-take-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.detail-take-ask,
.detail-take-wait {
  margin: 0;
  font-size: 13px;
  color: var(--fg-secondary);
}
.detail-take-wait { color: var(--fg-tertiary); }
.detail-take-option {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: white;
  color: var(--fg);
  font: inherit;
  text-align: left;
}
button.detail-take-option { cursor: pointer; transition: border-color 0.12s; }
button.detail-take-option:hover:not(:disabled) { border-color: var(--accent); }
button.detail-take-option:disabled { opacity: 0.6; cursor: wait; }
.detail-take-option span {
  display: block;
  font-size: 10px;
  font-weight: 700;
  color: var(--fg-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 2px;
}
.detail-take-option strong {
  display: block;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.45;
}
.detail-take-option small,
.detail-take-option em {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  font-style: normal;
  line-height: 1.4;
  color: var(--fg-tertiary);
}
.detail-take-option em { color: var(--fg-secondary); }
.detail-take-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.detail-take-actions .btn-primary,
.detail-take-actions .btn-secondary {
  padding: 0 11px;
  font-size: 12px;
}
.detail-take-state,
.detail-take-failed {
  font-size: 12px;
  color: var(--fg-tertiary);
}
.detail-take-failed { font-size: 13px; color: var(--error); }

.detail-empty-state {
  padding: 14px;
  border-radius: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border-subtle);
  color: var(--fg-tertiary);
  font-size: 13px;
}
.detail-ai-json {
  margin: 0;
  max-height: 320px;
  overflow: auto;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--surface-alt);
  padding: 13px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--fg);
}

/* ---------- Dialog / modal ---------- */
body.dialog-open { overflow: hidden; }
.dialog {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 16px;
}
.dialog-backdrop {
  position: absolute; inset: 0;
  background: rgba(26, 24, 22, 0.42);
  backdrop-filter: blur(2px);
}
.dialog-body {
  position: relative;
  background: white;
  border-radius: 12px;
  box-shadow: 0 24px 64px rgba(26, 24, 22, 0.24);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow: auto;
  padding: 20px 22px 18px;
}
.dialog-body-wide { max-width: 760px; }
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.dialog-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
}
.dialog-close {
  background: none; border: 0; cursor: pointer;
  font-size: 22px; line-height: 1; color: var(--fg-tertiary);
  padding: 4px 8px; border-radius: 6px;
  font-family: inherit;
}
.dialog-close:hover { background: var(--surface-hover); color: var(--fg); }
.dialog-p { font-size: 13px; color: var(--fg-secondary); line-height: 1.55; margin: 0 0 14px; }
.dialog-label { display: block; font-size: 12px; color: var(--fg-secondary); margin-bottom: 6px; font-weight: 500; }
.dialog-select {
  width: 100%; height: 38px; padding: 0 12px;
  background: white; color: var(--fg);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit;
}
.dialog-select-spaced { margin-bottom: 12px; }
.dialog-input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  background: white;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 12px;
}
.dialog-input::placeholder { color: var(--fg-tertiary); }
.dialog-select:focus, .dialog-input:focus { outline: none; border-color: var(--fg); box-shadow: 0 0 0 2px var(--focus-ring); }
.dialog-hint { font-size: 12px; color: var(--fg-tertiary); min-height: 16px; margin-top: 8px; }
.process-scope-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  margin: 0 0 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--surface-alt);
}
.process-scope-option {
  min-height: 44px;
  cursor: pointer;
}
.process-scope-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.process-scope-option span {
  width: 100%;
  height: 100%;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  color: var(--fg-secondary);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.process-scope-option input:checked + span {
  background: var(--surface);
  color: var(--fg);
  box-shadow: var(--shadow-soft);
}
.process-scope-option input:focus-visible + span {
  box-shadow: 0 0 0 2px var(--focus-ring), var(--shadow-soft);
}
.dialog-actions {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  margin-top: 18px;
}

/* ---------- Upload dialog ---------- */
.upload-form { display: flex; flex-direction: column; }
.upload-mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  margin-bottom: 14px;
}
.upload-mode-btn {
  height: 34px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--fg-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.upload-mode-btn.active {
  background: white;
  color: var(--fg);
  box-shadow: 0 3px 10px rgba(26, 24, 22, 0.08);
}
.upload-panel { margin-bottom: 14px; }
.upload-drop {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-height: 116px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--surface-alt);
  padding: 18px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.upload-drop:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.upload-drop-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  overflow-wrap: anywhere;
}
.upload-drop-meta {
  font-size: 12px;
  color: var(--fg-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.upload-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.btn-primary, .btn-secondary {
  height: 36px; padding: 0 16px;
  border-radius: 8px; font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.btn-primary { background: var(--accent); color: white; border: 0; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary { background: white; color: var(--fg); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-hover); }
.btn-secondary:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------- Collection manager ---------- */
.collection-create-form {
  display: grid;
  grid-template-columns: minmax(160px, 0.8fr) minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: start;
}
.collection-create-form .dialog-input { margin-bottom: 0; }
.collection-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}
.collection-empty {
  padding: 34px 16px;
  background: var(--surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
}
.collection-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--surface-alt);
}
.collection-card-main {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(140px, 0.8fr) minmax(140px, 1fr);
  gap: 8px;
}
.collection-card-name,
.collection-card-description {
  min-width: 0;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: white;
  color: var(--fg);
  font-family: inherit;
  font-size: 13px;
  padding: 0 10px;
}
.collection-card-name:focus,
.collection-card-description:focus {
  outline: none;
  border-color: var(--fg);
  box-shadow: 0 0 0 2px var(--focus-ring);
}
.collection-card-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
  min-width: 92px;
  font-size: 11.5px;
  color: var(--fg-tertiary);
}
.collection-status {
  display: inline-flex;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #dff5e3;
  color: #1e6b31;
}
.collection-status.archived {
  background: #ece7df;
  color: var(--fg-tertiary);
}
.collection-card-actions {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.collection-card-actions .btn-secondary {
  height: 32px;
  padding: 0 10px;
  font-size: 12px;
}
.description-content {
  background: var(--surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 14px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  color: var(--fg);
  max-height: 60vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}
.copy-flash {
  font-size: 12px; color: var(--accent); font-weight: 500;
  margin-right: auto;
}

/* ---------- Description regenerate loading ---------- */
.description-stage { position: relative; }
.description-content.is-blurred {
  filter: blur(4px) saturate(0.85);
  opacity: 0.55;
  transition: filter 0.25s ease, opacity 0.25s ease;
  pointer-events: none;
}
.description-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(244, 239, 231, 0.86), rgba(231, 232, 251, 0.86));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 2;
  animation: fadeInOverlay 0.25s ease;
}
@keyframes fadeInOverlay {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}
.loader-orb {
  position: relative;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.loader-orb-pulse {
  position: absolute;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 24px rgba(69, 72, 226, 0.55);
  animation: orbPulse 1.4s ease-in-out infinite;
}
.loader-orb-ring {
  position: absolute;
  width: 100%; height: 100%;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  animation: orbRing 2.0s cubic-bezier(0.2, 0.7, 0.3, 1) infinite;
}
.loader-orb-ring--lag { animation-delay: 1.0s; }
@keyframes orbPulse {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%      { transform: scale(0.7); opacity: 0.6; }
}
@keyframes orbRing {
  0%   { transform: scale(0.4); opacity: 0.7; }
  100% { transform: scale(1.4); opacity: 0; }
}
.loader-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: -0.01em;
}
.loader-step {
  font-size: 12.5px;
  color: var(--fg-secondary);
  font-variant-numeric: tabular-nums;
  min-height: 18px;
  transition: opacity 0.18s ease;
  text-align: center;
}
.loader-bar {
  width: min(280px, 70%);
  height: 3px;
  background: rgba(69, 72, 226, 0.12);
  border-radius: 999px;
  overflow: hidden;
}
.loader-bar > span {
  display: block;
  width: 38%;
  height: 100%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  border-radius: 999px;
  animation: loaderSlide 1.6s ease-in-out infinite;
}
@keyframes loaderSlide {
  0%   { transform: translateX(-110%); }
  100% { transform: translateX(310%); }
}
.loader-hint {
  font-size: 11.5px;
  color: var(--fg-tertiary);
  margin-top: 2px;
}

/* ---------- Shared sync settings ---------- */
.settings-view { padding: 32px; max-width: 920px; }
.settings-header { margin-bottom: 28px; }
.settings-header h1 { margin: 0 0 6px; font-size: 28px; font-weight: 600; letter-spacing: -0.04em; }
.settings-header p { margin: 0; color: var(--fg-secondary); font-size: 14px; }
.settings-panel { padding: 28px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-alt); }
.settings-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.settings-eyebrow { margin: 0 0 5px; color: var(--fg-secondary); font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; }
.settings-panel h2 { margin: 0; font-size: 21px; font-weight: 600; letter-spacing: -0.025em; }
.settings-state { flex-shrink: 0; padding: 5px 10px; border-radius: 6px; background: var(--surface); color: var(--fg-secondary); font-size: 12px; font-weight: 500; }
.settings-state[data-kind="active"] { background: #e0ecdf; color: #29542e; }
.settings-state[data-kind="warning"] { background: #f8e5d7; color: #8c3d10; }
.settings-description { max-width: 540px; margin: 14px 0 26px; color: var(--fg-secondary); font-size: 14px; }
.settings-fields { display: grid; grid-template-columns: minmax(140px, 0.7fr) minmax(0, 1.3fr); gap: 24px; padding: 0; margin: 0; border: 0; min-width: 0; }
.settings-fields legend { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.settings-field { display: flex; flex-direction: column; gap: 8px; min-width: 0; font-size: 13px; font-weight: 600; }
.settings-field input, .settings-field select { width: 100%; min-width: 0; height: 46px; padding: 0 12px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); color: var(--fg); font: inherit; font-size: 15px; font-weight: 400; }
.settings-field small { color: var(--fg-secondary); font-size: 12px; font-weight: 400; }
.settings-field :is(input, select):focus-visible, .settings-view button:focus-visible, .settings-activity-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.settings-next { display: flex; flex-direction: column; gap: 6px; margin-top: 28px; padding: 20px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.settings-next > span { font-size: 12px; color: var(--fg-secondary); }
.settings-next strong { font-size: 18px; font-weight: 500; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.settings-next p { margin: 0; font-size: 12px; color: var(--fg-secondary); }
.settings-actions { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-top: 22px; }
.settings-actions p { margin: 0; max-width: 280px; color: var(--fg-secondary); font-size: 12px; }
.settings-actions .btn-primary { height: 44px; flex-shrink: 0; }
.settings-feedback { display: flex; align-items: center; gap: 14px; }
.settings-feedback p { margin: 14px 0 0; font-size: 13px; color: var(--fg-secondary); }
.settings-feedback p:empty { display: none; }
.settings-feedback [data-kind="error"] { color: var(--error); }
.settings-feedback [data-kind="success"] { color: #29542e; }
.settings-feedback button { margin-top: 14px; flex-shrink: 0; }
.settings-activity-link { display: inline-flex; gap: 10px; align-items: center; margin-top: 22px; min-height: 44px; font-size: 13px; color: var(--accent); text-decoration: none; }
.settings-activity-link:hover { text-decoration: underline; }
@media (max-width: 600px) {
  .settings-view { padding: 22px 16px; }
  .settings-header { margin-bottom: 22px; }
  .settings-panel { padding: 20px; }
  .settings-panel-head { align-items: flex-start; gap: 10px; }
  .settings-state { font-size: 11px; }
  .settings-fields { grid-template-columns: 1fr; gap: 20px; }
  .settings-field input, .settings-field select { font-size: 16px; }
  .settings-next strong { font-size: 16px; }
  .settings-actions { flex-direction: column; align-items: stretch; gap: 16px; }
  .settings-actions p { max-width: none; }
}

/* ---------- Tasks view ---------- */
.tasks-view { padding: 24px; }
.tasks-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.tasks-header h2 { margin: 0 0 4px; font-size: 20px; font-weight: 600; color: var(--fg); }
.tasks-sub { margin: 0; font-size: 13px; color: var(--fg-secondary); max-width: 720px; line-height: 1.55; }
.activity-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  max-width: 900px;
  margin-bottom: 14px;
}
.activity-stat {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  padding: 13px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-card);
}
.activity-stat span {
  color: var(--fg-tertiary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.activity-stat strong {
  color: var(--fg);
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.activity-tabs {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin: 12px 0;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--surface-alt);
}
.activity-tab {
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--fg-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.activity-tab.active {
  background: var(--surface);
  color: var(--fg);
  box-shadow: var(--shadow-soft);
}
.tasks-list,
.sync-runs-list { display: flex; flex-direction: column; gap: 12px; max-width: 900px; }
.task-card,
.sync-run-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
}
.task-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.task-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
}
.task-tag span {
  flex: 0 0 auto;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--fg-tertiary);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.task-status {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 10px; border-radius: 999px;
  background: var(--surface-alt); color: var(--fg-secondary);
  font-weight: 600;
}
.task-card.status-running .task-status { background: var(--accent-soft); color: var(--accent); }
.task-card.status-queued .task-status { background: #fff5db; color: #8a6a00; }
.task-card.status-completed .task-status { background: #dff5e3; color: #1e6b31; }
.task-card.status-cancelled .task-status { background: var(--surface-alt); color: var(--fg-tertiary); }
.task-card.status-failed .task-status { background: #fde0d1; color: var(--error); }
.sync-run-card.status-completed .task-status { background: #dff5e3; color: #1e6b31; }
.sync-run-card.status-completed_with_errors .task-status { background: #fff5db; color: #8a6a00; }
.sync-run-card.status-running .task-status { background: var(--accent-soft); color: var(--accent); }
.sync-run-card.status-failed .task-status { background: #fde0d1; color: var(--error); }
.task-progress { margin-bottom: 10px; }
.task-bar {
  height: 6px; background: var(--surface-alt); border-radius: 999px; overflow: hidden;
  margin-bottom: 8px;
}
.task-bar-fill {
  height: 100%; background: var(--accent); transition: width 0.4s ease;
}
.task-card.status-completed .task-bar-fill { background: #2ea049; }
.task-card.status-failed .task-bar-fill { background: var(--error); }
.task-counts {
  display: flex; flex-wrap: wrap; gap: 14px;
  font-size: 12px; color: var(--fg-secondary);
}
.task-counts strong { color: var(--fg); font-weight: 600; }
.task-total { color: var(--fg-tertiary); }
.sync-run-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--fg-secondary);
}
.sync-run-counts strong { color: var(--fg); font-weight: 600; }
.task-meta {
  display: flex; flex-wrap: wrap; gap: 16px;
  font-size: 11px; color: var(--fg-tertiary);
  padding-top: 10px; border-top: 1px solid var(--border-subtle);
}
.task-error {
  margin-top: 10px;
  padding: 8px 10px;
  background: #fde0d1;
  color: var(--error);
  border-radius: 6px;
  font-size: 11px;
  word-break: break-word;
}
.task-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}
.task-actions .btn-secondary {
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
}

@media (max-width: 900px) {
  .nav-item { padding: 6px 12px; }
  .tasks-view { padding: 16px; }
  .task-meta { gap: 10px; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .detail-overlay { z-index: 120; padding: 0; }
  .detail-panel {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
  }
  .detail-content {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
  }
  .detail-media-column {
    min-height: 46vh;
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }
  .detail-media { min-height: 46vh; padding: 12px; }
  .detail-info { overflow: visible; padding: 18px 16px calc(var(--mobile-nav-h) + 22px); }
  .detail-facts { grid-template-columns: 1fr; }
  .detail-copy-grid { grid-template-columns: 1fr; }
  .detail-section-head { align-items: flex-start; flex-direction: column; }
  .detail-section-actions { width: 100%; }
  .detail-section-actions .btn-secondary { flex: 1; }
  .collection-create-form,
  .collection-card,
  .collection-card-main {
    grid-template-columns: 1fr;
  }
  .collection-card-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
  }
  .collection-card-actions .btn-secondary { padding: 0 6px; }
  .dialog-body { padding: 18px 16px 16px; }
  .dialog-body-wide { max-width: 100%; }
  .description-content { font-size: 11.5px; padding: 12px 14px; max-height: 55vh; }
  .task-counts { gap: 10px; font-size: 11.5px; }
  .tasks-header h2 { font-size: 17px; }
  .tasks-sub { font-size: 12px; }
  .tasks-header { flex-direction: column; }
  .tasks-header .btn-secondary { width: 100%; min-height: 44px; }
  .activity-summary { grid-template-columns: 1fr; }
  .activity-tabs { width: 100%; }
  .activity-tab { min-height: 44px; }
  .task-head { align-items: flex-start; gap: 10px; }
  .task-actions { justify-content: stretch; }
  .task-actions .btn-secondary { flex: 1; min-height: 40px; }
  .sync-run-counts { gap: 10px; font-size: 11.5px; }
}

/* ── MeiGen tab — uses the app's cream theme tokens, not a dark overlay. ── */
.meigen-view {
  padding: 22px 30px 60px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  color: var(--fg);
}
.meigen-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.meigen-head h2 { margin: 0; font-size: 22px; color: var(--fg); }
.meigen-sub { margin: 4px 0 0; color: var(--fg-secondary); font-size: 13px; max-width: 60ch; }
.meigen-head-actions { display: flex; gap: 10px; }
.meigen-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 14px 16px;
}
.meigen-stat-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-tertiary);
  margin-bottom: 4px;
}
.meigen-stat-value { font-size: 17px; font-weight: 600; color: var(--fg); }
.meigen-search {
  display: grid;
  grid-template-columns: 1fr 220px auto;
  gap: 10px;
  align-items: center;
}
.meigen-search input[type=search],
.meigen-search select.dialog-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--fg);
  padding: 9px 14px;
  font-size: 14px;
  outline: none;
}
.meigen-search input[type=search]::placeholder { color: var(--fg-tertiary); }
.meigen-search input[type=search]:focus,
.meigen-search select.dialog-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.meigen-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.meigen-grid .empty {
  color: var(--fg-secondary);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 32px;
  text-align: center;
  grid-column: 1 / -1;
}
.meigen-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}
.meigen-card:hover {
  border-color: var(--border);
  transform: translateY(-1px);
  box-shadow: var(--shadow-card);
}
.meigen-card-media {
  position: relative;
  background: var(--surface-alt);
  overflow: hidden;
  cursor: pointer;
}
.meigen-card-media img { width: 100%; height: auto; display: block; }
.meigen-card-multi {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(26, 24, 22, 0.78);
  color: #fff;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 600;
}
/* Orphaned styles below kept only so older /static/?v=2 caches don't break.
   New markup uses Pinterest's .meta / .tags-row / .row / .row-actions classes. */
.meigen-card-actions .meigen-card-delete {
  margin-left: auto;
  color: var(--fg-tertiary);
}
.meigen-card-actions .meigen-card-delete:hover {
  color: var(--danger, #c0392b);
}
.meigen-session-input {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11.5px;
  resize: vertical;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
}
.meigen-detail-prompt {
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 40vh;
  overflow: auto;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border-subtle);
}
.detail-collection-chip {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg-secondary);
  font-size: 12.5px;
  margin: 4px 6px 0 0;
  cursor: pointer;
}
.detail-collection-chip:hover { background: var(--surface-hover); }
.detail-collection-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.detail-danger { color: var(--error); }
.dialog-list { padding-left: 22px; margin: 0 0 12px; line-height: 1.55; font-size: 13px; color: var(--fg-secondary); }
.dialog-list code { background: var(--surface); padding: 1px 6px; border-radius: 4px; color: var(--fg); }
.dialog-list strong { color: var(--fg); }
.nav-item-meigen { font-weight: 600; }
.collection-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  background: var(--surface);
  border-radius: 10px;
  margin-top: 8px;
}
.collection-row .collection-name { font-weight: 600; color: var(--fg); }
.collection-row .collection-desc { font-size: 12px; color: var(--fg-secondary); }
.collection-row .collection-meta { font-size: 11.5px; color: var(--fg-tertiary); margin-top: 2px; }

/* MeiGen badge for sync history rows so it's distinguishable from Pinterest. */
.sync-source-badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  margin-right: 8px;
  vertical-align: middle;
}
.sync-source-badge.pinterest { background: var(--surface); color: var(--fg-secondary); border: 1px solid var(--border); }
.sync-source-badge.meigen { background: var(--accent-soft); color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); }
.sync-run-card.sync-source-meigen { border-left: 3px solid var(--accent); }

@media (max-width: 700px) {
  .meigen-view { padding: 16px 14px 80px; }
  .meigen-search { grid-template-columns: 1fr; }
}

/* ── API keys view ───────────────────────────────────────────────── */
.keys-view {
  padding: 24px 28px 80px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.keys-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.keys-head h2 { margin: 0; font-size: 22px; color: var(--fg); }
.keys-sub { margin: 4px 0 0; color: var(--fg-secondary); font-size: 13px; max-width: 70ch; line-height: 1.55; }
.keys-head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.keys-head-actions .btn-secondary,
.keys-head-actions .btn-primary { white-space: nowrap; }

.keys-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.keys-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(260px, 1.6fr) auto;
  gap: 16px;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
}
.keys-row-main { min-width: 0; }
.keys-row-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.keys-row-prefix code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--fg-tertiary);
  background: var(--surface-hover);
  padding: 2px 6px;
  border-radius: 6px;
}
.keys-row-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  font-size: 12px;
  color: var(--fg-secondary);
}
.keys-row-meta span {
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 10.5px;
  color: var(--fg-tertiary);
  margin-bottom: 2px;
}
.keys-row-meta strong {
  font-weight: 500;
  color: var(--fg);
  font-size: 12.5px;
}
.keys-row-actions { display: flex; justify-content: flex-end; }

.keys-reveal-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface-hover);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  margin: 12px 0 6px;
  flex-wrap: wrap;
}
.keys-reveal-value {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: var(--fg);
  word-break: break-all;
  user-select: all;
}

.dialog-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.dialog-field span {
  font-size: 12px;
  color: var(--fg-secondary);
  font-weight: 500;
}
.dialog-field input[type=text] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--fg);
  font-size: 14px;
}
.dialog-field input[type=text]:focus {
  outline: none;
  border-color: var(--fg);
  box-shadow: 0 0 0 2px var(--focus-ring);
}

@media (max-width: 700px) {
  .keys-view { padding: 16px 14px 80px; }
  .keys-row { grid-template-columns: 1fr; gap: 10px; }
  .keys-row-actions { justify-content: flex-start; }
}

/* ── Global Search ("Search all") view ─────────────────────────────── */
.search-all-view {
  padding: 24px 28px 80px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.search-all-head h2 { margin: 0; font-size: 22px; color: var(--fg); }
.search-all-sub { margin: 4px 0 0; color: var(--fg-secondary); font-size: 13px; max-width: 70ch; line-height: 1.55; }
.search-all-form {
  display: grid;
  grid-template-columns: 1fr 180px 180px;
  gap: 10px;
  align-items: center;
}
.search-all-form input[type=search],
.search-all-form select {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
}
.search-all-form input[type=search]:focus,
.search-all-form select:focus {
  outline: none;
  border-color: var(--fg);
  box-shadow: 0 0 0 2px var(--focus-ring);
}
.source-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.source-badge-pinterest { background: rgba(230, 0, 35, 0.92); color: #fff; }
.source-badge-meigen { background: rgba(180, 100, 60, 0.92); color: #fff; }
/* Infinite-scroll sentinel — also doubles as the "Loaded X of Y" footer. */
.search-all-sentinel {
  text-align: center;
  font-size: 12.5px;
  color: var(--fg-tertiary);
  font-variant-numeric: tabular-nums;
  padding: 24px 16px 32px;
  min-height: 36px;
}

/* Tiny relevance-score chip overlaid on the search-all card image. */
.score-badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(26, 24, 22, 0.78);
  color: #fff;
  letter-spacing: 0.04em;
}
@media (max-width: 700px) {
  .search-all-view { padding: 16px 14px 80px; }
  .search-all-form { grid-template-columns: 1fr; }
}
