/* =========================
   THEME TOKENS — LIGHT
   ========================= */
:root {
  /* base */
  --bg: #f4f6fa;
  /* nền trang dịu, gần màu card */
  --text: #0f172a;
  --muted: #64748b;
  --card: #ffffff;
  --border: #e5e7eb;
  --shadow: 0 6px 18px rgba(2, 6, 23, .06);
  --shadow-lg: 0 16px 40px rgba(2, 6, 23, .12);

  /* surfaces */
  --card-grad-start: #ffffff;
  --card-grad-end: #f7f9fc;
  --thead-grad-start: #f9fafb;
  --thead-grad-end: #eef2f7;
  --row-hover: #f5f7fb;

  /* highlights */
  --topgw-start: #f0fdf4;
  --topgw-end: #dcfce7;

  /* points trigger & hits */
  --trigger-bg: #f1f5f9;
  --trigger-bg-hover: #e2e8f0;
  --hit-fg: #b91c1c;
  --hit-note-fg: #b91c1c;

  /* micro progress bar */
  --bar-start: #e5edff;
  --bar-end: #c7d2fe;
  --bar-opacity: .35;

  /* bench/on badges */
  --on-bg: #ecfdf5;
  --on-fg: #065f46;
  --bench-bg: #f1f5f9;
  --bench-fg: #475569;

  /* chips */
  --chip-shadow: 0 1px 2px rgba(0, 0, 0, .06);
  --chip-tc-start: #fff7d6;
  --chip-tc-end: #fde68a;
  --chip-tc-fg: #92400e;
  --chip-bb-start: #eafff1;
  --chip-bb-end: #bbf7d0;
  --chip-bb-fg: #065f46;
  --chip-fh-start: #e6f4ff;
  --chip-fh-end: #bae6fd;
  --chip-fh-fg: #075985;
  --chip-wc-start: #f6e8ff;
  --chip-wc-end: #e9d5ff;
  --chip-wc-fg: #6b21a8;

  /* winner border */
  --winner-border: rgba(16, 185, 129, .60);
  --winner-shadow: 0 12px 30px rgba(16, 185, 129, .18);
}

/* =========================
   THEME TOKENS — DARK
   bật bằng <html class="theme-dark">
   ========================= */
html.theme-dark {
  --bg: #0d1117;
  /* giống GitHub Dark */
  --text: #e2e8f0;
  --muted: #94a3b8;
  --card: #161b22;
  /* card đậm hơn nền chút */
  --border: #1f2937;
  --shadow: 0 10px 24px rgba(2, 6, 23, .35);
  --shadow-lg: 0 18px 44px rgba(2, 6, 23, .42);

  --card-grad-start: #161b22;
  --card-grad-end: #0f172a;
  --thead-grad-start: #1e293b;
  --thead-grad-end: #142234;
  --row-hover: #0f172a;

  --topgw-start: #064e3b;
  --topgw-end: #065f46;

  --trigger-bg: #0f172a;
  --trigger-bg-hover: #1f2937;
  --hit-fg: #fca5a5;
  --hit-note-fg: #fca5a5;

  --bar-start: #334155;
  --bar-end: #64748b;
  --bar-opacity: .45;

  --on-bg: #052e2b;
  --on-fg: #86efac;
  --bench-bg: #111827;
  --bench-fg: #94a3b8;

  --chip-tc-start: #854d0e;
  --chip-tc-end: #92400e;
  --chip-tc-fg: #fde68a;
  --chip-bb-start: #065f46;
  --chip-bb-end: #064e3b;
  --chip-bb-fg: #a7f3d0;
  --chip-fh-start: #075985;
  --chip-fh-end: #0c4a6e;
  --chip-fh-fg: #bae6fd;
  --chip-wc-start: #6d28d9;
  --chip-wc-end: #4c1d95;
  --chip-wc-fg: #e9d5ff;

  --winner-border: rgba(16, 185, 129, .65);
  --winner-shadow: 0 12px 30px rgba(16, 185, 129, .22);
}

/* =========================
   FOUC GUARD + PAGE FADE
   ========================= */
