:root {
  --bg: #f5f7f9;
  --surface: #ffffff;
  --ink: #172b24;
  --muted: #66756f;
  --line: #dde5e1;
  --accent: #157a5b;
  --accent-hover: #106348;
  --accent-soft: #eaf5f0;
  --warn-bg: #fff7e6;
  --warn-text: #8a5a00;
  --error-bg: #fff0f0;
  --error-text: #b42318;
  --ok-bg: #eaf7f0;
  --ok-text: #137a50;
  --shadow: 0 4px 16px rgba(23, 43, 36, 0.06);
  --shadow-sticky: 0 6px 18px rgba(23, 43, 36, 0.08);
  --radius: 12px;
  --font: "Segoe UI", "Candara", "Calibri", sans-serif;
  --control-h: 40px;
  --focus: 0 0 0 3px rgba(21, 122, 91, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}

.page {
  width: 90%;
  max-width: none;
  margin: 0 auto;
  padding: 1.25rem 0 2.5rem;
}

.hidden {
  display: none !important;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.topbar h1 {
  margin: 0 0 0.25rem;
  font-size: clamp(1.35rem, 2vw, 1.75rem);
  letter-spacing: -0.02em;
}

.lead {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.workflow {
  margin-bottom: 1rem;
  overflow-x: auto;
}

.workflow-list {
  list-style: none;
  margin: 0;
  padding: 0.65rem 0.85rem;
  display: flex;
  gap: 0.5rem;
  min-width: max-content;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.workflow-step {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.step-index {
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  background: #eef2f0;
  color: var(--muted);
}

.step-pending {
  opacity: 0.7;
}

.step-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.step-active .step-index {
  background: var(--accent);
  color: #fff;
}

.step-complete {
  color: var(--ok-text);
}

.step-complete .step-index {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.step-complete .step-index::before {
  content: "✓";
  font-size: 0.7rem;
}

.step-complete .step-index {
  font-size: 0;
}

.step-error {
  background: var(--error-bg);
  color: var(--error-text);
}

.step-error .step-index {
  background: var(--error-text);
  color: #fff;
}

.upload-section {
  margin-bottom: 1rem;
  border: 2px dashed #b7c9c0;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.upload-section.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.upload-section.is-compact {
  border-style: solid;
  border-width: 1px;
}

.upload-inner {
  padding: 2rem 1.25rem;
  text-align: center;
}

.upload-icon {
  margin-bottom: 0.75rem;
}

.upload-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.upload-hint,
.file-count {
  color: var(--muted);
}

.upload-hint {
  margin: 0.4rem 0 1rem;
}

.file-count {
  margin: 0.85rem 0 0;
}

.upload-compact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  font-weight: 600;
}

.actions-panel {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sticky);
  padding: 0.55rem 0.85rem;
  margin-bottom: 1rem;
}

.actions-panel.is-compact {
  padding: 0.35rem 0.75rem;
}

.actions-panel.is-compact .btn {
  min-height: 36px;
  padding: 0.4rem 0.85rem;
}

.actions-panel.is-compact .actions-status {
  display: none;
}

.progress-panel.is-done {
  margin-top: 0.2rem;
  padding-top: 0.2rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.65rem;
}

.progress-panel.is-done .progress-track {
  display: none;
}

.progress-panel.is-done .progress-meta,
.progress-panel.is-done .progress-details {
  display: contents;
  font-size: 0.8rem;
}

.progress-panel.is-done #progressPercent {
  font-weight: 700;
  color: var(--ok-text);
}

.actions-buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}

.export-file-hint {
  color: var(--muted);
  font-size: 0.82rem;
  max-width: min(280px, 100%);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.actions-status {
  margin-top: 0.35rem;
  min-height: 0;
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress-panel {
  margin-top: 0.55rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--line);
}

.progress-panel.is-done {
  margin-top: 0.25rem;
  padding-top: 0.25rem;
}

.progress-panel.is-done .progress-track {
  display: none;
}

.progress-panel.is-done .progress-meta,
.progress-panel.is-done .progress-details {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  font-size: 0.82rem;
  margin: 0;
}

.progress-panel.is-done .progress-percent-done {
  font-weight: 700;
  color: var(--ok-text);
}

.progress-meta,
.progress-details {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-size: 0.9rem;
  color: var(--muted);
}

.progress-track {
  margin: 0.45rem 0;
  height: 8px;
  border-radius: 999px;
  background: #eef2f0;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.progress-panel.is-indeterminate .progress-fill {
  width: 40%;
  transition: none;
  animation: progress-indeterminate 1.2s ease-in-out infinite;
}

@keyframes progress-indeterminate {
  0% {
    transform: translateX(-120%);
  }
  100% {
    transform: translateX(280%);
  }
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 10px;
  min-height: var(--control-h);
  padding: 0.55rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  border-color: #c5d2cc;
  background: #fafcfb;
}

.btn:focus-visible,
.tab-btn:focus-visible,
.chip:focus-visible,
.cell-input:focus-visible,
.filter-input:focus-visible,
.filter-select:focus-visible,
.rttf-open-btn:focus-visible,
.link-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: var(--accent-soft);
  border-color: #b7d4c7;
  color: var(--accent);
}

.btn-secondary:hover:not(:disabled) {
  background: #dff0e8;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: transparent;
}

.btn-fresh-ratings {
  border-color: #d5e4dc;
  color: #4d6b5c;
  font-weight: 500;
}

.btn-fresh-ratings:hover:not(:disabled) {
  background: #f3f8f5;
  border-color: #c5d8cc;
  color: var(--accent);
}

.btn-primary-next {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.results {
  margin-top: 0.25rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
}

.stat-card .label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.2rem;
}

.stat-card .value {
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.15;
}

.stat-card.is-attention .value {
  color: var(--warn-text);
}

.stat-card.is-attention {
  background: var(--warn-bg);
  border-color: #f0dfb4;
}

.stats-secondary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: #eef2f0;
  color: var(--muted);
  font-size: 0.82rem;
  border: 1px solid transparent;
}

.meta-chip strong {
  color: var(--ink);
  font-weight: 700;
}

.meta-chip.is-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-color: #f0dfb4;
}

