: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; /* legacy */
  --ct-z:#7c3aed; /* Zephyria – fiolet */
  --ct-a:#ef4444; /* Aleksandria – czerwony */
}

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
}
.app{flex:1 0 auto;display:grid;grid-template-columns:380px 1fr;gap:18px;padding:18px;box-sizing:border-box;align-items:start}

.panel{background:#0f1628;color:#e5ecf8;border:1px solid #1f2b46;border-radius:14px;padding:16px;position:sticky;top:18px}
.panel .row{display:flex;gap:8px;align-items:center;margin:8px 0}
.panel input[type="number"], .panel input[type="text"], .panel select{background:#0b1222;border:1px solid #223055;color:#e5ecf8;border-radius:8px;padding:8px 10px}
.text{background:#0b1222;border:1px solid #223055;color:#e5ecf8;border-radius:8px;padding:8px 10px}
.select{background:#0b1222;border:1px solid #223055;color:#e5ecf8;border-radius:8px;padding:8px 10px}
.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}
.sep{border:none;border-top:1px solid #253052;margin:14px 0}
.note{font-size:12px;color:#a9b6cb}
.subhead{margin-top:12px;margin-bottom:6px;font-size:12px;color:#a9b6cb;text-transform:uppercase;letter-spacing:.04em}

/* Legenda */
.legend{display:flex;gap:10px;flex-wrap:wrap;margin:8px 0 12px}
.legend-item{display:inline-flex;align-items:center;gap:8px;background:#0b1222;border:1px solid #223055;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 */
.stage-wrap{overflow:auto;background:#0b1222;border:1px solid #1f2b46;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}

/* BOARD */
.topbar{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px}
.title{font-weight:800;font-size:38px;color:#10243a}
.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}
.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}
.stage.exporting .sort-btn{display:none!important}

/* ROWS */
#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;gap:0;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}
.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}

.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}
.points{font-weight:900;font-size:24px;text-align:center;color:#082038;border-left:2px solid var(--divider);padding-left:16px;cursor:text}

/* actions */
.row-actions{margin-left:auto;display:flex;gap:6px;opacity:.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%;background:#0b1222;border:1px solid #223055;color:#e5ecf8;border-radius:8px;padding:8px 10px}
.db-list{display:grid;gap:8px;margin:10px 0;max-height:260px;overflow:auto}
.db-item{
  display:grid;grid-template-columns:26px 1fr 60px auto;column-gap:10px;align-items:center;
  background:linear-gradient(180deg,#0b1222,#0e1730);border:1px solid #223055;color:#e5ecf8;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)} /* legacy */
.db-country[data-cc="Z"]{background:var(--ct-z)}
.db-country[data-cc="A"]{background:var(--ct-a)}

/* 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:#0b1222;border:1px solid #223055;color:#e5ecf8;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}

.name.name-dup{background:#ffecec;box-shadow:inset 0 -2px 0 #d94848;transition:background .2s}

/* Error + export-all */
.db-error{background:#311b1b;color:#ffd9d9;border:1px solid #5b2b2b;border-radius:10px;padding:8px 10px;margin:8px 0;font-size:13px}
.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}

/* Pomoc / Legenda */
.help{margin-top:12px;background:#0b1222;border:1px solid #223055;border-radius:12px;padding:10px}
.help summary{display:flex;align-items:center;gap:8px;cursor:pointer;font-weight:800;color:#e5ecf8;list-style:none}
.help summary::-webkit-details-marker{display:none}
.help .chev{transition:transform .2s ease}
.help[open] .chev{transform:rotate(180deg)}
.help-grid{margin-top:10px;display:grid;gap:10px}
.help-sec{background:#0f1628;border:1px dashed #223055;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 #223055;border-bottom-width:2px;border-radius:6px;background:#0b1222;color:#e5ecf8;font:700 12px/1 Inter,system-ui,Arial}

/* Sekcje rozwijane */
.sec{margin-top:12px;background:#0b1222;border:1px solid #223055;border-radius:12px;padding:10px}
.sec summary{display:flex;align-items:center;gap:8px;cursor:pointer;font-weight:800;color:#e5ecf8;list-style:none}
.sec summary::-webkit-details-marker{display:none}
.sec .chev{transition:transform .2s ease}
.sec[open] .chev{transform:rotate(180deg)}
.sec > *:not(summary){margin-top:8px}