/* =========================================================
   Design Tokens
   ========================================================= */
:root {
  /* Brand and surfaces */
  --color-bg: #f3f6fb;
  --color-surface: #ffffff;
  --color-surface-muted: #f8fafc;
  --color-text: #1a1a2e;
  --color-text-muted: #64748b;
  --color-border: #dbe3ee;
  --color-primary: #2563eb;
  --color-primary-strong: #1d4ed8;
  --color-secondary: #64748b;
  --color-success: #15803d;
  --color-danger: #b91c1c;
  --color-warning: #b45309;

  /* Type scale */
  --font-family-base: "Segoe UI", system-ui, sans-serif;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.75rem;
  --line-height-base: 1.5;
  --line-height-tight: 1.3;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;

  /* Radius and shadows */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.1);

  /* Safe area */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

/* =========================================================
   Base / Reset
   ========================================================= */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
}

body {
  font-family: var(--font-family-base);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  background: var(--color-bg);
  color: var(--color-text);
  overflow-x: clip;
}

img,
svg,
canvas {
  max-width: 100%;
}

h1,
h2,
h3 {
  line-height: var(--line-height-tight);
}

h1 {
  margin-top: 0;
  font-size: clamp(1.5rem, 2.4vw, 2rem);
}

/* =========================================================
   Global Layout / Navigation
   ========================================================= */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  padding: max(var(--space-2), var(--safe-top)) calc(var(--space-4) + var(--safe-right))
    var(--space-2) calc(var(--space-4) + var(--safe-left));
  background: var(--color-text);
  color: #fff;
}
.navbar a { color: #e2e8f0; text-decoration: none; margin-left: 0; }
.nav-links { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); width: 100%; }
.nav-links a { margin-left: 0; }
.navbar a:hover { color: #fff; }
.brand { font-weight: 700; font-size: var(--font-size-lg); margin-left: 0 !important; }

.container {
  max-width: 1100px;
  width: 100%;
  margin: var(--space-5) auto;
  padding: 0 calc(var(--space-4) + var(--safe-right)) 0 calc(var(--space-4) + var(--safe-left));
}

/* =========================================================
   Core Surfaces
   ========================================================= */
.auth-card {
  max-width: 400px;
  margin: 60px auto;
  background: var(--color-surface);
  padding: var(--space-8);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}
.auth-card-wide {
  max-width: 560px;
}
.auth-alt-link {
  margin-top: 1.25rem;
  text-align: center;
  font-size: 0.95rem;
}
.form-section-title {
  margin: 1.5rem 0 0.75rem;
  font-size: 1rem;
  color: #334155;
}
.form-section-title:first-of-type {
  margin-top: 0;
}
.pending-clients-section {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 16px 20px;
  margin: 20px 0;
}
.pending-approval-banner a {
  color: inherit;
  font-weight: 600;
}
.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 12px;
}
.table-wrap .table {
  margin-top: 0;
  min-width: 520px;
}
.table-actions-cell {
  white-space: nowrap;
}
.table-actions-cell .inline-form {
  display: inline-block;
  margin: 0 4px 4px 0;
}
/* =========================================================
   Core Form Controls / Buttons
   ========================================================= */
