/*
 * The one layout. There is no separate mobile site: the same markup runs from
 * a ~360px phone up to a wide desktop, reflowing at two breakpoints.
 *
 * Every value with a *decision* in it -- colour, spacing, radius, type,
 * shadow, motion -- comes from src/theme.css. This file is shapes and
 * arrangement. Three rules that later cards need to keep to:
 *
 *  1. No literal colour in here. Not a hex, not an rgb(), not a named
 *     colour. If a screen needs one it belongs in the theme, where its
 *     contrast gets checked.
 *  2. Every interactive thing is at least --tap tall and wide (44px). This is
 *     a calculator you use standing in a car park holding a dog lead.
 *  3. Nothing is hover-only. A :hover rule always has a :focus-visible twin,
 *     and hover never reveals content or controls -- on a touch screen there
 *     is no hover, and the first tap would have to be spent summoning it.
 *
 * test/styles.test.js and test/theme.test.js enforce all three.
 */

/* ---------- reset ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: var(--text-base) / var(--leading) var(--font);
  /* Room for the tab bar, which is fixed to the bottom on phones. */
  padding-bottom: calc(var(--tap) + var(--space-5) + env(safe-area-inset-bottom, 0px));
}

h1, h2, h3, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/*
 * The blunt instrument, kept alongside the theme's zeroed --dur tokens: this
 * catches anything that set its own duration, the tokens catch anything that
 * builds a transition out of them. Neither is enough on its own.
 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}

/* <main> takes focus on navigation, so it must not draw a ring for that. */
main:focus { outline: none; }

/* ---------- shell ---------- */

.wrap {
  width: 100%;
  max-width: var(--page);
  margin: 0 auto;
  padding: 0 var(--space-4);
}

.app-header {
  padding: var(--space-5) 0 var(--space-4);
}

/* The title and the language switch share a line; the subtitle runs full
   width under both. */
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-1);
}

.app-header h1 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  /* So a long title shrinks rather than shoving the switch off a 360px
     phone: a flex item will not go below its content width without this. */
  min-width: 0;
  font-size: var(--text-title);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-title);
  line-height: var(--leading-tight);
}

.app-header .sub {
  color: var(--muted);
  font-size: var(--text-md);
  max-width: 38rem;
}

/*
 * The language switch: a two-up segmented control, drawn by src/app.js from
 * the locales it has loaded. Both options stay on screen, so changing
 * language is one tap and reading which one you are in costs none -- a menu
 * would charge a tap for each. Sized from --tap like every other control,
 * because this one gets used with a dog lead in the other hand too.
 */
.lang-switch {
  flex: none;
  display: flex;
  gap: var(--space-1);
  padding: var(--space-1);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
}

.lang-btn {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-label);
  cursor: pointer;
  transition:
    color var(--dur-fast) var(--ease),
    background-color var(--dur-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}

/* aria-pressed is the state, and it is what the styling hangs off: there is
   no second class to forget to keep in step with it. */
.lang-btn[aria-pressed='true'] {
  background: var(--accent-soft);
  color: var(--accent-soft-ink);
}

.lang-btn:hover,
.lang-btn:focus-visible { background: var(--accent-soft); color: var(--ink); }

.app-footer {
  color: var(--muted);
  font-size: var(--text-sm);
  text-align: center;
  padding: var(--space-6) 0 var(--space-4);
}

/*
 * The tab bar. On a phone it is pinned to the bottom, where a thumb already
 * is; from tablet up it moves inline under the header and becomes a
 * segmented control. Same markup, same anchors, both times.
 */
.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-1) 0;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tab {
  flex: 1 1 0;
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-1);
  border-radius: var(--radius) var(--radius) var(--radius-xs) var(--radius-xs);
  color: var(--muted);
  text-decoration: none;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: .01em;
  transition:
    color var(--dur-fast) var(--ease),
    background-color var(--dur-fast) var(--ease);
  /* Kill the grey flash Android paints over a tapped link. */
  -webkit-tap-highlight-color: transparent;
}

