/* Pico CSS 2 gives the base components; this file sets the palette, Thai type and the page's own pieces. */
:root:not([data-theme=dark]) {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --ink: #18181b;
  --text: #27272a;
  --muted: #5c5c63;
  --placeholder: #6b6b72;
  --line: #e4e4e0;
  --line-strong: #c9c9c3;
  --field: #fafaf9;
  --seg: #ebebe8;
  --seg-hover: #e0e0dc;
  --seg-on: #ffffff;
  --switch-off: #cfcfca;
  --accent: #c0261d;
  --danger: #b42318;
  --warn-bg: #fdf3e1;
  --warn-ink: #6f4100;
  --warn-line: #efd3a0;
  --focus: rgb(24 24 27 / 0.22);
  --shadow: 0 1px 2px rgb(24 24 27 / 0.06), 0 2px 8px rgb(24 24 27 / 0.04);
  --seg-shadow: 0 1px 2px rgb(24 24 27 / 0.12), 0 1px 1px rgb(24 24 27 / 0.04);
  --on-ink: #ffffff;
  --ink-hover: #000000;
  /* Thai weekday colors (Ford's pick), as soft tints with dark text of the same hue */
  --sun-bg: #f8e4e2; --sun-ink: #8a2f27;
  --mon-bg: #faf1c8; --mon-ink: #665200;
  --tue-bg: #fbe5ee; --tue-ink: #8a2d55;
  --wed-bg: #e3f1e1; --wed-ink: #2f6131;
  --thu-bg: #fce6d4; --thu-ink: #8a4310;
  --fri-bg: #e1eff9; --fri-ink: #1f557d;
  --sat-bg: #ece6f6; --sat-ink: #5a3f88;

  --pico-font-family-sans-serif: "Noto Sans Thai", system-ui, "Leelawadee UI", "Segoe UI", sans-serif;
  --pico-font-size: 100%;
  --pico-line-height: 1.6;
  --pico-border-radius: 0.625rem;
  --pico-form-element-spacing-vertical: 0.625rem;
  --pico-form-element-spacing-horizontal: 0.875rem;
  --pico-background-color: var(--bg);
  --pico-color: var(--text);
  --pico-text-selection-color: rgb(192 38 29 / 0.18);
  --pico-muted-color: var(--muted);
  --pico-muted-border-color: var(--line);
  --pico-primary: var(--ink);
  --pico-primary-background: var(--ink);
  --pico-primary-border: var(--ink);
  --pico-primary-underline: var(--line-strong);
  --pico-primary-hover: var(--ink-hover);
  --pico-primary-hover-background: var(--ink-hover);
  --pico-primary-hover-border: var(--ink-hover);
  --pico-primary-hover-underline: var(--ink);
  --pico-primary-focus: var(--focus);
  --pico-primary-inverse: var(--on-ink);
  --pico-secondary: var(--text);
  --pico-secondary-background: var(--seg);
  --pico-secondary-border: var(--seg);
  --pico-secondary-hover: var(--ink);
  --pico-secondary-hover-background: var(--seg-hover);
  --pico-secondary-hover-border: var(--seg-hover);
  --pico-secondary-focus: var(--focus);
  --pico-secondary-inverse: var(--ink);
  --pico-h1-color: var(--ink);
  --pico-h2-color: var(--ink);
  --pico-h3-color: var(--ink);
  --pico-h4-color: var(--ink);
  --pico-card-background-color: var(--surface);
  --pico-card-sectioning-background-color: var(--surface);
  --pico-card-box-shadow: 0 0 0 1px var(--line), var(--shadow);
  --pico-table-border-color: var(--line);
  --pico-form-element-background-color: var(--field);
  --pico-form-element-border-color: var(--line-strong);
  --pico-form-element-color: var(--ink);
  --pico-form-element-placeholder-color: var(--placeholder);
  --pico-form-element-active-background-color: var(--surface);
  --pico-form-element-active-border-color: var(--ink);
  --pico-form-element-focus-color: var(--focus);
  --pico-switch-background-color: var(--switch-off);
  --pico-switch-checked-background-color: var(--ink);
  --pico-switch-color: var(--surface);
  --pico-accordion-border-color: var(--line);
  --pico-accordion-close-summary-color: var(--muted);
  --pico-accordion-open-summary-color: var(--ink);
  --pico-accordion-active-summary-color: var(--ink);
}

/* Light only (Ford's choice): <html data-theme="light"> also keeps Pico out of its dark palette. */

