/* ═══ ZMIENNE ═══ */
:root {
  --bg: #f2f6fb;
  --row-even: #fff;
  --row-odd: #f7fafc;
  --top1: #fdf6bf;
  --top2: #e9edf2;
  --top3: #fde59a;
  --playoff: #e9fbe9;
  --bar-playoff: #22c55e;
  --releg: #ffe1e1;
  --bar-releg: #ff6b6b;
  --bar-top: #e3b341;
  --bar-top2: #9aa3ad;
  --bar-top3: #e8b20f;
  --text: #0e1b2b;
  --divider: #cfd7e3;
  --accent: #0f6fff;
  --radius: 12px;
  --rowH: 86px;
  --ct-sz: #0ea5e9;
  --ct-w: #f59e0b;
  --ct-i: #64748b;
  --panel-bg: #0f1628;
  --panel-border: #1f2b46;
  --input-bg: #0b1222;
  --input-border: #223055;
  --panel-text: #e5ecf8;
}

/* ═══ RESET / BASE ═══ */
html, body { height: 100%; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background: #10131a linear-gradient(180deg, #10131a, #121828 50%, #0e1424);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ═══ LAYOUT ═══ */
.app {
  flex: 1 0 auto;
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 18px;
  padding: 18px;
  box-sizing: border-box;
  align-items: start;
}

/* ✅ Responsywność */
@media (max-width: 1400px) {
  .app { grid-template-columns: 340px 1fr; }
}
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    padding: 10px;
  }
  .stage-wrap { order: -1; }
}

/* ═══ LINKI JAKO PRZYCISKI ═══ */
a.btn, a.btn.secondary {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

/* ═══ PANEL (lewa strona) ═══ */
.panel {
  background: var(--panel-bg);
  color: var(--panel-text);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 16px;
  position: sticky;
  top: 18px;
}

.panel h2 { margin: 0 0 8px; font-size: 18px; }
.panel .row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }

/* ✅ Unified input styling (zamiast 3 duplikatów) */
.panel input[type="number"],
.panel input[type="text"],
.panel select,
.text,
.select,
.db-search {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  color: var(--panel-text);
  border-radius: 8px;
  padding: 8px 10px;
}

/* ✅ Klasa zamiast inline style="width:90px" */
.input-sm { width: 90px; }

/* ═══ PRZYCISKI ═══ */
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
}

