/* ==========================================================================
   The home experience, the Direct Debit control centre and payment runs.

   Design intent, in the code rather than only in a document:

   - The position is TYPE. Four figures in the display serif, on the page
     ground, separated by rules. A balance does not need a box drawn round it
     to be important, and putting one there makes it look like a widget.
   - Attention is a LIST with the action visible. Empty most days.
   - The timeline is a TABLE. Business users read tables faster than cards,
     and a fortnight of money fits on one screen this way.
   - No gradients, no glass, no glow, no shadow doing hierarchy's job. The
     only accent is brass, and it appears where money or action does.
   ========================================================================== */

.stack-lg { display: flex; flex-direction: column; gap: var(--s-8); }

/* --------------------------------------------------------------------------
   The position — four numbers, no cards
   -------------------------------------------------------------------------- */
.position { padding-block: var(--s-2) var(--s-4); }

.position-figures {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.figure {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  align-items: flex-start;
  text-align: left;
  padding: var(--s-5) var(--s-5) var(--s-5) 0;
  background: none;
  border: 0;
  border-right: 1px solid var(--border);
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: background-color 120ms ease;
}
.figure:last-child { border-right: 0; }
.figure:not(:first-child) { padding-left: var(--s-5); }
.figure:hover { background: var(--surface-sunken); }
.figure:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.figure-label {
  font-size: var(--step--1);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.figure-amount {
  font-family: var(--font-display);
  font-size: var(--step-4);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.figure-lead .figure-amount { color: var(--accent); }

.figure-foot {
  display: flex;
  gap: var(--s-2);
  align-items: center;
  font-size: var(--step--1);
  min-height: 1.4em;
}

.position-note {
  margin-top: var(--s-3);
  color: var(--text-muted);
  font-size: var(--step--1);
  max-width: 62ch;
}

/* --------------------------------------------------------------------------
   Tags — small, quiet, meaningful
   -------------------------------------------------------------------------- */
.tag {
  display: inline-block;
  font-size: var(--step--2);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.15em 0.5em;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  white-space: nowrap;
}
.tag-estimate { border-color: var(--caution-400); color: var(--caution-600); }
.tag-fact { border-color: var(--positive-400); color: var(--positive-600); }
.tag-overdue { border-color: var(--critical-400); color: var(--critical-600); }
.tag-notified,
.tag-committed,
.tag-scheduled { border-color: var(--border-strong); }
.tag-guarded { border-color: var(--info-400); color: var(--info-600); }

/* --------------------------------------------------------------------------
   Cash-flow warning — serious, not decorative
   -------------------------------------------------------------------------- */
.shock {
  border-left: 3px solid var(--caution-400);
  padding: var(--s-4) var(--s-5);
  background: var(--caution-100);
}
[data-theme="dark"] .shock { background: transparent; }

.shock-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}
.shock-head h2 { font-size: var(--step-1); margin: 0; }
.shock-head svg { color: var(--caution-600); flex: none; }

.shock-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--s-5);
}
.shock-body h4 {
  font-size: var(--step--1);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 var(--s-2);
}
.driver-list { list-style: none; margin: 0; padding: 0; }
.driver-list li {
  display: flex;
  justify-content: space-between;
  gap: var(--s-4);
  padding: 0.3em 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--step--1);
}
.driver-list .num { font-variant-numeric: tabular-nums; }
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: 0.3em 0; font-size: var(--step--1); }

.shock-note {
  margin-top: var(--s-4);
  font-size: var(--step--2);
  color: var(--text-muted);
  max-width: 70ch;
}

/* --------------------------------------------------------------------------
   Attention — a list, ordered by how much it matters
   -------------------------------------------------------------------------- */
.attention h2 { font-size: var(--step-2); margin: 0 0 var(--s-4); }

.attention-clear {
  border-top: 1px solid var(--border);
  padding-top: var(--s-5);
}
.attention-clear h2 { color: var(--text-muted); font-weight: 400; }

.attention-group { margin-bottom: var(--s-5); }
.attention-group h3 {
  font-size: var(--step--1);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 var(--s-2);
  font-weight: 600;
}

.attention-items { list-style: none; margin: 0; padding: 0; }

.attention-item {
  display: flex;
  gap: var(--s-5);
  align-items: flex-start;
  padding: var(--s-4) 0 var(--s-4) var(--s-4);
  border-top: 1px solid var(--border);
  border-left: 2px solid transparent;
}
.attention-items li:last-child { border-bottom: 1px solid var(--border); }

.sev-critical .attention-item { border-left-color: var(--critical-400); }
.sev-important .attention-item { border-left-color: var(--caution-400); }
.sev-worth_knowing .attention-item { border-left-color: var(--border-strong); }

.attention-main { flex: 1; min-width: 0; }
.attention-headline { font-weight: 600; }
.attention-detail {
  color: var(--text-muted);
  font-size: var(--step--1);
  margin-top: 0.2em;
}
.attention-action {
  font-size: var(--step--1);
  margin-top: 0.4em;
}

.attention-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--s-2);
  flex: none;
}
.attention-amount {
  font-family: var(--font-display);
  font-size: var(--step-1);
  font-variant-numeric: tabular-nums;
}

