* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #FAF9FD; color: #1C4154; }

header {
  padding: 14px 24px;
  background: #1C4154;
  color: #F4EEE5;
  border-bottom: 4px solid #DE528C;
  display: flex;
  align-items: center;
  gap: 32px;
}
header h1 { font-size: 18px; margin: 0; letter-spacing: 1px; }
header .stats { font-size: 12px; color: #B9D4E0; margin-top: 2px; }
.searchbar { flex: 1; display: flex; gap: 8px; align-items: center; }
.searchbar input[type=search] {
  flex: 1; padding: 10px 14px; font-size: 15px; border-radius: 4px;
  border: 1px solid #6D8A99; background: #F4EEE5; color: #1C4154;
}
.searchbar button {
  padding: 10px 18px; background: #DE528C; color: white; border: 0;
  border-radius: 4px; font-weight: 600; cursor: pointer;
}
.searchbar a.reset { color: #B9D4E0; font-size: 13px; text-decoration: none; }
.searchbar a.reset:hover { color: white; }

.layout { display: grid; grid-template-columns: 250px 1fr; gap: 0; }

aside.filters {
  padding: 20px;
  border-right: 1px solid #DDD;
  background: white;
  min-height: calc(100vh - 62px);
}
aside.filters h3 { margin-top: 0; font-size: 14px; text-transform: uppercase; color: #6D8A99; }
aside.filters label {
  display: block; margin: 12px 0 6px; font-size: 12px; color: #6D8A99;
  text-transform: uppercase; letter-spacing: 0.5px;
}
aside.filters select {
  width: 100%; padding: 6px 8px; border: 1px solid #BBB;
  border-radius: 3px; background: white; font-size: 14px;
}
.actions { margin-top: 24px; display: flex; flex-direction: column; gap: 6px; }
.actions button {
  padding: 8px 12px; background: #F4EEE5; color: #1C4154; border: 1px solid #BBB;
  border-radius: 3px; cursor: pointer; font-size: 13px;
}
.actions button:disabled { opacity: 0.5; cursor: not-allowed; }
.actions button#copyUrls:not(:disabled) { background: #DE528C; color: white; border-color: #DE528C; }

.tips { margin-top: 20px; font-size: 11px; color: #6D8A99; border-top: 1px solid #EEE; padding-top: 14px; }
.tips h4 { margin: 0 0 6px; font-size: 11px; text-transform: uppercase; }
.tips code { background: #F4EEE5; padding: 1px 4px; border-radius: 2px; }

main { padding: 16px 24px 48px; }
.resultbar { font-size: 14px; color: #6D8A99; padding: 8px 0 16px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.card {
  background: white;
  border: 1px solid #E0D9D0;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.card:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(28,65,84,0.14); }
.card.selected { outline: 3px solid #DE528C; }
.card .pick { position: absolute; top: 6px; left: 6px; z-index: 2; background: rgba(255,255,255,0.9); border-radius: 3px; padding: 2px 6px; }
.card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #EEE;
  display: block;
}
.card .info { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.card .name { font-family: monospace; font-size: 12px; color: #6D8A99; }
.card .tags { display: flex; flex-wrap: wrap; gap: 4px; }
.card .tag {
  font-size: 11px; padding: 2px 6px; border-radius: 999px; background: #F4EEE5; color: #1C4154;
}
.tag.scene { background: #B9D4E0; }
.tag.mood { background: #F6B7D2; }
.tag.team { background: #FFE5A8; }
.tag.tv { background: #D8E5C7; }
.tag.src-dropbox { background: #E8DFFF; color: #3a2a66; }
.tag.hosted { background: #1C4154; color: #B9D4E0; }
.tag.focal { background: #1C4154; color: #F4EEE5; }
.tag.shot { background: #DE528C; color: white; }
.tag.negspace { background: #E8DFFF; }
.focal-line { font-size: 12px; color: #1C4154; padding: 2px 0; }
.focal-line strong { color: #6D8A99; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; }
.focal-toggle { color: #B9D4E0; font-size: 13px; display: flex; align-items: center; gap: 4px; margin-right: 8px; cursor: pointer; }
.focal-toggle input { margin: 0; }
.card .preview {
  font-size: 12px; color: #4A5A66; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card .actions-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; padding-top: 4px; border-top: 1px solid #F4EEE5;
}
.card .actions-row a { color: #1C4154; text-decoration: none; }
.card .actions-row a:hover { text-decoration: underline; }
.card .actions-row .detailbtn {
  background: none; border: 1px solid #BBB; border-radius: 3px; padding: 2px 8px; font-size: 11px; cursor: pointer; color: #6D8A99;
}

.empty { padding: 60px; text-align: center; color: #6D8A99; grid-column: 1 / -1; }

dialog#detailModal {
  max-width: 800px; width: 90%; border: 0; border-radius: 8px; padding: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
dialog#detailModal::backdrop { background: rgba(0,0,0,0.45); }
#detailContent h2 { margin-top: 0; color: #1C4154; }
#detailContent dl { display: grid; grid-template-columns: 180px 1fr; gap: 6px 16px; font-size: 13px; }
#detailContent dt { font-weight: 600; color: #6D8A99; }
#detailContent dd { margin: 0; word-break: break-word; }
#detailContent pre { background: #F4EEE5; padding: 12px; border-radius: 4px; overflow: auto; font-size: 11px; max-height: 300px; }
/* Sources page */
.sources-wrap { padding: 24px 48px; max-width: 1200px; }
.flash { padding: 10px 16px; border-radius: 4px; margin-bottom: 12px; }
.flash-ok { background: #D8E5C7; color: #1C4154; }
.flash-warn { background: #FFE5A8; color: #8a6200; }
.flash-error { background: #F6B7D2; color: #7a1d3c; }
.add-source { background: white; border: 1px solid #E0D9D0; border-radius: 6px; padding: 20px 24px; margin-bottom: 24px; }
.add-form { display: grid; grid-template-columns: 3fr 2fr 1fr auto; gap: 12px; align-items: end; }
.add-form label { font-size: 12px; color: #6D8A99; text-transform: uppercase; letter-spacing: 0.5px; }
.add-form input { display: block; width: 100%; padding: 8px 10px; margin-top: 4px; border: 1px solid #BBB; border-radius: 3px; }
.add-form button { background: #DE528C; color: white; border: 0; border-radius: 4px; padding: 10px 18px; cursor: pointer; font-weight: 600; }
.hint { font-size: 12px; color: #6D8A99; margin-top: 10px; line-height: 1.4; }
.hint code { background: #F4EEE5; padding: 1px 4px; border-radius: 2px; }
.sources-list { background: white; border: 1px solid #E0D9D0; border-radius: 6px; padding: 20px 24px; margin-bottom: 24px; }
.sources-list table { width: 100%; border-collapse: collapse; }
.sources-list th, .sources-list td { padding: 10px 8px; text-align: left; border-bottom: 1px solid #F4EEE5; font-size: 13px; vertical-align: top; }
.sources-list tr.disabled { opacity: 0.5; }
.sources-list tr.pending { background: #FFFBE8; }
.source-type { font-size: 11px; padding: 2px 6px; border-radius: 3px; text-transform: uppercase; font-weight: 600; }
.source-type.drive { background: #B9D4E0; color: #1C4154; }
.source-type.dropbox { background: #E8DFFF; color: #3a2a66; }
.pending-tag { font-size: 10px; color: #8a6200; margin-left: 4px; }
.source-label { font-weight: 600; }
.source-url { font-size: 11px; color: #6D8A99; word-break: break-all; display: block; }
.source-fid { font-family: monospace; font-size: 11px; color: #6D8A99; }
.actions-cell { white-space: nowrap; }
button.tiny { background: #F4EEE5; border: 1px solid #BBB; padding: 4px 8px; font-size: 11px; border-radius: 3px; cursor: pointer; margin-right: 4px; }
button.tiny.danger { background: #F6B7D2; color: #7a1d3c; border-color: #D99CB4; }
.hint-block { background: #FAF9FD; border-left: 4px solid #DE528C; padding: 16px 20px; font-size: 13px; }
.hint-block h4 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; color: #6D8A99; }

.dup-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin-top: 10px; }
.dup-item { border: 1px solid #E0D9D0; border-radius: 4px; overflow: hidden; background: white; }
.dup-item img { width: 100%; aspect-ratio: 1/1; object-fit: cover; display: block; background: #EEE; }
.dup-name { font-family: monospace; font-size: 10px; padding: 4px 6px; color: #6D8A99; word-break: break-all; }
.dup-meta { font-size: 10px; padding: 0 6px 4px; color: #6D8A99; }

.refresh-block { background: white; border: 1px solid #E0D9D0; border-radius: 6px; padding: 20px 24px; margin-bottom: 24px; }
.refresh-block p { font-size: 13px; line-height: 1.5; margin: 6px 0 14px; }
.refresh-form { display: grid; grid-template-columns: auto auto auto 1fr; gap: 16px; align-items: end; margin-bottom: 12px; }
.refresh-form label { font-size: 12px; color: #6D8A99; text-transform: uppercase; letter-spacing: 0.5px; }
.refresh-form select, .refresh-form input[type=number] { display: block; padding: 6px 8px; margin-top: 4px; border: 1px solid #BBB; border-radius: 3px; font-size: 13px; }
.refresh-form label input[type=checkbox] { vertical-align: middle; margin-right: 4px; transform: translateY(-1px); }
.refresh-actions { display: flex; align-items: center; gap: 12px; justify-self: end; }
.refresh-actions button.primary { background: #DE528C; color: white; border: 0; border-radius: 4px; padding: 10px 20px; cursor: pointer; font-weight: 600; font-size: 13px; }
.refresh-actions button.primary:disabled { opacity: 0.4; cursor: not-allowed; }
.refresh-actions button.danger { background: #F6B7D2; color: #7a1d3c; border: 1px solid #D99CB4; border-radius: 4px; padding: 8px 16px; cursor: pointer; font-weight: 600; font-size: 13px; }
.refresh-actions a { font-size: 13px; color: #DE528C; text-decoration: none; }
.refresh-actions a:hover { text-decoration: underline; }
.refresh-status { background: #F4EEE5; border: 1px solid #E0D9D0; border-radius: 4px; padding: 10px 14px; font-size: 13px; }
.refresh-status-line { font-weight: 600; }
.refresh-status-line #refresh-state.running { color: #2c7a48; }
.refresh-status-line #refresh-state.idle { color: #6D8A99; }
.refresh-status-line .hint { margin-left: 8px; font-weight: normal; }
.refresh-tail { background: #1a1a1a; color: #c8e6b6; font-family: "Menlo", "Consolas", monospace; font-size: 11px; padding: 10px 14px; margin-top: 10px; border-radius: 3px; max-height: 280px; overflow: auto; line-height: 1.4; }

.source-meta, .source-totals, .folder-tree { background: white; border: 1px solid #E0D9D0; border-radius: 6px; padding: 20px 24px; margin-bottom: 24px; }
.source-meta table.kv { font-size: 13px; }
.source-meta table.kv th { text-align: left; color: #6D8A99; padding: 6px 14px 6px 0; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; vertical-align: top; width: 150px; }
.source-meta table.kv td { padding: 6px 0; word-break: break-all; }
.source-meta table.kv code { background: #F4EEE5; padding: 1px 4px; border-radius: 2px; font-size: 12px; }

.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-top: 8px; }
.kpi { background: #F4EEE5; border-radius: 4px; padding: 12px 16px; text-align: center; }
.kpi-num { font-size: 26px; font-weight: 700; color: #1C4154; line-height: 1.1; }
.kpi-label { font-size: 11px; text-transform: uppercase; color: #6D8A99; letter-spacing: 0.6px; margin-top: 2px; }

.folders { width: 100%; border-collapse: collapse; font-size: 13px; }
.folders th, .folders td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #F4EEE5; vertical-align: top; }
.folders th { color: #6D8A99; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; }
.folders th.num, .folders td.num { text-align: right; font-variant-numeric: tabular-nums; }
.folders .folder-path a { color: #1C4154; font-weight: 500; }
.folders .folder-path .drive-link { margin-left: 6px; color: #6D8A99; text-decoration: none; font-size: 11px; }
.folders .folder-path .drive-link:hover { color: #DE528C; }
.folders .pct { color: #6D8A99; font-size: 11px; margin-left: 4px; }

.sources-list th.num, .sources-list td.num { text-align: right; font-variant-numeric: tabular-nums; }
.sources-list td.num .pct { color: #6D8A99; font-size: 11px; display: block; }
a.tiny { display: inline-block; background: #B9D4E0; color: #1C4154; padding: 4px 8px; font-size: 11px; border-radius: 3px; text-decoration: none; margin-right: 4px; }
a.tiny:hover { background: #98c0d0; }

.flash.flash-warn { background: #FFF4D6; border: 1px solid #F1D78F; color: #7a5b1a; padding: 10px 14px; border-radius: 4px; font-size: 13px; margin-top: 12px; }

.upload-date { font-size: 11px; color: #6D8A99; margin-top: 4px; }
.actions-row a + a { margin-left: 8px; }

.card img { cursor: zoom-in; }

/* User tags (on cards) */
.user-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.user-tag {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: #E8DFFF; color: #3a2a66; border: 1px solid #C8B9F0;
}

/* User-corrected focal differs from Claude's */
.focal-line.user { color: #3a2a66; }
.focal-line.user strong { color: #6750a4; }

/* Sidebar: Collections block */
.collections-block {
  margin-top: 20px; padding-top: 14px; border-top: 1px solid #EEE;
}
.collections-block h4 {
  margin: 0 0 8px; font-size: 11px; text-transform: uppercase;
  color: #6D8A99; letter-spacing: 0.5px;
  display: flex; align-items: center; justify-content: space-between;
}
.collections-block .tiny-link,
.tiny-link {
  color: #DE528C; font-size: 10px; text-decoration: none;
  text-transform: none; letter-spacing: 0;
}
.tiny-link:hover { text-decoration: underline; }
.coll-list { list-style: none; margin: 0; padding: 0; font-size: 13px; max-height: 220px; overflow-y: auto; }
.coll-list li { padding: 4px 0; border-bottom: 1px dashed #F0EAE2; display: flex; justify-content: space-between; gap: 6px; }
.coll-list li a { color: #1C4154; text-decoration: none; flex: 1; }
.coll-list li a:hover { color: #DE528C; }
.coll-list li.active a { color: #DE528C; font-weight: 600; }
.coll-list .count { color: #6D8A99; font-size: 11px; }

/* Actions button for "Add to collection" */
.actions button#addToCollection:not(:disabled) {
  background: #3a2a66; color: white; border-color: #3a2a66;
}
.actions button#removeFromCollection:not(:disabled) {
  background: #F6B7D2; color: #7a1d3c; border-color: #D99CB4;
}

/* Detail-modal user-edit section */
.user-edit {
  background: #FAF9FD; border: 1px solid #E0D9D0; border-radius: 6px;
  padding: 12px 16px; margin: 12px 0 20px;
}
.user-edit h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; color: #6D8A99; letter-spacing: 0.5px; }
.user-edit .field { margin-bottom: 14px; }
.user-edit .field label {
  display: block; font-size: 11px; text-transform: uppercase;
  color: #6D8A99; letter-spacing: 0.5px; margin-bottom: 6px;
}
.user-edit .field label .hint {
  text-transform: none; letter-spacing: 0; color: #6D8A99; font-size: 11px;
  font-weight: normal; margin-left: 6px;
}
.tag-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; min-height: 22px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 4px 2px 10px; border-radius: 999px;
  background: #E8DFFF; color: #3a2a66; font-size: 12px;
}
.chip-x {
  background: none; border: 0; color: #6750a4; cursor: pointer;
  font-size: 14px; padding: 0 4px; line-height: 1;
}
.chip-x:hover { color: #DE528C; }
.tag-input-row { display: flex; gap: 6px; }
.tag-input-row input[type=text] {
  flex: 1; padding: 6px 10px; border: 1px solid #BBB; border-radius: 3px; font-size: 13px;
}
.tag-input-row button, .focal-edit-row button {
  padding: 6px 14px; background: #DE528C; color: white; border: 0;
  border-radius: 3px; cursor: pointer; font-size: 12px; font-weight: 600;
}
.tag-input-row button:disabled, .focal-edit-row button:disabled {
  opacity: 0.6; cursor: not-allowed;
}
.focal-edit-row { display: flex; gap: 6px; }
.focal-edit-row input[type=text] {
  flex: 1; padding: 6px 10px; border: 1px solid #BBB; border-radius: 3px; font-size: 13px;
}
.claude-hint { font-size: 11px; color: #6D8A99; margin-top: 4px; }
.claude-hint em { color: #1C4154; font-style: normal; }

.coll-membership { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.coll-membership li {
  padding: 4px 0; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; border-bottom: 1px dashed #F0EAE2;
}
.coll-membership li a { color: #1C4154; text-decoration: none; }
.coll-membership li a:hover { color: #DE528C; }

/* Collection-detail page: rename form + export block */
.rename-form label {
  display: block; font-size: 11px; text-transform: uppercase;
  color: #6D8A99; letter-spacing: 0.5px; margin: 10px 0 4px;
}
.rename-form label input {
  display: block; width: 100%; padding: 6px 8px; border: 1px solid #BBB;
  border-radius: 3px; font-size: 13px;
}
.rename-form button {
  margin-top: 8px; padding: 6px 14px; background: #DE528C; color: white;
  border: 0; border-radius: 3px; cursor: pointer; font-size: 12px; font-weight: 600;
}
.export-block {
  margin-top: 20px; padding-top: 14px; border-top: 1px solid #EEE;
  font-size: 13px;
}
.export-block h4 {
  margin: 0 0 8px; font-size: 11px; text-transform: uppercase;
  color: #6D8A99; letter-spacing: 0.5px;
}
.export-block button { margin-top: 6px; }

.brand-home { color: inherit; text-decoration: none; }
.brand-home:hover { opacity: 0.85; }

.modal-nav { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 12px; border-bottom: 1px solid #E0D9D0; margin-bottom: 12px; gap: 12px; }
.modal-nav button { background: #F4EEE5; border: 1px solid #BBB; padding: 6px 12px; font-size: 13px; border-radius: 4px; cursor: pointer; font-weight: 500; }
.modal-nav button:hover { background: #E8DFCF; }
.modal-pos { font-size: 12px; color: #6D8A99; font-variant-numeric: tabular-nums; }

/* Card tags as links — preserve existing colored backgrounds, add hover */
a.tag, .tags a.tag { text-decoration: none; cursor: pointer; }
a.tag:hover { filter: brightness(0.92); text-decoration: underline; }
.tag.tv-link { color: inherit; text-decoration: underline; }
.user-tag { text-decoration: none; cursor: pointer; }
.user-tag:hover { text-decoration: underline; }

/* Modal user-tag chips: text is link, X stays a button */
.chip-text { color: inherit; text-decoration: none; padding-right: 4px; }
.chip-text:hover { text-decoration: underline; }

/* Inline search links inside the modal's analysis dl */
.search-link { color: #1C4154; text-decoration: none; border-bottom: 1px dotted #B9D4E0; }
.search-link:hover { color: #DE528C; border-bottom-color: #DE528C; }

/* "Load more" footer below the grid */
.load-more-bar { display: flex; justify-content: center; padding: 24px 0 48px; }
.load-more-bar button { background: #1C4154; color: white; border: 0; border-radius: 4px; padding: 12px 28px; font-size: 14px; font-weight: 600; cursor: pointer; }
.load-more-bar button:hover { background: #234E63; }
.load-more-bar button:disabled { opacity: 0.5; cursor: wait; }

/* Hover preview: separate floating panel anchored next to the hovered card.
   Doesn't touch the card layout, so the checkbox stays clickable and the
   surrounding cards don't reflow. */
.card { position: relative; }
.card img { transition: box-shadow 120ms ease; }
.card.hovering img { box-shadow: 0 4px 12px rgba(0,0,0,0.18); }

#hoverPreview {
  position: fixed;
  display: none;
  z-index: 9999;
  background: #1a1a1a;
  border: 2px solid #DE528C;
  border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  padding: 6px;
  pointer-events: none;       /* hover preview never eats clicks */
  max-width: min(900px, 60vw);
  max-height: 85vh;
}
#hoverPreview.show { display: block; }
#hoverPreview img {
  display: block;
  max-width: 100%;
  max-height: calc(85vh - 12px);
  border-radius: 4px;
}
/* Touch / no-mouse devices never get the hover preview at all. */
@media (hover: none), (pointer: coarse) {
  #hoverPreview { display: none !important; }
}
