:root {
  --bg: #0b1020;
  --bg-elev: #121a2f;
  --bg-card: #162038;
  --bg-input: #0e1629;
  --border: #263557;
  --border-subtle: #1e2b48;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #8b5cf6;
  --accent-hover: #7c3aed;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --radius-lg: 16px;
  --radius-md: 11px;
  --radius-sm: 8px;
}

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

html,
body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
  background: radial-gradient(circle at 15% 0%, #17254a 0%, var(--bg) 52%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  width: 100%;
  max-width: 1180px;
  margin-inline: auto;
  padding: 18px 16px 48px;
}

/* Header */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: grid;
  place-items: center;
  color: #fff;
  box-shadow: 0 8px 20px rgba(59, 130, 246, 0.32);
}

.brand-title {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-subtitle {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  word-break: keep-all;
}

.status-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-elev);
}

.pill-live {
  border-color: rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
}

.pill-live .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.pill-offline {
  border-color: rgba(245, 158, 11, 0.45);
  color: #fcd34d;
}

.pill-offline .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
}

/* KPI Strip: 2x2 on mobile, 4 columns in 1 single horizontal row at >= 720px (iPad 768px/810px+) */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

@media (min-width: 720px) {
  .kpi-strip {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.kpi-label {
  font-size: 0.74rem;
  color: var(--text-muted);
  font-weight: 600;
}

.kpi-value {
  font-size: 1.02rem;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
}

.kpi-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Cards */
.main-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: 0 12px 32px rgba(3, 7, 18, 0.35);
}

.hero-header,
.queue-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.section-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 700;
}

.section-desc {
  margin: 3px 0 0;
  font-size: 0.83rem;
  color: var(--text-muted);
  word-break: keep-all;
}

.engine-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-tag {
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(59, 130, 246, 0.13);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: #93c5fd;
  font-weight: 600;
}

/* URL Form & modern-web-guidance :user-invalid / :user-valid */
.label-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 6px;
}

.field-label {
  font-size: 0.88rem;
  font-weight: 700;
}

.hint {
  display: block;
  font-size: 0.77rem;
  color: var(--text-muted);
}

.url-input-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.url-input {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  font-size: 0.96rem;
  color: var(--text);
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.url-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.22);
}

.url-input:user-valid,
.url-input.user-valid-fallback {
  border-color: var(--success);
}

.url-input:user-invalid,
.url-input.user-invalid-fallback {
  border-color: var(--danger);
  background-color: var(--danger-bg);
}

.error-msg {
  display: none;
  color: #fca5a5;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 4px 2px 0;
}

.url-input:user-invalid + .error-msg,
.url-input.user-invalid-fallback + .error-msg {
  display: block;
}

.hero-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

@media (min-width: 720px) {
  .hero-actions {
    grid-template-columns: auto auto 1.3fr 1fr;
  }
}

/* Buttons (Minimum 42px touch target for mobile/iPad QA) */
.btn {
  min-height: 42px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  transition: background-color 0.15s ease, transform 0.08s ease, opacity 0.15s ease;
  word-break: keep-all;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-accent {
  background: var(--accent);
  color: #ffffff;
}

.btn-accent:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: #1f2e4d;
  border-color: #314773;
  color: #e2e8f0;
}

.btn-secondary:hover:not(:disabled) {
  background: #283b63;
}

.btn-success {
  background: var(--success);
  color: #052e16;
}

.btn-success:hover:not(:disabled) {
  background: #34d399;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.btn-danger-ghost {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.btn-danger-ghost:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.24);
}

.btn-sm {
  min-height: 36px;
  padding: 6px 11px;
  font-size: 0.78rem;
}

.btn-lg {
  min-height: 44px;
  width: 100%;
}

/* Status Banner */
.status-banner {
  margin-top: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-elev);
}

.status-banner.info {
  border-color: rgba(59, 130, 246, 0.45);
  color: #bfdbfe;
}

.status-banner.error {
  border-color: rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.12);
  color: #fecaca;
}

.status-banner.success {
  border-color: rgba(16, 185, 129, 0.45);
  background: rgba(16, 185, 129, 0.1);
  color: #a7f3d0;
}

/* Analyzed Preview Panel */
.analysis-panel {
  margin-top: 16px;
  padding: 15px;
  background: var(--bg-elev);
  border: 1px solid #2f4673;
  border-radius: var(--radius-md);
}

.preview-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

@media (min-width: 680px) {
  .preview-grid {
    grid-template-columns: 240px minmax(0, 1fr);
    align-items: center;
  }
}

.thumb-box {
  position: relative;
  aspect-ratio: 16 / 9;
  width: 100%;
  background: #090e1c;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.preview-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.duration-badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 2px 7px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

.preview-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.meta-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  font-size: 0.73rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
}

.badge-blue {
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
}

.badge-slate {
  background: rgba(148, 163, 184, 0.16);
  color: #cbd5e1;
}

.preview-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.preview-uploader {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.quality-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 4px;
}

@media (min-width: 680px) {
  .quality-row {
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    align-items: end;
  }
}

