/* =========================================================================
   Bendigos Web — Media Library
   Monochrome terminal theme. No external fonts/scripts — everything here
   stays compliant with the app's CSP (style-src 'self', script-src 'self').
   ========================================================================= */

:root {
  --bg: #060607;
  --bg-raised: #0a0b0c;
  --panel: #101113;
  --panel-hover: #17191b;
  --border: #232527;
  --border-soft: #191b1c;

  --text: #edeeee;
  --text-dim: #9aa0a0;
  --muted: #5c6263;

  --white: #ffffff;
  --glow: rgba(255, 255, 255, 0.08);
  --glow-strong: rgba(255, 255, 255, 0.22);

  --danger: #ff5c5c;
  --danger-glow: rgba(255, 92, 92, 0.14);

  --rail-w: 72px;
  --radius: 4px;

  --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", "Source Code Pro",
           "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: inherit; }

/* Faint CRT scanline wash over the whole app — quiet, not a gimmick. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.014) 0px,
    rgba(255, 255, 255, 0.014) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: overlay;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ---------------- App shell ---------------- */

.app-shell {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  min-height: 100vh;
}

/* ---------------- Icon rail ---------------- */

.rail {
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem 0;
  gap: 0.35rem;
}

.rail-logo {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 0.9rem;
  border: 1px solid var(--border);
}

.rail-spacer { flex: 1; }

.rail-item {
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  border: 1px solid transparent;
  background: none;
  cursor: pointer;
  font-family: var(--mono);
  position: relative;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.rail-item svg { width: 20px; height: 20px; stroke: currentColor; fill: none; }
.rail-item:hover {
  color: var(--text);
  border-color: var(--border);
  background: var(--panel);
}
.rail-item.is-active {
  color: var(--white);
  background: var(--panel);
  border-color: var(--border);
}
.rail-item.is-active::before {
  content: "";
  position: absolute;
  left: -13px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 22px;
  background: var(--white);
  border-radius: 2px;
  box-shadow: 0 0 10px var(--glow-strong);
}
.rail-item.is-unlocked { color: var(--white); }
.rail-item[title] { }
.rail-form { display: contents; }

/* ---------------- Main column ---------------- */

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 1.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: 0.92rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.brand-text::before { content: "> "; color: var(--muted); }
.brand-text::after {
  content: "_";
  animation: blink 1.1s step-end infinite;
  margin-left: 1px;
  color: var(--white);
}
@keyframes blink { 50% { opacity: 0; } }

.search-form {
  flex: 1;
  display: flex;
  max-width: 620px;
  margin: 0 auto;
}
.search-form-inner {
  display: flex;
  align-items: center;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  padding: 0.2rem 0.3rem 0.2rem 1rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-form-inner:focus-within {
  border-color: var(--text-dim);
  box-shadow: 0 0 0 3px var(--glow);
}
.search-form-inner svg { width: 16px; height: 16px; stroke: var(--muted); flex-shrink: 0; }
.search-form input {
  flex: 1;
  border: 0;
  background: none;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.9rem;
  padding: 0.55rem 0.7rem;
  outline: none;
}
.search-form input::placeholder { color: var(--muted); }
.search-form button {
  border: 0;
  background: var(--white);
  color: var(--bg);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.03em;
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  cursor: pointer;
  transition: box-shadow 0.15s ease, opacity 0.15s ease;
}
.search-form button:hover { box-shadow: 0 0 16px var(--glow-strong); }
.clear-link {
  align-self: center;
  color: var(--muted);
  font-size: 0.8rem;
  text-decoration: none;
  white-space: nowrap;
}
.clear-link:hover { color: var(--text); }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}
.logout-form { display: contents; }
.link-button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius);
  transition: color 0.15s ease, border-color 0.15s ease;
}
.link-button:hover { color: var(--white); border-color: var(--text-dim); }

.container {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.75rem 1.75rem 3rem;
}

/* ---------------- Hero / terminal panel ---------------- */

