:root {
  --bg: #f7f8fb;
  --ink: #18202b;
  --muted: #687385;
  --line: #d8dde6;
  --panel: #ffffff;
  --blue: #2f75b5;
  --green: #3f8f63;
  --red: #b54747;
  --amber: #a36b22;
  --shadow: 0 1px 2px rgba(24, 32, 43, 0.08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.4 "Segoe UI", Arial, sans-serif;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

h1, h2, p { margin: 0; }
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 16px; margin-bottom: 12px; }
.topbar p { color: var(--muted); margin-top: 2px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; flex: 0 0 auto; }
.session-user {
  display: grid;
  gap: 1px;
  margin-top: 6px;
  line-height: 1.15;
}
.session-user strong { font-size: 13px; }
.session-user span { color: var(--muted); font-size: 12px; }

button, input, select {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  min-height: 36px;
}
button {
  padding: 0 12px;
  cursor: pointer;
  color: var(--ink);
}
button:hover { border-color: #9aa8bc; }
button:active { transform: translateY(1px); }
button:disabled {
  cursor: progress;
  opacity: 0.65;
}
input, select { padding: 0 10px; }

.select-with-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.select-with-action select {
  min-width: 0;
}

.select-with-action button {
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 24px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.tab {
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}
.tab.active {
  color: var(--ink);
  border-bottom-color: var(--blue);
}

main { padding: 18px 24px 32px; }
.panel { display: none; }
.panel.active { display: block; }

.login-panel {
  display: grid;
  place-items: center;
  min-height: 55vh;
  padding: 24px;
}
.login-card {
  display: grid;
  gap: 12px;
  width: min(420px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.login-card p, #loginStatus {
  color: var(--muted);
}
.login-card label {
  display: grid;
  gap: 5px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
}
.sanity-panel {
  margin-top: 18px;
}
.sanity-ok {
  padding: 10px 12px;
  border: 1px solid #b9d8c6;
  border-radius: 8px;
  background: #edf8f1;
  color: #245a3b;
}
.sanity-ok.compact {
  margin-top: 10px;
}
.sanity-details {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.sanity-details summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  cursor: pointer;
  color: var(--muted);
}
.sanity-details summary strong { color: var(--ink); }
.sanity-details summary span { color: var(--muted); }
.sanity-list {
  display: grid;
  gap: 0;
  border-top: 1px solid #edf0f5;
  overflow: hidden;
}
.sanity-issue {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  border-bottom: 1px solid #f3dddd;
  padding: 6px 8px;
}
.sanity-issue.error { color: var(--red); }
.sanity-issue.warning { color: var(--amber); }
.sanity-issue span { font-weight: 700; }
.sanity-issue.is-waived {
  color: var(--muted);
  background: #fafbfc;
}
.sanity-open {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  gap: 8px;
  min-height: 30px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}
.sanity-waive, .sanity-unwaive {
  min-height: 30px;
  padding: 0 10px;
}
.sanity-subhead {
  margin: 12px 12px 6px;
  font-size: 13px;
  color: var(--muted);
}
.match-issues {
  display: grid;
  gap: 6px;
  margin: 10px 0 12px;
}
.match-issues .sanity-issue {
  border: 1px solid #edf0f5;
  border-radius: 6px;
}
.match-issues .sanity-issue.error {
  border: 1px solid #efc2c2;
  background: #fff2f2;
  color: var(--red);
}
.match-issues .sanity-issue.warning {
  border: 1px solid #ecd2aa;
  background: #fff8ed;
  color: var(--amber);
}
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { display: block; font-size: 24px; margin-top: 2px; }

.next-match-panel {
  margin-bottom: 18px;
}
.next-match-card {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  gap: 10px 14px;
  width: 100%;
  min-height: 0;
  padding: 12px 14px;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.next-match-card span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}
.next-match-card strong {
  font-size: 18px;
}
.next-match-card small {
  color: var(--muted);
}
.next-match-card em {
  grid-column: 1 / -1;
  overflow: hidden;
  color: var(--ink);
  font-style: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.result-prompt-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}
.result-prompt-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid #b9d8c6;
  border-radius: 8px;
  background: #edf8f1;
}
.result-prompt-item strong,
.result-prompt-item span {
  display: block;
}
.result-prompt-item span {
  color: var(--muted);
}
.load-result-btn {
  border-color: #8ec4a5;
  background: #fff;
  color: #245a3b;
  font-weight: 700;
  white-space: nowrap;
}

.grid.two, .split {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 16px;
}
.grid.two > section, .split > div, .match-form, .players .table-wrap {
  background: var(--panel);
}
.grid.two > section, .split > div, .match-form {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}
.match-form.is-saving {
  opacity: 0.92;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.toolbar input { min-width: 240px; }
.toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.toolbar-check {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  color: var(--ink);
  white-space: nowrap;
}
.toolbar-check input {
  min-width: 0;
  min-height: 0;
}
.inline-form { display: flex; gap: 8px; }
.merge-form {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto minmax(180px, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.merge-status {
  display: none;
  margin: -4px 0 12px;
  padding: 10px;
  border: 1px solid #b9d8c6;
  border-radius: 8px;
  background: #edf8f1;
  color: #245a3b;
}
.merge-status.show { display: block; }

.players-split {
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, 0.9fr);
}

.table-wrap {
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f7faff; }
tr.selected-row td { background: #eef6ff; }
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  padding: 9px 10px;
  border-bottom: 1px solid #edf0f5;
  text-align: left;
  white-space: nowrap;
}
th {
  color: var(--muted);
  font-weight: 600;
  background: #fbfcfe;
}
th[data-player-sort] {
  cursor: pointer;
  user-select: none;
}
th[data-player-sort]:hover { color: var(--ink); }

.tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #eef2f7;
}
.tag.mps { color: var(--blue); background: #eaf2fa; }
.tag.no { color: #222; background: #eceff3; }
.tag.played { color: var(--green); background: #e9f5ee; }
.tag.suspended { color: var(--red); background: #faeeee; }
.tag.scheduled { color: var(--amber); background: #f8f0e6; }

.rank-list { display: grid; gap: 8px; }
.rank-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid #edf0f5;
}
.rank-item small { color: var(--muted); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
label { display: grid; gap: 5px; color: var(--muted); }
label input, label select { color: var(--ink); width: 100%; }

.player-slots {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}
.slot-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, auto) 42px;
  gap: 8px;
  align-items: center;
}
.slot-row > button {
  grid-column: 3;
  padding: 0;
}
.slot-row.needs-review select,
.slot-row.needs-player select {
  border-color: var(--amber);
  box-shadow: 0 0 0 2px rgba(217, 119, 6, 0.12);
}
.slot-row.needs-player select {
  border-color: var(--red);
  box-shadow: 0 0 0 2px rgba(185, 28, 28, 0.12);
}
.slot-review {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  min-width: 0;
}
.slot-review strong {
  color: var(--ink);
}
.slot-review small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.slot-review button {
  min-height: 28px;
  padding: 0 8px;
}

.whatsapp-import {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
  background: #fbfcfe;
}
.whatsapp-import summary {
  cursor: pointer;
  font-weight: 700;
}
.whatsapp-import textarea {
  width: 100%;
  margin-top: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  resize: vertical;
  color: var(--ink);
  font: inherit;
}
.import-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.import-actions span,
.import-review {
  color: var(--muted);
}
.import-review {
  display: grid;
  gap: 4px;
  margin-top: 10px;
}
.import-review strong,
.import-review span {
  color: var(--ink);
}

.check-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  max-height: 620px;
  overflow: auto;
}
.balance-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.balance-columns section {
  min-width: 0;
}
.balance-columns h3 {
  margin: 0 0 8px;
  font-size: 14px;
}
.selected-summary {
  min-height: 32px;
  margin-bottom: 10px;
  color: var(--muted);
}
.selected-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0 6px 6px 0;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--ink);
  font-size: 12px;
}
.check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.check-item input { min-height: 0; }

.suggestion.empty { color: var(--muted); }
.detail.empty { color: var(--muted); }
.detail {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}
.detail-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.detail-head > div:last-child {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.use-balance-btn {
  min-height: 30px;
  padding: 0 10px;
}
.danger-btn {
  min-height: 30px;
  padding: 0 10px;
  border-color: #efc2c2;
  color: var(--red);
}
.danger-btn:hover {
  border-color: var(--red);
  background: #fff2f2;
}
.detail h2 { margin: 0; }
.detail-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}
.detail-list div {
  padding: 8px;
  background: #fbfcfe;
  border: 1px solid #edf0f5;
  border-radius: 6px;
}
.detail-list span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.player-status-form {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 8px;
  margin: 10px 0 12px;
}
.player-history {
  max-height: 420px;
}
.rating-debug-row td {
  padding: 0 10px 8px;
  background: #fbfcfe;
}
.rating-debug {
  border: 1px solid #d9e4f2;
  border-radius: 6px;
  background: #f5f9fd;
}
.rating-debug summary {
  padding: 8px 10px;
  cursor: pointer;
  color: var(--ink);
  font-weight: 700;
}
.debug-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 6px;
  padding: 0 10px 10px;
}
.debug-grid div, .debug-teams div {
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid #e6edf6;
  border-radius: 6px;
  background: #fff;
  white-space: normal;
}
.debug-grid span, .debug-teams span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.debug-grid code {
  white-space: normal;
}
.debug-teams {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 0 10px 10px;
}
.edit-match {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}
.edit-match .form-grid {
  grid-template-columns: repeat(2, minmax(140px, 1fr));
  margin-bottom: 0;
}
.mini-slots {
  display: grid;
  gap: 6px;
  max-height: 260px;
  overflow: auto;
}
.mini-slot {
  display: grid;
  grid-template-columns: 1fr 74px;
  gap: 6px;
}
.mini-slot.one-col { grid-template-columns: 1fr; }
.match-teams, .team-edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 10px 0 12px;
}
.match-team, .team-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}
.match-team h3, .team-editor h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 14px;
}
.match-team ol {
  margin: 0;
  padding-left: 22px;
}
.match-team li { padding: 3px 0; }
.team-level {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 8px;
}
.team-level div {
  padding: 7px 8px;
  border: 1px solid #edf0f5;
  border-radius: 6px;
  background: #fbfcfe;
}
.team-level span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.team-player-list {
  display: grid;
  gap: 6px;
}
.team-player-list li {
  padding: 6px 0;
}
.team-player-list strong {
  display: block;
}
.team-player-list small {
  color: var(--muted);
}
.team-editor label { margin-bottom: 8px; }
.teams {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.suggestion-list {
  display: grid;
  gap: 14px;
}
.suggestion-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}
.suggestion-card h3 {
  margin: 0 0 8px;
  font-size: 15px;
}
.suggestion-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.suggestion-head h3 {
  margin: 0;
}
.apply-suggestion {
  min-height: 30px;
  padding: 0 10px;
}
.metric-help {
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid #d9e4f2;
  border-radius: 8px;
  background: #f5f9fd;
  color: var(--muted);
}
.metric-help strong {
  display: block;
  color: var(--ink);
  margin-bottom: 4px;
}
.metric-details summary {
  cursor: pointer;
  color: var(--ink);
  font-weight: 700;
}
.metric-details:not([open]) {
  padding: 8px 10px;
}
.metric-help p { margin: 2px 0; }
.metric-help dl {
  display: grid;
  gap: 4px 10px;
  grid-template-columns: minmax(150px, 0.35fr) minmax(0, 1fr);
  margin: 8px 0 12px;
}
.metric-help dt {
  color: var(--ink);
  font-weight: 700;
}
.metric-help dd {
  margin: 0;
}
.team {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
.team h3 {
  margin: 0 0 8px;
  font-size: 15px;
}
.team ul { margin: 0; padding-left: 18px; }
.balance-note {
  margin: 0 0 12px;
  color: var(--muted);
}
.societies-panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.societies-panel summary, .rating-calibrator-panel summary {
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 700;
}
.societies-list {
  display: grid;
  gap: 0;
  max-height: 360px;
  overflow: auto;
  border-top: 1px solid #edf0f5;
}
.society-head, .society-row {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) 46px 70px 86px 82px minmax(130px, 0.8fr);
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid #edf0f5;
}
.society-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #fbfcfe;
}
.society-row small {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.empty-note {
  padding: 10px 12px;
  color: var(--muted);
}
.rating-calibrator-panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.calibrator-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid #edf0f5;
}
.calibrator-controls label {
  min-width: 0;
}
.rating-calibrator {
  padding: 0 12px 12px;
}
.calibrator-note {
  display: grid;
  gap: 3px;
  margin-bottom: 10px;
  padding: 8px 10px;
  border: 1px solid #d9e4f2;
  border-radius: 6px;
  background: #f5f9fd;
  color: var(--muted);
}
.calibrator-note strong {
  color: var(--ink);
}
.rating-calibrator table {
  width: 100%;
}
.rating-calibrator small {
  display: block;
  color: var(--muted);
}
.calibrator-formulas {
  display: grid;
  gap: 5px;
  margin-top: 10px;
}
.calibrator-formulas code {
  padding: 6px 8px;
  border: 1px solid #edf0f5;
  border-radius: 6px;
  background: #fbfcfe;
  white-space: normal;
}