.sub-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: #cbd5e1;
  margin-bottom: 3px;
}

.mini-hint {
  display: block;
  font-size: 0.73rem;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.select-control,
.text-control,
.textarea-control {
  width: 100%;
  min-height: 41px;
  padding: 8px 11px;
  font-size: 0.86rem;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  font-family: inherit;
}

.textarea-control {
  min-height: 76px;
  resize: vertical;
}

.select-control:focus,
.text-control:focus,
.textarea-control:focus {
  border-color: var(--primary);
}

/* Collapsible <details> Drawers */
.drawers-grid {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.drawer {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-elev);
  overflow: hidden;
}

.drawer-summary {
  list-style: none;
  cursor: pointer;
  min-height: 44px;
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.86rem;
  font-weight: 700;
  user-select: none;
}

.drawer-summary::-webkit-details-marker {
  display: none;
}

.drawer-hint {
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-muted);
}

.drawer[open] .drawer-summary {
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(59, 130, 246, 0.06);
}

.drawer-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.spa-toggle-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.25);
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.82rem;
  cursor: pointer;
  flex: 1 1 260px;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--primary);
  flex-shrink: 0;
}

.form-grid-2,
.form-grid-3 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 720px) {
  .form-grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .form-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.batch-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.batch-select {
  max-width: 220px;
}

/* Filter Tabs */
.filter-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  background: var(--bg-input);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.tab-btn {
  min-height: 36px;
  padding: 6px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.tab-btn.active {
  background: var(--primary);
  color: #fff;
}

.empty-state {
  padding: 32px 16px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  background: rgba(14, 22, 41, 0.45);
}

.empty-title {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 700;
}

.empty-desc {
  margin: 5px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Responsive Data Table (modern-web-guidance `responsive-table` + zero overflow on iPad 768px/810px) */
.table-wrapper {
  overflow-x: hidden;
  overflow-y: auto;
  max-inline-size: 100%;
  max-block-size: min(620px, 78vh);
  container-type: inline-size;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.quant-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  --label-2: "포맷·옵션";
  --label-3: "진행 상태";
  --label-4: "저장·관리";
}

.quant-table thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  background: #10192e;
}

.quant-table thead th {
  text-align: left;
  padding: 11px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  word-break: keep-all;
}

.quant-table .col-title {
  width: 36%;
}
.quant-table .col-format {
  width: 16%;
}
.quant-table .col-progress {
  width: 26%;
}
.quant-table .col-actions {
  width: 22%;
}

.quant-table tbody th,
.quant-table tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
  font-size: 0.83rem;
  background: var(--bg-card);
  min-width: 0;
}

.quant-table tbody th {
  text-align: left;
  font-weight: 600;
}

.job-title-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.job-mini-thumb {
  width: 58px;
  height: 34px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: #090e1c;
  border: 1px solid var(--border);
}

.job-title-text {
  min-width: 0;
  flex: 1;
}

.job-name {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.job-host {
  display: block;
  font-size: 0.73rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.format-pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  background: rgba(139, 92, 246, 0.16);
  color: #ddd6fe;
}

.trim-note {
  display: block;
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.prog-wrap {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.prog-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
}

.prog-label {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prog-label.st-completed {
  color: #6ee7b7;
}
.prog-label.st-failed,
.prog-label.st-cancelled {
  color: #fca5a5;
}
.prog-label.st-downloading,
.prog-label.st-merging {
  color: #93c5fd;
}

.prog-bar {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: #0b1222;
  overflow: hidden;
}

.prog-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), #38bdf8);
  transition: width 0.25s ease;
}

.prog-fill.done {
  background: var(--success);
}

.prog-fill.err {
  background: var(--danger);
}

.prog-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Mobile Stacked Card Transformation (< 640px container width) */
@container (width < 640px) {
  .quant-table,
  .quant-table thead,
  .quant-table tbody,
  .quant-table tr,
  .quant-table th,
  .quant-table td {
    display: block;
    width: 100%;
  }

  .quant-table thead {
    display: none;
  }

  .quant-table tbody tr {
    margin-block-end: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
  }

  .quant-table tbody th {
    position: sticky;
    inset-block-start: 0;
    z-index: 1;
    background: #1a2744;
    border-bottom: 1px solid var(--border);
  }

  .quant-table tbody td {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
  }

  .quant-table tbody td:nth-child(2)::before {
    content: var(--label-2) ": ";
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
  }

  .quant-table tbody td:nth-child(3)::before {
    content: var(--label-3) ": ";
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
  }

  .quant-table tbody td:nth-child(4)::before {
    content: var(--label-4) ": ";
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
  }
}

/* Preview <dialog> */
.preview-dialog {
  width: min(92vw, 840px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  color: var(--text);
}

.preview-dialog::backdrop {
  background: rgba(3, 7, 18, 0.78);
}

.dialog-inner {
  padding: 16px;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.dialog-title {
  margin: 0;
  font-size: 0.96rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dialog-video {
  width: 100%;
  max-height: 70vh;
  background: #000;
  border-radius: var(--radius-sm);
}
