/* UoB Table Tennis Elo
   One hand-written stylesheet. Plain, boxy, utilitarian.
   No frameworks, no shadows, no gradients, no rounded corners. */

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: system-ui, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  color: #222222;
  background: #ffffff;
  overflow-wrap: break-word;
}

a {
  color: #1a4d8f;
  text-decoration: underline;
}

a,
button,
input,
select,
textarea {
  touch-action: manipulation;
}

a:hover {
  color: #1a4d8f;
}

h1,
h2 {
  margin: 0 0 8px 0;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
}

h3 {
  margin: 0 0 6px 0;
  font-size: 14px;
  font-weight: 600;
}

p {
  margin: 0 0 8px 0;
}

ul,
ol {
  margin: 0 0 8px 0;
  padding-left: 20px;
}

:focus-visible {
  outline: 2px solid #1a4d8f;
  outline-offset: 2px;
}

/* Accessibility */

.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  z-index: 20;
  padding: 6px 10px;
  border: 1px solid #1a4d8f;
  background: #ffffff;
  color: #1a4d8f;
}

.skip-link:focus {
  top: 8px;
}

/* Top bar */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid #cccccc;
  background: #ffffff;
}

.topbar-inner {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto 0 0;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.club-name {
  color: #222222;
  font-weight: 600;
  text-decoration: none;
}

.club-name:hover {
  color: #222222;
  text-decoration: underline;
}

.user-area {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 4px 10px;
}

.user-name {
  color: #1a4d8f;
}

.logout-form {
  margin: 0;
}

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: #1a4d8f;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* Page layout */

.layout {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto 0 0;
  padding: 20px 16px;
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 68px;
  background: #f2f2f2;
  border: 1px solid #cccccc;
  padding: 5px;
}

.sidebar ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.sidebar li {
  margin: 0 0 2px 0;
}

.sidebar li:last-child {
  margin-bottom: 0;
}

.sidebar a {
  display: block;
  padding: 6px 8px;
  border-left: 3px solid transparent;
  color: #1a4d8f;
  text-decoration: none;
}

.sidebar a:hover {
  background: #ffffff;
  text-decoration: underline;
}

.sidebar a.active {
  border-left-color: #1a4d8f;
  background: #ffffff;
  color: #222222;
  font-weight: 600;
}

.content {
  min-width: 0;
  width: 100%;
}

/* Page title row */

.page-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 10px;
  border-bottom: 1px solid #cccccc;
}

.page-title-row h1 {
  margin: 0;
}

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

/* Sections */

.section {
  margin-bottom: 28px;
}

.section h2 {
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid #cccccc;
}

/* Summary statistics */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 20px;
  border-top: 1px solid #cccccc;
  border-left: 1px solid #cccccc;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-right: 1px solid #cccccc;
  border-bottom: 1px solid #cccccc;
}

.stat-label {
  font-size: 12px;
}

.stat-value {
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Flash messages */

.flash-list {
  margin-bottom: 16px;
}

.flash {
  margin-bottom: 8px;
  padding: 8px 10px;
  border: 1px solid #cccccc;
  border-left-width: 4px;
  background: #ffffff;
  color: #222222;
}

.flash:last-child {
  margin-bottom: 0;
}

.flash-success {
  border-color: #2e7d32;
  color: #1b5e20;
}

.flash-error {
  border-color: #b00020;
  color: #b00020;
}

.flash-info {
  border-color: #1a4d8f;
  color: #222222;
}

/* Buttons */

.btn {
  display: inline-block;
  padding: 5px 12px;
  border: 1px solid #1a4d8f;
  background: #ffffff;
  color: #1a4d8f;
  font: inherit;
  line-height: 1.4;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  background: #f2f2f2;
  color: #1a4d8f;
}

.btn-primary {
  background: #1a4d8f;
  color: #ffffff;
}

.btn-primary:hover {
  background: #1a4d8f;
  color: #ffffff;
  text-decoration: underline;
}

.btn:disabled,
.btn[disabled] {
  border-color: #cccccc;
  background: #f2f2f2;
  color: #222222;
  cursor: default;
}

/* Forms */

form {
  margin: 0 0 16px 0;
}

.field {
  margin-bottom: 12px;
}

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

.field .required {
  font-weight: 400;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  max-width: 420px;
  min-height: 32px;
  padding: 5px 6px;
  border: 1px solid #cccccc;
  background: #ffffff;
  color: #222222;
  font: inherit;
}

.field input[type="checkbox"] {
  width: auto;
  max-width: none;
  min-height: 0;
  padding: 0;
  accent-color: #1a4d8f;
}

.field textarea {
  min-height: 80px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid #1a4d8f;
  outline-offset: 0;
}

.field-hint {
  margin-top: 3px;
  font-size: 12px;
}

.field-error {
  margin-top: 3px;
  font-size: 12px;
  color: #b00020;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
}

.form-actions form {
  margin: 0;
}

.auth-form {
  max-width: 420px;
  margin-bottom: 16px;
}

.game-grid {
  max-width: 420px;
  margin-bottom: 16px;
  border: 1px solid #cccccc;
}

.game-row {
  display: grid;
  grid-template-columns: 52px 70px 16px 70px;
  gap: 6px;
  align-items: center;
  padding: 4px 6px;
  border-bottom: 1px solid #cccccc;
}

.game-row:last-child {
  border-bottom: 0;
}

.game-head {
  background: #f2f2f2;
  font-weight: 600;
}

.game-row input {
  width: 70px;
  max-width: 70px;
  min-height: 0;
  padding: 3px 5px;
}

.game-number {
  font-weight: 600;
}

.filter-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 16px;
}

.filter-form .field {
  margin-bottom: 0;
}

