:root {
  --page-bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #172033;
  --muted: #64748b;
  --border: #d9e1ea;
  --border-strong: #b8c4d2;
  --header: #24304a;
  --header-alt: #155e75;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --success-bg: #dcfce7;
  --success-text: #166534;
  --event-bg: #fff6cc;
  --event-border: #f1d66b;
  --event-col-width: 112px;
  --card-sticky-col-width: 128px;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body.score-page {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.08), rgba(245, 247, 251, 0) 260px),
    var(--page-bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
}

.score-shell {
  width: min(100%, 1320px);
  margin: 0 auto;
  padding: 28px 24px 40px;
}

.score-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.score-header > div {
  min-width: 0;
}

.score-kicker {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

#banner {
  margin: 0;
  color: var(--text);
  font-size: 28px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: 0;
}

.score-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.score-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  text-align: center;
  white-space: nowrap;
  max-width: 100%;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

.score-button:hover,
.score-button:focus {
  transform: translateY(-1px);
  text-decoration: none;
}

.score-button-primary {
  background: #0f766e;
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.22);
}

.score-button-primary:hover,
.score-button-primary:focus {
  background: #115e59;
  color: #ffffff;
}

.score-button-success {
  background: #365486;
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(54, 84, 134, 0.2);
}

.score-button-success:hover,
.score-button-success:focus {
  background: #2f4772;
  color: #ffffff;
}

.score-button-muted {
  background: #ffffff;
  color: #334155;
  border-color: var(--border);
}

.score-button-muted:hover,
.score-button-muted:focus {
  background: #f8fafc;
  color: #172033;
}

.score-button-danger {
  background: #fff1f2;
  color: #be123c;
  border-color: #fecdd3;
}

.score-button-danger:hover,
.score-button-danger:focus {
  background: #ffe4e6;
  color: #9f1239;
}

.score-button-compact {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.share-link {
  max-width: 360px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.share-link:empty {
  display: none;
}

.score-toolbar {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.score-toolbar > * {
  min-width: 0;
}

.control-field {
  display: grid;
  gap: 6px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.control-search {
  min-width: min(320px, 100%);
}

.control-field input,
.control-field select {
  height: 38px;
  min-width: 138px;
  max-width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0;
}

.control-field input {
  width: 100%;
  padding: 0 12px;
}

.control-field select {
  padding: 0 34px 0 10px;
}

.control-field input:focus,
.control-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
  outline: none;
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  margin: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 26px;
  flex: 0 0 44px;
  border: 1px solid var(--border-strong);
  background-color: #cbd5e1;
  transition: background-color 140ms ease, border-color 140ms ease;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 2px;
  bottom: 2px;
  border-radius: 50%;
  background-color: white;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.22);
  transition: transform 140ms ease;
}

.slider.round {
  border-radius: 999px;
}

input:checked + .slider {
  border-color: var(--accent);
  background-color: var(--accent);
}

input:checked + .slider:before {
  transform: translateX(18px);
}

.table-container {
  width: 100%;
  max-height: calc(100vh - 190px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

#swimmers {
  width: 100%;
  min-width: 860px;
  border-collapse: separate;
  border-spacing: 0;
  color: var(--text);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

#swimmers th,
#swimmers td {
  height: 36px;
  padding: 8px 10px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
}

#swimmers th {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--header);
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-align: left;
}

#swimmers th:nth-child(2) {
  background: var(--header-alt);
}

#swimmers th.national-header {
  text-align: center;
}

#swimmers th a {
  color: #ffffff;
  text-decoration: none;
}

#swimmers th a:hover,
#swimmers th a:focus {
  color: #e0f2fe;
  text-decoration: underline;
}

#swimmers td {
  background: #ffffff;
}

#swimmers tbody tr:nth-child(even) td {
  background: var(--surface-soft);
}

#swimmers tbody tr:hover td {
  background: #eef6f6;
}

#swimmers tr > th:first-child,
#swimmers tr > td:first-child {
  position: sticky;
  left: 0;
  z-index: 20;
  width: var(--event-col-width);
  min-width: var(--event-col-width);
  max-width: var(--event-col-width);
  border-right: 1px solid var(--event-border);
  background: var(--event-bg);
  color: #1f2937;
  font-weight: 800;
}

#swimmers tr > th:first-child {
  z-index: 40;
  background: #3f3f46;
  color: #ffffff;
}

#swimmers tbody tr:hover > td:first-child {
  background: #fff0a6;
}

body.score-card-page #swimmers tr > th:nth-child(2),
body.score-card-page #swimmers tr > td:nth-child(2) {
  position: sticky;
  left: var(--event-col-width);
  width: var(--card-sticky-col-width);
  min-width: var(--card-sticky-col-width);
  max-width: var(--card-sticky-col-width);
  border-right: 1px solid var(--border-strong);
  box-shadow: 6px 0 10px -10px rgba(15, 23, 42, 0.55);
}

body.score-card-page #swimmers tr > th:nth-child(2) {
  z-index: 39;
  background: var(--header-alt);
}

body.score-card-page #swimmers tr > td:nth-child(2) {
  z-index: 19;
  background: #ffffff;
}

body.score-card-page #swimmers tbody tr:nth-child(even) > td:nth-child(2) {
  background: var(--surface-soft);
}

body.score-card-page #swimmers tbody tr:hover > td:nth-child(2) {
  background: #eef6f6;
}

#swimmers td.qualified {
  background: var(--success-bg);
  color: var(--success-text);
  font-weight: 800;
}

#swimmers tbody tr:nth-child(even) td.qualified,
#swimmers tbody tr:hover td.qualified {
  background: #bbf7d0;
}

#swimmers td.standards {
  color: #334155;
  font-weight: 800;
}

#swimmers .time-delta {
  color: var(--muted);
  background: #fefce8;
  font-weight: 700;
}

.tooltip {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.tooltip-inner {
  max-width: 300px !important;
}

.cell_with_comment {
  position: relative;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}

.cell_comment {
  display: none;
  position: absolute;
  z-index: 100;
  top: -60px;
  left: 120px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(36, 48, 74, 0.96);
  color: #ffffff;
  font-family: Arial, sans-serif;
}

.cell_with_comment:hover span.cell_comment {
  display: block;
}

.discovery-shell {
  max-width: 1120px;
}

.discovery-panel,
.selected-panel,
.settings-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

.discovery-panel {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 16px;
  padding: 16px;
}

.discovery-search {
  flex: 1 1 360px;
}

.discovery-search input,
.discovery-search select,
.compare-select {
  width: 100%;
  max-width: 100%;
  min-height: 40px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.discovery-search input,
.compare-select {
  padding: 0 12px;
}

.discovery-search select {
  padding: 0 34px 0 10px;
}

.loader {
  display: none;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
}

.htmx-request {
  display: block;
}

.results-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.results-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  color: var(--text);
  font-size: 14px;
}

.results-table th,
.results-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

.results-table th {
  background: var(--header);
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.results-table tbody tr:nth-child(even) td {
  background: var(--surface-soft);
}

.results-table tbody tr:hover td {
  background: #eef6f6;
}

.results-table tbody tr:last-child td {
  border-bottom: 0;
}

.result-name {
  color: var(--accent-strong);
  font-weight: 800;
  text-decoration: none;
}

.result-name:hover,
.result-name:focus {
  color: #0f766e;
  text-decoration: underline;
}

.result-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.favorite-button.is-favorite {
  border-color: #f59e0b;
  background: #fffbeb;
  color: #92400e;
}

.favorite-button.is-favorite:hover,
.favorite-button.is-favorite:focus {
  background: #fef3c7;
  color: #78350f;
}

.result-id,
.selected-meta {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.empty-row td {
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.pagination-row td {
  background: #ffffff;
}

.pagination-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.pagination-status {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.pagination-controls .score-button:disabled {
  opacity: 0.45;
  transform: none;
  cursor: not-allowed;
}

.compare-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(360px, 1.1fr);
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

.compare-picker {
  align-items: stretch;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 0;
}

.compare-picker .discovery-search {
  flex: 0 0 auto;
}

.favorite-panel {
  display: grid;
  gap: 8px;
  padding-top: 2px;
}

.favorite-panel-heading {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.favorite-list {
  display: grid;
  gap: 8px;
}

.search-favorites-panel {
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

.search-favorites-panel .favorite-list {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.favorite-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.favorite-name {
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
}

.favorite-meta,
.favorite-empty {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.favorite-actions {
  display: flex;
  gap: 6px;
}

.selected-panel {
  overflow: hidden;
}

.panel-heading {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-soft);
}

.panel-heading h2 {
  margin: 0;
  color: var(--text);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.2;
}

.selected-table th:first-child,
.selected-table td:first-child {
  width: 120px;
  color: var(--muted);
  font-weight: 800;
}

.selected-name {
  display: block;
  color: var(--text);
  font-weight: 800;
}

.settings-panel {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(240px, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 16px;
}

@media (hover: none) {
  .score-button:hover,
  .score-button:focus {
    transform: none;
  }
}

@media (max-width: 760px) {
  body.score-page {
    font-size: 14px;
  }

  .score-shell {
    padding: 16px 10px 28px;
  }

  .score-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 14px;
  }

  #banner {
    font-size: 23px;
  }

  .score-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .score-button {
    width: 100%;
    min-height: 42px;
    padding: 0 10px;
    font-size: 13px;
    line-height: 1.15;
    white-space: normal;
  }

  .share-link {
    grid-column: 1 / -1;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .score-toolbar {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 12px;
    padding: 12px;
  }

  .control-field,
  .control-search {
    width: 100%;
  }

  .control-field input,
  .control-field select,
  .discovery-search input,
  .discovery-search select,
  .compare-select {
    height: 44px;
    min-height: 44px;
    font-size: 16px;
  }

  .switch {
    justify-content: space-between;
    width: 100%;
  }

  .discovery-panel,
  .settings-panel {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .discovery-panel {
    flex-direction: column;
    gap: 10px;
    padding: 12px;
  }

  .discovery-search {
    flex: 1 1 auto;
    width: 100%;
  }

  .loader {
    align-self: center;
  }

  .compare-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .selected-panel {
    overflow: visible;
  }

  .panel-heading {
    padding: 12px;
  }

  .settings-panel {
    gap: 10px;
    padding: 12px;
  }

  .settings-panel .score-button {
    min-height: 44px;
  }

  .favorite-item {
    grid-template-columns: 1fr;
  }

  .favorite-actions .score-button {
    flex: 1 1 0;
  }

  .table-container {
    width: calc(100% + 20px);
    max-height: calc(100vh - 240px);
    margin-right: -10px;
    margin-left: -10px;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  #swimmers {
    min-width: 640px;
    font-size: 12px;
  }

  #swimmers th,
  #swimmers td {
    height: 34px;
    padding: 6px 8px;
  }

  #swimmers th {
    font-size: 11px;
    line-height: 1.2;
    vertical-align: bottom;
    white-space: normal;
  }

  #swimmers th a {
    display: block;
    max-width: 88px;
    overflow-wrap: anywhere;
    white-space: normal;
  }

  #swimmers tr > th:first-child,
  #swimmers tr > td:first-child {
    width: 86px;
    min-width: 86px;
    max-width: 86px;
    padding-right: 8px;
    padding-left: 8px;
    line-height: 1.15;
    white-space: normal;
  }

  body.score-card-page #swimmers tr > th:nth-child(2),
  body.score-card-page #swimmers tr > td:nth-child(2) {
    left: 86px;
    width: 88px;
    min-width: 88px;
    max-width: 88px;
  }

  #swimmers td:not(:first-child) {
    min-width: 62px;
  }

  .cell_comment {
    top: auto;
    bottom: calc(100% + 6px);
    left: 0;
    max-width: 220px;
    white-space: normal;
  }

  .results-wrap {
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .results-table,
  .results-table tbody,
  .results-table tr,
  .results-table td {
    display: block;
    width: 100%;
  }

  .results-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .results-table tr {
    margin-bottom: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
  }

  .results-table td {
    padding: 10px 12px;
    border-bottom: 0;
    background: transparent;
  }

  .results-table td + td {
    border-top: 1px solid var(--border);
  }

  .results-table td[data-label] {
    display: grid;
    grid-template-columns: 84px minmax(0, 1fr);
    gap: 12px;
    align-items: start;
    text-align: left;
  }

  .results-table td[data-label]::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
  }

  .result-id,
  .selected-meta {
    grid-column: 2;
  }

  .results-table tbody tr:nth-child(even) td,
  .results-table tbody tr:hover td {
    background: transparent;
  }

  .result-actions {
    grid-column: 2;
    width: 100%;
  }

  .result-actions .score-button {
    flex: 1 1 88px;
  }

  .results-table .empty-row td {
    display: block;
    text-align: center;
  }

  .pagination-row {
    box-shadow: none;
  }

  .pagination-controls {
    justify-content: space-between;
  }

  .selected-table th:first-child,
  .selected-table td:first-child {
    width: auto;
  }
}

@media (max-width: 520px) {
  .score-actions {
    grid-template-columns: 1fr;
  }

  #banner {
    font-size: 22px;
  }

  .score-kicker {
    font-size: 11px;
  }

  #swimmers {
    min-width: 600px;
  }

  #swimmers th a {
    max-width: 76px;
  }
}

