:root {
  --bg: #0b0b0d;
  --card: #141418;
  --surface: #1a1a22;
  --text: #f5f5f7;
  --muted: #8e8e9a;
  --border: #262631;
  --accent: #4f8cff;
  --accent2: #2bd576;
  --danger: #ff4f4f;
  --warn: #ffb84f;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { font-family: -apple-system, system-ui, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); min-height: 100dvh; overflow-x: hidden; }
html { scroll-behavior: smooth; }

.screen { min-height: 100dvh; }
.hidden { display: none !important; }

/* ── LOGIN ── */
.login-card {
  max-width: 360px;
  margin: 0 auto;
  padding: 40px 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100dvh;
}
.login-logo { font-size: 32px; font-weight: 900; text-align: center; }
.login-sub { text-align: center; color: var(--muted); margin: 8px 0 32px; font-size: 14px; }
.login-card form { display: grid; gap: 16px; }
.error-msg { color: var(--danger); font-size: 13px; text-align: center; padding: 8px; background: rgba(255,79,79,0.1); border-radius: 8px; }

/* ── HEADER ── */
.app-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(11,11,13,0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex; justify-content: space-between; align-items: center;
}
.title { font-size: 18px; font-weight: 800; }
.subtitle { font-size: 11px; color: var(--muted); margin-top: 2px; }
.header-actions { display: flex; gap: 6px; }

/* ── CONTAINER ── */
.container { max-width: 600px; margin: 0 auto; padding: 12px 12px 180px; display: grid; gap: 10px; }

/* ── CARDS ── */
.card, .day-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
h2 { font-size: 16px; font-weight: 700; }
h3 { font-size: 14px; font-weight: 700; margin: 12px 0 6px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.4; margin-top: 6px; }

/* ── ROWS / LAYOUT ── */
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.space-between { justify-content: space-between; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .grid { grid-template-columns: 1fr; } }

/* ── BUTTONS ── */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); border-color: rgba(255,255,255,0.1); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn.full { width: 100%; }
.small { font-size: 12px; padding: 7px 10px; }
.small-danger { background: rgba(255,79,79,0.15); border-color: rgba(255,79,79,0.3); color: var(--danger); }

/* ── CHIPS / PILLS / BADGES ── */
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 7px 10px;
  border-radius: 999px;
  display: inline-flex;
  gap: 6px;
  align-items: center;
  font-size: 13px;
  cursor: pointer;
}
.pill {
  font-size: 12px;
  color: #0b0b0d;
  background: var(--accent2);
  padding: 5px 10px;
  border-radius: 999px;
  font-weight: 800;
}
.badge {
  display: inline-flex;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
}
.mb-badge {
  display: inline;
  background: rgba(255,184,79,0.15);
  color: var(--warn);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}

/* ── FIELDS ── */
.field { display: grid; gap: 5px; }
.field span { color: var(--muted); font-size: 12px; }
.field input, .field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.field.checkbox { display: flex; flex-direction: row; align-items: center; gap: 8px; }

/* ── EXERCISE CARDS (workout list) ── */
.list { display: grid; gap: 8px; }
.exercise-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: all 0.15s;
  border-left: 4px solid transparent;
}
.exercise-card:hover { background: var(--surface); }
.exercise-card:active { transform: scale(0.99); }
.exercise-card.partial { border-left-color: var(--warn); }
.exercise-card.done { border-left-color: var(--accent2); opacity: 0.7; }

