/* =========================================
   Styles.css  —  shared: PouleSheet + LadderManager
   Plain light base. Override with a theme file for branding.
   ========================================= */

/* ---------- Design tokens ---------- */

:root {
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;

  --radius: 0.4rem;

  --border: 1px solid rgba(0, 0, 0, 0.15);
  --border-strong: 1px solid rgba(0, 0, 0, 0.28);

  --text: #111;
  --muted: rgba(0, 0, 0, 0.55);

  --bg: #fff;
  --hover: rgba(0, 0, 0, 0.05);

  --selected: rgba(30, 110, 220, 0.15);
  --selected-strong: rgba(30, 110, 220, 0.32);

  --win-bg:  rgba(0, 140, 60, 0.10);
  --loss-bg: rgba(200, 0, 0, 0.07);
}

/* ---------- Reset / base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  line-height: 1.4;
}

/* ---------- Semantic layout ---------- */

header, main, footer, section {
  display: block;
}

/* ---------- Header — shared ---------- */

header {
  padding: var(--space-3) var(--space-5);
  border-bottom: var(--border);
}

/*
  header-bar: single flex row containing the title h1 and any
  right-side controls (fullscreen icon, action buttons, etc.)
  Used identically in both apps.
*/
header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

header-bar h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/*
  header-controls: the right-hand cluster of buttons inside header-bar.
  Used in PouleSheet for Export / Print / New Sheet / Fullscreen.
*/
header-controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  flex: 0 0 auto;
}

/* ---------- Main layout ---------- */

/* LadderManager: two-column side-by-side */
main.two-col {
  display: flex;
  gap: var(--space-5);
  padding: var(--space-5);
  align-items: flex-start;
}

main.two-col section {
  flex: 1 1 0;
  min-width: 18rem;
}

@media (max-width: 56rem) {
  main.two-col {
    flex-direction: column;
    align-items: stretch;
  }
  main.two-col section {
    width: 100%;
    min-width: 0;
  }
}

/* PouleSheet: single-column stacked */
main.one-col {
  max-width: 1100px;
  margin: var(--space-5) auto;
  padding: 0 var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

@media (max-width: 600px) {
  header { padding: var(--space-3) var(--space-4); }
  main.one-col { padding: 0 var(--space-3); margin: var(--space-3) auto; }
}

/* ---------- Sections ---------- */

section {
  background: var(--bg);
  border: var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
}

section h2 {
  margin: 0 0 var(--space-3);
  font-size: 1.1rem;
}

section h3 {
  margin: var(--space-4) 0 var(--space-2);
  font-size: 0.85rem;
  color: var(--muted);
}

/* ---------- Footer ---------- */

footer {
  padding: var(--space-3) var(--space-5);
  border-top: var(--border);
  color: var(--muted);
}

footer p {
  margin: 0;
  font-size: 0.9rem;
}

/* ---------- Buttons — shared base ---------- */

button {
  appearance: none;
  border: var(--border-strong);
  background: var(--bg);
  color: var(--text);
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.4;
}

button:hover   { background: var(--hover); }
button:active  { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

/* Fullscreen / icon-only buttons — shared */
button.icon-btn {
  padding: 0.3rem 0.4rem;
  line-height: 0;
  border-radius: var(--radius);
}

button.icon-btn img {
  width: 1.2rem;
  height: 1.2rem;
  display: block;
}

/* Danger tint — used on "New Sheet" */
button.danger {
  color: #c00;
  border-color: rgba(200, 0, 0, 0.3);
}
button.danger:hover { background: rgba(200, 0, 0, 0.06); }

/* ---------- Inputs & selects — shared ---------- */

input[type="text"],
input[type="number"],
input[type="date"],
select {
  border: var(--border-strong);
  border-radius: var(--radius);
  padding: 0.4rem 0.55rem;
  font-size: 0.95rem;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}

input:focus, select:focus {
  outline: 2px solid rgba(0, 0, 0, 0.3);
  outline-offset: 1px;
}

input:disabled { background: rgba(0, 0, 0, 0.04); }

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23555' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  padding-right: 2rem;
}

/* Hide native number spinners — ScoreOverlay provides +/- instead */
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ---------- Labels ---------- */

label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

/* ---------- Utility ---------- */

.hidden { display: none !important; }

/* ===========================================
   POULE SHEET — specific
   =========================================== */

/* Setup grid */
setup-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

setup-field {
  display: flex;
  flex-direction: column;
}

/* Fencer name entry grid */
fencer-names-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

fencer-name-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.fencer-num {
  font-weight: 700;
  font-size: 0.95rem;
  min-width: 1.5rem;
  text-align: right;
  flex-shrink: 0;
  color: var(--muted);
}

fencer-name-field input { flex: 1; }

/* Start button */
button.btn-wide {
  width: 100%;
  padding: 0.6rem;
  font-size: 1rem;
  margin-top: var(--space-2);
}

/* Bout list */
bout-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.bout-item {
  display: grid;
  grid-template-columns: 2.5rem 1fr auto auto auto 1fr auto;
  align-items: center;
  gap: var(--space-2);
  padding: 0.4rem var(--space-3);
  border: var(--border);
  border-radius: var(--radius);
}

.bout-item.complete { color: var(--muted); }

.bout-num {
  font-size: 0.7rem;
  color: var(--muted);
  text-align: right;
}

.bout-fencer-label {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
}

.bout-fencer-left  { justify-content: flex-end; }
.bout-fencer-right { justify-content: flex-start; }

.bout-fencer-num {
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
  color: var(--muted);
}

.bout-fencer-name {
  font-size: 0.88rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bout-winner .bout-fencer-name,
.bout-winner .bout-fencer-num {
  color: var(--text);
  font-weight: 700;
}

input.score-input {
  width: 2.6rem;
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  padding: 0.25rem 0;
}

.bout-vs {
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
}

.bout-status {
  font-size: 0.85rem;
  color: #080;
  min-width: 1rem;
  text-align: center;
}

/* Score grid (read-only matrix) */
grid-scroll {
  display: block;
  overflow-x: auto;
}

.score-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 400px;
}

.score-table th,
.score-table td {
  border: var(--border);
  padding: 0;
  text-align: center;
  min-width: 2.25rem;
  height: 2.4rem;
}

.score-table thead th {
  background: rgba(0, 0, 0, 0.03);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.4rem;
  white-space: nowrap;
}

.score-table .th-name {
  text-align: left;
  min-width: 8rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  padding-left: 0.5rem;
}

.score-table td.row-header {
  background: rgba(0, 0, 0, 0.02);
  border-right: var(--border-strong);
  text-align: left;
  white-space: nowrap;
  padding: 0 var(--space-3) 0 var(--space-2);
}

.row-num {
  font-weight: 700;
  font-size: 0.85rem;
  display: inline-block;
  min-width: 1.75rem;
  text-align: right;
  padding-right: var(--space-3);
  color: var(--muted);
}

.row-name {
  font-size: 0.85rem;
}

.score-cell.blocked { background: rgba(0, 0, 0, 0.04); }

.score-display {
  display: block;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.4rem 0.25rem;
  user-select: none;
}

.score-cell.has-win  { background: var(--win-bg); }
.score-cell.has-loss { background: var(--loss-bg); }

/* Results table */
.results-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 500px;
}

