/* =========================================================
   Bancada TCG — folha de estilo única

   O tema escuro é o único automático: o manual da marca manda usar
   o carvão institucional, então o site não acompanha mais a
   preferência do sistema. O tema claro continua inteiro aqui e entra
   com <html data-theme="light"> — é o que um botão de tema usaria.

   Cores nomeadas seguem a paleta do manual:
   Areia #F8E9C9 · Azul #2563EB · Roxo #7C3AED · Vermelho #DC2626
   Verde #16A34A · Dourado #D4AF37 · Marrom #8B5E3C · Carvão #0F172A
   ========================================================= */

:root {
  color-scheme: dark;

  /* Paleta ESCURA — padrão */
  --bg:        #0F172A;
  --surface:   #18202F;
  --surface-2: #212B3D;
  --line:      #2E3A50;
  --ink:       #EDEAE2;
  --ink-soft:  #9A9DB0;
  --ink-faint: #6C7085;
  --brass:     #D4AF37;
  --brass-dim: #A8872B;
  /* Marrom da bancada. O #8B5E3C puro dá 3,2:1 no carvão — serve para
     traço e fundo, não para texto; por isso o par claro logo abaixo. */
  --wood:      #8B5E3C;
  --wood-ink:  #C08E62;
  --ok:        #4BA86A;
  --warn:      #D9A441;
  --danger:    #D4574A;
  --shadow:    0 1px 2px rgba(0,0,0,.45), 0 8px 24px rgba(0,0,0,.28);

  --w:   #F8E9C9;
  --u:   #2563EB;
  --b:   #853EFE;
  --r:   #DC2626;
  --g:   #16A34A;
  --c:   #9A9DB0;

  --display: "Montserrat", "Helvetica Neue", Arial, sans-serif;
  --body:    "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono:    "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;

  --r-sm: 4px;
  --r-md: 7px;
  --gap:  14px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg:        #F7F5F0;
  --surface:   #FFFFFF;
  --surface-2: #F0EDE6;
  --line:      #DCD7CC;
  --ink:       #1F2027;
  --ink-soft:  #5B5F70;
  --ink-faint: #8B8FA0;
  --brass:     #AA8C2C;
  --brass-dim: #D4AF37;
  /* No fundo areia o marrom puro já dá 5,1:1, então serve de texto. */
  --wood-ink:  #8B5E3C;
  --ok:        #2F7D4B;
  --warn:      #A9761A;
  --danger:    #B03A2E;
  --shadow:    0 1px 2px rgba(31,32,39,.08), 0 8px 24px rgba(31,32,39,.07);
  --w:         #A78D41;
  --b:         #7C3AED;
  --c:         #6C7085;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }

a { color: var(--brass); }

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
  border-radius: 2px;
}

.wrap {
  max-width: 1360px;
  margin: 0 auto;
  padding-inline: 16px;
  padding-block: 0 48px;
}

/* ---------------------------------------------------- topo */

.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 40;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.topbar-in {
  max-width: 1360px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: var(--gap);
  flex-wrap: wrap;
}

/* O brasão à esquerda e, separada por um fio, a ferramenta aberta.
   Quando houver uma segunda ferramenta, só o rótulo à direita muda. */
.brandblock { display: flex; align-items: center; }

/* O <h1> só embrulha a imagem: zera altura de linha para ele não
   somar espaço fantasma abaixo do brasão. */
.brand { margin: 0; line-height: 0; font-size: 0; }

.brandmark {
  height: 48px;
  width: auto;
  display: block;
}

.tool-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-soft);
  white-space: nowrap;
  margin-left: 12px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
}

.topbar-spacer { flex: 1 1 auto; }

/* ------------------------------------------- medidor de orçamento */

.budget {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 8px 14px;
  min-width: 260px;
}

.budget-figures { display: flex; align-items: baseline; gap: 6px; }

.budget-now {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 23px;
  font-weight: 600;
  line-height: 1;
  color: var(--ok);
  white-space: nowrap;
}
.budget.over .budget-now { color: var(--danger); }
.budget.near .budget-now { color: var(--warn); }

