/* --- Layout (base) --- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: system-ui, sans-serif;
  line-height: 1.5;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-nav {
  flex-shrink: 0;
  background: #f8f8f8;
  border-bottom: 1px solid #ddd;
  padding: 0.5rem 2rem;
}

.app-nav-bar {
  display: none;
}

.app-nav-burger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  margin: 0;
  padding: 0;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.app-nav-burger:hover {
  background: #f0f0f0;
}

.app-nav-burger:focus-visible {
  outline: 2px solid #06c;
  outline-offset: 2px;
}

.app-nav-burger-lines {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 1.25rem;
}

.app-nav-burger-line {
  display: block;
  height: 2px;
  background: #222;
  border-radius: 1px;
  transition:
    transform 0.2s ease,
    opacity 0.2s ease;
}

.app-nav-checkbox:checked ~ .app-nav-bar .app-nav-burger-line:nth-child(1) {
  transform: translateY(0.4375rem) rotate(45deg);
}

.app-nav-checkbox:checked ~ .app-nav-bar .app-nav-burger-line:nth-child(2) {
  opacity: 0;
}

.app-nav-checkbox:checked ~ .app-nav-bar .app-nav-burger-line:nth-child(3) {
  transform: translateY(-0.4375rem) rotate(-45deg);
}

.app-nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
}

.app-nav li form {
  display: inline;
  margin: 0;
}

.app-nav a {
  color: #06c;
}

.app-nav button {
  font: inherit;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  .app-nav-burger-line {
    transition: none;
  }
}

main.page {
  flex: 1 0 auto;
  margin: 2rem;
  max-width: 100%;
  min-width: 0;
}

.app-footer {
  flex-shrink: 0;
  padding: 1.25rem 2rem 2rem;
  border-top: 1px solid #eee;
  font-size: 0.875rem;
  color: #555;
}

.app-footer-text {
  margin: 0;
  max-width: 48rem;
}

.app-footer a {
  color: #06c;
}

/* Horizontal scroll for wide tables without shrinking columns unreadably */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 0.25rem;
}

.table-scroll table {
  max-width: none;
}

main.page a:not(.btn) {
  color: #06c;
}

time {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* --- Utilities --- */
.muted {
  color: #555;
  font-size: 0.9rem;
}

.flush-top {
  margin-top: 0;
}

.help-text {
  font-size: 0.9rem;
  color: #555;
}

.subheading-sm {
  font-size: 1.1rem;
  margin: 0 0 0.5rem 0;
}

/* --- Home (index) --- */
.strava-connect a {
  display: inline-block;
  line-height: 0;
}

.strava-connect img {
  display: block;
  height: auto;
  max-width: 100%;
}

.account-details {
  margin: 1rem 0;
}

.account-details dt {
  font-weight: 600;
}

.account-details dd {
  margin: 0.25rem 0 1rem 0;
}

/* --- Bordered data tables (leaders, weeks, results) --- */
.table-bordered {
  border-collapse: collapse;
  width: 100%;
}

.table-bordered th,
.table-bordered td {
  border: 1px solid #ccc;
  padding: 0.5rem 0.75rem;
  text-align: left;
}

.table-bordered th {
  background: #f5f5f5;
}

.table-bordered tbody tr:nth-child(even) {
  background: #fafafa;
}

.table-bordered td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.leader-section .table-bordered {
  max-width: 36rem;
  margin-top: 0.75rem;
}

.period .table-bordered {
  max-width: 52rem;
  margin-bottom: 2rem;
}

.summary .table-bordered {
  margin-bottom: 2rem;
}

/* --- Row-style tables (athletes, bonuses) --- */
.table-rows {
  border-collapse: collapse;
  width: 100%;
  max-width: 64rem;
  font-size: 0.95rem;
}

.table-rows th,
.table-rows td {
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid #ddd;
}

.table-rows th {
  font-weight: 600;
  background: #f6f6f6;
}

.table-rows th.table-sort a {
  color: inherit;
  text-decoration: none;
}

.table-rows th.table-sort a:hover {
  text-decoration: underline;
}

.table-rows th.table-sort .table-sort-indicator {
  font-weight: 400;
  opacity: 0.75;
}

.table-rows tbody tr:hover {
  background: #fafafa;
}

.btn {
  font: inherit;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
}

a.btn {
  display: inline-block;
  text-decoration: none;
  color: inherit;
  background: buttonface;
  border: 1px solid buttonborder;
  border-radius: 2px;
}

.table-rows td.actions-cell,
.athlete-actions.actions-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.table-rows td.actions-cell form,
.athlete-actions.actions-cell form {
  margin: 0;
}

.athlete-actions.actions-cell {
  margin-top: 1.5rem;
  max-width: 48rem;
}

.athletes-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0 0 1rem 0;
  max-width: 64rem;
}