.ex-top { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.ex-thumb-wrap {
  position: relative;
  width: 56px;
  height: 56px;
  flex-shrink: 0;
}
.ex-thumb {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  position: relative;
  z-index: 1;
}
.ex-thumb-placeholder {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
  color: var(--muted);
}
.ex-info { flex: 1; min-width: 0; }
.ex-name { font-weight: 700; font-size: 15px; }
.ex-slot { color: var(--muted); font-size: 12px; margin-top: 2px; }
.ex-meta { color: var(--muted); font-size: 11px; margin-top: 4px; }
.ex-muscles { margin-top: 6px; display: flex; gap: 4px; flex-wrap: wrap; }
.muscle-tag {
  background: rgba(79,140,255,0.12);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}
.ex-status { text-align: right; flex-shrink: 0; }
.ex-progress { font-weight: 800; font-size: 18px; }
.ex-weight { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ── MODAL ── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 100; }
.modal {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  max-width: 600px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  z-index: 101;
  max-height: 85dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-header {
  position: sticky; top: 0;
  background: var(--card);
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  z-index: 1;
}
.modal-title { font-weight: 900; font-size: 16px; }
.modal-subtitle { color: var(--muted); font-size: 12px; margin-top: 2px; }
.modal-body { padding: 14px; }

.exercise-image { margin-bottom: 12px; }
.ex-img-full {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
}
/* Hide broken image icon while loading */
img.ex-thumb[src]:not([src=""]) { color: transparent; }
img.ex-img-full[src]:not([src=""]) { color: transparent; }
.ex-img-placeholder {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 16px;
  text-align: center;
  font-size: 20px;
  font-weight: 800;
  color: var(--muted);
}
.muscle-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }

.form-cues {
  background: rgba(43,213,118,0.08);
  border: 1px solid rgba(43,213,118,0.2);
  border-radius: 10px;
  padding: 10px;
  margin: 10px 0;
}
.cue-title { font-size: 12px; font-weight: 700; color: var(--accent2); margin-bottom: 4px; }
.form-cues p { font-size: 13px; color: var(--text); line-height: 1.4; }

.target {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 12px;
  padding: 12px;
  margin: 10px 0;
}
.target-big { font-size: 22px; font-weight: 900; }
.target-small { margin-top: 4px; color: var(--muted); font-size: 12px; }

.sep { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

.setlog {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  border: 1px dashed rgba(165,165,177,0.2);
  border-radius: 10px;
  padding: 10px;
  background: rgba(0,0,0,0.1);
}

/* ── SLIDE PANELS ── */
.slide-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-left: 1px solid var(--border);
  z-index: 200;
  overflow-y: auto;
  animation: slideIn 0.2s ease;
}
@keyframes slideIn { from { transform: translateX(100%); } }
.panel-header {
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: var(--card);
  z-index: 1;
}
.panel-body { padding: 14px; }

.injury-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  font-size: 13px;
}

.hist-entry {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 8px;
}
.hist-header { font-size: 14px; }
.hist-note { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ── CHAT BAR ── */
.chat-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  max-width: 600px;
  margin: 0 auto;
  background: var(--card);
  border-top: 1px solid var(--border);
  z-index: 60;
}
.chat-messages {
  max-height: 120px;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat-msg {
  font-size: 13px;
  line-height: 1.4;
  padding: 8px 12px;
  border-radius: 12px;
  max-width: 85%;
}
.chat-msg.assistant {
  background: var(--surface);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.chat-msg.user {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
}
.chat-input-row input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.chat-input-row input:focus { outline: none; border-color: var(--accent); }

/* ── STEPPER ── */
.stepper-row {
  display: flex;
  align-items: center;
  gap: 0;
}
.stepper-row input {
  text-align: center;
  font-size: 20px;
  font-weight: 800;
  width: 60px;
  border-radius: 0;
  border-left: none;
  border-right: none;
}
.stepper-btn {
  width: 48px;
  height: 48px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stepper-btn:first-child { border-radius: 10px 0 0 10px; }
.stepper-btn:last-child { border-radius: 0 10px 10px 0; }
.stepper-btn:active { background: var(--accent); }

/* ── SET LOGGED FLASH ── */
@keyframes setFlash {
  0% { background: rgba(43,213,118,0.3); }
  100% { background: transparent; }
}
.set-flash { animation: setFlash 0.6s ease-out; }

/* ── SAFE AREA / MOBILE ── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .chat-bar { padding-bottom: env(safe-area-inset-bottom); }
}
