:root { --fg: #1d2330; --muted: #6b7280; --border: #d9dee7; --accent: #2563eb; --err: #b91c1c; --bg: #f5f7fb; --ok: #15803d; }
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--fg); background: var(--bg); }
main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 48px; }
h1 { margin: 0 0 16px; font-size: 1.6rem; }
h2 { margin: 0 0 12px; font-size: 1.15rem; }
.card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 18px; margin-bottom: 20px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 16px; margin-bottom: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 0.9rem; }
input { font: inherit; font-weight: 400; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input.invalid { border-color: var(--err); }
.err { color: var(--err); font-weight: 400; min-height: 1em; }
.muted { color: var(--muted); font-weight: 400; }
.actions { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
button, a.button { font: inherit; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; }
button.secondary, a.button.secondary { background: #fff; color: var(--accent); }
button.danger { background: #fff; color: var(--err); border-color: var(--border); padding: 4px 10px; font-size: 0.85rem; }
button.danger:hover:not(:disabled) { border-color: var(--err); background: #fef2f2; filter: none; }
button:disabled { opacity: 0.6; cursor: default; }
select:disabled { opacity: 0.7; cursor: not-allowed; background: var(--bg); }
#form-status.ok { color: #15803d; }
#form-status.bad { color: var(--err); }
.list-header { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 10px; }
.filters { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.filters label { font-size: 0.8rem; }
.filters input { padding: 5px 8px; }
.filters button { padding: 5px 10px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; margin-top: 8px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.time { white-space: nowrap; font-variant-numeric: tabular-nums; }
td.note { color: var(--muted); min-width: 10em; max-width: 280px; overflow-wrap: break-word; }
#totals { margin-top: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-weight: 600; font-size: 0.9rem; }
.datetime-row { display: flex; gap: 6px; }
.datetime-row #spent_at { flex: 1; min-width: 0; }
.foreign-row { display: flex; gap: 6px; }
.foreign-row #foreign_amount { flex: 0 1 34%; min-width: 0; }
.foreign-row .combo, .foreign-row select { flex: 1 1 66%; min-width: 0; }
.charges-row { display: flex; gap: 6px; }
.charges-row input { flex: 1 1 50%; min-width: 0; }
.foreign-amt { display: block; font-size: 0.8rem; font-weight: 400; color: var(--muted); white-space: nowrap; }
td.actions-cell { white-space: nowrap; }
td.actions-cell > * + * { margin-left: 6px; }
button.edit, a.button.edit { padding: 4px 10px; font-size: 0.85rem; background: #fff; color: var(--accent); }
.edited { font-size: 0.75rem; color: var(--muted); margin-left: 6px; }
.tabs { display: flex; gap: 4px; margin: -4px 0 16px; border-bottom: 1px solid var(--border); }
.tab { padding: 8px 16px; text-decoration: none; color: var(--muted); font-weight: 600; border: 1px solid transparent; border-bottom: none; border-radius: 8px 8px 0 0; margin-bottom: -1px; }
.tab:hover { color: var(--fg); }
.tab.active { color: var(--accent); background: #fff; border-color: var(--border); }
.tab-docs { margin-left: auto; }
select { font: inherit; font-weight: 400; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
h3 { margin: 18px 0 6px; font-size: 1rem; }
.small { font-size: 0.85rem; margin: 0 0 6px; }
.group-empty { color: var(--muted); margin: 4px 0 8px; font-size: 0.9rem; }
td.neg { color: var(--err); }
.badge { display: inline-block; font-size: 0.72rem; font-weight: 600; padding: 1px 6px; border-radius: 999px; margin-left: 6px; vertical-align: middle; }
.badge.over { background: #fee2e2; color: var(--err); }
#b-totals td, #b-totals th { white-space: nowrap; }
[hidden] { display: none !important; }
.type-income, .type-return_on_investment { color: #1a7f37; }
.type-transfer, .type-asset_purchase, .type-repay_debt { color: #555; font-style: italic; }
.type-balance_adjustment { color: #6d28d9; font-weight: 600; }
tr.row-adjustment td { background: #f5f3ff; }
#b-form-status.ok, #c-form-status.ok, #s-form-status.ok, #t-form-status.ok { color: #15803d; }
.conflict { border: 1px solid #fcd34d; background: #fffbeb; color: #92400e; border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
.conflict p { margin: 0 0 8px; }
#b-form-status.bad, #c-form-status.bad, #s-form-status.bad, #t-form-status.bad { color: var(--err); }
a.button { display: inline-block; text-decoration: none; line-height: inherit; }
a.button:hover, button:hover:not(:disabled) { filter: brightness(1.05); }
.list-header .add-btn { margin-left: auto; font-weight: 600; }
.list-header h2 { margin: 0; }
.list-header { margin-bottom: 8px; }
.flash { margin: 8px 0; padding: 8px 12px; border-radius: 6px; background: #ecfdf5; color: #15803d; border: 1px solid #bbf7d0; }
.flash.bad { background: #fef2f2; color: var(--err); border-color: #fecaca; }
tr.just-saved td { background: #ecfdf5; transition: background 2s; }
.back { margin: 0 0 6px; font-size: 0.9rem; }
.back a { color: var(--accent); text-decoration: none; }
.form-card { max-width: 760px; }
.combo { position: relative; display: flex; }
.combo-input { flex: 1; min-width: 0; padding-right: 52px; }
.combo-input:disabled { opacity: 0.7; cursor: not-allowed; background: var(--bg); }
.combo-toggle, .combo-clear { position: absolute; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--muted); padding: 2px 6px; font-size: 0.95rem; line-height: 1; }
.combo-toggle { right: 4px; }
.combo-clear { right: 26px; font-size: 1.1rem; }
.combo-toggle:hover, .combo-clear:hover { color: var(--fg); filter: none; }
.combo-list { position: absolute; z-index: 10; top: calc(100% + 2px); left: 0; right: 0; max-height: 240px; overflow-y: auto; margin: 0; padding: 4px 0; list-style: none; background: #fff; border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 6px 16px rgba(29, 35, 48, 0.12); font-weight: 400; }
.combo-option { padding: 6px 10px; cursor: pointer; }
.combo-option.active, .combo-option:hover { background: #eff4ff; color: var(--accent); }
.combo-none { color: var(--muted); font-style: italic; }
.combo-empty { padding: 6px 10px; color: var(--muted); font-style: italic; }
.combo-group { padding: 8px 10px 2px; font-weight: 600; color: var(--muted); cursor: default; }
.combo-option.combo-grouped { padding-left: 20px; }
/* Header with the signed-in user (issue #30). */
.app-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.app-header h1 { margin: 0; }
.user-bar { display: flex; align-items: center; gap: 8px; }
.user-bar[hidden] { display: none; }
.auth-card { max-width: 420px; }
.auth-card label { display: block; margin-bottom: 12px; }
.auth-card input { width: 100%; box-sizing: border-box; }
.error { margin: 8px 0; padding: 8px 12px; border-radius: 6px; background: #fef2f2; color: var(--err); border: 1px solid #fecaca; }
.auth-switch { margin-top: 16px; padding-top: 12px; border-top: 1px solid #e5e7eb; }
.auth-switch p { margin: 0 0 8px; }

/* Cross-currency transfers */
button.linklike { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; }
td.num.fx { min-width: 9em; }
td.num.fx .fx-amounts { display: flex; flex-wrap: wrap; justify-content: flex-end; column-gap: 0.35em; }
td.num.fx .fx-amounts > span, td.num.fx .fx-rates > span { white-space: nowrap; }
td.num.fx .fx-rates { display: flex; flex-direction: column; align-items: flex-end; margin-top: 2px; font-size: 0.75rem; line-height: 1.3; color: var(--muted); }
.fx-conv { display: flex; flex-wrap: wrap; gap: 4px 6px; font-weight: 400; }
.fx-conv-line { font-size: 0.85rem; padding: 2px 8px; border-radius: 999px; background: #eef2ff; color: #3730a3; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* Narrow screens: each transaction becomes a compact two-column card
   (details left, amount and rates right) instead of a wide scrolling table. */
@media (max-width: 640px) {
  #transaction-table thead { display: none; }
  #transaction-table, #transaction-table tbody { display: block; }
  #transaction-table tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px;
    grid-template-areas: "time amount" "type amount" "acct cur" "cat cat" "note note" "actions actions";
    padding: 10px 0; border-bottom: 1px solid var(--border);
  }
  #transaction-table td { border: 0; padding: 1px 0; }
  #transaction-table td:empty { display: none; }
  #transaction-table td.time { grid-area: time; font-size: 0.85rem; color: var(--muted); }
  #transaction-table td.type { grid-area: type; }
  #transaction-table td.num { grid-area: amount; font-weight: 600; }
  #transaction-table td.cur { grid-area: cur; text-align: right; color: var(--muted); font-size: 0.85rem; }
  #transaction-table tr.fx-row td.cur { display: none; } /* currencies are in the amount */
  #transaction-table td.acct { grid-area: acct; }
  #transaction-table td.cat { grid-area: cat; font-size: 0.85rem; }
  #transaction-table td.note { grid-area: note; max-width: none; overflow-wrap: break-word; font-size: 0.85rem; }
  #transaction-table td.actions-cell { grid-area: actions; margin-top: 6px; }
  #transaction-table td[colspan] { grid-column: 1 / -1; }
  td.num.fx { min-width: 0; }
  td.num.fx .fx-amounts { flex-direction: column; align-items: flex-end; }
  td.num.fx .fx-rates { font-weight: 400; }
}

/* Settings: API tokens */
.token-new { border: 1px solid #fcd34d; background: #fffbeb; color: #92400e; border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
.token-new p { margin: 0 0 8px; }
.token-secret-row { display: flex; gap: 8px; }
.token-secret-row input { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
td.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; white-space: nowrap; }
#tokens-card { max-width: 1000px; }
#token-table td.time { white-space: nowrap; }
.load-more { text-align: center; margin: 12px 0 4px; }
.load-more:has(button[hidden]) { display: none; }
.type-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.type-choice { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 8px; color: var(--fg); text-decoration: none; background: #fff; }
.type-choice:hover, .type-choice:focus-visible { border-color: var(--accent); background: #eff4ff; outline: none; }
.type-choice strong { font-size: 1rem; }
.type-choice .muted { font-size: 0.85rem; }

/* ---- UI polish -------------------------------------------------------- */
a { color: var(--accent); }
a:not(.button):not(.tab):not(.type-choice):hover { text-decoration-thickness: 2px; }
select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
select.invalid { border-color: var(--err); }
/* Amounts: money in is green; expenses stay in the normal text colour. */
.amt-income, .amt-return_on_investment { color: var(--ok); }
td.num { white-space: nowrap; }
td.acct, td.cat { min-width: 7em; }
/* Totals under the transaction list: one line per currency. */
.totals { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.totals:empty { display: none; }
.totals-title { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; cursor: help; }
.totals-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 20px; font-variant-numeric: tabular-nums; }
.totals-cur { min-width: 5.5em; font-weight: 600; }
/* Balance groups: the same column widths in every group, so the tables line up. */
.balance-table { table-layout: fixed; min-width: 640px; }
.balance-table .col-name { width: 24%; }
.balance-table .col-cur { width: 11%; }
.balance-table th.num { width: 13%; }
.balance-table .col-actions { width: 205px; }
.balance-table td { overflow-wrap: break-word; }

@media (max-width: 640px) {
  main { padding: 16px 12px 40px; }
  h1 { font-size: 1.3rem; }
  .app-header { margin-bottom: 10px; }
  .user-bar { font-size: 0.9rem; }
  .user-bar button { padding: 5px 10px; }
  /* Tabs scroll sideways instead of wrapping. */
  .tabs { overflow-x: auto; scrollbar-width: none; margin-left: -12px; margin-right: -12px; padding: 0 12px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 8px 12px; white-space: nowrap; }
  .card { padding: 14px; border-radius: 8px; }
  .list-header h2 { flex: 1; }
  .list-header .filters { order: 1; width: 100%; }
  .filters label { flex: 1 1 40%; }
  .filters input, .filters select { width: 100%; }
  /* Transaction cards: Edit/Delete sit at the right, beside category and note. */
  #transaction-table tr { grid-template-areas: "time amount" "type amount" "acct cur" "cat actions" "note actions"; }
  #transaction-table td.actions-cell { margin-top: 0; align-self: end; text-align: right; }
  #transaction-table td.acct, #transaction-table td.cat { min-width: 0; }
  #transaction-table td.note { min-width: 0; }
  /* Balance rows become cards: name and currency left, amounts right. */
  .balance-table { min-width: 0; table-layout: auto; }
  .balance-table thead { display: none; }
  .balance-table, .balance-table tbody { display: block; }
  .balance-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
  .balance-table td { border: 0; padding: 1px 0; }
  .balance-table td:nth-child(1) { grid-column: 1; grid-row: 1; font-weight: 600; }
  .balance-table td:nth-child(2) { grid-column: 1; grid-row: 2; color: var(--muted); font-size: 0.85rem; }
  .balance-table td.num { grid-column: 2; }
  .balance-table td.num:nth-child(3) { grid-row: 1; font-weight: 600; }
  .balance-table td.num:nth-child(4) { grid-row: 2; font-size: 0.85rem; }
  .balance-table td.num:nth-child(5) { grid-row: 3; font-size: 0.85rem; }
  .balance-table[data-type="credit_card"] td.num::before, .balance-table[data-type="other_liability"] td.num::before { content: attr(data-label) " "; color: var(--muted); font-weight: 400; font-size: 0.8rem; }
  .balance-table td.note { display: none; }
  .balance-table td.actions-cell { grid-column: 1; grid-row: 3; margin-top: 6px; }
  th, td { padding: 8px 6px; }
}

/* ---- Reports (issue #136): horizontal bar charts ----------------------- */
.report-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.report-tab { padding: 5px 12px; border: 1px solid var(--border); border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 0.9rem; background: #fff; }
.report-tab:hover { color: var(--fg); border-color: var(--accent); }
.report-tab.active { color: #fff; background: var(--accent); border-color: var(--accent); }
.report-filters { margin-bottom: 6px; }
.report-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.report-range { margin: 4px 0 0; font-size: 0.9rem; }
.report-currency { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.report-currency h3.report-cur { margin: 0 0 8px; }
.report-currency h4 { margin: 14px 0 6px; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.report-net { margin: 6px 0 0; font-variant-numeric: tabular-nums; }
.pos-text { color: var(--ok); }
.neg-text { color: var(--err); }
.report-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 28px; }
/* One grid per chart (rows share it through subgrid), so every bar in a chart starts and ends at the same x. */
.bar-chart { display: grid; grid-template-columns: minmax(6em, 11em) minmax(60px, 1fr) auto; gap: 6px 10px; }
.bar-row { grid-column: 1 / -1; display: grid; grid-template-columns: subgrid; align-items: center; }
.bar-label { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.bar-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-sub { font-size: 0.75rem; }
.bar-track { height: 18px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--accent); }
.bar-fill.bar-income, .bar-fill.bar-asset { background: #16a34a; }
.bar-fill.bar-expense, .bar-fill.bar-liability { background: #dc2626; }
.bar-fill.bar-neg { background-image: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.55) 0 4px, transparent 4px 8px); opacity: 0.75; }
.bar-value { display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1.25; }
.bar-amount { font-weight: 600; }
.bar-note { font-size: 0.75rem; }
@media (max-width: 640px) {
  .report-cols { grid-template-columns: 1fr; }
  .bar-chart { display: flex; flex-direction: column; gap: 8px; }
  .bar-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "label value" "track track"; gap: 3px 10px; }
  .bar-label { grid-area: label; }
  .bar-value { grid-area: value; }
  .bar-track { grid-area: track; height: 12px; }
  .report-filters label { flex: 1 1 40%; }
}

/* Hidden balances (issue #147) and the delete dialog. */
.show-hidden { display: flex; flex-direction: row; align-items: center; gap: 6px; font-weight: 400; color: var(--muted); font-size: 0.9rem; margin-left: auto; }
.show-hidden + .add-btn { margin-left: 0; }
.badge.hidden-badge { background: #e5e7eb; color: var(--muted); }
tr.is-hidden td { color: var(--muted); }
#b-delete-dialog { border: 1px solid var(--border); border-radius: 10px; padding: 20px; max-width: min(460px, calc(100vw - 32px)); }
#b-delete-dialog::backdrop { background: rgba(15, 23, 42, 0.35); }
#b-delete-dialog h3 { margin-top: 0; }
#b-delete-dialog button.danger { padding: 8px 14px; font-size: inherit; border-color: var(--err); }
