:root {
  --bg:           #0f1117;
  --surface:      #1c1f2a;
  --border:       #2a2d3a;
  --border-input: #3a3d4a;
  --text:         #e0e0e0;
  --text-muted:   #888;
  --text-label:   #aaa;
  --text-heading: #fff;
  --text-card:    #ccc;
  --accent:       #4ade80;
  --accent-hover: #22c55e;
  --accent-t:     rgba(74,222,128,0.15);
  --blue:         #60a5fa;
  --red:          #f87171;
  --grid:         rgba(255,255,255,0.06);
  --tick:         #666;
  --hover:        rgba(255,255,255,0.08);
  --year2:        rgba(96,165,250,0.9);
  --year3:        rgba(249,115,22,0.9);
  --year4:        rgba(167,139,250,0.9);
  --year5:        rgba(251,113,133,0.9);
  --year6:        rgba(250,204,21,0.9);
  --bar-selected:   rgba(96,165,250,0.55);
  --bar-unselected:  rgba(96,165,250,0.2);
  --goal-line:    rgba(250,204,21,0.6);
  --radius-sm:    6px;
  --radius-md:    8px;
  --radius-lg:    12px;
  --radius-xl:    16px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:           #f5f5f7;
    --surface:      #ffffff;
    --border:       #e2e4ea;
    --border-input: #d0d0d8;
    --text:         #1a1a1a;
    --text-muted:   #666;
    --text-label:   #555;
    --text-heading: #111;
    --text-card:    #333;
    --accent:       #16a34a;
    --accent-hover: #15803d;
    --accent-t:     rgba(22,163,74,0.12);
    --blue:         #2563eb;
    --red:          #dc2626;
    --grid:         rgba(0,0,0,0.06);
    --tick:         #999;
    --hover:        rgba(0,0,0,0.06);
    --year2:        rgba(37,99,235,0.9);
    --year3:        rgba(234,88,12,0.9);
    --year4:        rgba(109,40,217,0.9);
    --year5:        rgba(190,18,60,0.9);
    --year6:        rgba(161,98,7,0.9);
    --bar-selected:   rgba(37,99,235,0.55);
    --bar-unselected:  rgba(37,99,235,0.2);
    --goal-line:    rgba(161,98,7,0.6);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 72px 24px 32px;
  min-height: 100vh;
}
@media (max-width: 540px) {
  html { font-size: 112%; }
  body { padding: 64px 16px 20px; }
}
.topbar {
  display: flex;
  align-items: center;
  padding: 0 24px;
  height: 48px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
}
@media (max-width: 540px) {
  .topbar { padding: 0 16px; }
}
.is-staging .topbar { background: repeating-linear-gradient(135deg, #7c3aed 0px, #7c3aed 10px, #6d28d9 10px, #6d28d9 20px); }
.is-staging .topbar::after { content: "TESTMILJÖ"; font-size: 0.65rem; font-weight: 700; letter-spacing: .1em; color: #fff; background: rgba(0,0,0,0.25); border-radius: 3px; padding: 2px 7px; margin-left: 8px; }
.topbar-back { font-size: 0.78rem; color: var(--accent); text-decoration: none; opacity: 0.7; margin-right: 16px; white-space: nowrap; }
.topbar-back:hover { opacity: 1; }
.topbar-title { font-size: 0.8rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); flex: 1; }
.topbar-version { font-size: 0.65rem; color: var(--text-muted); opacity: 0.6; margin-right: 8px; white-space: nowrap; }
.fetch-status {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%) translateY(-100%);
  background: var(--surface);
  border: 1px solid var(--accent);
  border-top: none;
  border-radius: 0 0 10px 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  padding: 7px 18px;
  font-size: 0.82rem;
  color: var(--text);
  white-space: nowrap;
  pointer-events: none;
  z-index: 51;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
}
.fetch-status:not(:empty) {
  opacity: 1;
  transform: translateX(-50%) translateY(0%);
}
.fetch-status.error   { color: var(--red); }
.fetch-status.pulsing { animation: fetch-pulse 1.4s ease-in-out infinite; }
h1 { font-size: 1.6rem; font-weight: 600; margin-bottom: 4px; color: var(--text-heading); }
.subtitle { color: var(--text-muted); font-size: 0.95rem; margin-bottom: 28px; }

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius-md);
  padding: 11px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 6px;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

