/* Themes: light by default, dark when the system asks for it, and either one when forced from the settings panel
   (the data-theme attribute on the html element). color-scheme also themes native controls and scrollbars. */
:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #16202f;
  --muted: #667085;
  --border: #e1e6ef;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --ok: #0f9d58;
  --warn: #c77700;
  --bad: #d92d20;
  --info: #2563eb;
  /* The colours of the money charts (dashboard, transactions, invoices, salaries); expense categories have
     their own palette, in app.js. */
  --c1: #002fa7; --c2: #b3522a; --c3: #f2b800; --c4: #0b7a55;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e131b;
    --surface: #171e29;
    --text: #e8edf5;
    --muted: #98a2b3;
    --border: #2a3342;
    --accent: #5b8def;
    --c1: #3358ff; --c2: #e2703f; --c3: #ffd21f; --c4: #1fae7a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e131b;
  --surface: #171e29;
  --text: #e8edf5;
  --muted: #98a2b3;
  --border: #2a3342;
  --accent: #5b8def;
  --c1: #3358ff; --c2: #e2703f; --c3: #ffd21f; --c4: #1fae7a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 18px; margin: 0; display: flex; align-items: center; gap: 10px; }
h1 .logo { display: block; flex: none; }
h2 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.note { margin: 6px 4px 18px; font-size: 12px; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { white-space: nowrap; }

main { max-width: 1280px; margin: 0 auto; padding: 16px 24px 48px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .75; cursor: progress; filter: none; }
.badge {
  min-width: 20px; padding: 0 6px; border-radius: 999px; text-align: center;
  background: var(--accent); color: var(--accent-text); font-size: 12px; font-weight: 700; line-height: 20px;
}
.btn[aria-expanded="true"] { border-color: var(--accent); }

.flag { width: 22px; height: 15px; border-radius: 2px; flex: none; box-shadow: 0 0 0 1px rgba(128, 128, 128, .4); }
.lang { position: relative; }
.lang-btn { gap: 7px; }
.lang-btn .chev { color: var(--muted); }
.lang-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  margin: 0; padding: 4px; list-style: none; min-width: 160px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}
.lang-menu button {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 7px 10px;
  border: 0; border-radius: 7px; background: transparent; color: var(--text);
  font: inherit; text-align: left; cursor: pointer;
}
.lang-menu button:hover, .lang-menu button:focus-visible { background: color-mix(in srgb, var(--accent) 12%, transparent); outline: none; }
.lang-menu button[aria-selected="true"] { font-weight: 650; }
.lang-menu button[aria-selected="true"]::after { content: "✓"; margin-left: auto; color: var(--accent); }
.icon-btn {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 4px 8px; border-radius: 6px;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .8s linear infinite;
}
.spinner.large { width: 22px; height: 22px; border-width: 3px; color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

.banner, .result {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 10px; box-shadow: var(--shadow); padding: 12px 16px; margin-bottom: 14px;
}
.banner { display: flex; align-items: center; gap: 14px; }
.banner.waiting { border-left-color: var(--warn); }
.banner-text { display: flex; flex-direction: column; flex: 1; }
.result.ok { border-left-color: var(--ok); }
.result.fail { border-left-color: var(--bad); }
.result-head { display: flex; justify-content: space-between; align-items: center; }
.result .stats { display: flex; flex-wrap: wrap; gap: 8px 22px; margin-top: 8px; }
.result .stat b { font-size: 18px; margin-right: 4px; }
.result .stat span { color: var(--muted); }
.result .error { color: var(--bad); margin: 6px 0 0; white-space: pre-wrap; }

.filters {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: end;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
  margin-bottom: 14px;
}
.tabs { display: flex; gap: 4px; margin: 0 0 14px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button {
  border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted);
  font: inherit; font-weight: 600; padding: 10px 16px; cursor: pointer; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.res-chart-card { margin-bottom: 14px; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }
/* Who a transaction goes to or comes from: a round badge before the name, one look per kind of party. */
.party { display: inline-flex; align-items: center; gap: 8px; }
.party-badge { flex: none; width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 12px; line-height: 1; }
.party-jump { background: #141414; color: #fff; font-weight: 800; font-size: 13px; box-shadow: 0 0 0 1px var(--border); }
.party-bank { background: #dff5d0; }
.party-state { background: #fff; overflow: hidden; }
.party-state img { display: block; }
.party-client { background: #ece6ff; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 6px; font-weight: 600;
  background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.source-stats { margin-top: 10px; }
.source-name { display: block; font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.source-stats .stats { margin-top: 2px; }
.settings {
  display: flex; flex-direction: column; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
  margin-bottom: 14px;
}
.setting-group { border: 1px solid var(--border); border-radius: 10px; margin: 0; padding: 10px 14px 12px; }
.setting-group > summary { padding: 0 6px; font-weight: 650; cursor: pointer; }
.setting-group[open] > summary { margin-bottom: 8px; }
.setting-group .sub { display: block; margin-top: 14px; }
.setting-group .sched-actions.first { margin-top: 0; }
.segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented label {
  display: flex; align-items: center; gap: 7px; padding: 6px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg); cursor: pointer;
}
.segmented label:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 10px; cursor: pointer; }
.check.spaced { margin-top: 18px; }
/* Discreet mode (discreet.js): the amounts it found are blurred, in proportion to their text size. */
:root[data-discreet="on"] .amt { filter: blur(0.4em); user-select: none; }
.check input, .segmented input { width: auto; min-height: 0; margin: 0; accent-color: var(--accent); }
.sched-fields { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.sched-fields label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); flex: 1 1 150px; min-width: 0; }
.sched-fields:has(:disabled) { opacity: .55; }
.sched-actions { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.next-sync { margin: 12px 0 4px; font-weight: 600; }
.small { font-size: 12px; margin: 6px 0 0; }
.error-text { color: var(--bad); }
.settings .filters-head { flex: none; }
.filters-head { flex: 1 0 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); flex: 1 1 150px; min-width: 0; }
.filters .grow { flex: 2 1 200px; }
select, input {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; min-height: 32px;
  width: 100%; min-width: 0;
}

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow); }
.tile .label { color: var(--muted); font-size: 12px; }
.tile .value { font-size: 22px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: 12px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 14px; }
.charts { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
.chart-card.full { grid-column: 1 / -1; }
.chart { height: 360px; }
@media (max-width: 900px) {
  .charts { grid-template-columns: 1fr; }
  main { padding: 12px 12px 40px; }
  .top { padding: 10px 12px; position: static; }
  .chart { height: 300px; }
}

.table-card { padding: 14px 0 6px; }
.table-card h2 { padding: 0 14px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td.desc { white-space: normal; min-width: 220px; }
th { font-size: 12px; color: var(--muted); font-weight: 600; cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--surface); }
th.sorted::after {
  content: ""; display: inline-block; width: 12px; height: 12px; margin-left: 4px; vertical-align: -2px; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27%3E%3Cpath d=%27M6 3.5 10.5 8 6 12.5%27 fill=%27none%27 stroke=%27black%27 stroke-width=%271.8%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27%3E%3Cpath d=%27M6 3.5 10.5 8 6 12.5%27 fill=%27none%27 stroke=%27black%27 stroke-width=%271.8%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27/%3E%3C/svg%3E") center / contain no-repeat;
  transform: rotate(-90deg);
}
th.sorted.desc::after { transform: rotate(90deg); }
.num { text-align: right; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
/* Date fields: free text plus a calendar button; the native picker is an invisible input next to the button. */
.date-field { position: relative; display: flex; gap: 4px; }
.date-field input[type="text"] { flex: 1; min-width: 0; }
.date-field input.invalid { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); }
.cal-btn {
  flex: none; width: 34px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); cursor: pointer; font-size: 14px; line-height: 1;
}
.cal-btn:hover, .cal-btn:focus-visible { border-color: var(--accent); outline: none; }
.native-date {
  position: absolute; right: 0; bottom: 0; width: 1px; height: 1px; padding: 0; border: 0;
  opacity: 0; pointer-events: none;
}

.pager {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 18px;
  padding: 10px 14px 6px;
}
.pager label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.pager select { width: auto; min-height: 30px; }
.pager-nav { display: flex; align-items: center; gap: 6px; }
.btn.icon { padding: 4px 10px; font-size: 16px; line-height: 1.2; }

/* The dot in a category's chart colour, so list rows match the charts. */
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.help { color: var(--muted); cursor: help; font-size: 13px; }
.help:hover, .help:focus-visible { color: var(--accent); outline: none; }
.chip { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: color-mix(in srgb, var(--c) 16%, transparent); color: var(--c); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 10;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: -8px 0 28px rgba(0, 0, 0, .18);
  display: flex; flex-direction: column; overflow: hidden;
}
.drawer[hidden] { display: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
#drawerBody { padding: 14px 16px; overflow: auto; flex: 1; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 0 0 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.status-edit { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.status-note { margin: 6px 0 0; font-size: 12px; }
/* Why Jump refused an expense or asks for changes */
.reason-box { border-left: 3px solid var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent);
  border-radius: 6px; padding: 8px 10px; }
.reason-box p { margin: 0; }
.reason-box p + p { margin-top: 6px; }
.reason-text { font-weight: 600; }
.reason-mark { display: inline-grid; place-items: center; width: 16px; height: 16px; margin-left: 4px; border-radius: 50%;
  background: var(--warn); color: #fff; font-size: 11px; font-weight: 800; vertical-align: middle; cursor: help; }
.docs { margin: 0 0 14px; padding-left: 20px; }
.docs li { margin: 4px 0; }
.docs a { color: var(--accent); }
summary { cursor: pointer; }
details pre { max-height: 240px; overflow: auto; background: var(--bg); padding: 10px; border-radius: 8px; font-size: 12px; }

/* The user's initials at the end of the top bar: small and quiet; the full name is the tooltip. */
.avatar {
  align-self: center; display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: color-mix(in srgb, var(--accent) 18%, var(--surface)); color: var(--accent);
  font-size: 12px; font-weight: 700; letter-spacing: .02em; cursor: default; user-select: none;
}
.avatar:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#section-missions { margin-top: 16px; }

/* Sync progress: a thin bar under the step text, the percentage next to the elapsed time. */
.banner .bar { height: 5px; margin-top: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.banner .bar > div { height: 100%; width: 0; background: var(--accent); transition: width .6s ease; }
.banner .percent { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 3.2em; text-align: right; }

/* The result of a sync: one block per kind of data, as many columns as fit. */
#resultBody { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 4px 28px; }
#resultBody .error { grid-column: 1 / -1; }

/* "Filters" is a quiet text button at the top of every tab; the filters stay folded until it is used. */
.filters-toggle {
  display: inline-flex; align-items: center; gap: 6px; margin: 0 0 8px; padding: 2px 4px;
  border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; border-radius: 6px;
}
.filters-toggle:hover, .filters-toggle[aria-expanded="true"] { color: var(--text); }
.filters-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chev { flex: none; transition: transform .15s; }
.chev.down { transform: rotate(90deg); }
.chev.up { transform: rotate(-90deg); }
.export-toggle[aria-expanded="true"] .chev.down { transform: rotate(-90deg); }
.filters-toggle[aria-expanded="true"] .chev:not(.down), .charts-box[open] > summary .chev { transform: rotate(90deg); }
.charts-box > summary { margin-bottom: 8px; list-style: none; width: fit-content; }
.charts-box > summary::-webkit-details-marker { display: none; }
.charts-box { margin: 0 0 14px; }
.charts-box[open] > summary { color: var(--text); }
/* Filters and Charts are folded by default: the label and an icon in the accent colour, and while folded a hint of
   what is inside, so they are not overlooked. */
.fold-toggle { color: var(--accent); }
.fold-toggle:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.fold-toggle[aria-expanded="true"], .charts-box[open] > summary.fold-toggle { color: var(--text); }
.fold-icon { flex: none; }
.fold-hint { color: var(--muted); font-weight: 400; }
.fold-hint::before { content: "·"; margin-right: 6px; }
.fold-toggle[aria-expanded="true"] .fold-hint, .charts-box[open] > summary .fold-hint { display: none; }
@media (max-width: 600px) { .fold-hint { display: none; } }

.data-block { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.data-block:first-of-type { border-top: 0; padding-top: 0; }
.data-block p { margin: 2px 0 8px; }
.small.first { margin-top: 0; }
label.inline { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }

/* The Filters and Export buttons share one row at the top of every tab. */
.tab-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 0 0 8px; }
.tab-toolbar .filters-toggle { margin: 0; }
.export-menu { position: relative; display: inline-flex; align-items: center; gap: 10px; }
.export-list {
  position: absolute; right: 0; top: 100%; z-index: 20; margin: 4px 0 0; padding: 4px; list-style: none; min-width: 170px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
}
.export-list[hidden] { display: none; }
.export-list button {
  width: 100%; text-align: left; padding: 7px 10px; border: 0; border-radius: 6px; background: none; color: var(--text);
  font: inherit; cursor: pointer;
}
.export-list button:hover, .export-list button:focus-visible { background: color-mix(in srgb, var(--accent) 12%, transparent); outline: none; }
.export-msg { font-size: 12px; }

.dash-charts { grid-template-columns: 1fr 1fr; margin-bottom: 14px; }
@media (max-width: 900px) { .dash-charts { grid-template-columns: 1fr; } }
.tile.bad .sub { color: var(--bad); font-weight: 600; }

.year-body h3 { font-size: 13px; margin: 14px 0 4px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.year-body table { font-size: 13px; }
.year-body tr.total td { border-top: 2px solid var(--border); }

.legal { max-width: 1280px; margin: 0 auto; padding: 0 24px 28px; color: var(--muted); font-size: 12px; line-height: 1.5; }

/* Your own tags and notes. */
.tag-chips { display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); white-space: nowrap;
}
.tag-chip button { border: 0; background: none; color: inherit; font: inherit; cursor: pointer; padding: 0 0 0 2px; line-height: 1; }
.note-mark { color: var(--muted); cursor: help; font-size: 13px; }
.annotation-editor { margin-top: 18px; }
.tag-input {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px 8px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); margin-bottom: 10px;
}
.tag-input .tag-list { display: contents; }
.tag-input input { flex: 1 1 120px; min-width: 100px; border: 0; background: transparent; color: var(--text); font: inherit; outline: none; padding: 2px; }
.note-label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.note-text {
  width: 100%; box-sizing: border-box; resize: vertical; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px;
}
.annotation-actions { display: flex; align-items: center; gap: 12px; margin-top: 10px; }

/* The charts of the expenses tab are folded away until asked for. */