.meta-chip.is-error {
  background: var(--error-bg);
  color: var(--error-text);
  border-color: #f0c7c7;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
}

.tab-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  min-height: 38px;
  padding: 0.4rem 0.95rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.is-active,
.tab-btn[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.section-title {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.empty-hint {
  color: var(--muted);
  padding: 1rem;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.filter-input,
.filter-select {
  min-height: var(--control-h);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.45rem 0.7rem;
  font: inherit;
  background: var(--surface);
  color: var(--ink);
}

.filter-input {
  min-width: min(280px, 100%);
  flex: 1 1 220px;
}

.filter-select {
  min-width: 180px;
}

.filter-check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--ink);
  font-size: 0.92rem;
}

.filter-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.9rem;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  min-height: 34px;
  padding: 0.3rem 0.75rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.chip.is-active {
  background: var(--accent-soft);
  border-color: #b7d4c7;
  color: var(--accent);
}

.table-wrap {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.table-wrap-players {
  max-height: 62vh;
  min-height: 55vh;
}

.table-wrap-teams {
  max-height: 70vh;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 0.45rem 0.55rem;
  text-align: left;
  vertical-align: middle;
  background: var(--surface);
}

th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #f3f6f4;
  font-size: 0.84rem;
  white-space: nowrap;
  color: var(--muted);
  font-weight: 700;
}

.col-num {
  text-align: right;
}

td.col-num {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

#playersTable th.col-center,
#playersTable td.col-center,
#playersTable th.col-num,
#playersTable td.col-num {
  text-align: center;
}

#playersTable td.col-center .cell-input,
#playersTable td.col-num .cell-input {
  text-align: center;
}

.place-cell {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
}