/* ---- base ---- */
body { background: var(--bg); min-height: 100dvh; }
.icon { width: 1.125rem; height: 1.125rem; flex: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
button:has(> .icon) { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; }
button:focus:not(:focus-visible),
button.secondary:focus:not(:focus-visible) { --pico-box-shadow: 0 0 0 rgb(0 0 0 / 0); }
input, textarea { caret-color: var(--accent); }

/* ---- top bar and tabs ---- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--bg); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
.topbar-inner { max-width: 44rem; margin: 0 auto; padding: 0.625rem 1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.brand { margin: 0; display: flex; align-items: baseline; gap: 0.5rem; font-size: 1rem; font-weight: 700; letter-spacing: -0.01em; color: var(--ink); }
.brand::before { content: ""; align-self: center; width: 0.625rem; height: 0.625rem; border-radius: 50%; background: var(--accent); }
.brand small { font-size: 0.8125rem; font-weight: 400; color: var(--muted); }

.tabs { display: flex; gap: 0.25rem; padding: 0.25rem; background: var(--seg); border-radius: 0.75rem; }
.tabs button { --pico-background-color: transparent; --pico-border-color: transparent; --pico-color: var(--muted); position: relative; margin: 0; padding: 0.375rem 0.875rem; border-radius: 0.5rem; font-size: 0.9375rem; }
.tabs button:is(:hover, :active, :focus) { --pico-background-color: transparent; --pico-border-color: transparent; --pico-color: var(--ink); }
/* button[type=button] outranks Pico's [type=button][aria-current] rule, which paints the current tab black */
.tabs button[type=button][aria-current="page"] { --pico-background-color: var(--seg-on); --pico-border-color: var(--seg-on); --pico-color: var(--ink); font-weight: 600; }
.tabs button[type=button]:focus:not(:focus-visible) { --pico-box-shadow: 0 0 0 rgb(0 0 0 / 0); }
.badge { min-width: 1.25rem; height: 1.25rem; padding: 0 0.3rem; border: 1px solid var(--warn-line); border-radius: 999px; background: var(--warn-bg); color: var(--warn-ink); font-size: 0.75rem; font-weight: 700; line-height: 1.125rem; text-align: center; font-variant-numeric: tabular-nums; }
.badge:empty { display: none; }

/* ---- layout ---- */
main { max-width: 44rem; margin: 0 auto; padding: 1rem 1rem 3rem; }
.panel { display: none; }
body[data-tab="form"] #form-panel,
body[data-tab="trainer"] #trainer-panel,
body[data-tab="client"] #client-panel { display: block; animation: panel-in 0.22s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes panel-in { from { opacity: 0.5; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .panel { animation: none !important; } }

@media (max-width: 767.98px) {
  .topbar-inner { justify-content: flex-start; }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; gap: 0; padding: 0.25rem 0.5rem calc(0.25rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); border-radius: 0; background: var(--surface); }
  .tabs button { flex: 1; flex-direction: column; gap: 0.125rem; min-height: 3.25rem; padding: 0.375rem 0; font-size: 0.75rem; }
  .tabs button[type=button][aria-current="page"] { --pico-background-color: transparent; --pico-border-color: transparent; }
  .tabs button[aria-current="page"] .icon { color: var(--accent); }
  .tabs .icon { width: 1.375rem; height: 1.375rem; }
  .tabs .badge { position: absolute; top: 0.25rem; left: calc(50% + 0.5rem); }
  main { padding-bottom: calc(5.5rem + env(safe-area-inset-bottom)); }
}

/* ---- form cards ---- */
article { margin: 0 0 1rem; padding: 1.125rem 1rem 0.375rem; border-radius: 0.875rem; }
article > h2 { margin: 0 0 0.875rem; font-size: 1.0625rem; font-weight: 650; letter-spacing: -0.005em; }
.field { display: block; min-width: 0; margin: 0 0 0.875rem; }
.field > span,
fieldset.field > legend { display: block; margin: 0 0 0.3rem; font-size: 0.875rem; font-weight: 500; color: var(--muted); }
.field :is(input, select, textarea) { margin: 0; }
textarea { min-height: 4.5rem; resize: vertical; }
.cols-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 0.75rem; }
.cols-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 0.625rem; align-items: end; }
.hint { margin: 0.25rem 0 0.875rem; font-size: 0.875rem; color: var(--muted); }
ul.hint { padding-left: 1.125rem; }
ul.hint li { margin-bottom: 0.25rem; }
.warn { display: flex; align-items: flex-start; gap: 0.5rem; margin: 0.25rem 0 0.875rem; padding: 0.625rem 0.75rem; border: 1px solid var(--warn-line); border-radius: 0.625rem; background: var(--warn-bg); color: var(--warn-ink); font-size: 0.875rem; }
.warn .icon { margin-top: 0.2rem; width: 1rem; height: 1rem; }
.error { color: var(--danger); }
article details { margin: 0.25rem 0 0.75rem; padding-top: 0.625rem; border-top: 1px solid var(--line); border-bottom: 0; }
article details summary { font-size: 0.875rem; }
article details[open] > summary { margin-bottom: 0.5rem; }
article details ul { font-size: 0.875rem; padding-left: 1.125rem; }

