@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Space+Mono:wght@400;600&display=swap");

:root {
  --bg: #f8fafc;
  --bg-2: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-soft: #94a3b8;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.12);
  --radius: 8px;
  --radius-lg: 8px;
  --font-display: "Space Grotesk", "Segoe UI", sans-serif;
  --font-mono: "Space Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #0f172a;
    --bg-2: #111827;
    --surface: #111c2f;
    --surface-2: #0f1a2b;
    --border: rgba(148, 163, 184, 0.2);
    --text: #f8fafc;
    --text-muted: rgba(226, 232, 240, 0.68);
    --text-soft: rgba(148, 163, 184, 0.6);
    --accent-soft: rgba(96, 165, 250, 0.18);
    --shadow: 0 24px 60px rgba(2, 6, 23, 0.45);
  }
}

:root[data-theme="dark"] {
  --bg: #0f172a;
  --bg-2: #111827;
  --surface: #111c2f;
  --surface-2: #0f1a2b;
  --border: rgba(148, 163, 184, 0.2);
  --text: #f8fafc;
  --text-muted: rgba(226, 232, 240, 0.68);
  --text-soft: rgba(148, 163, 184, 0.6);
  --accent-soft: rgba(96, 165, 250, 0.18);
  --shadow: 0 24px 60px rgba(2, 6, 23, 0.45);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-display);
  color: var(--text);
  background:
    radial-gradient(700px 600px at 12% -10%, rgba(37, 99, 235, 0.18), transparent 55%),
    radial-gradient(700px 600px at 88% 0%, rgba(14, 116, 144, 0.16), transparent 55%),
    radial-gradient(700px 700px at 50% 110%, rgba(59, 130, 246, 0.14), transparent 60%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 260px;
  gap: 24px;
  padding: 24px 24px 80px;
}

.sidebar {
  display: grid;
  gap: 24px;
  align-content: start;
  position: sticky;
  top: 24px;
  height: fit-content;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mobile-brand {
  display: none;
  justify-content: center;
  margin-bottom: 12px;
  gap: 8px;
  align-items: center;
  text-align: center;
  width: 100%;
}

.mobile-brand {
  flex-direction: column;
}

.mobile-brand .brand-mark {
  margin: 0 auto;
}

.mobile-account-btn {
  width: 100%;
  max-width: 220px;
  border-radius: 999px;
  border: 1px solid rgba(37, 99, 235, 0.35);
  background: var(--accent-soft);
  font-weight: 600;
  align-self: center;
  position: relative;
  z-index: 1;
  pointer-events: auto;
}

.link-btn {
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-display);
}

.brand-text {
  display: none;
}

.brand-mark {
  width: 220px;
  max-width: 100%;
  border-radius: var(--radius);
  background: transparent;
  border: none;
  display: grid;
  place-items: center;
  overflow: visible;
  padding: 0;
}

.brand-logo {
  width: 100%;
  height: auto;
  object-fit: contain;
  display: block;
}

.brand-logo.dark-logo {
  display: none;
}

:root[data-theme="dark"] .brand-logo.dark-logo {
  display: block;
}

:root[data-theme="dark"] .brand-logo.light-logo {
  display: none;
}

:root[data-theme="light"] .brand-logo.dark-logo {
  display: none;
}

:root[data-theme="light"] .brand-logo.light-logo {
  display: block;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .brand-logo.dark-logo {
    display: block;
  }

  :root[data-theme="auto"] .brand-logo.light-logo {
    display: none;
  }
}

.brand-title {
  font-weight: 700;
  font-size: 18px;
}

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

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  padding: 10px 12px;
  border-radius: var(--radius);
  text-align: left;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.2s ease, color 0.2s ease;
}

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

.nav-item.active {
  background: var(--accent-soft);
  color: var(--text);
  border-color: rgba(37, 99, 235, 0.2);
}

.nav-label {
  font-weight: 600;
}

.sidebar-actions {
  display: grid;
  gap: 12px;
}

.main {
  display: grid;
  gap: 18px;
}