.rating-cell {
  font-size: 1.05rem;
  font-weight: 700;
}

.sticky-col {
  position: sticky;
  z-index: 2;
}

th.sticky-col {
  z-index: 6;
}

.sticky-col-1 {
  left: 0;
  min-width: 14rem;
  width: 14rem;
  max-width: 14rem;
}

.sticky-col-2 {
  left: 14rem;
  min-width: 19rem;
  width: 19rem;
  max-width: 19rem;
  box-shadow: 1px 0 0 var(--line);
}

tbody tr:nth-child(even) td {
  background: #fafcfb;
}

tbody tr:hover td {
  background: #f3f8f5;
}

tbody tr.row-problem td {
  background: #fffdf8;
}

tbody tr.row-problem td:first-child {
  box-shadow: inset 3px 0 0 #e2b84a;
}

tbody tr.row-error td {
  background: #fffafa;
}

tbody tr.row-error td:first-child {
  box-shadow: inset 3px 0 0 #d96b63;
}

.cell-input {
  width: 100%;
  min-width: 7rem;
  border: 1px solid transparent;
  background: transparent;
  font: inherit;
  color: inherit;
  padding: 0.3rem 0.35rem;
  border-radius: 6px;
  min-height: 34px;
}

.cell-input:hover {
  border-color: #c9d6d0;
}

.cell-input:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: var(--focus);
}

.rttf-cell {
  min-width: 14rem;
}

.rttf-field {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
  min-width: 0;
}

.rttf-field .cell-input {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
}

.rttf-open-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf8;
  color: var(--accent);
  cursor: pointer;
}

.rttf-open-btn svg {
  width: 1rem;
  height: 1rem;
  fill: currentColor;
}

.rttf-open-btn:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: #b7d4c7;
}

.rttf-open-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  color: var(--muted);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
}

.status-badge.success {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.status-badge.warning {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.status-badge.error {
  background: var(--error-bg);
  color: var(--error-text);
}

.status-badge.neutral {
  background: #eef2f0;
  color: var(--muted);
}

.status-badge.info {
  background: #e8f1fb;
  color: #1d5bbf;
}

.calc-players {
  margin: 0;
  padding-left: 1rem;
  font-size: 0.86rem;
  line-height: 1.35;
  color: var(--ink);
}

.calc-players li {
  margin: 0;
}

.calc-toggle {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 0;
  margin-top: 0.15rem;
}

.calc-details {
  margin-top: 0.25rem;
  padding: 0.35rem 0.45rem;
  border-radius: 8px;
  background: #f4f8f6;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: pre-wrap;
}

.team-name {
  font-weight: 600;
}

#teamsTable td:last-child {
  min-width: 10.5rem;
  white-space: nowrap;
}

#teamsTable th,
#teamsTable td {
  padding-top: 0.35rem;
  padding-bottom: 0.35rem;
}

.problems-list {
  display: grid;
  gap: 0.65rem;
}

.problem-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.35rem;
}

.problem-card.is-error {
  border-left: 3px solid #d96b63;
}

.problem-card.is-warning {
  border-left: 3px solid #e2b84a;
}

.problem-top {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
}

.problem-meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.problem-action {
  font-weight: 600;
  color: var(--ink);
}

.problem-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.problem-link:hover {
  text-decoration: underline;
}

.link-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

@media (max-width: 1200px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 800px) {
  .page {
    width: 96%;
  }

  .topbar {
    flex-direction: column;
  }

  .stats {
    grid-template-columns: 1fr 1fr;
  }

  .actions-buttons .btn {
    flex: 1 1 100%;
  }

  .filter-count {
    margin-left: 0;
    width: 100%;
  }

  .sticky-col-1,
  .sticky-col-2 {
    position: static;
    box-shadow: none;
    left: auto;
  }

  .table-wrap-players {
    min-height: 50vh;
  }
}

@media (max-width: 520px) {
  .stats {
    grid-template-columns: 1fr;
  }
}