.hero {
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, var(--bg-raised) 0%, var(--bg) 100%);
  border-radius: 8px;
  padding: 1.6rem 1.8rem;
  margin-bottom: 1.75rem;
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 85% 0%, var(--glow), transparent 55%);
  pointer-events: none;
}
.hero-titlebar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 1rem;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
}
.hero-dot { width: 8px; height: 8px; border-radius: 50%; border: 1px solid var(--border); }
.hero-path { margin-left: 0.5rem; }
.hero-headline {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--white);
}
.hero-sub {
  margin: 0 0 1.1rem;
  color: var(--text-dim);
  max-width: 46ch;
  font-size: 0.88rem;
}
.hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.6rem;
  font-size: 0.82rem;
  color: var(--text-dim);
}
.hero-stats li { list-style: none; }
.hero-stats b { color: var(--white); font-weight: 700; }
.hero-cursor-line { color: var(--muted); }
.hero-cursor {
  display: inline-block;
  width: 8px;
  height: 1em;
  background: var(--white);
  vertical-align: -0.15em;
  animation: blink 1s step-end infinite;
  margin-left: 2px;
}

/* ---------------- Breadcrumbs ---------------- */

.breadcrumbs {
  margin-bottom: 1.4rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.breadcrumbs a { color: var(--muted); text-decoration: none; }
.breadcrumbs a:hover { color: var(--white); }
.breadcrumbs a:last-child { color: var(--text); }
.crumb-sep { margin: 0 0.4rem; color: var(--border); }

.section-label {
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.9rem;
}

/* ---------------- Video / folder grid ---------------- */

.video-grid {
  list-style: none;
  padding: 0;
  margin: 0 0 2rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.2rem;
}

.video-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.video-card:hover,
.video-card:focus-within {
  border-color: var(--text-dim);
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--glow);
}
.video-card a.video-link {
  display: block;
  text-decoration: none;
  color: var(--text);
}

.thumb-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--bg-raised);
  overflow: hidden;
}
.thumb-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  color: var(--muted);
  transition: color 0.15s ease, opacity 0.15s ease;
}
.video-card:hover .thumb-icon,
.video-card:focus-within .thumb-icon { color: var(--text-dim); }
.folder-card .thumb-icon { font-size: 1.9rem; letter-spacing: 0.05em; }

.thumb-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: saturate(0.35) contrast(1.05) brightness(0.85);
  transition: filter 0.2s ease;
}
.video-card:hover .thumb-img,
.video-card:focus-within .thumb-img { filter: saturate(0.55) contrast(1.05) brightness(0.95); }
/* Hidden by default; JS reveals this only if the <img> above fails to load
   (ffmpeg not installed yet, or frame extraction failed for that file). */
.thumb-icon-fallback { display: none; }
.thumb-icon-fallback.is-visible { display: flex; }

/* corner brackets, viewfinder-style — quiet hacker accent on hover */
.thumb-wrap::before,
.thumb-wrap::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 0 solid var(--white);
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}
.thumb-wrap::before { top: 6px; left: 6px; border-top-width: 2px; border-left-width: 2px; }
.thumb-wrap::after { bottom: 6px; right: 6px; border-bottom-width: 2px; border-right-width: 2px; }
.video-card:hover .thumb-wrap::before,
.video-card:hover .thumb-wrap::after,
.video-card:focus-within .thumb-wrap::before,
.video-card:focus-within .thumb-wrap::after { opacity: 0.55; }

.thumb-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.thumb-preview.is-active { opacity: 1; }

