:root {
  --radius: 6px;
  --radius-sm: 4px;
  --red-50: #fde8e8;
  --red-100: #f9bebe;
  --red-200: #f59494;
  --red-300: #f16a6a;
  --red-400: #ed4040;
  --red-500: #eb2323;
  --red-600: #bf1212;
  --red-700: #950e0e;
  --red-800: #6b0a0a;
  --red-900: #410606;
  --red-950: #170202;
  --background: #e8e6e3;
  --background-overlay: rgb(232 230 227 / 0.97);
  --surface: #f2f0ed;
  --text: #2a2724;
  --muted: #5f5b56;
  --border: #bdb9b3;
  --brand: var(--red-600);
  --on-brand: #ffffff;
  --primary: var(--red-600);
  --primary-hover: var(--red-700);
  --on-primary: #ffffff;
  --accent: var(--red-600);
  --accent-soft: var(--red-50);
  --error: var(--red-700);
  --skeleton: #dad7d3;
  --sheet-grid: #bdb9b3;
  --sheet-header: #434343;
  --sheet-header-text: #ffffff;
  --sheet-column-header: #d5d2cd;
  --sheet-column-text: #2a2724;
  --sheet-athlete: #c5d5e2;
  --sheet-notes: #e2dfdb;
  --sheet-locked: #e2dfdb;
  --emphasis-primary: var(--red-200);
  --emphasis-secondary: var(--red-50);
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #161616;
    --background-overlay: rgb(22 22 22 / 0.96);
    --surface: #222222;
    --text: #eeeeee;
    --muted: #a8a8a8;
    --border: #4a4a4a;
    --brand: var(--red-800);
    --on-brand: #ffffff;
    --primary: var(--red-300);
    --primary-hover: var(--red-200);
    --on-primary: var(--red-950);
    --accent: var(--red-300);
    --accent-soft: var(--red-900);
    --error: var(--red-200);
    --skeleton: #333333;
    --sheet-grid: #4a4a4a;
    --sheet-header: #3d3d3d;
    --sheet-header-text: #ffffff;
    --sheet-column-header: #292929;
    --sheet-column-text: #c9c9c9;
    --sheet-athlete: #243746;
    --sheet-notes: #2c2c2c;
    --sheet-locked: #1c1c1c;
    --emphasis-primary: var(--red-800);
    --emphasis-secondary: var(--red-900);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(var(--background-overlay), var(--background-overlay)),
    url("/images/gym.jpg") center / cover no-repeat;
}

.brand-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 14px 16px;
  background: var(--brand);
  color: var(--on-brand);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0;
  color: var(--on-brand);
  font-weight: 700;
  text-decoration: none;
}

.account {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  font-size: 0.9rem;
}

#app {
  max-width: 880px;
  margin: 32px auto;
  padding: 0 16px;
}

.narrow {
  max-width: 420px;
  margin: 16px auto;
}

.nav-link {
  color: var(--on-brand);
  text-decoration: none;
}

.nav-link:hover,
.nav-link[aria-current="page"] {
  text-decoration: underline;
}

.hero {
  max-width: 640px;
  margin: 72px auto;
  text-align: center;
}

.hero-title {
  margin: 0 0 16px;
  font-size: clamp(1.75rem, 5vw, 2.75rem);
  line-height: 1.15;
}

.hero-text {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 1.1rem;
}

.button.hero-button {
  padding: 14px 28px;
}

.hero-notice {
  margin: 28px 0 0;
}

.inline-link {
  color: var(--accent);
}

.profile-section {
  margin-bottom: 32px;
}

.person-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.person-details {
  min-width: 0;
  overflow-wrap: anywhere;
}

.person-name {
  font-weight: 600;
}

.person-secondary {
  margin: 2px 0 0;
  font-size: 0.9rem;
}

.person-actions,
.invite-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}

.invite-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.profile-section .search-input {
  margin-bottom: 8px;
}

.invite-form .input {
  flex: 1 1 240px;
}

