/* ---------------------------------------------------------------------
   spool — design tokens
   Palette: deep graphite/navy console with a phosphor-amber signal
   accent (a nod to VU meters / oscilloscopes / tape decks), blue for
   "in progress", green strictly for success, red-orange for failure.
   Type: IBM Plex Sans for UI chrome, IBM Plex Mono for all data —
   speeds, sizes, percentages, URLs — because numbers on a console
   should look like console numbers.
--------------------------------------------------------------------- */
:root {
  --bg: #10131a;
  --surface: #171b24;
  --surface-2: #1e2330;
  --surface-3: #262c3c;
  --border: #2a3040;
  --border-soft: #232838;

  --text: #e7eaf1;
  --text-dim: #8b93a8;
  --text-faint: #565e73;

  --amber: #e8a33d;
  --amber-dim: #7a5a24;
  --blue: #5b9bd5;
  --blue-dim: #2c4a66;
  --green: #59c98a;
  --green-dim: #285e40;
  --red: #e8604a;
  --red-dim: #6e2e24;
  --gray: #6b7385;

  --radius: 3px;
  --radius-lg: 6px;

  --font-ui: "IBM Plex Sans", -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(circle at 15% 0%, rgba(232, 163, 61, 0.05), transparent 45%),
    radial-gradient(circle at 85% 10%, rgba(91, 155, 213, 0.05), transparent 40%);
  background-attachment: fixed;
}

a { color: var(--amber); }

::selection { background: var(--amber-dim); color: var(--text); }

button, input, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 28px 80px;
}

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 26px 0 18px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand-mark {
  font-family: var(--font-mono);
  color: var(--amber);
  font-size: 15px;
  letter-spacing: -2px;
}

.brand-name {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 19px;
  letter-spacing: 0.5px;
  color: var(--text);
}

.brand-sub {
  font-size: 12.5px;
  color: var(--text-faint);
  letter-spacing: 0.3px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.ffmpeg-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.ffmpeg-pill .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}
.ffmpeg-pill.warn .dot { background: var(--red); box-shadow: 0 0 6px var(--red); }
.ffmpeg-pill.warn { color: var(--red); border-color: var(--red-dim); }

/* ---------------------------------------------------------------- banner */

.banner {
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 18px;
}
.banner-warn {
  background: rgba(232, 96, 74, 0.08);
  border: 1px solid var(--red-dim);
  color: #f0a898;
}
.banner-warn a { color: var(--amber); margin-left: 6px; }

/* ---------------------------------------------------------------- buttons */

.btn {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--text-faint); background: var(--surface-3); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--amber);
  border-color: var(--amber);
  color: #1a1204;
}
.btn-primary:hover { background: #f0ad4e; border-color: #f0ad4e; }
.btn-primary:disabled {
  background: var(--surface-3);
  border-color: var(--border);
  color: var(--text-faint);
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
}

.btn-block { width: 100%; margin-top: 6px; }

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: var(--radius);
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
}
.icon-btn:hover { color: var(--text); background: var(--surface-3); }

/* ---------------------------------------------------------------- stats strip */

.stats-strip {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1px;
  background: var(--border-soft);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 18px;
}

.stat {
  background: var(--surface);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-num {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-faint);
}

.stat-active .stat-num { color: var(--blue); }
.stat-convert .stat-num { color: var(--amber); }
.stat-done .stat-num { color: var(--green); }
.stat-fail .stat-num { color: var(--red); }

/* ---------------------------------------------------------------- filter bar */

.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 16px;
}

.filter-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 3px;
}

.tab {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 2px;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface-3); color: var(--amber); }

.search-input {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--text);
  width: 260px;
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.search-input::placeholder { color: var(--text-faint); }

/* ---------------------------------------------------------------- job list */

.job-list-wrap {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
}

.job-list-head {
  display: grid;
  grid-template-columns: 2.2fr 0.9fr 1.6fr 1fr 1fr;
  gap: 12px;
  padding: 10px 18px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border-soft);
}

.job-list { display: flex; flex-direction: column; }

