/*
  Tournaments Scheduler – základní téma (světlé + tmavé)
*/

/* CSS proměnné a barevná paleta */
:root, [data-theme="dark"] {
  --bg: #0b0e14;
  --bg-soft: #121723;
  --surface: #161b26;
  --surface-2: #1c2331;
  --text: #e6edf3;
  --text-muted: #a6b2c0;
  --primary: #4c8bf5;
  --primary-600: #3f78e0;
  --primary-700: #3769c5;
  --danger: #ff6b6b;
  --warning: #f5a524;
  --success: #2ecc71;
  --border: rgba(230, 237, 243, 0.12);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --radius: 12px;
}

[data-theme="light"] {
  --bg: #f7f9fc;
  --bg-soft: #eef2f8;
  --surface: #ffffff;
  --surface-2: #f3f6fb;
  --text: #101828;
  --text-muted: #59657a;
  --primary: #2f6feb;
  --primary-600: #2a62d1;
  --primary-700: #2456b8;
  --danger: #e03131;
  --warning: #d99100;
  --success: #1aab5b;
  --border: rgba(16, 24, 40, 0.08);
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.08);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f7f9fc;
    --bg-soft: #eef2f8;
    --surface: #ffffff;
    --surface-2: #f3f6fb;
    --text: #101828;
    --text-muted: #59657a;
    --primary: #2f6feb;
    --primary-600: #2a62d1;
    --primary-700: #2456b8;
    --danger: #e03131;
    --warning: #d99100;
    --success: #1aab5b;
    --border: rgba(16, 24, 40, 0.08);
    --shadow: 0 8px 24px rgba(16, 24, 40, 0.08);
  }
}

/* Reset/typografie */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background: radial-gradient(1200px 800px at 10% -10%, rgba(76,139,245,0.12), transparent 35%),
              radial-gradient(1200px 800px at 110% 10%, rgba(46,213,115,0.10), transparent 35%),
              var(--bg);
  line-height: 1.5;
}

.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px;
}

/* Hlavička a navigace */
.header {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(150%) blur(8px);
  background: linear-gradient(to bottom, rgba(0,0,0,0.35), rgba(0,0,0,0.0)) , transparent;
  border-bottom: 1px solid var(--border);
}

.header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.site-title { font-size: 20px; margin: 0; white-space: nowrap; }
.site-title a { color: var(--text); text-decoration: none; }

.nav { display: flex; align-items: center; }

.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}

.nav-toggle:hover {
  background: rgba(230,237,243,0.08);
}

.nav-menu {
  display: flex;
  align-items: center;
  gap: 20px;
}

.nav-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.nav-links {
  display: flex;
  gap: 12px;
  align-items: center;
}

.nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 8px;
  white-space: nowrap;
}
.nav-links a:hover { color: var(--text); background: rgba(230,237,243,0.08); }

.btn-icon {
  padding: 4px 8px;
  font-size: 1.2rem;
  height: auto;
  min-width: 40px;
}

/* Tabulky */
.table-container {
  width: 100%;
  overflow-x: auto;
  margin-top: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}

th, td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Karty a layout */
.card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-top: 28px;
}

h2 { margin-top: 0; font-size: 22px; }
.muted { color: var(--text-muted); font-size: 0.95rem; }

/* Formuláře */
form { display: grid; gap: 14px; }
.form-row { display: grid; gap: 6px; }
label { font-weight: 600; color: var(--text); }
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}

/* Ensure number inputs have visible arrows (spinners) on desktop, but hide on small screens if they overlap */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  opacity: 1;
  display: block;
}

@media (max-width: 640px) {
  input[type="number"]::-webkit-inner-spin-button,
  input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }
}
input[type="number"] {
  -moz-appearance: number-input;
  appearance: number-input;
}
input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 35%, transparent);
}

.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 6px; }

.mb-20 { margin-bottom: 20px; }

.round-nav { display: flex; justify-content: center; align-items: center; gap: 20px; margin-bottom: 20px; }
.round-title { font-weight: bold; font-size: 1.1rem; }
.round-header { margin-top: 30px; border-bottom: 2px solid var(--border); padding-bottom: 5px; }

