/* === Base === */
body {
  font-family: system-ui, -apple-system, sans-serif;
  margin: 0;
  padding: 24px;
  padding-top: 56px;
  background: #07182d;
  color: #eee;
}

h1 {
  margin: 0 0 24px;
  font-size: 20px;
}

h3 {
  margin: 0;
  font-size: 14px;
  text-transform: uppercase;
  opacity: 0.6;
}

a {
  color: #e94560;
  text-decoration: none;
}

/* === Top bar === */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: #0f3460;
  z-index: 10;
}

.top-bar a {
  color: white;
  text-decoration: none;
  font-size: 14px;
}

.top-bar a.active {
  font-weight: 700;
}

.top-bar .org-name {
  color: #eee;
  font-size: 14px;
  opacity: 0.7;
}

/* === Centered card (login, settings) === */
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: #07182d;
  padding: 28px 40px;
  border-radius: 16px;
}

/* === Inputs === */
input {
  padding: 8px 12px;
  font-size: 14px;
  border: none;
  border-radius: 8px;
  background: #0f3460;
  color: #eee;
  box-sizing: border-box;
}

input::placeholder {
  color: #888;
}

input[type="number"].minutes {
  width: 40px;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}

input.input-error {
  border: 2px solid #e94560;
  color: #e94560;
}

.link-warning {
  color: #e94560;
  font-size: 13px;
  margin-top: 4px;
}

.public-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: #eee;
}

.public-link {
  margin-top: 8px;
  font-size: 14px;
}

.public-link a {
  color: #2ecc71;
  text-decoration: none;
}

.public-link a:hover {
  text-decoration: underline;
}

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

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

.switch .slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #e94560;
  transition: 0.3s;
  border-radius: 26px;
}

.switch .slider::before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: white;
  transition: 0.3s;
  border-radius: 50%;
}

.switch input:checked + .slider {
  background: #2ecc71;
}

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

select {
  padding: 6px 10px;
  border: none;
  border-radius: 6px;
  background: #0f3460;
  color: #eee;
  font-size: 13px;
}

/* === Buttons === */
button {
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: #e94560;
  color: white;
  cursor: pointer;
  transition: background 0.2s;
}

button:hover {
  background: #c73e54;
}

.btn {
  padding: 8px 16px;
  font-size: 14px;
  border-radius: 6px;
}

.btn-save {
  background: #2ecc71;
  color: white;
}

.btn-cancel {
  background: #555;
  color: white;
}

.btn-edit {
  background: #3498db;
  color: white;
  padding: 4px 10px;
  font-size: 12px;
}

/* === Tables === */
table {
  width: 100%;
  border-collapse: collapse;
  background: #07182d;
  border-radius: 8px;
  overflow: hidden;
}

/* Wide tables scroll inside their wrapper instead of stretching the page */
.table-wrap {
  overflow-x: auto;
}

th, td {
  padding: 8px 8px;
  text-align: center;
  border-bottom: 1px solid #0f3460;
}

th {
  font-size: 12px;
  text-transform: uppercase;
  background: #0f3460;
}

tr th:nth-child(2) {
  text-align: left;
}

tr td:nth-child(2) {
  text-align: left;
}

tr td:first-child {
  font-weight: 700;
}

tr:last-child td {
  border-bottom: none;
}

.empty {
  text-align: center;
  padding: 40px;
  opacity: 0.4;
}

.editing {
  background: #0f3460;
}

.editing input,
.editing select {
  background: #16213e;
  padding: 4px 6px;
  border: none;
  border-radius: 4px;
  color: #eee;
  font-size: 14px;
}

/* === Login page === */
.login-body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 0;
  padding-top: 0;
}

.login-body input {
  width: 100%;
}

.login-body button {
  width: 100%;
}

.btn-row {
  display: flex;
  gap: 12px;
  width: 100%;
}

.btn-row button {
  flex: 1;
}

.btn-secondary {
  background: #0f3460;
}

.btn-secondary:hover {
  background: #1a4a8a;
}

.error {
  color: #e94560;
  font-size: 14px;
  text-align: center;
  display: none;
  margin: 0;
}

/* === My Competitions page === */
.comp-create {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.comp-create input {
  flex: 1;
}

.comp-create button {
  padding: 12px 24px;
}

/* === Settings page === */
#settings-panel {
  flex-direction: row;
  align-items: flex-start;
  flex-wrap: wrap;
}

.settings-section {
  flex: 1;
  min-width: 200px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-section input,
.settings-section select {
  width: 100%;
}

.weight-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.weight-col h3 {
  margin: 0;
  font-size: 14px;
  text-transform: uppercase;
  opacity: 0.6;
}

.weight-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 32px;
}

