:root {
  --bg: #f6f5f1; --surface: #ffffff; --ink: #1c2430; --muted: #667085; --line: #e2dfd6;
  --accent: #1f3a5f; --accent-ink: #ffffff; --good: #1d7a4f; --warn: #a15c00; --bad: #b3261e;
  --radius: 10px; --gap: 16px;
  --series: #2a78d6; --flag-edge: rgba(16, 24, 40, 0.14);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12161c; --surface: #1b212a; --ink: #e8ebf0; --muted: #98a2b3; --line: #2c3440;
          --accent: #8fb4e3; --accent-ink: #10151b; --good: #5cc796; --warn: #e3a857; --bad: #f2867f;
          --series: #3987e5; --flag-edge: rgba(255, 255, 255, 0.16); }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45;
       padding-bottom: env(safe-area-inset-bottom); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 var(--gap); }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

header.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
             padding-top: env(safe-area-inset-top); }
header.top nav { display: flex; gap: 4px; align-items: center; max-width: 1200px; margin: 0 auto; padding: 8px 16px;
                 overflow-x: auto; scrollbar-width: none; }
header.top a { padding: 6px 10px; border-radius: 8px; color: var(--ink); white-space: nowrap; }
header.top a.on { background: var(--accent); color: var(--accent-ink); }
header.top .spacer { flex: 1; }
header.top form { margin: 0; }

main { max-width: 1200px; margin: 0 auto; padding: var(--gap); }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--gap); min-width: 0; }
.card.span { grid-column: 1 / -1; }
.stats { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: var(--gap); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px var(--gap); }
.stat b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 0.85rem; }

.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 600; border-top: 2px solid var(--line); }
td.nowrap { white-space: nowrap; }
@media (max-width: 720px) { .wide { display: none; } }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: var(--gap); align-items: center; }
.tabs a { padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); }
.tabs a.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tabs .spacer { flex: 1; }

.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.78rem; border: 1px solid var(--line); white-space: nowrap; }
.tag.good { color: var(--good); border-color: var(--good); }
.tag.warn { color: var(--warn); border-color: var(--warn); }
.tag.bad { color: var(--bad); border-color: var(--bad); }
.struck { text-decoration: line-through; color: var(--muted); }

button, .button { font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--accent);
                  background: var(--accent); color: var(--accent-ink); cursor: pointer; display: inline-block; }
button.plain, .button.plain { background: transparent; color: var(--accent); }
button.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
button:disabled { opacity: 0.6; cursor: default; }
.button:hover { text-decoration: none; }

form.fields { display: grid; gap: 12px var(--gap); grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
form.fields .full { grid-column: 1 / -1; }
label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 3px; }
input, select, textarea { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
                          background: var(--surface); color: var(--ink); }
input[type=checkbox] { width: auto; margin-right: 6px; }
.check label { display: inline; font-size: inherit; color: var(--ink); }
.errorlist { color: var(--bad); margin: 4px 0 0; padding: 0; list-style: none; font-size: 0.85rem; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
form.quick { display: grid; gap: 10px; grid-template-columns: 2fr 1fr 1fr; }
form.quick .full { grid-column: 1 / -1; }
@media (max-width: 520px) { form.quick { grid-template-columns: 1fr 1fr; } form.quick .task { grid-column: 1 / -1; } }

.messages { list-style: none; padding: 0; margin: 0 0 var(--gap); }
.messages li { padding: 10px 14px; border-radius: 8px; background: var(--surface); border: 1px solid var(--good); color: var(--good); }
.messages li.error { border-color: var(--bad); color: var(--bad); }
.chart { position: relative; height: 280px; }
.chart.tall { height: 420px; }
.signin { max-width: 380px; margin: 12vh auto; text-align: center; }
.signin .card { padding: 32px 24px; }
#passkey-status { color: var(--bad); min-height: 1.4em; margin-top: 12px; }
pre.notes { white-space: pre-wrap; font: inherit; margin: 0; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 8px 0; border-bottom: 1px solid var(--line); }
ul.plain li:last-child { border-bottom: 0; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); }
/* Tables that turn into a list of stacked entries on a phone. */
@media (max-width: 720px) {
  table.stack thead { display: none; }
  table.stack tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack td, table.stack td.wide { display: block; border: 0; padding: 2px 0; white-space: normal; }
  table.stack td:empty { display: none; }
  table.stack td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 0.82rem; }
}