.budget-of {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--ink-faint);
  white-space: nowrap;
}

.budget-bar {
  flex: 1 1 70px;
  max-width: 150px;
  height: 6px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
}
.budget-fill {
  height: 100%;
  width: 0;
  background: var(--ok);
  border-radius: 99px;
  transition: width .18s ease, background-color .18s ease;
}
.budget.near .budget-fill { background: var(--warn); }
.budget.over .budget-fill { background: var(--danger); }

.budget-limit-input {
  width: 92px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 5px 8px;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  text-align: right;
}

/* ---------------------------------------------------- botões */

.btn {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: var(--r-sm);
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .12s, background-color .12s;
}
.btn:hover { border-color: var(--brass-dim); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--brass);
  border-color: var(--brass);
  color: #0F172A;
  font-weight: 600;
}
.btn-primary:hover { background: var(--brass-dim); border-color: var(--brass-dim); color: #fff; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-ghost:hover { color: var(--ink); border-color: var(--line); }

.btn-sm { padding: 4px 8px; font-size: 12.5px; }

/* --------------------------------------------- faixa de contexto */

.meta {
  display: grid;
  grid-template-columns: minmax(0,1fr) minmax(0,1.6fr) auto;
  gap: var(--gap);
  align-items: stretch;
  margin-top: 18px;
}

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }

.field-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.field input, .field textarea {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 9px 11px;
  width: 100%;
  resize: vertical;
}
.field input::placeholder, .field textarea::placeholder { color: var(--ink-faint); }
.field textarea { min-height: 58px; }

.field-hint { font-size: 11.5px; color: var(--ink-faint); }

.tally {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 10px 14px;
  min-width: 150px;
}
.tally-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-size: 12.5px;
  color: var(--ink-soft);
}
.tally-row b {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 600;
}
.tally-total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 5px; }
.tally-total.bad b { color: var(--danger); }
.tally-total.good b { color: var(--ok); }

/* ------------------------------------------------------- abas */

.tabs {
  display: flex;
  gap: 2px;
  margin-top: 20px;
  border-bottom: 1px solid var(--line);
}

.tab {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--ink-soft);
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 500;
  margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--brass);
  font-weight: 600;
}

/* --------------------------------------------------- métricas */

/* Par validado contra as duas superfícies (escura e clara) para
   separação sob daltonismo, contraste e faixa de luminosidade.
   O "depois" leva o destaque; o "antes" fica como contexto. */
:root {
  --series-before: #5878B4;
  --series-after:  #C08828;
}

#view-metricas { padding-top: 18px; }

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--gap);
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.stat-line { display: flex; align-items: baseline; gap: 8px; }

.stat-value {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 27px;
  font-weight: 600;
  line-height: 1.1;
  color: var(--ink);
}
.stat-value.tone-good { color: var(--ok); }
.stat-value.tone-bad  { color: var(--danger); }

.stat-delta {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.stat-note {
  font-size: 11.5px;
  color: var(--ink-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ------------------------------------------------------ legenda */

.legend {
  display: flex;
  gap: 16px;
  margin-top: 18px;
  font-size: 12px;
  color: var(--ink-soft);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 11px; height: 11px; border-radius: 2px; display: inline-block; }
.swatch-before { background: var(--series-before); }
.swatch-after  { background: var(--series-after); }

/* ------------------------------------------------------ gráficos */

.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: var(--gap);
  margin-top: 10px;
  align-items: start;
}

.chart {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 16px 12px;
  margin: 0;
  min-width: 0;
}

.chart-title {
  font-family: var(--display);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.chart-sub {
  font-size: 11.5px;
  color: var(--ink-faint);
  margin: 3px 0 0;
  line-height: 1.45;
}

/* --------------------------------------------- curva (vertical) */

.curve-wrap { margin-top: 16px; }

.curve {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  /* Linha de base fina, exatamente onde as barras nascem.
     Nada de tracejado, que só adiciona ruído. */
  border-bottom: 1px solid var(--line);
}

.curve-axis {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}

.curve-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
}

.curve-bars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;          /* respiro entre as duas barras */
  height: 118px;
  width: 100%;
}

.bar-slot { flex: 1 1 0; height: 100%; display: flex; align-items: flex-end; max-width: 15px; }

.bar {
  width: 100%;
  min-height: 2px;
  border-radius: 3px 3px 0 0;   /* ponta arredondada, base ancorada */
  transition: height .18s ease;
}
.bar-before { background: var(--series-before); }
.bar-after  { background: var(--series-after); }

.curve-val {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--ink-soft);
  margin-bottom: 3px;
  min-height: 14px;
}

