/* Shared styles for every page: warm off-white, serif headings, flat surfaces. */
:root {
  --canvas: #faf7f0;
  --panel: #fdfbf6;
  --ink: #1b201d;
  --soft: #555d57;
  --control: #6b6f69;
  --hairline: #ddd9cd;

  /* The one accent colour. */
  --accent: #2c6b4f;
  --accent-ink: #ffffff;
  --accent-soft: #dceadf;

  /* Reserved for losses and input errors. */
  --loss: #8c2f25;
  --loss-soft: #f6dcd7;

  --serif: "Iowan Old Style", Charter, ui-serif, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

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

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  font: 1rem/1.6 var(--sans);
}

.wrap {
  width: 100%;
  max-width: 40rem;
  margin: 0 auto;
  padding: 0 1rem;
}

a { color: var(--accent); text-underline-offset: 3px; }

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

.skip-link {
  position: absolute;
  left: -999rem;
}
.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
  z-index: 1;
  padding: 0.5rem 1rem;
  background: var(--panel);
}

.site-header { border-bottom: 1px solid var(--hairline); }
.site-name {
  display: inline-flex;
  align-items: center;
  min-height: 3.25rem;
  color: var(--ink);
  font: 700 1.25rem/1.2 var(--serif);
  letter-spacing: -0.01em;
  text-decoration: none;
}

main { flex: 1; padding-bottom: 3rem; }

h1, h2, h3 { font-family: var(--serif); letter-spacing: -0.01em; }
h1 { font-size: clamp(1.625rem, 6.4vw, 2.25rem); line-height: 1.18; margin: 1.1rem 0 0.25rem; }
h2 { font-size: 1.45rem; line-height: 1.25; margin: 2.5rem 0 0.75rem; }
h3 { font-size: 1.15rem; line-height: 1.3; margin: 1.5rem 0 0.35rem; }
p { margin: 0 0 1rem; }
li + li { margin-top: 0.4rem; }

.lead { margin: 0 0 1rem; color: var(--soft); }

.card {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 18px;
  padding: 1rem;
}