.rail {
  display: grid;
  gap: 16px;
  align-content: start;
  position: sticky;
  top: 24px;
  height: fit-content;
}

.rail-card {
  display: grid;
  gap: 12px;
}

.rail-stat {
  font-size: 22px;
  font-weight: 700;
}

.rail-sub {
  font-size: 13px;
  color: var(--text-muted);
}

.tab-panel {
  display: none;
  gap: 18px;
}

.tab-panel.active {
  display: grid;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow);
  opacity: 1;
  transform: none;
}

body.loaded .panel {
  animation: fadeUp 0.45s ease both;
  animation-delay: var(--delay, 0s);
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

.panel-header h2,
.panel-header h3 {
  margin: 0;
  font-size: 16px;
}

.hero-panel {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.hero-left {
  display: grid;
  gap: 6px;
}

.hero-right {
  display: grid;
  gap: 12px;
  align-content: start;
}

.eyebrow {
  margin: 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--text-soft);
}

h1 {
  margin: 0;
  font-size: 28px;
}

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

#accountStatus {
  font-size: 12px;
  color: var(--text-muted);
}

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

.auth-note {
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px dashed rgba(37, 99, 235, 0.35);
  background: rgba(37, 99, 235, 0.08);
}

.streak-pill {
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
}

.focus-text {
  font-size: 14px;
  color: var(--text-muted);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.stat-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 6px;
}

.stat-title {
  font-size: 12px;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
}

.stat-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.group-list,
.feed-list,
.leaderboard {
  display: grid;
  gap: 12px;
}

.group-card {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 12px;
  display: grid;
  gap: 6px;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.2s ease;
}

.group-card:hover {
  transform: translateY(-1px);
  border-color: rgba(37, 99, 235, 0.3);
}

.group-card.active {
  border-color: rgba(37, 99, 235, 0.5);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.group-title {
  font-weight: 600;
}

.group-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 9px 14px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.2s ease, background 0.2s ease;
  font-family: var(--font-display);
}

.btn:disabled,
.inputText:disabled,
.textarea:disabled,
select.inputText:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  filter: none;
}

.btn:hover {
  filter: brightness(0.98);
}

.btn:active {
  transform: scale(0.98);
}

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

.btn.ghost {
  background: transparent;
}

.btn.danger {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.4);
}

.seg {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 4px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.seg button {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font-display);
}

.seg button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

.member-role {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.log-toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.log-panel {
  display: grid;
  gap: 12px;
}

.log-panel[hidden] {
  display: none;
}

.library {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.progress-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.progress-summary .note {
  grid-column: 1 / -1;
}

.summary-card {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 6px;
}

.summary-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.summary-value {
  font-size: 20px;
  font-weight: 700;
}

.summary-value span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.summary-meta {
  font-size: 12px;
  color: var(--text-muted);
}

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

.progress-block {
  display: grid;
  gap: 12px;
}

.progress-body-list {
  display: grid;
  gap: 10px;
}

.body-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.body-stat-title {
  font-weight: 600;
  font-size: 13px;
}

.body-stat-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.progress-insights {
  margin-top: 16px;
  display: grid;
  gap: 10px;
}

.insight-list {
  display: grid;
  gap: 10px;
}

.insight-card {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 8px;
}

.insight-card.warn {
  border-color: rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.08);
}

.insight-card.nudge {
  border-color: rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.08);
}

.insight-card.success {
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.08);
}

.insight-card.info {
  border-color: rgba(59, 130, 246, 0.35);
  background: rgba(59, 130, 246, 0.06);
}

