:root {
  --bg: #f7faf6;
  --panel: #ffffff;
  --ink: #17221b;
  --muted: #667468;
  --line: #cfd8ce;
  --line-dark: #8d9b91;
  --accent: #2563eb;
  --danger: #dc2626;
  --ok: #16a34a;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

[hidden] {
  display: none !important;
}

body:not(.is-authenticated) .judge-app {
  display: none !important;
}

body.is-authenticated .login-screen {
  display: none !important;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 9px 14px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 850;
  cursor: pointer;
}

button.secondary {
  background: var(--panel);
  color: var(--accent);
}

button.danger {
  border-color: var(--danger);
  background: var(--danger);
}

button:active {
  transform: translateY(1px);
}

.app-shell {
  min-height: 100vh;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(23, 34, 27, 0.12);
}

.brand-logo {
  display: block;
  width: 76px;
  height: 70px;
  object-fit: contain;
  margin-bottom: 18px;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.login-card p {
  margin: 0 0 22px;
  color: var(--muted);
}

.login-card label {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-weight: 800;
}

.login-card input,
.dialog-card textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 12px;
  color: var(--ink);
  background: var(--panel);
}

.login-card button {
  width: 100%;
  margin-top: 14px;
}

#loginError {
  display: block;
  min-height: 18px;
  margin-top: 10px;
  color: var(--danger);
  font-weight: 800;
}

.judge-app {
  min-height: 100vh;
  padding: 14px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin: -14px -14px 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 250, 246, 0.94);
  backdrop-filter: blur(14px);
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: clamp(20px, 2.5vw, 30px);
}

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

.status-pill {
  min-width: 128px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 850;
}

.status-pill.is-saving {
  border-color: #f59e0b;
  color: #b45309;
}

.status-pill.is-saved {
  border-color: var(--ok);
  color: var(--ok);
}

.meta-panel {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.meta-item {
  min-width: 0;
}

.meta-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.meta-item strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 17px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid #000000;
  border-radius: 8px;
  background: var(--panel);
}

.judge-table {
  width: 100%;
  min-width: 1120px;
  border-collapse: separate;
  border-spacing: 0;
}

.judge-table th,
.judge-table td {
  border-right: 1px solid #000000;
  border-bottom: 1px solid #000000;
  padding: 0;
}

.judge-table th:last-child,
.judge-table td:last-child {
  border-right: 0;
}

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

.judge-table th {
  position: sticky;
  top: 0;
  z-index: 4;
  padding: 8px 6px;
  background: #f3f4f6;
  color: #000000;
  font-size: 13px;
  font-weight: 900;
  text-align: center;
}

.seq-cell {
  width: 54px;
  text-align: center;
  font-size: 18px;
  font-weight: 900;
}

.identity-cell {
  width: 310px;
  padding: 6px 8px !important;
}

.identity-cell .rider,
.identity-cell .horse {
  font-weight: 950;
}

.identity-cell .club {
  margin-top: 2px;
  color: #000000;
  font-size: 13px;
}

.obstacle-cell {
  width: 58px;
}

.score-cell,
.time-cell,
.status-cell {
  width: 96px;
}

.total-cell {
  width: 82px;
  text-align: center;
  font-size: 20px;
  font-weight: 950;
}

.computed-cell {
  background: #f8faf7;
}

.judge-input,
.judge-select {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 0;
  padding: 8px 7px;
  background: #ffffff;
  color: #000000;
  text-align: center;
  font-weight: 850;
}

.time-input {
  font-size: 18px;
}

.judge-input:focus,
.judge-select:focus {
  outline: 3px solid rgba(37, 99, 235, 0.25);
  outline-offset: -3px;
}

.judge-row.is-complete {
  background: #fbfffb;
}

.judge-row.status-withdrawn {
  background: rgba(249, 115, 22, 0.14);
  box-shadow: inset 4px 0 0 #f97316;
}

.judge-row.status-dns {
  background: rgba(220, 38, 38, 0.13);
  box-shadow: inset 4px 0 0 #dc2626;
}

.judge-row.status-eliminated {
  background: rgba(124, 58, 237, 0.13);
  box-shadow: inset 4px 0 0 #7c3aed;
}

.judge-row.status-withdrawn .judge-input,
.judge-row.status-withdrawn .judge-select,
.judge-row.status-withdrawn .computed-cell {
  background: rgba(249, 115, 22, 0.05);
}

.judge-row.status-dns .judge-input,
.judge-row.status-dns .judge-select,
.judge-row.status-dns .computed-cell {
  background: rgba(220, 38, 38, 0.05);
}

.judge-row.status-eliminated .judge-input,
.judge-row.status-eliminated .judge-select,
.judge-row.status-eliminated .computed-cell {
  background: rgba(124, 58, 237, 0.05);
}

dialog {
  border: 0;
  padding: 0;
  border-radius: 14px;
  box-shadow: 0 24px 80px rgba(23, 34, 27, 0.24);
}

dialog::backdrop {
  background: rgba(23, 34, 27, 0.46);
}

.dialog-card {
  width: min(760px, calc(100vw - 40px));
  padding: 22px;
  background: var(--panel);
}

.dialog-card h2 {
  margin: 0 0 8px;
}

.dialog-card p {
  margin: 0 0 12px;
  color: var(--muted);
}

.dialog-card textarea {
  min-height: 280px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

@media (max-width: 860px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    display: flex;
  }

  .topbar-actions {
    flex-wrap: wrap;
  }

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