.results-table th {
  background: rgba(0, 0, 0, 0.03);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  padding: 0.5rem var(--space-3);
  text-align: center;
  border: var(--border);
  white-space: nowrap;
}

.results-table th.th-left { text-align: left; }

.results-table td {
  border: var(--border);
  padding: 0.45rem var(--space-3);
  text-align: center;
  font-size: 0.9rem;
}

.results-table td.td-name { text-align: left; }
.results-table td.td-pos  { font-weight: 700; }
.results-table td.td-vm   { font-weight: 600; }

.results-table tr:nth-child(even) td { background: rgba(0, 0, 0, 0.02); }

/* Penalties */
penalties-section { display: block; margin-top: var(--space-4); }

penalties-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.penalty-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.4rem var(--space-2);
  border: var(--border);
  border-radius: var(--radius);
}

.penalty-row select,
.penalty-row input { flex: 1; }

.btn-remove {
  background: transparent;
  border: none;
  color: #c00;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius);
  line-height: 1;
}
.btn-remove:hover { background: rgba(200, 0, 0, 0.08); }

/* Print */
@media print {
  header-controls,
  #section-setup,
  #section-bouts,
  #btn-add-penalty,
  penalties-section { display: none !important; }
  section { border: 1px solid #ccc; }
}

@media (max-width: 600px) {
  setup-grid { grid-template-columns: 1fr 1fr; }
}

/* ===========================================
   LADDER MANAGER — specific
   =========================================== */

ladder-view,
ladder-row,
ladder-controls,
ladder-actions,
round-view,
round-controls,
match-list,
match-row,
match-name,
present-cell,
position-cell,
name-cell,
group-cell {
  display: block;
}

ladder-controls,
round-controls {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-top: var(--space-3);
  align-items: center;
}

ladder-view {
  border-top: var(--border);
  margin-top: var(--space-2);
}

ladder-row {
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-2);
  border-bottom: var(--border);
}

present-cell {
  display: flex;
  align-items: center;
  margin-right: var(--space-2);
}

position-cell {
  font-variant-numeric: tabular-nums;
  min-width: 2.25rem;
}

name-cell,
group-cell {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

name-cell  { font-weight: 500; }
group-cell { color: var(--muted); }

ladder-row[selected]         { background: var(--selected); }
ladder-row[editing]          { outline: 1px solid rgba(0,0,0,0.3); outline-offset: -1px; }
ladder-row[absent]           { background: #e5e5e5; color: #fff; }
ladder-row[absent] group-cell { color: #fff; }
ladder-row[absent][selected]  { background: var(--selected-strong); }

ladder-actions {
  display: flex;
  gap: var(--space-2);
}

ladder-actions button { padding: 0.35rem 0.45rem; }
ladder-actions img { width: 1.1rem; height: 1.1rem; display: block; }

round-view {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

round-view > button { margin-top: var(--space-3); }

match-list {
  margin-top: var(--space-3);
  margin-bottom: var(--space-3);
  border-top: var(--border);
  display: flex;
  flex-direction: column;
  gap: 0;
  align-items: stretch;
}

match-row {
  padding: var(--space-2);
  border-bottom: var(--border);
}

match-row[mode="entry"] {
  text-align: center;
  font-weight: 500;
  padding-left: var(--space-3);
  padding-right: var(--space-3);
}

match-row[mode="results"],
match-row[mode="locked"] {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto minmax(0, 1fr);
  gap: var(--space-2);
  align-items: center;
}

match-row[mode="results"] match-name,
match-row[mode="locked"]  match-name {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

match-row[mode="results"] match-name:first-child,
match-row[mode="locked"]  match-name:first-child { text-align: right; }

match-row[mode="results"] match-name:last-child,
match-row[mode="locked"]  match-name:last-child  { text-align: left; }

match-row[mode="results"] input.score-input,
match-row[mode="locked"]  input.score-input {
  width: 3.25rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding: 0.35rem 0.4rem;
}

p {
  margin: var(--space-2) 0;
  color: var(--muted);
}
