/* ============================================================
   FitTrack — Dark mobile-first styles
   ============================================================ */

:root {
  --bg:          #0f0f1a;
  --surface:     #1a1a2e;
  --card:        #1e1e35;
  --border:      #2d2d50;
  --primary:     #4cc9f0;
  --primary-dk:  #0a9dc4;
  --success:     #2ecc71;
  --danger:      #e74c3c;
  --warning:     #f39c12;
  --text:        #e8e8f0;
  --text-muted:  #7878a8;
  --radius:      14px;
  --radius-sm:   8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h:    60px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  height: 100dvh;
  position: relative;
  overflow: hidden;
}

/* ---- Screens ---- */
.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  position: absolute;
  inset: 0;
  background: var(--bg);
}
.screen.active { display: flex; }

.screen-main {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---- Header ---- */
.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}
.header-title {
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-title h1 { font-size: 20px; font-weight: 700; }
.app-logo { font-size: 22px; }
.header-center {
  flex: 1;
  text-align: center;
}
.header-center h1 { font-size: 17px; font-weight: 600; }
.w-40 { width: 40px; }

/* ---- Cards ---- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}
.section-title-sm {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* ---- Quick stats (home) ---- */
.quick-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.bw-card {
  cursor: pointer;
  transition: border-color .15s;
}
.bw-card:hover { border-color: var(--primary); }
.quick-stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  text-align: center;
}
.quick-stat-card .val {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
}
.quick-stat-card .lbl {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---- Workout type grid ---- */
.workout-type-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.workout-type-card {
  border-radius: var(--radius-sm);
  padding: 16px 12px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform .1s, border-color .15s;
  position: relative;
  overflow: hidden;
}
.workout-type-card:active { transform: scale(.97); }
.workout-type-card .wt-name {
  font-weight: 600;
  font-size: 14px;
  color: #fff;
}
.workout-type-card .wt-count {
  font-size: 12px;
  color: rgba(255,255,255,.65);
  margin-top: 4px;
}
.workout-type-card .wt-last {
  font-size: 11px;
  color: rgba(255,255,255,.45);
  margin-top: 6px;
}

/* ---- Recent sessions ---- */
.recent-sessions { display: flex; flex-direction: column; gap: 8px; }
.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.session-item-left { display: flex; flex-direction: column; gap: 2px; }
.session-item-name { font-weight: 600; font-size: 14px; }
.session-item-date { font-size: 12px; color: var(--text-muted); }
.session-item-right { text-align: right; }
.session-item-weight { font-weight: 700; color: var(--primary); font-size: 15px; }
.session-item-dur { font-size: 11px; color: var(--text-muted); }
.empty-state { color: var(--text-muted); font-size: 14px; text-align: center; padding: 16px; }

/* ---- Session bar (workout screen) ---- */
.session-bar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.session-stat { text-align: center; }
.session-stat .stat-value { display: block; font-size: 20px; font-weight: 700; color: var(--primary); }
.session-stat .stat-label { display: block; font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.session-stat-sep { width: 1px; height: 30px; background: var(--border); }

/* ---- Exercise table ---- */
.exercise-table-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}
.exercise-table {
  width: 100%;
  border-collapse: collapse;
}
.exercise-table thead th {
  background: var(--surface);
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}
.exercise-table thead th:last-child { text-align: center; }

.exercise-row {
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}
.exercise-row:active { background: var(--surface); }
.exercise-row td {
  padding: 13px 12px;
  vertical-align: middle;
}
.exercise-row td:first-child {
  font-weight: 500;
  font-size: 14px;
  border-left: 3px solid transparent;
}
.exercise-row.status-success td:first-child { border-left-color: var(--success); }
.exercise-row.status-failure td:first-child { border-left-color: var(--danger); }
.exercise-row.status-pending td:first-child { border-left-color: var(--border); }

.ex-params {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}
.ex-params strong { color: var(--text); }
.ex-status-cell { text-align: center; }

/* ---- Status badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  min-width: 32px;
  height: 28px;
  border-radius: 20px;
  padding: 0 8px;
}
.badge-success { background: rgba(46,204,113,.18); color: var(--success); }
.badge-failure { background: rgba(231,76,60,.18); color: var(--danger); font-size: 17px; }
.badge-pending { background: var(--surface); color: var(--text-muted); }
.badge-streak  { background: rgba(255,255,255,.07); color: var(--text); font-weight: 600; }

/* ---- Workout footer ---- */
.workout-footer {
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ---- Timer ---- */
.timer {
  font-family: 'SF Mono', 'Roboto Mono', monospace;
  font-size: 15px;
  font-weight: 600;
  color: var(--primary);
  background: rgba(76,201,240,.1);
  padding: 4px 10px;
  border-radius: 20px;
  min-width: 58px;
  text-align: center;
}

/* ---- Buttons ---- */
.btn-primary, .btn-success, .btn-danger, .btn-ghost, .btn-secondary {
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  padding: 12px 20px;
  transition: opacity .15s, transform .1s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-primary:active, .btn-success:active, .btn-danger:active { transform: scale(.97); }

.btn-primary { background: var(--primary); color: #0f0f1a; }
.btn-primary:hover { background: var(--primary-dk); }

.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }

.btn-ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--border);
  font-size: 13px;
  padding: 8px 14px;
}

.btn-lg { width: 100%; font-size: 16px; padding: 15px; }
.btn-sm { font-size: 13px; padding: 8px 14px; }
.btn-result {
  flex: 1;
  font-size: 16px;
  padding: 16px;
  border-radius: var(--radius-sm);
}

.icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 18px;
  padding: 8px;
  border-radius: 50%;
  color: var(--text-muted);
  line-height: 1;
  min-width: 40px;
  min-height: 40px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.icon-btn:hover { background: var(--surface); }
.icon-btn.danger { color: var(--danger); }

/* ---- Modals ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(2px);
}

.modal-sheet {
  position: relative;
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  padding: 0 16px calc(24px + var(--safe-bottom));
  max-height: 92dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: slideUp .22s ease-out;
}
.modal-sheet-sm { max-height: 60dvh; }

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2 { font-size: 18px; font-weight: 700; }

/* ---- Streak bar ---- */
.streak-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}
.streak-label { font-size: 13px; color: var(--text-muted); }
.streak-dots { display: flex; gap: 5px; }
.streak-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--border);
}
.streak-dot.filled { background: var(--success); }
.streak-dot.failed { background: var(--danger); }
.streak-count {
  margin-left: auto;
  font-size: 20px;
  font-weight: 700;
  color: var(--success);
}
.streak-count.failure { color: var(--danger); }