.weight-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: #0f3460;
  border-radius: 6px;
  font-size: 14px;
}

.weight-tag button {
  padding: 0;
  font-size: 14px;
  background: none;
  color: #e94560;
  cursor: pointer;
}

.weight-tag button:hover {
  background: none;
}

.add-weight {
  display: flex;
  gap: 6px;
}

.add-weight input {
  width: 80px;
}

.add-weight button {
  padding: 6px 12px;
  font-size: 14px;
}

/* === Athletes page === */
.form-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.form-row input {
  width: 120px;
}

.form-row select {
  width: 130px;
}

table input[type="number"].e-weight,
table input[type="number"].e-birthyear,
table input[type="text"].e-age,
table .e-lift {
  width: 75px;
}

table input[type="text"].e-wc,
table input[type="number"].e-group,
table input[type="number"].e-lot {
  width: 60px;
}


.btn-add {
  background: #e94560;
  color: white;
}

.btn-lifts {
  background: #9b59b6;
  color: white;
  padding: 4px 10px;
  font-size: 12px;
}

.lifts-row td {
  padding: 0 16px 16px;
}

.lifts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.lift-group {
  background: #0f3460;
  border-radius: 6px;
  padding: 10px;
}

.lift-group h4 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  opacity: 0.6;
}

.lift-item {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 13px;
}

.lift-item label {
  min-width: 70px;
}

.lift-item input[type="number"] {
  width: 60px;
  padding: 4px 6px;
  border: none;
  border-radius: 4px;
  background: #16213e;
  color: #eee;
  font-size: 13px;
}

.light-btn {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}

.light-btn:hover {
  background: inherit;
}

.light-0 {
  background: #666;
  color: white;
}

.light-1 {
  background: #2ecc71;
  color: white;
}

.light--1 {
  background: #e74c3c;
  color: white;
}

/* === Competition page === */
.control-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.clock-bar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.judge-bar {
  display: flex;
  gap: 8px;
}

.group-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.group-bar label {
  font-size: 14px;
  opacity: 0.7;
}

.group-section {
  margin-bottom: 24px;
}

.group-inactive {
  opacity: 0.5;
}

.group-section th:nth-child(n+5):nth-child(-n+13),
.group-section td:nth-child(n+5):nth-child(-n+13) {
  padding: 6px 2px;
}

.lift-btns {
  display: flex;
  gap: 8px;
}

.total-cell {
  font-weight: 700;
  text-align: center;
}

/* === Clock === */
#clock-display {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 80px;
  text-align: center;
}


.btn-good {
  background: #2ecc71;
  color: white;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 700;
  border-radius: 8px;
}

.btn-nolift {
  background: #e74c3c;
  color: white;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 700;
  border-radius: 8px;
}

.btn-good:disabled,
.btn-nolift:disabled {
  opacity: 0.3;
  cursor: default;
}

.lift-good {
  background: #2ecc71;
  color: black;
  text-align: center;
}

.lift-fail {
  background: #e74c3c;
  color: black;
  text-align: center;
}

.lift-pending {
  /*background: #f39c12;*/
  color: white;
  text-align: center;
}

.lift-empty {
  text-align: center;
}

.lift-current {
  background: #5dade2;
  color: white;
  text-align: center;
}

.current-lifter td:not(.lift-current):not(.lift-good):not(.lift-fail) {
  background: #0f3460;
}
.lift-cell {
  
}
.lift-weight {
  text-align: center;
  padding: 8px 12px;
  font-size: 14px;
  border: none;
  border-radius: 4px;
  background: #0f3460;
  color: #eee;
  box-sizing: border-box;
  width: 65px;
}

.lift-good .lift-weight {
  background:#2ecc71;
}

.lift-fail .lift-weight {
  background:#e74c3c;
}

.current-lifter td:not(.lift-good):not(.lift-fail) .lift-weight {
  background: #07182d;
}

.lift-status {
  display: block;
  margin: 4px auto 0;
  padding: 2px 2px;
  font-size: 11px;
  border: none;
  border-radius: 4px;
  background: #16213e;
  color: #eee;
  cursor: pointer;
}

.completed {
  opacity: 0.4;
}