.job-row {
  display: grid;
  grid-template-columns: 2.2fr 0.9fr 1.6fr 1fr 1fr;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-soft);
  align-items: center;
  transition: background .15s;
}
.job-row:last-child { border-bottom: none; }
.job-row:hover { background: var(--surface-2); }

/* Admin view adds a "user" column between source and format - both the
   header and each row pick up the extra track together since they share
   this selector, so they always stay aligned. */
.job-list-wrap.is-admin-view .job-list-head,
.job-list-wrap.is-admin-view .job-row {
  grid-template-columns: 1.9fr 0.85fr 0.9fr 1.5fr 1fr 1fr;
}

.col-user {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.job-title {
  font-weight: 500;
  font-size: 13.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.job-url {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}
.job-error {
  font-size: 11.5px;
  color: var(--red);
  margin-top: 4px;
}

.col-format { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.format-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 2px;
  background: var(--surface-3);
  color: var(--text-dim);
  letter-spacing: 0.4px;
}
.quality-tag {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
}
.provider-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
}
.provider-tag.is-fallback {
  color: var(--amber);
}
.provider-tag.is-fallback::before {
  content: "↳ ";
}

.col-progress { display: flex; flex-direction: column; gap: 6px; }

.status-badge {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.status-badge.st-queued { color: var(--text-faint); }
.status-badge.st-downloading { color: var(--blue); }
.status-badge.st-converting { color: var(--amber); }
.status-badge.st-completed { color: var(--green); }
.status-badge.st-failed { color: var(--red); }
.status-badge.st-canceled { color: var(--gray); }

/* signature element: segmented, VU-meter style progress bar */
.progress-track {
  height: 8px;
  border-radius: 2px;
  background: var(--surface-3);
  overflow: hidden;
  position: relative;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background-image: repeating-linear-gradient(
    90deg,
    currentColor 0px, currentColor 5px,
    transparent 5px, transparent 7px
  );
  color: var(--blue);
  transition: width .4s ease;
}
.progress-fill.st-downloading { color: var(--blue); }
.progress-fill.st-converting {
  color: var(--amber);
  animation: pulse-segments 1.1s linear infinite;
}
.progress-fill.st-completed { color: var(--green); }
.progress-fill.st-failed { color: var(--red); }
.progress-fill.st-canceled { color: var(--gray); }
.progress-fill.st-queued { color: var(--text-faint); }

@keyframes pulse-segments {
  0% { background-position-x: 0; }
  100% { background-position-x: 24px; }
}

.progress-pct {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
}

.col-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}
.col-meta span:empty { display: none; }

.col-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ---------------------------------------------------------------- empty state */

.empty-state {
  text-align: center;
  padding: 70px 20px;
  color: var(--text-faint);
}
.empty-glyph { font-size: 30px; color: var(--border); margin-bottom: 10px; }
.empty-state p { margin: 4px 0; }
.empty-sub { font-size: 12.5px; }
.empty-state-tight { padding: 40px 0; }

/* ---------------------------------------------------------------- side panel */

.scrim {
  position: fixed; inset: 0;
  background: rgba(8, 10, 14, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 40;
}
.scrim.open { opacity: 1; pointer-events: auto; }

.panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 400px;
  max-width: 92vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform .25s ease;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.panel.open { transform: translateX(0); }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-soft);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.panel-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.field-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-faint);
  margin: 16px 0 7px;
}
.field-label:first-child { margin-top: 0; }

.field-hint {
  font-size: 11.5px;
  color: var(--text-faint);
  min-height: 15px;
  margin: 6px 2px 0;
}
.field-hint.error { color: var(--red); }

.text-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--text);
  width: 100%;
  font-family: var(--font-mono);
  font-size: 13px;
}
.text-input:focus { border-color: var(--amber); }

.url-row { display: flex; gap: 8px; }
.url-row .text-input { flex: 1; }

.preview-card {
  display: flex;
  gap: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 10px;
  margin-top: 12px;
}
.preview-card img {
  width: 84px; height: 47px;
  object-fit: cover;
  border-radius: 2px;
  background: var(--surface-3);
  flex-shrink: 0;
}
.preview-title {
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--text);
}
.preview-meta {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
  margin-top: 4px;
}