body {
  background: var(--bg);
  color: var(--text);
  opacity: 0;
  transition: opacity .25s ease;
}

body.ready {
  opacity: 1;
}

.muted {
  color: var(--muted);
}

html,
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* =========================
   CARDS
   ========================= */
.card-plain {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: linear-gradient(180deg, var(--card-grad-start), var(--card-grad-end));
  padding: 1rem;
  box-shadow: var(--shadow);
  transition: .2s box-shadow, .2s transform;
}

.card-plain:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

/* Winner highlight */
.team-card.winner {
  border: 1.5px solid var(--winner-border);
  box-shadow: var(--winner-shadow), inset 0 0 0 1px rgba(16, 185, 129, .15);
}

/* =========================
   CHIPS
   ========================= */
.chip {
  font-size: .75rem;
  padding: .25rem .6rem;
  border-radius: 999px;
  box-shadow: var(--chip-shadow);
}

.chip.small {
  font-size: .65rem;
  padding: .15rem .5rem;
}

.chip.tc {
  background: linear-gradient(180deg, var(--chip-tc-start), var(--chip-tc-end));
  color: var(--chip-tc-fg);
}

.chip.bb {
  background: linear-gradient(180deg, var(--chip-bb-start), var(--chip-bb-end));
  color: var(--chip-bb-fg);
}

.chip.fh {
  background: linear-gradient(180deg, var(--chip-fh-start), var(--chip-fh-end));
  color: var(--chip-fh-fg);
}

.chip.wc {
  background: linear-gradient(180deg, var(--chip-wc-start), var(--chip-wc-end));
  color: var(--chip-wc-fg);
}

/* =========================
   TABLE — BASE
   ========================= */
.table {
  border-radius: 12px;
  overflow: hidden;
}

thead.table-light th {
  background: linear-gradient(180deg, var(--thead-grad-start), var(--thead-grad-end));
  color: var(--text);
  font-weight: 600;
}

tbody tr {
  transition: all 0.15s ease;
}

tbody tr:hover {
  background: var(--row-hover);
  box-shadow: inset 0 1px 0 rgba(0, 0, 0, .03);
}

/* Top of GW */
tr.top-gw td {
  background: linear-gradient(180deg, var(--topgw-start), var(--topgw-end)) !important;
  box-shadow: inset 0 1px 0 rgba(16, 185, 129, .25);
  font-weight: 600;
  position: relative;
}

/* Cúp rung lắc mạnh */
.cup-badge {
  display: inline-block;
  font-size: 1.5em;
  animation: shake-strong 0.8s infinite;
  position: relative; /* để pháo hoa bắn ra từ cúp */
}

@keyframes shake-strong {
  0% { transform: translateX(0); }
  20% { transform: translateX(-6px) rotate(-10deg); }
  40% { transform: translateX(6px) rotate(10deg); }
  60% { transform: translateX(-6px) rotate(-10deg); }
  80% { transform: translateX(6px) rotate(10deg); }
  100% { transform: translateX(0); }
}

.firework {
  position: absolute;
  bottom: 100%; /* trên đỉnh cúp */
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.5em; /* gần bằng cúp */
  pointer-events: none;
  animation: fireworks 1s ease-out infinite;
}

@keyframes fireworks {
  0% { transform: translateX(-50%) translateY(0) scale(0); opacity: 1; }
  50% { transform: translateX(calc(-50% + var(--x, 0px))) translateY(var(--y, -0px)) scale(1); opacity: 0.9; }
  100% { transform: translateX(calc(-50% + var(--x, 0px))) translateY(var(--y, -0px)) scale(0); opacity: 0; }
}

