:root {
  --bg: #f6f7f9;
  --fg: #1f2430;
  --muted: #6b7280;
  --card: #ffffff;
  --border: #e3e6ea;
  --accent: #2563eb;
  --danger: #dc2626;
  --th-bg: #fafbfc;
  --flash-bg: #ecfdf5;
  --flash-border: #6ee7b7;
  --flash-fg: #065f46;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --fg: #e5e7eb;
    --muted: #9ca3af;
    --card: #1e222b;
    --border: #343a46;
    --accent: #3b82f6;
    --danger: #f87171;
    --th-bg: #232833;
    --flash-bg: #0c2b22;
    --flash-border: #14724f;
    --flash-fg: #6ee7b7;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
}

/* Content links use the accent colour (both unvisited and visited) so they
   stay legible in both themes; without this they fall back to the browser
   default blue/purple, which is nearly unreadable against the dark
   background. Wrapped in :where() so this rule carries zero specificity and
   never overrides styled anchors (.brand, .button, .nav-links a), including
   their visited state. */
:where(a:link, a:visited) {
  color: var(--accent);
}

header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

nav {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  font-weight: 600;
  color: var(--fg);
  text-decoration: none;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nav-links a {
  color: var(--fg);
  text-decoration: none;
}

main {
  max-width: 960px;
  margin: 2rem auto;
  padding: 0 1rem;
}

h1 { font-size: 1.4rem; margin: 0 0 1rem; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
}

.narrow { max-width: 480px; margin: 0 auto; }

label { display: block; margin: 0.9rem 0 0.25rem; font-weight: 500; }

input[type="password"], input[type="date"], select {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: var(--card);
  color: var(--fg);
}

button, .button {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}

button.primary, .button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.link {
  border: none;
  background: none;
  margin: 0;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
}

button.link.danger { color: var(--danger); }

.card.actions { display: flex; align-items: center; gap: 1.25rem; }
.card.actions .button, .card.actions button { margin-top: 0; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

th, td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.95rem;
}

th { background: var(--th-bg); font-weight: 600; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.memo { color: var(--muted); max-width: 16rem; overflow-wrap: anywhere; }
/* fixed width: inside the scrollable mobile table the cell would otherwise
   squeeze the select down to a few pixels. Wide enough that the leading
   "Already <CUR>" stays visible when the option is collapsed. */
td.action select { width: 15rem; max-width: 100%; font-size: 0.85rem; }
/* action ≠ convert: the rate/converted columns won't be applied */
tr.no-convert td.fx { opacity: 0.45; text-decoration: line-through; }

.error { color: var(--danger); }
.hint { color: var(--muted); font-size: 0.9rem; }

dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1.25rem; margin: 0 0 1rem; }
dt { font-weight: 600; }
dd { margin: 0; }

tfoot td { background: var(--th-bg); font-weight: 600; border-top: 2px solid var(--border); }

.flash {
  background: var(--flash-bg);
  border: 1px solid var(--flash-border);
  color: var(--flash-fg);
  border-radius: 8px;
  padding: 0.75rem 1.25rem;
  margin-bottom: 1rem;
}

/* landing page */
.hero { text-align: center; padding: 2.5rem 0 1.5rem; }
.hero h1 { font-size: 2rem; line-height: 1.2; }
.lede { max-width: 40rem; margin: 0 auto 1rem; color: var(--muted); font-size: 1.05rem; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin: 1.5rem 0; }
.step h2, .card h2 { font-size: 1.05rem; margin: 0 0 0.5rem; }

/* small screens: primary usage is from a phone */
@media (max-width: 700px) {
  main { margin: 1rem auto; }
  .steps { grid-template-columns: 1fr; }
  .hero { padding: 1.5rem 0 0.5rem; }
  .hero h1 { font-size: 1.5rem; }
  /* the 8-column preview table: drop the memo column, let the rest scroll */
  th.memo, td.memo { display: none; }
  th, td { padding: 0.45rem 0.5rem; font-size: 0.85rem; }
  table { display: block; overflow-x: auto; }
  /* keep form controls at 16px: below that iOS Safari auto-zooms on focus */
  td.action select { font-size: 1rem; }
}

footer {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.5rem 1rem 1.5rem;
  text-align: center;
  font-size: 0.8rem;
}
footer .disclaimer {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
  max-width: 640px;
  margin: 0 auto 0.5rem;
  text-align: left;
}

.prose { max-width: 720px; margin: 0 auto; }
.prose h2 { margin-top: 1.5rem; }
.prose ul { padding-left: 1.25rem; }
.prose li { margin: 0.35rem 0; }