/* Rótulo do eixo, abaixo da linha de base. */
.curve-x {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  padding-top: 5px;
  text-align: center;
}

/* ------------------------------------------ barras horizontais */

.hbars { display: flex; flex-direction: column; gap: 9px; margin-top: 15px; }

.hbar-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) 30px;
  align-items: center;
  gap: 9px;
}

.hbar-label {
  font-size: 12px;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hbar-track {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.hbar {
  height: 7px;
  min-width: 2px;
  border-radius: 0 3px 3px 0;
  transition: width .18s ease;
}
.hbar-before { background: var(--series-before); }
.hbar-after  { background: var(--series-after); }

.hbar-target {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 1px;
  background: var(--ink-faint);
}

.hbar-val {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--ink);
  text-align: right;
}

/* ------------------------------------------------- três colunas */

.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--gap);
  margin-top: 18px;
  align-items: start;
}

.pile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.pile-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 13px 9px;
  border-bottom: 1px solid var(--line);
}

.pile-title {
  font-family: var(--display);
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  letter-spacing: .01em;
}
/* Uma cor por pilha, tiradas da paleta: a madeira da bancada para o que
   já está montado, vermelho para o que sai, verde para o que entra. */
.pile--deck .pile-title { color: var(--wood-ink); }
.pile--out  .pile-title { color: var(--danger); }
.pile--in   .pile-title { color: var(--ok); }

.pile-count {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--ink-faint);
  background: var(--surface-2);
  border-radius: 99px;
  padding: 1px 8px;
}
.pile-head-spacer { flex: 1; }

.pile-sum {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.pile-body {
  max-height: min(58vh, 620px);
  overflow-y: auto;
  overflow-x: hidden;
}

.empty {
  padding: 22px 14px;
  color: var(--ink-faint);
  font-size: 12.5px;
  text-align: center;
}

/* --------------------------------------------------- linha de carta */

.row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  padding: 6px 11px 6px 0;
  border-bottom: 1px solid var(--line);
  position: relative;
  min-width: 0;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }

/* A faixa da esquerda codifica a identidade de cor da carta. */
.row-ci {
  width: 3px;
  align-self: stretch;
  flex: 0 0 3px;
  border-radius: 0 2px 2px 0;
  background: var(--c);
}

.row-qty {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--ink-faint);
  width: 26px;
  text-align: right;
  flex: 0 0 26px;
  white-space: nowrap;
}

.row-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
}
.row-name.unknown { color: var(--warn); }

.pips { display: inline-flex; gap: 2px; margin-left: 6px; vertical-align: -1px; }
.pip {
  width: 13px; height: 13px;
  border-radius: 50%;
  font-size: 8.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #0F172A;
  background: var(--c);
  font-family: var(--body);
}
.pip[data-p="W"] { background: var(--w); }
.pip[data-p="U"] { background: var(--u); color: #fff; }
.pip[data-p="B"] { background: var(--b); color: #fff; }
.pip[data-p="R"] { background: var(--r); color: #fff; }
.pip[data-p="G"] { background: var(--g); }

.row-price {
  width: 82px;
  flex: 0 0 82px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 3px 6px;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  text-align: right;
}
.row-price.estimated { border-style: dashed; color: var(--ink-soft); }

.row-acts { display: flex; gap: 2px; flex: 0 0 auto; white-space: nowrap; }

.iconbtn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink-faint);
  border-radius: var(--r-sm);
  width: 24px; height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}
.iconbtn:hover { color: var(--ink); border-color: var(--line); background: var(--surface); }
.iconbtn.danger:hover { color: var(--danger); }

.lm-link { text-decoration: none; font-size: 11px; font-weight: 700; }

/* ------------------------------------------------- campo de busca */

.add { padding: 9px 11px; border-top: 1px solid var(--line); position: relative; }

.add input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 7px 10px;
}