/* segmented choice: radios styled as one control */
.seg { display: flex; gap: 0.125rem; padding: 0.1875rem; border-radius: 0.75rem; background: var(--seg); }
.seg label { position: relative; flex: 1 1 0; min-width: 0; width: auto; margin: 0; }
.seg input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.seg span { display: block; padding: 0.5625rem 0.25rem; border-radius: 0.5625rem; font-size: 0.9375rem; line-height: 1.35; text-align: center; color: var(--muted); overflow-wrap: anywhere; transition: background-color 0.15s, color 0.15s, box-shadow 0.15s; }
.seg label:hover span { color: var(--ink); }
.seg input:checked + span { background: var(--seg-on); color: var(--ink); font-weight: 600; box-shadow: var(--seg-shadow); }
.seg input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 1px; }

.check { display: flex; align-items: center; gap: 0.625rem; width: auto; margin: 0 0 0.875rem; font-size: 0.9375rem; }
.check input { margin: 0; }

/* exercise blocks inside a day card */
.exercise { padding: 0.875rem 0 0; border-top: 1px solid var(--line); }
.exercise-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.25rem; }
.exercise-index { font-size: 0.8125rem; font-weight: 600; color: var(--muted); }
.field input.exercise-name-input { font-weight: 600; }
.load-group { margin: 0; }
.load-group .hint { margin-top: -0.375rem; }
button.icon-btn { --pico-background-color: transparent; --pico-border-color: transparent; --pico-color: var(--muted); display: inline-grid; place-items: center; min-width: 2.75rem; min-height: 2.75rem; margin: -0.5rem -0.625rem -0.5rem 0; padding: 0; }
button.icon-btn:is(:hover, :active, :focus) { --pico-background-color: color-mix(in srgb, var(--danger) 10%, transparent); --pico-border-color: transparent; --pico-color: var(--danger); }
.day-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.25rem 0 0.875rem; }
.day-actions button { flex: 1 1 10rem; margin: 0; padding: 0.625rem 0.75rem; font-size: 0.9375rem; }
.day-actions .add { flex-basis: 100%; }
.form-end { display: flex; justify-content: center; padding: 0.5rem 0 1rem; }
button.danger { --pico-background-color: transparent; --pico-border-color: var(--line-strong); --pico-color: var(--danger); margin: 0; font-size: 0.9375rem; }
button.danger:is(:hover, :active, :focus) { --pico-background-color: color-mix(in srgb, var(--danger) 8%, transparent); --pico-border-color: var(--danger); --pico-color: var(--danger); }