.athletes-filter-btn {
  display: inline-block;
  padding: 0.4rem 0.75rem;
  font: inherit;
  font-size: 0.9rem;
  text-decoration: none;
  color: #222;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  cursor: pointer;
}

.athletes-filter-btn:hover {
  background: #f5f5f5;
}

.athletes-filter-btn.is-active {
  background: #e8eef8;
  border-color: #06c;
  color: #06c;
  font-weight: 600;
}

.athletes-filter-btn:focus-visible {
  outline: 2px solid #06c;
  outline-offset: 2px;
}

.results-note,
.athletes-note,
.bonuses-note {
  color: #555;
  font-size: 0.9rem;
  margin: 0.75rem 0 0 0;
}

.results-note {
  max-width: 40rem;
}

.athletes-note {
  max-width: 40rem;
}

.bonuses-note {
  max-width: 44rem;
}

.results-table-note {
  color: #555;
  font-size: 0.9rem;
  margin: 0 0 0.75rem 0;
  max-width: 44rem;
}

/* --- Leaders --- */
.rank-line {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
}

.rank-line .medal {
  font-style: normal;
}

.leader-section {
  margin-bottom: 2.5rem;
}

.leader-section h2 {
  margin: 0 0 0.35rem 0;
  font-size: 1.25rem;
}

.leader-section > p.desc {
  margin: 0;
  color: #444;
  max-width: 44rem;
}

.leaders-empty {
  color: #555;
  margin: 0.5rem 0 0 0;
}

/* --- Weeks --- */
.period {
  margin-bottom: 2rem;
}

.period-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.period-heading h2 {
  font-size: 1.1rem;
  margin: 0;
}

.period-heading form {
  margin: 0;
}

.meta {
  color: #444;
  font-size: 0.9rem;
  margin: 0 0 0.75rem 0;
}

/* --- Results --- */
.summary {
  margin-bottom: 2rem;
}

.summary > h2 {
  font-size: 1.15rem;
  margin: 0 0 0.5rem 0;
}

/* --- Bonuses --- */
.bonus-form {
  margin-top: 2rem;
  max-width: 32rem;
  border-top: 1px solid #ddd;
  padding-top: 1.25rem;
}

.bonus-form label {
  display: block;
  margin: 0.65rem 0 0.2rem 0;
  font-weight: 600;
}

.bonus-form input,
.bonus-form select {
  font: inherit;
  width: 100%;
  max-width: 24rem;
  box-sizing: border-box;
  padding: 0.35rem 0.5rem;
}

.bonus-form button {
  font: inherit;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
  margin-top: 1rem;
}

.error-msg {
  color: #a30;
  margin: 0 0 1rem 0;
  max-width: 40rem;
}

/* --- Settings --- */
.settings-page {
  max-width: 40rem;
}

.settings-page h1 {
  font-size: 1.35rem;
  margin-top: 0;
}

.settings-page h2 {
  font-size: 1.05rem;
  margin: 1.5rem 0 0.5rem 0;
}

.settings-page p {
  margin: 0.75rem 0;
}

.settings-panel {
  margin-top: 1rem;
  padding: 1rem 1.25rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fafafa;
}

.settings-panel form {
  margin: 0.75rem 0 0 0;
}

.settings-panel button.primary {
  font: inherit;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  color: #fff;
  border: 1px solid #06c;
  background: #06c;
  border-radius: 4px;
}

.mcp-key-reveal {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid #c9a227;
  border-radius: 4px;
  background: #fffbeb;
}

.mcp-key-reveal p {
  margin: 0 0 0.65rem 0;
  font-size: 0.95rem;
}

.mcp-key-value {
  margin: 0;
  padding: 0.5rem 0.65rem;
  font-size: 0.9rem;
  word-break: break-all;
  background: #fff;
  border: 1px solid #e6d89c;
  border-radius: 4px;
}

.gdpr-danger-zone {
  margin-top: 1.75rem;
  padding: 1rem 1.25rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fafafa;
}

.gdpr-danger-zone h2 {
  font-size: 1.05rem;
  margin: 0 0 0.5rem 0;
}

.gdpr-danger-zone form {
  margin: 0.75rem 0 0 0;
}

.gdpr-danger-zone button.danger {
  font: inherit;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  color: #b00020;
  border: 1px solid #b00020;
  background: #fff;
}

.gdpr-danger-hint {
  margin: 0;
  font-size: 0.9rem;
  color: #555;
}