/* Badge cho bét vòng */
.podium-poop {
  display:inline-flex; align-items:center; justify-content:center;
  font-size:1rem;              /* to hơn emoji */
  line-height:1;
  padding:4px 6px;
  border-radius:50%;
  background:radial-gradient(circle at center,#fecaca 0%, #fca5a5 100%);
  box-shadow:0 2px 6px rgba(0,0,0,.15);
  margin-left:.4rem;
  animation: poop-wiggle 1.8s infinite ease-in-out;
}
@keyframes poop-wiggle {
  0%,100% { transform:rotate(0deg); }
  25% { transform:rotate(-10deg); }
  75% { transform:rotate(10deg); }
}

/* Sort indicators */
th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable .sort-ind {
  opacity: .55;
  font-size: .8em;
  margin-left: 4px;
}

th.sortable.active .sort-ind {
  opacity: 1;
}

/* =========================
   TABLE — DARK FIX (Bootstrap cells)
   ========================= */
html.theme-dark .table {
  --tbl-surface: var(--card);
  --tbl-alt: #0c1222;
  --tbl-hover: #142234;
  --tbl-border: #233044;
  color: var(--text);
}

html.theme-dark .table> :not(caption)>*>* {
  background-color: var(--tbl-surface) !important;
  color: var(--text);
  border-color: var(--tbl-border) !important;
}

html.theme-dark thead.table-light th {
  background: linear-gradient(180deg, var(--thead-grad-start), var(--thead-grad-end)) !important;
  color: #cbd5e1 !important;
  border-color: var(--tbl-border) !important;
}

html.theme-dark .table-striped>tbody>tr:nth-of-type(odd)>* {
  background-color: var(--tbl-alt) !important;
}

html.theme-dark tbody tr:hover>* {
  background-color: var(--tbl-hover) !important;
}

html.theme-dark tr.top-gw>* {
  background: linear-gradient(90deg, var(--topgw-start), var(--topgw-end)) !important;
  color: #bbf7d0 !important;
  border-color: var(--tbl-border) !important;
}

/* =========================
   POINTS + HITS
   ========================= */
.points-trigger {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  background: var(--trigger-bg);
  line-height: 1;
  white-space: nowrap;
  transition: background .2s ease;
}

.points-trigger:hover {
  background: var(--trigger-bg-hover);
}

.points-trigger .bi {
  opacity: .85;
  font-size: .9em;
}

.transfer-hit-note {
  margin-top: 2px;
  font-size: .72rem;
  font-weight: 600;
  color: var(--hit-note-fg);
  opacity: .95;
  line-height: 1.1;
}

/* Pill điểm: kích thước cố định, căn giữa, bar phủ nền */
.inline-bar{
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;            /* cố định chiều cao */
  padding: 0 8px;          /* chỉ đệm ngang */
  border-radius: 8px;
  box-sizing: border-box;
  vertical-align: middle;  /* canh với text xung quanh */
  background: var(--trigger-bg);       /* nền pill thống nhất */
}

/* nền bar nằm dưới text, phủ toàn bộ pill */
.inline-bar .bar{
  position: absolute;
  inset: 0;                /* phủ toàn bộ pill */
  z-index: 0;
  border-radius: 8px;
  opacity: var(--bar-opacity);
  transform-origin: left center;
}

/* text nổi lên trên, dùng tabular-nums cho đều */
.inline-bar .txt{
  position: relative;
  z-index: 1;
  line-height: 1;                  /* tránh đội cao */
  font-variant-numeric: tabular-nums; /* số rộng đều */
  font-weight: 600;                /* tùy ý: đồng bộ với cột còn lại */
}

/* nếu muốn đẩy pill sát phải trong ô .text-end */
td.text-end .inline-bar{ margin-left: auto; }

.entry-cell strong {
  display: block;
  line-height: 1.15;
}

.entry-cell .manager-sub {
  font-size: .82rem;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.1;
}

.podium {
  font-size: .65rem;
  padding: 2px 6px;
  border-radius: 999px;
  font-weight: 700;
  aspect-ratio: 1 / 1;
  min-width: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.podium-1 {
  background: linear-gradient(180deg, #fff1a6, #facc15);
  color: #92400e;
  box-shadow: 0 0 0 1px rgba(234, 179, 8, .25) inset;
}

.podium-2 {
  background: linear-gradient(180deg, #eef2ff, #c7d2fe);
  color: #1f2937;
  box-shadow: 0 0 0 1px rgba(148, 163, 184, .25) inset;
}

.podium-3 {
  background: linear-gradient(180deg, #fde7d9, #fdba74);
  color: #7c2d12;
  box-shadow: 0 0 0 1px rgba(251, 146, 60, .25) inset;
}

.entry-cell .chip,
.entry-cell .podium {
  vertical-align: middle;
}


/* =========================
   HOVER CARD
   ========================= */
.hover-card {
  position: fixed;
  z-index: 1055;
  min-width: 340px;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow-lg);
  padding: 12px 14px;
  display: none;
  pointer-events: auto;
}

.hover-card h4 {
  margin: 2px 0 8px;
  font-size: 14px;
}

.grid-players {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px 10px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
}

.grid-players:last-child {
  border-bottom: none;
}

.badge-on {
  background: var(--on-bg);
  color: var(--on-fg);
}

.badge-bench {
  background: var(--bench-bg);
  color: var(--bench-fg);
}

.cap {
  color: #b45309;
  font-weight: 700;
}

.pos {
  font-size: 11px;
  color: var(--muted);
}

.pts {
  font-weight: 700;
  text-align: right;
  min-width: 44px;
}

.subheader {
  margin: 10px 0 4px;
  font-size: 12px;
  color: #0f172a;
  font-weight: 600;
}

html.theme-dark .subheader {
  color: #cbd5e1;
}

.hover-card.mobile {
  left: 8px !important;
  right: 8px !important;
  top: 12vh !important;
  width: auto !important;
  min-width: auto !important;
  max-width: none !important;
  max-height: 76vh !important;
  transform: none !important;
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .25);
  display: none;
  z-index: 1050;
}

/* =========================
   SKELETON SHIMMER
   ========================= */
.skel {
  position: relative;
  overflow: hidden;
  background: #e5e7eb;
  border-radius: 8px;
}

html.theme-dark .skel {
  background: #1f2937;
}

.skel::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .5), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.4s ease-in-out infinite;
  opacity: .35;
}

@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}

