/* Footage Library — dark, refined UI ported from the library Space. */

:root {
  --bg: #0d0d10;
  --surface: #15151a;
  --surface-2: #1c1c22;
  --text: #eeece7;
  --muted: #9a97a3;
  --border: #2a2a32;
  --accent: #c9973f;
  --accent-soft: rgba(201, 151, 63, 0.16);
  --warn: #d8a03c;
  --radius: 12px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "IBM Plex Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.mono { font-family: var(--mono); font-size: 12px; word-break: break-all; }

/* ---------- buttons ---------- */
.btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #161310; font-weight: 600; }
.btn-accent:hover { border-color: var(--accent); filter: brightness(1.08); }
.btn-warn { background: rgba(216, 160, 60, 0.15); border-color: var(--warn); color: var(--warn); font-weight: 600; }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--text); border-color: transparent; }
.btn[disabled] { opacity: 0.55; cursor: wait; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 36px 32px; width: 340px; max-width: 100%; text-align: center;
  display: flex; flex-direction: column; gap: 12px;
}
.login-mark { font-size: 30px; color: var(--accent); }
.login-card h1 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: 0.01em; }
.login-sub { margin: 0; color: var(--muted); font-size: 14px; }
.login-card input {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 14px; text-align: center;
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-error { margin: 0; color: #e07a5f; font-size: 13px; }

/* ---------- top bar ---------- */
.topbar {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
@media (min-width: 640px) {
  .topbar { position: sticky; top: 0; z-index: 30; }
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { font-size: 17px; font-weight: 650; letter-spacing: 0.01em; }
.brand-mark { color: var(--accent); font-size: 13px; margin-right: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.clip-count { color: var(--muted); font-size: 13px; font-family: var(--mono); }

.controls-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 12px; }
#search {
  flex: 1 1 220px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 16px;
}
#search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.view-toggle { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 2px; }
.toggle-btn { background: transparent; border: 0; border-radius: 999px; padding: 5px 14px; font-size: 13px; color: var(--muted); }
.toggle-btn.active { background: var(--surface-2); color: var(--text); }
.size-wrap { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.size-wrap input[type="range"] { accent-color: var(--accent); width: 110px; }

/* ---------- filter sections ---------- */
.filters { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.filter-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.filter-head {
  width: 100%; display: flex; align-items: center; gap: 10px;
  background: transparent; border: 0; padding: 9px 14px; text-align: left;
}
.filter-title { font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.filter-summary { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-summary .on { color: var(--accent); font-weight: 600; }
.filter-clear { color: var(--warn); font-size: 12px; font-weight: 600; }
.chev { color: var(--muted); transition: transform 0.15s; }
.filter-head[aria-expanded="true"] .chev { transform: rotate(90deg); }
.filter-body { padding: 2px 12px 12px; max-height: 38vh; overflow-y: auto; }
.pill-row { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 11px; font-size: 13px; cursor: pointer; user-select: none;
}
.pill input { display: none; }
.pill .n { color: var(--muted); font-size: 11px; font-family: var(--mono); }
.pill.checked { background: var(--accent-soft); border-color: var(--accent); }
.pill.checked .n { color: var(--accent); }

/* ---------- results head ---------- */
.results-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px; margin-top: 12px;
}
.results-label { color: var(--muted); font-size: 13px; }
.results-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#selected-count { font-size: 13px; color: var(--accent); font-weight: 600; }

/* ---------- grouped view ---------- */
.results { padding: 16px; max-width: 1440px; margin: 0 auto; }
.group { margin-bottom: 28px; }
.group-title {
  font-size: 14px; font-weight: 650; margin: 0 0 10px;
  display: flex; align-items: baseline; gap: 8px;
}
.group-title .n { color: var(--muted); font-weight: 400; font-size: 12px; font-family: var(--mono); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; position: relative; cursor: pointer;
}
.card:hover { border-color: var(--muted); }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.card-thumb { position: relative; aspect-ratio: 16 / 9; background: #000; overflow: hidden; }
.card-thumb img, .tile img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.strip { position: absolute; inset: 0; background-repeat: no-repeat; }
.card-body { padding: 10px 12px 12px; }
.card-name { font-family: var(--mono); font-size: 12.5px; font-weight: 600; margin: 0 0 4px; }
.card-desc {
  margin: 0; color: var(--muted); font-size: 13px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-foot { display: flex; align-items: center; gap: 6px; margin-top: 9px; }
.card-cam { color: var(--muted); font-size: 11.5px; flex: 1; }
.card-tmatch { color: var(--accent); font-size: 11px; white-space: nowrap; }
.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 10px; font-size: 12px;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* selection badge + gallery download corner */
.pick-badge {
  position: absolute; top: 8px; right: 8px; z-index: 3;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: #161310; font-weight: 700; font-size: 14px;
  display: none; align-items: center; justify-content: center;
}
.selected .pick-badge { display: flex; }
body.selecting .card, body.selecting .tile { cursor: cell; }
.dl-corner {
  position: absolute; left: 8px; bottom: 8px; z-index: 3;
  width: 28px; height: 28px; border-radius: 50%;
  background: rgba(10, 10, 12, 0.72); color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.25);
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.dl-corner:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- gallery (justified rows) ---------- */
.jrow { display: flex; gap: 4px; margin-bottom: 4px; }
.tile { position: relative; overflow: hidden; background: #000; border-radius: 4px; cursor: pointer; flex: none; }
.tile.selected { box-shadow: inset 0 0 0 2px var(--accent); }
.tile .tile-name {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 8px 5px;
  font-family: var(--mono); font-size: 10.5px; color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  opacity: 0; transition: opacity 0.15s; pointer-events: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile:hover .tile-name { opacity: 1; }

/* ---------- detail ---------- */
.detail-wrap {
  position: fixed; inset: 0; z-index: 50; overflow-y: auto;
  background: rgba(5, 5, 7, 0.82); padding: 18px 12px 40px;
}
.detail-card {
  position: relative; max-width: 880px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; overflow: hidden;
}
.detail-close { position: absolute; top: 10px; right: 10px; z-index: 5; background: rgba(10,10,12,0.6); border-radius: 50%; width: 34px; height: 34px; }
.detail-media { background: #000; position: relative; }
.detail-media video { width: 100%; max-height: 62vh; display: block; background: #000; }
.detail-loading { position: absolute; top: 0; left: 0; right: 0; height: 40vh; display: flex; align-items: center; justify-content: center; color: #9a97a3; font-size: 14px; letter-spacing: 0.02em; pointer-events: none; }
.detail-loading[hidden] { display: none; }
.detail-frames { display: flex; gap: 3px; padding: 3px; background: #000; overflow-x: auto; }
.detail-frames img { height: 64px; border-radius: 3px; display: block; }
.detail-body { padding: 18px 20px 22px; }
.detail-body h2 { margin: 0; font-family: var(--mono); font-size: 17px; }
.detail-folder { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.detail-desc { margin: 12px 0 0; font-size: 15px; }
.detail-transcript-wrap { margin-top: 16px; }
.detail-transcript-title {
  margin: 0 0 6px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
.detail-tmatch { color: var(--accent); font-weight: 400; text-transform: none; letter-spacing: 0; }
.detail-transcript {
  margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.55;
  white-space: pre-wrap;
}
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 10px; font-size: 12px; color: var(--muted); cursor: pointer;
}
.chip:hover { color: var(--accent); border-color: var(--accent); }
.detail-meta { margin: 16px 0 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px 18px; }
.detail-meta dt { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.detail-meta dd { margin: 2px 0 0; font-size: 13.5px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.detail-note { color: var(--muted); font-size: 12px; margin: 10px 0 0; }

/* ---------- misc ---------- */
.empty, .loading { text-align: center; color: var(--muted); padding: 40px 16px; }
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 80;
  background: var(--surface-2); border: 1px solid var(--accent); color: var(--text);
  border-radius: 999px; padding: 9px 18px; font-size: 13.5px; box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
[hidden] { display: none !important; }
