/* Strava Calendar — client-side static site styles.
   Palette: validated categorical slots; dark values are re-stepped, not flipped. */

:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid-line: #e1e0d9;
  --baseline: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --danger: #d03b3b;
  --delta-up: #006300;

  --sport-run: #2a78d6;      /* slot 1 blue */
  --sport-ride: #008300;     /* slot 2 green */
  --sport-paddle: #e87ba4;   /* slot 3 magenta */
  --sport-walk: #eda100;     /* slot 4 yellow */
  --sport-swim: #1baf7a;     /* slot 5 aqua */
  --sport-strength: #eb6834; /* slot 6 orange */
  --sport-winter: #4a3aa7;   /* slot 7 violet */
  --sport-other: #898781;    /* muted */
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid-line: #2c2c2a;
    --baseline: #383835;
    --ring: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --danger: #e66767;
    --delta-up: #0ca30c;

    --sport-run: #3987e5;
    --sport-ride: #008300;
    --sport-paddle: #d55181;
    --sport-walk: #c98500;
    --sport-swim: #199e70;
    --sport-strength: #d95926;
    --sport-winter: #9085e9;
    --sport-other: #898781;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid-line: #2c2c2a;
  --baseline: #383835;
  --ring: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --danger: #e66767;
  --delta-up: #0ca30c;

  --sport-run: #3987e5;
  --sport-ride: #008300;
  --sport-paddle: #d55181;
  --sport-walk: #c98500;
  --sport-swim: #199e70;
  --sport-strength: #d95926;
  --sport-winter: #9085e9;
  --sport-other: #898781;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.45;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 20px 32px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

main { flex: 1; }

a { color: var(--accent); }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 14px;
}

.topbar-left { display: flex; align-items: center; gap: 10px; }
.app-title { font-size: 18px; font-weight: 700; margin: 0; }

.source-badge {
  font-size: 12px;
  color: var(--text-secondary);
  border: 1px solid var(--grid-line);
  border-radius: 999px;
  padding: 2px 10px;
  background: var(--surface-1);
}

.month-nav { display: flex; align-items: center; gap: 6px; margin: 0 auto; }
.month-title { font-size: 17px; font-weight: 650; margin: 0 0 0 10px; min-width: 12ch; }

.topbar-right { display: flex; align-items: center; gap: 6px; margin-left: auto; }

.btn {
  font: inherit;
  font-size: 13.5px;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--grid-line);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}
.btn:hover { border-color: var(--baseline); }
.btn-icon { padding: 6px 10px; font-size: 15px; line-height: 1; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }

/* ---------- empty state ---------- */

.empty-state {
  text-align: center;
  padding: 48px 16px 24px;
  max-width: 720px;
  margin: 0 auto;
}
.empty-state h2 { font-size: 26px; margin: 0 0 6px; }
.empty-state > p { color: var(--text-secondary); margin: 0 0 28px; }

.empty-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; text-align: left; }
@media (max-width: 640px) { .empty-cards { grid-template-columns: 1fr; } }

.empty-card {
  background: var(--surface-1);
  border: 1px solid var(--grid-line);
  border-radius: 12px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.empty-card h3 { margin: 0; font-size: 16px; }
.empty-card p { margin: 0; color: var(--text-secondary); font-size: 14px; flex: 1; }
.empty-card .btn { align-self: flex-start; }

.empty-footnote { color: var(--text-muted); font-size: 13.5px; margin-top: 24px; }

/* ---------- legend ---------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 2px 2px 10px;
  color: var(--text-secondary);
  font-size: 13px;
}
.legend:empty { display: none; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}
.dot-run { background: var(--sport-run); }
.dot-ride { background: var(--sport-ride); }
.dot-paddle { background: var(--sport-paddle); }
.dot-walk { background: var(--sport-walk); }
.dot-swim { background: var(--sport-swim); }
.dot-strength { background: var(--sport-strength); }
.dot-winter { background: var(--sport-winter); }
.dot-other { background: var(--sport-other); }

/* ---------- calendar ---------- */

.calendar {
  background: var(--surface-1);
  border: 1px solid var(--grid-line);
  border-radius: 12px;
  overflow: hidden;
}

@keyframes slide-from-right {
  from { opacity: 0.35; transform: translateX(28px); }
  to { opacity: 1; transform: none; }
}
@keyframes slide-from-left {
  from { opacity: 0.35; transform: translateX(-28px); }
  to { opacity: 1; transform: none; }
}
.calendar.slide-from-right { animation: slide-from-right 0.18s ease-out; }
.calendar.slide-from-left { animation: slide-from-left 0.18s ease-out; }
@media (prefers-reduced-motion: reduce) {
  .calendar.slide-from-right, .calendar.slide-from-left { animation: none; }
}

.cal-head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--grid-line);
}
.cal-head-cell {
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }

.cal-cell {
  min-height: 108px;
  padding: 6px;
  border-top: 1px solid var(--grid-line);
  border-left: 1px solid var(--grid-line);
  display: flex;
  flex-direction: column;
  gap: 2px; /* surface gap between adjacent chips */
}
.cal-grid .cal-cell:nth-child(-n + 7) { border-top: none; }
.cal-grid .cal-cell:nth-child(7n + 1) { border-left: none; }
.cal-cell-blank { background: var(--page); }

.cal-daynum {
  align-self: flex-end;
  font-size: 12.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  padding: 1px 5px;
  border-radius: 999px;
}
.cal-cell-today .cal-daynum {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

/* ---------- activity chips ---------- */

.chip {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: 0;
  padding: 3px 6px 3px 4px;
  border: none;
  border-radius: 7px;
  border-left: 4px solid var(--baseline);
  background: color-mix(in srgb, var(--surface-1) 96%, var(--text-primary));
  text-decoration: none;
  text-align: left;
  font: inherit;
  color: var(--text-primary);
  font-size: 12px;
  line-height: 1.3;
  cursor: pointer;
  width: 100%;
}
.chip:hover { background: color-mix(in srgb, var(--surface-1) 90%, var(--text-primary)); }

.chip-run { border-left-color: var(--sport-run); }
.chip-ride { border-left-color: var(--sport-ride); }
.chip-paddle { border-left-color: var(--sport-paddle); }
.chip-walk { border-left-color: var(--sport-walk); }
.chip-swim { border-left-color: var(--sport-swim); }
.chip-strength { border-left-color: var(--sport-strength); }
.chip-winter { border-left-color: var(--sport-winter); }
.chip-other { border-left-color: var(--sport-other); }

.chip-icon { flex: none; font-size: 12px; }
.chip-body { min-width: 0; display: flex; flex-direction: column; }
.chip-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-meta { color: var(--text-secondary); font-size: 11.5px; font-variant-numeric: tabular-nums; }

@media (max-width: 720px) {
  .cal-cell { min-height: 72px; padding: 4px; }
  .chip-name { display: none; }
  .chip { padding: 2px 4px; }
}

/* ---------- summary tiles ---------- */

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.summary:empty { display: none; }

.tile {
  background: var(--surface-1);
  border: 1px solid var(--grid-line);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tile-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tile-value { font-size: 22px; font-weight: 700; }
.tile-sub { font-size: 12.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ---------- statistics ---------- */

.stats-block { margin-top: 20px; display: flex; flex-direction: column; gap: 12px; }

.stats-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stats-title { margin: 0; font-size: 15px; font-weight: 650; }
.stats-filter {
  font: inherit;
  font-size: 13.5px;
  padding: 5px 8px;
  border: 1px solid var(--grid-line);
  border-radius: 8px;
  background: var(--surface-1);
  color: var(--text-primary);
}
.stats-empty { color: var(--text-muted); margin: 0; font-size: 14px; }

.stats-tiles { margin-top: 0; }
.tile-deltas { display: flex; flex-wrap: wrap; gap: 2px 12px; }
.delta { font-weight: 650; font-variant-numeric: tabular-nums; }
.delta-up { color: var(--delta-up); }
.delta-down { color: var(--text-secondary); }
.delta-na { color: var(--text-muted); }

.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 10px;
}
.chart-card {
  margin: 0;
  background: var(--surface-1);
  border: 1px solid var(--grid-line);
  border-radius: 12px;
  padding: 14px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.chart-caption {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.chart { width: 100%; height: auto; display: block; }
.chart-grid { stroke: var(--grid-line); stroke-width: 1; }
.chart-baseline { stroke: var(--baseline); stroke-width: 1; }
.chart-tick { fill: var(--text-muted); font-size: 10.5px; }
.chart-label { font-size: 11px; font-weight: 600; fill: var(--text-secondary); }
.chart-label-accent { fill: var(--text-primary); }
.chart-hit { fill: transparent; }
.chart-hit:hover { fill: color-mix(in srgb, var(--text-primary) 6%, transparent); }

.chart-line { stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-line.series-now { stroke: var(--accent); }
.chart-line.series-prev { stroke: var(--text-muted); stroke-width: 1.5; }
.chart-line.series-year { stroke: var(--text-muted); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart-label.series-now { fill: var(--accent); }

.legend-line { display: inline-block; width: 18px; height: 0; border-top: 2px solid var(--text-muted); }
.legend-line.series-now { border-color: var(--accent); }
.legend-line.series-year { border-top-style: dashed; }
.legend-note { font-style: italic; }
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  color: var(--text-secondary);
  font-size: 12.5px;
}

.chart-bar { fill: color-mix(in srgb, var(--accent) 45%, var(--surface-1)); }
.chart-bar-current { fill: var(--accent); }
.chart-bar:hover { fill: color-mix(in srgb, var(--accent) 75%, var(--surface-1)); }

/* ---------- tooltip ---------- */

.tooltip {
  position: fixed;
  z-index: 50;
  max-width: 280px;
  background: var(--surface-1);
  border: 1px solid var(--grid-line);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tooltip strong { font-size: 13px; }
.tt-type { color: var(--text-secondary); display: inline-flex; align-items: center; gap: 6px; }
.tt-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  margin-top: 2px;
}
.tt-k { color: var(--text-muted); }
.tt-v { font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- notice / errors ---------- */

.notice {
  margin: 12px auto;
  max-width: 720px;
  background: var(--surface-1);
  border: 1px solid var(--danger);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
}

/* ---------- modals ---------- */

.modal {
  border: 1px solid var(--grid-line);
  border-radius: 14px;
  background: var(--surface-1);
  color: var(--text-primary);
  padding: 0;
  max-width: 520px;
  width: calc(100vw - 40px);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.45); }
.modal-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; }
.modal-body h2 { margin: 0; font-size: 18px; }
.modal-body p { margin: 0; color: var(--text-secondary); font-size: 14px; }
.setup-steps { margin: 0; padding-left: 20px; color: var(--text-secondary); font-size: 14px; }
.setup-steps li { margin-bottom: 4px; }

.modal-body label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}
.modal-body input, .modal-body select {
  font: inherit;
  font-size: 14px;
  padding: 7px 10px;
  border: 1px solid var(--baseline);
  border-radius: 8px;
  background: var(--page);
  color: var(--text-primary);
}
.modal-hint { font-size: 12.5px !important; color: var(--text-muted) !important; }

.choice {
  font: inherit;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 14px;
  border: 1px solid var(--grid-line);
  border-radius: 10px;
  background: var(--page);
  color: var(--text-primary);
  cursor: pointer;
}
.choice:hover { border-color: var(--accent); }
.choice strong { font-size: 15px; }
.choice span { color: var(--text-secondary); font-size: 13px; }

.diag { display: flex; flex-direction: column; gap: 8px; }
.diag .btn { align-self: flex-start; }
.diag-output {
  font-size: 13px;
  background: var(--page);
  border: 1px solid var(--grid-line);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  word-break: break-word;
}
.diag-ok { color: var(--text-secondary); }
.diag-fail { color: var(--danger); }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.modal-actions-split { justify-content: space-between; }
.modal-actions-split > :last-child { margin-left: auto; }

/* ---------- activity detail ---------- */

.modal-wide { max-width: 640px; }

.detail-sub {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.detail-map {
  height: 300px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--grid-line);
  background: var(--page);
  color: var(--sport-strength); /* SVG-fallback route stroke */
}
.detail-map .route-svg { width: 100%; height: 100%; }

.detail-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px 16px;
}
.detail-stat { display: flex; flex-direction: column; }
.detail-stat-k {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.detail-stat-v { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }

#detail-strava-link { text-decoration: none; }

/* ---------- drag & drop overlay ---------- */

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}
.drop-overlay-inner {
  background: var(--surface-1);
  border: 2px dashed var(--accent);
  border-radius: 16px;
  padding: 32px 48px;
  font-size: 18px;
  font-weight: 600;
}

.pagefoot { text-align: center; color: var(--text-muted); font-size: 12.5px; margin-top: 24px; }
.pagefoot a { color: inherit; }

code {
  background: color-mix(in srgb, var(--surface-1) 88%, var(--text-primary));
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.92em;
}

[hidden] { display: none !important; }