.insight-header {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.insight-badge {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.insight-title {
  font-weight: 600;
  font-size: 13px;
}

.insight-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.insight-body {
  font-size: 13px;
}

.insight-action {
  font-size: 12px;
  color: var(--text-muted);
}

.live-setup {
  display: grid;
  gap: 16px;
  margin-top: 12px;
}

.live-setup .seg {
  width: 100%;
  justify-content: flex-start;
}

.live-block {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 10px 12px;
}

.history-item summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.history-item summary::-webkit-details-marker {
  display: none;
}

.history-title {
  font-weight: 600;
  font-size: 14px;
}

.history-meta {
  font-size: 12px;
  color: var(--text-muted);
  text-align: right;
}

.history-body {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.history-ex {
  display: grid;
  gap: 4px;
}

.history-ex-title {
  font-weight: 600;
  font-size: 13px;
}

.history-ex-sets {
  font-size: 12px;
  color: var(--text-muted);
}

.body-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.body-chip-row.disabled {
  opacity: 0.6;
  pointer-events: none;
}

.chip-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.chip-btn.active {
  background: var(--accent-soft);
  border-color: rgba(37, 99, 235, 0.4);
  color: var(--text);
}

.exercise-picker {
  width: 100%;
}

.library-list {
  display: grid;
  gap: 8px;
}

.member-suggestions {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.member-suggestions:empty {
  display: none;
}

.library-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.library-title {
  font-weight: 600;
  font-size: 13px;
}

.library-tags,
.exercise-tags {
  font-size: 11px;
  color: var(--text-muted);
}

.exercise-tags {
  margin-top: -4px;
}

.exercise-list {
  display: grid;
  gap: 12px;
}

.exercise-card {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 10px;
}

.exercise-body {
  display: grid;
  gap: 8px;
}

.exercise-card.collapsed .exercise-body {
  display: none;
}

.exercise-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.exercise-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.exercise-toggle {
  border: 0;
  background: transparent;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
}

.exercise-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.set-list {
  display: grid;
  gap: 8px;
}

.set-row {
  display: grid;
  grid-template-columns: 60px 1fr 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.set-row.slide-in {
  animation: slideIn 0.3s ease both;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.set-label {
  font-size: 12px;
  color: var(--text-soft);
}

.inputText,
.textarea,
select.inputText {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 8px 10px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 13px;
}

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

.inputText:focus,
.textarea:focus,
select.inputText:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
  border-color: rgba(37, 99, 235, 0.4);
}

.add-exercise {
  margin-top: 12px;
}

.inline {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.sticky-bar {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.unit-label {
  font-size: 13px;
  color: var(--text-soft);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.chart-card {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 12px;
}

canvas {
  width: 100%;
  height: 220px;
  display: block;
}

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

.detail {
  margin-top: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 12px;
  background: var(--surface-2);
  font-size: 13px;
  color: var(--text-muted);
}

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

.leaderboard-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.leaderboard-row.me {
  border-color: rgba(37, 99, 235, 0.5);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.leaderboard-name {
  font-weight: 600;
}

.leaderboard-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.feed-card {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 12px;
  display: grid;
  gap: 8px;
}

.feed-title {
  font-weight: 600;
}

.feed-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.feed-actions {
  display: flex;
  gap: 8px;
}

.feed-comments {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: none;
  gap: 4px;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.bottom-nav .nav-item {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 12px;
  line-height: 1.2;
  padding: 8px 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  white-space: normal;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 1000;
}

.modal {
  width: min(540px, 100%);
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 18px;
  display: grid;
  gap: 12px;
}

.auth-form {
  display: grid;
  gap: 8px;
}

.auth-form label {
  font-size: 12px;
  color: var(--text-muted);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.option-grid {
  display: grid;
  gap: 8px;
}

.option-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.option-btn.selected {
  border-color: rgba(37, 99, 235, 0.5);
  background: var(--accent-soft);
}

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

@media (max-width: 1200px) {
  .app-shell {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .rail {
    display: none;
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding-bottom: 100px;
  }

  .sidebar {
    display: none;
  }

  .mobile-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .mobile-brand .brand-mark {
    width: 200px;
  }

  .bottom-nav {
    display: grid;
  }

  .progress-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .panel {
    padding: 14px;
  }

  .set-row {
    grid-template-columns: 1fr 1fr 1fr auto;
  }

  .hero-panel {
    flex-direction: column;
    align-items: flex-start;
  }
}
