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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(160deg, #eff6ff 0%, #f8fafc 45%, #f1f5f9 100%);
  color: #0f172a;
  min-height: 100vh;
}

.page {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.logo {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, #2563eb, #25f4ee);
  color: #fff;
  font-weight: 800;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

h1 { font-size: 1.5rem; font-weight: 800; }
.header p { color: #64748b; font-size: 0.9rem; margin-top: 4px; }
.header a { color: #2563eb; text-decoration: none; }

.card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.06);
}

.message {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  margin-bottom: 12px;
}
.message.ok { background: #ecfdf5; color: #065f46; }
.message.error { background: #fef2f2; color: #991b1b; }
.message.warn { background: #fffbeb; color: #92400e; margin-bottom: 12px; }
.message.info { background: #eff6ff; color: #1e40af; margin-bottom: 12px; line-height: 1.45; }

.cdn-panel {
  margin-top: 14px;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.88rem;
}
.cdn-panel summary { cursor: pointer; font-weight: 600; color: #475569; }
.cdn-hint { margin: 8px 0 10px; }
#directUrl {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 8px;
}
.btn-secondary {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 11px;
  font-weight: 600;
  background: #f8fafc;
  cursor: pointer;
}
.btn-secondary:hover { background: #f1f5f9; }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.url-row { display: flex; gap: 8px; }
#url {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font-size: 0.95rem;
}
#url:focus { outline: 2px solid #93c5fd; border-color: #3b82f6; }

.btn-scan {
  padding: 0 16px;
  border: none;
  border-radius: 10px;
  background: #e2e8f0;
  font-weight: 600;
  cursor: pointer;
}
.btn-scan:hover { background: #cbd5e1; }
.btn-scan:disabled { opacity: 0.5; cursor: not-allowed; }

.hint { font-size: 0.8rem; color: #94a3b8; margin-top: 8px; }
.hint code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; }

.scan-state {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  color: #475569;
  font-size: 0.9rem;
}
.scan-state[hidden] {
  display: none !important;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #cbd5e1;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.options-panel { margin-top: 18px; }

.preview {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.preview-thumb {
  width: 88px;
  height: 88px;
  border-radius: 10px;
  object-fit: cover;
  background: linear-gradient(135deg, #1e293b, #334155);
  color: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.preview-title { font-size: 1rem; line-height: 1.35; font-weight: 700; }
.preview-meta { font-size: 0.8rem; color: #64748b; margin-top: 6px; }

.label { font-size: 0.75rem; text-transform: uppercase; color: #94a3b8; margin-bottom: 8px; }

.quality-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.quality-opt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
}
.quality-opt:has(input:checked) {
  border-color: #2563eb;
  background: #eff6ff;
}

.btn-primary {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: opacity 0.2s ease, filter 0.2s ease;
}
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary--loading,
.btn-primary--locked {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
  filter: saturate(0.75);
  box-shadow: none;
}

.btn-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}

.active-panel {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid #e2e8f0;
}
.active-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.active-panel-head h2 {
  font-size: 0.95rem;
  font-weight: 800;
  color: #1e40af;
}
.active-job-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.active-job-card {
  border: 1px solid #dbeafe;
  border-radius: 12px;
  padding: 12px 14px;
  background: #f8fafc;
}
.active-job-card--queued { border-color: #cbd5e1; }
.active-job-card--done { border-color: #bbf7d0; background: #ecfdf5; }
.active-job-card--failed { border-color: #fecaca; background: #fef2f2; }
.active-job-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 4px;
}
.active-job-title {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.35;
}
.active-job-dismiss {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: #e2e8f0;
  color: #475569;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.active-job-dismiss:hover { background: #fecaca; color: #b91c1c; }
.active-job-meta {
  font-size: 0.8rem;
  color: #64748b;
  margin-bottom: 8px;
}
.active-job-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.active-job-pct {
  font-size: 0.85rem;
  font-weight: 800;
  color: #2563eb;
  min-width: 42px;
  text-align: right;
}
.progress-bar {
  flex: 1;
  height: 8px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2563eb, #25f4ee);
  transition: width 0.3s;
  min-width: 2%;
}
.active-job-card--queued .progress-bar-fill { background: #94a3b8; }

.btn-dl {
  display: inline-block;
  margin-top: 10px;
  padding: 8px 14px;
  background: #059669;
  color: #fff;
  text-decoration: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.85rem;
}

.log-panel {
  margin-top: 20px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 14px 16px 12px;
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.04);
}

.log-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.log-panel-head h2 {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
}

.log-panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-log {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  color: #475569;
}
.btn-log:hover { background: #f1f5f9; }
.btn-log--muted { color: #94a3b8; }

.job-badge {
  font-size: 0.72rem;
  font-weight: 600;
  color: #1d4ed8;
  background: #eff6ff;
  padding: 3px 8px;
  border-radius: 99px;
}

.event-log {
  max-height: 220px;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  line-height: 1.45;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 10px;
  padding: 10px 12px;
}

.event-log-empty {
  color: #64748b;
  font-style: italic;
}

.event-line {
  display: flex;
  gap: 8px;
  padding: 2px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}
.event-line:last-child { border-bottom: none; }

.event-ts { color: #64748b; flex-shrink: 0; }
.event-src { color: #38bdf8; flex-shrink: 0; min-width: 36px; }
.event-msg { word-break: break-word; }
.event-line--ok .event-msg { color: #4ade80; }
.event-line--warn .event-msg { color: #fbbf24; }
.event-line--error .event-msg { color: #f87171; }

.footer {
  margin-top: 16px;
  font-size: 0.8rem;
  color: #94a3b8;
}

.sys-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.sys-stat {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px 12px;
  text-align: center;
}

.sys-label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
  margin-bottom: 4px;
}

.sys-value {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: #1e293b;
  line-height: 1.3;
}

.sys-stat--warn .sys-value { color: #b45309; }
.sys-stat--danger .sys-value { color: #b91c1c; }

.footer-note {
  text-align: center;
  margin: 0;
}
.footer-note a { color: #2563eb; text-decoration: none; }
.footer-note a:hover { text-decoration: underline; }

/* Toast */
.toast-root {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.4;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.15);
  opacity: 0;
  transform: translateX(12px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: auto;
}
.toast--show {
  opacity: 1;
  transform: translateX(0);
}
.toast--ok {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}
.toast--info {
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}
.toast--warn {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
}

@media (max-width: 480px) {
  .url-row { flex-direction: column; }
  .btn-scan { padding: 12px; }
  .sys-stats { grid-template-columns: 1fr; }
  .log-panel-head { flex-direction: column; align-items: flex-start; }
  .toast-root { left: 16px; right: 16px; max-width: none; }
}
