:root {
  color-scheme: light;
  --bg: #f7f5ef;
  --ink: #202426;
  --muted: #697177;
  --line: #d8d4c8;
  --accent: #244c5a;
  --accent-2: #9a5b2f;
  --panel: #ffffff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.brand {
  font-weight: 700;
  text-decoration: none;
}

nav {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.nav-form {
  margin: 0;
}

main {
  width: min(1180px, calc(100vw - 32px));
  margin: 28px auto;
}

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

h1,
h2 {
  margin: 0 0 14px;
}

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

.panel-stack {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

.panel,
.stats > div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.stats > div {
  min-width: 0;
}

.narrow {
  max-width: 620px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.stats strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(1.25rem, 3vw, 1.5rem);
  line-height: 1.1;
  white-space: nowrap;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-scroll table {
  min-width: max-content;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 600;
}

label {
  display: block;
  margin-bottom: 4px;
  font-weight: 600;
}

input,
select,
textarea {
  min-width: 0;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}

input:disabled,
select:disabled,
textarea:disabled {
  background: #eeeeea;
  color: var(--muted);
}

button:disabled {
  background: var(--muted);
  cursor: not-allowed;
  opacity: 0.65;
}

textarea {
  min-height: 90px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
}

.checkbox-label input {
  width: auto;
}

button,
.button {
  display: inline-block;
  width: auto;
  padding: 9px 14px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.secondary-button {
  background: var(--muted);
}

.split-options {
  display: grid;
  gap: 20px;
}

.split-option {
  display: grid;
  gap: 14px;
}

.split-option-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  cursor: pointer;
}

.split-option-heading input {
  width: auto;
}

.split-map {
  width: 100%;
  height: 400px;
  border: 1px solid var(--line);
}

.split-option p {
  margin: 0;
}

.split-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

.secret-field {
  display: flex;
  align-items: stretch;
}

.secret-field input {
  border-radius: 6px 0 0 6px;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 42px;
  padding: 0;
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 0 6px 6px 0;
  background: #ffffff;
  color: var(--accent);
}

.eye-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.eye-open {
  display: none;
}

.icon-button[aria-pressed="true"] .eye-closed {
  display: none;
}

.icon-button[aria-pressed="true"] .eye-open {
  display: block;
}

.rate-summary {
  margin-bottom: 16px;
  color: var(--muted);
}

.rate-summary p {
  margin: 0 0 6px;
}

.log-cost-panel {
  margin-bottom: 20px;
}

.log-page-header {
  flex-wrap: wrap;
}

.negative-amount {
  color: #8c2f1b;
}

.log-entry-actions {
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.log-table tbody td {
  vertical-align: middle;
}

.none-ride-row td {
  background: #fff4d6;
}

.log-table-fixed-column {
  width: 1%;
  white-space: nowrap;
}

.log-table-description-column {
  width: 100%;
}

.ride-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0 8px;
}

.ride-distance {
  white-space: nowrap;
}

.ride-note {
  margin-top: 2px;
}

.grouped-ride-cell {
  position: relative;
  padding-left: 30px;
}

.ride-group-rail {
  position: absolute;
  z-index: 1;
  top: -1px;
  bottom: -1px;
  left: 14px;
  width: 6px;
  border-left: 2px solid var(--accent-2);
}

.ride-group-rail-top {
  top: 10px;
  border-top: 2px solid var(--accent-2);
}

.ride-group-rail-bottom {
  bottom: 10px;
  border-bottom: 2px solid var(--accent-2);
}

.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;
}

.ride-details-header {
  display: grid;
  grid-template-areas: "earlier heading later actions";
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: flex-start;
}

.ride-details-navigation {
  display: contents;
}

.earlier-ride-button {
  grid-area: earlier;
}

.later-ride-button {
  grid-area: later;
}

.ride-navigation-button {
  min-width: 100px;
  text-align: center;
  white-space: nowrap;
}

.ride-details-heading {
  grid-area: heading;
  min-width: 0;
}

.ride-details-heading h1 {
  margin: 4px 0 0;
}

.ride-details-date {
  font-size: 0.7em;
  font-weight: 600;
  white-space: nowrap;
}

.ride-details-edit-header {
  grid-template-areas: "heading actions";
  grid-template-columns: minmax(0, 1fr) auto;
}

.ride-details-actions {
  grid-area: actions;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ride-segment p {
  margin: 4px 0 0;
}

.ride-activity-summary {
  margin-bottom: 20px;
}

.stats.ride-activity-stats {
  width: 100%;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-bottom: 0;
  margin-left: 0;
  transform: none;
}

.stats.ride-activity-stats span,
.stats.ride-segment-stats span {
  font-size: 0.9rem;
}

.stats.ride-activity-stats strong,
.stats.ride-segment-stats strong {
  font-size: 1.5rem;
}

.ride-segments {
  display: grid;
  gap: 20px;
}

.ride-segment {
  display: grid;
  gap: 16px;
}

.ride-segment-content {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(240px, 1fr);
  align-items: stretch;
  gap: 20px;
}

.ride-segment-map,
.ride-segment-information {
  min-width: 0;
}

.stats.ride-segment-stats {
  width: 100%;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-bottom: 0;
  margin-left: 0;
  transform: none;
}

.stats.ride-segment-stats strong {
  white-space: normal;
  overflow-wrap: anywhere;
}

.stats.ride-segment-stats label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 400;
  white-space: nowrap;
}

.stats.ride-segment-stats select,
.stats.ride-segment-stats textarea {
  min-width: 0;
  margin-top: 8px;
}

.stats.ride-segment-stats textarea {
  resize: vertical;
}

.ride-segment-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.ride-map {
  width: 100%;
  height: 400px;
  border: 1px solid var(--line);
}

.map-unavailable {
  height: 100%;
  min-height: 160px;
  margin: 0;
  padding: 16px;
  background: var(--bg);
  border: 1px dashed var(--line);
  color: var(--muted);
}

.ride-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

.cost-entry-form {
  display: grid;
  gap: 14px;
}

.cost-entry-row {
  display: grid;
  gap: 14px;
}

.cost-entry-field {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.cost-entry-field label {
  margin-bottom: 0;
}

.cost-entry-fields {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cost-entry-actions {
  display: flex;
  justify-content: flex-end;
}

.link-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  text-decoration: underline;
}

.auth-panel {
  margin: 0 auto;
}

.error-text {
  color: #8c2f1b;
  font-weight: 600;
}

.messages p {
  padding: 10px 12px;
  border-radius: 6px;
  background: #e8f2ed;
  border: 1px solid #b8d8c6;
}

.messages .error {
  background: #f7e7e4;
  border-color: #d9aca4;
}

.burndown-chart {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

@media (max-width: 700px) {
  .site-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .cost-entry-fields {
    grid-template-columns: 1fr;
  }

  .cost-entry-field {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .ride-segment-content {
    grid-template-columns: 1fr;
  }

  .ride-details-header {
    grid-template-areas:
      "navigation"
      "heading"
      "actions";
    grid-template-columns: minmax(0, 1fr);
  }

  .ride-details-edit-header {
    grid-template-areas:
      "heading"
      "actions";
  }

  .ride-details-navigation {
    grid-area: navigation;
    display: flex;
    justify-content: space-between;
    gap: 16px;
  }

  .ride-details-actions {
    justify-content: flex-start;
  }

  .ride-details-date {
    display: block;
    margin-top: 4px;
  }

  .ride-map {
    height: 300px;
  }
}

@media (min-width: 1540px) {
  .stats {
    width: min(1500px, calc(100vw - 32px));
    grid-template-columns: repeat(8, minmax(0, 1fr));
    margin-left: 50%;
    transform: translateX(-50%);
  }

  .stats span {
    font-size: 0.78rem;
  }

  .stats strong {
    font-size: 1.25rem;
  }
}

@media (max-width: 900px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 460px) {
  .stats {
    grid-template-columns: 1fr;
  }
}