.rating-lab {
  display: grid;
  gap: 16px;
}
.lab-decision {
  padding: 20px;
  border: 1px solid #e5c98f;
  border-left: 5px solid #c88a16;
  border-radius: 10px;
  background: #fffaf0;
  box-shadow: var(--shadow);
}
.lab-decision.consistent {
  border-color: #b9ddc6;
  border-left-color: var(--green);
  background: #f1f9f4;
}
.lab-decision h2 {
  margin: 4px 0 8px;
}
.lab-decision > p {
  margin: 0 0 12px;
}
.lab-decision-kicker {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.lab-decision-progress {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin: 14px 0 10px;
}
.lab-decision-progress div {
  padding: 10px 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.65);
}
.lab-decision-progress strong,
.lab-decision-progress span {
  display: block;
}
.lab-decision-progress span {
  color: var(--muted);
  font-size: 0.84rem;
}
.rating-lab-metrics {
  margin-bottom: 0;
}
.rating-lab-section {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.rating-lab-section h2 {
  margin-bottom: 10px;
}
.lab-details > summary,
.evidence-details > summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}
.lab-details > summary span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: normal;
}
.lab-details[open] > summary,
.evidence-details[open] > summary {
  margin-bottom: 14px;
}
.lab-details .rating-lab-section {
  margin-top: 12px;
  box-shadow: none;
}
.evidence-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
  margin: 12px 0;
}
.evidence-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}
.evidence-card > span,
.evidence-card > strong {
  display: block;
}
.evidence-card > span {
  color: var(--muted);
  font-size: 0.84rem;
}
.evidence-card h3 {
  margin: 5px 0;
}
.evidence-card p {
  margin: 0 0 9px;
  color: var(--muted);
}
.evidence-card > strong {
  font-size: 0.86rem;
}
.evidence-details {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.learning-curve {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.learning-curve div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
}
.learning-curve strong,
.learning-curve span {
  display: block;
}
.learning-curve span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}
.rating-lab-table td.lab-best {
  background: #e9f5ee;
  color: var(--green);
  font-weight: 700;
}
.rating-lab-table td.lab-worst {
  background: #faeeee;
  color: var(--red);
  font-weight: 700;
}
.rating-lab-table td.lab-mid {
  background: #fbfcfe;
}
.rating-lab-scroll {
  max-height: 430px;
}
.rating-lab-bottom {
  align-items: start;
}
.rating-lab-notes {
  display: grid;
  gap: 8px;
  margin: 0 0 12px;
  padding-left: 18px;
}
.exclusion-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.ts-tuning-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 10px 0;
}
.ts-tuning-grid label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.88rem;
}
.ts-tuning-grid input,
.lab-actions select {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}
.lab-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.lab-callout {
  margin: 8px 0 12px;
  padding: 10px 12px;
  border: 1px solid #f0dfc8;
  border-radius: 8px;
  background: #fff8ed;
  color: #77501c;
}
.lab-callout.good {
  border-color: #cfe8d8;
  background: #eef8f1;
  color: var(--green);
}
.trueskill-suggestion {
  margin-top: 10px;
}
.team-card small {
  color: var(--muted);
}
.metric-guide {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.metric-guide div {
  padding: 12px;
  border: 1px solid #edf0f5;
  border-radius: 8px;
  background: #fbfcfe;
}
.metric-guide strong {
  display: block;
  margin-bottom: 4px;
}
.metric-guide span {
  display: inline-block;
  margin-bottom: 6px;
  color: var(--blue);
  font-size: 0.84rem;
  font-weight: 700;
}
.metric-guide p {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  min-width: 220px;
  max-width: 420px;
  padding: 11px 12px;
  border-radius: 8px;
  background: #18202b;
  color: #fff;
  opacity: 0;
  transform: translateY(8px);
  transition: 150ms ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .grid.two, .split { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .toolbar, .toolbar-left, .inline-form { flex-direction: column; align-items: stretch; }
  .merge-form, .balance-columns { grid-template-columns: 1fr; }
  .calibrator-controls { grid-template-columns: 1fr; }
  .match-teams, .team-edit-grid { grid-template-columns: 1fr; }
  .slot-row { grid-template-columns: minmax(0, 1fr) 42px; }
  .slot-row > button { grid-column: 2; }
  .slot-review { grid-column: 1 / -1; }
  .tabs { overflow-x: auto; }
}

@media (max-width: 700px) {
  body { font-size: 13px; }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 12px 14px 10px;
  }
  h1 { font-size: 20px; }
  h2 { font-size: 15px; }
  main { padding: 12px 12px 24px; }
  .tabs {
    position: sticky;
    top: 69px;
    z-index: 19;
    gap: 2px;
    padding: 0 10px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    flex: 0 0 auto;
    min-height: 42px;
    padding: 0 10px;
    white-space: nowrap;
  }
  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .metric { padding: 10px; }
  .metric strong { font-size: 20px; }
  .next-match-card {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .toolbar, .toolbar-left, .inline-form {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }
  .toolbar input, .toolbar select, .inline-form input, .inline-form select, .inline-form button {
    min-width: 0;
    width: 100%;
  }
  .grid.two > section, .split > div, .match-form, .detail, .rating-lab-section, .suggestion-card {
    padding: 10px;
    border-radius: 8px;
  }
  .split { gap: 12px; }
  .table-wrap {
    margin-inline: -10px;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }
  th, td {
    padding: 8px 9px;
    font-size: 12px;
  }
  .detail-head {
    display: grid;
    grid-template-columns: 1fr;
  }
  .detail-head > div:last-child {
    justify-content: stretch;
  }
  .detail-head button { flex: 1 1 auto; }
  .detail-list, .team-level, .debug-grid, .debug-teams, .teams, .metric-help dl {
    grid-template-columns: 1fr;
  }
  .match-team h3, .team-editor h3, .suggestion-head {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
  }
  .suggestion-head button { width: 100%; }
  .balance-columns { gap: 10px; }
  .check-list { max-height: none; }
  .check-item {
    align-items: flex-start;
    padding: 10px;
  }
  .merge-form {
    padding: 10px;
  }
  .merge-form > span { display: none; }
  .player-status-form, .select-with-action, .slot-row {
    grid-template-columns: 1fr;
  }
  .slot-row > button {
    grid-column: auto;
    width: 100%;
  }
  .import-actions, .lab-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
  .society-head { display: none; }
  .society-row {
    grid-template-columns: 1fr 54px;
    gap: 4px 10px;
  }
  .society-row strong { grid-column: 1 / -1; }
  .society-row small { grid-column: 1 / -1; white-space: normal; }
  .toast {
    right: 12px;
    bottom: 12px;
    left: 12px;
    max-width: none;
    min-width: 0;
  }
}

@media (max-width: 430px) {
  .metrics { grid-template-columns: 1fr; }
  .form-grid, .edit-match .form-grid, .calibrator-controls { grid-template-columns: 1fr; }
  .login-panel { padding: 12px; }
  .login-card { padding: 14px; }
  button, input, select { min-height: 40px; }
}

@media (max-width: 700px) {
  #players table th:nth-child(4), #players table td:nth-child(4),
  #players table th:nth-child(5), #players table td:nth-child(5),
  #players table th:nth-child(6), #players table td:nth-child(6),
  #players table th:nth-child(7), #players table td:nth-child(7),
  #players table th:nth-child(12), #players table td:nth-child(12) {
    display: none;
  }
  #matches table th:nth-child(1), #matches table td:nth-child(1) {
    max-width: 92px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #dashboard .grid.two table th:nth-child(5), #dashboard .grid.two table td:nth-child(5) {
    display: none;
  }
  .players-split .detail,
  #matchDetail {
    scroll-margin-top: 126px;
  }
}

