/*
 * Application styles.
 * Layout: chukker tournament editing — teams + roster + schedule.
 */

:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-soft: #fbfaf7;
  --ink: #151515;
  --muted: #6a665f;
  --line: #ddd8cf;
  --accent: #176f62;
  --accent-strong: #0d4d45;
  --danger: #b91c1c;
  --play: #05a84f;
  --out: #e11d12;
  --radius: 8px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

a {
  color: var(--accent-strong);
  font-weight: 600;
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* ---------------- Header / shell ---------------- */

.app-header {
  align-items: center;
  background: #0e0e0e;
  color: #fff;
  display: flex;
  justify-content: space-between;
  padding: 14px 28px;
}
.app-header a { color: #fff; }
.app-header nav { display: flex; gap: 18px; }
.brand { font-size: 20px; font-weight: 700; letter-spacing: 0.5px; }

.app-shell {
  margin: 0 auto;
  max-width: 1280px;
  padding: 28px 24px 56px;
}

.page-title {
  align-items: flex-end;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  margin-bottom: 22px;
}
.page-title h1 { font-size: 30px; line-height: 1.1; margin: 4px 0 0; }

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin: 0;
  text-transform: uppercase;
}

.small { font-size: 12px; }
.muted { color: var(--muted); }

/* ---------------- Buttons & inputs ---------------- */

.button-row,
.inline-form,
.team-edit {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.button {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  font: inherit;
  font-weight: 600;
  min-height: 36px;
  padding: 7px 13px;
  text-decoration: none;
  transition: border-color 0.1s, background 0.1s;
}
.button:hover { border-color: #b9b3a8; text-decoration: none; }
.button-small { min-height: 28px; padding: 4px 9px; font-size: 13px; }
.button-large { min-height: 44px; padding: 11px 24px; font-size: 16px; }

.button-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.button-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }

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

.button-icon {
  font-size: 16px;
  line-height: 1;
  padding: 4px 8px;
}

.link-button,
.text-danger {
  background: none;
  border: 0;
  color: var(--danger);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  padding: 0;
}

input,
select,
textarea {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font: inherit;
  min-height: 36px;
  padding: 7px 10px;
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(23, 111, 98, 0.15);
}
textarea { resize: vertical; }

label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.compact-field {
  display: grid;
  gap: 4px;
}
.compact-field.grow { flex: 1; }
.compact-num-field { min-width: 72px; }

.compact-check {
  align-items: center;
  display: flex;
  gap: 6px;
}
.compact-check input { min-height: auto; width: auto; }

.input-num {
  min-height: 32px;
  padding: 4px 8px;
  text-align: center;
  width: 64px;
}

/* ---------------- Flashes & panels ---------------- */

.flash {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-weight: 600;
  margin: 0 0 18px;
  padding: 11px 14px;
}
.flash-notice { background: #eef7f1; border-color: #b7d8c7; }
.flash-alert  { background: #fff5f5; border-color: #e7aaa5; color: var(--danger); }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 22px;
  padding: 18px 20px;
}
.panel-empty { color: var(--muted); }
.panel-header {
  align-items: flex-start;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.panel-header h2 { font-size: 18px; margin: 0; }
.panel-header p { margin: 4px 0 0; }

/* ---------------- Forms (event new/edit) ---------------- */

.form-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.field { display: grid; gap: 6px; }
.field-wide,
.form-errors,
.form-actions { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; }

.form-errors {
  background: #fff5f5;
  border: 1px solid #e7aaa5;
  border-radius: var(--radius-sm);
  color: var(--danger);
  padding: 12px;
}

.field-hint {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
}

.advanced-settings {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}
.advanced-settings > summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  padding: 4px 0;
}
.advanced-settings > summary::-webkit-details-marker { display: none; }
.advanced-settings > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.15s ease;
}
.advanced-settings[open] > summary::before { transform: rotate(90deg); }
.advanced-settings-grid { margin-top: 12px; }

.nested-section-header {
  margin-bottom: 8px;
}
.nested-section-header h2 {
  font-size: 16px;
  margin: 0;
}
.nested-section-header p { margin: 2px 0 0; }

.horse-form-grid {
  display: grid;
  gap: 8px;
}
.horse-form-row {
  align-items: flex-end;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 12px;
}

/* ---------------- Tables (generic) ---------------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
}
.panel > .table-wrap { border: 0; border-radius: 0; padding: 0; }

table {
  border-collapse: collapse;
  width: 100%;
}
th, td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}
th { font-size: 13px; font-weight: 700; }
.actions { text-align: right; }

/* ---------------- Teams chip grid ---------------- */

.team-chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.team-chip {
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 4px 6px 4px 8px;
}
.team-chip input {
  min-height: 28px;
  padding: 3px 8px;
  font-size: 13px;
}
.team-chip .button { margin-left: 2px; }
.team-chip-form { display: contents; }
.team-chip-new { background: #fff; border-style: dashed; }

.team-chip-swatch {
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-block;
  height: 18px;
  width: 18px;
  flex-shrink: 0;
}
.team-chip-name { width: 110px; font-weight: 600; }
.team-chip-delete { display: inline-block; margin-left: 2px; }
.team-chip-delete button { font-size: 13px; }

.team-color-picker {
  position: relative;
}

.team-color-summary {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  font-size: 13px;
  font-weight: 600;
  gap: 6px;
  list-style: none;
  min-height: 28px;
  padding: 3px 10px 3px 6px;
}
.team-color-summary::-webkit-details-marker { display: none; }
.team-color-summary::after {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--muted);
  content: "";
  margin-left: 2px;
}

.team-color-options {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: 0 16px 32px rgba(21, 21, 21, 0.16);
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  left: 0;
  padding: 8px;
  position: absolute;
  top: calc(100% + 6px);
  width: 316px;
  z-index: 20;
}

.team-color-radio {
  opacity: 0;
  pointer-events: none;
  position: absolute;
}

.team-color-option {
  background: var(--team-color);
  border: 1px solid rgba(21, 21, 21, 0.18);
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  display: block;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  min-height: 34px;
  overflow: hidden;
  padding: 6px 7px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.team-color-option:hover {
  border-color: var(--ink);
  text-decoration: none;
}
.team-color-radio:checked + .team-color-option {
  box-shadow: inset 0 0 0 2px var(--ink);
}
.team-color-radio:focus-visible + .team-color-option {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------------- Roster ---------------- */

.roster-add {
  align-items: flex-end;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  padding: 10px 12px;
}
.roster-add .compact-field { min-width: 160px; }

.roster-form { display: contents; }

.roster-table {
  width: 100%;
}
.roster-table thead th {
  background: var(--surface-soft);
  font-size: 12px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.roster-table td { vertical-align: middle; }

.roster-table .col-player { min-width: 160px; }
.roster-table .col-player .roster-player-link { font-weight: 600; }
.roster-table .col-player .small { display: block; margin-top: 2px; }
.roster-table .col-horse { min-width: 180px; max-width: 260px; white-space: normal; }

.roster-table .col-hcp,
.roster-table .col-num { width: 80px; }
.roster-table .col-team { min-width: 130px; }

.team-select {
  min-height: 32px;
  padding: 3px 8px;
  font-weight: 600;
  border-radius: var(--radius-sm);
}
.team-select-auto {
  background: #fff;
  color: var(--muted);
  font-weight: 500;
  font-style: italic;
}

.inline-delete { display: inline; }
.inline-delete button { padding: 4px 8px; }

.roster-form-footer {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-top: 14px;
}

/* ---------------- Schedule ---------------- */

.schedule-scroll { overflow-x: auto; }

.schedule-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  min-width: 100%;
}
.schedule-table th,
.schedule-table td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 6px 8px;
}
.schedule-table thead th {
  background: var(--surface-soft);
  position: sticky;
  top: 0;
  z-index: 3;
}

.schedule-table th.sticky-col,
.schedule-table td.sticky-col {
  background: var(--surface);
  position: sticky;
  z-index: 2;
}
.schedule-table .player-col { left: 0; min-width: 160px; font-weight: 600; }
.schedule-table .hcp-col    { left: 160px; min-width: 56px; text-align: center; }
.schedule-table .total-col  { left: 216px; min-width: 48px; text-align: center; font-weight: 700; }

.schedule-table thead th.sticky-col { z-index: 4; }

.schedule-table th.cell-summary,
.schedule-table td.cell-status {
  min-width: 64px;
  text-align: center;
  font-weight: 700;
}

.cell-out, .cell-unavailable {
  color: var(--muted);
  background: var(--surface-soft);
}
.cell-play { font-weight: 800; }

.schedule-team-code,
.schedule-horse-name {
  display: block;
}
.schedule-horse-name {
  font-size: 10px;
  font-weight: 600;
  line-height: 1.1;
  max-width: 76px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.schedule-team-summary th {
  background: var(--surface-soft);
  font-size: 12px;
}
.schedule-team-summary .player-col { font-weight: 700; }

.schedule-fix-badge {
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-left: 6px;
  padding: 1px 6px;
  text-transform: uppercase;
}

/* ---------------- Details list ---------------- */

.details {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin: 0;
}
.details dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.details dd { margin: 0; }
.details-inline > div { min-width: 0; }

/* ---------------- Horse list (player edit/show, Hotwire) ---------------- */

.horse-list {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}
.horse-list-empty {
  background: var(--surface-soft);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
  margin: 0;
}

.horse-row {
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px 10px;
}
.horse-row-form {
  align-items: flex-end;
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0;
}
.horse-row-check { align-self: center; }
.horse-row-delete-form {
  display: inline-flex;
  margin: 0;
  align-self: center;
}
.horse-row-delete-form button { padding: 4px 8px; }

.horse-row-new {
  background: #fff;
  border-style: dashed;
}

/* ---------------- Add-player blocks on event show ---------------- */

.step-number {
  background: var(--accent);
  border-radius: 999px;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  height: 24px;
  margin-right: 6px;
  vertical-align: 2px;
  width: 24px;
}

.quick-add-form {
  align-items: flex-end;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
  padding: 12px 14px;
}
.quick-add-form .input-num { width: 84px; }

.add-player-block {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  padding: 10px 14px;
}
.add-player-block > summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  padding: 4px 0;
}
.add-player-block > summary::-webkit-details-marker { display: none; }
.add-player-block > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.15s ease;
}
.add-player-block[open] > summary::before { transform: rotate(90deg); }

.add-player-form {
  display: grid;
  gap: 12px;
  margin-top: 10px;
}

.add-player-actions {
  align-items: flex-end;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.player-pick-grid {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.player-pick-card {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  gap: 10px;
  padding: 8px 10px;
  font-weight: 500;
  transition: border-color 0.1s, box-shadow 0.1s;
}
.player-pick-card:hover { border-color: #b9b3a8; }
.player-pick-card:has(input:checked) {
  background: #eef7f1;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.player-pick-card input { margin: 0; min-height: auto; width: auto; }
.player-pick-info { display: grid; gap: 2px; min-width: 0; }
.player-pick-name { font-weight: 600; }

/* ---------------- Per-event horse chips ---------------- */

.event-horse-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  white-space: normal;
}

.horse-chip-form { display: inline-flex; margin: 0; }

.horse-chip {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  gap: 6px;
  min-height: 26px;
  padding: 3px 10px;
  text-decoration: none;
  transition: background 0.1s, border-color 0.1s;
}
.horse-chip:hover { border-color: #b9b3a8; text-decoration: none; }

.horse-chip-on  { background: #eef7f1; border-color: #b7d8c7; }
.horse-chip-off {
  background: var(--surface-soft);
  border-style: dashed;
  color: var(--muted);
}
.horse-chip-off .horse-chip-name { text-decoration: line-through; }

.horse-chip-status { font-weight: 800; }
.horse-chip-add {
  background: transparent;
  border-style: dashed;
  color: var(--accent);
}

/* ---------------- Responsive ---------------- */

@media (max-width: 720px) {
  .app-header,
  .page-title {
    align-items: flex-start;
    flex-direction: column;
  }
  .app-shell { padding: 20px 14px 40px; }
  .form-grid { grid-template-columns: 1fr; }
  .roster-form-footer { flex-direction: column; align-items: stretch; }
  .roster-form-footer .button-large { width: 100%; justify-content: center; }
}
