/*
 * "Iron Ledger" — a gym-logbook identity, not a generic light-blue app
 * skin: warm iron/chalk neutrals, a single brass accent (the same hue as
 * the pr-badge always used), numbers set in a monospace face like entries
 * in a paper training log. No framework, no build step (Propshaft).
 * Priority: usable on a phone in the gym — big touch targets, single
 * column, readable at arm's length.
 */

:root {
  --bg: #f7f2e7;
  --surface: #fffaf1;
  --surface-2: #fdf3df;
  --text: #241d12;
  --muted: #6f6250;
  --border: rgba(30, 20, 10, 0.12);
  --edge-hi: rgba(30, 20, 10, 0.16);
  --accent: #b9791f;
  --accent-contrast: #fffaf1;
  --danger: #9c3d28;
  --success: #55692f;
  --radius: 8px;
  --radius-pill: 999px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17140f;
    --surface: #211c15;
    --surface-2: #2a2419;
    --text: #f3ede1;
    --muted: #a89a83;
    --border: rgba(255, 255, 255, 0.08);
    --edge-hi: rgba(255, 255, 255, 0.1);
    --accent: #e3a83c;
    --accent-contrast: #1b1305;
    --danger: #c1533a;
    --success: #7f9b5e;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 1rem;
  max-width: 560px;
  margin-inline: auto;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Golos Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.4;
}

.mono {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

/* Grid/flex children (select, input, a, button) default to min-width: auto,
   which can exceed their track width and overflow the viewport. */
.nested-fields > *,
ul li > * {
  min-width: 0;
}

.muted {
  color: var(--muted);
  overflow-wrap: anywhere;
}

h1, h2, h3 {
  font-family: "Unbounded", "Golos Text", sans-serif;
  font-weight: 700;
  line-height: 1.2;
}

a {
  color: var(--accent);
}

/* Flash messages */
.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 var(--edge-hi);
}
.flash-alert { border-color: var(--danger); color: var(--danger); }
.flash-notice { border-color: var(--success); color: var(--success); }

/* Buttons and inputs: 44px minimum touch target (Apple HIG) */
button,
input[type="submit"],
a.button {
  display: inline-block;
  min-height: 44px;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

/* A standalone submit button sitting at the end of a plain block-flow
   section (not a flex row with its own gap) had zero space before
   whatever followed it — looked like the two were stuck together. */
input[type="submit"] {
  margin-bottom: 1rem;
}

[data-controller="nested-form"] {
  margin-bottom: 1rem;
}

/* A <button> that should look like a plain text link, not the bold blue
   CTA style above — e.g. secondary/optional actions sitting next to <a>
   nav links. */
.link-button {
  display: inline;
  min-height: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: inherit;
  font-weight: normal;
}

/* Root cause of the "notifications button never hides" saga: this class's
   own display: inline (an author rule) beats the browser's built-in
   [hidden] { display: none } UA rule — the button's `hidden` property was
   true the whole time, it just never took visual effect. Same specificity
   pattern already hit once before with .page-nav-more-panel[hidden]. */
.link-button[hidden] {
  display: none;
}

/* Home page top nav: a couple of common links always visible, everything
   else tucked behind a "more" toggle — this grew to 7 plain links crammed
   on one wrapping line before, with no hierarchy between "start a workout"
   and "log out". */
.page-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.3rem 0.9rem;
  margin-bottom: 0.9rem;
}

.page-nav-more {
  display: contents;
}

.page-nav-more-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.9rem;
  flex-basis: 100%;
  margin-top: 0.2rem;
  font-size: 0.92rem;
}

/* display:flex above otherwise beats the browser's built-in `[hidden] {
   display: none }` rule (a class selector always outranks that UA-sheet
   attribute selector), so the panel would render open by default before
   disclosure_controller's connect() ever runs. */
.page-nav-more-panel[hidden] {
  display: none;
}

.page-nav-more-panel a {
  color: var(--muted);
}

/* A destructive plain-text link (not a button) sitting next to ordinary
   navigation — same "quiet until you mean it" idea as .remove-set, applied
   to <a> instead of <button>. */