.mobile-back-btn {
  display: none;
}

@media (max-width: 700px) {
  .mobile-back-btn {
    display: block;
    width: 100%;
    margin: 0 0 10px;
    border-color: #c7d5e8;
    background: #f7faff;
    color: var(--blue);
    font-weight: 700;
  }
  #matches.mobile-detail-open > .toolbar,
  #matches.mobile-detail-open > .split > .table-wrap,
  #players.mobile-detail-open > .toolbar,
  #players.mobile-detail-open > .merge-form,
  #players.mobile-detail-open > .merge-status,
  #players.mobile-detail-open > .players-split > .table-wrap {
    display: none;
  }
  #matches.mobile-detail-open > .split,
  #players.mobile-detail-open > .players-split {
    display: block;
  }
  #matches.mobile-detail-open #matchDetail,
  #players.mobile-detail-open #playerDetail {
    display: block;
    min-height: calc(100vh - 126px);
  }
  #balance .split {
    display: flex;
    flex-direction: column;
  }
  #balance .split > div:nth-child(2) {
    order: -1;
  }
  #balance .split > div:nth-child(1),
  #balance .split > div:nth-child(2) {
    box-shadow: none;
  }
  #balance .toolbar {
    position: sticky;
    top: 111px;
    z-index: 10;
    padding: 8px;
    margin: -4px -4px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
  }
  #balance .balance-columns {
    grid-template-columns: 1fr;
  }
  #balance .check-list {
    max-height: 320px;
    overflow: auto;
  }
  #balance .selected-summary {
    position: sticky;
    top: 183px;
    z-index: 9;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
  }
  #balance .metric-help {
    display: none;
  }
  #balance .suggestion-list {
    gap: 10px;
  }
  #balance .team ul {
    padding-left: 16px;
  }
}

