:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --text: #1c1c1e;
  --text-secondary: #6e6e73;
  --text-tertiary: #aeaeb2;
  --separator: rgba(60, 60, 67, 0.15);
  --accent: #2f9e6e;
  --accent-contrast: #ffffff;
  --danger: #ff3b30;
  --warning: #ff9500;
  --success: #248a4d;
  --info: #0071e3;
  --pill-bg: rgba(60, 60, 67, 0.08);
  --nav-bg: rgba(249, 249, 251, 0.92);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --surface: #1c1c1e;
    --text: #f2f2f7;
    --text-secondary: #98989f;
    --text-tertiary: #636366;
    --separator: rgba(84, 84, 88, 0.55);
    --accent: #43c98c;
    --accent-contrast: #06120c;
    --success: #43c98c;
    --info: #4ea6ff;
    --pill-bg: rgba(118, 118, 128, 0.24);
    --nav-bg: rgba(22, 22, 24, 0.86);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #000000;
  --surface: #1c1c1e;
  --text: #f2f2f7;
  --text-secondary: #98989f;
  --text-tertiary: #636366;
  --separator: rgba(84, 84, 88, 0.55);
  --accent: #43c98c;
  --accent-contrast: #06120c;
  --success: #43c98c;
  --info: #4ea6ff;
  --pill-bg: rgba(118, 118, 128, 0.24);
  --nav-bg: rgba(22, 22, 24, 0.86);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
}

button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; border-radius: 6px; }
.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; }

#root { min-height: 100%; }

.app-shell { display: flex; min-height: 100vh; }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; padding-bottom: 70px; }
@media (min-width: 900px) { .app-main { padding-bottom: 0; } }

.sidebar { display: none; }
@media (min-width: 900px) {
  .sidebar {
    display: flex; flex-direction: column; width: 240px; flex-shrink: 0;
    background: var(--surface); border-right: 1px solid var(--separator);
    padding: 24px 12px; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  }
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 8px 12px 20px; }
.sidebar-brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); flex-shrink: 0; }
.sidebar-brand-text { font-weight: 700; font-size: 15px; line-height: 1.2; }
.sidebar-link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--text); font-size: 14.5px; font-weight: 500; cursor: pointer; }
.sidebar-link.active { background: var(--pill-bg); color: var(--accent); }
.sidebar-link:hover { background: var(--pill-bg); }

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex;
  background: var(--nav-bg); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--separator); z-index: 40;
}
@media (min-width: 900px) { .bottom-nav { display: none; } }
.bottom-nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 0 8px; color: var(--text-tertiary); font-size: 10.5px; font-weight: 500; cursor: pointer; background: none; border: none; }
.bottom-nav-item.active { color: var(--accent); }
.bottom-nav-item svg { width: 23px; height: 23px; }

.page-header {
  position: sticky; top: 0; z-index: 20; background: var(--nav-bg);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  padding: 12px 16px; border-bottom: 1px solid var(--separator);
  display: flex; align-items: center; gap: 10px; min-height: 52px;
}
.page-header h1 { font-size: 17px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 999px; color: var(--accent); background: none; border: none; cursor: pointer; flex-shrink: 0; }
.icon-btn:hover { background: var(--pill-bg); }
.page-content { flex: 1; padding: 16px; padding-bottom: 40px; max-width: 720px; width: 100%; margin: 0 auto; box-sizing: border-box; }

.btn { appearance: none; border: none; cursor: pointer; font-weight: 600; font-size: 15px; border-radius: 12px; padding: 12px 18px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: opacity .15s ease; font-family: inherit; }
.btn:hover { opacity: .88; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); width: 100%; }
.btn-secondary { background: var(--pill-bg); color: var(--text); }
.btn-danger { background: rgba(255,59,48,.12); color: var(--danger); }
.btn-text { background: none; color: var(--accent); padding: 8px 4px; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 9px; }