@media (max-width: 760px) {
  body.score-data-page .score-shell {
    padding-top: 14px;
  }

  body.score-data-page .score-header {
    gap: 9px;
    margin-bottom: 10px;
  }

  body.score-data-page #banner {
    font-size: 21px;
  }

  body.score-data-page .score-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  body.score-data-page .score-button {
    min-height: 34px;
    padding: 0 8px;
    border-radius: 7px;
    font-size: 11px;
    line-height: 1.1;
  }

  body.score-data-page .share-link {
    font-size: 12px;
  }

  body.score-data-page .score-toolbar {
    grid-template-columns: minmax(0, 1fr) 96px;
    gap: 8px;
    margin-bottom: 8px;
    padding: 10px;
  }

  body.score-data-page .control-switch {
    grid-column: 1 / -1;
  }

  body.score-data-page .control-field {
    gap: 4px;
    font-size: 11px;
  }

  body.score-data-page .control-field input,
  body.score-data-page .control-field select {
    height: 36px;
    min-height: 36px;
    min-width: 0;
    padding-right: 28px;
    font-size: 14px;
  }

  body.score-data-page .switch {
    min-height: 32px;
    font-size: 13px;
  }

  body.score-data-page .slider {
    width: 38px;
    height: 22px;
    flex-basis: 38px;
  }

  body.score-data-page .slider:before {
    width: 16px;
    height: 16px;
  }

  body.score-data-page input:checked + .slider:before {
    transform: translateX(16px);
  }

  body.score-data-page .table-container {
    max-height: calc(100vh - 170px);
  }
}

@media (max-width: 520px) {
  body.score-data-page .score-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body.score-data-page .share-link {
    grid-column: 1 / -1;
  }
}