.link-button {
  background: none;
  border: 0;
  border-bottom: 1px solid var(--accent);
  color: var(--accent);
  padding: 0 0 1px;
  font: inherit;
  font-size: var(--step--1);
  cursor: pointer;
}
.link-button:hover { border-bottom-width: 2px; }

/* --------------------------------------------------------------------------
   Timeline — a table, because that is what it is
   -------------------------------------------------------------------------- */
.timeline .section-head {
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
  margin-bottom: var(--s-3);
}
.timeline h2 { font-size: var(--step-2); margin: 0; }

.timeline-table { width: 100%; }
.timeline-table td, .timeline-table th { vertical-align: top; }

.day-row th {
  padding-top: var(--s-4);
  padding-bottom: var(--s-1);
  border-bottom: 1px solid var(--border-strong);
  text-align: left;
  font-size: var(--step--1);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}
.day-row.is-today th { color: var(--accent); }
.day-row.is-past th { opacity: 0.7; }
.day-net {
  float: right;
  font-variant-numeric: tabular-nums;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  font-weight: 400;
}

.event-row td { padding-block: 0.45em; font-size: var(--step-0); }
.event-dir { width: 1.6em; }
.dir { font-size: var(--step-0); }
.dir-in { color: var(--positive-600); }
.dir-out { color: var(--text-muted); }
.event-certainty { width: 9em; }

.data .num { text-align: right; font-variant-numeric: tabular-nums; }
.data .strong { font-weight: 600; }
.data.compare th[scope="row"] {
  text-align: left;
  font-weight: 600;
  width: 16em;
}

/* --------------------------------------------------------------------------
   Explain panel — every number can be taken apart
   -------------------------------------------------------------------------- */
.explain {
  position: fixed;
  inset-block: 0;
  inset-inline-end: 0;
  width: min(560px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border-strong);
  padding: var(--s-6);
  overflow-y: auto;
  z-index: 60;
}

.explain-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-bottom: var(--s-2);
}
.explain-head h3 {
  margin: 0;
  font-size: var(--step-2);
  text-transform: capitalize;
}
.explain-head .icon-button { margin-left: auto; }

.explain-sum {
  color: var(--text-muted);
  font-size: var(--step--1);
  margin: 0 0 var(--s-5);
}

.explain-table { width: 100%; margin-bottom: var(--s-5); }
.explain-table tfoot td {
  border-top: 2px solid var(--border-strong);
  padding-top: var(--s-3);
  font-family: var(--font-display);
  font-size: var(--step-1);
}

.explain-excluded h4 {
  font-size: var(--step--1);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 var(--s-2);
}
.explain-excluded ul { margin: 0 0 var(--s-4); padding-left: 1.1em; }
.explain-excluded li { font-size: var(--step--1); margin-bottom: 0.4em; }

.explain-gap,
.explain-trust {
  font-size: var(--step--1);
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: var(--s-3);
  margin: 0;
}

/* --------------------------------------------------------------------------
   Density: desktop is information-rich, mobile is prioritised.
   Not the same layout at two sizes.
   -------------------------------------------------------------------------- */
@media (max-width: 1080px) {
  .position-figures { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .figure:nth-child(2) { border-right: 0; }
  .figure:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
  .figure:nth-child(3) { padding-left: 0; }
}

@media (max-width: 780px) {
  .position-figures {
    grid-template-columns: 1fr;
    border-bottom: 0;
  }
  .figure {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: var(--s-4) 0;
    flex-direction: row;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
  }
  .figure:not(:first-child) { padding-left: 0; }
  /* On mobile the lead figure keeps its size; the rest step down, because a
     phone screen cannot carry four equal headlines. */
  .figure-amount { font-size: var(--step-2); }
  .figure-lead .figure-amount { font-size: var(--step-3); }
  .figure-foot { flex-basis: 100%; }

  .attention-item { flex-direction: column; gap: var(--s-2); }
  .attention-side { flex-direction: row; align-items: baseline; }

  .event-certainty { display: none; }
  .explain { width: 100vw; }
}

/* ==========================================================================
   Position: one figure leads
   --------------------------------------------------------------------------
   Replaces the four-column equal-weight grid. The hero is the answer; the
   three below are the working. The rule between them is the only decoration,
   and it is doing a job — separating a conclusion from its arithmetic.
   ========================================================================== */
.figure-hero {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--s-6) 0 var(--s-5);
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.figure-hero .label { display: block; margin-bottom: var(--s-3); }
.figure-hero .money { display: block; }
.figure-hero:hover .money-whole { color: var(--accent); }
.figure-hero:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }

.figure-hero-note {
  display: block;
  margin-top: var(--s-3);
  font-size: var(--step--1);
  color: var(--text-muted);
}

.position-supporting {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-bottom: 1px solid var(--border);
}
.position-supporting .figure {
  padding: var(--s-4) var(--s-5) var(--s-4) 0;
  gap: var(--s-2);
}
.position-supporting .figure:last-child { border-right: 0; }

@media (max-width: 720px) {
  .position-supporting { grid-template-columns: 1fr; }
  .position-supporting .figure {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: var(--s-3) 0;
    flex-direction: row;
    align-items: baseline;
    justify-content: space-between;
  }
  .position-supporting .figure:last-child { border-bottom: 0; }
}