.link-danger-quiet {
  color: var(--muted);
}

.link-danger-quiet:hover,
.link-danger-quiet:focus-visible {
  color: var(--danger);
}

.back-link {
  display: inline-block;
  margin-bottom: 0.6rem;
  font-size: 0.9rem;
  color: var(--muted);
}

input[type="text"],
input[type="number"],
input[type="datetime-local"],
input[type="date"],
input[type="password"],
select {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}

/* Browsers default the focus ring to a system blue that clashed with the
   brass accent everywhere else on the page. */
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field {
  margin-bottom: 0.75rem;
}

/* 2x2 instead of 4 full-width fields stacked — order/sets/rep-range are
   short numbers, no reason each one gets its own row. */
.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 0.7rem;
}

.field-grid .field input {
  margin-bottom: 0;
}

.field label {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Template list */
ul {
  list-style: none;
  padding: 0;
}

ul li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 var(--edge-hi);
  padding: 0.9rem 1rem;
  margin-bottom: 0.6rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.9rem;
}

ul li a:first-child {
  font-weight: 600;
  font-size: 1.05rem;
}

/* Template list on the home screen: "start workout" is the action people
   reach for constantly, edit/delete are rare — so it gets a big primary
   button, they get small muted links underneath. */
.template-card,
.stacked-card {
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
}

.template-name {
  font-weight: 700;
  font-size: 1.1rem;
}

.start-workout {
  width: 100%;
  margin-top: 0.3rem;
  /* ul li's own flex gap already spaces this from .template-actions below —
     the general input[type="submit"] margin-bottom would double it up. */
  margin-bottom: 0;
}

.template-actions {
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
}

/* Home page "resume workout" prompt — a session started but not finished.
   Distinct from a template card: solid accent background so it stands out
   above the template list, since it's the more relevant action than
   starting a new session. */
.resume-banner {
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin-bottom: 0.9rem;
}

.resume-banner p {
  margin: 0 0 0.6rem;
}

.resume-banner .button {
  background: var(--accent-contrast);
  color: var(--accent);
  width: 100%;
}

/* Nested exercise rows in the template form */
.nested-fields {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 var(--edge-hi);
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  display: grid;
  gap: 0.5rem;
}

.nested-fields select,
.nested-fields input {
  margin-bottom: 0;
}

/* Exercise sections on the workout-logging screen */
.exercise-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 var(--edge-hi);
  padding: 0.9rem;
  margin-bottom: 0.75rem;
}

.exercise-section-done {
  opacity: 0.75;
}