.card { background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); padding: 16px; }
.list-card { background: var(--surface); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); }
.list-row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--separator); color: var(--text); cursor: pointer; background: none; border-left: none; border-right: none; border-top: none; width: 100%; text-align: left; font-family: inherit; font-size: inherit; }
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--pill-bg); }
.list-row-body { flex: 1; min-width: 0; }
.list-row-title { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row-subtitle { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.list-row-chevron { color: var(--text-tertiary); flex-shrink: 0; }
.avatar { width: 40px; height: 40px; border-radius: 999px; background: var(--accent); color: var(--accent-contrast); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0; }
.avatar-lg { width: 60px; height: 60px; font-size: 21px; }
.section-label { font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary); padding: 0 4px; margin-bottom: 8px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 560px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat-card { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.stat-card-value { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-card-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--pill-bg); color: var(--text-secondary); white-space: nowrap; }
.badge-success { background: rgba(52,199,89,.15); color: var(--success); }
.badge-warning { background: rgba(255,149,0,.15); color: #a35d00; }
.badge-danger { background: rgba(255,59,48,.15); color: var(--danger); }
.badge-info { background: rgba(0,113,227,.15); color: var(--info); }
.badge-neutral { background: var(--pill-bg); color: var(--text-secondary); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge-warning { color: #ffb340; } }
:root[data-theme="dark"] .badge-warning { color: #ffb340; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; background: var(--pill-bg); color: var(--text); font-size: 13.5px; font-weight: 600; border: none; cursor: pointer; font-family: inherit; }
.chip.selected { background: var(--accent); color: var(--accent-contrast); }
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }

.form-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.form-label { font-size: 12.5px; font-weight: 700; color: var(--text-secondary); }
.form-label .optional { font-weight: 400; color: var(--text-tertiary); text-transform: none; }
.form-hint { font-size: 12px; color: var(--text-tertiary); }
.form-error { font-size: 12px; color: var(--danger); font-weight: 600; }
.input, .textarea, .select { width: 100%; background: var(--surface); border: 1px solid var(--separator); border-radius: 10px; padding: 11px 13px; font-size: 15px; color: var(--text); font-family: inherit; }
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); }
.input.has-error, .textarea.has-error { border-color: var(--danger); }
.textarea { resize: vertical; min-height: 76px; }
fieldset.form-group { border: none; padding: 0; margin: 0 0 22px; }
.form-group legend { font-size: 15px; font-weight: 700; padding: 0 0 12px; width: 100%; }
.radio-row, .checkbox-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; font-size: 14.5px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 560px) { .form-grid-2 { grid-template-columns: 1fr 1fr; } }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }

.tabbar { display: flex; gap: 4px; background: var(--pill-bg); padding: 3px; border-radius: 12px; margin-bottom: 16px; overflow-x: auto; }
.tabbar-item { flex: 1; text-align: center; padding: 8px 10px; border-radius: 9px; font-size: 13px; font-weight: 700; color: var(--text-secondary); white-space: nowrap; background: none; border: none; cursor: pointer; font-family: inherit; }
.tabbar-item.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 48px 24px; color: var(--text-secondary); }
.empty-state-icon { color: var(--text-tertiary); margin-bottom: 4px; }
.empty-state-title { font-size: 16px; font-weight: 700; color: var(--text); }

.search-bar { display: flex; align-items: center; gap: 8px; background: var(--pill-bg); border-radius: 10px; padding: 9px 12px; margin-bottom: 14px; }
.search-bar input { border: none; background: none; flex: 1; font-size: 15px; color: var(--text); min-width: 0; }
.search-bar input:focus { outline: none; }

.segmented { display: flex; background: var(--pill-bg); border-radius: 10px; padding: 3px; }
.segmented button { flex: 1; border: none; background: none; padding: 7px 10px; border-radius: 8px; font-size: 12.5px; font-weight: 700; color: var(--text-secondary); cursor: pointer; font-family: inherit; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; z-index: 100; padding: 12px; }
@media (min-width: 560px) { .modal-overlay { align-items: center; } }
.modal-sheet { background: var(--surface); border-radius: 18px; width: 100%; max-width: 420px; padding: 22px; box-shadow: var(--shadow); }
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.modal-message { font-size: 14px; color: var(--text-secondary); margin-bottom: 20px; line-height: 1.4; }
.modal-actions { display: flex; gap: 10px; }

.exercise-card { border: 1px solid var(--separator); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.exercise-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.exercise-card-title { font-size: 12.5px; font-weight: 700; color: var(--text-secondary); }
.exercise-remove-btn { background: none; border: none; color: var(--danger); font-size: 12.5px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; font-family: inherit; }
.exercise-fields-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 480px) { .exercise-fields-grid { grid-template-columns: repeat(3, 1fr); } }
.exercise-fields-grid .form-field { margin-bottom: 0; }

.set-row { display: flex; align-items: flex-end; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.set-row .form-field { flex: 1 1 96px; min-width: 96px; margin-bottom: 0; }
.set-row-index {
  font-size: 11.5px; font-weight: 700; color: var(--text-tertiary); background: var(--pill-bg);
  width: 20px; height: 20px; border-radius: 999px; flex-shrink: 0; margin-bottom: 12px;
  display: flex; align-items: center; justify-content: center;
}
.set-remove-btn {
  width: 30px; height: 30px; border-radius: 8px; border: none; background: var(--pill-bg); color: var(--danger);
  display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; margin-bottom: 1px;
}
.set-remove-btn:hover { background: rgba(255,59,48,.15); }

.chart-card { background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); padding: 16px; }
.chart-title { font-size: 14px; font-weight: 700; margin-bottom: 2px; }
.chart-subtitle { font-size: 12px; color: var(--text-secondary); margin-bottom: 12px; }
.chart-empty { padding: 24px 0; text-align: center; color: var(--text-tertiary); font-size: 13px; }

.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-danger { color: var(--danger); }
.flex-row { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.wrap { flex-wrap: wrap; }

.banner {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px;
  background: rgba(255, 149, 0, .12); color: #a35d00; font-size: 13px; font-weight: 600; margin-bottom: 16px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .banner { color: #ffb340; } }
:root[data-theme="dark"] .banner { color: #ffb340; }
.loading-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--accent); display: inline-block; animation: pulse 1s infinite ease-in-out; }
@keyframes pulse { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }
