:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --border: #e9eaee;
  --text: #14161a;
  --text-muted: #6b7280;
  --text-faint: #9aa0ab;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-tint: #eaf1ff;
  --green: #16a34a;
  --green-tint: #e9f9ee;
  --red: #dc2626;
  --red-tint: #fdeeee;
  --amber: #d97706;
  --amber-tint: #fef6e7;
  --gray: #6b7280;
  --gray-tint: #f0f1f3;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 22, 26, 0.04), 0 8px 24px -12px rgba(20, 22, 26, 0.10);
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  max-width: 720px;
  margin: 0 auto;
  padding: 40px 20px 80px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header ---------- */

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.app-header .logo {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), #60a5fa);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 14px -4px rgba(37, 99, 235, 0.5);
}

.app-header .logo svg { width: 20px; height: 20px; }

.app-header h1 {
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 0;
  line-height: 1.2;
}

.app-header .subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 1px 0 0;
}

/* ---------- Login screen ---------- */

.screen.hidden { display: none; }

#login {
  max-width: 340px;
  margin: 18vh auto 0;
  text-align: center;
}

#login h1 { font-size: 20px; margin-bottom: 24px; }

#login-form {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 8px;
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

/* ---------- Cards ---------- */

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

/* ---------- Forms & inputs ---------- */

form { display: flex; gap: 8px; }

.add-form-row { margin-bottom: 8px; }

.secondary-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 10px;
  margin-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-muted);
}

.secondary-row form { flex: 1; }

input[type="text"],
input[type="password"] {
  flex: 1;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  min-width: 0;
}

input[type="text"]:focus,
input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--card);
}

input[type="file"] {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}
select:focus { outline: none; border-color: var(--accent); }

button {
  padding: 10px 15px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: white;
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, transform 0.05s ease;
}

button:hover { background: var(--accent-hover); }
button:active { transform: scale(0.98); }

button.is-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  pointer-events: none;
  opacity: 0.85;
}
button.is-loading::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
  flex-shrink: 0;
}
@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

button.subtle {
  background: var(--gray-tint);
  color: var(--text);
}
button.subtle:hover { background: #e4e5e9; }

.error {
  color: var(--red);
  font-size: 13px;
}

/* ---------- Job list ---------- */

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

.job {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  gap: 13px;
}

.job-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent-tint);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.job-icon svg { width: 20px; height: 20px; }

.job.status-done .job-icon { background: var(--green-tint); color: var(--green); }
.job.status-error .job-icon { background: var(--red-tint); color: var(--red); }
.job.status-extracting .job-icon { background: var(--amber-tint); color: var(--amber); }
.job.status-cancelled .job-icon { background: var(--gray-tint); color: var(--gray); }

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

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

.job-label {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  word-break: break-word;
}

.badge {
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--gray-tint);
  color: var(--gray);
  white-space: nowrap;
}

.badge.status-downloading,
.badge.status-uploading,
.badge.status-queued { background: var(--accent-tint); color: var(--accent); }
.badge.status-done { background: var(--green-tint); color: var(--green); }
.badge.status-error { background: var(--red-tint); color: var(--red); }
.badge.status-extracting { background: var(--amber-tint); color: var(--amber); }
.badge.status-cancelled { background: var(--gray-tint); color: var(--gray); }

.job-dest {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
}

.job-meta {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 3px;
}

.job-error-text {
  color: var(--red);
}

.bar {
  height: 5px;
  background: var(--gray-tint);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 9px;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.status-done .bar-fill { background: var(--green); }
.status-extracting .bar-fill { background: var(--amber); }

.job-links {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.job-links a {
  font-size: 12.5px;
  color: var(--accent);
  text-decoration: none;
}
.job-links a:hover { text-decoration: underline; }

.job-actions {
  margin-top: 11px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.job-actions button {
  padding: 6px 12px;
  font-size: 12.5px;
  border-radius: 999px;
  background: var(--gray-tint);
  color: var(--text);
  font-weight: 500;
}
.job-actions button:hover { background: #e4e5e9; }

.job-actions button.retry-btn,
.job-actions button.delete-btn {
  background: var(--red-tint);
  color: var(--red);
}
.job-actions button.retry-btn:hover,
.job-actions button.delete-btn:hover { background: #fbdcdc; }

.job-actions button.resume-btn {
  background: var(--green-tint);
  color: var(--green);
}
.job-actions button.resume-btn:hover { background: #d7f3e0; }

.job-actions button.cancel-btn {
  background: var(--gray-tint);
  color: var(--text);
}

.job-actions button:disabled {
  opacity: 0.55;
  cursor: default;
}

.zip-choice {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--accent-tint);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--accent);
}

.zip-choice label {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  font-weight: 500;
}

.zip-choice input[type="radio"] { cursor: pointer; accent-color: var(--accent); }
.zip-choice input[type="radio"]:disabled { cursor: default; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-faint);
  font-size: 13.5px;
}

/* ---------- API key box ---------- */

#api-key-box h2 {
  font-size: 14.5px;
  font-weight: 650;
  margin: 0 0 6px;
}

#api-key-box .hint {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 0 0 12px;
  line-height: 1.55;
}

#api-key-box code {
  background: var(--gray-tint);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11.5px;
}

.api-key-row { display: flex; gap: 8px; }

#api-key-field {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--gray-tint);
}

#api-curl-example {
  margin-top: 12px;
  padding: 13px 14px;
  background: #14161a;
  color: #e5e7eb;
  border-radius: var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  white-space: pre-wrap;
  word-break: break-all;
  overflow-x: auto;
  line-height: 1.6;
}

#copy-curl-btn {
  margin-top: 8px;
  background: var(--gray-tint);
  color: var(--text);
}
#copy-curl-btn:hover { background: #e4e5e9; }

@media (max-width: 480px) {
  body { padding: 24px 14px 60px; }
  .job { flex-direction: column; }
  .job-icon { display: none; }

  #add-form { flex-wrap: wrap; }
  #add-form input[type="text"] { flex-basis: 100%; }
  #destination-select { flex: 1; }

  .secondary-row { flex-wrap: wrap; }
  .secondary-row form { flex: 1 1 100%; flex-wrap: wrap; }
  #file-form input[type="file"] { flex-basis: 100%; }
}