.mobile-player-actions {
  display: none;
}

@media (max-width: 700px) {
  #players.panel:not(.active) {
    display: none;
  }
  #players.panel.active {
    display: flex;
    flex-direction: column;
  }
  #players > .toolbar { order: 1; }
  #mobilePlayerActions { order: 2; }
  #players > #addPlayerForm,
  #players > .merge-form,
  #players > .merge-status { order: 3; }
  #players > .players-split { order: 4; }
  #players > .toolbar {
    gap: 8px;
    margin-bottom: 8px;
  }
  #players .toolbar-left {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }
  #players .toolbar-check {
    display: flex;
    justify-content: flex-start;
    gap: 8px;
    min-height: 30px;
    white-space: normal;
  }
  #players .toolbar-check input {
    width: auto;
    min-width: 18px;
    min-height: 18px;
  }
  #addPlayerForm,
  #mergePlayersForm {
    display: none;
  }
  #addPlayerForm.mobile-open,
  #mergePlayersForm.mobile-open {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin: 0 0 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
  }
  .mobile-player-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 0 0 10px;
  }
  .mobile-player-actions button {
    min-height: 38px;
    background: var(--panel);
  }
  .mobile-player-actions button.active {
    border-color: var(--blue);
    color: var(--blue);
    font-weight: 700;
    background: #eef6ff;
  }
  #players.mobile-detail-open > #mobilePlayerActions,
  #players.mobile-detail-open > #addPlayerForm,
  #players.mobile-detail-open > .merge-form {
    display: none;
  }
}

