:root {
  --bg: #0f1115;
  --surface: #181b21;
  --surface-elevated: #20242d;
  --surface-hover: #252a35;
  --border: #262a34;
  --border-strong: #343a47;

  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;

  --gym: #38bdf8;
  --gym-soft: rgba(56, 189, 248, 0.14);
  --walk: #34d399;
  --walk-soft: rgba(52, 211, 153, 0.14);
  --body: #fbbf24;
  --body-soft: rgba(251, 191, 36, 0.14);
  --purple: #a78bfa;
  --purple-soft: rgba(167, 139, 250, 0.15);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --nav-height: 64px;
  --sidebar-width: 232px;
  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.25);
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang HK", "Noto Sans TC", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

a {
  color: var(--gym);
  text-decoration: none;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* Shell & Navigation */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: rgba(24, 27, 33, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-brand {
  display: none;
}

.nav-links {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: var(--nav-height);
  max-width: 640px;
  margin: 0 auto;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  transition: color 0.16s ease, background 0.16s ease;
  -webkit-tap-highlight-color: transparent;
}

.nav-item svg {
  width: 21px;
  height: 21px;
}

.nav-item:hover {
  color: var(--text);
}

.nav-item.active {
  color: var(--gym);
}

.nav-item[data-tab="cardio"].active {
  color: var(--walk);
}

.nav-item[data-tab="body"].active {
  color: var(--body);
}

.app-content-wrap {
  flex: 1;
  width: 100%;
  max-width: 1140px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 14px calc(var(--nav-height) + 28px + env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.page-title {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.app-main {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

/* Desktop Sidebar Breakpoint */
@media (min-width: 900px) {
  .app-nav {
    top: 0;
    bottom: 0;
    right: auto;
    width: var(--sidebar-width);
    border-top: none;
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    gap: 20px;
  }

  .nav-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 4px 8px;
  }

  .nav-brand-icon {
    border-radius: 8px;
    flex-shrink: 0;
  }

  .nav-brand-text {
    display: flex;
    flex-direction: column;
  }

  .nav-brand-title {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
  }

  .nav-brand-sub {
    font-size: 11px;
    color: var(--text-muted);
  }

  .nav-links {
    display: flex;
    flex-direction: column;
    gap: 4px;
    height: auto;
    margin: 0;
  }

  .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 11px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
  }

  .nav-item.active {
    background: var(--surface-elevated);
  }

  .app-content-wrap {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    max-width: 1180px;
    padding: 26px 32px 44px;
  }

  .page-title {
    font-size: 25px;
  }
}

/* Cards & Layout Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-card);
  min-width: 0;
}

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

.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.kpi-grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 520px) {
  .kpi-grid.cols-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 900px) {
  .kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
  }
  .kpi-grid.cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

.kpi-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--border-strong);
}

.kpi-card.accent-gym::before { background: var(--gym); }
.kpi-card.accent-walk::before { background: var(--walk); }
.kpi-card.accent-body::before { background: var(--body); }

.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.kpi-value {
  font-size: 22px;
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.kpi-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

@media (min-width: 900px) {
  .grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Progress Bars */
.progress-track {
  width: 100%;
  height: 6px;
  background: var(--surface-elevated);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 2px;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.35s ease;
}

.progress-fill.gym { background: var(--gym); }
.progress-fill.walk { background: var(--walk); }
.progress-fill.body { background: var(--body); }

/* Charts */
.chart-wrap {
  position: relative;
  width: 100%;
  height: 250px;
}

@media (min-width: 900px) {
  .chart-wrap {
    height: 300px;
  }
}

/* Activity Heatmap (180 days) */
.heatmap-scroll {
  overflow-x: auto;
  padding-bottom: 6px;
  -webkit-overflow-scrolling: touch;
}

.heatmap-board {
  display: inline-flex;
  align-items: flex-start;
  gap: 6px;
}

.heatmap-days {
  display: grid;
  grid-template-rows: repeat(7, 13px);
  gap: 3px;
  font-size: 10px;
  color: var(--text-dim);
  line-height: 13px;
  padding-top: 1px;
  user-select: none;
}

.heatmap-grid {
  display: grid;
  grid-template-rows: repeat(7, 13px);
  grid-auto-flow: column;
  gap: 3px;
}

.hm-cell {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  background: #1f2430;
  border: none;
  padding: 0;
  cursor: pointer;
  transition: transform 0.12s ease, outline 0.12s ease;
}

.hm-cell:hover,
.hm-cell:focus-visible {
  transform: scale(1.22);
  outline: 1.5px solid var(--text);
  z-index: 2;
}

.hm-cell.empty-pad {
  background: transparent;
  pointer-events: none;
}

.hm-cell.s-0 { background: #202530; }
.hm-cell.s-1 { background: var(--gym); }
.hm-cell.s-2 { background: var(--walk); }
.hm-cell.s-3 { background: linear-gradient(135deg, var(--gym) 50%, var(--walk) 50%); }

.heatmap-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.heatmap-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  display: inline-block;
}

/* Segmented Controls & Pills */
.segmented {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 11px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg-btn.active {
  background: var(--surface-elevated);
  color: var(--text);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-gym { background: var(--gym-soft); color: var(--gym); }
.badge-walk { background: var(--walk-soft); color: var(--walk); }
.badge-body { background: var(--body-soft); color: var(--body); }
.badge-purple { background: var(--purple-soft); color: var(--purple); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: var(--surface-elevated); color: var(--text-muted); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 12px;
}

.btn-primary {
  background: var(--gym);
  color: #08121a;
}

.btn-primary:hover:not(:disabled) {
  background: #5ccbfa;
}

.btn-walk {
  background: var(--walk);
  color: #062118;
}

.btn-walk:hover:not(:disabled) {
  background: #52dfa9;
}

.btn-body {
  background: var(--body);
  color: #1f1402;
}

.btn-secondary {
  background: var(--surface-elevated);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn-danger-ghost {
  background: transparent;
  border-color: rgba(248, 113, 113, 0.35);
  color: var(--danger);
}

.btn-icon {
  width: 38px;
  min-height: 38px;
  padding: 0;
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-muted);
}

.btn-icon:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.form-grid .full {
  grid-column: 1 / -1;
}

@media (max-width: 480px) {
  .form-grid.stack-mobile {
    grid-template-columns: minmax(0, 1fr);
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease;
}

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

.textarea {
  min-height: 70px;
  resize: vertical;
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-row .input {
  flex: 1;
  min-width: 0;
}

/* Lists, Accordions & Tables */
.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.overload-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.overload-main {
  min-width: 0;
  flex: 1 1 170px;
}

.overload-name {
  font-weight: 650;
  font-size: 14px;
}

.overload-stats {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.overload-advice {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}

.accordion-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.accordion-trigger {
  width: 100%;
  background: transparent;
  border: none;
  padding: 13px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}

.accordion-trigger:hover {
  background: var(--surface-elevated);
}

.accordion-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
}

.accordion-chevron {
  color: var(--text-muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.accordion-item.open .accordion-chevron {
  transform: rotate(180deg);
}

.accordion-body {
  border-top: 1px solid var(--border);
  padding: 12px 14px;
  background: rgba(15, 17, 21, 0.55);
}

.exercise-block {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.exercise-block:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.exercise-block-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 14px;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
  padding: 7px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* Cardio Row Card */
.session-row {
  padding: 13px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.session-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.session-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.session-metric strong {
  color: var(--text);
}

.session-metric span {
  color: var(--text-muted);
  font-size: 12px;
}

/* Code Snippet & Dropzone */
.code-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  color: #d1d5db;
  overflow-x: auto;
  white-space: pre;
  margin: 0;
}

.url-copy-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px 6px 11px;
}

.url-copy-row code {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--gym);
}

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 20px 14px;
  text-align: center;
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone.dragover {
  border-color: var(--gym);
  background: var(--gym-soft);
}

.dropzone p {
  margin: 4px 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* Empty State & Loading Skeleton */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 32px 16px;
  color: var(--text-muted);
}

.empty-state.compact {
  padding: 20px 12px;
}

.empty-state h3 {
  margin: 0;
  font-size: 15px;
  color: var(--text);
}

.empty-state p {
  margin: 0;
  font-size: 13px;
  max-width: 380px;
}

.skeleton-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.skeleton-box {
  height: 92px;
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-elevated) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

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

.modal-root.hidden {
  display: none;
}

@media (min-width: 640px) {
  .modal-root {
    align-items: center;
  }
}

.modal-card {
  width: 100%;
  max-width: 500px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

/* Toast */
.toast-container {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  right: 14px;
  left: 14px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  max-width: 440px;
}

.toast.success { border-left: 3px solid var(--walk); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--gym); }

.divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

.muted-note {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}

.delta-up { color: var(--danger); }
.delta-down { color: var(--walk); }
.delta-flat { color: var(--text-muted); }
