/* ── Base ──────────────────────────────────────────────────── */

:root {
  --strava-orange: #FC4C02;
}

* { box-sizing: border-box; }

body {
  background-color: #f0f0f0;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: #111;
}

a { color: inherit; }

/* ── Navbar ────────────────────────────────────────────────── */

.navbar {
  background: var(--strava-orange);
  color: #fff;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 52px;
}

.navbar-brand {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.02em;
  text-decoration: none;
  color: #fff;
  white-space: nowrap;
}

.navbar-left {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  margin-left: auto;
}

.nav-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.nav-dropdown { position: relative; }

#nav-user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}

.nav-page-name {
  display: none;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.75);
  padding: 0 8px;
  white-space: nowrap;
}

.nav-dropdown-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.9);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-dropdown-btn:hover { background: rgba(255,255,255,0.15); }

.nav-dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  min-width: 160px;
  z-index: 100;
  overflow: hidden;
}

.nav-dropdown-menu a,
.nav-dropdown-menu button {
  display: block;
  width: 100%;
  padding: 10px 14px;
  text-decoration: none;
  color: #333;
  font-size: 13px;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
}

.nav-dropdown-menu a:hover,
.nav-dropdown-menu button:hover { background: #f5f5f5; }

.nav-dropdown-menu hr { margin: 4px 0; border: none; border-top: 1px solid #eee; }

.nav-dropdown-menu .danger { color: #d94f3d; }

/* Navbar week selector controls */
.navbar-left .dash-nav-btn,
.navbar-left .dash-week-select {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.25);
  color: rgba(255,255,255,0.85);
}
.navbar-left .dash-nav-btn:hover { background: rgba(255,255,255,0.2); color: #fff; }
.navbar-left .dash-week-select option { background: #333; color: #fff; }

/* ── Landing page ──────────────────────────────────────────── */

.landing {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 52px);
}

.landing-card {
  background: #fff;
  border-radius: 12px;
  padding: 48px 40px;
  text-align: center;
  max-width: 380px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

.landing-title { font-size: 22px; font-weight: 600; margin-bottom: 8px; }
.landing-sub   { color: #888; font-size: 14px; margin-bottom: 28px; }

.btn-strava {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--strava-orange);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn-strava:hover { background: #e04500; }

/* ── Page wrapper ──────────────────────────────────────────── */

.page {
  padding: 20px 16px;
  max-width: 1000px;
  margin: 0 auto;
}

/* ── Dashboard card system ─────────────────────────────────── */

.dash {
  --dash-bg:     #fff;
  --dash-bg-2:   #f5f5f5;
  --dash-border: rgba(0,0,0,0.08);
  --dash-text:   #111;
  --dash-muted:  #888;
  --dash-mono:   'SF Mono', ui-monospace, 'Cascadia Code', 'Courier New', monospace;
  --dash-pos:    #2a9d5c;
  --dash-neg:    #d94f3d;

  background: var(--dash-bg);
  border: 0.5px solid var(--dash-border);
  border-radius: 12px;
  overflow: hidden;
  max-width: 960px;
  margin: 0 auto;
}

.dash-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 22px;
  border-bottom: 0.5px solid var(--dash-border);
  flex-wrap: wrap;
  gap: 8px;
}
.dash-header-left  { display: flex; align-items: baseline; gap: 14px; }
.dash-header-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dash-wordmark { font-size: 12px; font-weight: 500; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dash-muted); }
.dash-week     { font-family: var(--dash-mono); font-size: 11px; color: var(--dash-muted); }

.dash-nav { display: flex; gap: 4px; }
.dash-nav-btn, .dash-export-btn, .dash-week-select {
  font-family: var(--dash-mono);
  font-size: 11px;
  padding: 3px 10px;
  border: 0.5px solid var(--dash-border);
  border-radius: 4px;
  background: var(--dash-bg);
  color: var(--dash-muted);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.dash-nav-btn:hover, .dash-export-btn:hover { background: var(--dash-bg-2); color: var(--dash-text); }
.dash-nav-btn.disabled { opacity: 0.3; pointer-events: none; }

.dash-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 22px; }

.section-head {
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--dash-muted);
  padding-bottom: 10px;
  border-bottom: 0.5px solid var(--dash-border);
  margin-bottom: 12px;
}

/* ── Stat grid ─────────────────────────────────────────────── */

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

.stat { background: var(--dash-bg-2); border-radius: 8px; padding: 13px 14px; }
.stat-lbl  { font-size: 10px; color: var(--dash-muted); margin-bottom: 5px; letter-spacing: 0.02em; }
.stat-val  { font-size: 22px; font-weight: 500; color: var(--dash-text); line-height: 1; font-variant-numeric: tabular-nums; }
.stat-unit { font-size: 12px; font-weight: 400; color: var(--dash-muted); margin-left: 2px; }
.stat-sub  { font-size: 11px; color: var(--dash-muted); margin-top: 5px; font-family: var(--dash-mono); }
.stat-val.pos  { color: var(--dash-pos); }
.stat-val.neg  { color: var(--dash-neg); }

/* ── Body section ──────────────────────────────────────────── */

.body-row { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.body-row > * { min-width: 0; }

.weight-stat { background: var(--dash-bg-2); border-radius: 8px; padding: 13px 14px; }
.weight-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.weight-val   { font-size: 22px; font-weight: 500; color: var(--dash-text); font-variant-numeric: tabular-nums; }
.weight-val.pos { color: var(--dash-pos); }
.weight-val.neg { color: var(--dash-neg); }
.weight-trend { font-size: 11px; font-family: var(--dash-mono); color: var(--dash-muted); }
.weight-trend.pos { color: var(--dash-pos); }
.weight-trend.neg { color: var(--dash-neg); }

.weight-track { height: 3px; background: var(--dash-border); border-radius: 2px; position: relative; margin-bottom: 5px; }
.weight-fill  { height: 100%; border-radius: 2px; background: var(--dash-muted); }
.weight-thumb { position: absolute; top: 50%; transform: translate(-50%,-50%); width: 10px; height: 10px; border-radius: 50%; background: var(--dash-text); border: 2px solid var(--dash-bg-2); }
.weight-scale { display: flex; justify-content: space-between; font-size: 10px; color: var(--dash-muted); font-family: var(--dash-mono); }

.graph-stat { grid-column: span 2; background: var(--dash-bg-2); border-radius: 8px; padding: 13px 14px 10px; overflow: hidden; min-width: 0; }
.graph-stat canvas { display: block; max-width: 100%; }
.graph-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.graph-lbl { font-size: 10px; color: var(--dash-muted); letter-spacing: 0.02em; }

/* ── Weekly todo widget ────────────────────────────────────── */

.todo-card { background: var(--dash-bg-2); border-radius: 8px; padding: 13px 14px; }
.todo-card.all-done { background: #f0faf2; border: 0.5px solid #a5d6a7; }
.todo-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.todo-title { font-size: 10px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dash-muted); }
.todo-all-done { font-size: 12px; font-weight: 500; color: #2e7d32; }
.todo-items { display: flex; flex-wrap: wrap; gap: 6px; }
.todo-item { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-family: var(--dash-mono); color: var(--dash-text); background: var(--dash-bg); border: 0.5px solid var(--dash-border); border-radius: 4px; padding: 3px 8px; }
.todo-item-val { font-weight: 600; color: var(--dash-neg); }

/* ── Activity table ────────────────────────────────────────── */

.act-table { width: 100%; border-collapse: collapse; }
.act-table thead tr { border-bottom: 0.5px solid var(--dash-border); }
.act-table th { font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dash-muted); padding: 0 6px 8px 0; font-weight: 500; text-align: left; }
.act-table th:not(:first-child) { text-align: right; }
.act-table td { padding: 9px 6px 9px 0; border-bottom: 0.5px solid var(--dash-border); color: var(--dash-muted); vertical-align: middle; }
.act-table tr:last-child td { border-bottom: none; }
.act-table td:not(:first-child) { text-align: right; font-family: var(--dash-mono); font-size: 11px; }
.act-name { font-weight: 500; color: var(--dash-text); font-size: 12px; }
.act-date { font-size: 11px; color: var(--dash-muted); margin-top: 1px; font-family: var(--dash-mono); }
.act-pill { display: inline-block; font-size: 9px; padding: 2px 7px; border-radius: 3px; letter-spacing: 0.06em; text-transform: uppercase; border: 0.5px solid var(--dash-border); color: var(--dash-muted); background: var(--dash-bg); }
.act-pill.indoor   { background: #eaf1fb; color: #2a5aa8; border-color: #b8cfef; }
.act-pill.outdoor  { background: #e8f5e9; color: #2e7d32; border-color: #a5d6a7; }
.act-pill.climbing { background: #efebe9; color: #6d4c41; border-color: #bcaaa4; }

/* ── Footer ────────────────────────────────────────────────── */

.dash-footer {
  padding: 10px 22px;
  border-top: 0.5px solid var(--dash-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  color: var(--dash-muted);
  font-family: var(--dash-mono);
}
.src-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.src-dot.strava { background: #fc4c02; }

/* ── Loading / error states ────────────────────────────────── */

.loading-msg, .error-msg {
  text-align: center;
  padding: 40px;
  color: var(--dash-muted);
  font-family: var(--dash-mono);
  font-size: 12px;
}
.error-msg { color: var(--dash-neg); }


/* ── Connection status pills ───────────────────────────────── */

.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--dash-mono);
  font-size: 10px;
  color: var(--dash-muted);
  text-decoration: none;
  padding: 2px 6px;
  border-radius: 3px;
  border: 0.5px solid transparent;
  transition: border-color 0.15s;
}
.conn-pill:hover { border-color: var(--dash-border); }
.conn-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}
.conn-dot.ok  { background: var(--dash-pos); }
.conn-dot.off { background: var(--dash-neg); }
.conn-pill-alert { color: var(--dash-neg); }

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 640px) {
  .stat-grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .stat-grid-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .stat-grid-2 { grid-template-columns: 1fr; }
  .body-row { grid-template-columns: 1fr; }
  .graph-stat { grid-column: span 1; }
  .dash-body { padding: 16px; }
  .dash-header, .dash-footer { padding: 12px 16px; }
  .navbar-brand { display: none; }
  .nav-avatar { display: none; }
  .navbar-left { position: static; transform: none; flex: 1; }
  .dash-week-select { flex: 1; max-width: 200px; }

  /* Activities table: name full-width on top, data row below */
  .act-table thead { display: none; }
  .act-table tbody tr { display: flex; flex-wrap: wrap; padding: 10px 0; border-bottom: 0.5px solid var(--dash-border); }
  .act-table tbody tr:last-child { border-bottom: none; }
  .act-table td { border-bottom: none; padding: 2px 10px 2px 0; }
  .act-table td:first-child { width: 100%; padding: 0 0 6px 0; }
  .act-table td:not(:first-child) { text-align: left; }
}

/* ── Print ─────────────────────────────────────────────────── */

@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  .navbar, .dash-header-right, .dash-footer { display: none !important; }

  body { background: #fff; }
  .page { padding: 0; max-width: 100%; }
  .dash { border: none; border-radius: 0; max-width: 100%; box-shadow: none; }

  .dash-header { padding: 4px 10px; }
  .dash-body { padding: 6px 10px; gap: 6px; }

  .section-head { padding-bottom: 3px; margin-bottom: 4px; }

  .stat { padding: 4px 7px; border-radius: 5px; }
  .stat-lbl { margin-bottom: 2px; }
  .stat-val { font-size: 14px; }
  .stat-sub { margin-top: 2px; font-size: 10px; }
  .stat-grid { gap: 4px; }

  .weight-stat { padding: 4px 7px; border-radius: 5px; }
  .weight-header { margin-bottom: 4px; }
  .weight-val { font-size: 14px; }
  .weight-trend { font-size: 10px; }
  .body-row { gap: 4px; }

  .graph-stat { padding: 4px 7px; border-radius: 5px; }
  .graph-header { margin-bottom: 4px; }

  .act-table td { padding: 3px 6px 3px 0; font-size: 10px; }
  .act-table th { padding: 0 6px 3px 0; }
  .act-name { font-size: 11px; }
  .act-date { font-size: 10px; margin-top: 0; }
  .act-pill { font-size: 8px; padding: 1px 5px; }
}

/* ── Settings modal ────────────────────────────────────────── */

.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.settings-overlay[hidden] { display: none; }

.settings-modal {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px 12px;
  border-bottom: 0.5px solid #eee;
}

.settings-title {
  font-size: 14px;
  font-weight: 600;
  color: #111;
}

.settings-close {
  background: none;
  border: none;
  font-size: 20px;
  color: #999;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}
.settings-close:hover { color: #333; }

.settings-section-head {
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #999;
  padding: 14px 20px 6px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 20px;
  gap: 16px;
}

.settings-label {
  font-size: 13px;
  color: #333;
  flex: 1;
}

.settings-input {
  width: 100px;
  padding: 5px 8px;
  font-size: 13px;
  border: 0.5px solid #ddd;
  border-radius: 5px;
  background: #f9f9f9;
  color: #111;
  text-align: right;
  font-family: 'SF Mono', ui-monospace, monospace;
}
.settings-input:focus {
  outline: none;
  border-color: #aaa;
  background: #fff;
}

.settings-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 16px;
  border-top: 0.5px solid #eee;
  margin-top: 8px;
  gap: 12px;
}

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

.settings-btn-cancel {
  padding: 7px 14px;
  font-size: 13px;
  border: 0.5px solid #ddd;
  border-radius: 6px;
  background: #fff;
  color: #555;
  cursor: pointer;
}
.settings-btn-cancel:hover { background: #f5f5f5; }

.settings-btn-save {
  padding: 7px 16px;
  font-size: 13px;
  border: none;
  border-radius: 6px;
  background: var(--strava-orange);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.settings-btn-save:hover { background: #e04500; }
.settings-btn-save:disabled { opacity: 0.5; cursor: default; }

.settings-msg {
  font-size: 12px;
  font-family: 'SF Mono', ui-monospace, monospace;
  color: transparent;
}
.settings-msg-ok    { color: #2a9d5c; }
.settings-msg-error { color: #d94f3d; }
