/* Admin layout on top of /ui.css tokens. */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: 60px; padding: 0 max(24px, calc((100vw - 1120px) / 2 + 24px));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--page) 85%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.topbar-title { font-weight: 600; letter-spacing: -.01em; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.button-wide { width: 100%; }

.label { display: block; margin: 18px 0 8px; font-size: 14px; font-weight: 500; }
.optional { color: var(--muted); font-weight: 400; }
.hint { margin-top: 8px; font-size: 13px; line-height: 1.5; color: var(--muted); }
.form-error { margin-top: 12px; font-size: 14px; color: var(--danger); }
.form-error:empty { display: none; }
textarea.field { resize: vertical; line-height: 1.5; }
.field.is-invalid { border-color: var(--danger); }

/* Sign-in */
.login {
  width: min(400px, calc(100% - 32px)); margin: 12vh auto 0; padding: 32px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow);
}
.login h1 { font-size: 24px; font-weight: 600; letter-spacing: -.02em; }
.login-lead { margin: 8px 0 6px; color: var(--muted); font-size: 14px; }
.login .button { margin-top: 20px; }

/* Library */
.admin { max-width: 1120px; margin: 0 auto; padding: 36px 24px 80px; }
.library-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.library-head h1 { font-size: 28px; font-weight: 600; letter-spacing: -.02em; display: flex; align-items: baseline; gap: 10px; }
.count { color: var(--muted); font-size: 18px; font-weight: 500; font-variant-numeric: tabular-nums; }
.library-tools { display: flex; gap: 8px; align-items: center; }
.search { width: 240px; }

.library { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); overflow: hidden; }
.library:empty { display: none; }
.video {
  display: grid; grid-template-columns: 176px minmax(0, 1fr) auto; gap: 20px; align-items: center;
  padding: 14px 16px; border-top: 1px solid var(--line);
}
.video:first-child { border-top: 0; }
.video[hidden] { display: none; }
.video:hover { background: var(--hover); }

.thumb {
  position: relative; display: grid; place-items: center; aspect-ratio: 16 / 9; overflow: hidden;
  border-radius: 8px; background: var(--sunken); color: var(--muted);
}
.thumb svg { width: 28px; height: 28px; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .2s; }
.thumb.has-image img { opacity: 1; }
.thumb-time {
  position: absolute; right: 6px; bottom: 6px; padding: 2px 6px; border-radius: 5px;
  background: #000000b3; color: #fff; font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums;
}
.video-title { font-size: 16px; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.video-description {
  margin-top: 4px; color: var(--ink-2); font-size: 14px;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
}
.video-meta { margin-top: 6px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.video-actions { display: flex; gap: 4px; align-items: center; }

.empty { padding: 56px 24px; text-align: center; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: 14px; }
.empty-title { color: var(--ink); font-weight: 600; margin-bottom: 6px; }

/* Upload and processing */
.jobs { display: grid; gap: 10px; margin-bottom: 16px; }
.jobs:empty { display: none; }
.job {
  display: flex; align-items: center; gap: 16px; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.job-text { flex: 1; min-width: 0; }
.job-title { font-weight: 600; overflow-wrap: anywhere; }
.job-status { margin-top: 2px; color: var(--muted); font-size: 14px; }
.job-failed { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.job-failed .job-status { color: var(--danger); }
.job-bar { position: relative; height: 4px; margin-top: 10px; border-radius: 4px; background: var(--sunken); overflow: hidden; }
.job-fill { width: 0; height: 100%; border-radius: inherit; background: var(--ink); transition: width .3s; }
.job-bar.is-indeterminate .job-fill { position: absolute; width: 30%; animation: job-slide 1.4s ease-in-out infinite; }
@keyframes job-slide { from { left: -30%; } to { left: 100%; } }

/* Dialogs */
.dialog {
  width: min(520px, calc(100% - 32px)); max-height: calc(100% - 48px); padding: 0;
  border: 1px solid var(--line); border-radius: 16px; background: var(--raised); color: var(--ink); box-shadow: var(--shadow);
}
.dialog-wide { width: min(960px, calc(100% - 32px)); }
.dialog::backdrop { background: #0a0b0d8c; backdrop-filter: blur(3px); }
.dialog-body { padding: 24px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.dialog-head h2 { font-size: 20px; font-weight: 600; line-height: 1.3; letter-spacing: -.01em; overflow-wrap: anywhere; padding-top: 6px; }
.dialog-close { margin: -2px -8px 0 0; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }

.drop {
  position: relative; display: grid; justify-items: center; gap: 6px; padding: 28px 20px; text-align: center;
  border: 1.5px dashed var(--line-strong); border-radius: 12px; background: var(--page); cursor: pointer;
  transition: border-color .15s, background-color .15s;
}
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop:hover, .drop.is-over { border-color: var(--ink); }
.drop:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; }
.drop svg { width: 28px; height: 28px; color: var(--muted); margin-bottom: 4px; }
.drop-title { font-weight: 500; }
.drop-title u { text-underline-offset: 3px; }
.drop-note { font-size: 13px; color: var(--muted); }
.drop-file { margin-top: 6px; padding: 6px 10px; border-radius: 8px; background: var(--sunken); font-size: 13px; font-weight: 500; overflow-wrap: anywhere; }
.drop.has-file { border-style: solid; }

.share-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.preview { aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; background: #000; }
.preview iframe { display: block; width: 100%; height: 100%; border: 0; }
.share-fields .label:first-child { margin-top: 0; }
.field-time { width: 140px; font-variant-numeric: tabular-nums; }
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row .field { flex: 1; min-width: 0; }
.copy-row-end { justify-content: space-between; margin-top: 8px; }
.copy-row-end .hint { margin: 0; }
.code { font: 12px/1.55 ui-monospace, "SF Mono", Menlo, monospace; color: var(--ink-2); }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 20; translate: -50% 12px;
  max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 10px;
  background: var(--primary); color: var(--primary-ink); font-size: 14px; font-weight: 500; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s, translate .2s;
}
.toast.is-visible { opacity: 1; translate: -50% 0; }

@media (max-width: 760px) {
  .topbar { padding: 0 16px; }
  .admin { padding: 24px 16px 64px; }
  .library-tools, .search { width: 100%; }
  .library-tools #open-upload { flex: none; }
  .video { grid-template-columns: 112px minmax(0, 1fr); gap: 12px 14px; padding: 12px; }
  .video-actions { grid-column: 1 / -1; }
  .video-actions .button:first-child { flex: 1; }
  .video-description { display: none; }
  .share-grid { grid-template-columns: 1fr; }
  .dialog-body { padding: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .job-bar.is-indeterminate .job-fill { animation: none; width: 100%; opacity: .4; }
}