.input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  margin: 4px 0 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  line-height: 1.3;
  background: var(--color-surface);
  color: var(--color-text);
}
.btn {
  display: inline-block;
  min-height: 44px;
  padding: 10px 16px;
  background: #e0e0e0;
  color: #333;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  font-size: 0.95rem;
  line-height: 1.2;
  font-weight: 600;
}
.btn-primary { background: var(--color-primary); color: white; }
.btn-secondary { background: var(--color-secondary); color: white; }
.btn-danger { background: #dc2626; color: white; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.btn-sm { padding: 2px 8px; font-size: 0.85rem; }
.entry-move-form {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.entry-global-pos {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.6rem;
  height: 1.6rem;
  border-radius: 4px;
  background: #eef2f7;
  font-weight: 600;
  font-size: 0.85rem;
}
.entry-move-input {
  width: 3.2rem;
  min-width: 3.2rem;
  padding: 2px 6px;
  text-align: center;
}
.entry-move-action {
  width: auto;
  min-width: 5.5rem;
  padding: 2px 6px;
  font-size: 0.85rem;
}
.entry-move-sep {
  color: #6c757d;
  font-size: 0.85rem;
}
.entry-pos-cell {
  font-weight: 600;
  white-space: nowrap;
}
.entry-actions-cell {
  min-width: 12rem;
}
.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; }
.alert-success { background: #d1fae5; color: #065f46; }
.alert-danger { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef3c7; color: #92400e; }

/* =========================================================
   Core Data Display
   ========================================================= */
.table { width: 100%; background: white; border-collapse: collapse; border-radius: 8px; overflow: hidden; margin-top: 12px; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid #eee; text-align: left; }
.table th { background: #f8fafc; }
.stats-grid { display: grid; grid-template-columns: 1fr; gap: 16px; margin: 20px 0; }
.stat-card { background: white; padding: 20px; border-radius: 8px; text-align: center; }
.stat-value { display: block; font-size: 2rem; font-weight: 700; color: #2563eb; }
.profile-section { background: white; padding: 24px; border-radius: 8px; margin-bottom: 20px; }
.profile-section h2 { margin-top: 0; font-size: 1.1rem; }
.profile-dl { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; margin: 0; }
.profile-dl dt { font-weight: 600; color: #555; }
.profile-dl dd { margin: 0; }
.profile-form { max-width: 400px; }
.client-features-form { max-width: 520px; }
.client-features-form .checkbox-label { margin: 10px 0; }
.form-hint { font-size: 0.85rem; color: #666; margin: -8px 0 12px; }
.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}
.field-label-row label { margin-bottom: 0; }
.exercise-ai-description-loading { font-size: 0.9rem; color: #555; margin: 0.25rem 0 0.5rem; }
.exercise-ai-description-error { margin: 0.25rem 0 0.75rem; }
.stat-label { color: #666; }

/* =========================================================
   Dashboard / Home
   ========================================================= */
.client-home-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin: 20px 0;
}
.client-home-stack {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin: 20px 0;
}
.client-home-row {
  min-width: 0;
}
.client-home-top {
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr;
  gap: 20px;
  margin: 20px 0 0;
  align-items: stretch;
}
.client-home-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 768px) {
  .client-home-charts {
    grid-template-columns: 1fr;
  }
}
.dashboard-card {
  background: white;
  border-radius: 8px;
  padding: 20px 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.dashboard-card-profile {
  padding: 20px 24px;
}
.dashboard-card-profile .profile-compact-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 4px 24px;
}
.dashboard-card-profile .profile-compact-list li {
  border-bottom: none;
  padding: 10px 0;
}
.dashboard-card-profile .profile-compact-list li.profile-compact-bmi {
  grid-column: 1 / -1;
}
.dashboard-card-profile .dashboard-card-title {
  font-size: 1.05rem;
  margin-bottom: 12px;
}
.dashboard-card-plans {
  min-width: 0;
}
.dashboard-card-chart {
  min-width: 0;
}
.dashboard-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.dashboard-card-header .dashboard-card-title { margin-bottom: 0; }
.dashboard-card-link {
  font-size: 0.85rem;
  white-space: nowrap;
}
.dashboard-card-title {
  margin: 0 0 16px;
  font-size: 1.05rem;
}
.dashboard-card-tabbar {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 12px;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 8px;
}
.dashboard-card-tab {
  background: transparent;
  border: none;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  border-radius: 4px 4px 0 0;
}
.dashboard-card-tab.is-active {
  color: #2563eb;
  background: #eff6ff;
}
.dashboard-card-panel[hidden] { display: none !important; }
.card-eval-panel { margin-top: 0.25rem; }
.card-eval-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
}
.card-eval-quota-hint { margin: 0; font-size: 0.8rem; }
.llm-quota-hint {
  padding: 0.5rem 0.75rem;
  background: #eff6ff;
  border-radius: 6px;
}
.llm-quota-exhausted {
  background: #fef2f2;
  color: #991b1b;
}
.card-eval-subtitle {
  font-size: 0.95rem;
  margin: 1rem 0 0.5rem;
}
.card-eval-text,
.card-eval-history-text {
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 0.9rem;
}
.card-eval-latest .card-eval-text {
  padding: 0.75rem 1rem;
  background: #f8f9fa;
  border-radius: 6px;
}
.card-eval-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.card-eval-history-item {
  padding: 0.75rem 0;
  border-bottom: 1px solid #eee;
}
.card-eval-history-item:last-child { border-bottom: none; }
.card-eval-history-date {
  display: block;
  font-size: 0.8rem;
  color: #64748b;
  margin-bottom: 0.35rem;
}
.card-eval-loading { font-size: 0.9rem; color: #555; }
.card-eval-history-table { font-size: 0.85rem; margin-top: 0.5rem; }
.card-eval-history-table th { font-size: 0.75rem; white-space: nowrap; }
.card-eval-stars-cell { white-space: nowrap; }
.card-eval-actions-cell { text-align: right; }
.star-rating { display: inline-flex; gap: 1px; letter-spacing: 0; }
.star-rating .star { color: #cbd5e1; font-size: 0.95rem; line-height: 1; }
.star-rating .star.is-filled { color: #f59e0b; }
.card-eval-latest-stars { display: flex; flex-wrap: wrap; gap: 0.75rem; margin: 0.35rem 0 0.5rem; }
.card-eval-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.card-eval-modal.hidden { display: none !important; }
.card-eval-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}
.card-eval-modal-box {
  position: relative;
  background: #fff;
  border-radius: 8px;
  max-width: 640px;
  width: 100%;
  max-height: min(80vh, 560px);
  overflow: auto;
  padding: 1rem 1.25rem 1.25rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}
.card-eval-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.card-eval-modal-header h3 { margin: 0; font-size: 1.1rem; }
.card-eval-modal-close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: #64748b;
  padding: 0.25rem 0.5rem;
}
.card-eval-modal-stars {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0.5rem 0 0.75rem;
  font-size: 0.85rem;
}
.card-eval-modal-star-col { display: inline-flex; align-items: center; gap: 0.35rem; }
.card-eval-modal-text {
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 0.92rem;
  padding: 0.75rem 1rem;
  background: #f8f9fa;
  border-radius: 6px;
}
body.card-eval-modal-open { overflow: hidden; }

.app-dialog {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.app-dialog.hidden { display: none !important; }
.app-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}
.app-dialog-box {
  position: relative;
  background: #fff;
  border-radius: 8px;
  max-width: 440px;
  width: 100%;
  padding: 1rem 1.25rem 1.25rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}
.app-dialog-header h3 {
  margin: 0;
  font-size: 1.1rem;
}
.app-dialog-body {
  margin-top: 0.75rem;
  line-height: 1.5;
  color: #334155;
  white-space: pre-wrap;
}
.app-dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.25rem;
}
body.app-dialog-open { overflow: hidden; }

.profile-bmi-hint { margin-top: 0.5rem; }
.bmi-thresholds {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0.5rem 0.6rem;
  font-size: 0.8rem;
  color: #475569;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
}
.bmi-threshold-item {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 2px 0;
}
.bmi-threshold-item.is-active .bmi-threshold-label {
  color: #2563eb;
  font-weight: 600;
}
.bmi-threshold-item.is-active .bmi-threshold-range {
  color: #2563eb;
}
.profile-bmi-thresholds-wrap {
  margin-top: 0.35rem;
  width: 100%;
}
.profile-bmi-thresholds-wrap .bmi-thresholds {
  margin-top: 0.25rem;
}
.profile-section .bmi-thresholds {
  max-width: 320px;
  margin-bottom: 0.75rem;
}

.profile-compact-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.profile-compact-list li {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.9rem;
}
.profile-compact-list li:last-child { border-bottom: none; padding-bottom: 0; }
.profile-compact-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.profile-compact-value {
  line-height: 1.3;
  word-break: break-word;
}
.dashboard-profile-dl { margin-bottom: 0; }
.dashboard-card-footer {
  margin: 16px 0 0;
  padding-top: 12px;
  border-top: 1px solid #eee;
  font-size: 0.9rem;
}
.dashboard-card-footer.compact {
  margin-top: 10px;
  padding-top: 8px;
  font-size: 0.85rem;
}
.active-plans-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.active-plan-line {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #eee;
  flex-wrap: nowrap;
  min-width: 0;
}
.active-plan-line:last-child { border-bottom: none; padding-bottom: 0; }
.active-plan-line:first-child { padding-top: 0; }
.active-plan-title {
  font-weight: 600;
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.active-plan-period {
  flex: 0 0 auto;
  font-size: 0.85rem;
  white-space: nowrap;
}
.active-plan-actions {
  display: flex;
  flex-shrink: 0;
  gap: 8px;
  margin-left: auto;
}
.chart-wrap-dashboard {
  height: 220px;
}
.dashboard-card-load-stats {
  margin: 0 0 20px;
}
.stats-card-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.tab-bar {
  display: flex;
  gap: 4px;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 8px;
}
.tab-btn {
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: #64748b;
}
.tab-btn.is-active {
  background: white;
  color: #1a1a2e;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.stats-view-label { margin: 0; }
.stats-view-select {
  width: auto;
  min-width: 130px;
  margin: 0;
  padding: 6px 10px;
  font-size: 0.9rem;
}
.stats-load-table { margin-top: 0; }
.stats-load-table th:last-child,
.stats-load-table td:last-child { text-align: right; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
@media (max-width: 900px) {
  .client-home-top { grid-template-columns: 1fr; }
  .client-home-charts { grid-template-columns: 1fr; }
  .active-plan-line { flex-wrap: wrap; }
  .active-plan-period { flex-basis: 100%; padding-left: 0; }
  .active-plan-actions { margin-left: 0; }
}
@media (max-width: 768px) {
  .client-home-grid { grid-template-columns: 1fr; }
}

/* =========================================================
   Exercise Library
   ========================================================= */
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 24px; }
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 20px; }
.exercise-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.exercise-card {
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s;
  outline: none;
}
.exercise-card:hover,
.exercise-card:focus-visible {
  box-shadow: 0 4px 14px rgba(0,0,0,.1);
  transform: translateY(-1px);
}
.exercise-card.is-expanded {
  box-shadow: 0 6px 18px rgba(0,0,0,.12);
}
.exercise-card img { width: 100%; height: 140px; object-fit: cover; pointer-events: none; }
.exercise-card .no-image { height: 140px; background: #eee; display: flex; align-items: center; justify-content: center; color: #999; font-size: 0.85rem; pointer-events: none; }
.exercise-card h3 { font-size: 0.95rem; margin: 8px 0 4px; }
.exercise-card .exercise-meta { font-size: 0.8rem; color: #666; margin: 0 0 8px; }
.exercise-stat-badge {
  display: inline-block;
  margin: 0 0 8px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #1d4ed8;
  background: #eff6ff;
  border-radius: 999px;
}
.exercise-library-filter { margin-bottom: 16px; }
.exercise-images-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.exercise-image-item {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px;
  background: #fafafa;
  text-align: center;
  max-width: 200px;
}
.exercise-image-item img {
  display: block;
  max-width: 180px;
  max-height: 180px;
  margin: 0 auto 8px;
  object-fit: contain;
}
.exercise-image-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
}
.exercise-upload-preview-item {
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  padding: 8px;
  max-width: 180px;
  text-align: center;
}
.exercise-upload-preview-item img {
  display: block;
  max-width: 160px;
  max-height: 160px;
  margin: 0 auto 6px;
  object-fit: contain;
}
.exercise-upload-preview-name {
  margin: 0 0 6px;
  word-break: break-word;
}
.exercise-grid-empty { grid-column: 1 / -1; color: #666; }
.exercise-card-body { padding: 0 12px 12px; }
.exercise-description-wrap { margin-bottom: 8px; }
.exercise-description {
  font-size: 0.85rem;
  line-height: 1.45;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-line;
}
.exercise-card.is-expanded .exercise-description {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
}
.exercise-description-hint {
  font-size: 0.75rem;
  margin: 6px 0 0;
}
.exercise-card.is-expanded .exercise-description-hint,
.exercise-card[data-has-description="0"] .exercise-description-hint {
  display: none;
}
.exercise-description-empty { font-style: italic; }
.card-actions { margin-top: 8px; }
.card-actions .btn { pointer-events: auto; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 16px; }
.danger-zone { margin-top: 32px; padding-top: 16px; border-top: 1px solid #eee; }
.current-image { margin-bottom: 16px; }
.current-image form { margin-top: 8px; }
.image-paste-zone {
  border: 2px dashed var(--border, #ccc);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  background: var(--surface-alt, #fafafa);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.image-paste-zone:focus,
.image-paste-zone.paste-focus,
.image-paste-zone.drag-over {
  border-color: var(--primary, #2563eb);
  background: var(--surface-focus, #eff6ff);
}
.image-paste-zone.has-image { border-style: solid; }
.image-paste-hint { margin: 0 0 10px; }
.image-paste-hint kbd {
  padding: 2px 6px;
  border: 1px solid var(--border, #ccc);
  border-radius: 4px;
  background: #fff;
  font-size: 0.85em;
}
.paste-preview { margin-top: 12px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.paste-feedback { margin: 10px 0 0; font-size: 0.9rem; }
.paste-feedback-ok { color: var(--success, #15803d); }
.paste-feedback-error { color: var(--danger, #b91c1c); }
.pdf-download-form {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.checkbox-label-inline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  margin: 0;
  white-space: nowrap;
  cursor: pointer;
}
.checkbox-label-inline input { margin: 0; cursor: pointer; }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 12px;
  font-size: 0.95rem;
}

/* =========================================================
   Plan Editor / Trainer Workflows
   ========================================================= */
.entry-edit-form { background: white; padding: 20px; border-radius: 8px; }
.day-tabs { display: flex; gap: 8px; margin: 20px 0; flex-wrap: wrap; }
.day-tab { padding: 6px 12px; background: white; border-radius: 4px; text-decoration: none; color: #333; border: 1px solid #ddd; }
.day-section { background: white; padding: 20px; border-radius: 8px; margin-bottom: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.entry-form-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.entry-form-row > div { flex: 1; min-width: 140px; }
.preview-img { max-width: 120px; max-height: 120px; border-radius: 4px; }
.hidden { display: none !important; }
.badge { background: #e67e22; color: white; padding: 2px 6px; border-radius: 3px; font-size: 0.75rem; }
.table-thumb { width: 36px; height: 36px; object-fit: cover; border-radius: 4px; vertical-align: middle; margin-right: 6px; }
.pyramid-list { margin: 4px 0 0 0; padding-left: 18px; font-size: 0.85rem; color: #555; }
.backup-section { margin-top: 32px; background: white; padding: 16px; border-radius: 8px; }
.plan-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.template-section {
  background: white;
  padding: 16px 20px;
  border-radius: 8px;
  margin-bottom: 20px;
}
.template-section h2 { margin-top: 0; font-size: 1.1rem; }
.template-actions { display: flex; flex-direction: column; gap: 12px; }
.template-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.template-form .input { flex: 1; min-width: 180px; max-width: 320px; margin: 0; }
.template-list { list-style: none; padding: 0; margin: 12px 0 0; }
.template-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #eee;
}
.inline-form { display: inline; margin-left: auto; }
.section-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.section-header-row h2 { margin: 0; }
.plan-view-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}
.client-plans-table { margin-top: 0; }
.plan-trainer-summary .trainer-summary-block {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  margin: 0;
  padding: 12px;
  background: #f8fafc;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
}
.plan-actions-cell { white-space: nowrap; }
.plan-actions-cell .inline-form { margin-left: 6px; }
.plan-actions-cell .btn { margin-right: 4px; }
.rename-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.input-inline { width: auto; min-width: 160px; max-width: 280px; margin: 0; padding: 4px 8px; font-size: 0.9rem; }
.small { font-size: 0.8rem; }
.template-notes-row td { background: #fafafa; padding-top: 0; border-top: none; }
.muted { color: #666; font-size: 0.9rem; }
.entry-superset { background: #fffbeb; }
.plan-view-header { margin-bottom: 20px; }
.plan-day-section { margin-bottom: 24px; }
.plan-progress-table th,
.plan-progress-table td { vertical-align: top; }
.progress-stat { white-space: nowrap; font-weight: 600; color: #2563eb; }
.progress-row td { background: #f8fafc; border-top: none; padding-top: 0; }
.progress-details summary { cursor: pointer; font-size: 0.9rem; color: #2563eb; padding: 6px 0; }
.progress-panel { padding: 12px 0 4px; }
.progress-form { margin-bottom: 12px; }
.progress-form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 8px; }
.progress-form-actions { margin-bottom: 12px; }
.progress-log-list { list-style: none; padding: 0; margin: 0; }
.progress-log-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #eee;
  font-size: 0.9rem;
}
.progress-log-meta { flex: 1; min-width: 200px; }
.new-muscle-field,
.new-exercise-field {
  margin-top: 8px;
}
.field-sublabel {
  display: block;
  font-size: 0.8rem;
  color: #64748b;
  margin: 6px 0 4px;
}
.entry-field-muscle,
.entry-field-exercise {
  flex: 1;
  min-width: 180px;
}
.plan-exercise-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.plan-exercise-card {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 14px 16px;
  background: #fff;
}
.plan-exercise-card.entry-superset {
  background: #fffbeb;
  border-color: #fde68a;
}
.plan-exercise-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.plan-exercise-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}
.plan-exercise-info { flex: 1; min-width: 0; }
.plan-exercise-name {
  margin: 0 0 4px;
  font-size: 1rem;
  line-height: 1.3;
}
.plan-exercise-params {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin: 0;
  font-size: 0.85rem;
  color: #64748b;
}
.plan-exercise-stats {
  display: flex;
  gap: 10px;
  margin: 0;
  padding: 0;
  flex-shrink: 0;
}
.plan-exercise-stats div {
  text-align: center;
  min-width: 52px;
}
.plan-exercise-stats dt {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: #94a3b8;
  margin: 0;
}
.plan-exercise-stats dd {
  margin: 2px 0 0;
  font-weight: 700;
  color: #2563eb;
  font-size: 0.95rem;
}
.progress-log-section {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid #e2e8f0;
}
.progress-log-title {
  margin: 0 0 10px;
  font-size: 0.95rem;
  color: #334155;
}
.progress-form-quick { margin-bottom: 0; }
.progress-form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px 12px;
  align-items: end;
}
.progress-field label {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 4px;
  color: #475569;
}
.progress-field-notes { grid-column: 1 / -1; }
.progress-field-submit { grid-column: 1 / -1; }
.weight-stepper {
  display: flex;
  align-items: stretch;
  gap: 6px;
}
.weight-step-btn {
  flex: 0 0 40px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  border-radius: 8px;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  color: #334155;
}
.weight-step-btn:hover { background: #e2e8f0; }
.weight-stepper .progress-weight-input {
  flex: 1;
  min-width: 0;
  margin: 0;
  text-align: center;
  font-weight: 600;
}
.progress-hint { margin: 4px 0 0; }
.progress-history-details summary {
  cursor: pointer;
  color: #2563eb;
  font-size: 0.9rem;
  padding: 8px 0 4px;
}
.progress-empty-hint { margin: 8px 0 0; }

/* =========================================================
   Client Personal Area
   ========================================================= */
.personal-section {
  background: white;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 24px;
}
.personal-section h2 { margin-top: 0; font-size: 1.15rem; }
.personal-section h3 { font-size: 1rem; margin-top: 0; }
.personal-area-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 20px;
  padding: 4px;
  background: #e2e8f0;
  border-radius: 8px;
}
.personal-area-tab {
  padding: 8px 16px;
  border-radius: 6px;
  text-decoration: none;
  color: #334155;
  font-weight: 600;
  font-size: 0.9rem;
}
.personal-area-tab:hover {
  background: rgba(255, 255, 255, 0.6);
  color: #1e293b;
}
.personal-area-tab:target,
.personal-area-tab:focus-visible {
  background: white;
  color: #2563eb;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
#schede:target,
#grafici:target,
#metriche:target {
  scroll-margin-top: 80px;
  outline: 2px solid #2563eb33;
  outline-offset: 4px;
}
.plan-type-filters { margin-bottom: 12px; }
.filter-tab {
  padding: 6px 12px;
  background: #f1f5f9;
  border-radius: 20px;
  text-decoration: none;
  color: #334155;
  font-size: 0.9rem;
  border: 1px solid #e2e8f0;
}
.filter-tab:hover { background: #e2e8f0; color: #1e293b; }
.filter-tab.is-active {
  background: #2563eb;
  color: white;
  border-color: #2563eb;
}
.plan-type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.plan-type-forza { background: #fee2e2; color: #991b1b; }
.plan-type-ipertrofia { background: #dbeafe; color: #1e40af; }
.plan-type-resistenza { background: #d1fae5; color: #065f46; }
.plan-type-definizione { background: #ede9fe; color: #5b21b6; }
.plan-type-generale { background: #f1f5f9; color: #475569; }
.plan-type-recupero { background: #cffafe; color: #0e7490; }
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}
.status-active { background: #d1fae5; color: #065f46; }
.status-past { background: #f1f5f9; color: #64748b; }
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.chart-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px;
}
.chart-card-wide { grid-column: 1 / -1; }
.chart-card h3 { margin: 0 0 8px; font-size: 0.95rem; }
.chart-wrap { position: relative; height: 220px; }
.chart-empty {
  margin: 0;
  padding: 24px 12px;
  text-align: center;
  color: #64748b;
  font-size: 0.9rem;
}
.metrics-layout {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 20px;
  align-items: start;
}
.metric-form { margin-bottom: 0; }
.metric-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.metric-form-grid .metric-field label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 4px;
  color: #475569;
}
.metric-form-grid .input {
  margin-bottom: 0;
}
.metric-field-date { grid-column: 1 / -1; }
.metric-field-weight { grid-column: 1 / -1; }
.metric-field-notes { grid-column: 1 / -1; }
.metric-field-submit { grid-column: 1 / -1; }
.metric-weight-input {
  text-align: center;
  font-weight: 600;
  font-size: 1.05rem;
}
.metric-submit-btn { width: auto; }
.metrics-history h3 { margin-top: 0; }
.metrics-history-mobile {
  display: none;
  list-style: none;
  margin: 0;
  padding: 0;
}
.metric-history-card {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px 14px;
  background: #fff;
}
.metric-history-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.metric-history-date { font-size: 0.95rem; }
.metric-history-dl {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 10px;
  margin: 0;
}
.metric-history-dl dt {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #94a3b8;
  margin: 0;
}
.metric-history-dl dd {
  margin: 2px 0 0;
  font-weight: 600;
  font-size: 0.9rem;
}
.metric-history-notes { margin: 10px 0 0; }
.metric-notes-row td { background: #fafafa; padding-top: 0; border-top: none; }
.metrics-history-table { font-size: 0.9rem; }
@media (max-width: 768px) {
  .metrics-layout { grid-template-columns: 1fr; gap: 16px; }
  .metric-form-grid { grid-template-columns: 1fr 1fr; }
  .metric-field-weight,
  .metric-field-date,
  .metric-field-notes,
  .metric-field-submit {
    grid-column: 1 / -1;
  }
  .metric-weight-input { font-size: 1.15rem; padding: 10px 8px; }
  .metric-submit-btn {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
  }
  .metrics-history-desktop { display: none; }
  .metrics-history-mobile {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .metric-history-dl { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .charts-grid { grid-template-columns: 1fr; }
  .chart-wrap { height: 200px; min-width: 0; }
  .chart-wrap-dashboard { height: 200px; min-width: 0; }
  .dashboard-card { padding: 14px 16px; }
  .dashboard-card-tab {
    flex: 1;
    text-align: center;
    padding: 8px 6px;
    font-size: 0.85rem;
  }
  .dashboard-card-footer.compact {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  .dashboard-card-footer.compact a { display: block; }
  .dashboard-card-profile .profile-compact-list {
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
  }
  .dashboard-card-profile .profile-compact-list li.profile-compact-bmi {
    grid-column: 1 / -1;
  }
  .personal-area-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .personal-area-tab { flex-shrink: 0; }
  .personal-section { padding: 14px 16px; }
  .plan-type-filters { gap: 6px; }
  .navbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }
  .nav-links {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px 12px;
  }
  .container { padding: 12px; max-width: 100%; overflow-x: hidden; }
  .day-section { padding: 14px; }
  .entry-form-row > div,
  .entry-field-muscle,
  .entry-field-exercise {
    flex: 1 1 100%;
    min-width: 0;
  }
  .day-toggle-form {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .day-toggle-form input[type="text"],
  .day-toggle-form input[type="date"] {
    width: 100%;
  }
  .entries-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .form-grid { grid-template-columns: 1fr; }
  .plan-actions { gap: 8px; }
  .plan-exercise-head { flex-direction: column; }
  .plan-exercise-stats {
    width: 100%;
    justify-content: space-between;
  }
  .progress-form-grid {
    grid-template-columns: 1fr 1fr;
  }
  .progress-field-weight,
  .progress-field-notes,
  .progress-field-submit {
    grid-column: 1 / -1;
  }
  .progress-submit-btn {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
  }
  .weight-stepper .progress-weight-input {
    font-size: 1.15rem;
    padding: 10px 8px;
  }
}

/* Chat assistente IA */
.chat-limit-hint { margin-bottom: 1.25rem; }
.chat-list-header { margin-top: 1.5rem; }
.chat-conversation-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.chat-conversation-item {
  display: flex;
  align-items: stretch;
  gap: 0.75rem;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 8px;
  margin-bottom: 0.75rem;
  overflow: hidden;
}
.chat-conversation-link {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.85rem 1rem;
  text-decoration: none;
  color: inherit;
}
.chat-conversation-link:hover {
  background: var(--surface-muted, #f8fafc);
}
.chat-conversation-title {
  font-weight: 600;
}
.chat-conversation-preview {
  font-size: 0.9rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.chat-conversation-meta { font-size: 0.8rem; }
.chat-delete-form {
  display: flex;
  align-items: center;
  padding-right: 0.75rem;
}
.chat-empty-state { margin-top: 1rem; }
.chat-breadcrumb {
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}
.chat-breadcrumb a { color: inherit; }
.chat-conversation-header { margin-bottom: 1rem; }
.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: min(60vh, 520px);
  overflow-y: auto;
  padding: 1rem;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 8px;
  background: var(--surface-muted, #f8fafc);
  margin-bottom: 1.25rem;
}
.chat-bubble {
  max-width: 85%;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  line-height: 1.45;
}
.chat-bubble-user {
  align-self: flex-end;
  background: var(--primary, #2563eb);
  color: #fff;
}
.chat-bubble-user .chat-bubble-role { color: rgba(255, 255, 255, 0.85); }
.chat-bubble-assistant {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--border-color, #e2e8f0);
}
.chat-bubble-role {
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.chat-bubble-content {
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-empty-thread { margin: 0; }
.chat-compose textarea.chat-message-input {
  min-height: 4.5rem;
  resize: vertical;
}
.chat-form .form-actions { margin-top: 0.75rem; }

/* Agenda allenamenti */
.agenda-form-section,
.agenda-history-section {
  margin-top: 2rem;
}
.agenda-form textarea.input,
.agenda-content-input {
  min-height: 10rem;
  resize: vertical;
}
.agenda-history-table { font-size: 0.9rem; }
.agenda-history-actions {
  white-space: nowrap;
}
.agenda-history-actions .inline-form {
  display: inline;
}
.agenda-history-mobile {
  display: none;
  list-style: none;
  margin: 0;
  padding: 0;
}
.agenda-history-card {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px 14px;
  background: #fff;
}
.agenda-history-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 12px;
  margin-bottom: 8px;
}
.agenda-history-card-date { font-size: 0.95rem; }
.agenda-history-card-stars {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  font-size: 0.85rem;
  margin-bottom: 10px;
}
.agenda-history-card-stars > span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.agenda-history-no-ai { margin: 0 0 10px; }
.agenda-history-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.agenda-modal-section { margin-top: 1rem; }
.agenda-modal-section-title {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #64748b;
}
.agenda-modal-content,
.agenda-modal-ai-text,
.agenda-modal-comparison-text {
  white-space: pre-wrap;
}
.agenda-modal-comparison {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px dashed #cbd5e1;
}
.agenda-comparison-title {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: #475569;
}
.agenda-modal-box { max-height: min(90vh, 640px); overflow-y: auto; }
@media (max-width: 768px) {
  .agenda-history-desktop { display: none; }
  .agenda-history-mobile {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .agenda-history-card-actions .btn-sm {
    flex: 1;
    min-width: 0;
    text-align: center;
  }
}

/* Nutrizione / diario alimentare */
.nutrition-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin: 1.25rem 0 1.5rem;
}
.nutrition-stat-card {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nutrition-stat-label {
  font-size: 0.8rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.nutrition-stat-value {
  font-size: 1.25rem;
  color: #0f172a;
}
.nutrition-macro-line {
  font-size: 0.95rem;
}
.nutrition-section {
  margin-top: 2rem;
}
.nutrition-section h2 {
  margin-bottom: 0.75rem;
}
.nutrition-profile-form,
.nutrition-log-form {
  max-width: 32rem;
}
.nutrition-log-form {
  position: relative;
}
.food-search-results {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  max-width: 32rem;
  max-height: 240px;
  overflow-y: auto;
  background: white;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  margin-top: 4px;
}
.food-search-results button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: #0f172a;
}
.food-search-results button:hover,
.food-search-results button:focus-visible {
  background: #f1f5f9;
}
.food-search-results .food-search-meta {
  display: block;
  font-size: 0.8rem;
  color: #64748b;
  margin-top: 2px;
}
.nutrition-log-table,
.nutrition-history-table {
  font-size: 0.9rem;
}
.section-header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 0.75rem;
}
.text-danger {
  color: #dc2626;
}

/* === Client mobile === */

/* ── Touch targets ────────────────────────────────────────────── */
/* Small buttons: usable minimum height */
.btn-sm {
  min-height: 36px;
}
/* Modal close button: larger tap target */
.card-eval-modal-close {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

/* ── Form actions block (submit + cancel stacked) ─────────────── */
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
  align-items: center;
}

@media (max-width: 640px) {
  /* ── Page title sizing ────────────────────────────────────── */
  h1 { font-size: 1.45rem; }

  /* ── Personal area tabs: breathing room ───────────────────── */
  .personal-area-tabs {
    padding-bottom: 6px;
    gap: 6px;
  }
  .personal-area-tab {
    padding: 8px 14px;
    font-size: 0.88rem;
  }

  /* ── Section header row: stack on narrow screens ──────────── */
  .section-header-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  .section-header-row h2 { margin: 0; }

  /* ── Nutrition summary: 2×2 grid, macro card full-width ───── */
  .nutrition-summary-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .nutrition-stat-card:last-child {
    grid-column: 1 / -1;
  }
  .nutrition-stat-value {
    font-size: 1.05rem;
  }
  .nutrition-macro-line {
    font-size: 0.85rem;
  }

  /* ── Nutrition forms: expand to full width ─────────────────── */
  .nutrition-profile-form,
  .nutrition-log-form {
    max-width: 100%;
  }
  .food-search-results {
    max-width: 100%;
  }

  /* ── Nutrition log table → card layout ────────────────────── */
  .nutrition-log-table,
  .nutrition-log-table thead,
  .nutrition-log-table tbody,
  .nutrition-log-table tr {
    display: block;
  }
  /* Override table-wrap min-width for this specific table */
  .table-wrap .nutrition-log-table {
    min-width: 0;
  }
  .nutrition-log-table thead {
    display: none;
  }
  .nutrition-log-table tbody {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .nutrition-log-table tr {
    position: relative;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    padding: 12px 52px 12px 14px;
  }
  .nutrition-log-table td {
    display: block;
    padding: 1px 0;
    border: none;
  }
  /* Meal type: small accent label */
  .nutrition-log-table td:nth-child(1) {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #2563eb;
    margin-bottom: 3px;
  }
  /* Food name: primary text */
  .nutrition-log-table td:nth-child(2) {
    font-size: 0.95rem;
    font-weight: 500;
    color: #0f172a;
    margin-bottom: 4px;
  }
  /* Quantity + kcal + macros: flow on one line */
  .nutrition-log-table td:nth-child(3),
  .nutrition-log-table td:nth-child(4),
  .nutrition-log-table td:nth-child(5),
  .nutrition-log-table td:nth-child(6),
  .nutrition-log-table td:nth-child(7) {
    display: inline;
    font-size: 0.8rem;
    color: #475569;
    padding: 0;
  }
  .nutrition-log-table td:nth-child(4)::before { content: " · "; }
  .nutrition-log-table td:nth-child(4)::after  { content: " kcal"; }
  .nutrition-log-table td:nth-child(5)::before { content: " · P "; }
  .nutrition-log-table td:nth-child(5)::after  { content: "g"; }
  .nutrition-log-table td:nth-child(6)::before { content: " G "; }
  .nutrition-log-table td:nth-child(6)::after  { content: "g"; }
  .nutrition-log-table td:nth-child(7)::before { content: " C "; }
  .nutrition-log-table td:nth-child(7)::after  { content: "g"; }
  /* Delete button: absolute top-right */
  .nutrition-log-table td:nth-child(8) {
    position: absolute;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    padding: 0;
  }

  /* ── Agenda quota hint: compact on mobile ──────────────────── */
  .agenda-quota-hint { font-size: 0.85rem; }

  /* ── Agenda form actions: stacked full-width buttons ──────── */
  .form-actions {
    flex-direction: column;
    gap: 8px;
  }
  .form-actions .btn {
    display: block;
    width: 100%;
    text-align: center;
    box-sizing: border-box;
  }
  /* Standalone submit in agenda new-entry form */
  .agenda-form-section .agenda-form > input[type="submit"],
  .agenda-form-section .agenda-form > .btn {
    display: block;
    width: 100%;
    text-align: center;
    box-sizing: border-box;
  }

  /* ── Agenda history: better action button targets ─────────── */
  .agenda-history-card-actions .btn-sm {
    min-height: 40px;
    flex: 1;
    text-align: center;
  }

  /* ── Agenda modal: bottom-sheet on mobile ─────────────────── */
  .agenda-entry-modal {
    align-items: flex-end;
    padding: 0;
  }
  .agenda-entry-modal .card-eval-modal-box {
    width: 100%;
    max-width: 100%;
    max-height: 88vh;
    border-radius: 20px 20px 0 0;
    padding: 16px 16px 24px;
  }

  /* ── Personal section padding on mobile ────────────────────── */
  .personal-section { padding: 14px; }

  /* ── Nutrition section spacing ─────────────────────────────── */
  .nutrition-section { margin-top: 1.5rem; }
}

/* Workout session flow */
.workout-day-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}
.workout-day-card {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 14px;
  background: #fff;
}
.workout-day-card h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}
.workout-current-card {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 14px;
  background: #f8fafc;
}
.workout-entry-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
}
.workout-entry-row {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}
.workout-entry-row h3 {
  margin: 0 0 4px;
  font-size: 0.95rem;
}
.workout-inline-form {
  margin: 8px 0 12px;
}
.workout-rest-timer {
  margin: 8px 0 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #eff6ff;
  color: #1d4ed8;
}
.workout-rest-timer.workout-rest-finished {
  background: #dcfce7;
  color: #166534;
}
.workout-set-form-grid {
  margin-bottom: 6px;
}
.workout-session-section .btn,
.workout-session-section input[type="number"],
.workout-session-section input[type="text"] {
  min-height: 46px;
}
.workout-session-section .workout-current-card .btn-primary {
  width: 100%;
}
.workout-session-section .workout-entry-row {
  padding: 12px;
}
.workout-session-header-actions,
.workout-start-alert-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.workout-session-header-actions form,
.workout-start-alert-actions form {
  margin: 0;
}
.workout-start-alert-actions {
  margin-top: 8px;
}

/* === Trainer mobile === */

/* ── Horizontal-scroll tables: scroll-shadow hint on both edges ── */
@media (max-width: 640px) {
  .table-wrap:not(.trainer-clients-wrap) {
    background-color: #fff;
    background-image:
      linear-gradient(to right, #fff 20%, transparent),
      linear-gradient(to left,  #fff 20%, transparent),
      radial-gradient(farthest-side at 0%   50%, rgba(0,0,0,.10), transparent),
      radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.10), transparent);
    background-position: left center, right center, left center, right center;
    background-size: 32px 100%, 32px 100%, 12px 100%, 12px 100%;
    background-repeat: no-repeat;
    background-attachment: local, local, scroll, scroll;
  }
}

/* ── Exercise grid: 2-col on small, 1-col on tiny phones ── */
@media (max-width: 540px) {
  .exercise-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
  }
}
@media (max-width: 380px) {
  .exercise-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Action buttons stack on phone ── */
@media (max-width: 600px) {
  .page-actions,
  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .page-actions .btn,
  .page-actions button,
  .form-actions .btn,
  .form-actions button {
    width: 100%;
    text-align: center;
    box-sizing: border-box;
  }
  .workout-session-header-actions,
  .workout-start-alert-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .workout-session-header-actions .btn,
  .workout-start-alert-actions .btn,
  .workout-session-header-actions form,
  .workout-start-alert-actions form {
    width: 100%;
  }
  .field-label-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px 0;
  }
  .field-label-row label {
    margin-bottom: 0;
  }
}

/* ── Client list: table → card layout on phone ── */
@media (max-width: 640px) {
  .trainer-clients-wrap {
    overflow-x: visible;
    background: none;
    background-color: transparent;
    margin-top: 8px;
  }
  .trainer-clients-wrap .trainer-clients-table {
    min-width: 0;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
    margin-top: 0;
  }
  .trainer-clients-table thead {
    display: none;
  }
  .trainer-clients-table tbody tr {
    display: block;
    margin-bottom: 10px;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 1px 5px rgba(0,0,0,.08);
    padding: 10px 14px;
  }
  .trainer-clients-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    padding: 5px 0;
    border: none;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.9rem;
  }
  .trainer-clients-table td:last-child {
    border-bottom: none;
    padding-top: 8px;
  }
  .trainer-clients-table td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    min-width: 90px;
    font-size: 0.78rem;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding-right: 8px;
    padding-top: 2px;
  }
  .trainer-clients-table td.table-actions-cell {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  .trainer-clients-table td.table-actions-cell::before {
    display: none;
  }
  .trainer-clients-table td.table-actions-cell .inline-form,
  .trainer-clients-table td.table-actions-cell a {
    display: inline-block;
  }
  .trainer-clients-table td.table-actions-cell .actions-sep {
    display: none;
  }
}

/* === Mobile nav === */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
}

/* Hamburger button — hidden on desktop */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: #e0e0e0;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}
.nav-toggle:focus-visible {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
}

/* Three-bar icon drawn via box-shadow */
.nav-toggle-icon {
  display: block;
  width: 22px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  position: relative;
  transition: background 0.18s ease;
}
.nav-toggle-icon::before,
.nav-toggle-icon::after {
  content: '';
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: transform 0.22s ease, top 0.22s ease;
}
.nav-toggle-icon::before { top: -7px; }
.nav-toggle-icon::after  { top:  7px; }

/* Animate bars → X when open */
.navbar.nav-open .nav-toggle-icon             { background: transparent; }
.navbar.nav-open .nav-toggle-icon::before     { top: 0; transform: rotate(45deg); }
.navbar.nav-open .nav-toggle-icon::after      { top: 0; transform: rotate(-45deg); }

@media (max-width: 767px) {
  .navbar {
    flex-wrap: wrap;
    padding: 10px 16px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    gap: 0;
  }

  .nav-toggle {
    display: flex;
  }

  /* Collapsed by default on mobile */
  .nav-links {
    display: none;
    flex-direction: column;
    width: 100%;
    gap: 0;
    margin-top: 10px;
    padding-bottom: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
  }

  /* Expanded when navbar has .nav-open */
  .navbar.nav-open .nav-links {
    display: flex;
  }

  /* Touch-friendly individual links */
  .nav-links a {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 10px 4px;
    font-size: 1rem;
    margin-left: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  }
  .nav-links a:last-child {
    border-bottom: none;
  }

  /* Give the main content a bit more breathing room under sticky header */
  .container {
    margin-top: 16px;
  }
}

/* =========================================================
   Mobile-First Accessibility & Responsive Architecture
   ========================================================= */

/* Prevent accidental horizontal scrolling on narrow devices. */
.container,
.dashboard-card,
.day-section,
.profile-section,
.personal-section,
.template-section,
.table-wrap,
.chart-wrap,
.chart-wrap-dashboard {
  min-width: 0;
}

/* Shared card surface for a cohesive design language. */
.card,
.dashboard-card,
.profile-section,
.entry-edit-form,
.day-section,
.personal-section,
.backup-section,
.template-section {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

/* Touch targets and readable controls on mobile. */
.btn,
.tab-btn,
.dashboard-card-tab,
.day-tab,
.personal-area-tab,
.filter-tab,
.weight-step-btn,
.food-search-results button {
  min-height: 44px;
}

.btn:focus-visible,
.input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(37, 99, 235, 0.35);
  outline-offset: 1px;
}

/* Default mobile layouts */
.client-home-grid,
.client-home-top,
.client-home-charts,
.metrics-layout,
.form-grid {
  grid-template-columns: 1fr;
}

.progress-form-grid {
  grid-template-columns: 1fr;
  gap: 10px;
}

.dashboard-card {
  padding: var(--space-4);
}

.dashboard-card-tabbar {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.dashboard-card-tab {
  flex: 1;
  text-align: center;
}

.table {
  font-size: var(--font-size-sm);
}

/* Tablet and up */
@media (min-width: 768px) {
  .navbar {
    flex-wrap: nowrap;
    gap: var(--space-3);
    padding: max(var(--space-3), var(--safe-top)) calc(var(--space-6) + var(--safe-right))
      var(--space-3) calc(var(--space-6) + var(--safe-left));
  }

  .nav-links {
    display: flex;
    width: auto;
    justify-content: flex-end;
  }

  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .client-home-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .client-home-top {
    grid-template-columns: minmax(180px, 240px) 1fr;
  }

  .client-home-charts {
    grid-template-columns: 1fr 1fr;
  }

  .metrics-layout {
    grid-template-columns: 1fr 1.2fr;
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .progress-form-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px 12px;
  }

  .dashboard-card {
    padding: var(--space-5) var(--space-6);
  }
}

/* Desktop and up */
@media (min-width: 1024px) {
  :root {
    --font-size-base: 1.03rem;
  }

  .container {
    margin: var(--space-6) auto;
  }

  .auth-card {
    padding: 2.25rem;
  }
}

/* =========================================================
   Auth & components
   ========================================================= */

/* ── Form groups: structured label + input pairing ──────────── */
.form-group {
  margin-bottom: var(--space-4);
}
.form-group > label {
  display: block;
  font-weight: 600;
  font-size: var(--font-size-sm);
  color: var(--color-text);
  margin-bottom: var(--space-1);
}
/* Remove default top/bottom margin from inputs nested in form-group */
.form-group > .input,
.form-group > select,
.form-group > textarea {
  margin-top: 0;
  margin-bottom: 0;
}
/* Hint text inside form-group sits just below the input */
.form-group > .form-hint {
  margin-top: var(--space-1);
  margin-bottom: 0;
}

/* ── Auth card: full-width submit button ─────────────────────── */
.auth-card .btn[type="submit"],
.auth-card input[type="submit"],
.auth-card button[type="submit"] {
  display: block;
  width: 100%;
  text-align: center;
  margin-top: var(--space-2);
}

/* ── Checkbox labels: 44 px touch target, pointer cursor ─────── */
.checkbox-label {
  min-height: 44px;
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--color-primary);
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Auth card on small screens: less side-padding ──────────── */
@media (max-width: 480px) {
  .auth-card {
    margin: var(--space-6) var(--space-4);
    padding: var(--space-6) var(--space-5);
  }
}

/* ── Profile forms: full-width submit on mobile ─────────────── */
@media (max-width: 640px) {
  .profile-form .btn[type="submit"],
  .profile-form input[type="submit"],
  .profile-form button[type="submit"],
  .client-features-form button[type="submit"] {
    display: block;
    width: 100%;
    text-align: center;
  }

  /* profile-dl stacks dt/dd on a single column */
  .profile-dl {
    grid-template-columns: 1fr;
    gap: 2px 0;
  }
  .profile-dl dt {
    margin-top: var(--space-3);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
  }
  .profile-dl dt:first-child {
    margin-top: 0;
  }
  .profile-dl dd {
    font-weight: 600;
  }

  /* Slightly tighter profile section padding */
  .profile-section {
    padding: var(--space-4);
  }

  /* Danger zone: ensure delete button is full-width */
  .danger-zone .btn-danger {
    display: block;
    width: 100%;
    text-align: center;
  }
}