/* layout skeleton helpers */
.skel-line {
  height: 12px;
  margin: 6px 0;
}

.skel-lg {
  height: 24px;
  border-radius: 10px;
}

/* =========================
   NICE EXTRAS
   ========================= */
.card-plain,
.points-trigger {
  transition: all .25s ease-in-out;
}

.card-plain:hover {
  transform: translateY(-2px);
}

html.theme-dark h1,
html.theme-dark h2,
html.theme-dark h3 {
  background: linear-gradient(90deg, #38bdf8, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}


/* =========================
   SHADCN/UI INSPIRED TABLE
   ========================= */

/* Table container - clean and minimal */
.table-responsive {
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  background: var(--card);
  overflow: auto;
}

/* Base table - remove bootstrap defaults */
.table {
  margin-bottom: 0;
  font-size: 14px;
  line-height: 1.5;
}

/* Header styling - shadcn approach */
thead.table-light th {
  background: var(--card);
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  border-top: none;
  border-left: none;
  border-right: none;
  height: 48px;
}

/* Body cells - clean spacing */
tbody td {
  padding: 0.5rem !important;
  border-bottom: 1px solid var(--border);
  border-left: none;
  border-right: none;
  border-top: none;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
}

/* Row styling - subtle hover */
tbody tr {
  transition: background-color 0.15s ease;
}

tbody tr:hover td {
  background: color-mix(in srgb, var(--card) 96%, var(--text) 4%);
}

/* Last row */
tbody tr:last-child td {
  border-bottom: none;
}

/* Top GW highlighting - shadcn accent style */
tr.top-gw td {
  background: #10b981;
  font-weight: 500;
}

/* Manager cell - clean typography */
.entry-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.entry-cell strong {
  font-weight: 600;
  color: var(--text);
  font-size: 1.2rem;
  line-height: 1.4;
}

.entry-cell .manager-sub {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.3;
}

/* Sortable headers - minimal interaction */
th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color 0.15s ease;
}

th.sortable:hover {
  color: var(--text);
}

th.sortable .sort-ind {
  opacity: 0.5;
  font-size: 10px;
  margin-left: 4px;
  font-weight: 400;
}

th.sortable.active {
  color: var(--text);
}

th.sortable.active .sort-ind {
  opacity: 1;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.6);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.loading-overlay.dark {
  background: rgba(0,0,0,0.4);
}