.tab svg {
  width: 1.35rem;
  height: 1.35rem;
  display: block;
  transition: transform var(--dur) var(--ease-bounce);
}

.tab[aria-current='page'] {
  color: var(--accent-soft-ink);
  background: var(--accent-soft);
}

/* The icon leans in a little on the screen you are on. Purely a nicety, and
   the colour above carries the meaning on its own. */
.tab[aria-current='page'] svg { transform: translateY(-1px) scale(1.08); }

.tab:hover,
.tab:focus-visible { color: var(--ink); background: var(--accent-soft); }

.tab:focus-visible { outline-offset: -3px; }

.tab:active { background: var(--accent-soft); }

/* ---------- content columns ---------- */

.columns { display: grid; gap: var(--gap); }

/* ---------- card ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--gap);
  box-shadow: var(--shadow);
}

.card > h2 {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--muted);
  font-weight: var(--weight-bold);
  margin-bottom: var(--space-3);
}

.card > h2 + .lede { margin-top: calc(var(--space-2) * -1); margin-bottom: var(--space-3); }

.lede { color: var(--muted); font-size: var(--text-md); }

/* ---------- form controls ---------- */

.grid { display: grid; grid-template-columns: 1fr; gap: var(--gap); }

.field > label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-1);
}

input[type='date'],
input[type='number'],
input[type='text'],
select {
  width: 100%;
  min-height: var(--tap);
  padding: var(--space-2) var(--space-3);
  font-family: inherit;
  /* --text-base is exactly 1rem, and has to stay there: anything smaller and
     iOS Safari zooms the page when you focus the field. */
  font-size: var(--text-base);
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  appearance: none;
  -webkit-appearance: none;
  transition:
    border-color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}

select {
  /* Leave room for the caret we draw ourselves, since appearance is off. */
  padding-right: var(--space-6);
  background-image: var(--icon-caret);
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: .7rem;
}

input:hover,
select:hover,
input:focus-visible,
select:focus-visible { border-color: var(--accent); }

.hint { font-size: var(--text-sm); color: var(--muted); margin-top: var(--space-1); }

/*
 * Checkbox rows. The whole row is the target, not the 13px box the browser
 * draws, so it clears --tap in both directions.
 */
.checks { display: grid; gap: var(--space-1); margin-top: var(--space-4); }

.checks label {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  min-height: var(--tap);
  padding: var(--space-1) var(--space-2);
  margin: 0 calc(var(--space-2) * -1);
  border-radius: var(--radius-sm);
  font-size: var(--text-md);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.checks input[type='checkbox'] {
  flex: none;
  width: 1.4rem;
  height: 1.4rem;
  margin: 0;
  accent-color: var(--accent);
}

.checks label:hover,
.checks label:focus-within { background: var(--accent-soft); }

/* ---------- the number ---------- */

/*
 * The one place a paw is more than punctuation: a single large print in the
 * corner of the card that holds the answer. It is the identity's signature,
 * and it appears once per screen. Resist adding a second.
 */
.total-card {
  position: relative;
  background-color: var(--accent);
  background-image: var(--icon-paw-quiet);
  background-repeat: no-repeat;
  background-position: right -1.2rem bottom -1.6rem;
  background-size: 8rem;
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow-lift);
  overflow: hidden;
}

.total-card > h2 { color: var(--accent-ink-soft); }

.total {
  font-size: var(--text-total);
  font-weight: var(--weight-bold);
  line-height: 1;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  /* Grows from the left so the digits do not slide about while it settles. */
  transform-origin: left center;
}

/*
 * A short nod when the number changes, so a total that moved while you were
 * looking at the form does not change in silence. Added by the view on a
 * change only, never on first paint, and flattened by the reduced-motion
 * rule at the top of this file.
 */
