/* ============================================================
   dashboard.css — Pergamino · Trilha gamificada (mobile-first)
   Requer tokens.css carregado ANTES deste arquivo.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-base);
  background: rgb(var(--surface-bg));
  color: rgb(var(--text-primary));
  min-height: 100vh;
  padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: var(--maxw-app);
  margin: 0 auto;
  position: relative;
}

/* layout padrão (mobile): tudo em fluxo */
.layout { display: block; }
.app__aside { display: block; }

/* ============================================================
   HEADER DE MÉTRICAS (full-width / conteúdo centralizado)
   ============================================================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  height: var(--header-h);
  background: rgb(var(--surface-header));
  box-shadow: var(--shadow-sm);
}
.topbar__inner {
  max-width: var(--maxw-app);
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 0 var(--space-4);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  color: rgb(var(--text-inverted));
  white-space: nowrap;
}

.topbar__metrics {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.metric {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  color: rgb(var(--text-inverted));
  line-height: 1;
}
.metric small {
  font-size: var(--fs-xs);
  font-weight: var(--fw-regular);
  opacity: .8;
}

.metric--gracas-baixo { color: #FFB454; animation: pulse-soft 1.8s ease infinite; }
.metric--gracas-vazio { opacity: .6; }

.metric__timer {
  font-size: var(--fs-xs);
  font-weight: var(--fw-regular);
  opacity: .85;
}

/* botão de tema no header */
.theme-toggle {
  background: rgb(255 255 255 / .12);
  border: none;
  color: rgb(var(--text-inverted));
  width: 36px; height: 36px;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t-fast);
}
.theme-toggle:hover { background: rgb(255 255 255 / .22); }


/* ============================================================
   BANNER DE UNIDADE / SEÇÃO (cor dinâmica vinda do banco)
   ============================================================ */
.unit-banner {
  --trilha-cor: rgb(var(--c-brand));   /* fallback se não vier do banco */
  background: linear-gradient(135deg,
              var(--trilha-cor),
              color-mix(in srgb, var(--trilha-cor) 78%, #000 22%));
  color: #fff;
  margin: var(--space-4);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  box-shadow: var(--shadow-md);
}
.unit-banner__icon {
  font-size: 1.8rem;
  flex-shrink: 0;
}
.unit-banner__info { flex: 1; min-width: 0; }
.unit-banner__eyebrow {
  display: block;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: .06em;
  opacity: .85;
  font-weight: var(--fw-medium);
}
.unit-banner__title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
}
.unit-banner__progress {
  margin-top: var(--space-2);
  height: 6px;
  background: rgb(255 255 255 / .25);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.unit-banner__progress-fill {
  height: 100%;
  background: rgb(var(--c-gold));
  border-radius: var(--radius-full);
  transition: width .6s ease;
}
.unit-banner__resumo {
  flex-shrink: 0;
  background: rgb(255 255 255 / .18);
  border: none;
  color: #fff;
  width: 36px; height: 36px;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-weight: var(--fw-bold);
  transition: background var(--t-fast), transform var(--t-fast);
}
.unit-banner__resumo:hover { background: rgb(255 255 255 / .3); transform: translateY(-1px); }


/* ============================================================
   ESTADO DE EXCEÇÃO — CARDS (sem graças / sem liga / premium / anúncio)
   ============================================================ */
.notice {
  margin: var(--space-4);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-sm);
}
.notice__title { font-weight: var(--fw-bold); font-size: var(--fs-md); }
.notice__text  { font-size: var(--fs-sm); color: rgb(var(--text-muted)); margin-top: var(--space-1); }
.notice__actions {
  display: flex; flex-wrap: wrap; gap: var(--space-2);
  margin-top: var(--space-3);
}

.notice--danger {
  background: rgb(var(--c-error-soft));
  border: 1px solid rgb(var(--c-error) / .35);
}
.notice--danger .notice__title { color: rgb(var(--c-error)); }

.notice--premium {
  background: rgb(var(--c-brand-soft));
  border: 1px solid rgb(var(--c-brand) / .3);
}
.notice--premium .notice__title { color: rgb(var(--c-brand)); }

.notice--ad {
  background: rgb(var(--surface-card));
  border: 1px dashed rgb(var(--border-strong));
  text-align: center;
  color: rgb(var(--text-muted));
  font-size: var(--fs-sm);
}
.notice--ad a { color: rgb(var(--c-brand)); font-weight: var(--fw-medium); text-decoration: none; }
.notice--ad a:hover { text-decoration: underline; }

/* botões genéricos */
.btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: 48px;
  padding: 0 var(--space-4);
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  cursor: pointer;
  text-decoration: none;
  transition: transform var(--t-fast), opacity var(--t-fast), filter var(--t-fast);
}
.btn:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.05); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:focus-visible { outline: 3px solid rgb(var(--border-focus) / .5); outline-offset: 2px; }
.btn:disabled { cursor: default; opacity: .6; }