.filter-form select {
  width: auto;
  min-width: 160px;
}

.filter-form input[type="search"] {
  width: 220px;
  max-width: 100%;
}

.provisional {
  font-size: 12px;
}

/* Charts */

.chart-note {
  font-size: 12px;
}

.rating-chart {
  margin-bottom: 16px;
  padding: 10px;
  border: 1px solid #cccccc;
  background: #ffffff;
  overflow-x: auto;
}

.rating-chart svg {
  display: block;
  width: 100%;
  min-width: 560px;
  height: auto;
}

.sparkline {
  display: inline-block;
  vertical-align: middle;
}

.sparkline svg {
  display: block;
}

.trend-cell {
  width: 130px;
  white-space: nowrap;
}

.audit-details {
  font-size: 12px;
  word-break: break-word;
}

.field input[type="file"] {
  padding: 4px;
}

/* Tables */

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid #cccccc;
}

.data-table th,
.data-table td {
  padding: 6px 8px;
  border: 1px solid #cccccc;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  background: #f2f2f2;
  font-weight: 600;
}

.data-table tbody tr:hover {
  background: #f2f2f2;
}

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

.data-table .table-empty {
  text-align: left;
}

.table-actions {
  white-space: nowrap;
}

.table-actions .btn {
  margin: 0 4px 2px 0;
}

.inline-form {
  display: inline;
  margin: 0;
}

/* Pagination */

.pagination {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: stretch;
  border: 1px solid #cccccc;
}

.pagination a,
.pagination span {
  padding: 4px 8px;
  border-right: 1px solid #cccccc;
  color: #1a4d8f;
  text-decoration: none;
}

.pagination a:hover {
  background: #f2f2f2;
}

.pagination a:last-child,
.pagination span:last-child {
  border-right: 0;
}

.pagination .current {
  background: #f2f2f2;
  color: #222222;
  font-weight: 600;
}

.pagination .disabled {
  background: #f2f2f2;
  color: #222222;
}

.pagination .ellipsis {
  color: #222222;
}

.pagination-info {
  margin: 6px 0 0 0;
  font-size: 12px;
}

/* Footer */

.site-footer {
  margin-top: 24px;
  border-top: 1px solid #cccccc;
  background: #ffffff;
}

.footer-inner {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto 0 0;
  padding: 10px 16px;
  font-size: 12px;
}

/* Tablet */

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 160px minmax(0, 1fr);
    gap: 18px;
  }

  .sidebar a {
    padding: 6px;
  }
}

/* Mobile */

@media (max-width: 700px) {
  .site-header {
    position: static;
  }

  .topbar-inner {
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 12px;
    padding: 8px 12px;
  }

  .club-name,
  .user-area a,
  .logout-form {
    display: flex;
    align-items: center;
    min-height: 40px;
  }

  .user-area {
    justify-content: flex-start;
    gap: 0 12px;
  }

  .link-button {
    min-height: 40px;
    padding: 0 2px;
  }

  .layout {
    display: block;
    padding: 14px 12px;
  }

  .sidebar {
    position: static;
    margin-bottom: 16px;
    padding: 4px;
  }

  .sidebar ul {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(125px, 1fr));
    gap: 2px;
  }

  .sidebar li {
    margin: 0;
    min-width: 0;
  }

  .sidebar a {
    display: flex;
    align-items: center;
    height: 100%;
    min-height: 44px;
    padding: 8px 10px;
    border-left: 3px solid transparent;
    border-bottom: 0;
  }

  .sidebar a.active {
    border-left-color: #1a4d8f;
    border-bottom-color: transparent;
  }

  .page-title-row {
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
  }

  .page-title-row h1 {
    width: 100%;
  }

  .page-actions {
    width: 100%;
    gap: 6px;
  }

  .page-actions .btn {
    flex: 1 1 120px;
  }

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

  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 8px 12px;
  }

  .field input,
  .field select,
  .field textarea {
    max-width: none;
    min-height: 40px;
    /* 16px stops mobile browsers zooming in when a field is focused. */
    font-size: 16px;
  }

  .field input[type="checkbox"] {
    min-height: 0;
  }

  .filter-form {
    display: block;
  }

  .filter-form .field {
    margin-bottom: 10px;
  }

  .filter-form select,
  .filter-form input[type="search"] {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .filter-form .btn {
    display: flex;
    width: 100%;
  }

  .form-actions {
    gap: 6px;
  }

  .form-actions .btn,
  .form-actions button {
    flex: 1 1 140px;
  }

  .game-grid {
    max-width: none;
  }

  .game-row {
    grid-template-columns: 40px minmax(0, 1fr) 12px minmax(0, 1fr);
    gap: 4px;
    padding: 5px 6px;
  }

  .game-row input {
    width: 100%;
    max-width: none;
    min-height: 40px;
    font-size: 16px;
  }

  .data-table {
    min-width: 480px;
  }

  .data-table th,
  .data-table td {
    padding: 7px 8px;
  }

  .table-actions {
    white-space: normal;
  }

  .table-actions .btn {
    min-height: 36px;
    padding: 6px 10px;
    margin: 0 4px 4px 0;
  }

  .rating-chart {
    padding: 6px;
  }

  .rating-chart svg {
    min-width: 480px;
  }

  .pagination {
    display: flex;
    width: 100%;
  }

  .pagination a,
  .pagination span {
    display: flex;
    flex: 1 0 auto;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 8px 10px;
  }

  .footer-inner {
    padding: 10px 12px;
  }
}

/* Narrow phones */

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

  .page-actions .btn {
    flex-basis: 100%;
  }

  .data-table {
    min-width: 420px;
  }

  .rating-chart svg {
    min-width: 420px;
  }
}
