/* ============================================================
   Ligas DrawPhase · estrutura partilhada (site público + Backstage)
   Barra lateral, topo com a data e tema claro/escuro (escolhido no
   topo; por omissão é o escuro). Carregar depois de style.css.
   ============================================================ */

/* ---------- Tema escuro ---------- */

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #13101a;
  --surface: #1a1623;
  --surface-2: #211c2c;
  --text: #f3f0f9;
  --muted: #a49eb4;
  --faint: #6f6981;
  --line: #2a2437;
  --line-strong: #3a3249;
  --brand-soft: #2a1f45;
  --danger: #f0806c;
  --ok: #62d08b;
  --warn: #f2b84b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 18px 40px -24px rgba(0, 0, 0, 0.6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #13101a;
    --surface: #1a1623;
    --surface-2: #211c2c;
    --text: #f3f0f9;
    --muted: #a49eb4;
    --faint: #6f6981;
    --line: #2a2437;
    --line-strong: #3a3249;
    --brand-soft: #2a1f45;
    --danger: #f0806c;
    --ok: #62d08b;
    --warn: #f2b84b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 18px 40px -24px rgba(0, 0, 0, 0.6);
  }
}

:root {
  --warn: #b7791f;
  --sidebar-w: 256px;
}

body {
  background: var(--bg);
}

.shell svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* No escuro, o tom de texto da cor da liga clareia em vez de escurecer. */
:root[data-theme="dark"] body,
:root[data-theme="dark"] .league-card {
  --accent-ink: color-mix(in srgb, var(--accent) 60%, #fff);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body,
  :root:not([data-theme="light"]) .league-card {
    --accent-ink: color-mix(in srgb, var(--accent) 60%, #fff);
  }
}

/* Logótipos pretos (One Piece) passam a brancos no escuro. */
:root[data-theme="dark"] .logo-invert-dark {
  filter: invert(1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-invert-dark {
    filter: invert(1);
  }
}

/* Logótipos com versão própria para cada tema (Lorcana). */
.logo-on-dark {
  display: none !important;
}

:root[data-theme="dark"] .logo-on-dark {
  display: block !important;
}

:root[data-theme="dark"] .logo-on-light {
  display: none !important;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-on-dark {
    display: block !important;
  }

  :root:not([data-theme="light"]) .logo-on-light {
    display: none !important;
  }
}

/* ---------- Estrutura ---------- */

.shell {
  display: flex;
  min-height: 100vh;
}

.main-col {
  flex: 1;
  min-width: 0;
}

.main-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 40px 0;
}

.today {
  font-size: 14.5px;
  color: var(--muted);
}

.theme-toggle {
  display: inline-flex;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.theme-toggle button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
}

.theme-toggle button:hover {
  color: var(--text);
}

.theme-toggle button[aria-pressed="true"] {
  background: var(--surface-2);
  color: var(--text);
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
}

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 40px 80px;
}

/* ---------- Barra lateral ---------- */

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w);
  height: 100vh;
  flex-shrink: 0;
  padding: 22px 16px 18px;
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.side-logo {
  width: 132px;
  margin: 0 0 18px 10px;
}

.side-label {
  margin: 14px 12px 6px;
  font-size: 13px;
  color: var(--faint);
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.side-item svg {
  width: 19px;
  height: 19px;
  flex-shrink: 0;
}

.side-item .league-dot {
  margin: 0 5px;
  flex-shrink: 0;
}

.side-item:hover {
  background: var(--surface);
  color: var(--text);
}

.side-item.is-active {
  background: color-mix(in srgb, var(--brand) 18%, var(--surface));
  color: color-mix(in srgb, var(--brand) 70%, var(--text));
}

.side-bottom {
  margin-top: auto;
  padding-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.side-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 4px 0;
  border-top: 1px solid var(--line);
}

.side-avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 13.5px;
  font-weight: 600;
}

.side-user-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.side-user-email {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-user-role {
  font-size: 12.5px;
  color: var(--faint);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--surface);
  color: var(--text);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* ---------- Botões e estados ---------- */

body .btn {
  border-radius: 12px;
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

body .btn:hover {
  background: var(--brand-mid);
  border-color: var(--brand-mid);
}

body .btn svg {
  width: 17px;
  height: 17px;
}

body .btn-ghost {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--text);
}

body .btn-ghost:hover {
  background: var(--surface);
  border-color: var(--brand);
  color: var(--text);
}

.btn-glow {
  box-shadow: 0 10px 30px -10px color-mix(in srgb, var(--brand) 80%, transparent);
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--brand);
  font-size: 14.5px;
  font-weight: 500;
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

body .status-em_curso {
  background: color-mix(in srgb, var(--ok) 12%, var(--surface));
  border-color: color-mix(in srgb, var(--ok) 30%, var(--surface));
}

body .status-inscricoes_abertas {
  background: color-mix(in srgb, #4b82e0 12%, var(--surface));
  border-color: color-mix(in srgb, #4b82e0 30%, var(--surface));
}

/* ---------- Cabeçalho da página ---------- */

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.page-head .league-head-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--muted);
}

.page-head .league-dot {
  width: 10px;
  height: 10px;
}

.page-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(30px, 4vw, 42px);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.page-sub {
  margin: 8px 0 0;
  font-size: 15px;
  color: var(--muted);
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.season-select {
  width: auto;
  min-width: 190px;
  padding-top: 11px;
  padding-bottom: 11px;
  border-radius: 12px;
}

/* ---------- Cartões de resumo ---------- */

.stats-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  margin-bottom: 18px;
}

.stat-skeleton {
  height: 196px;
}

.stats-grid .state-card {
  grid-column: 1 / -1;
}

.stat-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 24px 26px;
  border-radius: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.stat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: auto;
  padding-bottom: 24px;
}

