*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f0f0f;
  --surface:   #1a1a1a;
  --surface2:  #222;
  --border:    #2a2a2a;
  --accent:    #FF5733;
  --purple:    #7c6af7;
  --text:      #f0f0f0;
  --muted:     #888;
  --danger:    #ef4444;
  --sidebar-w: 220px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
}

/* ── Layout ──────────────────────────────────────────── */
body { display: flex; }

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  position: sticky;
  top: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 24px;
  font-size: 16px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
}

.sidebar-nav {
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, color .15s;
  cursor: pointer;
}
.nav-item:hover  { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(255,87,51,.12); color: var(--accent); }

/* ── Main ────────────────────────────────────────────── */
.main {
  flex: 1;
  overflow-y: auto;
  min-height: 100vh;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 18px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.top-bar-left { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.top-bar-left h1 { font-size: 22px; font-weight: 700; }
.video-count { font-size: 13px; color: var(--muted); }

.admin-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(255, 87, 51, 0.12);
  border: 1px solid rgba(255, 87, 51, 0.28);
  padding: 3px 10px;
  border-radius: 999px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  align-self: center;
}

.top-bar-right { display: flex; align-items: center; gap: 10px; }

.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  color: var(--muted);
}
.search-wrap input {
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  width: 200px;
}
.search-wrap input::placeholder { color: var(--muted); }

.sort-select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  padding: 7px 12px;
  cursor: pointer;
  outline: none;
}

/* ── Grid ────────────────────────────────────────────── */
.grid-wrap { padding: 28px 32px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

/* ── Video Card ──────────────────────────────────────── */
.video-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s, border-color .15s, box-shadow .15s;
  position: relative;
}
.video-card:hover {
  transform: translateY(-3px);
  border-color: #3a3a3a;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

.card-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--surface2);
  position: relative;
  overflow: hidden;
}
.card-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.card-thumb .no-thumb {
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
}
.card-duration {
  position: absolute;
  bottom: 8px; right: 8px;
  background: rgba(0,0,0,.75);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  backdrop-filter: blur(4px);
}

/* Play overlay on hover */
.card-thumb::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.35);
  opacity: 0;
  transition: opacity .15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-card:hover .card-thumb::after { opacity: 1; }

.card-play-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .15s;
  pointer-events: none;
}
.video-card:hover .card-play-icon { opacity: 1; }
.card-play-icon svg {
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.6));
}

.card-body { padding: 12px 14px 14px; }
.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 5px;
}
.card-meta {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Inline status pills shown next to date/size in the card meta row. */
.card-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  margin-left: auto;
}
.card-badge-transcribing {
  background: rgba(124, 106, 247, 0.15);
  color: #b6acff;
  border: 1px solid rgba(124, 106, 247, 0.35);
  /* tiny pulse so users notice it'll change */
  animation: card-badge-pulse 1.6s ease-in-out infinite;
}
.card-badge-failed {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.32);
}
@keyframes card-badge-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

.card-owner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  min-width: 0; /* allow flex children to shrink for ellipsis */
}
.card-owner-avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface2);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
}
.card-owner-fallback {
  background: linear-gradient(135deg, #ff5733, #7c6af7);
  color: #fff;
}
.card-owner-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}
.card-owner-name {
  font-size: 11px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-owner-email {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-actions {
  display: flex;
  gap: 6px;
  padding: 0 14px 12px;
}

.btn-copy, .btn-open {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity .15s;
  background: var(--surface2);
  color: var(--text);
}
.btn-copy:hover, .btn-open:hover { opacity: .8; }

/* ── Skeleton ────────────────────────────────────────── */
@keyframes shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position:  400px 0; }
}

.skeleton-card {
  border-radius: 12px;
  aspect-ratio: 16/10;
  background: linear-gradient(90deg, #1e1e1e 25%, #2a2a2a 50%, #1e1e1e 75%);
  background-size: 400px 100%;
  animation: shimmer 1.4s infinite;
}

/* ── Empty / Error states ────────────────────────────── */
.empty-state, .error-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  gap: 14px;
  color: var(--muted);
  text-align: center;
}
.empty-state h2  { font-size: 20px; color: var(--text); }
.empty-state p   { font-size: 14px; max-width: 400px; line-height: 1.5; }
.btn-retry {
  padding: 8px 20px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}

/* ── Sidebar foot (log + version) ────────────────────── */
.sidebar-foot {
  margin-top: auto;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
  transition: background .15s, color .15s;
  font-family: inherit;
}
.sidebar-link:hover { background: var(--surface2); color: var(--text); }
.sidebar-link-quiet { color: #666; font-size: 11px; padding-top: 4px; padding-bottom: 6px; }
.sidebar-link-quiet:hover { color: var(--danger); background: transparent; }

.sidebar-version {
  padding: 12px 20px 14px;
  font-size: 11px;
  color: #666;
  letter-spacing: 0.3px;
  user-select: text;
}

/* ── Auth overlay ────────────────────────────────────── */
.auth-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 15, 15, .55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  z-index: 9999;
}
.auth-card {
  background: #fff;
  border-radius: 16px;
  padding: 28px 24px 24px;
  width: 360px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 24px 64px rgba(0,0,0,.32);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.auth-card .auth-icon {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: rgba(255, 87, 51, 0.1);
  display: grid; place-items: center;
  margin-bottom: 6px;
}
.auth-card h2 {
  font-size: 18px;
  font-weight: 700;
  color: #111;
  margin: 0;
}
.auth-card p {
  font-size: 13px;
  color: #666;
  margin: 0 0 14px;
  line-height: 1.45;
}
.auth-card .google-signin-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #dadce0;
  background: #fff;
  color: #1f1f1f;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
}
.auth-card .google-signin-btn:hover {
  background: #fafafa;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.auth-card .google-signin-btn:disabled {
  opacity: .6; cursor: progress;
}
.auth-card .auth-error {
  margin-top: 10px;
  font-size: 12px;
  color: #d33;
  background: rgba(211, 51, 51, .08);
  padding: 6px 10px;
  border-radius: 6px;
  word-wrap: break-word;
}

/* ── User chip in top bar ────────────────────────────── */
.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.user-chip img {
  width: 26px; height: 26px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface2);
}
.user-chip .user-meta {
  display: flex; flex-direction: column;
  line-height: 1.1;
  max-width: 180px;
}
.user-chip .user-email {
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}
.user-chip .signout-link {
  background: none; border: none; padding: 0;
  font-size: 11px; color: var(--muted); cursor: pointer;
  text-align: left; margin-top: 1px;
}
.user-chip .signout-link:hover { color: var(--accent); text-decoration: underline; }
.user-chip img:not([src]), .user-chip img[src=""] { display: none; }

/* Make [hidden] win over display:flex/grid */
[hidden] { display: none !important; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 720px) {
  body { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 12px 16px;
    position: relative;
  }
  .sidebar-logo { padding: 0; border: none; flex: 1; }
  .sidebar-nav { padding: 0; flex-direction: row; }
  .top-bar { flex-direction: column; align-items: flex-start; }
  .top-bar-right { width: 100%; flex-wrap: wrap; }
  .search-wrap input { width: 100%; }
  .grid-wrap { padding: 20px 16px; }
}