/* Settings-knapp i topbar */
.topbar-icon-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.5rem; padding: 4px 6px; line-height: 1; }
.topbar-icon-btn:hover { color: var(--accent); }

/* Settings-modal */
.modal-settings-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; font-size: 0.95rem; font-weight: 600; color: var(--text-card); }
.modal-close-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.1rem; padding: 2px 4px; line-height: 1; }
.modal-close-btn:hover { color: var(--text-card); }
.settings-modal-body { overflow: hidden; flex: 1; display: flex; flex-direction: column; padding: 16px 16px 16px; margin-bottom: 0; border: none; border-radius: 0; background: none; }
.profile-header { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 20px 16px 18px; text-align: center; }
.profile-avatar { width: 64px; height: 64px; border-radius: 50%; background: var(--surface); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--text-muted); flex-shrink: 0; }
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-avatar svg { width: 30px; height: 30px; }
.profile-name { font-size: 1rem; font-weight: 700; color: var(--text-heading); }
.profile-name:empty { display: none; }
.profile-fields { justify-content: center; margin-top: 4px; }
.settings-tabs { display: flex; border-bottom: 1px solid var(--border); padding: 0 16px; flex-shrink: 0; }
.settings-tab { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: none; border: none; border-bottom: 2px solid transparent; padding: 10px 16px; margin-bottom: -1px; font-size: 0.9rem; color: var(--text-muted); cursor: pointer; }
.settings-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.settings-tab-chevron { flex-shrink: 0; color: var(--text-muted); }
.settings-detail-header { display: none; }
.settings-back-btn { display: flex; align-items: center; gap: 4px; background: none; border: none; color: var(--text-heading); font-size: 0.95rem; font-weight: 700; cursor: pointer; padding: 4px 0; }
.settings-back-btn svg { color: var(--accent); flex-shrink: 0; }

