*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0f1a;
  --surface: #161929;
  --surface2: #1e2235;
  --border: #252c40;
  --text: #e8eaf0;
  --text-dim: #8890a8;
  --text-faint: #3f4760;
  --accent: #5b7cfd;
  --accent-hover: #7494ff;
  --accent-dim: rgba(91, 124, 253, 0.12);
  --success: #22c87a;
  --success-dim: rgba(34, 200, 122, 0.12);
  --warning: #f0aa2a;
  --warning-dim: rgba(240, 170, 42, 0.12);
  --danger: #f05656;
  --danger-dim: rgba(240, 86, 86, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --nav-height: 64px;
  --header-height: 56px;
}

html           { height: 100%; }
body           { height: 100dvh; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app { height: 100dvh; display: flex; flex-direction: column; }
#view { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

/* ── Hidden ───────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Bottom Nav ───────────────────────────────────────────────────────────── */
.bottom-nav {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: max(calc(env(safe-area-inset-bottom) - 12px), 0px);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 500;
  position: relative;
  transition: color 0.15s;
  padding: 8px 0;
}

.nav-item.active { color: var(--accent); }
.nav-item svg { flex-shrink: 0; }

.nav-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 18px);
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ── View layout ─────────────────────────────────────────────────────────── */
.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

.view-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.view-header h1 {
  font-size: 17px;
  font-weight: 600;
  flex: 1;
}

.view-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.view-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

/* ── Centered views (auth/setup) ─────────────────────────────────────────── */
.view-centered {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  overflow-y: auto;
}

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 10px;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:active:not(:disabled) { opacity: 0.8; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--accent); padding: 6px 10px; }

.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 7px; }
.btn-lg { padding: 14px 22px; font-size: 16px; border-radius: var(--radius); }
.btn-full { width: 100%; }
.btn-icon { padding: 8px; border-radius: 8px; background: transparent; color: var(--text-dim); }
.btn-icon:hover { background: var(--surface2); color: var(--text); }

/* ── Form inputs ─────────────────────────────────────────────────────────── */
.input-group { margin-bottom: 14px; }

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

textarea { resize: vertical; min-height: 72px; }

input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-accent   { background: var(--accent-dim);   color: var(--accent);  }
.badge-success  { background: var(--success-dim);  color: var(--success); }
.badge-warning  { background: var(--warning-dim);  color: var(--warning); }
.badge-danger   { background: var(--danger-dim);   color: var(--danger);  }
.badge-dim      { background: var(--surface2);     color: var(--text-dim); }

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 48px 24px;
  color: var(--text-dim);
  font-size: 14px;
}

/* ── Alert messages ──────────────────────────────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 12px;
}

.alert-error   { background: var(--danger-dim);  color: var(--danger);  border: 1px solid rgba(240,86,86,0.25); }
.alert-success { background: var(--success-dim); color: var(--success); border: 1px solid rgba(34,200,122,0.25); }
.alert-warning { background: var(--warning-dim); color: var(--warning); border: 1px solid rgba(240,170,42,0.25); }
.alert-info    { background: var(--accent-dim);  color: var(--accent);  border: 1px solid rgba(91,124,253,0.25); }

/* ── Auth view ───────────────────────────────────────────────────────────── */
.auth-logo {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.auth-logo span { color: var(--accent); }

.auth-subtitle {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 32px;
  text-align: center;
}

.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  width: 100%;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  font-family: inherit;
}

.auth-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.auth-form { width: 100%; max-width: 360px; }

.remember-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-dim);
  font-weight: 400;
}
.remember-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Onboarding ──────────────────────────────────────────────────────────── */
.onboarding-progress {
  display: flex;
  gap: 6px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.progress-dot {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  transition: background 0.3s;
}

.progress-dot.done  { background: var(--success); }
.progress-dot.active { background: var(--accent); }

.step-info {
  padding: 12px 16px 0;
  flex-shrink: 0;
}

.step-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 600;
}

/* ── Chat ────────────────────────────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.chat-msg { display: flex; flex-direction: column; max-width: 82%; }
.chat-msg.user { align-self: flex-end; align-items: flex-end; }
.chat-msg.ai   { align-self: flex-start; align-items: flex-start; }

.chat-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg.user .chat-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg.ai .chat-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-msg .chat-time {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 3px;
  padding: 0 4px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.chat-input-row textarea {
  flex: 1;
  min-height: 42px;
  max-height: 120px;
  padding: 10px 12px;
  font-size: 15px;
  resize: none;
  border-radius: var(--radius);
}

.chat-input-row .btn { align-self: flex-end; flex-shrink: 0; }

/* ── Dashboard ───────────────────────────────────────────────────────────── */
.dashboard-hero {
  background: linear-gradient(135deg, var(--accent), #7b5de8);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  color: #fff;
}

.dashboard-hero-greeting {
  font-size: 14px;
  opacity: 0.8;
  margin-bottom: 2px;
}

.dashboard-hero-name {
  font-size: 22px;
  font-weight: 700;
}

.phase-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.phase-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 10px;
}

.phase-name { font-size: 16px; font-weight: 600; }
.phase-type { font-size: 12px; color: var(--text-dim); margin-top: 1px; }

.phase-progress-bar {
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  margin-bottom: 8px;
  overflow: hidden;
}

.phase-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.4s;
}

.phase-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-dim);
}

.section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 10px;
  margin-top: 4px;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.session-item:hover { border-color: var(--accent); }

.session-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.session-info { flex: 1; min-width: 0; }
.session-type { font-size: 14px; font-weight: 600; }
.session-meta { font-size: 12px; color: var(--text-dim); }

/* ── Session execution ───────────────────────────────────────────────────── */
.exercise-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
  transition: border-color 0.2s;
}

