/* Painel BI — Óticas São Paulo
 *
 * Extraído de `06-entregas/modelo_completo_bi_otica.html`, o protótipo que a cliente viu e
 * aprovou. ⚠️ Não redesenhe: as variáveis, os cards e a barra roxa do topo são o que ela
 * reconhece. O que foi acrescentado aqui é só o que o protótipo não tinha por ser estático —
 * a tela de login, a faixa de aviso de dado velho e os estados de erro.
 */

:root {
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e6e9ef;
  --soft: #f6f8fc;
  --panel: #fff;
  --accent: #4f46e5;
  --accent2: #7c3aed;
  --sky: #0ea5e9;
  --amber: #f59e0b;
  --rose: #f43f5e;
}

* { box-sizing: border-box }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--soft);
  color: var(--ink);
}

.app { max-width: 1160px; margin: 0 auto; padding: 0 16px 60px }
[hidden] { display: none !important }

/* ---------------------------------------------------------------- login */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .08);
}
.login-marca { display: flex; align-items: center; gap: 12px; margin-bottom: 22px }
.login-marca .logo {
  width: 42px; height: 42px; border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; display: grid; place-items: center; font-weight: 800;
}
.login-marca h1 { margin: 0; font-size: 16px }
.login-marca p { margin: 2px 0 0; font-size: 12px; color: var(--muted) }

.campo { margin-bottom: 14px }
.campo label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 5px }
.campo input {
  width: 100%; padding: 10px 12px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink);
}
.campo input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent }

button.primario {
  width: 100%; padding: 11px; font-size: 14px; font-weight: 700; color: #fff; cursor: pointer;
  background: linear-gradient(100deg, var(--accent), var(--accent2));
  border: none; border-radius: 9px;
}
button.primario:disabled { opacity: .6; cursor: progress }

.erro {
  background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c;
  font-size: 12.5px; padding: 9px 11px; border-radius: 9px; margin-bottom: 14px;
}

/* ---------------------------------------------------------------- shell */

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: linear-gradient(100deg, var(--accent), var(--accent2));
  color: #fff; margin: 0 -16px; padding: 14px 20px;
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
}
.brand { display: flex; align-items: center; gap: 12px }
.brand .logo {
  width: 36px; height: 36px; border-radius: 9px; background: rgba(255, 255, 255, .18);
  display: grid; place-items: center; font-weight: 800; font-size: 14px;
}
.brand h1 { margin: 0; font-size: 16px; font-weight: 700 }
.brand p { margin: 2px 0 0; font-size: 11.5px; opacity: .85 }
.who { text-align: right; font-size: 11.5px; opacity: .92; display: flex; align-items: center; gap: 12px }
.who button {
  background: rgba(255, 255, 255, .18); border: none; color: #fff;
  font-size: 11.5px; font-weight: 700; padding: 6px 11px; border-radius: 8px; cursor: pointer;
}

nav.tabs {
  position: sticky; top: 64px; z-index: 29;
  display: flex; gap: 4px; overflow-x: auto;
  background: var(--soft); padding: 10px 0 8px; border-bottom: 1px solid var(--line);
}
nav.tabs button {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  font-weight: 600; font-size: 13px; padding: 8px 13px; border-radius: 10px;
  cursor: pointer; white-space: nowrap;
}
nav.tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent) }
nav.tabs button:disabled { opacity: .45; cursor: not-allowed }