.btn--brand  { background: rgb(var(--c-brand)); color: rgb(var(--text-inverted)); }
.btn--gold   { background: rgb(var(--c-gold));  color: rgb(var(--text-inverted)); }
.btn--green  { background: rgb(var(--c-success)); color: rgb(var(--text-inverted)); }
.btn--muted  { background: rgb(var(--surface-muted)); color: rgb(var(--text-muted)); }
.btn--ghost  {
  background: transparent;
  border: 1.5px solid rgb(var(--border-strong));
  color: rgb(var(--text-secondary));
}


/* ============================================================
   WIDGET DE LIGA
   ============================================================ */
.league {
  margin: var(--space-4);
  background: rgb(var(--surface-card));
  border: 2px solid var(--league-color, rgb(var(--c-brand)));
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}
.league__top {
  display: flex; align-items: center; gap: var(--space-3);
}
.league__icon { font-size: 1.7rem; flex-shrink: 0; }
.league__name { font-size: var(--fs-md); font-weight: var(--fw-bold); }
.league__zone {
  font-size: var(--fs-xs); font-weight: var(--fw-medium);
  padding: 2px var(--space-2); border-radius: var(--radius-full);
  width: fit-content; margin-top: 2px;
}
.league__zone--promocao     { background: rgb(var(--c-completed-soft)); color: rgb(var(--c-completed)); }
.league__zone--segura       { background: rgb(var(--surface-muted));    color: rgb(var(--text-muted)); }
.league__zone--rebaixamento { background: rgb(var(--c-error-soft));     color: rgb(var(--c-error)); }

.league__stats {
  display: flex; align-items: center; justify-content: space-around;
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid rgb(var(--border-default));
}
.league__stat { text-align: center; }
.league__stat-value { font-size: var(--fs-md); font-weight: var(--fw-black); }
.league__stat-label { font-size: var(--fs-xs); color: rgb(var(--text-muted)); }
.league__cta {
  display: block; text-align: center; margin-top: var(--space-3);
  background: var(--league-color, rgb(var(--c-brand)));
  color: #fff; text-decoration: none;
  font-weight: var(--fw-bold); font-size: var(--fs-sm);
  padding: var(--space-3); border-radius: var(--radius-full);
  min-height: 48px; line-height: 24px;
  transition: filter var(--t-fast), transform var(--t-fast);
}
.league__cta:hover { filter: brightness(1.05); transform: translateY(-1px); }

.league--inactive { border-color: rgb(var(--border-default)); opacity: .9; }
.league--inactive .league__icon { opacity: .5; }


/* ============================================================
   TRILHA EM ZIGUE-ZAGUE
   ============================================================ */
.trilha {
  padding: var(--space-6) var(--space-4) var(--space-10);
}
.trilha__section-title {
  text-align: center;
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  color: rgb(var(--text-muted));
  text-transform: uppercase;
  letter-spacing: .08em;
  margin: var(--space-6) 0 var(--space-2);
  position: relative;
}
.trilha__section-title::before,
.trilha__section-title::after {
  content: '';
  position: absolute; top: 50%;
  width: 22%; height: 1px;
  background: rgb(var(--border-strong));
}
.trilha__section-title::before { left: 0; }
.trilha__section-title::after  { right: 0; }

/* caminho dos nós */
.path {
  list-style: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
  position: relative;
}

/* posicionamento zigue-zague leve via nth-child */
.node-wrap { position: relative; }
.node-wrap:nth-child(6n+1) { transform: translateX(0); }
.node-wrap:nth-child(6n+2) { transform: translateX(-58px); }
.node-wrap:nth-child(6n+3) { transform: translateX(-58px); }
.node-wrap:nth-child(6n+4) { transform: translateX(0); }
.node-wrap:nth-child(6n+5) { transform: translateX(58px); }
.node-wrap:nth-child(6n+6) { transform: translateX(58px); }