@media (max-width: 700px) {
  main > .panel:not(.active) {
    display: none !important;
  }
  #matches .table-wrap,
  #players .table-wrap,
  #dashboard .table-wrap {
    margin-inline: 0;
    border: 0;
    background: transparent;
    overflow: visible;
  }
  #matches table,
  #players table,
  #dashboard .grid.two table,
  #matches tbody,
  #players tbody,
  #dashboard .grid.two tbody {
    display: block;
  }
  #matches thead,
  #players thead,
  #dashboard .grid.two thead {
    display: none;
  }
  #matches tr.clickable,
  #players tr.clickable,
  #dashboard .grid.two tr.clickable {
    display: grid;
    gap: 6px;
    margin-bottom: 8px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
  }
  #matches tr.clickable td,
  #players tr.clickable td,
  #dashboard .grid.two tr.clickable td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0;
    border: 0;
    white-space: normal;
    text-align: right;
  }
  #matches tr.clickable td::before,
  #players tr.clickable td::before,
  #dashboard .grid.two tr.clickable td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    text-align: left;
  }
  #matches tr.clickable td:first-child,
  #players tr.clickable td:first-child,
  #dashboard .grid.two tr.clickable td:first-child {
    justify-content: flex-start;
    font-weight: 700;
    font-size: 14px;
  }
  #matches tr.clickable td:first-child::before,
  #players tr.clickable td:first-child::before,
  #dashboard .grid.two tr.clickable td:first-child::before {
    display: none;
  }
  #matches tr.clickable td:nth-child(4),
  #dashboard .grid.two tr.clickable td:nth-child(3),
  #players tr.clickable td:nth-child(4),
  #players tr.clickable td:nth-child(5),
  #players tr.clickable td:nth-child(6),
  #players tr.clickable td:nth-child(7),
  #players tr.clickable td:nth-child(12) {
    display: none;
  }
  #players tr.clickable {
    grid-template-columns: 1fr auto auto auto;
    align-items: center;
  }
  #players tr.clickable td {
    display: block;
  }
  #players tr.clickable td::before { display: none; }
  #players tr.clickable td:nth-child(1) { grid-column: 1; }
  #players tr.clickable td:nth-child(2) { grid-column: 2; }
  #players tr.clickable td:nth-child(3) { grid-column: 3; font-weight: 700; }
  #players tr.clickable td:nth-child(8) { grid-column: 4; color: var(--muted); }
  #players tr.clickable td:nth-child(9),
  #players tr.clickable td:nth-child(10),
  #players tr.clickable td:nth-child(11) {
    grid-row: 2;
    justify-self: start;
    color: var(--muted);
    font-size: 12px;
  }
  #players tr.clickable td:nth-child(9)::before { content: "G "; display: inline; }
  #players tr.clickable td:nth-child(10)::before { content: "E "; display: inline; }
  #players tr.clickable td:nth-child(11)::before { content: "P "; display: inline; }

  .slot-row {
    grid-template-columns: minmax(0, 1fr) 38px;
    gap: 8px;
  }
  .slot-row .slot-player {
    grid-column: 1;
  }
  .slot-row .remove-slot-btn {
    grid-column: 2;
    width: 38px;
    min-height: 38px;
    padding: 0;
    font-weight: 700;
    color: var(--red);
  }
  .slot-review {
    grid-column: 1 / -1;
  }

  #balance .check-item {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
  }
  #balance .check-item input {
    justify-self: center;
    width: 18px;
    height: 18px;
  }
  #balance .check-item span {
    display: grid;
    gap: 2px;
    min-width: 0;
  }
  #balance .check-item small {
    color: var(--muted);
  }
  #balance .balance-columns h3 {
    margin: 6px 0;
  }
  #balance .selected-summary {
    max-height: 92px;
    overflow: auto;
  }
}