/* Kontrollrad */
.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
}
.controls label { color: var(--text-label); font-size: 0.88rem; white-space: nowrap; }
.ctrl-group { display: flex; align-items: center; gap: 8px; }
.ctrl-section { display: flex; flex-direction: column; gap: 8px; }
.ctrl-section-label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); }
.ctrl-section-fields { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ctrl-section-divider { height: 1px; background: var(--border); margin: 10px 0 18px; }
.settings-tab-pane { width: 100%; display: flex; flex-direction: column; flex: 1; overflow-y: auto; scrollbar-gutter: stable; }
.controls input[type=date],
.controls input[type=number] {
  background: var(--bg);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-md);
  color: var(--text);
  padding: 7px 12px;
  font-size: 0.9rem;
}
.controls input[type=number] { width: 72px; -moz-appearance: textfield; }
.controls input[type=number]:focus { outline: none; border-color: var(--accent); }
.controls input[type=number]::-webkit-inner-spin-button,
.controls input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.type-exclusion-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
.type-exclusion-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.82rem;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  cursor: pointer;
  user-select: none;
}
.type-exclusion-label:has(input:checked) {
  border-color: var(--accent);
  color: var(--accent);
}
.type-exclusion-label input { accent-color: var(--accent); }
.controls select {
  background: var(--bg);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-md);
  color: var(--text);
  padding: 7px 10px;
  font-size: 0.9rem;
  cursor: pointer;
}
.controls select:focus { outline: none; border-color: var(--accent); }
.start-day   { width: 58px; }
.start-month { width: 120px; }
.controls span { color: var(--text-muted); font-size: 0.88rem; }
.controls .divider { display: none; }
.prompt-hint { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 8px; }
.prompt-hint code { background: var(--surface-raised, var(--border)); border-radius: 3px; padding: 1px 4px; font-size: 0.72rem; color: var(--accent); }
#coach-prompt-template { width: 100%; font-size: 0.82rem; font-family: inherit; color: var(--text-card); background: var(--bg); border: 1px solid var(--border-input); border-radius: var(--radius-sm); padding: 10px 12px; resize: none; line-height: 1.55; field-sizing: content; overflow: hidden; }
#coach-prompt-template:focus { outline: none; border-color: var(--accent); }
@keyframes spin  { to { transform: rotate(360deg); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.refresh-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: color 0.15s;
  line-height: 0;
  margin-right: 4px;
  display: flex;
  align-items: center;
}
.refresh-btn svg {
  width: 18px;
  height: 18px;
}
.refresh-btn:hover  { color: var(--accent); }
.refresh-btn.spinning { animation: spin 0.8s linear infinite; color: var(--accent); }
.refresh-btn:disabled   { opacity: 0.35; cursor: default; }
.refresh-btn.rate-limited { animation: shake 0.4s ease; color: var(--text-muted); }
.more-menu { position: relative; }
.more-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.more-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text-muted);
  border-radius: 2px;
  transition: background 0.15s;
}
.more-btn:hover span { background: var(--accent); }
.more-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-width: 160px;
  z-index: 100;
  overflow: hidden;
}
.more-dropdown.active { display: block; }
.more-dropdown button {
  display: block;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 10px 16px;
  text-align: left;
  font-size: 0.88rem;
  cursor: pointer;
}
.more-dropdown button:hover { background: var(--hover); }
.more-dropdown button.danger:hover { color: var(--red); }
.ctrl-btn {
  background: transparent;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  padding: 7px 16px;
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
}
.ctrl-btn:hover { border-color: var(--accent); color: var(--accent); }
a.ctrl-btn { display: inline-block; text-decoration: none; line-height: 1; }
.ai-action-link {
  display: inline-block;
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.ctrl-btn:disabled { opacity: 0.4; cursor: default; }
.ctrl-btn.danger:hover { border-color: var(--red); color: var(--red); }
.year-select {
  background: var(--bg);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 3px 8px;
  font-size: 0.78rem;
  cursor: pointer;
}
.year-select:focus { outline: none; border-color: var(--accent); }
.year-select-label { font-size: 0.72rem; color: var(--text-muted); opacity: 0.6; white-space: nowrap; }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 28px;
  width: 100%;
  max-width: 380px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-settings { max-width: 560px; max-height: 90vh; display: flex; flex-direction: column; padding: 0; }
.modal h2 { font-size: 1rem; color: var(--text-card); margin-bottom: 20px; }
.modal-info { font-size: 0.78rem; color: var(--text-muted); margin: 12px 0 4px; line-height: 1.5; }

.welcome-box { max-width: 480px; margin: 80px auto; text-align: center; padding: 0 24px; }
.welcome-text { color: var(--text-muted); font-size: 0.95rem; line-height: 1.6; margin-bottom: 16px; }
#welcome-retry-btn { width: auto; padding: 9px 20px; margin-top: 10px; }

.setup-hint p { color: var(--text-muted); font-size: 0.9rem; line-height: 1.5; margin: 0 0 14px; }
.setup-hint-actions { display: flex; align-items: center; gap: 10px; }
.setup-hint-actions .btn-primary { width: auto; padding: 9px 18px; margin-top: 0; }
.setup-hint-actions .btn-icon { color: var(--text-muted); font-size: 1rem; padding: 4px 8px; margin-left: auto; }
.setup-hint-actions .btn-icon:hover { color: var(--text-card); }
.modal-status { font-size: 0.85rem; margin-top: 10px; color: var(--text-muted); min-height: 18px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions button,
.modal-actions a.act-strava-link {
  flex: 1;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 8px 12px;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.modal-actions button:hover,
.modal-actions a.act-strava-link:hover { background: var(--hover); }
.modal-actions button.danger { color: var(--red); border-color: var(--red); }

/* Senaste pass */
.card-latest {
  padding-bottom: 0;
  margin-bottom: 0;
}
.latest-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }
#latest-date  { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 4px; }
.latest-row   { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.latest-name  { font-size: 1rem; font-weight: 600; color: var(--text-heading); }
.latest-chip  { font-size: 0.75rem; color: var(--accent); background: var(--accent-t); border-radius: var(--radius-sm); padding: 2px 8px; text-transform: capitalize; }
.ai-classification-chip { color: #fff; border-radius: var(--radius-sm); padding: 2px 8px; font-size: 0.75rem; }
.cls-distans      { background: #3a7d44; }
.cls-langpass     { background: #1a5fa8; }
.cls-intervall    { background: #9b2335; }
.cls-troskel      { background: #c05a1f; }
.cls-aterhamtning { background: #5a7a2e; }
.cls-styrka       { background: #5b3a8c; }
.cls-teknik       { background: #2a7a7a; }
.cls-test         { background: #8c3a3a; }
.cls-default      { background: #555; }
.latest-meta  { font-size: 0.85rem; color: var(--text-muted); display: flex; gap: 8px; align-items: center; }
.latest-dot   { color: var(--border-input); }
.latest-cls-row { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.latest-tag   { font-size: 0.72rem; color: var(--text-muted); background: var(--bg-input); border-radius: var(--radius-sm); padding: 2px 7px; }
.latest-zone-wrap { display: flex; align-items: flex-start; gap: 12px; margin-top: 10px; }
.latest-zone-bar { display: inline-flex; gap: 3px; align-items: flex-end; height: 36px; margin-top: 3px; }
.latest-zone-hr  { display: flex; flex-direction: column; gap: 2px; font-size: 0.8rem; color: var(--text-muted); }
.zone-col     { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 14px; }
.zone-col-bar { width: 10px; border-radius: 2px 2px 0 0; min-height: 2px; }
.zone-col-lbl { font-size: 0.65rem; color: var(--text-muted); line-height: 1; }

.latest-top  { display: flex; align-items: center; gap: 16px; }
.latest-info { flex: 1; min-width: 0; }
.latest-route { position: relative; flex-shrink: 0; width: 110px; height: 72px; border-radius: var(--radius-md); overflow: hidden; background: var(--bg); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; }
.latest-route svg { position: relative; z-index: 1; width: 110px; height: 72px; }
.activity-route { position: relative; flex-shrink: 0; width: 64px; height: 42px; border-radius: var(--radius-sm); overflow: hidden; background: var(--bg); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; }
.activity-route svg { position: relative; z-index: 1; width: 64px; height: 42px; }
.route-map-bg { position: absolute; inset: 0; opacity: 0.4; border-radius: inherit; }
.activity-main { flex: 1; min-width: 0; }

.card-latest.clickable { cursor: pointer; transition: color 0.15s; }
.card-latest.clickable:hover .latest-name { text-decoration: underline; }

/* Diagram-kort */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 24px;
  margin-bottom: 24px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; }
.card-header h2 { font-size: 1rem; font-weight: 600; color: var(--text-card); margin: 0; }
.card-header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.chart-with-tooltip { display: flex; flex-direction: column; gap: 8px; }
.chart-wrap { height: 180px; }
#wrap-fitness-chart { height: 220px; }
#wrap-tsb-chart     { height: 180px; }
@media (max-width: 540px) {
  .chart-wrap         { height: 130px; }
  #wrap-fitness-chart { height: 160px; }
  #wrap-tsb-chart     { height: 140px; }
  .card               { padding: 14px; margin-bottom: 12px; }
  .card-header        { margin-bottom: 12px; }
.card-latest        { padding-bottom: 10px; margin-bottom: 10px; }
}
canvas { display: block; width: 100%; }
#chart-tooltip {
  font-size: 0.92rem;
  color: var(--text-card);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 16px;
}
.ct-title { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 0; flex: 0 0 4rem; }
.ct-row { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 0; flex: 0 0 auto; display: flex; flex-direction: row; align-items: baseline; gap: 6px; }
.ct-row-value { font-size: 0.95rem; font-weight: 700; color: var(--accent); letter-spacing: 0; text-transform: none; font-variant-numeric: tabular-nums; display: inline-block; width: 6ch; }
@media (max-width: 540px) {
  #chart-tooltip, #fitness-tooltip, #tsb-tooltip { padding: 8px 10px; }
  .topbar-icon-btn { font-size: 1.1rem; }
}

/* Aktivitetslista */
#activities-section { touch-action: pan-y; user-select: none; margin-bottom: 0; }
.swipe-viewport {
  position: relative;
  overflow-x: clip;
  /* body: 64px padding-top + 64px padding-bottom (nav) + safe-area
     card: 24px padding-top + 24px padding-bottom
     card-header: ~38px + 20px margin */
  min-height: calc(100dvh - 234px - env(safe-area-inset-bottom));
}
@media (min-width: 541px) {
  .swipe-viewport { min-height: calc(100dvh - 220px); }
}
.swipe-side { width: 100%; }
#activities-list-next { position: absolute; top: 0; left: 0; width: 100%; }
.activity-row {
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  color: inherit;
  display: flex;
  align-items: center;
  gap: 12px;
}
.activity-row:last-child { border-bottom: none; }
.activity-row:hover { background: var(--hover); border-radius: var(--radius-md); }
.activity-date { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 3px; }
.activity-content-row   { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; flex-wrap: wrap; }
.activity-name  { font-size: 0.9rem; font-weight: 600; color: var(--text-heading); }
.activity-meta  { font-size: 0.82rem; color: var(--text-muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.activity-header { display: flex; align-items: center; gap: 8px; }
.activity-filter-title { font-size: 0.82rem; color: var(--text-muted); margin-left: 4px; }
.activity-empty { font-size: 0.88rem; color: var(--text-muted); padding: 8px 0; }
.act-detail-modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 16px; }
.act-detail-modal-header h2 { margin-bottom: 0; }
.act-detail-heading { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); margin: 14px 0 6px; border-top: 1px solid var(--border); padding-top: 12px; }
.act-detail-modal-header + .act-detail-heading { border-top: none; margin-top: 0; padding-top: 0; }
.act-detail-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin-bottom: 4px; }
.act-detail-row { display: contents; }
.act-detail-label { font-size: 0.82rem; color: var(--text-muted); white-space: nowrap; }
.act-detail-value { font-size: 0.82rem; color: var(--text-card); }
.act-detail-zones { margin-bottom: 16px; }
.act-detail-zone-bar { height: auto !important; }
.act-detail-zone-col { width: 30px !important; }
.act-detail-desc { font-size: 0.82rem; color: var(--text-muted); margin: 0 0 16px; line-height: 1.5; }
.act-strava-link { text-decoration: none; }
.act-nav-btn { background: none; border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-muted); cursor: pointer; font-size: 0.82rem; padding: 2px 8px; line-height: 1.4; display: inline-flex; align-items: center; }
.act-nav-btn:hover { background: var(--hover); color: var(--text); }
@media (hover: none) { .act-nav-btn:not(.act-today-btn) { display: none; } }

.strava-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 8px;
  gap: 12px;
}
.strava-footer a { color: var(--accent); font-size: 0.85rem; text-decoration: none; }
.strava-footer a:hover { text-decoration: underline; }
.strava-badge { height: 24px; display: block; }
.stat-value.form-negative { color: var(--red); }
#fitness-tooltip,
#tsb-tooltip {
  font-size: 0.92rem;
  color: var(--text-card);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 16px;
}

.hidden { display: none; }
.btn-icon { background: none; border: none; cursor: pointer; padding: 0; }
.strava-brand { color: #FC5200; font-weight: 700; }

/* Fetch spinner */
@keyframes fetch-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}

/* AI-analys */
.ai-output.ai-loading { animation: fetch-pulse 1.4s ease-in-out infinite; }
.ai-output {
  white-space: pre-wrap;
  font-size: 0.88rem;
  line-height: 1.65;
  padding: 8px 0;
  min-height: 1.5em;
  color: var(--text-card);
}
.ai-usage {
  font-size: 0.73rem;
  color: var(--text-muted);
  margin-top: 4px;
}
.ai-output-meta {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.ai-usage-chip {
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg-card-alt, rgba(255,255,255,0.06));
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 10px;
  white-space: nowrap;
  flex-shrink: 0;
}
.ai-coach-output {
  border-top: 1px solid var(--border);
  margin-top: 10px;
  padding-top: 10px;
  white-space: normal;
}
.ai-coach-output h1, .ai-coach-output h2, .ai-coach-output h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 10px 0 4px;
  color: var(--text-heading);
}
.ai-coach-output ul, .ai-coach-output ol {
  padding-left: 1.4em;
  margin: 4px 0;
}
.ai-coach-output li { margin: 2px 0; }
.ai-coach-output p  { margin: 4px 0; }
.ai-coach-output strong { font-weight: 700; }
.ai-chat {
  border-top: 1px solid var(--border);
  margin-top: 10px;
  padding-top: 10px;
}
.ai-chat-messages { display: flex; flex-direction: column; gap: 8px; }
.ai-chat-messages:not(:empty) { margin-bottom: 10px; }
.ai-chat-msg {
  max-width: 85%;
  font-size: 0.88rem;
  line-height: 1.5;
  white-space: pre-wrap;
  padding: 8px 12px;
  border-radius: var(--radius-md);
}
.ai-chat-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--bg);
}
.ai-chat-msg.assistant {
  align-self: flex-start;
  background: var(--bg-card-alt, rgba(255,255,255,0.06));
  border: 1px solid var(--border);
  color: var(--text-card);
}
.ai-chat-msg.assistant.ai-loading { animation: fetch-pulse 1.4s ease-in-out infinite; }
.ai-chat-form { display: flex; gap: 8px; }
.ai-chat-input {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  font-family: inherit;
  color: var(--text-card);
  background: var(--bg);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}
.ai-chat-input:focus { outline: none; border-color: var(--accent); }
.ai-chat-input:disabled { opacity: 0.5; }
.ai-chat-send { width: auto; padding: 8px 16px; margin-top: 0; font-size: 0.85rem; }
.manifest-status { display: flex; flex-direction: column; gap: 8px; }
.manifest-filename {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.settings-tab:focus { outline: none; }

/* ── Bottom navigation ───────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 60;
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav.hidden { display: none; }

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav-item:hover { color: var(--text); }
.bottom-nav-item.active { color: var(--accent); }

.bottom-nav-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.bottom-nav-label {
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: .02em;
  line-height: 1;
}

body.has-bottom-nav {
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
@media (max-width: 540px) {
  body.has-bottom-nav {
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }
}

/* Desktop: nav som vänsterkolumn */
@media (min-width: 541px) {
  .bottom-nav {
    flex-direction: column;
    top: 48px;
    bottom: 0;
    right: auto;
    width: 76px;
    border-top: none;
    border-right: 1px solid var(--border);
    padding: 8px 0 0;
    justify-content: flex-start;
    align-items: stretch;
  }
  .bottom-nav .bottom-nav-item {
    flex: none;
    padding: 14px 0;
  }
  body.has-bottom-nav {
    padding-bottom: 32px;
    padding-left: calc(76px + 24px);
  }
}

.coming-soon-text {
  color: var(--text-muted);
  text-align: center;
  padding: 24px 0;
  font-size: 0.9rem;
}

/* ── Settings view (inline, inte modal) ──────────────────────────────────── */
.settings-info-text {
  color: var(--text-card);
  font-size: 0.9rem;
  line-height: 1.5;
  margin: 0 0 10px;
}
.settings-info-text a { color: var(--accent); }
.settings-view-body {
  padding: 16px 0;
}
.settings-view-body .settings-tab-pane {
  overflow-y: visible;
  flex: none;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
  padding: 0 16px;
}

/* ── Statistiksida ───────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 380px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
.stats-block { background: var(--bg); border-radius: var(--radius-md); padding: 12px 8px; text-align: center; }
.stats-block-value { font-size: 1.15rem; font-weight: 700; color: var(--text-heading); line-height: 1.2; font-variant-numeric: tabular-nums; }
.stats-block-label { font-size: 0.68rem; color: var(--text-muted); margin-top: 3px; text-transform: uppercase; letter-spacing: .04em; }
.stats-month-chart { display: flex; flex-direction: column; }
.stats-month-bars { display: flex; align-items: flex-end; gap: 4px; height: 90px; }
.stats-month-bar { flex: 1; min-height: 0; border-radius: 3px 3px 0 0; background: var(--accent); opacity: 0.35; }
.stats-month-bar.current { opacity: 0.8; }
.stats-month-labels { display: flex; gap: 4px; margin-top: 5px; }
.stats-month-label { flex: 1; text-align: center; font-size: 0.6rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; }
.stats-type-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.stats-type-row:last-child { border-bottom: none; }
.stats-type-name { font-size: 0.85rem; color: var(--text-card); text-transform: capitalize; min-width: 80px; flex-shrink: 0; }
.stats-type-bar-wrap { flex: 1; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.stats-type-bar { height: 100%; background: var(--accent); border-radius: 3px; }
.stats-type-value { font-size: 0.82rem; color: var(--text-muted); min-width: 5ch; text-align: right; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.stats-metric-toggle { display: flex; background: var(--bg); border-radius: var(--radius-sm); padding: 2px; gap: 2px; }
.stats-metric-btn { border: none; background: none; font-size: 0.75rem; padding: 4px 10px; border-radius: calc(var(--radius-sm) - 2px); color: var(--text-muted); cursor: pointer; }
.stats-metric-btn.active { background: var(--accent); color: #fff; }
.stats-record-row { display: flex; align-items: baseline; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); gap: 16px; }
.stats-record-row:last-child { border-bottom: none; }
.stats-record-label { font-size: 0.82rem; color: var(--text-muted); flex-shrink: 0; }
.stats-record-right { text-align: right; }
.stats-record-value { font-size: 0.9rem; color: var(--text-card); font-weight: 600; display: block; }
.stats-record-name { font-size: 0.72rem; color: var(--text-muted); display: block; margin-top: 1px; }

/* Mobil: lista med rader, drill-down till underskärm */
@media (max-width: 540px) {
  #view-settings .profile-header {
    position: sticky;
    top: 48px;
    z-index: 11;
    background: var(--bg);
    margin: 0 -16px;
    padding: 14px 16px 16px;
    border-bottom: 1px solid var(--border);
  }
  #view-settings.settings-detail-active .profile-header { display: none; }
  #view-settings .settings-tabs {
    flex-direction: column;
    gap: 10px;
    border-bottom: none;
    padding: 4px 16px 0;
  }
  #view-settings .settings-tab {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border-bottom: none;
    margin-bottom: 0;
    padding: 16px 18px;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-heading);
  }
  #view-settings .settings-tab.active { color: var(--text-heading); }
  #view-settings.settings-detail-active .settings-tabs { display: none; }
  #view-settings:not(.settings-detail-active) .settings-detail-header { display: none; }
  #view-settings.settings-detail-active .settings-detail-header {
    display: flex;
    position: sticky;
    top: 48px;
    z-index: 10;
    background: var(--bg);
    padding: 10px 16px;
  }
  #view-settings:not(.settings-detail-active) .settings-view-body { display: none; }
}

/* Desktop: vertikal kolumn till vänster, profilbanner ovanför båda kolumnerna */
@media (min-width: 541px) {
  #view-settings .profile-header {
    position: fixed;
    top: 48px;
    left: calc(76px + 24px);
    right: 0;
    flex-direction: row;
    justify-content: flex-start;
    gap: 16px;
    padding: 14px 24px;
    text-align: left;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    z-index: 11;
  }
  #view-settings .profile-fields { margin-top: 0; }
  #view-settings .settings-tabs {
    position: fixed;
    top: 142px;
    left: calc(76px + 24px);
    width: 148px;
    flex-direction: column;
    align-items: stretch;
    border-bottom: none;
    border-right: 1px solid var(--border);
    padding: 8px 0;
    max-height: calc(100vh - 142px);
    overflow-y: auto;
    background: var(--bg);
    z-index: 10;
  }
  #view-settings .settings-tab {
    text-align: left;
    border-bottom: none;
    border-right: 2px solid transparent;
    margin-bottom: 0;
    margin-right: -1px;
    padding: 10px 16px;
    white-space: normal;
  }
  #view-settings .settings-tab.active {
    border-bottom-color: transparent;
    border-right-color: var(--accent);
  }
  #view-settings .settings-tab-chevron { display: none; }
  .settings-view-body {
    margin-left: 164px;
    padding: 142px 0 16px;
  }
}