/* --- Hub / department onboarding --- */
.hub-dept-form label {
  display: block;
  font-weight: 600;
  margin-top: 1rem;
}

.hub-dept-form select {
  font: inherit;
  min-width: 16rem;
  padding: 0.35rem 0.5rem;
}

.hub-dept-form button {
  font: inherit;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  margin-top: 1.25rem;
}

.gdpr-stuff {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid #eee;
  max-width: 40rem;
}

.gdpr-stuff h2 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 0.65rem 0;
  color: #333;
}

.gdpr-stuff p {
  margin: 0.5rem 0;
  font-size: 0.95rem;
  line-height: 1.5;
  color: #444;
}

/* --- Error pages --- */
.error-page h1 {
  font-size: 1.5rem;
  margin: 0 0 0.5rem 0;
}

.error-page p.sub {
  color: #555;
  margin: 0 0 1rem 0;
  font-size: 1.05rem;
}

.error-page p.hint {
  color: #666;
  font-size: 0.95rem;
}

/* --- Activities (home + organiser view) --- */
.activities-section {
  margin-top: 2rem;
}

.activities-section h2 {
  font-size: 1.15rem;
  margin-bottom: 0.5rem;
}

.team-points {
  font-size: 1.05rem;
  margin-bottom: 1rem;
}

table.activities {
  border-collapse: collapse;
  width: 100%;
  max-width: 48rem;
  font-size: 0.95rem;
}

table.activities th,
table.activities td {
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid #ddd;
}

table.activities th {
  font-weight: 600;
  background: #f6f6f6;
}

table.activities tbody tr:hover {
  background: #fafafa;
}

.activities-intro {
  margin: 0 0 1rem 0;
  max-width: 48rem;
}

.athlete-activities-back {
  margin-bottom: 1rem;
}

/* --- Small screens (phones, narrow tablets) --- */
@media (max-width: 45rem) {
  main.page {
    margin: 1rem 0.75rem;
  }

  .app-footer {
    padding: 1rem 0.75rem 1.5rem;
  }

  h1 {
    font-size: 1.35rem;
    line-height: 1.25;
  }

  .app-nav {
    padding: 0;
  }

  .app-nav-bar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 0.4rem 0.65rem;
  }

  .app-nav-list {
    display: none;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 0;
    width: 100%;
    padding: 0.25rem 0 0.35rem;
    border-top: 1px solid #e5e5e5;
  }

  .app-nav-checkbox:checked ~ ul.app-nav-list {
    display: flex;
  }

  .app-nav li {
    width: 100%;
    border-bottom: 1px solid #eee;
  }

  .app-nav li:last-child {
    border-bottom: none;
  }

  .app-nav a {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    line-height: 1.35;
    text-decoration: none;
  }

  .app-nav a:hover {
    background: #f0f0f0;
  }

  .app-nav li form {
    display: block;
    width: 100%;
    margin: 0;
    padding: 0.5rem 1rem 0.65rem;
  }

  .app-nav li form button {
    width: 100%;
    min-height: 2.75rem;
    padding: 0.5rem 0.75rem;
  }

  /* Let wide tables extend past the viewport; scroll inside .table-scroll */
  .table-scroll .table-rows {
    min-width: 42rem;
  }

  .table-scroll table.activities {
    min-width: 34rem;
  }

  .table-bordered th,
  .table-bordered td {
    padding: 0.45rem 0.5rem;
    font-size: 0.9rem;
  }

  .table-bordered td:not(.num) {
    overflow-wrap: anywhere;
  }

  .table-rows th,
  .table-rows td {
    padding: 0.45rem 0.5rem;
    font-size: 0.875rem;
  }

  .table-rows td:not(.actions-cell) {
    overflow-wrap: anywhere;
  }

  table.activities th,
  table.activities td {
    padding: 0.45rem 0.5rem;
    font-size: 0.875rem;
  }

  .leader-section > p.desc,
  .results-table-note,
  .meta {
    font-size: 0.875rem;
  }

  .hub-dept-form select {
    min-width: 0;
    width: 100%;
    max-width: 100%;
  }

  .bonus-form input,
  .bonus-form select {
    max-width: 100%;
  }

  .settings-panel,
  .gdpr-danger-zone,
  .mcp-key-reveal {
    padding: 0.85rem 1rem;
  }

  .settings-panel button.primary,
  .gdpr-danger-zone button.danger,
  .bonus-form button {
    min-height: 2.75rem;
    padding: 0.5rem 0.85rem;
  }

  .table-rows .btn {
    min-height: 2.5rem;
  }
}

@media (max-width: 28rem) {
  .table-rows td.actions-cell {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .table-rows .btn {
    width: 100%;
  }
}