.ac {
  position: absolute;
  left: 11px; right: 11px;
  bottom: calc(100% - 4px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  max-height: 240px;
  overflow-y: auto;
  z-index: 30;
}
.ac-item { padding: 7px 11px; cursor: pointer; border-bottom: 1px solid var(--line); }
.ac-item:last-child { border-bottom: 0; }
.ac-item:hover, .ac-item.sel { background: var(--surface-2); color: var(--brass); }

/* ------------------------------------------------- pré-visualização */

#preview {
  position: fixed;
  z-index: 60;
  width: 244px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  pointer-events: none;
  display: block;
}

/* --------------------------------------------------------- rodapé */

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 18px;
  align-items: center;
}
.actions-spacer { flex: 1 1 auto; }

.notice {
  margin-top: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 14px;
  font-size: 12.5px;
  color: var(--ink-soft);
}
.notice b { color: var(--ink); }
.notice code {
  font-family: var(--mono);
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--warn);
}

.legal {
  margin-top: 26px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--ink-faint);
  font-size: 11.5px;
  line-height: 1.55;
  max-width: 68ch;
}
.legal p { margin: 0 0 5px; }
.legal a { color: var(--ink-soft); }

/* --------------------------------------------------------- modais */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8,9,12,.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 70;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 20px;
}
.modal h2 {
  font-family: var(--display);
  font-size: 19px;
  margin: 0 0 4px;
  text-wrap: balance;
}
.modal p.sub { color: var(--ink-soft); font-size: 13px; margin: 0 0 16px; }
.modal textarea {
  width: 100%;
  min-height: 210px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 10px;
  font-family: var(--mono);
  font-size: 12.5px;
}
.modal .field { margin-bottom: 12px; }
.modal-acts { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }

.err { color: var(--danger); font-size: 12.5px; min-height: 18px; }

.saved-list { display: flex; flex-direction: column; gap: 1px; }
.saved-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
}
.saved-item b { font-weight: 600; }
.saved-meta { color: var(--ink-faint); font-size: 12px; }

/* --------------------------------------------------------- toast */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: var(--r-md);
  padding: 9px 16px;
  box-shadow: var(--shadow);
  z-index: 90;
  font-size: 13px;
  max-width: calc(100vw - 32px);
}

.spin {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid var(--line);
  border-top-color: var(--brass);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -1px;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ------------------------------------------------------ responsivo */

@media (max-width: 1000px) {
  .meta { grid-template-columns: 1fr 1fr; }
  .tally { grid-column: 1 / -1; flex-direction: row; justify-content: space-around; }
  .tally-total { border-top: 0; border-left: 1px solid var(--line); margin-top: 0; padding-top: 0; padding-left: 14px; }
  .board { grid-template-columns: 1fr; }
  .pile-body { max-height: none; }
}

@media (max-width: 560px) {
  .meta { grid-template-columns: 1fr; }
  .budget { min-width: 0; width: 100%; }
  /* 40px é o piso testado: abaixo disso o "TCG" do brasão embola. */
  .brandmark { height: 40px; }
  .tool-label { margin-left: 10px; padding-left: 10px; }
  .field textarea { min-height: 96px; }
  .row { gap: 6px; padding-right: 8px; }
  .row-price { width: 74px; flex-basis: 74px; }
  .budget-bar { order: 5; flex-basis: 100%; max-width: none; }
  .budget-limit-input { width: 78px; }
  #preview { display: none !important; }
}