.match-card { background: var(--bg-soft); border-radius: 8px; margin-bottom: 20px; border: 1px solid var(--border); overflow: hidden; }
.match-main { display: grid; grid-template-columns: 1fr auto 1fr; gap: 20px; align-items: center; padding: 15px; position: relative; border-bottom: 1px solid var(--border); }
.played-badge { position: absolute; top: 10px; right: 10px; background: var(--success); color: white; font-size: 0.65rem; padding: 2px 6px; border-radius: 4px; font-weight: bold; }

.match-team.home { text-align: right; font-weight: 600; }
.match-team.away { text-align: left; font-weight: 600; }

.match-score-inputs { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.score-row { display: flex; gap: 10px; align-items: center; }
.score-input { width: 3rem; padding: 0.25rem 0.125rem; text-align: center; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); font-weight: bold; color: var(--text); }
.score-separator { font-weight: bold; }

.ot-checkbox { display: flex; align-items: center; gap: 0.3rem; font-size: 0.8rem; }
.ot-checkbox label { margin-bottom: 0; font-weight: normal; }

.match-parts { 
  padding: 0.5rem 0.6rem; 
  background: rgba(0,0,0,0.05); 
  display: flex; 
  justify-content: center; 
  gap: clamp(0.2rem, 1vw, 0.6rem); 
  font-size: 0.85rem; 
  flex-wrap: nowrap; 
  overflow: hidden; 
}
.match-parts > * { flex-shrink: 1; min-width: 0; }

@media (max-width: 640px) {
  .match-parts { 
    padding: 0.4rem 0.05rem;
    flex-wrap: wrap;
    justify-content: center;
  }
  .part-label { font-size: clamp(0.5rem, 2vw, 0.55rem); }
  .part-input { 
    width: clamp(1.2rem, 8vw, 1.8rem);
    padding: 0.2rem 0; 
    font-size: 0.8rem; 
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
    border-radius: 2px;
    height: auto;
    line-height: normal;
  }
  .btn-generate {
    padding: 0.06rem 0.125rem;
    font-size: 0.55rem;
    margin-left: 0;
  }
  .part-item {
    margin: 2px;
  }
  /* Vynucení zalomení po 2. části pomocí prázdného elementu */
  .match-parts::after {
    content: "";
    flex-basis: 100%;
    order: 2;
  }
  .part-item:nth-child(-n+2) { order: 1; }
  .part-item:nth-child(n+3) { order: 3; }
}
.part-item { display: flex; flex-direction: column; align-items: center; gap: 0.125rem; min-width: 0; }
.part-label { font-size: 0.7rem; white-space: nowrap; }
.part-inputs { display: flex; gap: 0.2rem; align-items: center; }
.part-input { width: 2.2rem; padding: 0.25rem 0.125rem; text-align: center; border-radius: 4px; border: 1px solid var(--border); background: var(--surface); font-size: 0.85rem; color: var(--text); }
.part-separator { font-size: 0.75rem; }

.btn-generate { padding: 2px 5px; font-size: 0.7rem; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; cursor: pointer; margin-left: 2px; }

.sticky-actions { margin-top: 30px; position: sticky; bottom: 20px; background: var(--surface); padding: 15px; border-radius: var(--radius); border: 1px solid var(--primary); box-shadow: var(--shadow); z-index: 10; }
.full-width { width: 100%; }

.mt-20 { margin-top: 20px; }

.tournament-list { display: grid; gap: 15px; margin-top: 15px; }
.tournament-item { padding: 15px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-soft); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.tournament-info { flex: 1; min-width: 200px; }
.tournament-name { font-size: 1.1rem; color: var(--primary); }
.private-badge { background: var(--danger); color: white; }
.tournament-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.delete-btn { color: var(--danger); border-color: var(--danger); }
.delete-btn:hover { background: rgba(224, 49, 49, 0.08); }

/* Tlačítka */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  transition: transform .05s ease, background .15s ease, border-color .15s ease;
  cursor: pointer;
}
.btn:hover { border-color: color-mix(in oklab, var(--primary) 35%, var(--border)); }
.btn:active { transform: translateY(1px); }

.btn.primary {
  border: none;
  background: linear-gradient(180deg, var(--primary), var(--primary-600));
  color: #fff;
}
.btn.primary:hover { background: linear-gradient(180deg, var(--primary-600), var(--primary-700)); }

