:root { --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100; }
@media (prefers-color-scheme: dark) { :root:not([data-theme=light]) { --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; } }
/* manual-theme */ :root[data-theme=dark] { --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; }

.flash.warning { background: var(--warn-soft); color: var(--warn); }
.tip { position: fixed; z-index: 80; background: var(--text); color: var(--surface); padding: 3px 9px; border-radius: 6px; font-size: 12px; pointer-events: none; white-space: nowrap; max-width: 90vw; overflow: hidden; text-overflow: ellipsis; }
.tip[hidden] { display: none; }
.chart .hit { fill: transparent; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .grid { stroke: var(--line); }
.chart .bar { fill: var(--series-1); opacity: .45; }
.chart .bar-current, .chart g:hover .bar { fill: var(--series-1); opacity: 1; }
.chart .bar-value { fill: var(--text); }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 5px; }

.hbar { display: grid; grid-template-columns: minmax(90px, 170px) 1fr auto; gap: 10px; align-items: center; padding: 6px 16px; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { height: 9px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--series-1); border-radius: 5px; }
.hbar .val { font-size: 12.5px; white-space: nowrap; color: var(--muted); }

.heatmap { display: grid; gap: 2px; font-size: 11px; color: var(--muted); }
.hm-head { text-align: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.hm-row { display: flex; align-items: center; }
.hm-cell { height: 26px; border-radius: 3px; background: color-mix(in srgb, var(--series-1) var(--level), var(--surface-2)); }

.hm-cell { display: flex; align-items: center; justify-content: center; color: var(--text); font-size: 11px; }
.hm-cell.hm-empty { background: transparent; border: 1px dashed var(--line); }
.hm-on-dark { color: #fff; }
.chart .whisker { stroke: var(--text); stroke-width: 1.5; }
.action-row { display: flex; gap: 9px; align-items: baseline; padding: 4px 0; }
.dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); transform: translateY(1px); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.progress { position: relative; height: 12px; border-radius: 6px; background: var(--surface-2); margin: 10px 0 4px; }
.progress .done { height: 100%; border-radius: 6px; background: var(--series-1); }
.progress .now { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text); }
.tile:has(a.label) { cursor: pointer; transition: border-color .12s, transform .12s; }
.tile:has(a.label):hover { border-color: var(--brand); transform: translateY(-1px); }
.tile a.label { display: block; }
.tile a.label::after { content: ' ‹'; color: var(--brand); }
.chart a { cursor: pointer; }
.bell { position: relative; text-decoration: none; font-size: 17px; }
.bell .count { position: absolute; top: -7px; inset-inline-start: -9px; background: #d9483b; color: #fff; font-size: 10.5px; line-height: 1; padding: 3px 5px; border-radius: 20px; }
.chat { max-height: 62vh; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 9px; }
.chat-msg { align-self: flex-start; max-width: 86%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.chat-msg.mine { align-self: flex-end; background: var(--brand-soft); border-color: transparent; }
.chat-meta { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }
.chat-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-msg img { display: block; max-width: 100%; max-height: 300px; border-radius: 8px; margin: 2px 0; }
.chat-msg audio { display: block; width: 250px; max-width: 100%; }
.chat-event { align-self: center; font-size: 12px; color: var(--muted); text-align: center; }
#record.on { background: var(--bad); color: #fff; border-color: var(--bad); }
details > summary.card-head { list-style: none; }
details > summary.card-head::-webkit-details-marker { display: none; }
.guide { max-width: 900px; }
.guide h2 { font-size: 17px; margin-bottom: 8px; }
.guide h3 { font-size: 14.5px; margin: 14px 0 4px; }
.guide p, .guide li { line-height: 2; }
.guide ul, .guide ol { margin: 4px 0; padding-inline-start: 22px; }
.guide section { scroll-margin-top: 70px; }
.tabs-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; }
.tabs-wrap .tabs { border-bottom: 0; }
.meter { height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.meter div { height: 100%; background: var(--series-1); }
.meter.bad div { background: var(--bad); }
.meter.good div { background: var(--ok); }
.insight { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.insight:last-child { border-bottom: 0; }
.insight h3 { margin: 4px 0; font-size: 14.5px; }
.insight p { margin: 2px 0; }
.report { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 2; }
.purchase { border-bottom: 1px solid var(--line); padding: 10px 16px; }
.purchase:last-child { border-bottom: 0; }
.purchase .items { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.event.cheque { background: var(--ok-soft); color: var(--ok); }
.check-grid { display: flex; flex-wrap: wrap; gap: 6px 16px; }
details.advanced summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }
@media (max-width: 760px) { .hm-cell { height: 18px; } .heatmap { font-size: 9px; } }
.dropping{outline:3px dashed var(--brand,#0f6b5f);outline-offset:-6px;background:rgba(15,107,95,.06)}

/* ---- change badges and small trend lines */
.delta { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 999px; vertical-align: middle; white-space: nowrap; }
.delta.good { background: var(--ok-soft); color: var(--ok); }
.delta.bad { background: var(--bad-soft); color: var(--bad); }
.tile .value .delta { font-size: 11px; margin-inline-start: 4px; }
.spark { display: block; width: 100%; max-width: 160px; height: 30px; margin-top: 6px; }
.spark polyline { fill: none; stroke: var(--series-1); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.spark circle { fill: var(--series-1); }
.tile.bad .spark polyline { stroke: var(--bad); }
.tile.bad .spark circle { fill: var(--bad); }

/* ---- cash calendar */
.cash-cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; padding: 12px 14px 16px; }
.cal-head { text-align: center; font-size: 11.5px; color: var(--muted); padding-bottom: 2px; }
.cal-day { display: flex; flex-direction: column; gap: 1px; min-height: 64px; padding: 5px 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); text-decoration: none; font-size: 11px; line-height: 1.35; }
.cal-day:hover { border-color: var(--brand); }
.cal-day.empty { border-style: dashed; background: transparent; }
.cal-day.plus { background: color-mix(in srgb, var(--ok-soft) 70%, var(--surface)); }
.cal-day.minus { background: color-mix(in srgb, var(--warn-soft) 70%, var(--surface)); }
.cal-day.short { background: var(--bad-soft); border-color: var(--bad); }
.cal-num { font-weight: 700; font-size: 12.5px; }
.cal-in { color: var(--ok); }
.cal-out { color: var(--bad); }
.cal-bal { margin-top: auto; color: var(--muted); }
.cal-day.short .cal-bal { color: var(--bad); font-weight: 700; }
@media (max-width: 700px) { .cal-day { min-height: 48px; font-size: 10px; padding: 3px; } .cal-in, .cal-out { display: none; } }

/* ---- funnel and inline bars */
.funnel { display: grid; gap: 10px; }
.funnel-step { display: grid; grid-template-columns: minmax(0, 1fr) minmax(150px, 260px); gap: 12px; align-items: center; }
.funnel-bar { min-width: 46px; height: 34px; display: flex; align-items: center; justify-content: center; border-radius: 8px; background: color-mix(in srgb, var(--series-1) 75%, var(--surface)); color: #fff; transition: width .3s; }
.funnel-label { font-size: 13px; }
.hbar-inline { position: relative; height: 22px; background: var(--surface-2); border-radius: 6px; overflow: hidden; min-width: 90px; }
.hbar-inline .fill { position: absolute; inset-block: 0; inset-inline-start: 0; background: color-mix(in srgb, var(--series-1) 55%, var(--surface-2)); border-radius: 6px; }
.hbar-inline.debt .fill { background: color-mix(in srgb, var(--series-2) 55%, var(--surface-2)); }
.hbar-inline .num { position: relative; z-index: 1; padding-inline-start: 8px; line-height: 22px; font-size: 12px; }
td.winner { background: var(--ok-soft); color: var(--ok); font-weight: 700; }

/* ---- a dashboard each person arranges */
.dash-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.dash-grid > .dash-block { margin: 0; min-width: 0; }
.dash-grid > .dash-wide { grid-column: 1 / -1; }
.dash-grid > .dash-hidden { display: none; }
.dash-grid.editing > .dash-block { outline: 2px dashed var(--line-strong); outline-offset: 3px; }
.dash-grid.editing > .dash-hidden { display: block; opacity: .45; }
.dash-tools { display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: var(--surface-2); border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; }
.dash-tools strong { flex: 1; font-size: 12.5px; }
.dash-hint { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: minmax(0, 1fr); } }

/* ---- inline edits in lists */
select.inline-edit { padding: 3px 6px; font-size: 12.5px; border: 1px solid transparent; background: transparent; border-radius: 6px; max-width: 150px; }
select.inline-edit:hover, select.inline-edit:focus { border-color: var(--line-strong); background: var(--surface); }
select.inline-edit.saved { border-color: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
select.inline-edit.failed { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }

/* ---- Ctrl+K */
.kbd-hint { position: absolute; inset-inline-end: 8px; top: 50%; transform: translateY(-50%); padding: 1px 7px; font: 600 11px/1.6 ui-monospace, monospace; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 6px; cursor: pointer; direction: ltr; }
.palette { position: fixed; inset: 0; z-index: 90; background: rgb(8 16 15 / 45%); display: flex; align-items: flex-start; justify-content: center; padding: 10vh 12px 12px; }
.palette[hidden] { display: none; }
.palette-box { width: min(620px, 100%); background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lift); overflow: hidden; border: 1px solid var(--line); }
.palette-box input { width: 100%; border: 0; border-bottom: 1px solid var(--line); padding: 16px 18px; font-size: 16px; background: transparent; color: var(--text); outline: none; }
.palette-results { max-height: 55vh; overflow: auto; padding: 6px; }
.palette-group { font-size: 11.5px; color: var(--muted); padding: 8px 12px 4px; }
.palette-item { display: flex; align-items: baseline; gap: 10px; padding: 8px 12px; border-radius: 8px; color: var(--text); text-decoration: none; }
.palette-item small { color: var(--muted); }
.palette-item.on, .palette-item:hover { background: var(--brand-soft); color: var(--brand-strong); }
.palette-empty { padding: 18px; text-align: center; color: var(--muted); }
.palette-foot { padding: 8px 14px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--line); background: var(--surface-2); }

/* ---- theme button and first-visit tour */
.theme-btn { border: 0; background: none; cursor: pointer; }
:root[data-theme=dark] .theme-btn svg { fill: currentColor; }
.tour-card { position: absolute; z-index: 95; background: var(--surface); color: var(--text); border: 1px solid var(--brand); border-radius: var(--radius); box-shadow: var(--shadow-lift); padding: 14px 16px; }
.tour-card p { margin: 0 0 12px; line-height: 1.7; }
.tour-row { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.tour-row .small { margin-inline-end: auto; }
.tour-focus { position: relative; z-index: 94; outline: 3px solid var(--brand); outline-offset: 3px; border-radius: 10px; box-shadow: 0 0 0 9999px rgb(8 16 15 / 35%); }
@media print { .palette, .tour-card, .kbd-hint, .dash-tools, .dash-hint, #dash-edit { display: none !important; } .dash-grid { display: block; } }
/* the list of companies after signing in, and the way back to it */
.company-back { display: inline-flex; align-items: center; margin-inline-start: 12px; padding: 4px 12px; border-radius: 999px; background: rgba(255,255,255,.14); color: #fff; font-size: 13px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.company-back:hover { background: rgba(255,255,255,.24); }
.company-cards { display: grid; gap: 14px; margin: 18px auto 0; max-width: 820px; }
.company-card { display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "mark name go" "mark role go"; align-items: center; column-gap: 16px; row-gap: 2px; padding: 18px 20px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); text-decoration: none; box-shadow: 0 1px 2px rgb(0 0 0 / 4%); transition: border-color .15s, box-shadow .15s, transform .15s; }
.company-card:hover { border-color: var(--brand); box-shadow: 0 8px 24px rgb(9 92 80 / 12%); transform: translateY(-1px); }
.company-card.main { border-inline-start: 4px solid var(--brand); }
.company-mark { grid-area: mark; width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; background: linear-gradient(135deg, var(--brand), var(--brand-strong)); color: #fff; font-weight: 700; font-size: 22px; }
.company-name { grid-area: name; font-size: 18px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.company-name .badge { font-size: 11px; font-weight: 600; }
.company-role { grid-area: role; font-size: 13px; color: var(--muted); }
.company-role strong { color: var(--brand-strong); font-weight: 600; }
.company-card .btn { grid-area: go; min-width: 92px; }
.choose-head { max-width: 820px; margin: 0 auto; }
.choose-head p { margin: 4px 0 0; color: var(--muted); }
@media (max-width: 560px) {
  .company-card { grid-template-columns: auto 1fr; grid-template-areas: "mark name" "mark role" "go go"; row-gap: 6px; }
  .company-card .btn { width: 100%; margin-top: 8px; }
}/* Fiscal-year switch: one pill per year */
.year-switch { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
.year-switch a { padding: 7px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: inherit; text-decoration: none; font-size: 13px; }
.year-switch a.active { border-color: var(--brand); background: var(--brand-soft); font-weight: 700; }
.table tfoot th { border-top: 2px solid var(--line); text-align: start; }
/* A negative amount keeps its minus sign in front of the digits, also inside right-to-left text */
.num, .money, td.money { unicode-bidi: plaintext; }
[dir=rtl] td.num, [dir=rtl] th.num { text-align: right; }

/* On a phone the search box has room for the magnifier only, and there is no Ctrl key: the whole box opens the quick search. */
@media (max-width: 700px) {
  .global-search { min-width: 44px; }
  .global-search input[type=search] { padding-inline: 0; color: transparent; caret-color: transparent; }
  .global-search input[type=search]::placeholder { color: transparent; }
  .global-search svg { inset-inline-start: 50%; margin-inline-start: -9px; }
  .global-search .kbd-hint { inset: 0; transform: none; width: 100%; padding: 0; font-size: 0; background: transparent; border-color: transparent; border-radius: 999px; }
}
/* Names that must stay on one line in narrow tables. */
td.nowrap, th.nowrap { white-space: nowrap; }

/* ---------- The list of AI services: a rank, a name, its buttons in one line; forms in even columns ---------- */
.svc-list { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.svc { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 6px 14px; padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.svc:last-child { border-bottom: 0; }
.svc-rank { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--surface-2); color: var(--muted); font-weight: 700; font-size: 13px; }
.svc-rank.first { background: var(--brand-soft); color: var(--brand); }
.svc-name { min-width: 0; line-height: 1.7; }
.svc-name .small { overflow-wrap: anywhere; }
.svc-actions { display: flex; flex-wrap: nowrap; gap: 6px; margin: 0; }
.svc-edit { grid-column: 2 / -1; }
.svc-edit summary, .svc-more summary { cursor: pointer; width: fit-content; padding: 2px 0; }
.svc-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px 16px; align-items: end; margin-top: 10px; }
.svc-form .field { margin: 0; }
.svc-submit { display: flex; }
.svc-title { margin: 22px 0 0; font-size: 15px; }
.svc-more { margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--line); }
.svc-more summary { font-weight: 600; color: var(--muted); }
.insights { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }
.insights .insight { border-inline-end: 1px solid var(--line); }
@media (max-width: 700px) {
  .svc { grid-template-columns: auto minmax(0, 1fr); }
  .svc-actions { grid-column: 1 / -1; flex-wrap: wrap; }
  .svc-actions .btn { flex: 1 1 auto; }
  .svc-edit { grid-column: 1 / -1; }
  .svc-form { grid-template-columns: minmax(0, 1fr); }
  .svc-submit .btn { width: 100%; justify-content: center; }
  .insights { grid-template-columns: minmax(0, 1fr); }
}

/* two thin bars, one over the other: what a group sold and what was bought for it */
.pair-bar { height: 8px; min-width: 120px; border-radius: 5px; background: var(--surface-2); overflow: hidden; margin: 3px 0; }
.pair-bar i { display: block; height: 100%; border-radius: 5px; background: var(--series-1, var(--brand)); }
.pair-bar.buy i { background: var(--series-2, var(--warn)); }
.pair-key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--series-1, var(--brand)); vertical-align: middle; }
.pair-key.buy { background: var(--series-2, var(--warn)); }

/* closing the panel for a while: three plain boxes side by side */
.closing { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.closing-box { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin: 0; background: var(--surface); }
.closing-box h3 { margin: 0 0 8px; font-size: 14.5px; }
.closing-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.closing-row label { flex: 1 1 100%; font-size: 13px; color: var(--muted); }
.closing-row input { flex: 1 1 100px; min-width: 0; }

/* ---------- Phones: forms and buttons that are easy to reach and read ----------
   One thing per line, full width, tall enough for a thumb; nothing squeezed beside something else. */
@media (max-width: 700px) {
  /* text that is read on a phone held at arm's length: a little larger everywhere, explanations included */
  body { font-size: 15.5px; line-height: 1.9; }
  .small, .muted.small, .hint, small { font-size: 13.5px; line-height: 1.85; }
  p.muted, .card-body > p { line-height: 1.95; }
  h2 { font-size: 17px; }
  .badge { font-size: 12.5px; padding: 4px 10px; }
  .tile .label { font-size: 13.5px; }
  .tile .hint { font-size: 12.5px; }
  .card { border-radius: 16px; }
  .card + .card, section.card { margin-bottom: 14px; }
  .content { padding-bottom: 88px; }  /* the last button is never under the phone's own bar */
  a.small, .insight a { display: inline-block; padding-block: 6px; }
  /* 16px text in every field: smaller text makes a phone zoom the whole page when the field is touched */
  input:not([type=checkbox]):not([type=radio]), select, textarea { font-size: 16px; min-height: 46px; }
  textarea { min-height: 96px; }
  .btn, button.btn { min-height: 46px; padding-block: 10px; font-size: 15px; }
  .btn.small, button.small { min-height: 40px; padding: 8px 14px; font-size: 13.5px; }
  .linkish { min-height: 40px; padding: 8px 6px; }
  input[type=checkbox], input[type=radio] { width: 22px; height: 22px; flex: none; }
  label:has(> input[type=checkbox]), label:has(> input[type=radio]) { display: flex; align-items: center; gap: 10px; min-height: 40px; white-space: normal; }

  /* the title on its own line, the page's buttons under it in two equal columns */
  .page-head { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 8px; margin-bottom: 14px; }
  .page-head > h1, .page-head > h2, .page-head > .actions, .page-head > form, .page-head > div:not(.badge) { flex: 1 1 100%; min-width: 0; }
  .page-head .actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; width: 100%; margin: 0; }
  .page-head .actions > * { width: 100%; justify-content: center; text-align: center; margin: 0; }
  .page-head .actions > :only-child, .page-head .actions > .seg { grid-column: 1 / -1; }

  /* filters: a column, the search box first, the button last and full width */
  .filters { flex-direction: column; align-items: stretch; gap: 10px; padding: 14px 16px; }
  .filters > *, .filters input, .filters select, .filters .btn { width: 100% !important; min-width: 0 !important; max-width: none; flex: none !important; margin: 0; }
  .filters input[type=checkbox], .filters input[type=radio] { width: 22px !important; }
  .filters .seg, .filters .year-switch { width: 100% !important; }

  /* a small form placed beside something (save this filter, add a tag): on its own line, field then button */
  form.inline, form.nowrap { display: flex !important; flex-wrap: wrap; gap: 8px; width: 100%; margin: 0 !important; white-space: normal; }
  form.inline > input:not([type=hidden]):not([type=checkbox]), form.inline > select { flex: 1 1 160px; min-width: 0; }
  form.inline > .btn, form.inline > button { flex: 1 1 auto; justify-content: center; }
  /* the month calendars keep their small figures: seven days must fit across */
  .cal-day, .cal-day *, .cal-head, .calendar .cell, .calendar .cell *, .event, .hm-cell, .heatmap, .heatmap * { font-size: 10px; line-height: 1.5; }
  .cash-cal { gap: 3px; padding-inline: 8px; }
  .cal-day { overflow: hidden; padding: 4px 3px; min-width: 0; }
  .cal-day > * { overflow: hidden; white-space: nowrap; text-overflow: clip; max-width: 100%; }
  /* a label and its figure: the label above, the figure under it with the whole width to itself */
  .facts { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .facts dt { font-size: 13px; margin-top: 8px; }
  .facts dd, .facts dd * { overflow-wrap: anywhere; white-space: normal; }
  .hbar, .hbar-inline { min-width: 0; }
  .hbar .val, .hbar-inline .num { font-size: 12px; }
  /* the form's own buttons: full width, the main one first */
  .form-actions { flex-direction: column; align-items: stretch; gap: 10px; }
  .form-actions > * { width: 100%; justify-content: center; text-align: center; }
  .field { margin-bottom: 4px; }
  .field label { font-size: 13.5px; margin-bottom: 5px; }
  form[style*="grid"] { grid-template-columns: minmax(0, 1fr) !important; }

  /* a row of choices never breaks its words: it scrolls sideways instead */
  .seg { display: flex; width: 100%; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .seg::-webkit-scrollbar { display: none; }
  .seg a { flex: 1 0 auto; white-space: nowrap; text-align: center; padding: 11px 14px; font-size: 14px; }
  .tabs a { padding: 14px 14px 12px; font-size: 14.5px; }

  /* a table keeps its shape and is slid sideways, rather than breaking every name into one word per line */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; max-width: 100%; }
  /* whatever holds a table may be narrower than the table: the table slides, the page never does */
  .content, .content > *, .card, .card > form, .grid > *, .dash-grid > *, main form { min-width: 0; max-width: 100%; }
  html, body { overflow-x: hidden; }
  .table-wrap table { min-width: 640px; }
  .table-wrap td, .table-wrap th { white-space: nowrap; }
  .table-wrap td:nth-child(2), .table-wrap td.wrap { white-space: normal; min-width: 150px; }
  .table-wrap td .btn, .table-wrap td button { min-height: 38px; }

  /* a table of up to fourteen columns becomes a list of cards: one row per card, each figure beside its own label,
     nothing to slide sideways. (app.js writes each column's heading on its cells.) Wider tables still slide. */
  .table-wrap table.stack { min-width: 0; display: block; width: 100%; }
  table.stack thead { display: none; }
  table.stack tbody, table.stack tfoot, table.stack tr { display: block; width: 100%; }
  table.stack tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }
  table.stack tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
  table.stack td, table.stack tfoot th { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; padding: 4px 0; border: 0; white-space: normal; text-align: start; min-width: 0; overflow-wrap: anywhere; }
  table.stack td::before, table.stack tfoot th::before { content: attr(data-label); flex: none; max-width: 45%; color: var(--muted); font-size: 12.5px; font-weight: 500; }
  table.stack td:not([data-label])::before, table.stack td[data-label=""]::before { content: none; }
  table.stack td[data-label] > * { text-align: end; min-width: 0; }
  table.stack td, table.stack td.money, table.stack td.num { unicode-bidi: normal; direction: inherit; }
  table.stack td .v { unicode-bidi: plaintext; text-align: end; }
  table.stack td.lead { display: block; font-weight: 700; font-size: 15.5px; padding-bottom: 6px; line-height: 1.8; }
  table.stack td.lead .v { text-align: start; }
  /* a tick box or a "done" button with no heading sits beside the card's title, not on a line of its own */
  table.stack td[data-label=""]:first-child { float: inline-start; margin-inline-end: 12px; padding: 0; }
  table.stack tr::after { content: ''; display: block; clear: both; }
  table.stack td.lead::before { content: none; }
  table.stack td.lead > * { text-align: start; }
  table.stack td.bare { display: none; }
  table.stack td.empty, table.stack td[colspan] { display: block; text-align: center; }
  table.stack td.empty::before, table.stack td[colspan]::before { content: none; }
  table.stack td .btn, table.stack td button, table.stack td form { margin: 0; }
  table.stack td:has(> form), table.stack td:has(> .btn), table.stack td:has(> button) { justify-content: flex-start; flex-wrap: wrap; }
  .table-wrap table:not(.stack) td:nth-child(2), .table-wrap table:not(.stack) td:first-child { min-width: 150px; white-space: normal; }

  /* rows of a list: the text on top, its buttons under it */
  .list-row { flex-wrap: wrap; gap: 8px; padding-block: 12px; }
  .list-row .grow { flex: 1 1 190px; min-width: 0; }  /* a dot or a number stays beside the text; buttons go under it */
  .card-head { flex-wrap: wrap; gap: 6px 10px; }
  .card-head h2 { flex: 1 1 auto; }
  .card-head .right { margin-inline-start: 0; flex: 0 1 auto; max-width: 100%; }
  .card-head .badge { flex: none; }
  details > summary { min-height: 40px; display: flex; align-items: center; }
}

/* The side menu waits off-screen on a phone: past the right edge in a right-to-left language, past the left edge
   in a left-to-right one (it used to stand half over the page in English). */
@media (max-width: 760px) {
  [dir=ltr] .sidebar { transform: translateX(-105%); }
  [dir=ltr] body.nav-open .sidebar { transform: none; }
}

/* Long words of other languages on a phone: a day's name is cut to the width of its column, a long button
   breaks onto a second line, and a sentence in a list is allowed to wrap. */
@media (max-width: 700px) {
  .cal-head, .calendar .dow { overflow: hidden; white-space: nowrap; text-overflow: clip; }
  .btn, button.btn { white-space: normal; height: auto; text-align: center; line-height: 1.5; }
  .list-row .nowrap, .list-row span.small { white-space: normal; }
}

/* Charts are drawn once, for right-to-left reading: their labels are placed from that side. In a left-to-right
   language the same drawing is kept, so a label never ends up pushed out past the edge of its chart. */
svg.chart, svg.chart text { direction: rtl; }
svg.chart text { unicode-bidi: isolate; }