.filtros { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; margin: 16px 0 6px }
.lojasel, .atalhos { display: flex; gap: 6px; flex-wrap: wrap }
.lojasel button, .atalhos button {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  font-weight: 700; font-size: 12.5px; padding: 8px 14px; border-radius: 10px; cursor: pointer;
}
.lojasel button.active { background: var(--ink); color: #fff; border-color: var(--ink) }

/* Atalho de período é escolha de FILTRO, não de escopo como a loja — por isso ele acende em
 * roxo (o mesmo do dado) e não no preto do seletor de loja. Nenhum aceso = intervalo livre,
 * digitado nos campos De/Até ao lado; é por isso que não existe um botão "Livre". */
.atalhos button { font-size: 11.5px; padding: 7px 11px }
.atalhos button.active { background: var(--accent); color: #fff; border-color: var(--accent) }
.periodo { display: flex; gap: 8px; align-items: flex-end }
.periodo label { font-size: 11px; font-weight: 700; color: var(--muted); display: block; margin-bottom: 4px }
.periodo input {
  border: 1px solid var(--line); border-radius: 9px; padding: 7px 9px; font-size: 12.5px;
  background: #fff; color: var(--ink);
}

/* ------------------------------------------------- carimbo e faixa de aviso
 * ⚠️ Painel sem carimbo é a pior falha silenciosa possível: com o coletor morto a tela
 * continua mostrando número plausível, só que de semana passada. A API manda `atualizado_em`
 * e `aviso` em toda página — os dois SEMPRE aparecem.
 */
.aviso {
  background: #fffbeb; border: 1px solid #fde68a; color: #92400e;
  font-size: 12.5px; padding: 10px 13px; border-radius: 10px; margin: 14px 0;
}
.carimbo { font-size: 11.5px; color: var(--muted); margin-top: 8px }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 13px;
  padding: 14px 16px; box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}
.vazio { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 13px }
.foot { margin-top: 26px; border-top: 1px solid var(--line); padding-top: 14px; font-size: 11px; color: var(--muted); line-height: 1.6 }

/* ------------------------------------------------------------ página 1 */

h2.vt { font-size: 17px; margin: 14px 0 2px }
p.vs { margin: 0 0 14px; color: var(--muted); font-size: 13px }
.sec { font-size: 13px; font-weight: 700; margin: 20px 0 9px }
.leve { font-weight: 500; color: var(--muted) }

/* Botão de exportar: fica ao lado do título da seção que ele baixa, nunca solto no topo —
 * "exportar" sem dizer o quê, numa tela com quatro blocos, é adivinhação. */
.exportar {
  display: inline-block; margin-left: 10px; padding: 3px 9px;
  font-size: 11px; font-weight: 700; text-decoration: none;
  color: var(--accent); background: #fff;
  border: 1px solid var(--line); border-radius: 8px;
}
.exportar:hover { border-color: var(--accent) }

.grid { display: grid; gap: 12px }
.k4 { grid-template-columns: repeat(4, 1fr) }
.k3 { grid-template-columns: repeat(3, 1fr) }
.k2 { grid-template-columns: repeat(2, 1fr) }
/* A Luciana abre no celular — os cards empilham e a tabela rola sozinha. */
@media (max-width: 840px) {
  .k4 { grid-template-columns: repeat(2, 1fr) }
  .k3, .k2 { grid-template-columns: 1fr }
}
@media (max-width: 470px) { .k4 { grid-template-columns: 1fr } }

.lbl { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .3px }
.val { font-size: 22px; font-weight: 800; margin-top: 5px; letter-spacing: -.5px }
.sub { font-size: 11.5px; color: var(--muted); margin-top: 3px }
.kpi.hero { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; border: none }
.kpi.hero .lbl, .kpi.hero .sub { color: #e9e7fd }

.bars { display: flex; align-items: flex-end; gap: 5px; height: 170px; padding-top: 20px; border-bottom: 1px solid var(--line) }
.bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100% }
.bar .col {
  width: 62%; max-width: 26px; border-radius: 5px 5px 0 0;
  background: linear-gradient(180deg, var(--accent2), var(--accent));
  position: relative; min-height: 2px;
}
.bar .cnt { position: absolute; top: -14px; left: 50%; transform: translateX(-50%); font-size: 9px; color: var(--muted) }
.bar .lb { font-size: 8.5px; color: var(--muted); margin-top: 4px }
.acc { font-size: 11.5px; color: var(--muted); margin-top: 7px }
.acc b { color: var(--accent) }

/* ------------------------------------------------------------ página 2
 * Barra empilhada com nota × sem nota. O protótipo não tinha este gráfico — é o único
 * acréscimo visual desta página. `sem nota` fica EM CIMA e em âmbar porque é a fatia que a
 * Luciana procura; o roxo embaixo é o mesmo das barras da página 1.
 */
.bar .col.pilha {
  background: none; overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-end;
}
.fatia-com { background: linear-gradient(180deg, var(--accent2), var(--accent)) }
.fatia-sem { background: var(--amber) }

.legenda { display: flex; gap: 16px; font-size: 11.5px; color: var(--muted); margin-top: 9px }
.legenda i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 5px }
.legenda i.cor-com { background: var(--accent) }
.legenda i.cor-sem { background: var(--amber) }

svg.linha { width: 100%; height: auto; display: block }

.rosca {
  display: flex; height: 30px; border-radius: 8px; overflow: hidden;
  font-size: 12px; font-weight: 700; color: #fff;
}
.rosca > div { display: flex; align-items: center; justify-content: center; white-space: nowrap }
.note { font-size: 11.5px; color: var(--muted); margin-top: 9px; line-height: 1.5 }

/* ------------------------------------------------------------ página 3
 * Ranking de vendedoras: uma barra horizontal por linha, largura proporcional ao maior total.
 * O protótipo não tinha este gráfico — mesmo espírito do empilhado da página 2, sem lib.
 */
.ranking { display: flex; flex-direction: column; gap: 9px }
.ranking .linha { display: grid; grid-template-columns: 110px 1fr 90px; align-items: center; gap: 10px }
.ranking .nome { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.ranking .trilha { background: var(--soft); border-radius: 6px; height: 16px; overflow: hidden }
.ranking .preenchido { height: 100%; min-width: 2px; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 6px }
.ranking .valor { font-size: 12px; font-weight: 700; text-align: right }
@media (max-width: 560px) { .ranking .linha { grid-template-columns: 78px 1fr 76px; gap: 6px } }

.tabela-rolante { overflow-x: auto }
table { width: 100%; border-collapse: collapse; font-size: 12.5px }
th, td { padding: 7px 9px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap }
th:first-child, td:first-child { text-align: left }
thead th { color: var(--muted); font-size: 10.5px; text-transform: uppercase }
tfoot td { font-weight: 700; border-top: 2px solid var(--line) }

/* ------------------------------------------------------------ página 4
 * Linha vencida em vermelho — pedido explícito da especificação (§4). O mesmo tom também
 * marca o card "vencido", pra ficar óbvio antes mesmo de abrir a tabela.
 */
tr.venc-atrasada td { color: var(--rose) }
.kpi .val.alerta { color: var(--rose) }