.exercise-summary {
  display: block;
  width: 100%;
  min-height: auto;
  padding: 0;
  border: none;
  background: none;
  color: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.exercise-summary .check {
  color: var(--success);
}

.hint {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
}

.set-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

.set-row > * {
  min-width: 0;
  margin-bottom: 0;
}

.set-row .set-number {
  font-size: 0.85rem;
}

.set-row .set-number svg,
.exercise-summary .check svg,
.pr-badge svg,
.remove-set svg,
.link-button svg {
  vertical-align: -2px;
  margin-right: 0.15rem;
}

.set-row-done .set-number svg { color: var(--success); }
.set-row-locked .set-number svg { color: var(--muted); }

/* The weight/reps + submit form. A sibling of the delete button's own
   <form> (button_to), not a parent — forms can't nest. */
.set-row-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.set-inputs {
  display: flex;
  gap: 0.4rem;
}

.set-inputs input {
  flex: 1 1 0;
}

/* +/- stepper flanking each weight/reps input (number_stepper_controller.js) */
.stepper {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex: 1 1 0;
  min-width: 0;
}

.stepper input {
  margin-bottom: 0;
  text-align: center;
}

.stepper-btn {
  flex: 0 0 auto;
  width: 44px;
  padding: 0;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 1.3rem;
  line-height: 1;
}

.set-row-form input[type="submit"] {
  width: 100%;
  /* .set-row lays its children out with its own column gap already —
     the general input[type="submit"] margin-bottom would add extra,
     uneven space before the delete button next to it. */
  margin-bottom: 0;
}

.set-row-current {
  outline: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.5rem 0.4rem 0.4rem;
}

.set-row-done {
  opacity: 0.75;
}

.set-row-done .set-summary {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.set-row-locked {
  opacity: 0.6;
}

/* Inserted/removed by offline_queue_controller.js — a set-entry save that
   failed with no server response at all (offline/flaky wifi) is queued for
   automatic retry, and this is the only visible sign of that while it's
   pending. */
.offline-queued-badge {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.offline-queued-badge svg {
  flex-shrink: 0;
}

.rest-timer {
  position: sticky;
  top: 0.5rem;
  z-index: 10;
  margin: 0.75rem 0;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 700;
  font-size: 1.1rem;
  text-align: center;
}

.rest-timer.rest-timer-done {
  background: var(--success);
}

.pr-badge {
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
}

.set-row-locked p {
  margin: 0;
  font-size: 0.9rem;
}

/* Deliberately quiet: this used to be a full-width danger-colored button on
   every single set row, competing with the one real action (the done/submit
   button) for attention. Delete is rare; it should read as a small,
   easy-to-ignore affordance, not a second equally-loud button. */
.remove-set {
  width: auto;
  align-self: flex-end;
  min-height: 40px;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.3rem 0.3rem;
  font-size: 0.82rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  /* It's rendered via button_to, so it's an input[type="submit"] too — reset
     the general trailing-space margin, it already sits tight in its row. */
  margin-bottom: 0;
}

.remove-set:hover,
.remove-set:focus-visible {
  color: var(--danger);
}

.add-set {
  margin-top: 0.6rem;
  width: 100%;
  /* Same button_to/input[type="submit"] margin-bottom to reset — it's the
     last child inside .exercise-section's own padding, not a row with a
     gap, so the general rule would add unwanted empty space at the
     card's bottom. */
  margin-bottom: 0;
}

/* Inline SVG progress charts */
.chart {
  margin: 0.75rem 0 1.1rem;
}

.chart-svg {
  max-width: 100%;
  height: auto;
  display: block;
}

.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
}

.chart-dot {
  fill: var(--accent);
}

.chart-label {
  font-size: 10px;
  fill: var(--text);
  font-family: "JetBrains Mono", ui-monospace, monospace;
}

.chart-legend {
  display: flex;
  gap: 0.9rem;
  font-size: 0.8rem;
  margin-bottom: 0.2rem;
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.chart-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.chart-caption {
  display: flex;
  justify-content: space-between;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.8rem;
  margin-top: 0.15rem;
}

.exercise-muscle-info {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  flex-wrap: wrap;
}

.muscle-illustration {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.muscle-illustration-svg {
  display: block;
}

.muscle-illustration-outline {
  fill: var(--surface-2);
  stroke: var(--border);
  stroke-width: 1.5;
}

.muscle-illustration-highlight {
  fill: var(--accent);
  fill-opacity: 0.65;
  stroke: var(--accent);
  stroke-width: 1;
}

.muscle-illustration-label {
  font-size: 0.7rem;
}

.errors {
  background: var(--surface);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 var(--edge-hi);
  padding: 1rem;
  margin-bottom: 1rem;
  color: var(--danger);
}

/* Undo toast (sandbox-228.51) — Gmail-style delete-with-undo banner
   shown after a soft-delete, in place of the old browser confirm() dialog.
   Fixed to the bottom so it doesn't shift page layout, capped to the same
   reading width as the body. */
.undo-toast {
  position: fixed;
  left: 1rem;
  right: 1rem;
  bottom: 1rem;
  max-width: 560px;
  margin-inline: auto;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}
.undo-toast p {
  margin: 0;
}
.undo-toast-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}
.undo-toast-action {
  color: var(--bg);
  font-weight: 700;
  text-decoration: underline;
  white-space: nowrap;
}
.undo-toast-dismiss {
  min-height: auto;
  padding: 0 0.25rem;
  border: none;
  background: transparent;
  color: var(--bg);
  font-size: 1.1rem;
  line-height: 1;
}