.group-section td:nth-child(2) {
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* === Lifter screen (public display) === */
.lifter-screen-body {
  padding: 0;
  background: #000;
  overflow: hidden;
  height: 100vh;
}

.lifter-screen {
  display: grid;
  grid-template-areas:
    "attempt timer"
    "name timer"
    "info bar"
    "next bar"
    "weight bar";
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto auto auto 1fr;
  gap: 8px 40px;
  padding: 24px 32px;
  width: 100%;
  height: 100vh;
  box-sizing: border-box;
  align-items: start;
}

.lifter-timer {
  grid-area: timer;
  font-size: 180px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-align: right;
  white-space: nowrap;
}

.lifter-attempt {
  grid-area: attempt;
  font-size: 64px;
  font-weight: 700;
  color: #e94560;
}

.lifter-name {
  grid-area: name;
  font-size: 96px;
  font-weight: 700;
  line-height: 1.05;
}

.lifter-info {
  grid-area: info;
  font-size: 40px;
  opacity: 0.8;
}

.lifter-next {
  grid-area: next;
  font-size: 28px;
  opacity: 0.7;
}

.lifter-weight {
  grid-area: weight;
  font-size: 160px;
  font-weight: 700;
  line-height: 1;
  align-self: end;
  color: #e94560;
}

.bar-load-container {
  grid-area: bar;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
}

.bar-load {
  display: flex;
  align-items: center;
  height: 100%;
  min-width: 200px;
  font-weight: bold;
  --plate-font-size: 23px;
  --plate-width: 30px;
  --plate-margin-right: 5px;
  --maximum-plate-height: 80%;
}

.bar-load div {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-right: var(--plate-margin-right);
  border-style: solid;
  border-color: white;
  padding: 5px;
  font-size: 50px;
  min-width: 50px;
  box-sizing: border-box;
}

.bar-load .lifter-bar {
  width: var(--plate-width);
  height: 10%;
  background-color: gray;
}

.lifter-plate.plate-50 {
  height: var(--maximum-plate-height);
  width: calc(var(--plate-width) * 1.5);
}

.lifter-plate.plate-25 {
  height: var(--maximum-plate-height);
  background-color: red;
}

.lifter-plate.plate-20 {
  height: var(--maximum-plate-height);
  background-color: blue;
}

.lifter-plate.plate-15 {
  height: calc(var(--maximum-plate-height) * 0.9);
  background-color: yellow;
  color: #000;
}

.lifter-plate.plate-10 {
  height: calc(var(--maximum-plate-height) * 0.8);
  background-color: green;
}

.lifter-plate.plate-5 {
  height: calc(var(--maximum-plate-height) * 0.7);
  background-color: #ffffff;
  color: #000;
}

.lifter-plate.plate-2p5 {
  height: calc(var(--maximum-plate-height) * 0.6);
  background-color: black;
}

.lifter-plate.plate-1p25 {
  height: calc(var(--maximum-plate-height) * 0.5);
  background-color: gray;
}

.lifter-plate.plate-0p5 {
  height: calc(var(--maximum-plate-height) * 0.45);
  background-color: #ffffff;
  color: #000;
}

.lifter-plate.plate-0p25 {
  height: calc(var(--maximum-plate-height) * 0.4);
  background-color: gray;
}

.bar-load .lifter-collar {
  margin-right: 0;
  height: 14%;
  background-color: gray;
  width: 50px;
}

.rack-info {
  position: absolute;
  right: 0;
  font-size: 50px;
  text-align: right;
  padding-right: 75px;
}

/* === Scoreboard screen (public display) === */
.scoreboard-body {
  padding: 0;
  overflow: auto;
  height: 100vh;
}

.scoreboard {
  padding: 24px 32px;
}

.scoreboard-comp {
  font-size: 40px;
  margin: 0 0 4px 0;
}

.scoreboard-title {
  font-size: 32px;
  margin: 0 0 16px 0;
  color: #2ecc71;
}

.scoreboard-list .group-section h3 {
  font-size: 24px;
}

.scoreboard-closed {
  font-size: 32px;
  color: #e94560;
}

/* === Stream bar screen (public display) === */
.stream-bar-body {
  padding: 0;
  background: transparent;
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: start;
}

.stream-bar {
  box-sizing: border-box;
  padding: 0 24px;
}

.stream-bar-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  padding: 10px 16px;
  border-radius: 12px;
  background: #0f3460;
}