.format-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-dim);
  cursor: pointer;
}
.chip:hover { border-color: var(--text-faint); }
.chip.active { border-color: var(--amber); color: var(--amber); background: rgba(232,163,61,0.08); }

.panel-error {
  background: rgba(232, 96, 74, 0.1);
  border: 1px solid var(--red-dim);
  color: #f0a898;
  font-size: 12.5px;
  padding: 10px 12px;
  border-radius: var(--radius);
  margin-top: 16px;
}

select.text-input {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-faint) 50%),
                     linear-gradient(135deg, var(--text-faint) 50%, transparent 50%);
  background-position: calc(100% - 16px) center, calc(100% - 11px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

/* ---------------------------------------------------------------- toasts */

.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
}

.toast {
  font-size: 12.5px;
  padding: 11px 16px;
  border-radius: var(--radius);
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: 0 6px 20px rgba(0,0,0,0.35);
  max-width: 320px;
  animation: toast-in .2s ease;
}
.toast.toast-error { border-color: var(--red-dim); color: #f0a898; }
.toast.toast-success { border-color: var(--green-dim); color: #b7ecd0; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------------------------------------------------------- responsive */

@media (max-width: 860px) {
  .stats-strip { grid-template-columns: repeat(3, 1fr); }
  .job-list-head { display: none; }
  .job-row,
  .job-list-wrap.is-admin-view .job-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .col-actions { justify-content: flex-start; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .search-input { width: 100%; }
  /* Header row (with its "user" label) is hidden on mobile - without a
     label of some kind here, a bare username floating in the stacked
     layout is easy to misread as part of the title. */
  .col-user::before { content: "queued by "; color: var(--text-faint); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------------------------------------------------------------- user menu (topbar) */

.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
  margin-left: 4px;
  border-left: 1px solid var(--border);
}

.user-name {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-dim);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-form { margin: 0; }

/* ---------------------------------------------------------------- auth pages (login / register) */

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-wrap {
  width: 100%;
  padding: 24px;
  display: flex;
  justify-content: center;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 28px 26px 24px;
}

.auth-brand {
  justify-content: center;
  margin-bottom: 4px;
}

.auth-sub {
  text-align: center;
  font-size: 12.5px;
  color: var(--text-faint);
  margin: 0 0 20px;
}

.auth-form {
  display: flex;
  flex-direction: column;
}

.auth-form .field-label { margin-top: 14px; }
.auth-form .field-label:first-child { margin-top: 0; }

.auth-submit { margin-top: 22px; }

.auth-error {
  margin-bottom: 4px;
}

.auth-footer {
  text-align: center;
  font-size: 12.5px;
  color: var(--text-faint);
  margin: 18px 0 0;
}
.auth-footer a { color: var(--amber); text-decoration: none; }
.auth-footer a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- banners (extra states) */

.banner-ok {
  background: rgba(89, 201, 138, 0.08);
  border: 1px solid var(--green-dim);
  color: #b7ecd0;
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 18px;
}

/* ---------------------------------------------------------------- admin page */

.admin-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 18px;
  align-items: start;
}

.admin-panel {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.admin-panel-title {
  font-family: var(--font-mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-faint);
  margin: 0 0 16px;
}

.admin-table-wrap { overflow-x: auto; }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.admin-table th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-faint);
  padding: 0 10px 10px;
  border-bottom: 1px solid var(--border-soft);
}
.admin-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }

.admin-cell-user { font-weight: 500; }
.admin-cell-date { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-faint); }
.admin-cell-actions { text-align: right; }

.you-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 1px 6px;
  margin-left: 6px;
}

.role-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 2px;
}
.role-badge.role-admin { color: var(--amber); background: var(--amber-dim); }
.role-badge.role-user { color: var(--text-dim); background: var(--surface-3); }

.inline-form { margin: 0; }

.text-input-sm {
  padding: 5px 8px;
  font-size: 12px;
  width: auto;
}

.admin-delete-btn:hover { border-color: var(--red-dim); color: var(--red); }

@media (max-width: 860px) {
  .admin-grid { grid-template-columns: 1fr; }
}
