:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #666;
  --border: #ddd;
  --accent: #2563eb;
  --danger-bg: #fdecec;
  --danger-fg: #8a1f1f;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --fg: #e8e8e8;
    --muted: #9aa0aa;
    --border: #333844;
    --accent: #5b8def;
    --danger-bg: #3a1c1c;
    --danger-fg: #f4a3a3;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
}
header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}
header h1 { font-size: 1.1rem; margin: 0; }
.app-title { cursor: pointer; user-select: none; }
nav { display: flex; gap: 0.5rem; }
.nav-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
}
.nav-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

main { padding: 1.5rem; max-width: 1100px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

form { display: flex; flex-direction: column; gap: 0.75rem; max-width: 480px; }
form.inline-form { flex-direction: row; flex-wrap: wrap; max-width: none; align-items: center; }
form.inline-form + form.inline-form { margin-top: 0.75rem; }
label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
input, select {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}
button {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  cursor: pointer;
}
button:hover { opacity: 0.9; }
.del-company, .del-account, .del-job, .del-history { background: #f97316; }
small { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.9rem; }

table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border); }

#review-grid { margin-top: 1rem; overflow-x: auto; }

.job-progress {
  max-width: 520px;
  margin-top: 0.5rem;
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--fg) 4%, transparent);
}
.job-progress-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.85rem;
}
.job-progress-pct { font-size: 2rem; font-weight: 700; line-height: 1; }
.job-progress-status { font-size: 0.95rem; font-weight: 600; color: var(--muted); }
.job-progress-bar {
  position: relative;
  width: 100%;
  height: 14px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--fg) 10%, transparent);
  overflow: hidden;
}
.job-progress-fill {
  position: relative;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.4s ease;
  overflow: hidden;
}
.job-progress-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    -45deg,
    rgba(255, 255, 255, 0.28) 0,
    rgba(255, 255, 255, 0.28) 10px,
    transparent 10px,
    transparent 20px
  );
  background-size: 28px 28px;
  animation: job-progress-stripes 1s linear infinite;
}
@keyframes job-progress-stripes {
  from { background-position: 0 0; }
  to { background-position: 28px 0; }
}
.job-progress-hint { margin: 0.65rem 0 0; color: var(--muted); font-size: 0.85rem; }

.job-summary {
  margin-top: 1rem;
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--fg) 4%, transparent);
  white-space: pre-line;
  font-size: 0.9rem;
  line-height: 1.6;
}
.job-summary:empty { display: none; }
.review-actions { margin-top: 1rem; }

.row-unmatched { background: var(--danger-bg) !important; color: var(--danger-fg); }

#companies-list { margin-top: 1rem; }
.company-card { border: 1px solid var(--border); border-radius: 8px; padding: 0.85rem 1rem; margin-bottom: 0.75rem; }
.company-card-header { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; font-size: 1.05rem; }
/* Every row is label (fixed width) + content (grows) + action button
 * (pinned flush right via margin-left:auto on the button itself, inside a
 * wrapping flex container) -- keeps buttons aligned regardless of how
 * long the filename/label text before them is. */
.company-card-row { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.6rem; }
.company-card-label { color: var(--muted); font-size: 0.85rem; width: 90px; flex-shrink: 0; }
.company-card-value { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; flex: 1; }
.company-card-value button, .company-card-account-list button { margin-left: auto; }
.company-card-accounts { margin-top: 0.6rem; }
.company-card-accounts > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
  list-style: revert;
  user-select: none;
}
.company-card-accounts[open] > summary { margin-bottom: 0.5rem; }
.company-card-account-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; min-width: 0; }
.company-card-account-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0.6rem;
  background: color-mix(in srgb, var(--fg) 4%, transparent);
  border-radius: 6px;
}
.company-card-value .muted, .company-card-account-list li.muted { color: var(--muted); font-style: italic; }

.dropzone-card { display: block; cursor: pointer; }
.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 2rem;
  background: color-mix(in srgb, var(--fg) 4%, transparent);
  transition: border-color 0.15s, background 0.15s;
}
.dropzone-card:hover .dropzone,
.dropzone.dragover { border-color: var(--accent); }
.dropzone.dragover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.dropzone-icon { width: 1.75rem; height: 1.75rem; color: var(--muted); }
.dropzone.dragover .dropzone-icon { color: var(--accent); }
.dropzone-title { margin: 1rem 0 0; text-align: center; font-size: 1.05rem; font-weight: 700; }
.dropzone-hint { margin: 0.25rem 0 0; text-align: center; color: var(--muted); font-size: 0.9rem; }
.dropzone-browse-btn {
  display: block;
  margin: 1rem 0 0;
  padding: 0.65rem 1rem;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  text-align: center;
  font-weight: 600;
}
.dropzone-card:hover .dropzone-browse-btn { opacity: 0.9; }
.dropzone-filelist { list-style: none; margin: 0.75rem 0 0; padding: 0; text-align: left; font-size: 0.9rem; color: var(--muted); width: 100%; }
.visually-hidden-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.review-files-list { margin-top: 0.75rem; }
.review-files-label { margin: 0 0 0.35rem; color: var(--muted); font-size: 0.85rem; }
.review-files-ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; max-width: 480px; }
.review-files-ul li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.35rem 0.6rem;
  background: color-mix(in srgb, var(--fg) 4%, transparent);
  border-radius: 6px;
}
.review-file-download {
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}
.review-file-download:hover { opacity: 0.9; }
