:root {
  --purple: #534AB7;
  --gold: #C39A3F;
  --ink: #1e1b2e;
  --muted: #6b6680;
  --bg: #f7f6fb;
  --card: #ffffff;
  --border: #e5e2f0;
  --danger: #b3402a;
  --ok: #1f7a45;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.topbar {
  background: var(--purple);
  color: white;
  padding: 14px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.topbar .brand { color: white; text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.topbar .brand span { display: block; font-weight: 400; font-size: 0.75rem; opacity: 0.85; }
.topbar nav a { color: white; text-decoration: none; margin-left: 20px; font-size: 0.9rem; opacity: 0.9; }
.topbar nav a:hover { opacity: 1; text-decoration: underline; }

.container { max-width: 1000px; margin: 0 auto; padding: 28px 20px 60px; }

h1 { color: var(--purple); }
h2 { color: var(--purple); font-size: 1.15rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px;
  margin-bottom: 20px;
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; }

.btn {
  display: inline-block;
  background: var(--purple);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { opacity: 0.9; }
.btn.secondary { background: transparent; color: var(--purple); border: 1px solid var(--purple); }
.btn.gold { background: var(--gold); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 0.82rem; }

form label { display: block; margin: 12px 0 4px; font-size: 0.88rem; color: var(--muted); }
form input[type=text], form input[type=number], form input[type=date], form select, form textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.95rem;
}
form textarea { min-height: 80px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }

.year-selector { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.year-selector select { width: auto; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; }

.stat-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-tile {
  flex: 1; min-width: 150px;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 18px;
}
.stat-tile .label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-tile .value { font-size: 1.5rem; font-weight: 700; color: var(--purple); margin-top: 4px; }
.stat-tile.gold .value { color: var(--gold); }
.stat-tile.ok .value { color: var(--ok); }
.stat-tile.danger .value { color: var(--danger); }

.quarter-card {
  border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; margin-bottom: 12px;
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
}
.quarter-card .q-label { font-weight: 700; color: var(--purple); font-size: 1.05rem; }
.quarter-card .q-due { color: var(--muted); font-size: 0.82rem; }
.quarter-card .q-figures { display: flex; gap: 22px; flex-wrap: wrap; }
.quarter-card .q-figures div { text-align: right; }
.quarter-card .q-figures .label { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; }
.quarter-card .q-figures .val { font-weight: 600; }
.quarter-card.current { border-color: var(--gold); background: #fdf9f0; }

.tax-table th, .tax-table td { white-space: nowrap; }
.tax-table td .muted { font-size: 0.75rem; margin-top: 2px; }
.tax-table tbody tr.current { background: #fdf9f0; }
.tax-table tbody tr.current td { border-color: #eee0c0; }
.tax-table tfoot td { border-top: 2px solid var(--purple); border-bottom: none; font-weight: 700; padding-top: 12px; }

.quick-pay-form-compact { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.quick-pay-form-compact .muted { white-space: nowrap; }
.quick-pay-form-compact select, .quick-pay-form-compact input[type=number] { width: auto; padding: 7px 10px; }

.progress-track {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  height: 10px; overflow: hidden; margin-top: 6px;
}
.progress-fill { background: var(--purple); height: 100%; }
.progress-fill.ok { background: var(--ok); }
.progress-fill.gold { background: var(--gold); }
.progress-fill.danger { background: var(--danger); }

.tag {
  display: inline-block; background: #efedfb; color: var(--purple);
  padding: 2px 8px; border-radius: 12px; font-size: 0.78rem;
}

.muted { color: var(--muted); font-size: 0.85rem; }
.right { text-align: right; }
.empty { color: var(--muted); padding: 30px 0; text-align: center; }

.status-msg { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; font-size: 0.9rem; }
.status-msg.error { background: #fbe9e6; color: var(--danger); }
.status-msg.ok { background: #e9f7ee; color: var(--ok); }

.status-msg.warn { background: #fdf6ea; color: #5a4a1c; border: 1px solid var(--gold); }
.status-msg a { color: inherit; font-weight: 600; }
.status-msg form { display: inline; }

/* Count of imported transactions awaiting review, shown in the nav. */
.badge {
  display: inline-block; background: var(--gold); color: #3a2d06;
  border-radius: 10px; padding: 1px 7px; font-size: 0.75rem; font-weight: 700;
}

/* How sure the categoriser was about a suggestion. */
.tag.conf-high { background: #e9f7ee; color: var(--ok); }
.tag.conf-med { background: #fdf6ea; color: #5a4a1c; }
.tag.conf-low { background: #fbe9e6; color: var(--danger); }

/* Wide tables scroll inside their card rather than stretching the page. */
.table-scroll { overflow-x: auto; }

.bulk-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.bulk-actions form { display: inline; }

.row-actions { white-space: nowrap; }
.row-actions form { display: inline; }

.amount-in { color: var(--ok); font-weight: 600; }
.why-cell { max-width: 240px; }
.why-cell div { margin-top: 3px; }

label.checkline {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 0 4px; font-size: 0.9rem; color: var(--ink);
}
label.checkline input { width: auto; }

.footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 20px 0 40px; }

/* The nav menu button only exists on narrow screens; see the phone layer below. */
.nav-toggle, .nav-burger { display: none; }

/* Hosted version only. Sign out has to be a form (a POST), but it should sit in the
   nav looking like every other link rather than like a button. */
.topbar nav .nav-signout { display: inline; margin-left: 20px; }
.topbar nav .nav-signout button {
  background: none;
  border: none;
  padding: 0;
  color: white;
  font: inherit;
  font-size: 0.9rem;
  opacity: 0.9;
  cursor: pointer;
}
.topbar nav .nav-signout button:hover { opacity: 1; text-decoration: underline; }

/* Signed-out pages (sign in, accept invitation) are a single narrow column. */
.container.narrow { max-width: 460px; }

/* ------------------------------------------------------------------
   Phone and small-tablet layer.

   The tracker is used on a laptop most of the time, so these are
   adjustments on top of the desktop layout rather than a mobile-first
   rewrite. Two breakpoints: the nav runs out of room well before the
   content does.
   ------------------------------------------------------------------ */

/* --- Nav becomes a menu ------------------------------------------- */
@media (max-width: 900px) {
  .topbar { padding: 12px 16px; }
  .topbar .brand { font-size: 1rem; }

  /* Kept reachable by keyboard rather than display:none, so the menu can
     still be opened with the space bar. */
  .nav-toggle {
    display: block;
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0);
    white-space: nowrap; border: 0;
  }

  .nav-burger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
  }
  .nav-burger svg { width: 18px; height: 18px; fill: none; }
  .nav-toggle:focus-visible + .nav-burger { outline: 2px solid white; outline-offset: 2px; }

  .topbar nav { display: none; width: 100%; }
  .nav-toggle:checked ~ nav { display: block; padding-bottom: 4px; }

  .topbar nav a {
    display: block;
    margin-left: 0;
    padding: 11px 2px;
    font-size: 1rem;
    opacity: 1;
    border-top: 1px solid rgba(255, 255, 255, 0.18);
  }

  .topbar nav .nav-signout {
    display: block;
    margin-left: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.18);
  }
  .topbar nav .nav-signout button { padding: 11px 2px; font-size: 1rem; opacity: 1; }
}

/* --- Content ------------------------------------------------------- */
@media (max-width: 640px) {
  body { overflow-wrap: break-word; }

  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

  .container { padding: 18px 14px 44px; }
  .card { padding: 16px 14px; border-radius: 8px; margin-bottom: 14px; }
  h1 { font-size: 1.5rem; }

  .stat-row { gap: 10px; }
  .stat-tile { min-width: 130px; padding: 13px 14px; }
  .stat-tile .value { font-size: 1.3rem; }

  /* 16px keeps iOS from zooming the page in when a field is focused. */
  form input[type=text], form input[type=number], form input[type=date],
  form select, form textarea { font-size: 16px; padding: 11px 10px; }

  /* Comfortable thumb targets. */
  .btn { padding: 11px 18px; }
  .btn.small { padding: 8px 13px; font-size: 0.85rem; }
  .row-actions .btn.small { padding: 7px 11px; }

  /* Rows of controls that sit side by side on a laptop need to stack. */
  .quick-pay-form-compact { align-items: stretch; flex-direction: column; }
  .quick-pay-form-compact select,
  .quick-pay-form-compact input[type=number] { width: 100%; }
  .quick-pay-form-compact .btn { width: 100%; text-align: center; }

  .year-selector { flex-wrap: wrap; }

  /* Wide tables scroll sideways instead of stretching the page. Tables that
     are already inside a .table-scroll wrapper keep using it; the rest become
     their own scroll container, which avoids wrapping every table in markup. */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; min-width: 100%; }
  .table-scroll table { display: table; }
  th, td { padding: 9px 7px; }

  /* Hold the first column still while the rest scrolls, so a row stays
     identifiable once you've scrolled away from its date or name. */
  table tbody td:first-child,
  table thead th:first-child {
    position: sticky;
    left: 0;
    background: var(--card);
    z-index: 1;
    /* The first column is usually a date; letting "2026-06-18" break across
       two lines to save a few pixels reads worse than scrolling for them. */
    white-space: nowrap;
  }
  .tax-table tbody tr.current td:first-child { background: #fdf9f0; }

  /* The quarterly table is the one screen someone really wants on a phone,
     and the number they came for sits in the fifth column - too far to
     scroll for. So this one table becomes a card per quarter instead. */
  .tax-table, .tax-table tbody, .tax-table tfoot { display: block; overflow: visible; }
  .tax-table thead { display: none; }
  .tax-table tr {
    display: block;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px 12px 6px;
    margin-bottom: 10px;
  }
  .tax-table tbody tr.current { background: #fdf9f0; border-color: var(--gold); }
  .tax-table td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 14px;
    position: static;
    white-space: normal;
    text-align: right;
    padding: 8px 0;
    border-bottom: 1px dashed var(--border);
  }
  .tax-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    text-align: left;
    flex: none;
  }
  .tax-table td:last-child { border-bottom: none; }
  /* First cell is the card's heading, not a labelled row. */
  .tax-table td:first-child {
    display: block;
    text-align: left;
    font-size: 1.05rem;
    padding-top: 10px;
    border-bottom: 1px solid var(--border);
  }
  .tax-table td:first-child::before { content: none; }
  .tax-table tfoot td { border-top: none; padding-top: 8px; }
  .tax-table tfoot tr { border-color: var(--purple); }
}

@media print {
  .table-scroll { overflow-x: visible; }
}

@media print {
  .topbar, .no-print { display: none !important; }
  body { background: white; }
  .container { max-width: 100%; padding: 0; }
}