@media (max-width: 700px) {
  #dashboard .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  #dashboard .metric {
    min-height: 58px;
    padding: 9px 10px;
    display: grid;
    align-content: center;
  }
  #dashboard .metric span {
    font-size: 12px;
  }
  #dashboard .metric strong {
    font-size: 20px;
    line-height: 1.05;
  }
  #dashboard .next-match-panel {
    margin-bottom: 10px;
  }
  #dashboard .next-match-card {
    padding: 10px 12px;
  }
  #dashboard .grid.two {
    gap: 10px;
  }
  #dashboard .grid.two > section {
    padding: 10px;
  }

  #players tr.clickable {
    grid-template-columns: minmax(0, 1fr) auto auto auto;
    gap: 4px 8px;
    padding: 9px 10px;
  }
  #players tr.clickable td {
    text-align: left;
  }
  #players tr.clickable td:nth-child(1) {
    justify-self: start;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #players tr.clickable td:nth-child(2),
  #players tr.clickable td:nth-child(3),
  #players tr.clickable td:nth-child(8) {
    justify-self: end;
    white-space: nowrap;
  }
  #players tr.clickable td:nth-child(9),
  #players tr.clickable td:nth-child(10),
  #players tr.clickable td:nth-child(11) {
    justify-self: start;
  }

  #newMatch .match-form {
    gap: 10px;
    padding: 10px;
  }
  #newMatch .form-grid {
    gap: 9px;
  }
  #newMatch .player-slots {
    gap: 7px;
  }
  #newMatch .slot-row select,
  #newMatch .slot-row .remove-slot-btn {
    min-height: 36px;
  }
  #newMatch h2 {
    margin-bottom: 8px;
  }

  #balance .rating-calibrator-panel {
    display: none !important;
  }
}