/* ── O NÓ ── */
.node {
  --node-color: var(--c-locked);
  --node-soft:  var(--c-locked-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  position: relative;
}
.node__circle {
  width: 72px; height: 72px;
  border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem;
  background: rgb(var(--node-color));
  color: #fff;
  box-shadow: var(--shadow-node) rgb(var(--node-color) / .45);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
  position: relative;
}
.node__label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  color: rgb(var(--text-secondary));
  text-align: center;
  max-width: 110px;
  line-height: var(--lh-tight);
}
.node__xp {
  font-size: var(--fs-xs);
  color: rgb(var(--c-gold));
  font-weight: var(--fw-bold);
}

/* badge no canto do círculo */
.node__badge {
  position: absolute;
  bottom: -4px; right: -6px;
  width: 26px; height: 26px;
  border-radius: var(--radius-full);
  background: rgb(var(--surface-card));
  border: 2px solid rgb(var(--node-color));
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem;
  box-shadow: var(--shadow-sm);
}

/* ── ESTADOS ── */
.node--completed {
  --node-color: var(--c-completed);
  --node-soft:  var(--c-completed-soft);
}
.node--completed .node__badge { color: rgb(var(--c-completed)); }

.node--current {
  --node-color: var(--c-current);
  --node-soft:  var(--c-brand-soft);
}
.node--current .node__circle {
  animation: node-pulse 2s ease-in-out infinite;
}

.node--locked {
  --node-color: var(--c-locked);
  --node-soft:  var(--c-locked-soft);
  pointer-events: none;
}
.node--locked .node__circle { opacity: .7; }
.node--locked .node__label  { color: rgb(var(--text-muted)); }

.node--premium {
  --node-color: var(--c-premium);
  --node-soft:  var(--c-brand-soft);
  pointer-events: none;
}
.node--premium .node__circle { opacity: .75; }

.node--bonus {
  --node-color: var(--c-bonus);
  --node-soft:  var(--c-gold-soft);
}

.node--review .node__circle {
  background: rgb(var(--surface-card));
  color: rgb(var(--c-review));
  border: 3px dashed rgb(var(--c-review));
  box-shadow: var(--shadow-sm);
}

/* hover/focus dos nós clicáveis */
.node[href]:hover .node__circle,
.node[role="button"]:hover .node__circle {
  transform: translateY(-2px);
  box-shadow: 0 8px 0 0 rgb(var(--node-color) / .45);
}
.node[href]:active .node__circle {
  transform: translateY(4px);
  box-shadow: 0 2px 0 0 rgb(var(--node-color) / .45);
}
.node:focus-visible { outline: none; }
.node:focus-visible .node__circle {
  outline: 3px solid rgb(var(--border-focus) / .6);
  outline-offset: 4px;
}

/* balão "Começar" no nó atual */
.node__tooltip {
  position: absolute;
  top: -42px; left: 50%;
  transform: translateX(-50%);
  background: rgb(var(--surface-card));
  color: rgb(var(--c-brand));
  font-size: var(--fs-xs);
  font-weight: var(--fw-black);
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-md);
  white-space: nowrap;
  animation: bob 1.6s ease-in-out infinite;
}
.node__tooltip::after {
  content: '';
  position: absolute;
  bottom: -5px; left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 10px; height: 10px;
  background: rgb(var(--surface-card));
}

/* mascote 🕊️ ao lado do nó atual */
.node__mascot {
  position: absolute;
  top: 8px; left: -56px;
  font-size: 2rem;
  animation: float 3s ease-in-out infinite;
  pointer-events: none;
}
.node-wrap:nth-child(6n+5) .node__mascot,
.node-wrap:nth-child(6n+6) .node__mascot {
  left: auto; right: -56px;
}


/* ============================================================
   SIDENAV — barra inferior no mobile / lateral no desktop
   ============================================================ */
.sidenav {
  position: fixed;
  left: 50%; bottom: 0;
  transform: translateX(-50%);
  width: 100%; max-width: var(--maxw-app);
  height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgb(var(--surface-card));
  border-top: 1px solid rgb(var(--border-default));
  display: flex;
  z-index: var(--z-bottomnav);
  box-shadow: 0 -2px 12px rgb(44 30 18 / .08);
}
.sidenav__item {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
  min-height: 48px;
  text-decoration: none;
  color: rgb(var(--text-muted));
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  transition: color var(--t-fast), background var(--t-fast);
}
.sidenav__icon { font-size: 1.3rem; line-height: 1; }
.sidenav__item:hover { color: rgb(var(--text-secondary)); }
.sidenav__item--active { color: rgb(var(--c-brand)); }
.sidenav__item--active .sidenav__icon { transform: translateY(-1px); }