@keyframes total-bump {
  0% { transform: scale(1); }
  45% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.total.is-bumped { animation: total-bump 400ms var(--ease-bounce); }

.total-sub { margin-top: var(--space-2); font-size: var(--text-md); color: var(--accent-ink-soft); }

/* ---------- tables ---------- */

table { width: 100%; border-collapse: collapse; font-size: var(--text-md); }

td { padding: var(--space-2) 0; border-bottom: 1px solid var(--line); vertical-align: top; }

td.amt {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  padding-left: var(--space-4);
}

tr:last-child td { border-bottom: 0; }

tr.sum td {
  font-weight: var(--weight-bold);
  border-top: 2px solid var(--ink);
  border-bottom: 0;
  padding-top: var(--space-3);
}

.det { display: block; color: var(--muted); font-size: var(--text-sm); }

/* ---------- notes ---------- */

ul.notes { list-style: none; display: grid; gap: var(--space-2); }

ul.notes li {
  background: var(--warn-bg);
  border-left: 3px solid var(--warn);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-xs) var(--radius-sm) var(--radius-sm) var(--radius-xs);
  font-size: var(--text-md);
  color: var(--warn);
}

ul.notes li.err { background: var(--err-bg); border-left-color: var(--err); color: var(--err); }

/* ---------- disclosure ---------- */

details { border-top: 1px solid var(--line); margin-top: var(--space-4); }

summary {
  min-height: var(--tap);
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--muted);
  transition: color var(--dur-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}

summary:hover,
summary:focus-visible { color: var(--ink); }

details ol { font-size: var(--text-sm); color: var(--muted); padding-left: var(--space-5); margin-bottom: var(--space-3); }
details li { margin-bottom: var(--space-2); }
details b { color: var(--ink); font-weight: var(--weight-semibold); }

/* ---------- placeholder for screens later cards will fill in ---------- */

.stub {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  color: var(--muted);
  font-size: var(--text-md);
}

.stub > * + * { margin-top: var(--space-3); }
.stub h3 { font-size: var(--text-md); color: var(--ink); font-weight: var(--weight-semibold); }
.stub .paw-list { display: grid; gap: var(--space-2); }

/* ---------- 640px: two columns inside a card, room for the tabs on top ---------- */

@media (min-width: 40rem) {
  .grid { grid-template-columns: 1fr 1fr; }
  .card { padding: var(--space-5); }
}

@media (min-width: 48rem) {
  body { padding-bottom: 0; }

  .tabs {
    position: static;
    max-width: var(--page);
    margin: 0 auto var(--space-5);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: var(--space-1);
    gap: var(--space-1);
    box-shadow: var(--shadow);
  }

  .tab {
    flex-direction: row;
    gap: var(--space-2);
    font-size: var(--text-md);
    border-radius: var(--radius);
  }

  .tab[aria-current='page'] { background: var(--accent); color: var(--accent-ink); }

  .tab[aria-current='page']:hover,
  .tab[aria-current='page']:focus-visible { background: var(--accent); color: var(--accent-ink); }
}

/* ---------- 1024px: the answer sits beside the form instead of under it ---------- */

@media (min-width: 64rem) {
  :root { --page: 68rem; }

  /*
   * Form on the left, everything derived from it on the right. The form is
   * the sticky one: you scroll the breakdown while still seeing the dates
   * that produced it.
   */
  .columns {
    grid-template-columns: minmax(0, 21rem) minmax(0, 1fr);
    align-items: start;
    gap: var(--space-5);
  }

  .col-main { position: sticky; top: var(--space-4); }

  /*
   * The form column is deliberately narrow, and two fields across it leaves
   * the slot selects too tight to read their own labels. Stack them.
   */
  .col-main .grid { grid-template-columns: 1fr; }

  .col-main .card:last-child,
  .col-side .card:last-child { margin-bottom: 0; }

  /* The tab bar should not stretch to the full desk-wide column. */
  .tabs { max-width: 30rem; margin-left: 0; }
}