@media (max-width: 430px) {
  #dashboard .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  #players .table-wrap {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    overflow-x: auto;
    box-shadow: var(--shadow);
  }
  #players table {
    display: table;
    width: 100%;
    min-width: 360px;
    border-collapse: collapse;
    table-layout: fixed;
  }
  #players thead {
    display: table-header-group;
    position: sticky;
    top: 0;
    z-index: 1;
    background: #fafbfc;
  }
  #players tbody {
    display: table-row-group;
  }
  #players tr.clickable {
    display: table-row;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }
  #players th,
  #players tr.clickable td {
    display: table-cell;
    padding: 8px 6px;
    border-bottom: 1px solid #edf0f5;
    font-size: 11px;
    line-height: 1.2;
    text-align: right;
    vertical-align: middle;
    white-space: nowrap;
  }
  #players th:first-child,
  #players tr.clickable td:first-child {
    width: 31%;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #players th:nth-child(2),
  #players tr.clickable td:nth-child(2) {
    width: 18%;
    text-align: left;
  }
  #players th:nth-child(3),
  #players tr.clickable td:nth-child(3) {
    width: 15%;
    font-weight: 700;
  }
  #players th:nth-child(8),
  #players tr.clickable td:nth-child(8) {
    width: 10%;
    color: var(--ink);
  }
  #players th:nth-child(9),
  #players th:nth-child(10),
  #players th:nth-child(11),
  #players tr.clickable td:nth-child(9),
  #players tr.clickable td:nth-child(10),
  #players tr.clickable td:nth-child(11) {
    width: 7%;
    color: var(--ink);
  }
  #players tr.clickable td::before {
    display: none !important;
    content: none;
  }
  #players tr.clickable td:nth-child(4),
  #players tr.clickable td:nth-child(5),
  #players tr.clickable td:nth-child(6),
  #players tr.clickable td:nth-child(7),
  #players tr.clickable td:nth-child(12),
  #players th:nth-child(4),
  #players th:nth-child(5),
  #players th:nth-child(6),
  #players th:nth-child(7),
  #players th:nth-child(12) {
    display: none;
  }
  #players .tag {
    padding: 2px 6px;
    font-size: 11px;
  }
}



@media (max-width: 700px) {
  .topbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 10px;
  }
  .topbar > div:first-child {
    min-width: 0;
  }
  .session-user {
    margin-top: 5px;
  }
  .topbar-actions button {
    width: auto;
    min-width: max-content;
    padding-inline: 12px;
  }
}