/* ---- trainer and client sheets ---- */
.panel-actions { display: flex; justify-content: flex-end; margin-bottom: 0.75rem; }
.panel-actions button { margin: 0; }
.sheet { padding: 1.25rem 1rem 0.5rem; border-radius: 1rem; background: var(--surface); box-shadow: 0 0 0 1px var(--line), var(--shadow); }
.sheet-head h2 { margin: 0 0 0.125rem; font-size: 1.375rem; font-weight: 700; letter-spacing: -0.015em; }
.sheet-head .hint { margin: 0; }
.sheet h3 { display: flex; align-items: center; gap: 0.5rem; margin: 1.75rem 0 0; padding-bottom: 0.5rem; border-bottom: 2px solid var(--ink); font-size: 1rem; font-weight: 650; }
.sheet h3 .icon { color: var(--warn-ink); }
.sheet h3.day-title { margin-top: 1.5rem; padding: 0.5rem 0.75rem; border: 0; border-radius: 0.5rem; background: var(--day-bg, var(--seg)); color: var(--day-ink, var(--ink)); -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.day-title[data-weekday="sun"] { --day-bg: var(--sun-bg); --day-ink: var(--sun-ink); }
.day-title[data-weekday="mon"] { --day-bg: var(--mon-bg); --day-ink: var(--mon-ink); }
.day-title[data-weekday="tue"] { --day-bg: var(--tue-bg); --day-ink: var(--tue-ink); }
.day-title[data-weekday="wed"] { --day-bg: var(--wed-bg); --day-ink: var(--wed-ink); }
.day-title[data-weekday="thu"] { --day-bg: var(--thu-bg); --day-ink: var(--thu-ink); }
.day-title[data-weekday="fri"] { --day-bg: var(--fri-bg); --day-ink: var(--fri-ink); }
.day-title[data-weekday="sat"] { --day-bg: var(--sat-bg); --day-ink: var(--sat-ink); }
.sheet section > p, .sheet section > ul { margin: 0.75rem 0 0; font-size: 0.9375rem; }
.sheet section > ul { padding-left: 1.125rem; }
.sheet section > ul.notes { font-size: 0.875rem; color: var(--muted); }
.warn-jump { display: inline-flex; align-items: center; gap: 0.375rem; margin-top: 0.75rem; padding: 0.3125rem 0.75rem; border: 1px solid var(--warn-line); border-radius: 999px; background: var(--warn-bg); color: var(--warn-ink); font-size: 0.875rem; font-weight: 600; text-decoration: none; }
.warn-jump:hover { color: var(--warn-ink); text-decoration: underline; }
.warn-jump .icon { width: 1rem; height: 1rem; }
#warnings { scroll-margin-top: 4.5rem; }

.summary { margin: 1rem 0 0; }
.summary > div { display: grid; grid-template-columns: 6rem minmax(0, 1fr); gap: 0.75rem; padding: 0.5rem 0; border-top: 1px solid var(--line); }
.summary dt { font-size: 0.875rem; font-weight: 500; color: var(--muted); }
.summary dd { margin: 0; font-size: 0.9375rem; }
.summary .dd-note { display: block; font-size: 0.8125rem; color: var(--muted); }

.table-wrap { overflow-x: auto; }
.sheet table { margin: 0; font-size: 0.9375rem; font-variant-numeric: tabular-nums; }
.sheet :is(th, td) { padding: 0.625rem 0.5rem; background: transparent; vertical-align: top; }
.sheet :is(th, td):first-child { padding-left: 0; }
.sheet :is(th, td):last-child { padding-right: 0; }
.sheet th { font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.exercise-name { font-weight: 600; color: var(--ink); }
.chip { display: inline-block; margin-left: 0.375rem; padding: 0 0.4rem; border-radius: 0.375rem; background: var(--seg); color: var(--muted); font-size: 0.75rem; font-weight: 500; line-height: 1.5; }
.num { font-weight: 600; color: var(--ink); }
.src { font-size: 0.75rem; color: var(--muted); }
.missing { display: inline-flex; vertical-align: -0.15em; color: var(--warn-ink); }
.missing .icon { width: 1rem; height: 1rem; }
.row-warn { color: var(--warn-ink); }

.warnings { margin: 0; padding: 0; list-style: none; counter-reset: warning; }
.warnings li { counter-increment: warning; display: grid; grid-template-columns: 1.5rem minmax(0, 1fr); gap: 0.625rem; margin: 0; padding: 0.625rem 0; border-bottom: 1px solid var(--line); font-size: 0.9375rem; }
.warnings li:last-child { border-bottom: 0; }
.warnings li::before { content: counter(warning); display: grid; place-items: center; width: 1.5rem; height: 1.5rem; border: 1px solid var(--warn-line); border-radius: 50%; background: var(--warn-bg); color: var(--warn-ink); font-size: 0.75rem; font-weight: 700; }

/* wide screens and paper: same column widths in every day's table */
.sheet table.stack { table-layout: fixed; }
#trainer .stack.rx th:nth-child(1) { width: 26%; }
#trainer .stack.rx th:nth-child(2) { width: 15%; }
#trainer .stack.rx th:nth-child(3) { width: 23%; }
#trainer .stack.rx th:nth-child(4) { width: 14%; }
#client .stack th:nth-child(1) { width: 30%; }
#client .stack th:nth-child(2) { width: 20%; }
#client .stack th:nth-child(3) { width: 35%; }

/* phone: each row becomes a block — name, then sets × reps with rest on the right, then load, then sources */
@media screen and (max-width: 640px) {
  .stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .stack, .stack tbody { display: block; }
  .stack tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.25rem 1rem; padding: 0.75rem 0; border-bottom: 1px solid var(--line); }
  .stack.even tr { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stack tr:last-child { border-bottom: 0; }
  .sheet .stack td { display: block; padding: 0; border: 0; }
  .stack td:first-child, .stack td.src, .stack td.full { grid-column: 1 / -1; }
  .stack td.c-dose { grid-column: 1; grid-row: 2; }
  .stack td.c-rest { grid-column: 2; grid-row: 2; text-align: right; }
  .stack td.c-load { grid-column: 1 / -1; grid-row: 3; }
  .stack td.src { grid-row: 4; }
  .stack td.c-dose { font-size: 1.0625rem; }
  .stack td[data-label]::before { content: attr(data-label); display: block; font-size: 0.6875rem; font-weight: 500; color: var(--muted); }
}

/* ---- print: client page only ---- */
@page { margin: 14mm; }
@media print {
  .no-print, .topbar, #form-panel, #trainer-panel { display: none !important; }
  #client-panel { display: block !important; animation: none; }
  body { background: #ffffff; }
  main { max-width: none; padding: 0; }
  .sheet { padding: 0; border-radius: 0; box-shadow: none; }
  .sheet h3 { break-after: avoid; }
  .sheet section { break-inside: avoid; }
  tr { break-inside: avoid; }
}