.thumb-badge {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.78);
  border: 1px solid var(--border-soft);
  color: var(--text);
  font-size: 0.68rem;
  padding: 0.12rem 0.4rem;
  border-radius: 3px;
  font-variant-numeric: tabular-nums;
}
.thumb-live {
  position: absolute;
  top: 6px;
  left: 6px;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  background: rgba(0, 0, 0, 0.78);
  border: 1px solid var(--border-soft);
  color: var(--text);
  font-size: 0.64rem;
  letter-spacing: 0.06em;
  padding: 0.15rem 0.4rem 0.15rem 0.3rem;
  border-radius: 3px;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.thumb-live.is-active { opacity: 1; }
.thumb-live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 6px var(--danger-glow);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.video-info { padding: 0.7rem 0.85rem 0.85rem; }
.video-title {
  font-weight: 500;
  font-size: 0.9rem;
  line-height: 1.35;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.video-meta {
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.74rem;
}

.private-card {
  border-style: dashed;
}

.empty-state { color: var(--muted); }


/* ---------------- Bare pages (login / unlock / error) ---------------- */

.bare-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.bare-topbar {
  padding: 1.3rem 1.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
}
.bare-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}
.bare-container { padding: 0; max-width: 380px; }
.bare-brand-logo { margin-bottom: 0; width: 32px; height: 32px; }

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.5);
}
.auth-card h1 {
  margin: 0 0 0.3rem;
  font-size: 1.1rem;
  color: var(--white);
  letter-spacing: 0.01em;
}
.auth-card .auth-sub {
  margin: 0 0 1.4rem;
  color: var(--muted);
  font-size: 0.8rem;
}
.auth-card label {
  display: block;
  margin-top: 1rem;
  margin-bottom: 0.35rem;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.auth-card input {
  width: 100%;
  padding: 0.65rem 0.8rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.auth-card input:focus {
  outline: none;
  border-color: var(--text-dim);
  box-shadow: 0 0 0 3px var(--glow);
}
.auth-card button {
  margin-top: 1.6rem;
  width: 100%;
  padding: 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--bg);
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: box-shadow 0.15s ease, opacity 0.15s ease;
}
.auth-card button:hover { box-shadow: 0 0 24px var(--glow-strong); }
.auth-back {
  margin-top: 1.2rem;
  display: block;
  text-align: center;
}

.back-link { color: var(--text-dim); text-decoration: none; font-size: 0.85rem; }
.back-link:hover { color: var(--white); }

.error-box { max-width: 440px; margin: 0 auto; text-align: center; }
.error-box h1 { color: var(--white); margin-bottom: 0.5rem; }
.error-box p { color: var(--text-dim); }
.error-box a { color: var(--text-dim); }
.error-box a:hover { color: var(--white); }

/* ---------------- Watch page ---------------- */

.watch-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.watch-head h1 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0.5rem 0 1rem;
  color: var(--white);
}

.player {
  width: 100%;
  max-height: 72vh;
  border-radius: 8px;
  background: black;
  border: 1px solid var(--border);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.55);
}

.player-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
  flex-wrap: wrap;
  gap: 1rem;
}
.player-nav { display: flex; gap: 0.6rem; }
.nav-button {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  transition: border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.nav-button:hover { border-color: var(--text-dim); box-shadow: 0 0 12px var(--glow); }
.nav-button-disabled { color: var(--muted); cursor: default; opacity: 0.4; }
.nav-button-disabled:hover { border-color: var(--border); box-shadow: none; color: var(--muted); }

.autoplay-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
}
.autoplay-toggle input { cursor: pointer; accent-color: var(--white); }

/* ---------------- Flashes ---------------- */

.flashes { list-style: none; padding: 0; margin: 0 0 1.5rem; }
.flash {
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  border: 1px solid transparent;
}
.flash-error { background: var(--danger-glow); color: var(--danger); border-color: rgba(255, 92, 92, 0.3); }
.flash-message { background: var(--glow); color: var(--text); border-color: var(--border); }

/* ---------------- Responsive ---------------- */

@media (max-width: 720px) {
  .app-shell { grid-template-columns: 1fr; }
  .rail {
    flex-direction: row;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .rail-logo { display: none; }
  .rail-spacer { display: none; }
  .topbar { flex-wrap: wrap; padding: 0.9rem 1rem; }
  .topbar-user { order: 3; width: 100%; justify-content: flex-end; }
  .container { padding: 1.25rem 1rem 2.5rem; }
  .hero { padding: 1.2rem 1.25rem; }
  .video-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.85rem; }
  .private-bar {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    flex-wrap: wrap;
  }
}

/* ---------------- Private-unlocked indicator ---------------- */
/* Only ever rendered server-side when the session has actually unlocked
   the private folder -- never hints at its existence otherwise. */

.private-bar {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.55rem 0.6rem 0.55rem 1rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--glow);
}
.private-bar-text {
  font-size: 0.78rem;
  color: var(--text-dim);
  white-space: nowrap;
}
.private-bar-text::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--white);
  margin-right: 0.55rem;
  box-shadow: 0 0 6px var(--glow-strong);
}
.private-bar-btn {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.private-bar-btn:hover {
  border-color: var(--text-dim);
  color: var(--white);
  box-shadow: 0 0 14px var(--glow);
}