.stream-bar-name {
  font-size: 56px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stream-bar-divisions {
  font-size: 26px;
  opacity: 0.85;
  white-space: nowrap;
  text-align: right;
}

.stream-bar-empty .stream-bar-top {
  justify-content: center;
  text-align: center;
}

.stream-bar-empty .stream-bar-name {
  font-size: 48px;
}

.stream-bar-bottom {
  display: flex;
  align-items: stretch;
  gap: 12px;
  margin-top: 12px;
}

.stream-attempt {
  width: 140px;
  border-radius: 8px;
  padding: 14px 8px;
  font-size: 46px;
  font-weight: 700;
  text-align: center;
  background: #0f3460;
}

.stream-attempt-current {
  background: #5dade2;
}

.stream-attempt-good {
  background: #2ecc71;
  color: #fff;
}

.stream-attempt-bad {
  background: #e74c3c;
  color: #fff;
}

.stream-spacer {
  flex: 1;
}

.stream-max-box {
  border-radius: 8px;
  min-width: 170px;
  padding: 6px 10px;
  background: #0f3460;
}

.stream-max-label {
  font-size: 20px;
  text-transform: uppercase;
  opacity: 0.8;
}

.stream-max-value {
  font-size: 34px;
  font-weight: 700;
}

.stream-points-box {
  border-radius: 8px;
  min-width: 190px;
  padding: 6px 10px;
  background: #0f3460;
  color: #eee;
}

.stream-points-label {
  font-size: 20px;
  text-transform: uppercase;
}

.stream-points-value {
  font-size: 42px;
  font-weight: 700;
  line-height: 1;
}

.stream-closed {
  font-size: 40px;
  color: #e94560;
  font-weight: 700;
}

/* === Mobile (<= 768px) === */
@media (max-width: 768px) {
  body {
    padding: 12px;
    padding-top: 12px;
  }

  /* Top bar stacks: org name on its own line, nav links wrap */
  .top-bar {
    position: static;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 12px;
  }

  .top-bar > div {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
  }

  /* Competition page: controls stack; Good Lift / No Lift side by side, always visible */
  .control-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .judge-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .judge-bar button {
    width: 100%;
  }

  .clock-bar {
    flex-wrap: wrap;
  }

  /* Athletes add form: inputs wrap ~2 per row so it fits 390 px */
  .form-row input,
  .form-row select {
    flex: 1 1 45%;
    width: auto;
  }

  /* Let the competition-name input shrink so Create/Load stay on screen */
  .comp-create input {
    min-width: 0;
  }
}

/* === Athletes page only: stack table cells into zones that wrap as units (all widths) === */
.athletes-page .table-wrap table,
  .athletes-page .table-wrap thead,
  .athletes-page .table-wrap tbody,
  .athletes-page .table-wrap tr,
  .athletes-page .table-wrap th,
  .athletes-page .table-wrap td {
    display: block;
  }

  .athletes-page .table-wrap thead {
    display: none;
  }

  .athletes-page .table-wrap tbody {
    display: flex;
    flex-direction: column;
    gap: 0px;
  }

  .athletes-page .table-wrap tr {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    border: 1px solid #0f3460;
    border-radius: 10px;
    background: #0a1f3c;
    margin-bottom: 10px;
  }

  /* Each zone is a wrapping row of fields that flows side by side with the
     others; a zone never splits, it moves to a new row as a unit when the
     card gets narrower. Bases are proportional to the field count so zones
     pack together on wide screens and drop down one by one as width shrinks. */
  .athletes-page .table-wrap .ath-zone {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px 8px;
    padding: 4px 6px;
    border-radius: 6px;
    min-width: 0;
  }

  /* Zone 1 (name + remove) gets its own full-width row. Zones 2+3 and 4+5
     live in .ath-row wrappers, so each pair shares one line and wraps to a
     new row dynamically only when the card gets too narrow. */
  .athletes-page .table-wrap .ath-zone:nth-child(1) {
    flex: 1 1 100%;
  }

  .athletes-page .table-wrap .ath-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex: 1 1 100%;
    min-width: 0;
  }

  .athletes-page .table-wrap .ath-row .ath-zone {
    flex: 0 1 auto;
    min-width: auto;
  }

  .athletes-page .table-wrap td {
    border: none;
    padding: 4px 2px;
    text-align: left;
    flex: 0 1 auto;
    min-width: 0;
  }

  .athletes-page .table-wrap td::before {
    content: attr(data-label);
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    opacity: 0.55;
    margin-bottom: 3px;
  }

  .athletes-page .table-wrap td[data-label=""]::before {
    display: none;
  }

  /* Inputs keep their natural size; cells hug them instead of stretching */
  .athletes-page .table-wrap td input,
  .athletes-page .table-wrap td select {
    min-width: 0;
    box-sizing: border-box;
  }

  /* Name, Club and School get a bit more room than the rest */
  .athletes-page .table-wrap td[data-label="Name"],
  .athletes-page .table-wrap td[data-label="Club"],
  .athletes-page .table-wrap td[data-label="School"] {
    flex-grow: 2;
  }

  /* Name input spans the full width of its zone */
  .athletes-page .table-wrap td[data-label="Name"] input {
    width: 400px;
    box-sizing: border-box;
  }

  /* Remove button always sticks to the right edge of its zone */
  .athletes-page .table-wrap td[data-label=""] {
    margin-left: auto;
    flex-grow: 0;
  }

/* Athletes cards on small screens: the desktop 400px Name input must fit its cell */
@media (max-width: 768px) {
  .athletes-page .table-wrap td[data-label="Name"] input {
    width: 100%;
  }
}
