:root {
  --blue: #1e40af;
  --blue-dark: #172554;
  --blue-soft: #dbeafe;
  --orange: #f97316;
  --orange-soft: #ffedd5;
  --green: #22c55e;
  --green-soft: #dcfce7;
  --red: #ef4444;
  --red-soft: #fee2e2;
  --gray-50: #f8fafc;
  --gray-100: #eef2f7;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-500: #64748b;
  --gray-700: #334155;
  --gray-900: #0f172a;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: linear-gradient(180deg, #eff6ff 0%, #f8fafc 100%); color: var(--gray-900); }
button, input, select { font: inherit; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
.container { width: min(1120px, calc(100% - 32px)); margin: 0 auto; }
.app-shell { min-height: 100vh; padding-bottom: 40px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 22px 0; }
.brand-row { display: flex; align-items: center; gap: 14px; }
.brand-logo { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 16px; background: linear-gradient(135deg, var(--blue), var(--orange)); color: white; font-size: 1.6rem; box-shadow: var(--shadow); }
h1 { font-size: 2rem; margin: 0 0 4px; }
h2, h3, h4, p { margin-top: 0; }
.muted { color: var(--gray-500); }
.card { background: rgba(255,255,255,0.95); border: 1px solid rgba(203,213,225,0.8); border-radius: var(--radius); box-shadow: var(--shadow); }
.hero-card { display: flex; justify-content: space-between; gap: 20px; align-items: center; padding: 28px; margin-bottom: 18px; }
.eyebrow { display: inline-block; padding: 6px 10px; border-radius: 999px; background: var(--blue-soft); color: var(--blue); font-weight: 700; font-size: .8rem; margin-bottom: 10px; }
.hero-badges { display: flex; flex-wrap: wrap; gap: 10px; }
.badge { display: inline-flex; align-items: center; justify-content: center; padding: 6px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; }
.badge-blue { color: var(--blue); background: var(--blue-soft); }
.badge-orange { color: var(--orange); background: var(--orange-soft); }
.badge-green { color: #15803d; background: var(--green-soft); }
.badge-gray { color: var(--gray-700); background: var(--gray-100); }
.badge-red { color: #b91c1c; background: var(--red-soft); }
.topbar-actions, .inline-actions, .toolbar-row { display: flex; gap: 10px; align-items: center; }
.toolbar-row { justify-content: space-between; margin-bottom: 18px; }
.search-box { flex: 1; }
.search-box input, .form-grid input, .form-grid select { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--gray-300); background: white; color: var(--gray-900); transition: .18s ease; }
.search-box input:focus, .form-grid input:focus, .form-grid select:focus { border-color: var(--blue); outline: 3px solid rgba(30,64,175,.15); }
.btn { border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 700; cursor: pointer; transition: .2s ease; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--blue); color: white; }
.btn-orange { background: var(--orange); color: white; }
.btn-secondary { background: white; color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-ghost { background: var(--gray-100); color: var(--gray-700); }
.icon-btn { border: none; background: transparent; font-size: 1.1rem; cursor: pointer; color: var(--gray-500); }
.tournament-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(245px, 1fr)); gap: 18px; }
.tournament-card { position: relative; overflow: hidden; padding: 18px; }
.tournament-card::before { content: ""; position: absolute; inset: 0 auto auto 0; width: 100%; height: 5px; background: linear-gradient(90deg, var(--blue), var(--orange)); }
.tournament-card h3 { margin-bottom: 6px; }
.meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin-top: 16px; }
.meta-item { font-size: .92rem; color: var(--gray-700); display: flex; align-items: center; gap: 8px; }
.card-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; }
.empty-state { padding: 42px; text-align: center; }
.empty-icon { font-size: 2.2rem; margin-bottom: 8px; }
.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 40; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(2px); }
.modal-panel { position: relative; width: min(720px, calc(100% - 24px)); background: white; border-radius: 18px; box-shadow: 0 30px 80px rgba(15,23,42,.2); padding: 22px; animation: modalIn .18s ease; }
.small-modal { width: min(420px, calc(100% - 24px)); }
@keyframes modalIn { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.compact-grid { grid-template-columns: 1fr 1fr; }
.form-grid label { display: grid; gap: 8px; font-weight: 600; color: var(--gray-700); }
.full-span { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }
.back-link { display: inline-block; color: var(--gray-500); margin-bottom: 14px; }
.tournament-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 24px; background: rgba(255,255,255,.9); border: 1px solid rgba(203,213,225,.8); border-radius: var(--radius); box-shadow: var(--shadow); min-width: min(760px, 100%); }
.tournament-title-row { display: flex; gap: 14px; align-items: center; }
.sport-icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; font-size: 1.5rem; background: linear-gradient(135deg, #fde68a, #fb923c); }
.tabs { display: flex; gap: 6px; padding: 8px; margin: 18px 0; overflow: auto; }
.tab-btn { padding: 10px 14px; border: none; background: transparent; border-radius: 12px; cursor: pointer; color: var(--gray-500); font-weight: 700; white-space: nowrap; }
.tab-btn.active { background: var(--blue); color: white; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.section-card { padding: 18px; margin-bottom: 18px; }
.section-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 16px; }
.fields-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.field-card { padding: 16px; border: 2px solid var(--gray-200); transition: .2s ease; }
.field-card.live { border-color: #86efac; background: #f0fdf4; }
.field-card.pending { border-color: var(--gray-200); background: white; }
.field-card.finished { border-color: #bfdbfe; background: #eff6ff; }
.versus { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; margin-top: 16px; }
.score-big { font-size: 2rem; font-weight: 800; color: var(--blue); }
.score-big.away { color: var(--orange); }
.team-name { font-weight: 700; }
.team-line { display: flex; align-items: center; gap: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: 0 0 12px; }
.round-block { margin-bottom: 18px; }
.round-label { display: inline-flex; padding: 6px 10px; border-radius: 10px; background: var(--gray-100); color: var(--gray-700); font-weight: 700; font-size: .8rem; margin-bottom: 8px; }
.match-card { padding: 14px; border: 1px solid #bfdbfe; background: #f8fbff; border-radius: 14px; margin-bottom: 10px; }
.match-card.live { border-color: #86efac; background: #f0fdf4; }
.match-card.done { border-color: #bfdbfe; background: #eff6ff; }
.match-topline, .match-actions, .team-row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.match-main { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; padding: 8px 0; }
.match-score { font-size: 1.9rem; font-weight: 800; text-align: center; }
.status-pill { padding: 6px 10px; border-radius: 999px; font-size: .75rem; font-weight: 800; }
.status-pending { background: var(--gray-100); color: var(--gray-700); }
.status-live { background: var(--green-soft); color: #15803d; }
.status-done { background: var(--blue-soft); color: var(--blue); }
.manner-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.manner-btn { border: 1px solid var(--gray-300); background: white; border-radius: 10px; padding: 8px 10px; cursor: pointer; font-weight: 700; min-width: 84px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--gray-200); text-align: left; white-space: nowrap; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--gray-500); }
.rank-1 { color: #ca8a04; font-weight: 800; }
.rank-2 { color: #94a3b8; font-weight: 800; }
.rank-3 { color: #b45309; font-weight: 800; }
.violet-text { color: #7c3aed; font-weight: 800; }
.team-layout { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; }
.list-stack { display: flex; flex-direction: column; gap: 10px; }
.team-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px; border-radius: 14px; border: 1px solid var(--gray-200); background: white; }
.color-picker { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.color-choice { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.color-choice.active { outline: 3px solid rgba(30,64,175,.25); border-color: white; }
.bareme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.bareme-item { padding: 14px; border-radius: 14px; border: 1px solid var(--gray-200); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.bareme-item.green { background: #ecfdf5; border-color: #bbf7d0; color: #059669; }
.bareme-item.gray { background: #f8fafc; color: #475569; }
.bareme-item.red { background: #fef2f2; border-color: #fecaca; color: #dc2626; }
.team-detail-list { display: grid; gap: 10px; }
.team-detail-row { border: 1px solid var(--gray-200); border-radius: 12px; padding: 12px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.sync-info { font-size: .85rem; color: var(--gray-500); }
.toast { position: fixed; right: 18px; bottom: 18px; background: var(--gray-900); color: white; padding: 12px 14px; border-radius: 12px; box-shadow: var(--shadow); z-index: 60; animation: fadeIn .18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 860px) {
  .topbar, .toolbar-row, .section-header, .team-layout, .hero-card, .tournament-header { flex-direction: column; align-items: stretch; }
  .form-grid, .bareme-grid { grid-template-columns: 1fr; }
  .team-layout { display: block; }
  .fields-grid, .tournament-grid { grid-template-columns: 1fr; }
  .match-main, .versus { grid-template-columns: 1fr; text-align: center; }
  .match-topline, .match-actions, .team-row-between { flex-wrap: wrap; }
  .responsive-stack { align-self: stretch; display: grid; grid-template-columns: 1fr; }
}
.round-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #1e40af;
  background: rgba(30, 64, 175, 0.10);
  border: 1px solid rgba(30, 64, 175, 0.18);
}

.field-card[data-action="open-field-match"] {
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.field-card[data-action="open-field-match"]:hover {
  transform: translateY(-2px);
}

.toast-root {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  background: #111827;
  color: #fff;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s ease;
  box-shadow: 0 12px 28px rgba(0,0,0,0.2);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.field-card-hint {
  margin-top: 0.75rem;
  font-size: 0.82rem;
}
/* =========================
   MATCH CARDS V2
========================= */

.match-card {
  border: 1px solid #dbe7f5;
  border-radius: 18px;
  background: #f8fbff;
  padding: 1rem;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.05);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.match-card.live {
  border-color: rgba(34, 197, 94, 0.35);
  background: #f3fff8;
}

.match-card.done {
  border-color: rgba(59, 130, 246, 0.18);
  background: #f7fbff;
}

.match-card.pending {
  border-color: rgba(30, 64, 175, 0.12);
  background: #f9fbff;
}

.match-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
}

.match-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.match-meta-left,
.match-meta-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.match-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: #eef4ff;
  color: #475569;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid #dbe7f5;
}

.match-card-main {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 140px minmax(220px, 1fr);
  align-items: center;
  gap: 1.25rem;
}

.match-team-block {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-width: 0;
  width: 100%;
}

.match-team-block.align-right {
  align-items: flex-end;
}
.match-team-block.align-right .manner-btn {
  margin-left: auto;
}

.match-team-name {
  font-weight: 700;
  font-size: 1rem;
  color: #0f172a;
  min-width: 0;
  width: 100%;
}

.match-team-name span:last-child {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.match-team-name.right {
  justify-content: flex-end;
  text-align: right;
}

.match-score-block {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 140px;
}

.match-score-big {
  font-size: 2.3rem;
  font-weight: 800;
  line-height: 1;
  color: #0f172a;
  letter-spacing: -0.02em;
  text-align: center;
  width: 100%;
}

.match-score-big span {
  color: #f97316;
  padding: 0 0.2rem;
}

.manner-btn {
  width: 100%;
  max-width: 240px;
  min-height: 42px;
  border-radius: 12px;
  border: 1px solid #d6dee8;
  background: #fff;
  color: #0f172a;
  font-weight: 700;
  font-size: 0.92rem;
  padding: 0.45rem 0.8rem;
  transition: all 0.15s ease;
}

.manner-btn:hover {
  border-color: #93c5fd;
  box-shadow: 0 6px 18px rgba(30, 64, 175, 0.08);
}

.match-card-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  padding-top: 0.35rem;
  border-top: 1px solid #e7eef8;
}

.match-card-actions .btn {
  min-height: 42px;
}

/* blocs de tour */
.round-block {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-bottom: 1.35rem;
}

.round-label {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  background: #eef2f7;
  color: #334155;
  font-size: 0.84rem;
  font-weight: 700;
}

/* =========================
   MOBILE
========================= */
@media (min-width: 1024px) {
  .match-card {
    padding: 1.1rem 1.2rem;
  }

  .match-card-main {
    grid-template-columns: minmax(260px, 1fr) 140px minmax(260px, 1fr);
    gap: 1.5rem;
  }

  .manner-btn {
    max-width: 220px;
  }
}

@media (max-width: 768px) {
  .match-card {
    padding: 0.9rem;
    gap: 0.9rem;
    border-radius: 16px;
  }

  .match-card-main {
    grid-template-columns: 1fr;
    gap: 0.9rem;
    text-align: center;
  }

  .match-team-block,
  .match-team-block.align-right {
    align-items: center;
  }

  .match-team-name,
  .match-team-name.right {
    justify-content: center;
    text-align: center;
  }

  .match-team-name span:last-child {
    white-space: normal;
    text-overflow: initial;
    overflow: visible;
  }

  .match-score-big {
    font-size: 2.3rem;
    min-width: auto;
  }

  .match-card-actions {
    justify-content: stretch;
  }

  .match-card-actions .btn {
    flex: 1 1 100%;
    width: 100%;
  }

  .manner-btn {
    width: 100%;
    max-width: 180px;
  }
}

@media (max-width: 480px) {
  .match-chip {
    font-size: 0.76rem;
    padding: 0.32rem 0.58rem;
  }

  .match-score-big {
    font-size: 2rem;
  }

  .match-team-name {
    font-size: 0.95rem;
  }

  .manner-btn {
    min-height: 38px;
    font-size: 0.88rem;
  }
}