/* ============================================================
   PB DASHBOARD — Dark theme, mobile-first
   Inspirado em "trading cockpit": denso mas legível, animações
   sutis, fontes monoespaçadas pra números.
   ============================================================ */

:root {
  /* Backgrounds (cinzas frios) */
  --bg-0: #07090d;             /* fundo da página */
  --bg-1: #0c1117;             /* cards, blocos */
  --bg-2: #131a23;             /* hover, ativo */
  --bg-3: #1c2530;             /* borda interna */

  /* Texto */
  --text:        #E6EDF3;       /* corpo */
  --text-mute:   #8B98A8;       /* secundário */
  --text-faint:  #5A6573;       /* placeholder */

  /* Acentos */
  --green:   #10D170;           /* faturado, conversão, live */
  --green-d: #0E8C4A;
  --orange:  #FF6B35;           /* destaque primário (marca) */
  --orange-d:#E55720;
  --red:     #FF4D5E;           /* alertas, erro */
  --blue:    #5BA8FF;           /* info, links */
  --yellow:  #F5B620;           /* warning */
  --purple:  #A874FF;           /* upsells */

  /* Borda */
  --border:   #1F2937;
  --border-h: #2D3845;          /* hover */

  /* Sombras */
  --shadow-card: 0 1px 0 rgba(255,255,255,0.03) inset, 0 8px 24px rgba(0,0,0,0.4);
  --shadow-pop:  0 12px 40px rgba(0,0,0,0.55);

  /* Radii */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;

  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-0);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* Show/hide por data-app-state — só renderiza o estado atual.
   Usamos !important pra vencer specificity de regras posteriores tipo
   `.loading { display: flex }` (ambos teriam (0,1,0) e a última venceria,
   deixando tudo visível ao mesmo tempo). */
[data-show-on] { display: none !important; }
body[data-app-state="loading"] [data-show-on="loading"],
body[data-app-state="login"]   [data-show-on="login"],
body[data-app-state="app"]     [data-show-on="app"]   { display: revert !important; }

/* ============================================================
   LOADING STATE
   ============================================================ */
.loading {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-0);
}
.loading__spin {
  width: 32px; height: 32px;
  border: 2.5px solid var(--bg-2);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   LOGIN
   ============================================================ */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 0%, rgba(255,107,53,0.06) 0%, transparent 70%) var(--bg-0);
}
.login__card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 32px;
  box-shadow: var(--shadow-pop);
}
.login__logo {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 28px;
}
.login__dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 0 14px var(--orange);
}
.login__brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
}
.login__title {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 6px;
}
.login__sub {
  margin: 0 0 24px;
  color: var(--text-mute);
  font-size: 13px;
}
.login__form { display: grid; gap: 6px; }
.login__label {
  font-size: 12px;
  color: var(--text-mute);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.login__inputwrap {
  position: relative;
}
.login__input {
  width: 100%;
  background: var(--bg-2);
  border: 1.5px solid var(--border);
  color: var(--text);
  padding: 14px 16px;
  border-radius: var(--r-md);
  font-size: 16px;
  font-family: var(--mono);
  letter-spacing: 0.05em;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login__input:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 4px rgba(255,107,53,0.14);
}
.login__err {
  font-size: 12px;
  color: var(--red);
  min-height: 16px;
  display: block;
  margin-top: 6px;
}
.login__btn {
  margin-top: 8px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(180deg, var(--orange) 0%, var(--orange-d) 100%);
  color: white;
  border: none;
  padding: 14px;
  border-radius: var(--r-md);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.15s;
  box-shadow: 0 6px 18px rgba(255,107,53,0.30);
}
.login__btn:hover { transform: translateY(-1px); }
.login__btn:active { transform: translateY(0); }
.login__btn:disabled { opacity: 0.6; cursor: not-allowed; }
.login__btn-spin { display: none; animation: spin 0.8s linear infinite; }
.login__btn.is-loading .login__btn-lbl { opacity: 0; }
.login__btn.is-loading .login__btn-spin { display: inline-block; }
.login__btn.is-loading { position: relative; }

/* ============================================================
   APP SHELL
   ============================================================ */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* TOPBAR */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
  position: sticky;
  top: 0;
  z-index: 30;
  flex-wrap: wrap;
  gap: 12px;
}
.topbar__left { display: flex; align-items: center; gap: 12px; }
.topbar__right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.topbar__dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 10px var(--green);
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
.topbar__brand {
  font-weight: 700;
  letter-spacing: 0.02em;
}
.topbar__chip {
  font-size: 12px;
  color: var(--text-mute);
  background: var(--bg-2);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-family: var(--mono);
}

/* PERIOD TABS */
.period {
  display: flex;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.period__btn {
  background: transparent;
  border: none;
  color: var(--text-mute);
  padding: 7px 12px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: background 0.15s, color 0.15s;
}
.period__btn:hover { color: var(--text); background: var(--bg-3); }
.period__btn.is-active {
  background: var(--bg-1);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255,255,255,0.05) inset, 0 2px 6px rgba(0,0,0,0.25);
}

/* LOGOUT btn */
.topbar__logout {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-mute);
  width: 36px; height: 36px;
  border-radius: 8px;
  display: grid; place-items: center;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.topbar__logout:hover { color: var(--red); background: var(--bg-3); }

/* ============================================================
   MAIN GRID
   ============================================================ */
.grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
  padding: 20px;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

.cards {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.block {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
  grid-column: span 6;
  min-width: 0;
}
.block--wide { grid-column: span 12; }
.block--full { grid-column: 1 / -1; }

@media (max-width: 900px) {
  .block { grid-column: 1 / -1; }
}

.block__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}
.block__title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  margin: 0;
  color: var(--text);
}
.block__hint {
  font-size: 11px;
  color: var(--text-mute);
  font-weight: 500;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}