.invite-form .error {
  flex-basis: 100%;
  margin: 0;
}

.title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-bottom: 16px;
}

.client-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-bottom: 16px;
  padding: 10px 16px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
}

.client-banner-name {
  flex: 1 1 200px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.client-banner-link {
  color: inherit;
  text-decoration: none;
}

.client-banner-link:hover,
.client-banner-link:focus-visible {
  text-decoration: underline;
}

.title-row .page-title {
  margin: 0;
}

.status-pill {
  padding: 2px 10px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 999px;
}

.status-pill.shared {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.person-link {
  color: var(--text);
}

.row-actions {
  width: 40px;
  text-align: center;
}

.choice-list {
  display: grid;
  max-height: 320px;
  margin: 8px 0;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.choice {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.choice:hover:not(:disabled),
.choice:focus-visible {
  background: var(--accent-soft);
}

.page-title {
  margin: 0 0 16px;
  font-size: 1.5rem;
  overflow-wrap: anywhere;
}

.section-title {
  margin: 24px 0 12px;
  font-size: 1.1rem;
}

.input {
  min-width: 0;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font: inherit;
  border-radius: var(--radius-sm);
}

.dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
}

.dialog::backdrop {
  background: rgb(0 0 0 / 0.5);
}

.field {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  font-weight: 600;
}

.field .input {
  width: 100%;
  font-weight: 400;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.dialog .error {
  margin-bottom: 12px;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  margin-top: 8px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.toolbar .search-input {
  flex: 1 1 240px;
}

.search-input {
  width: 100%;
}

.toolbar .button {
  flex-shrink: 0;
}

.program-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.program-table th {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-align: left;
}

.program-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

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

.program-row {
  cursor: pointer;
}

.program-row:hover {
  background: var(--accent-soft);
}

.program-name {
  overflow-wrap: anywhere;
}

.program-link {
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

.program-table .number-col {
  width: 80px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.program-table .date-col {
  width: 130px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

@media (max-width: 560px) {
  .program-table .hide-narrow {
    display: none;
  }
}

.skeleton {
  height: 48px;
  margin-bottom: 8px;
  background: var(--skeleton);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 12px;
}

.tab {
  max-width: 100%;
  padding: 6px 12px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  font: inherit;
  overflow-wrap: anywhere;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-primary);
  font-weight: 700;
}

.tab-add {
  color: var(--muted);
}

.block-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-bottom: 16px;
}

.block-name {
  flex: 1 1 240px;
  font-weight: 600;
}

.week-tabs {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  overflow-x: auto;
  padding: 4px 8px 0;
  background: transparent;
  border-bottom: 2px solid var(--accent);
}

.week-tab {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  border-radius: 8px 8px 0 0;
}

.week-tab.active {
  background: var(--surface);
  box-shadow: inset 0 2px 0 var(--accent);
}

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

.week-tab-label {
  padding: 8px 14px;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.week-tab.active .week-tab-label {
  color: var(--text);
  font-weight: 700;
}

.week-tab-remove,
.week-tab-add {
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.week-tab-remove {
  padding: 8px 10px 8px 0;
}

.week-tab-remove:hover {
  color: var(--error);
}

.week-tab-add {
  flex-shrink: 0;
  padding: 6px 12px;
  font-size: 1.1rem;
}

.week-tab-add:hover {
  color: var(--accent);
}

.session-list {
  padding-top: 16px;
}

.session {
  margin-bottom: 20px;
  overflow: clip;
  background: var(--surface);
  border: 1px solid var(--sheet-grid);
  border-radius: var(--radius);
}

.session-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  background: var(--sheet-header);
  border-bottom: 2px solid var(--sheet-grid);
  color: var(--sheet-header-text);
}

.session-title {
  display: flex;
  flex: 1 1 260px;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 8px;
}

.session-name {
  flex: 1 1 140px;
  min-width: 0;
  padding: 4px 6px;
  background: transparent;
  border: 1px solid transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-transform: uppercase;
}

.session-name:hover,
.session-name:focus {
  border-color: var(--sheet-header-text);
}

.session-weekday {
  flex: 0 1 120px;
  padding: 4px;
  background: var(--sheet-header);
  border: 1px solid transparent;
  color: inherit;
  font: inherit;
  font-size: 0.85rem;
}

.session-weekday:hover,
.session-weekday:focus {
  border-color: var(--sheet-header-text);
}

.session-field {
  display: grid;
  flex: 1 1 88px;
  grid-template-rows: auto 1fr;
  border-left: 1px solid var(--sheet-grid);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: center;
  text-transform: uppercase;
}

.session-field-label {
  padding: 4px;
}

.athlete-cell {
  min-height: 22px;
  background: var(--sheet-athlete);
}

.session-remove {
  padding: 0 12px;
  background: none;
  border: 0;
  border-left: 1px solid var(--sheet-grid);
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.session-remove:hover {
  background: var(--red-700);
}

.sheet-scroll {
  overflow-x: auto;
}

.sheet {
  width: 100%;
  min-width: 620px;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.875rem;
}

.sheet th,
.sheet td {
  border-right: 1px solid var(--sheet-grid);
  border-bottom: 1px solid var(--sheet-grid);
}

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

.sheet th {
  padding: 6px 8px;
  background: var(--sheet-column-header);
  color: var(--sheet-column-text);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  white-space: nowrap;
}

.sheet .exercise-col {
  position: sticky;
  left: 0;
  z-index: 1;
  text-align: left;
}

.sheet th.col-sets,
.sheet th.col-reps {
  width: 72px;
}

.sheet th.col-weight,
.sheet th.col-intensity {
  width: 96px;
}

.sheet th.col-dropdown {
  width: 112px;
}

.sheet th.exercise-col .column-head {
  justify-content: flex-start;
}

.sheet th.exercise-col {
  z-index: 2;
}

.sheet td.exercise-col {
  padding: 0;
  background: var(--surface);
}

.exercise-cell {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
}

.column-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}

.column-head span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.value-cell {
  padding: 0;
  background: var(--surface);
}

.session-name-text {
  overflow-wrap: anywhere;
}

.session-name-text:hover,
.session-name-text:focus {
  border-color: transparent;
}

.session-weekday-text:hover,
.session-weekday-text:focus {
  border-color: transparent;
}

.read-cell {
  padding: 8px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.sheet td.read-exercise {
  padding: 8px;
  overflow-wrap: anywhere;
}

.read-empty {
  padding: 10px 8px;
  background: var(--surface);
  color: var(--muted);
}

.sheet tr.emphasis-primary > td:not(.notes-cell) {
  background: var(--emphasis-primary);
}

.sheet tr.emphasis-secondary > td:not(.notes-cell) {
  background: var(--emphasis-secondary);
}

.emphasis-marker {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  margin: auto 0 auto 8px;
  padding: 0;
  background: transparent;
  border: 2px solid var(--muted);
  border-radius: 50%;
  cursor: pointer;
}

.emphasis-marker.primary {
  background: var(--red-600);
  border-color: var(--red-600);
}

.emphasis-marker.secondary {
  background: var(--red-200);
  border-color: var(--red-600);
}

.sheet-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px 16px;
  margin-bottom: 16px;
}

.lift-header {
  flex: 1 1 280px;
  max-width: 360px;
  overflow: clip;
  border: 1px solid var(--sheet-grid);
  border-radius: var(--radius);
}

.layout-panel {
  flex: 1 1 260px;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--sheet-grid);
  font-size: 0.875rem;
  border-radius: var(--radius);
}

.layout-panel-head {
  padding: 6px 8px;
  background: var(--sheet-column-header);
  border-bottom: 1px solid var(--sheet-grid);
  color: var(--sheet-column-text);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.layout-group {
  padding: 8px;
}

.layout-group + .layout-group {
  border-top: 1px solid var(--sheet-grid);
}

.layout-group-title {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.layout-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.layout-choice {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.layout-choice input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary);
}

.lift-table {
  min-width: 0;
}

.lift-table .lift-name {
  text-align: left;
}

.lift-table td.lift-name {
  padding: 0;
  background: var(--surface);
}

.lift-label {
  flex: 1;
  padding: 8px;
  overflow-wrap: anywhere;
}

.lift-table .lift-value {
  width: 110px;
}

.percent-cell {
  font-weight: 600;
}

.locked-cell {
  background: var(--sheet-locked);
  cursor: not-allowed;
}

.cell-input {
  display: block;
  width: 100%;
  min-height: 34px;
  padding: 6px 8px;
  background: transparent;
  border: 0;
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.cell-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.cell-input.invalid {
  background: var(--accent-soft);
  outline: 2px solid var(--error);
  outline-offset: -2px;
}

select.cell-input option {
  background: var(--surface);
  color: var(--text);
}

.sheet .notes-col {
  width: 18%;
}

.notes-cell {
  background: var(--sheet-notes);
  border-right: 0 !important;
}

.exercise-name {
  flex: 1;
  min-width: 0;
  padding: 8px;
  background: none;
  border: 0;
  color: var(--text);
  font: inherit;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.exercise-name:hover {
  color: var(--accent);
}

.row-remove {
  padding: 0 10px;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.row-remove:hover {
  color: var(--error);
}

.add-row td {
  padding: 0;
  background: var(--surface);
}

.add-exercise {
  display: block;
  width: 100%;
  padding: 6px 8px;
  background: none;
  border: 0;
  color: var(--accent);
  font: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.add-exercise:hover {
  background: var(--accent-soft);
}

.picker-row td {
  padding: 0;
  background: var(--surface);
}

.picker {
  padding: 8px;
}

.picker-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.picker-input {
  flex: 1;
}

.picker-results {
  display: grid;
  max-height: 240px;
  overflow-y: auto;
}

.picker-results .muted,
.picker-results .error {
  margin: 8px;
}

.picker-option {
  padding: 8px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.picker-option:hover,
.picker-option:focus {
  background: var(--accent-soft);
}

.save-status {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  max-width: calc(100vw - 32px);
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.25);
  color: var(--text);
  font-size: 0.9rem;
}

.save-status.error {
  border-left-color: var(--error);
}

.save-status:has(.save-text:empty) {
  padding: 8px;
  border-left: 1px solid var(--border);
}

.save-text:empty {
  display: none;
}

.save-text:empty + .history-buttons {
  padding-left: 0;
  border-left: 0;
}

.history-buttons {
  display: flex;
  gap: 6px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}

.history-button {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
}

.history-button:hover:not(:disabled),
.history-button:focus-visible {
  background: var(--red-600);
  border-color: var(--red-600);
  color: #fff;
}

.history-button:disabled {
  color: var(--muted);
  opacity: 0.5;
  cursor: default;
}

.save-status:has(.save-text:empty):not(:has(button:not([hidden]))) {
  display: none;
}

.page:has(.save-status) {
  padding-bottom: 72px;
}

.save-text.error {
  color: var(--error);
}

.text-button {
  padding: 6px 4px;
  background: none;
  border: 0;
  color: var(--text);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.text-button:disabled {
  color: var(--muted);
  text-decoration: none;
  cursor: default;
}

.text-button.on-brand {
  color: var(--on-brand);
}

.text-button.danger {
  color: var(--error);
}

.button.button-inline {
  display: inline-block;
  width: auto;
}

.card {
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card-title {
  margin: 0 0 16px;
  font-size: 1.25rem;
  overflow-wrap: anywhere;
}

.muted {
  margin: 0 0 16px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.error {
  margin: 0 0 16px;
  color: var(--error);
}

.button {
  display: block;
  width: 100%;
  padding: 12px 16px;
  background: var(--primary);
  border: 1px solid var(--primary);
  color: var(--on-primary);
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.button:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.button:disabled {
  opacity: 0.6;
  cursor: default;
}
