:root {
  color-scheme: light;
  --background: #f2f3f6;
  --surface: #ffffff;
  --surface-alt: #f7f8fa;
  --surface-hover: #eef0f4;
  --border: #dde0e6;
  --text: #191c22;
  --muted: #687080;
  --accent: #3b6ef5;
  --accent-hover: #2f5ddb;
  --accent-soft: rgba(59, 110, 245, 0.12);
  --accent-text: #ffffff;
  --danger: #d03c32;
  --danger-soft: rgba(208, 60, 50, 0.1);
  --success: #1f9d62;
  --success-soft: rgba(31, 157, 98, 0.12);
  --info: #3b6ef5;
  --info-soft: rgba(59, 110, 245, 0.12);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 2px 8px rgba(16, 24, 40, 0.04);
  --radius: 12px;
  --radius-small: 8px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --background: #0f1115;
    --surface: #171a20;
    --surface-alt: #1d2128;
    --surface-hover: #242933;
    --border: #2a2f39;
    --text: #e7e9ee;
    --muted: #949cab;
    --accent: #5b87ff;
    --accent-hover: #7298ff;
    --accent-soft: rgba(91, 135, 255, 0.16);
    --danger: #f06a5f;
    --danger-soft: rgba(240, 106, 95, 0.14);
    --success: #3fc486;
    --success-soft: rgba(63, 196, 134, 0.14);
    --info: #5b87ff;
    --info-soft: rgba(91, 135, 255, 0.16);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #0f1115;
  --surface: #171a20;
  --surface-alt: #1d2128;
  --surface-hover: #242933;
  --border: #2a2f39;
  --text: #e7e9ee;
  --muted: #949cab;
  --accent: #5b87ff;
  --accent-hover: #7298ff;
  --accent-soft: rgba(91, 135, 255, 0.16);
  --danger: #f06a5f;
  --danger-soft: rgba(240, 106, 95, 0.14);
  --success: #3fc486;
  --success-soft: rgba(63, 196, 134, 0.14);
  --info: #5b87ff;
  --info-soft: rgba(91, 135, 255, 0.16);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  background: var(--background);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

h2 {
  font-size: 1.05rem;
  font-weight: 650;
  margin: 0 0 14px;
  overflow-wrap: anywhere;
}

input,
select,
button {
  font: inherit;
  color: inherit;
}

input:not([type="checkbox"]),
select {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface-alt);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:not([type="checkbox"]):focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

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

button {
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-small);
  background: var(--surface-alt);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  color: var(--accent-text);
}

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

button.ghost,
button.secondary {
  background: transparent;
  border-color: var(--border);
}

button.ghost:hover,
button.secondary:hover {
  background: var(--surface-hover);
}

button.danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

button.danger:hover {
  background: var(--danger-soft);
}

button.small {
  min-height: 32px;
  padding: 4px 12px;
  font-size: 0.85rem;
}

button.block {
  width: 100%;
}

.muted {
  color: var(--muted);
}

.small-text {
  font-size: 0.85rem;
}

.mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.error {
  color: var(--danger);
  margin: 10px 0 0;
  font-size: 0.9rem;
}

.error:empty {
  display: none;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 550;
  color: var(--muted);
}

.field input,
.field select {
  font-weight: 400;
  color: var(--text);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  min-height: 32px;
  cursor: pointer;
}

.brand-mark {
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.chip {
  font-size: 0.8rem;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}

.chip:empty {
  display: none;
}

.login-view {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 28px;
}

.login-brand {
  text-align: center;
}

.login-brand .brand-mark {
  font-size: 1.8rem;
}

.login-brand p {
  margin: 4px 0 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.content {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
}

.download-form {
  display: flex;
  gap: 10px;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 24px 8px;
  margin: 0;
  border: 1px dashed var(--border);
  border-radius: var(--radius-small);
}

.job-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.job {
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  padding: 14px;
  background: var(--surface-alt);
  transition: border-color 0.15s ease;
}

.job.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.job-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.job-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.job-source {
  font-size: 0.8rem;
  margin: 2px 0 10px;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.job-message {
  font-size: 0.88rem;
  margin: 10px 0 0;
}

.job-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.badge {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-ready,
.badge-completed {
  color: var(--success);
  background: var(--success-soft);
}

.badge-failed,
.badge-cancelled {
  color: var(--danger);
  background: var(--danger-soft);
}

.badge-downloading,
.badge-extracting,
.badge-moving,
.badge-queued {
  color: var(--info);
  background: var(--info-soft);
}

.progress {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.progress-bar.indeterminate {
  width: 30% !important;
  animation: slide 1.2s ease-in-out infinite;
}

@keyframes slide {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(340%);
  }
}

.progress-text {
  font-size: 0.82rem;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.file-tree {
  max-height: 440px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  padding: 6px;
  background: var(--surface-alt);
  -webkit-overflow-scrolling: touch;
}

.file-tree > .muted {
  padding: 12px;
  margin: 0;
}

.tree-list {
  list-style: none;
  margin: 0;
  padding-left: 0;
}

.tree-list .tree-list {
  padding-left: 20px;
  border-left: 1px solid var(--border);
  margin-left: 14px;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  min-height: 40px;
  border-radius: 6px;
}

.tree-row:hover {
  background: var(--surface-hover);
}

.tree-label {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.tree-name {
  overflow-wrap: anywhere;
}

.tree-name.folder {
  font-weight: 600;
}

.tree-size {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.move-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}

.sheet {
  width: min(560px, calc(100% - 32px));
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.sheet::backdrop {
  background: rgba(10, 12, 16, 0.55);
}

.sheet-form {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 48px);
}

.sheet-header,
.sheet-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
}

.sheet-header {
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.sheet-header h2 {
  margin: 0;
}

.sheet-footer {
  justify-content: flex-end;
  border-top: 1px solid var(--border);
}

.sheet-body {
  padding: 4px 20px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.settings-group {
  border: none;
  padding: 0;
  margin: 16px 0 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-group legend {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0;
  margin-bottom: 10px;
}

.settings-group .checkbox {
  margin: 0;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.info-list {
  margin: 0;
  display: grid;
  gap: 4px;
}

.info-list dt {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 6px;
}

.info-list dd {
  margin: 0;
}

@media (max-width: 640px) {
  body {
    font-size: 16px;
  }

  .card {
    padding: 16px;
    border-radius: 10px;
  }

  .content {
    padding: 12px 12px calc(20px + env(safe-area-inset-bottom));
  }

  .topbar-inner {
    padding: 8px 12px;
    gap: 8px;
  }

  .topbar-actions button {
    min-height: 36px;
    padding: 6px 10px;
    font-size: 0.85rem;
  }

  .download-form {
    flex-direction: column;
  }

  .download-form button,
  button.block-mobile {
    width: 100%;
    min-height: 46px;
  }

  .move-controls,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .job-actions button {
    flex: 1;
    min-height: 40px;
  }

  .file-tree {
    max-height: 55vh;
  }

  .tree-row {
    min-height: 46px;
  }

  .tree-list .tree-list {
    padding-left: 12px;
    margin-left: 8px;
  }

  .sheet {
    width: 100%;
    max-width: none;
    max-height: 92dvh;
    margin: auto 0 0;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
  }

  .sheet-form {
    max-height: 92dvh;
  }

  .sheet-footer {
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }

  .sheet-footer button {
    flex: 1;
    min-height: 46px;
  }
}

@media (max-width: 380px) {
  .chip {
    display: none;
  }
}