/* ---- Params editor ---- */
.params-editor { display: flex; flex-direction: column; gap: 2px; }
.param-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}
.param-row:last-child { border-bottom: none; }
.param-label { font-size: 14px; color: var(--text-muted); }
.param-ctrl {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}
.param-btn {
  background: transparent;
  border: none;
  color: var(--primary);
  font-size: 22px;
  font-weight: 300;
  padding: 0 16px;
  cursor: pointer;
  line-height: 44px;
  height: 44px;
  transition: background .12s;
}
.param-btn:active { background: var(--border); }
.param-val {
  min-width: 48px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

/* ---- Volume / 1RM ---- */
.volume-orm-row {
  display: flex;
  gap: 10px;
}
.volume-orm-pill {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  text-align: center;
}
.volume-orm-pill .pill-val {
  display: block;
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}
.volume-orm-pill .pill-lbl {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---- Result buttons ---- */
.result-buttons {
  display: flex;
  gap: 10px;
}

/* ---- Exercise history (modal) ---- */
.exercise-history-wrap { padding-top: 4px; }
.exercise-mini-history {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.mini-hist-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  padding: 7px 10px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--border);
}
.mini-hist-row.success { border-left-color: var(--success); }
.mini-hist-row.failure { border-left-color: var(--danger); }
.mini-hist-date { color: var(--text-muted); }
.mini-hist-params { color: var(--text); font-weight: 500; }
.mini-hist-result { font-weight: 700; }
.mini-hist-row.success .mini-hist-result { color: var(--success); }
.mini-hist-row.failure .mini-hist-result { color: var(--danger); }

/* ---- Stats screen ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 4px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 12px;
  text-align: center;
}
.stat-card .s-val {
  display: block;
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
}
.stat-card .s-lbl {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.chart-wrap {
  position: relative;
  height: 200px;
}
.chart-wrap canvas { width: 100% !important; height: 100% !important; }

.select-input {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  appearance: none;
  cursor: pointer;
}

.exercise-detail-stats {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.detail-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-muted);
}
.detail-pill strong { color: var(--text); }

.session-history-list { display: flex; flex-direction: column; gap: 8px; }
.hist-session-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.hist-session-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}
.hist-session-name { font-weight: 600; font-size: 14px; }
.hist-session-date { font-size: 12px; color: var(--text-muted); }
.hist-session-meta { display: flex; gap: 12px; font-size: 12px; color: var(--text-muted); }
.hist-session-meta span strong { color: var(--primary); }

/* ---- Form ---- */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.input {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  width: 100%;
}
.input:focus { border-color: var(--primary); }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  z-index: 200;
  white-space: nowrap;
  animation: toastIn .2s ease;
}
.toast.hidden { display: none; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---- Edit mode ---- */
.header-right-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.btn-edit-mode {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}
.btn-edit-mode.edit-active {
  background: rgba(46,204,113,.15);
  border-color: var(--success);
  color: var(--success);
}

.edit-mode-row { cursor: default !important; }
.edit-mode-row:active { background: transparent !important; }

.btn-delete-ex {
  background: rgba(231,76,60,.15);
  border: 1px solid rgba(231,76,60,.4);
  color: var(--danger);
  border-radius: 50%;
  width: 30px; height: 30px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.btn-delete-ex:active { background: rgba(231,76,60,.35); }

.add-ex-row { cursor: pointer !important; }
.add-ex-row:hover td { background: rgba(76,201,240,.06); }
.add-ex-row:active td { background: rgba(76,201,240,.12); }

/* ---- Assisted exercise ---- */
.assisted-tag {
  font-size: 10px;
  color: var(--text-muted);
  background: rgba(255,255,255,.06);
  border-radius: 4px;
  padding: 1px 4px;
  margin-left: 2px;
  vertical-align: middle;
}
.assisted-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 4px;
  flex-wrap: wrap;
}
.assisted-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.assisted-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}
.assisted-info {
  font-size: 12px;
  color: var(--primary);
  background: rgba(76,201,240,.1);
  border-radius: 6px;
  padding: 3px 8px;
  display: none;
}

/* ---- Lock screen ---- */
#screen-lock {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  background: var(--bg);
}
.lock-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: 40px 24px;
}
.lock-logo {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
}
.lock-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 240px;
}
.lock-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 18px;
  padding: 14px 16px;
  text-align: center;
  outline: none;
  letter-spacing: 4px;
}
.lock-input:focus { border-color: var(--primary); }
.lock-btn {
  background: var(--primary);
  color: #0f0f1a;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  padding: 14px;
  cursor: pointer;
}
.lock-btn:active { opacity: .8; }
.lock-error {
  color: var(--danger);
  font-size: 14px;
}

/* ---- Utilities ---- */
.hidden      { display: none !important; }
.text-muted  { color: var(--text-muted); }
.text-sm     { font-size: 13px; }