.card--accent::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 0% 0%, rgba(16,209,112,0.10) 0%, transparent 60%);
  pointer-events: none;
}
.card__lbl {
  font-size: 11px;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.card__val {
  font-family: var(--mono);
  font-size: 32px;
  font-weight: 700;
  margin-top: 6px;
  line-height: 1.1;
  letter-spacing: -0.02em;
  /* Anima transição entre valores */
  transition: color 0.3s;
}
.card--accent .card__val { color: var(--green); }
.card__sub {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 4px;
  font-weight: 500;
}

/* ============================================================
   FUNNEL
   ============================================================ */
.funnel { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.funnel__row {
  display: grid;
  grid-template-columns: 130px 1fr 50px;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
}
.funnel__lbl {
  font-size: 12px;
  color: var(--text-mute);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.funnel__bar {
  height: 26px;
  background: var(--bg-2);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}
.funnel__bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--orange) 0%, var(--orange-d) 100%);
  border-radius: 6px;
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  min-width: 2px;
}
.funnel__row[data-paid="1"] .funnel__bar-fill {
  background: linear-gradient(90deg, var(--green) 0%, var(--green-d) 100%);
}
.funnel__val {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  text-align: right;
  color: var(--text);
}
.funnel__val[data-zero="1"] { color: var(--text-faint); font-weight: 500; }

/* ============================================================
   BARS (upsells, bumps)
   ============================================================ */
.bars { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.bars__row {
  display: grid;
  grid-template-columns: 140px 1fr 64px;
  align-items: center;
  gap: 10px;
}
.bars__lbl {
  font-size: 13px;
  color: var(--text);
  font-weight: 600;
}
.bars__lbl small { color: var(--text-mute); font-weight: 500; }
.bars__bar {
  height: 22px;
  background: var(--bg-2);
  border-radius: 5px;
  overflow: hidden;
}
.bars__bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--purple) 0%, #7E5BD8 100%);
  border-radius: 5px;
  transition: width 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  min-width: 2px;
}
.bars__row[data-kind="bump"] .bars__bar-fill {
  background: linear-gradient(90deg, var(--blue) 0%, #3F88E5 100%);
}
.bars__val {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  text-align: right;
}
.bars__val small { color: var(--text-mute); font-weight: 500; }

/* ============================================================
   CHART
   ============================================================ */
.chartwrap {
  position: relative;
  width: 100%;
}
#revenueChart { width: 100%; max-height: 260px; }

/* ============================================================
   ATTRIBUTION TREE
   ============================================================ */
.tree {
  font-family: var(--mono);
  font-size: 13px;
}
.tree__row {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 6px 0;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--border);
}
.tree__row:hover { background: var(--bg-2); border-radius: 4px; }
.tree__chev {
  width: 16px; height: 16px;
  display: grid; place-items: center;
  color: var(--text-mute);
  transition: transform 0.15s;
  font-size: 11px;
}
.tree__row[aria-expanded="true"] .tree__chev { transform: rotate(90deg); }
.tree__row[data-leaf="1"] .tree__chev { visibility: hidden; }

.tree__name {
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tree__row[data-level="0"] .tree__name { font-weight: 700; color: var(--text); }
.tree__row[data-level="1"] { padding-left: 18px; }
.tree__row[data-level="2"] { padding-left: 36px; }
.tree__row[data-level="3"] { padding-left: 54px; }
.tree__row[data-level="4"] { padding-left: 72px; color: var(--text-mute); }

.tree__val {
  color: var(--green);
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}
.tree__val small {
  color: var(--text-mute);
  font-weight: 500;
  margin-left: 6px;
}

.tree__children { display: none; }
.tree__children[data-open="1"] { display: block; }

.tree__empty {
  text-align: center;
  padding: 32px;
  color: var(--text-faint);
  font-size: 13px;
}

/* ============================================================
   MODAL (custom period)
   ============================================================ */
.modal {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  z-index: 100;
}
.modal[hidden] { display: none; }
.modal__backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
}
.modal__card {
  position: relative;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
  max-width: 380px;
  width: calc(100% - 32px);
  box-shadow: var(--shadow-pop);
}
.modal__title { margin: 0 0 16px; font-size: 16px; font-weight: 700; }
.modal__fields { display: grid; gap: 12px; margin-bottom: 20px; }
.modal__fields label {
  display: grid; gap: 4px;
  font-size: 12px;
  color: var(--text-mute);
}
.modal__fields input {
  background: var(--bg-2);
  border: 1.5px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--r-md);
  font-family: var(--mono);
  font-size: 14px;
  outline: none;
  color-scheme: dark;
}
.modal__fields input:focus { border-color: var(--orange); }
.modal__actions { display: flex; justify-content: flex-end; gap: 8px; }

.btn {
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
}
.btn--ghost:hover { background: var(--bg-3); }
.btn--primary {
  background: linear-gradient(180deg, var(--orange) 0%, var(--orange-d) 100%);
  border-color: var(--orange-d);
  color: white;
  box-shadow: 0 4px 12px rgba(255,107,53,0.25);
}
.btn--primary:hover { transform: translateY(-1px); }

/* ============================================================
   Responsivo
   ============================================================ */
@media (max-width: 640px) {
  .topbar { padding: 10px 14px; }
  .topbar__chip { display: none; }
  .grid { padding: 14px; gap: 12px; }
  .card__val { font-size: 24px; }
  .funnel__row { grid-template-columns: 96px 1fr 40px; gap: 8px; }
  .funnel__lbl { font-size: 11px; }
  .bars__row { grid-template-columns: 100px 1fr 48px; }
  .bars__lbl { font-size: 12px; }
  .period__btn { padding: 7px 10px; font-size: 11px; }
}