/* ============================================================
   MODAL DE RESUMO
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgb(var(--surface-overlay) / .6);
  display: flex; align-items: center; justify-content: center;
  z-index: var(--z-modal);
  padding: var(--space-4);
  backdrop-filter: blur(3px);
  animation: fade-in .2s ease;
}
.modal-overlay.is-hidden { display: none; }
.modal {
  background: rgb(var(--surface-card));
  border: 1px solid rgb(var(--border-default));
  border-radius: var(--radius-xl);
  max-width: 560px; width: 100%;
  max-height: 85vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: slide-up .25s ease;
}
.modal__header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid rgb(var(--border-default));
}
.modal__title { font-size: var(--fs-lg); font-weight: var(--fw-bold); color: rgb(var(--text-primary)); }
.modal__close {
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: var(--radius-full);
  border: 1.5px solid rgb(var(--border-default));
  background: transparent;
  font-size: 1.2rem; cursor: pointer;
  color: rgb(var(--text-muted));
  transition: background var(--t-fast), color var(--t-fast);
}
.modal__close:hover { background: rgb(var(--c-error-soft)); color: rgb(var(--c-error)); }
.modal__body {
  overflow-y: auto;
  padding: var(--space-5);
  color: rgb(var(--text-secondary));
  font-size: var(--fs-md);
  line-height: var(--lh-loose);
  white-space: pre-line;
}
.modal__refs {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid rgb(var(--border-default));
  font-size: var(--fs-sm);
  color: rgb(var(--text-muted));
}
.modal__refs strong { color: rgb(var(--c-gold)); }


/* ============================================================
   ANIMAÇÕES
   ============================================================ */
@keyframes node-pulse {
  0%, 100% { box-shadow: var(--shadow-node) rgb(var(--node-color) / .45), 0 0 0 0 rgb(var(--node-color) / .5); }
  50%      { box-shadow: var(--shadow-node) rgb(var(--node-color) / .45), 0 0 0 12px rgb(var(--node-color) / 0); }
}
@keyframes bob   { 0%,100% { transform: translateX(-50%) translateY(0); } 50% { transform: translateX(-50%) translateY(-4px); } }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes pulse-soft { 0%,100% { opacity: 1; } 50% { opacity: .55; } }
@keyframes slide-up { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes shake    { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-5px)} 75%{transform:translateX(5px)} }
.shake { animation: shake .4s ease; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}


/* ============================================================
   DESKTOP — 3 colunas: sidenav | trilha | widgets
   ============================================================ */
@media (min-width: 1024px) {

  /* não precisa mais de espaço para a barra inferior */
  body { padding-bottom: 0; }

  /* header full-width, conteúdo alinhado ao grid */
  .app { max-width: 100%; }
  .topbar__inner { max-width: 1200px; }

  /* grid de 3 colunas centralizado */
  .layout {
    display: grid;
    grid-template-columns: 240px minmax(0, 600px) 320px;
    gap: var(--space-6);
    justify-content: center;
    align-items: start;
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-6) var(--space-4) var(--space-12);
  }

  /* ── MENU LATERAL VERTICAL (ícone + texto) ── */
  .sidenav {
    position: sticky;
    top: calc(var(--header-h) + var(--space-6));
    left: auto; bottom: auto;
    transform: none;
    width: 100%; max-width: none;
    height: auto;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-3);
    border-top: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
  }
  .sidenav__item {
    flex: none;
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--fs-md);
    font-weight: var(--fw-bold);
  }
  .sidenav__icon { font-size: 1.4rem; }
  .sidenav__item:hover { background: rgb(var(--surface-muted)); }
  .sidenav__item--active {
    background: rgb(var(--c-brand-soft));
    color: rgb(var(--c-brand));
  }

  /* ── TRILHA CENTRAL ── */
  .trilha { padding: 0 0 var(--space-12); }

  /* ── COLUNA DE WIDGETS (direita) ── */
  .app__aside {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    position: sticky;
    top: calc(var(--header-h) + var(--space-6));
  }
  .app__aside .league,
  .app__aside .notice { margin: 0; }

  /* zigue-zague um pouco mais aberto no desktop */
  .node__circle { width: 84px; height: 84px; font-size: 2.3rem; }
  .node-wrap:nth-child(6n+2),
  .node-wrap:nth-child(6n+3) { transform: translateX(-80px); }
  .node-wrap:nth-child(6n+5),
  .node-wrap:nth-child(6n+6) { transform: translateX(80px); }
}

/* telas muito largas: mais respiro */
@media (min-width: 1440px) {
  .layout { grid-template-columns: 260px minmax(0, 640px) 360px; gap: var(--space-8); max-width: 1320px; }
  .topbar__inner { max-width: 1320px; }
}
