  /* ─── Light theme (default) ─── */
  :root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --muted: #64748b;
    --accent: #4f46e5;
    --accent-hover: #6366f1;
    --green: #16a34a;
    --yellow: #a16207;
    --red: #b91c1c;
    --orange: #ea580c;
    --hover-bg: rgba(0,0,0,0.03);
  }

  /* ─── Dark theme ─── */
  [data-theme="dark"] {
    --bg: #0f1117;
    --surface: #1a1d27;
    --border: #2a2d3a;
    --text: #e4e4e7;
    --muted: #8b8b94;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --green: #22c55e;
    --yellow: #eab308;
    --red: #ef4444;
    --orange: #f97316;
    --hover-bg: rgba(255,255,255,0.05);
  }

  * { margin: 0; padding: 0; box-sizing: border-box; }
  body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: 2rem;
    max-width: 64rem;
    margin: 0 auto;
  }
  h1 { font-size: 1.5rem; font-weight: 600; margin-bottom: 0.25rem; }
  .subtitle { color: var(--muted); font-size: 0.875rem; margin-bottom: 2rem; }
  .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
  }
  .card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }

  /* ─── Header row ─── */
  .header-row {
    display: flex;
    justify-content: space-between;
    align-items: start;
  }

  /* ─── Theme toggle ─── */
  .theme-toggle {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.625rem;
    cursor: pointer;
    color: var(--text);
    transition: background 0.2s;
    line-height: 0;
  }
  .theme-toggle:hover { background: var(--bg); }
  .theme-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  /* ─── Drop zone ─── */
  .dropzone {
    border: 2px dashed var(--border);
    border-radius: 0.5rem;
    padding: 3rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
  }
  .dropzone.dragover {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.05);
  }
  .dropzone p { color: var(--muted); margin-top: 0.5rem; font-size: 0.875rem; }
  .dropzone svg { margin-bottom: 0.5rem; }
  .dropzone:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
  .file-badges {
    margin-top: 0.75rem;
    display: flex;
    gap: 0.5rem;
    justify-content: center;
  }
  .file-badge {
    font-size: 0.625rem;
    padding: 0.125rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 9999px;
    color: var(--muted);
  }

  /* ─── Form ─── */
  .form-row {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    align-items: end;
  }
  .form-group { flex: 1; }
  .form-group label {
    display: block;
    font-size: 0.75rem;
    color: var(--muted);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  .form-group input,
  .form-group select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    color: var(--text);
    font-size: 0.875rem;
  }
  .form-group input:focus,
  .form-group select:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-color: var(--accent);
  }
  .form-group-sm { max-width: 120px; }
  .form-group-md { max-width: 150px; }

  .btn {
    padding: 0.5rem 1.25rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
  }
  .btn:hover { background: var(--accent-hover); }
  .btn:disabled { opacity: 0.5; cursor: not-allowed; }
  .btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
  .btn-sm { padding: 0.25rem 0.75rem; font-size: 0.75rem; }
  .btn-green { background: var(--green); }
  .btn-yellow { background: var(--yellow); color: #fff; }
  .btn-drive { background: #4285f4; text-decoration: none; margin-left: 0.5rem; }

  /* ─── API key bar ─── */
  .api-key-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    align-items: center;
  }
  .api-key-bar input { flex: 1; }
  .api-key-bar .status { font-size: 0.75rem; }
  .api-key-label {
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
  }

  /* ─── File name ─── */
  .file-name {
    background: var(--bg);
    padding: 0.375rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    margin-top: 0.75rem;
    display: none;
    align-items: center;
    gap: 0.5rem;
  }
  .file-name button.remove {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0.25rem;
    border-radius: 0.25rem;
  }
  .file-name button.remove:hover { color: var(--red); }
  .file-name button.remove:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  /* ─── Progress ─── */
  .progress-bar {
    width: 100%;
    height: 0.5rem;
    background: var(--bg);
    border-radius: 0.25rem;
    overflow: hidden;
    margin-top: 0.75rem;
  }
  .progress-bar .fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.5s ease;
    border-radius: 0.25rem;
  }
  .progress-label {
    font-size: 0.8125rem;
    color: var(--muted);
    margin-bottom: 0.25rem;
  }
  .progress-info {
    display: flex;
    justify-content: space-between;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--muted);
  }
  #active-job { display: none; }

  /* ─── Stats / downloads rows ─── */
  .stats-row {
    display: flex;
    gap: 2rem;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
  }
  .downloads-row {
    display: none;
    gap: 0.5rem;
    align-items: center;
  }
  .job-error {
    display: none;
    margin-top: 0.75rem;
    padding: 0.75rem 1rem;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 0.375rem;
    color: var(--red);
    font-size: 0.8125rem;
  }
  .actions-cell { white-space: nowrap; }

  /* ─── Fast pass progress ─── */
  .fast-pass-section {
    margin-bottom: 0.875rem;
    padding: 0.875rem 1rem;
    background: rgba(34, 197, 94, 0.06);
    border: 1px solid rgba(34, 197, 94, 0.2);
    border-radius: 0.5rem;
  }
  .fast-pass-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--green);
    text-transform: uppercase;
    letter-spacing: 0.06em;
  }
  .fast-pass-header .fp-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--green);
    animation: fp-pulse 1.5s ease-in-out infinite;
    flex-shrink: 0;
  }
  .fast-pass-header.fp-complete .fp-dot {
    animation: none;
  }
  @keyframes fp-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
  }
  .fast-pass-phases {
    display: flex;
    gap: 0;
    margin-bottom: 0.625rem;
    font-size: 0.6875rem;
  }
  .fp-phase {
    padding: 0.25rem 0.625rem;
    color: var(--muted);
    border: 1px solid var(--border);
    margin-right: -1px;
    white-space: nowrap;
  }
  .fp-phase:first-child { border-radius: 0.25rem 0 0 0.25rem; }
  .fp-phase:last-child { border-radius: 0 0.25rem 0.25rem 0; margin-right: 0; }
  .fp-phase.fp-active {
    background: rgba(34, 197, 94, 0.15);
    color: var(--green);
    border-color: rgba(34, 197, 94, 0.35);
    font-weight: 600;
    z-index: 1;
    position: relative;
  }
  .fp-phase.fp-done {
    background: rgba(34, 197, 94, 0.07);
    color: rgba(34, 197, 94, 0.6);
    border-color: rgba(34, 197, 94, 0.2);
  }
  .fast-pass-counts {
    font-size: 0.8125rem;
    color: var(--text);
    margin-bottom: 0.5rem;
  }
  .fast-pass-counts .fp-valid-num {
    font-weight: 600;
    color: var(--green);
  }
  .fast-pass-counts .fp-pct {
    color: var(--muted);
    font-size: 0.75rem;
    margin-left: 0.25rem;
  }
  .progress-bar.fp-bar .fill {
    background: var(--green);
  }

  /* ─── Table ─── */
  table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
  th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
  }
  /* Default transparent left border to prevent layout shift on hover */
  td:first-child { border-left: 3px solid transparent; }
  tbody tr { transition: background 0.15s; }
  tbody tr:hover td { background: var(--hover-bg); }
  tbody tr:hover td:first-child { border-left: 3px solid var(--accent); }

  /* ─── Sortable table ─── */
  th[data-sort] {
    cursor: pointer;
    user-select: none;
  }
  th[data-sort]:hover { color: var(--text); }
  th[data-sort]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
  th .sort-arrow {
    display: inline-block;
    margin-left: 4px;
    opacity: 0.3;
    font-size: 0.625rem;
  }
  th.sort-active .sort-arrow { opacity: 1; color: var(--accent); }

  /* ─── Status badges ─── */
  .status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.6875rem;
    font-weight: 500;
  }
  .status-badge svg {
    width: 12px;
    height: 12px;
    margin-right: 3px;
    flex-shrink: 0;
  }
  @keyframes status-spin {
    to { transform: rotate(360deg); }
  }
  .status-badge .status-spinner {
    animation: status-spin 1s linear infinite;
    display: inline-flex;
    align-items: center;
  }
  .status-pending { background: rgba(234,179,8,0.15); color: var(--yellow); }
  .status-running { background: rgba(99,102,241,0.15); color: var(--accent); }
  .status-complete { background: rgba(34,197,94,0.15); color: var(--green); }
  .status-failed { background: rgba(239,68,68,0.15); color: var(--red); }

  /* ─── Tooltip ─── */
  .tooltip-wrap {
    position: relative;
    display: inline-block;
    vertical-align: middle;
  }
  .tooltip-text {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    color: var(--text);
    white-space: normal;
    max-width: 260px;
    z-index: 10;
    line-height: 1.6;
    text-transform: none;
    letter-spacing: normal;
  }
  .tooltip-wrap.tooltip-visible .tooltip-text { display: block; }

  /* ─── Empty state ─── */
  .empty {
    text-align: center;
    color: var(--muted);
    padding: 3rem 1rem;
  }
  .empty svg { display: block; margin: 0 auto 0.5rem; }

  /* ─── Toast notifications ─── */
  .toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }
  .toast {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.8125rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    animation: toast-in 0.3s ease;
    max-width: 20rem;
  }
  .toast.toast-error { border-color: rgba(239,68,68,0.5); background: rgba(239,68,68,0.1); }
  .toast.toast-success { border-color: rgba(34,197,94,0.5); background: rgba(34,197,94,0.1); }
  @keyframes toast-in {
    from { opacity: 0; transform: translateY(0.5rem); }
    to { opacity: 1; transform: translateY(0); }
  }

  /* ─── Skeleton loading ─── */
  @keyframes skeleton-pulse {
    0%, 100% { opacity: 0.15; }
    50% { opacity: 0.3; }
  }
  .skeleton-row td {
    position: relative;
    overflow: hidden;
  }
  .skeleton-bar {
    display: inline-block;
    height: 0.75rem;
    background: var(--muted);
    border-radius: 0.25rem;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
  }

  /* ─── Button spinner ─── */
  @keyframes btn-spin {
    to { transform: rotate(360deg); }
  }
  .btn-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: btn-spin 0.8s linear infinite;
    vertical-align: -2px;
    margin-right: 6px;
  }

  /* ─── Skip to content ─── */
  .skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    background: var(--accent);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 0 0 0.375rem 0;
    z-index: 1001;
    font-size: 0.875rem;
    text-decoration: none;
  }
  .skip-link:focus {
    top: 0;
  }

  /* ─── Screen reader only ─── */
  .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;
  }

  /* ─── Utility ─── */
  .hidden { display: none; }
  .empty-title { margin-bottom: 0.25rem; }
  .empty-subtitle { font-size: 0.75rem; }

  /* ─── Rate column classes ─── */
  .rate-good { color: var(--green); font-weight: 500; }
  .rate-mid { color: var(--yellow); font-weight: 500; }
  .rate-low { color: var(--red); font-weight: 500; }

  /* ─── Reduced motion ─── */
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }

  /* ─── Responsive ─── */
  @media (max-width: 640px) {
    body { padding: 1rem; }
    .form-row { flex-direction: column; }
    .form-group-sm,
    .form-group-md { max-width: none; }
    #aj-stats { flex-direction: column; gap: 0.25rem; }
    #aj-downloads { flex-wrap: wrap; }
    table { font-size: 0.75rem; }
    th, td { padding: 0.375rem 0.5rem; }
    .btn-sm { min-height: 2.75rem; padding: 0.5rem 1rem; font-size: 0.8125rem; }
    .api-key-bar .btn { min-height: 2.75rem; }
    .theme-toggle { min-height: 2.75rem; min-width: 2.75rem; }
    .file-name button.remove { min-height: 2.75rem; min-width: 2.75rem; }
  }