/* Flash zprávy */
.flash { margin: 0; padding: 8px 20px 16px; }
.flash-item {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  margin-top: 10px;
}
.flash-item.info { border-color: color-mix(in oklab, var(--primary) 40%, var(--border)); }
.flash-item.error { border-color: color-mix(in oklab, var(--danger) 45%, var(--border)); }
.flash-item.warning { border-color: color-mix(in oklab, var(--warning) 45%, var(--border)); }
.flash-item.success { border-color: color-mix(in oklab, var(--success) 45%, var(--border)); }

/* Pomocné třídy */
.text-center { text-align: center; }
.btn-group { display: flex; background: var(--bg-soft); padding: 4px; border-radius: 8px; border: 1px solid var(--border); }
.btn-group .btn { padding: 6px 12px; font-size: 0.9rem; background: transparent; border-color: transparent; }
.btn-group .btn.primary { background: var(--primary); color: white; border-radius: 6px; }

.header-actions { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.header-btns { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.group-title { margin-top: 30px; margin-bottom: 10px; border-left: 4px solid var(--primary); padding-left: 10px; }

.rank-cell { font-weight: bold; }
.team-cell { white-space: nowrap; }
.team-player { font-size: 0.8rem; margin-left: 5px; }
.points-cell { font-weight: bold; color: var(--primary); }

.badge { font-size: 0.75rem; padding: 2px 6px; border-radius: 4px; margin-left: 8px; vertical-align: middle; font-weight: bold; }
.advance-badge { background: #40E0D0; color: #333; }
.preliminary-badge { border: 1px solid #40E0D0; color: var(--text); }

.gold-row { background: rgba(255, 215, 0, 0.15); border-left: 4px solid #FFD700; }
.silver-row { background: rgba(192, 192, 192, 0.15); border-left: 4px solid #C0C0C0; }
.bronze-row { background: rgba(205, 127, 50, 0.15); border-left: 4px solid #CD7F32; }
.advance-row { background: rgba(64, 224, 208, 0.15); border-left: 4px solid #40E0D0; }
.preliminary-row { background: rgba(64, 224, 208, 0.08); border-left: 4px solid #40E0D0; border-left-style: dashed; }

.form-container { display: flex; gap: 4px; justify-content: center; }
.form-circle {
  width: 14px; height: 14px; border-radius: 50%; cursor: pointer; display: flex;
  align-items: center; justify-content: center; font-size: 8px; font-weight: bold; color: white;
}
.form-circle.green { background-color: var(--success); }
.form-circle.red { background-color: var(--danger); }
.form-circle.yellow { background-color: var(--warning); }

/* Patička */
.footer { color: var(--text-muted); padding: 24px 0 8px; font-size: 0.95rem; }

/* Responsivita */
@media (max-width: 800px) {
  .nav-toggle {
    display: block;
  }

  .nav-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 20px;
    gap: 20px;
    box-shadow: var(--shadow);
  }

  .nav-menu.active {
    display: flex;
  }

  .nav-controls {
    justify-content: center;
    width: 100%;
  }

  .nav-links {
    flex-direction: column;
    width: 100%;
  }

  .nav-links a {
    width: 100%;
    text-align: center;
    padding: 12px;
  }
}

@media (max-width: 640px) {
  .container { padding: 14px; }
  .card { padding: 18px; }
  
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }

  .form-actions {
    flex-direction: column;
  }
  
.form-actions .btn {
    width: 100%;
  }

  .match-main {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .match-team.home, .match-team.away {
    text-align: center;
  }

}

/* Media query pro tisk */
@media print {
  .header, .header-btns, .round-nav, .muted, .sticky-actions, .btn, .btn-group, .btn-generate, .form-actions {
    display: none !important;
  }
  
  body {
    background: white !important;
    color: black !important;
  }

  .container {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .card {
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
  }

  table {
    border-collapse: collapse !important;
    width: 100% !important;
  }

  th, td {
    border: 1px solid #ddd !important;
    padding: 8px !important;
    color: black !important;
  }

  .match-card {
    border: 1px solid #ddd !important;
    break-inside: avoid;
    margin-bottom: 10px !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  .score-input {
    border: none !important;
    background: transparent !important;
    appearance: none;
    -moz-appearance: textfield;
    width: auto !important;
    text-align: center;
  }

  .score-input::-webkit-outer-spin-button,
  .score-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }

  .match-main {
    padding: 10px !important;
  }

  h2, h3 {
    color: black !important;
    margin-top: 20px !important;
  }

  .played-badge {
    display: none !important;
  }
}