.btn.secondary { background: #223055; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ═══ SEPARATORY / NOTES ═══ */
.sep { border: none; border-top: 1px solid #253052; margin: 14px 0; }
.note { font-size: 12px; color: #a9b6cb; }
.subhead { font-weight: 700; margin: 12px 0 6px; color: var(--panel-text); }

/* ═══ ROWS z inline styles przeniesione do klas ═══ */
/* ✅ Wszędzie takie same przyciski w nawigacji */
.row.nav {
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 0;
  margin-bottom: 12px;
}

.row.nav .btn {
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
}

.actions-row {
  margin-top: 12px;
  gap: 10px;
  flex-wrap: wrap;
}

.profile-row {
  gap: 8px;
  flex-wrap: wrap;
}

.profile-name { flex: 1 1 180px; }
.profile-select { flex: 1 1 240px; }

.db-actions { gap: 10px; }

/* ═══ LEGENDA ═══ */
.legend { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0 12px; }

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 999px;
  padding: 6px 10px;
}

.chip { display: inline-block; width: 16px; height: 16px; border-radius: 4px; }
.chip-gold { background: linear-gradient(180deg, #f9e07d, #f4c430); }
.chip-green { background: var(--playoff); border: 1px solid var(--bar-playoff); }
.chip-red { background: var(--releg); border: 1px solid var(--bar-releg); }

/* ═══ STAGE (eksport JPG) ═══ */
.stage-wrap {
  overflow: auto;
  background: var(--input-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
}

.stage {
  box-sizing: border-box;
  width: 1920px;
  height: 1080px;
  padding: 24px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.stage.exporting .row-actions { display: none !important; }
.stage.exporting .row-item.selected { outline: none !important; }
.stage.exporting #rows { overflow: hidden !important; }
.stage.exporting .sort-btn { display: none !important; }

/* ═══ BOARD ═══ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

/* ✅ h1 zamiast div, reset marginu */
.title {
  font-weight: 800;
  font-size: 38px;
  color: #10243a;
  margin: 0;
}

.board {
  background: #fff;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 6px 24px rgba(16, 24, 40, .08);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.board-header {
  display: grid;
  grid-template-columns: 110px 1fr 150px;
  align-items: center;
  padding: 0 16px;
  height: 76px;
  border-bottom: 1px solid var(--divider);
  font-weight: 700;
  font-size: 20px;
  color: #334155;
  background: #f8fafc;
}

/* ✅ Klasa zamiast inline style */
.header-pos { padding-left: 8px; }

.header-points {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.sort-btn {
  background: #e2e8f0;
  border: 1px solid #cbd5e1;
  color: #0b2239;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
}

/* ═══ ROWS (tabela) ═══ */
#rows {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-auto-rows: 1fr;
}

#rows.scroll {
  grid-auto-rows: var(--rowH);
  overflow-y: auto;
  height: 100%;
}

.row-item {
  position: relative;
  display: grid;
  grid-template-columns: 110px 1fr 150px;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid #eef2f7;
  cursor: default;
}

.row-item:nth-child(odd) { background: var(--row-odd); }
.row-item:nth-child(even) { background: var(--row-even); }

.row-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 12px;
  background: transparent;
}

/* Pozycje kolorowe */
.row-item.first   { background: var(--top1); }
.row-item.first::before  { background: var(--bar-top); }
.row-item.second  { background: var(--top2); }
.row-item.second::before { background: var(--bar-top2); }
.row-item.third   { background: var(--top3); }
.row-item.third::before  { background: var(--bar-top3); }
.row-item.playoff { background: var(--playoff); }
.row-item.playoff::before { background: var(--bar-playoff); }
.row-item.releg   { background: var(--releg); }
.row-item.releg::before  { background: var(--bar-releg); }

.row-item.selected { outline: 3px solid rgba(15, 111, 255, .45); outline-offset: -3px; }
.row-item.db-over  { outline: 3px dashed #0f6fff; outline-offset: -3px; }

.drag-ghost { opacity: .5; }
.drag-chosen { outline: 2px dashed #0f6fff; }

/* ═══ KOMÓRKI WIERSZA ═══ */
.pos {
  font-weight: 800;
  font-size: 28px;
  color: #243244;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-start;
  cursor: grab;
  user-select: none;
}

.team {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
  position: relative;
}

.logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  background: #f2f4f7;
  border-radius: 12px;
  border: 1px solid #e5e8ef;
  flex: 0 0 64px;
}

.name {
  font-size: 24px;
  font-weight: 700;
  outline: none;
  cursor: text;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.name[contenteditable="true"]:focus {
  box-shadow: inset 0 -2px 0 #9ec3ff;
}

.name.name-dup {
  background: #ffecec;
  box-shadow: inset 0 -2px 0 #d94848;
  transition: background .2s;
}

.points {
  font-weight: 900;
  font-size: 24px;
  text-align: center;
  color: #082038;
  border-left: 2px solid var(--divider);
  padding-left: 16px;
  cursor: text;
}

/* ═══ AKCJE WIERSZA ═══ */
.row-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
  opacity: 0;  /* ✅ było .0 */
  transition: .15s opacity;
}

.row-item:hover .row-actions { opacity: 1; }

.icon-btn {
  background: #f1f5f9;
  border: 1px solid #d8e1ee;
  color: #0b2239;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}

/* ═══ BAZA KLUBÓW ═══ */
.db-search { width: 100%; }

.db-list {
  display: grid;
  gap: 8px;
  margin: 10px 0;
  max-height: 260px;
  overflow: auto;
}

/* ✅ Naprawiony grid: 3 kolumny zamiast 4 (bo JS tworzy 3 elementy) */
.db-item {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  column-gap: 10px;
  align-items: center;
  background: linear-gradient(180deg, #0b1222, #0e1730);
  border: 1px solid var(--input-border);
  color: var(--panel-text);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: grab;
  transition: .15s border-color, .15s background;
}

.db-item:hover { border-color: #2a3c6b; background: #0f1c39; }
.db-item.selected { outline: 2px solid #0f6fff; background: #11254a; }
.db-item[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }

.db-badge {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--badge, #2b67ff);
  color: #cfe2ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 12px;
}

.db-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.db-country {
  justify-self: end;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 12px;
  color: #fff;
}

.db-country[data-cc="SZ"] { background: var(--ct-sz); }
.db-country[data-cc="W"]  { background: var(--ct-w); }
.db-country[data-cc="I"]  { background: var(--ct-i); }

/* ═══ FILTRY ═══ */
.tag-filter,
.country-filter {
  display: flex;
  gap: 8px;
  margin: 6px 0 8px;
  flex-wrap: wrap;
}

.tag-pill,
.country-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-appearance: none;
  appearance: none;
  outline: 0;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  color: var(--panel-text);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  font-weight: 700;
  line-height: 1;
}

.tag-pill.active,
.country-pill.active {
  border-color: #0f6fff;
  background: #11254a;
}

.tag-pill.clear,
.country-pill.clear {
  border-style: dashed;
  font-weight: 600;
}

/* ═══ AUTOCOMPLETE ═══ */
.ac {
  position: absolute;
  left: 0;
  right: 0;
  top: 72px;
  z-index: 5;
  display: none;
  background: #fff;
  border: 1px solid #e5e8ef;
  border-radius: 10px;
  box-shadow: 0 12px 24px rgba(16, 24, 40, .18);
  padding: 6px;
  max-height: 220px;
  overflow: auto;
}

.ac-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: transparent;
  border: 0;
  text-align: left;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  color: #0b2239;
}

.ac-item:hover,
.ac-item.selected { background: #f1f5f9; }

.ac-badge {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--badge, #2b67ff);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 12px;
}

.ac-text {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ac-tags { margin-left: 6px; opacity: .9; }

/* ═══ ERROR ═══ */
.db-error {
  background: #311b1b;
  color: #ffd9d9;
  border: 1px solid #5b2b2b;
  border-radius: 10px;
  padding: 8px 10px;
  margin: 8px 0;
  font-size: 13px;
}

/* ═══ EXPORT-ALL ═══ */
.stage.export-all #rows {
  overflow: visible !important;
  grid-auto-rows: var(--rowH) !important;
}

/* ═══ FOOTER ═══ */
.site-footer {
  padding: 12px 18px 18px;
  text-align: right;
  font-weight: 700;
  color: #a9b6cb;
}

/* ═══ SEKCJE ROZWIJANE ═══ */
.sec,
.help {
  margin-top: 12px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 12px;
  padding: 10px;
}

.sec summary,
.help summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 800;
  color: var(--panel-text);
  list-style: none;
}

.sec summary::-webkit-details-marker,
.help summary::-webkit-details-marker { display: none; }

/* ✅ Chevron przez CSS zamiast <span class="chev"> */
.sec summary::before,
.help summary::before {
  content: "▾";
  display: inline-block;
  transition: transform .2s ease;
}

.sec:not([open]) summary::before,
.help:not([open]) summary::before {
  transform: rotate(-90deg);
}

.sec > *:not(summary) { margin-top: 8px; }

/* ═══ POMOC ═══ */
.help-grid { margin-top: 10px; display: grid; gap: 10px; }

.help-sec {
  background: var(--panel-bg);
  border: 1px dashed var(--input-border);
  border-radius: 10px;
  padding: 8px 10px;
  color: #d7e1f3;
}

.help-sec h4 {
  margin: 0 0 6px;
  font-size: 12px;
  color: #a9b6cb;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.help-sec ul { margin: 0; padding-left: 18px; }
.help-sec li { margin: 4px 0; font-size: 13px; line-height: 1.25; }

.help kbd {
  display: inline-block;
  padding: 2px 6px;
  border: 1px solid var(--input-border);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--panel-text);
  font: 700 12px/1 Inter, system-ui, Arial;
}

.help .chip { vertical-align: middle; margin: 0 4px 0 6px; }

/* ═══ PANEL — scroll gdy za wysoki ═══ */
.panel {
  background: var(--panel-bg);
  color: var(--panel-text);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 16px;
  position: sticky;
  top: 18px;

  /* ✅ NOWE — panel nie wychodzi poza ekran */
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #223055 transparent;
}

/* Webkit scrollbar w panelu */
.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-track { background: transparent; }
.panel::-webkit-scrollbar-thumb {
  background: #223055;
  border-radius: 3px;
}
.panel::-webkit-scrollbar-thumb:hover { background: #2a3c6b; }

/* ═══ STAGE-WRAP — lepsze dopasowanie ═══ */
.stage-wrap {
  overflow: hidden;  /* ✅ było: auto (scrollbar) → teraz: hidden (stage-fit.js skaluje) */
  background: var(--input-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
}