:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #666;
  --border: #ddd;
  --accent: #2563eb;
  --danger-bg: #fdecec;
  --danger-fg: #8a1f1f;
  /* BANK vs CARD in the Results list. Teal and violet on purpose: red and
   * amber already mean "needs attention" in the review grid, and blue is
   * the colour of everything clickable, so none of those three can carry a
   * second meaning here without muddling the first. */
  --kind-bank: #0f766e;
  --kind-card: #7c3aed;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --fg: #e8e8e8;
    --muted: #9aa0aa;
    --border: #595e68;
    --accent: #5b8def;
    --danger-bg: #3a1c1c;
    --danger-fg: #f4a3a3;
    --kind-bank: #5eead4;
    --kind-card: #c4b5fd;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
}
/* The header carries the firm's logo, which is dark artwork on a
 * transparent background -- so this bar stays white in both themes rather
 * than following --bg, and its own colors are pinned here instead of
 * inherited (the themed --fg would be near-white in dark mode and vanish
 * against it). Everything below the header still follows the theme. */
header {
  padding: 0.75rem 1.5rem;
  background: #ffffff;
  color: #1a1a1a;
  border-bottom: 1px solid #e3e6ea;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}
.app-logo { height: 34px; width: auto; display: block; cursor: pointer; user-select: none; }
/* Pushed to the far right of the header by margin-left:auto -- the header is
 * a flex row, so this stays put as the nav grows or the window narrows. Its
 * colour is pinned like the rest of the header, which is white in both
 * themes (see the header rule above). */
.app-version { margin-left: auto; color: #6b7280; font-size: 0.8rem; white-space: nowrap; }
header h1 { font-size: 1.1rem; margin: 0; color: #1a1a1a; }
.app-title { cursor: pointer; user-select: none; }
nav { display: flex; gap: 0.5rem; }
.nav-btn {
  background: #ffffff;
  border: 1px solid #cfd4dc;
  color: #33383f;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
}
.nav-btn:hover { background: #f2f4f7; }
.nav-btn.active { background: #2563eb; color: #ffffff; border-color: #2563eb; }

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; }
/* Add-company and add-account sit side by side (they're separate <form>s,
 * so a flex wrapper is what puts them on one row) -- two stacked rows of
 * controls was a lot of vertical space for two rarely-used forms. They
 * still stack on their own once the row no longer fits. */
.client-forms { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.5rem; }
.client-forms form.inline-form + form.inline-form { margin-top: 0; }
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; }
/* The card is a <details>: the header is its summary, so clicking the
 * company name opens it. `display: flex` drops the browser's own
 * disclosure marker, hence the caret drawn here instead. */
.company-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 1.05rem;
  cursor: pointer;
  user-select: none;
  list-style: none;
}
.company-card-header::-webkit-details-marker { display: none; }
.company-card-header strong::before {
  content: "\25B8";
  display: inline-block;
  width: 1em;
  color: var(--muted);
  font-weight: 400;
}
.company-card[open] > .company-card-header strong::before { content: "\25BE"; }
/* 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; }
/* The study-data row packs label, filename, Download/Remove, the dropzone
 * and Update onto a single line -- the dropzone is the only part allowed
 * to grow, and the filename truncates rather than pushing anything off. */
.study-row { flex-wrap: nowrap; gap: 0.5rem; }
.study-row .company-card-label { width: 130px; }
.study-row .slim-dropzone { min-width: 120px; }
.study-filename {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 0;
  font-size: 0.85rem;
}
a.study-filename { color: var(--accent); text-decoration: none; }
a.study-filename:hover { text-decoration: underline; }
.study-row .muted { color: var(--muted); font-style: italic; }
.study-row > button, .study-row > a { flex-shrink: 0; }
.company-card-accounts { margin-top: 0.6rem; }
.company-card-accounts-label {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.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; }

/* Slim single-row dropzone -- used both for Study Data on the Clients
 * screen (once per company card, so it can't afford to be tall) and for
 * the Convert screen's statement upload. No separate "Browse" button: the
 * whole row is a <label> wrapping the file input, so a click opens the
 * file picker same as the drop. */
.slim-dropzone {
  flex: 1;
  min-width: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.75rem;
  border: 1.5px dashed var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.slim-dropzone:hover,
.slim-dropzone.dragover { border-color: var(--accent); }
.slim-dropzone.dragover { background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--fg); }
.slim-dropzone.has-file { color: var(--fg); border-style: solid; background: color-mix(in srgb, #f0c419 22%, var(--bg)); }
.slim-dropzone-text { white-space: pre-line; line-height: 1.5; }
/* Several filenames read better as a left-aligned list than centered --
 * only kicks in once there's more than one (Convert can pick multiple
 * files; Study Data never does), so the box still grows taller rather
 * than staying a fixed single-line height. */
.slim-dropzone.multi-file { justify-content: flex-start; text-align: left; padding: 0.5rem 0.75rem; }
.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; margin-left: auto; width: max-content; max-width: 480px; }
.review-files-label { margin: 0 0 0.35rem; color: var(--muted); font-size: 0.85rem; text-align: right; }
.review-files-ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.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-filename { color: var(--accent); text-decoration: none; font-size: 0.85rem; }
.review-filename:hover { text-decoration: underline; }

/* The account is resolved from the file name rather than chosen, so this
 * line is the only place the user sees which one a job will post against --
 * it reads as a statement of fact when resolved, and as a warning when not. */
.resolved-account { margin: 0; font-size: 0.9rem; }
.resolved-account.resolved { color: var(--fg); font-weight: 600; }
.resolved-account.unresolved { color: var(--danger-fg); font-weight: 600; }

/* One block per account on the Review screen: a combined statement is
 * converted per account, and each keeps its own totals, its own workbook
 * and its own list, so they are never shown pooled together. */
.review-account { margin-bottom: 1.5rem; }
.review-account + .review-account { border-top: 1px solid var(--border); padding-top: 1.25rem; }
.review-account-title { font-size: 1rem; margin: 0 0 0.6rem; }
.review-account-title .review-account-index { color: var(--muted); margin-right: 0.4rem; }

/* Amber, not red: the row is complete, but its payee was read off a check
 * stub whose amount disagreed with the statement, so it wants confirming
 * rather than filling in. See attentionReason() in app.js. */
.tabulator-row.row-stub-check { background: color-mix(in srgb, #f0a020 22%, var(--bg)) !important; }
.tabulator-row.row-stub-check .tabulator-cell { color: var(--fg); }

/* Twice the height on the Convert screens, where the target is what you aim
 * a dragged file at. The Clients study rows keep the slim version: there the
 * dropzone shares one line with the filename and its buttons. */
.slim-dropzone.tall-dropzone { min-height: 72px; }

/* Stands in for the grid when the filtered view has nothing in it. */
.grid-empty-note { margin: 0.5rem 0 0; color: var(--muted); font-size: 0.9rem; }

/* The BANK/CARD prefix on an account name in the Results list. Set at about
 * half the size of the name it sits in front of: it's a category tag, and
 * the account name is what people actually read. Bold with a little letter
 * spacing so it stays legible that small. */
.acct-kind {
  /* Condensed rather than small: at 14px the tag stays readable, and the
   * narrow face keeps it from stealing width from the account name it sits
   * in front of. The stack ends in the normal UI font, so a machine without
   * a condensed face loses the narrowness, not the label. */
  font-family: "Avenir Next Condensed", "Helvetica Neue Condensed",
    "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
  font-stretch: condensed;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  /* The tag is separated from the account name by a space rather than a
   * hyphen, and a hair of margin keeps that gap from closing up against the
   * condensed face. */
  margin-right: 0.1em;
}
.acct-kind.kind-bank { color: var(--kind-bank); }
.acct-kind.kind-card { color: var(--kind-card); }

/* Sits under the REVIEW heading: when this conversion was produced. */
.review-converted-at { margin: -0.4rem 0 1rem; color: var(--muted); font-size: 0.85rem; }

/* Rename/Delete sit together at the right of a company card's header. */
.company-card-actions { display: flex; gap: 0.4rem; margin-left: auto; }
.rename-input {
  font-size: 1.05rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  max-width: 20rem;
}