/* Billing timesheet */
.timesheet input { width: 4.2em; text-align: right; padding: 6px; }
.timesheet th.today { color: var(--accent); }
.timesheet .small { font-size: 0.75rem; }
th a.sort { color: inherit; text-decoration: none; }
th a.sort:hover { text-decoration: underline; }

/* Currencies */
.fx-source { margin-top: -6px; }
.fxgrid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); margin-bottom: var(--gap); }
.fxcard { display: flex; flex-direction: column; gap: 6px; background: var(--surface); border: 1px solid var(--line);
          border-radius: var(--radius); padding: 14px var(--gap); color: var(--ink); text-decoration: none;
          transition: border-color 0.15s, transform 0.15s; }
.fxcard:hover { border-color: var(--accent); transform: translateY(-2px); text-decoration: none; }
.fxcard.manual { border-style: dashed; }
.fxhead { display: flex; gap: 10px; align-items: center; line-height: 1.25; }
.fxrate { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 4px; }
.fxrate small { font-size: 0.9rem; font-weight: 600; color: var(--muted); }
.fxmoves { display: flex; gap: 6px; flex-wrap: wrap; }
.spark { width: 100%; height: 32px; }
.spark polyline { fill: none; stroke-width: 1.8; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.spark polyline { stroke: var(--muted); }
.spark.up polyline { stroke: var(--good); }
.spark.down polyline { stroke: var(--bad); }
.stat b.up { color: var(--good); }
.stat b.down { color: var(--bad); }
.small { font-size: 0.8rem; }
.fx-range-stats { margin: var(--gap) 0 0; }
.fx-extremes { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-bottom: 12px; }
.fx-extreme { display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; border: 1px solid var(--line);
              border-left-width: 4px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.fx-extreme:hover { border-color: var(--accent); text-decoration: none; }
.fx-extreme.good { border-left-color: var(--good); }
.fx-extreme.bad { border-left-color: var(--bad); }
.fx-extreme b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.fx-bookings { max-height: 520px; overflow-y: auto; }

/* Flags: real SVGs as small rounded chips, with a hairline edge so white flags keep their shape */
.flag { display: inline-block; flex: none; object-fit: cover; vertical-align: middle; border-radius: 3px;
        outline: 1px solid var(--flag-edge); outline-offset: -1px; }
.flag-md { width: 20px; height: 15px; }
.flag-lg { width: 32px; height: 24px; border-radius: 4px; }
.flag-none { background: var(--line); }

/* Ranked bars: one hue, largest first, value at the tip */
.rank-card { margin-bottom: var(--gap); }
.rank-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.rank-head h2 { margin: 0; }
.rank-head .muted { font-size: 0.85rem; }
.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.rank-row { display: grid; grid-template-columns: minmax(9rem, 13rem) 1fr; align-items: center; gap: 14px;
            padding: 7px 10px; margin: 0 -10px; border-radius: 8px; transition: background 0.12s; }
.rank-row:hover { background: color-mix(in srgb, var(--series) 9%, transparent); }
.rank-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.rank-name > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-track { display: flex; align-items: center; gap: 10px; min-width: 0; }
/* The longest bar fills the track less the room its label needs; the rest keep their exact proportions. */
.rank-bar { flex: none; height: 12px; width: calc((100% - 7.5rem) * var(--fraction, 1)); min-width: 3px;
            border-radius: 0 4px 4px 0; background: var(--series); }
.rank-value { font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 0.92rem; }
.rank-value b { font-weight: 600; }
@media (max-width: 560px) {  /* stack: name on one line, a full-width bar beneath */
  .rank-row { grid-template-columns: 1fr; gap: 6px; padding: 8px 10px; }
}
.points-icon { outline: none; color: var(--muted); }
.fx-title { display: flex; align-items: center; gap: 12px; }
.fx-title .muted { font-weight: 500; }
.kind { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 999px; font-size: 0.72rem;
        color: var(--muted); border: 1px solid var(--line); vertical-align: 1px; }
