:root {
  --bg: #10130e;
  --panel: #171c13;
  --panel-alt: #1f251a;
  --panel-hover: #262e20;
  --ink: #e9eedc;
  --muted: #94a187;
  --line: #262e20;
  --accent: #c6e26a;
  --accent-ink: #12180e;
  --accent-glow: rgba(198, 226, 106, 0.2);
  --kcal: #e8b86a;
  --hr: #ef7a6a;
  --ex: #7ec8c4;
  --success: #6ae28e;
  --danger: #ef7a6a;
  --warn: #e8b86a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  --profile-avatar-bg: #26351d;
  --profile-avatar-ink: #c6e26a;
  --advice-bg: #182116;
  --workout-bg: radial-gradient(circle at 90% -10%, #273619, transparent 31%), #090d08;
  --workout-overlay: radial-gradient(circle at 50% 38%, #273a1d, #090d08 55%);
  --workout-panel: #121a10;
  --workout-line: #2b3825;
  --workout-muted: #a6b19a;
  --workout-live: #57dc86;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  /* Brand foundations (Figma SoT 8BcZze3RjCnP9H8l2Qwb7R) — additive; themes keep accents */
  --brand-navy: #201959;
  --brand-purple: #8a7ff3;
  --brand-purple-ink: #020617;
  --brand-cyan: #67e8f9;
}

:root[data-theme="gerald"] {
  color-scheme: light;
  --bg: #fff9f6;
  --panel: #ffffff;
  --panel-alt: #fff0f4;
  --panel-hover: #f9dce5;
  --ink: #3c2432;
  --muted: #7f5868;
  --line: #edbdca;
  --accent: #c33f6b;
  --accent-ink: #ffffff;
  --accent-glow: rgba(195, 63, 107, 0.24);
  --success: #237a46;
  --danger: #b52f43;
  --warn: #8a5a12;
  --shadow: 0 5px 18px rgba(126, 55, 79, 0.12);
  --profile-avatar-bg: #ffdce6;
  --profile-avatar-ink: #a72e58;
  --advice-bg: #fff0f4;
  --workout-bg: radial-gradient(circle at 90% -10%, #ffe0e8, transparent 34%), #fff9f6;
  --workout-overlay: radial-gradient(circle at 50% 38%, #ffe3eb, #fff9f6 58%);
  --workout-panel: #ffffff;
  --workout-line: #edbdca;
  --workout-muted: #7f5868;
  --workout-live: #237a46;
  --brand-navy: #201959;
  --brand-purple: #8a7ff3;
  --brand-purple-ink: #201959;
  --brand-cyan: #67e8f9;
}

html, body {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  margin: 0;
  padding: 0;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  min-width: 0;
}

body {
  font-family: var(--font-family);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  padding-top: max(10px, env(safe-area-inset-top));
  padding-bottom: max(32px, calc(24px + env(safe-area-inset-bottom)));
  line-height: 1.45;
}

/* La sesión activa es un modo de foco; el shell global vuelve al desmontar. */
body.workout-focus-active {
  padding: 0;
  overflow: hidden;
}
body.workout-focus-active .app-shell {
  max-width: none;
  padding: 0;
}
body.workout-focus-active .app-shell > header,
body.workout-focus-active #pwa-install-banner {
  display: none !important;
}

.app-shell {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 0 12px;
}

@media (min-width: 640px) {
  .app-shell {
    padding: 0 16px;
  }
}

/* Header */
header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 8px 0 12px;
  margin-bottom: 14px;
}

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

.header-links {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.login-hint {
  margin: 12px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.login-hint a {
  color: var(--accent);
}

.login-lead {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.88rem;
}

.webauthn-conditional {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

.brand-icon {
  font-size: 1.25rem;
}

h1 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.beta-badge {
  font-size: 0.6rem;
  font-weight: 800;
  background: #e67e22;
  color: #fff;
  padding: 1px 5px;
  border-radius: 4px;
  letter-spacing: 0.05em;
}

.nav-health-btn {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  background: #172013;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background 0.15s;
}

.nav-health-btn:hover {
  background: #232d1d;
  border-color: var(--accent);
}

/* Navigation Bar */
.tab-nav {
  display: flex;
  gap: 6px;
  background: var(--panel);
  padding: 4px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tab-nav::-webkit-scrollbar { display: none; }

.nav-link {
  flex: 1;
  text-align: center;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.76rem;
  transition: all 0.15s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.nav-link.active {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

/* Main & Cards */
main {
  padding: 0;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}

.card:hover {
  border-color: rgba(198, 226, 106, 0.3);
}

.card h3 {
  margin: 0 0 6px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 14px;
  min-height: 44px;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 700;
  cursor: pointer;
  font-size: 0.82rem;
  transition: all 0.15s;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-secondary {
  background: var(--panel-alt);
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-secondary:hover {
  background: var(--panel-hover);
  border-color: var(--accent);
}

.btn-danger {
  background: var(--panel-alt);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-danger:hover {
  background: var(--panel-hover);
}

.btn-sm {
  padding: 5px 9px;
  min-height: 44px;
  font-size: 0.72rem;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  background: var(--panel-alt);
  color: var(--muted);
  border: 1px solid var(--line);
  white-space: nowrap;
}

.badge.origin-catalog { background: #18252e; color: var(--spo2); border-color: #284558; }
.badge.origin-manual { background: #262115; color: var(--kcal); border-color: #4a3e20; }
.badge.status-planned { background: #1d2136; color: #a5b4fc; border-color: #373e63; }
.badge.status-in_progress { background: #132b1a; color: var(--success); border-color: #235832; }
.badge.status-completed { background: #132b1a; color: var(--success); border-color: #235832; }
.badge.status-partial { background: #262115; color: var(--kcal); border-color: #4a3e20; }
.badge.status-cancelled { background: #3b1717; color: #fca5a5; border-color: #7f1d1d; }
.badge.index-fuerte { background: #132b1a; color: var(--success); border-color: #235832; }
.badge.index-ok { background: #18252e; color: var(--spo2); border-color: #284558; }
.badge.index-corto { background: #262115; color: var(--kcal); border-color: #4a3e20; }
.badge.index-bajo, .badge.index-sin-datos, .badge.index-na { background: #1d2136; color: #a5b4fc; border-color: #373e63; }

.index-card {
  margin: 8px 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-alt);
}
.index-score {
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.index-label {
  margin-left: 8px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
}
.index-meta {
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--muted);
}

.null-val {
  color: var(--muted);
  font-style: italic;
  opacity: 0.7;
}

.dup-warn {
  background: #2b2210;
  border: 1px solid #574116;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin-bottom: 10px;
  font-size: 0.78rem;
  color: #fcd34d;
}

/* Forms */
.form-group {
  margin-bottom: 10px;
}

.form-group label {
  display: block;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line);
  background: #13170f;
  color: var(--ink);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.form-row {
  display: flex;
  gap: 8px;
}

.form-row .form-group {
  flex: 1;
}

/* Exercise & Sets */
.exercise-card {
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.exercise-name {
  font-weight: 700;
  font-size: 0.86rem;
  color: var(--ink);
}

.exercise-plan {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 2px;
  margin-bottom: 6px;
}

.set-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.set-row:last-child {
  border-bottom: none;
}

.set-num {
  font-weight: 700;
  color: var(--accent);
  min-width: 20px;
}

.set-val {
  color: var(--ink);
}

.set-note {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  margin-top: 2px;
  margin-left: 20px;
  font-size: 0.72rem;
  color: var(--muted);
  font-style: italic;
  background: rgba(134, 239, 172, 0.04);
  border-left: 2px solid var(--accent);
  padding: 2px 8px;
  border-radius: 0 4px 4px 0;
}

/* Search Suggestions */
.search-suggestions {
  background: #13170f;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  max-height: 180px;
  overflow-y: auto;
  margin-top: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.suggestion-item {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--ink);
  transition: background 0.15s;
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-item:hover, .suggestion-item:active {
  background: var(--panel-hover);
  color: var(--accent);
}

.suggestion-empty {
  padding: 10px 12px;
  font-size: 0.75rem;
  color: var(--muted);
  font-style: italic;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

@media (min-width: 600px) {
  .modal-overlay {
    align-items: center;
    padding: 16px;
  }
}

.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 18px 16px;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
}

@media (min-width: 600px) {
  .modal {
    border-radius: 16px;
  }
}

.modal h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
}

#login-form {
  display: grid;
  gap: 8px;
}

#login-form label {
  color: var(--muted);
  font-size: .76rem;
  font-weight: 650;
}

#login-form input:not(.webauthn-conditional) {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-alt);
  color: var(--ink);
  font: inherit;
}

#login-form input:focus-visible {
  outline: 3px solid var(--accent-glow);
  border-color: var(--accent);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #172418;
  color: var(--ink);
  border: 1px solid #2d4734;
  padding: 9px 18px;
  border-radius: 99px;
  font-size: 0.78rem;
  font-weight: 600;
  z-index: 60;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  transition: all 0.25s ease;
  white-space: nowrap;
}

.empty {
  text-align: center;
  padding: 24px 12px;
  color: var(--muted);
  font-size: 0.8rem;
}

.section-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 12px 0 6px;
}

.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.filter-bar input {
  flex: 1;
  padding: 8px 11px;
  border: 1px solid var(--line);
  background: #13170f;
  color: var(--ink);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
}

.hidden {
  display: none !important;
}

.chat-shell { display: flex; flex-direction: column; gap: 10px; min-height: 60vh; }
.chat-header-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.chat-actions { display: flex; gap: 6px; }
.chat-intro { font-size: 0.8rem; color: var(--muted); margin: 0; }
.chat-log {
  flex: 1;
  min-height: 280px;
  max-height: 55vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-bubble {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-user { align-self: flex-end; background: #262e20; max-width: 90%; }
.chat-bot { align-self: flex-start; background: #13170f; border: 1px solid var(--line); max-width: 95%; }
.chat-tool, .chat-status { font-size: 0.72rem; color: var(--muted); margin-top: 4px; }
.chat-form { display: flex; flex-direction: column; gap: 8px; }
.chat-form textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line);
  background: #13170f;
  color: var(--ink);
  border-radius: var(--radius-sm);
  font: inherit;
  resize: vertical;
}

/* Trace Inspector Modal */
.trace-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  padding: 16px;
}
.trace-modal-content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  width: 100%;
  max-width: 650px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.trace-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}
.trace-modal-header h3 { margin: 0; font-size: 1.05rem; }
.trace-modal-meta { padding: 8px 0; font-size: 0.75rem; color: var(--muted); word-break: break-all; }
.trace-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 8px;
}
.trace-item {
  background: #13170f;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 0.82rem;
}
.trace-item-header { display: flex; justify-content: space-between; align-items: center; }
.trace-item-sub { display: flex; gap: 8px; align-items: center; margin: 4px 0; font-size: 0.72rem; color: var(--muted); }
.trace-badge { padding: 2px 6px; border-radius: 4px; font-weight: 700; font-size: 0.68rem; }
.trace-badge.ok { background: #1b4324; color: #72e486; }
.trace-badge.err { background: #5c1d1d; color: #ff8585; }
.trace-tag { background: #262e20; padding: 1px 5px; border-radius: 3px; }
.trace-dur { font-size: 0.75rem; color: var(--muted); margin-left: 4px; }
.trace-details summary { cursor: pointer; color: var(--accent); margin-top: 4px; font-size: 0.75rem; }
.trace-details pre { background: #0b0d08; padding: 6px; border-radius: 4px; overflow-x: auto; font-size: 0.7rem; margin-top: 4px; }
.trace-error { color: #ff8585; font-size: 0.75rem; margin-top: 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
