:root {
  color-scheme: light;
  --bg: #f5f7f3;
  --surface: #ffffff;
  --surface-soft: #f0f5ef;
  --ink: #17211b;
  --muted: #68746c;
  --line: #dce3dd;
  --accent: #197a61;
  --accent-dark: #0f5845;
  --accent-soft: #dff1ea;
  --energy: #f2b84b;
  --coral: #d96b5f;
  --blue: #4169a8;
  --shadow: 0 18px 48px rgba(23, 33, 27, 0.09);
  --radius: 8px;
  --sidebar: 300px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --webapp-top-space: calc(16px + var(--safe-top));
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: var(--webapp-top-space);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(25, 122, 97, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(242, 184, 75, 0.15), transparent 30%),
    var(--bg);
  overscroll-behavior-y: none;
  overflow-x: hidden;
}

body.webapp-mode {
  min-height: 100dvh;
  padding-top: var(--safe-top);
}

body.webapp-mode::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: var(--safe-top);
  background: var(--bg);
  z-index: 1000;
  pointer-events: none;
}

body.webapp-mode .app-shell {
  min-height: 100dvh;
}

body.webapp-mode .workspace {
  padding-top: calc(14px + var(--safe-top));
  padding-bottom: calc(18px + var(--safe-bottom));
}

body.webapp-mode .exercise-card {
  scroll-margin-top: var(--webapp-top-space);
}

body.webapp-mode .client-dialog {
  max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 28px);
  margin: calc(14px + var(--safe-top)) auto calc(14px + var(--safe-bottom));
  overflow: auto;
}

.auth-screen {
  position: relative;
  z-index: 2000;
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding: calc(18px + var(--safe-top)) 18px calc(18px + var(--safe-bottom));
  background: var(--bg);
}

body.auth-required .auth-screen {
  display: grid;
}

body.auth-pending .auth-screen,
body.auth-pending .app-shell {
  display: none;
}

body.auth-required .app-shell {
  display: none;
}

.auth-card {
  display: grid;
  gap: 14px;
  width: min(100%, 360px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-brand {
  margin-bottom: 6px;
}

.auth-register,
.logout-button {
  width: 100%;
}

.auth-message {
  min-height: 18px;
  margin: 0;
  color: var(--coral);
  font-size: 13px;
  font-weight: 800;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
label.import-trigger {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100svh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: 100vh;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border-radius: var(--radius);
  background: url("./icon.svg") center / cover no-repeat;
  overflow: hidden;
}

.brand-mark span {
  display: none;
}

.brand h1,
.brand p,
.client-header h2,
.client-header p,
.panel h3,
.panel p,
.exercise-title h4 {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.1;
}

.brand p,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
}

.eyebrow {
  margin: 0 0 6px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.client-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  gap: 10px;
}

.client-tools > .edit-client-button {
  display: none;
}

.logout-button {
  grid-column: 1 / -1;
  min-height: 38px;
}

.selected-client-strip {
  display: none;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
}

.selected-client-strip strong,
.selected-client-strip small {
  display: block;
}

.selected-client-strip small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.mode-switch {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.mode-button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-weight: 900;
}

.mode-button.active {
  color: #fff;
  background: var(--accent-dark);
}

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.search-field input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
}

.primary-action,
.ghost-button,
.save-button,
.icon-button,
.client-button,
.delete-session,
.copy-session-log,
.edit-client-inline,
.delete-client {
  cursor: pointer;
  border: 0;
}

.primary-action,
.ghost-button,
.save-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border-radius: var(--radius);
  font-weight: 800;
}

.primary-action {
  padding: 0 13px;
  color: #fff;
  background: var(--accent);
  white-space: nowrap;
}

.client-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding-right: 4px;
}

.client-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px 34px;
  gap: 6px;
  align-items: stretch;
}

.client-button {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  padding: 12px;
  text-align: left;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--ink);
  background: transparent;
}

.edit-client-inline,
.delete-client {
  display: grid;
  place-items: center;
  align-self: stretch;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-weight: 800;
}

.edit-client-inline {
  color: var(--accent-dark);
  background: #eef8f2;
  font-size: 19px;
}

.delete-client {
  color: var(--coral);
  background: #fff8f6;
  font-size: 20px;
}

body[data-mode="personal"] .client-list,
body[data-mode="personal"] .search-field,
body[data-mode="personal"] #addClientBtn,
body[data-mode="personal"] #editClientBtn {
  display: none;
}

.client-button:hover,
.client-button.active {
  border-color: var(--line);
  background: var(--surface);
}

.client-button.active {
  box-shadow: var(--shadow);
}

.avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  color: #fff;
  font-weight: 900;
  background: var(--blue);
  font-size: 18px;
}

.avatar svg {
  width: 23px;
  height: 23px;
  stroke-width: 1.9;
}

.avatar-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
  padding: 0;
  border: 0;
}

.avatar-picker legend {
  grid-column: 1 / -1;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.avatar-picker label {
  position: relative;
  display: block;
}

.avatar-picker input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.avatar-picker span {
  display: grid;
  grid-template-rows: 26px auto;
  place-items: center;
  min-height: 62px;
  padding: 7px 4px 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--avatar-color, var(--accent-dark));
  background: var(--surface);
  cursor: pointer;
}

.avatar-picker svg {
  width: 24px;
  height: 24px;
  stroke-width: 1.8;
}

.avatar-picker small {
  max-width: 100%;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  line-height: 1.05;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.avatar-picker input:checked + span {
  border-color: var(--accent-dark);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(25, 122, 97, 0.11);
}

.program-switcher {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.client-button:nth-child(3n) .avatar {
  background: var(--coral);
}

.client-button:nth-child(3n + 1) .avatar {
  background: var(--accent);
}

.client-meta {
  min-width: 0;
}

.client-meta strong,
.client-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.client-meta span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.client-meta small {
  display: block;
  margin-top: 2px;
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 850;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.client-profile-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.client-profile-grid .wide-field {
  grid-column: span 3;
}

.client-profile-grid textarea {
  min-height: 74px;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.client-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.client-header h2 {
  font-size: 34px;
  line-height: 1.05;
}

.header-actions {
  display: none;
  gap: 8px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--surface);
}

.icon-button:hover,
.ghost-button:hover {
  background: var(--surface-soft);
}

.import-trigger {
  position: relative;
  display: inline-grid;
}

.import-trigger input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.8);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  overflow-wrap: anywhere;
  margin-top: 8px;
  font-size: 24px;
  line-height: 1.1;
}

.metric strong.positive {
  color: var(--accent-dark);
}

.metric strong.negative {
  color: var(--coral);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(420px, 1.15fr) minmax(330px, 0.85fr);
  gap: 18px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.training-form {
  padding: 20px;
  overflow: hidden;
}

.right-column .panel > :not(.panel-summary) {
  margin: 0 20px 20px;
}

.right-column {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.panel-heading.compact {
  margin-bottom: 14px;
}

.panel-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  cursor: pointer;
  list-style: none;
}

.panel-summary::-webkit-details-marker {
  display: none;
}

.panel-summary::after {
  content: "+";
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--accent-dark);
  background: var(--surface);
  font-weight: 900;
}

details[open] > .panel-summary::after {
  content: "−";
}

.panel h3 {
  font-size: 21px;
}