.exercise-card.active { border-color: var(--accent); }
.exercise-card.completed { opacity: 0.6; }
.exercise-card.skipped { opacity: 0.45; }

.exercise-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
}

.exercise-order {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  flex-shrink: 0;
}

.exercise-card.active .exercise-order { background: var(--accent); color: #fff; }
.exercise-card.completed .exercise-order { background: var(--success-dim); color: var(--success); }

.exercise-name { font-size: 15px; font-weight: 600; flex: 1; }
.exercise-sets-count { font-size: 12px; color: var(--text-dim); }

.exercise-body { padding: 0 16px 14px; }

.exercise-gif {
  display: block;
  width: 100%;
  max-height: 180px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  margin-bottom: 12px;
}

.exercise-notes {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 14px;
  padding: 8px 12px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}

.sets-list { display: flex; flex-direction: column; gap: 10px; }

.set-row {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 12px;
}

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

.set-label { font-size: 13px; font-weight: 600; color: var(--text-dim); }
.set-planned { font-size: 12px; color: var(--text-faint); }

.set-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.set-input-cell { display: flex; flex-direction: column; gap: 3px; }
.set-input-cell label { font-size: 11px; color: var(--text-dim); margin: 0; }

.set-input-cell input {
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  padding: 8px;
  border-radius: var(--radius-sm);
}

.set-feedback-section { margin-top: 8px; }

.set-flag {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-top: 6px;
}

.set-flag.watch { background: var(--warning-dim); color: var(--warning); }
.set-flag.stop  { background: var(--danger-dim);  color: var(--danger); }

.ai-response-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text-dim);
  margin-top: 6px;
}

/* ── Proposal view ───────────────────────────────────────────────────────── */
.proposal-header {
  background: linear-gradient(135deg, var(--surface), var(--surface2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.proposal-type { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.proposal-meta { font-size: 13px; color: var(--text-dim); }
.proposal-reasoning {
  font-size: 14px;
  color: var(--text-dim);
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  line-height: 1.6;
}

.exercise-plan-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.exercise-plan-item:last-child { border-bottom: none; }
.exercise-plan-num { width: 24px; color: var(--text-dim); font-size: 13px; font-weight: 600; flex-shrink: 0; padding-top: 1px; }
.exercise-plan-name { font-size: 14px; font-weight: 600; flex: 1; }
.exercise-plan-detail { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* ── Finish form ─────────────────────────────────────────────────────────── */
.star-rating { display: flex; gap: 8px; margin-bottom: 4px; }

.star-btn {
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: var(--border);
  transition: color 0.15s;
  padding: 4px;
  -webkit-tap-highlight-color: transparent;
}

.star-btn.active { color: var(--warning); }

.rpe-slider {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.rpe-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}

.rpe-btn.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

/* ── Summary ─────────────────────────────────────────────────────────────── */
.summary-text {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  margin-bottom: 4px;
}

.observation-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.observation-item:last-child { border-bottom: none; }
.observation-text { flex: 1; font-size: 14px; }
.observation-meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* ── Observations view ───────────────────────────────────────────────────── */
.obs-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 8px;
}

.obs-item-header {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}

.obs-text { font-size: 14px; flex: 1; }

.confidence-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}

.confidence-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}

.obs-actions { display: flex; gap: 6px; margin-top: 8px; }

/* ── Plan changes ────────────────────────────────────────────────────────── */
.change-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}

.change-reason {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  line-height: 1.5;
}

.change-values {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.change-old { color: var(--text-dim); text-decoration: line-through; }
.change-arrow { color: var(--text-faint); }
.change-new { color: var(--success); font-weight: 600; }

.change-actions { display: flex; gap: 8px; margin-top: 12px; }

/* ── Phases view ─────────────────────────────────────────────────────────── */
.phase-item {
  position: relative;
  padding-left: 28px;
  margin-bottom: 16px;
}

.phase-item::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 28px;
  bottom: -16px;
  width: 2px;
  background: var(--border);
}

.phase-item:last-child::before { display: none; }

.phase-dot {
  position: absolute;
  left: 0;
  top: 10px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--border);
  border: 2px solid var(--bg);
}

.phase-dot.active   { background: var(--accent); }
.phase-dot.completed { background: var(--success); }
.phase-dot.planned  { background: var(--surface2); border-color: var(--border); }
.phase-dot.skipped  { background: var(--text-faint); }

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

.phase-card-inner.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.phase-card-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 8px; }
.phase-card-name { font-size: 15px; font-weight: 600; }
.phase-card-dates { font-size: 12px; color: var(--text-dim); margin-top: 1px; }
.phase-card-notes { font-size: 13px; color: var(--text-dim); margin-top: 8px; line-height: 1.5; }
.phase-card-actions { display: flex; gap: 6px; margin-top: 10px; }

/* ── Misc ────────────────────────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

.empty-state {
  text-align: center;
  padding: 40px 24px;
  color: var(--text-dim);
  font-size: 14px;
}

.empty-state-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 15px;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}

.back-btn:hover { color: var(--text); }

.inline-edit-row {
  display: flex;
  gap: 6px;
  align-items: flex-start;
}

.inline-edit-row textarea { flex: 1; min-height: 56px; }

/* ── Warning/Stop banner ─────────────────────────────────────────────────── */
.flag-banner {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
  margin: 10px 0;
  display: flex;
  gap: 8px;
}

.flag-banner.watch { background: var(--warning-dim); color: var(--warning); border: 1px solid rgba(240,170,42,0.3); }
.flag-banner.stop  { background: var(--danger-dim);  color: var(--danger);  border: 1px solid rgba(240,86,86,0.3); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (min-width: 600px) {
  #app { max-width: 600px; margin: 0 auto; position: relative; }
  .bottom-nav { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