/* Homepage tool list */
.tool-list {
  display: grid;
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.tool-list .card { position: relative; padding: 1.1rem 3rem 1.1rem 1.25rem; }
.tool-list .card:hover { border-color: var(--accent); }
.tool-list .card::after {
  content: "\203A" / "";
  position: absolute;
  right: 1.25rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  font-size: 1.75rem;
  font-weight: 700;
}
.tool-list li + li { margin-top: 0; }
.tool-list h3 { margin: 0; font-size: 1.3rem; }
.tool-list a { text-decoration: none; }
/* Makes the whole card clickable and shows the focus ring around it. */
.tool-list a::before { content: ""; position: absolute; inset: 0; border-radius: 18px; }
.tool-list a:focus-visible { outline: none; }
.tool-list a:focus-visible::before { outline: 3px solid var(--accent); outline-offset: 2px; }
.tool-list p { margin: 0.35rem 0 0; color: var(--soft); }

/* Calculator layout, intended for reuse */
.calculator { margin-bottom: 1rem; }
.fields { display: grid; gap: 0.6rem; }
@media (min-width: 34rem) {
  .calculator { padding: 1.5rem; }
  .fields { grid-template-columns: 1fr 1fr; gap: 1rem; }
  .field-wide { grid-column: 1 / -1; }
}

.field label { display: block; margin-bottom: 0.2rem; font-weight: 700; }
.field input {
  width: 100%;
  min-height: 3rem;
  padding: 0.5rem 0.85rem;
  border: 1.5px solid var(--control);
  border-radius: 12px;
  background: #ffffff;
  color: var(--ink);
  font: 600 1.25rem/1.3 var(--sans); /* 16px or more stops iOS zooming on focus */
  font-variant-numeric: tabular-nums;
}
.field input[aria-invalid="true"] { border: 2px solid var(--loss); }

.hint { margin: 0.2rem 0 0; color: var(--soft); font-size: 0.8rem; line-height: 1.35; }
.meaning { font-weight: 400; }

.error { margin: 0.25rem 0 0; color: var(--loss); font-size: 0.9rem; line-height: 1.4; }
.error:empty { display: none; }

/* Result panel: the first .result-primary is the headline, the others sit side by side. */
.result-panel {
  margin-top: 0.9rem;
  padding: 0.9rem 1.1rem;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  --panel-soft: var(--accent-soft);
}
.is-loss .result-panel { background: var(--loss); --panel-soft: var(--loss-soft); }

.results {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 1rem;
  margin: 0;
}
.result {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding-top: 0.6rem;
  border-top: 1px solid rgb(255 255 255 / 0.28);
}
.result dt { color: var(--panel-soft); font-size: 0.85rem; font-weight: 600; line-height: 1.4; }
/* On narrow screens "per item" gets its own line; the status line repeats it too. */
.unit { display: block; font-weight: 400; }
@media (min-width: 34rem) { .unit { display: inline; font-weight: inherit; } }
/* Keeps the two secondary values level when one label is taller. */
.result:not(.result-primary) dt { flex: 1; }
.result dd { margin: 0; overflow-wrap: anywhere; }
.value { font-size: 1.5rem; font-weight: 700; line-height: 1.35; font-variant-numeric: tabular-nums; }
.note { display: block; margin-bottom: 0.25rem; color: var(--panel-soft); font-size: 0.85rem; line-height: 1.4; }
.note:empty { display: none; }

/* For a lone secondary result. */
.result-wide { grid-column: 1 / -1; }

.result-primary {
  grid-column: 1 / -1;
  margin-bottom: 0.7rem;
  padding: 0 0 0.5rem;
  border-top: 0;
}
.result-primary dt { color: var(--accent-ink); font: 700 1.15rem/1.3 var(--serif); }
.result-primary .value { display: block; font-size: clamp(2.75rem, 15vw, 4.25rem); line-height: 1.1; letter-spacing: -0.02em; }
.result-primary .value.is-word { font-size: 2.25rem; line-height: 2; }

.status {
  margin: 0.6rem 0 0;
  padding-top: 0.6rem;
  border-top: 1px solid rgb(255 255 255 / 0.28);
  font-size: 0.95rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.calculator-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-top: 0.9rem;
}
.fine-print { flex: 1 1 14rem; margin: 0; color: var(--soft); font-size: 0.875rem; line-height: 1.45; }

.button {
  min-height: 2.75rem;
  padding: 0.5rem 1.5rem;
  border: 1.5px solid var(--accent);
  border-radius: 14px;
  background: transparent;
  color: var(--ink);
  font: 700 0.95rem var(--sans);
  cursor: pointer;
}
.button:hover { background: var(--accent-soft); }

/* Link to a related calculator, just below the tool. */
.related { font-weight: 700; }
.related a { display: inline-block; padding: 0.35rem 0; }

.formulas {
  padding: 0.9rem 1.1rem;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  list-style: none;
}

.notice { color: var(--loss); font-weight: 600; }

.site-footer {
  border-top: 1px solid var(--hairline);
  color: var(--soft);
  font-size: 0.9rem;
}
.site-footer p { margin: 1rem 0; }
.footer-links { display: flex; flex-wrap: wrap; gap: 0 1.5rem; }
.footer-links a { display: inline-block; padding: 0.5rem 0; }

/* Time card: one card per day, with the weekly total pinned to the bottom of the screen. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.day { min-width: 0; margin: 0 0 0.75rem; padding: 0.8rem 1rem; }
.day.is-flagged { border: 2px solid var(--loss); }
.day-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0 1rem; }
.day-head h2 { margin: 0 0 0.35rem; font-size: 1.2rem; }
.day-total { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.is-flagged .day-total, .is-flagged .day-note { color: var(--loss); }
.day-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem 0.75rem; }
.day-fields .field { min-width: 0; }
.day-fields input { padding: 0.4rem 0.6rem; font-size: 1.125rem; scroll-margin-bottom: 9rem; }
/*
 * iPhone browsers give native time boxes a width of their own, which can overflow a column.
 * Removing the native box styling makes them follow the column; tapping still opens the native picker.
 */
.day-fields input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 3rem;
}
/* On iPhone, keeps the chosen time left-aligned and an empty box from collapsing. */
.day-fields input[type="time"]::-webkit-date-and-time-value {
  min-height: 1.5em;
  margin: 0;
  text-align: left;
}
/* Very narrow screens: Start above End. */
@media (max-width: 22.4em) {
  .day-fields { grid-template-columns: minmax(0, 1fr); }
}
.field-break { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.field-break label { margin: 0; font-size: 0.95rem; }
.field-break input { width: 6rem; flex: none; }
@media (min-width: 34rem) {
  .day-fields { grid-template-columns: 1fr 1fr 1.2fr; align-items: end; }
  .field-break { grid-column: auto; display: block; }
  .field-break label { margin-bottom: 0.2rem; font-size: 1rem; }
  .field-break input { width: 100%; }
}
.day-note { margin: 0.4rem 0 0; font-size: 0.9rem; line-height: 1.4; }
.day-note:empty, .day-message:empty { display: none; }
.day-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; margin-top: 0.6rem; }
.day-actions .button, .day-actions .text-button { scroll-margin-bottom: 9rem; }
.day-message { margin: 0.5rem 0 0; color: var(--accent); font-size: 0.9rem; font-weight: 600; line-height: 1.4; }
.text-button {
  min-height: 2.75rem;
  padding: 0 0.25rem;
  border: 0;
  background: none;
  color: var(--accent);
  font: 600 0.95rem var(--sans);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.button-solid { background: var(--accent); color: var(--accent-ink); }
.button-solid:hover { background: var(--accent); }
.button:disabled { opacity: 0.55; cursor: default; }
.copy-panel { margin-top: 0.75rem; padding-top: 0.5rem; border-top: 1px solid var(--hairline); scroll-margin-bottom: 9rem; }
.copy-panel fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.copy-panel legend { padding: 0; font-weight: 700; }
.copy-choices { display: grid; }
.copy-choices label { display: flex; flex-wrap: wrap; align-items: center; gap: 0 0.5rem; min-height: 2.75rem; cursor: pointer; }
.copy-choices input { width: 1.35rem; height: 1.35rem; margin: 0; accent-color: var(--accent); scroll-margin-bottom: 9rem; }
.choice-note { color: var(--loss); font-size: 0.85rem; }

.week-total {
  position: sticky;
  bottom: 0;
  z-index: 2;
  margin: 0 -0.25rem;
  padding: 0.6rem 1rem 0.7rem;
  border-radius: 14px 14px 0 0;
  background: var(--accent);
  color: var(--accent-ink);
}
.is-unfinished .week-total { background: var(--loss); }
.week-total p { margin: 0; line-height: 1.35; }
.week-label { font: 700 1rem var(--serif); }
.week-hours { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 0.75rem; }
#week-time { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.week-decimal { font-weight: 600; }
.week-status { font-size: 0.875rem; }
/* On very short screens, such as with a keyboard open, let the total scroll with the page. */
@media (max-height: 420px) { .week-total { position: static; } }

/* FTE: reuses the time card's cards and pinned total, with a full-time week setting above. */
.standard-week { margin-bottom: 0.75rem; padding: 0.8rem 1rem; }
.field-inline { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.field-inline label { margin: 0; }
.field-inline input { width: 6rem; flex: none; scroll-margin-bottom: 11rem; }
/* Two equal boxes at every width that fits them, level even when one label wraps. */
.day-fields.pair-fields { align-items: end; }
@media (min-width: 34rem) { .day-fields.pair-fields { grid-template-columns: 1fr 1fr; } }
.pair-fields label { font-size: 0.95rem; line-height: 1.35; }
.group input, .group .button, .group .text-button { scroll-margin-bottom: 11rem; }
.group-actions { justify-content: flex-end; margin-top: 0.25rem; }
.group-actions[hidden] { display: none; }
.add-group .button { scroll-margin-bottom: 11rem; }
.add-group { margin-bottom: 0.75rem; }
.fte .fte-value { font-size: clamp(2.75rem, 13vw, 3.5rem); font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.fte-totals { font-weight: 600; font-variant-numeric: tabular-nums; column-gap: 1.25rem; }
.week-total .fte-totals { margin-bottom: 0.15rem; }

/* Electricity cost */
.rate-meaning { margin: 0.25rem 0 0; color: var(--accent); font-size: 0.9rem; font-weight: 600; line-height: 1.4; }
.rate-meaning:empty { display: none; }
.result-energy { margin-top: 0.6rem; }

/* Choice between the two profit margin modes. */
.modes { min-width: 0; margin: 0 0 0.75rem; padding: 0; border: 0; }
.modes legend { padding: 0; font-weight: 700; }
.modes label { display: flex; align-items: center; gap: 0.6rem; min-height: 2.75rem; cursor: pointer; }
.modes input { width: 1.25rem; height: 1.25rem; margin: 0; accent-color: var(--accent); }
.field[hidden], .result-panel[hidden] { display: none; }

/* Time duration: a long headline such as "23 h 59 min" has to fit a narrow phone. */
.duration-fields { margin-bottom: 0; }
.result-primary .value.is-time { font-size: clamp(2.25rem, 11vw, 3.5rem); }
/* On very narrow screens the two smaller results stack, so a time isn't split over two lines. */
@media (max-width: 22.4em) {
  #duration .results { grid-template-columns: minmax(0, 1fr); row-gap: 0.6rem; }
}

/* Windows high-contrast mode drops backgrounds, so keep the panel outlined. */
@media (forced-colors: active) {
  .result-panel, .week-total { border: 2px solid; }
}