.stat-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--brand-soft);
  color: var(--brand);
}

.stat-icon svg {
  width: 20px;
  height: 20px;
}

.stat-label {
  margin: 0;
  font-size: 15px;
  color: var(--muted);
}

.stat-value {
  margin: 0;
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.stat-value-name {
  font-size: 26px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-value-xl {
  margin-top: 6px;
  font-size: 38px;
}

.stat-sub {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.stat-hero {
  flex-direction: row;
  align-items: center;
  gap: 18px;
  position: relative;
  overflow: hidden;
  border-color: color-mix(in srgb, var(--brand) 45%, var(--line));
  background:
    radial-gradient(120% 140% at 0% 0%, color-mix(in srgb, var(--brand) 32%, transparent), transparent 60%),
    linear-gradient(160deg, color-mix(in srgb, var(--brand-dark) 70%, var(--surface)), var(--surface));
  box-shadow: 0 24px 60px -30px color-mix(in srgb, var(--brand) 70%, transparent);
}

.stat-hero-text {
  flex: 1;
  min-width: 0;
}

.stat-hero .stat-label,
.stat-hero .stat-sub {
  color: color-mix(in srgb, var(--text) 75%, transparent);
}

:root:not([data-theme="dark"]) .stat-hero {
  color: #fff;
  --text: #fff;
  background:
    radial-gradient(120% 140% at 0% 0%, rgba(196, 167, 255, 0.45), transparent 60%),
    var(--brand-gradient);
  border-color: transparent;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .stat-hero {
    color: var(--text);
    --text: #f3f0f9;
    background:
      radial-gradient(120% 140% at 0% 0%, color-mix(in srgb, var(--brand) 32%, transparent), transparent 60%),
      linear-gradient(160deg, color-mix(in srgb, var(--brand-dark) 70%, var(--surface)), var(--surface));
    border-color: color-mix(in srgb, var(--brand) 45%, var(--line));
  }
}

.ring {
  position: relative;
  width: 108px;
  height: 108px;
  flex-shrink: 0;
}

.ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring circle {
  stroke-width: 8;
  stroke-linecap: round;
}

.ring-track {
  stroke: rgba(255, 255, 255, 0.14);
}

.ring-fill {
  stroke: #c4a7ff;
  filter: drop-shadow(0 0 6px rgba(196, 167, 255, 0.55));
}

.ring-value {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
}

/* A barra lateral passa para o topo, com as listas a deslizar na horizontal. */
@media (max-width: 900px) {
  .shell {
    flex-direction: column;
  }

  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    padding: 14px 16px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: visible;
  }

  .side-logo {
    width: 64px;
    margin: 0 0 10px 4px;
  }

  .side-label {
    display: none;
  }

  .side-nav {
    flex-direction: row;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 6px;
  }

  .side-nav::-webkit-scrollbar {
    display: none;
  }

  .side-item {
    width: auto;
    flex-shrink: 0;
    white-space: nowrap;
    padding: 8px 12px;
    font-size: 14px;
  }

  .side-bottom {
    position: absolute;
    top: 12px;
    right: 16px;
    flex-direction: row;
    align-items: center;
    padding: 0;
    margin: 0;
  }

  .side-bottom > .side-item {
    display: none;
  }

  .side-user {
    padding: 0;
    border: 0;
  }

  .side-avatar {
    width: 34px;
    height: 34px;
    font-size: 12px;
  }

  .side-user-text {
    display: none;
  }

  .main-top {
    padding: 16px 16px 0;
  }

  .site-footer {
    padding: 0 16px 28px;
  }

  .page {
    padding: 20px 16px 64px;
  }
}

/* ---------- Cartões de resumo: ecrãs médios e telemóvel ---------- */

@media (max-width: 1100px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat-hero {
    grid-column: 1 / -1;
  }
}

@media (max-width: 680px) {
  .stats-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .stat-card {
    padding: 20px 18px;
    border-radius: 20px;
  }

  .stat-value-xl {
    font-size: 30px;
  }

  .ring {
    width: 84px;
    height: 84px;
  }

  .ring-value {
    font-size: 18px;
  }

  .page-actions,
  .season-select {
    width: 100%;
  }

  .page-actions .btn {
    flex: 1;
  }
}
