/* TingFy — base visual (tokens, tipografia, botões, campos, tabelas, navegação).
   Linguagem copiada da prévia variantes/redesenho/fable-2.html. Fonte servida de
   public/fonts/ (CSP estrita: nada de link para CDN). */
@font-face {
  font-family: 'Bricolage Grotesque';
  font-style: normal;
  font-weight: 400 800;
  font-stretch: 100%;
  font-display: swap;
  src: url('fonts/bricolage-var.woff2') format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Hanken Grotesk';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/hanken-var.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #EDEFF2;
  --surface: #FFFFFF;
  --surface2: #F6F7F9;
  --ink: #0F1217;
  --ink2: #434A55;
  --ink3: #78808C;
  --line: #DCE0E6;
  --line2: #EAEDF1;
  --accent: #2C3AF0;
  --accent-ink: #FFFFFF;
  --accent-soft: #E6E8FE;
  --pos: #0A7F4E;
  --pos-bg: #DDF2E7;
  --neg: #CC3326;
  --neg-bg: #FBE7E4;
  --warn: #9A6200;
  --warn-bg: #FCF0D8;
  --r: 10px;
  --side: 232px;
  --num: 'Bricolage Grotesque', 'Arial Narrow', system-ui, sans-serif;
  --txt: 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}
[data-theme='dark'] {
  --bg: #0E1116;
  --surface: #161A20;
  --surface2: #1D222A;
  --ink: #EDF0F4;
  --ink2: #B4BCC7;
  --ink3: #7F8895;
  --line: #2A3038;
  --line2: #222831;
  --accent: #7A85FF;
  --accent-ink: #0E1116;
  --accent-soft: #232A57;
  --pos: #4CD08E;
  --pos-bg: #123424;
  --neg: #FF8B7D;
  --neg-bg: #3B1C18;
  --warn: #F0C160;
  --warn-bg: #3A2C0E;
  color-scheme: dark;
}

/* nomes antigos usados por styles.css e pelas outras folhas: apontam para os tokens novos */
:root,
[data-theme='dark'] {
  --text: var(--ink);
  --muted: var(--ink2);
  --surface-2: var(--surface2);
  --radius: var(--r);
  --danger: var(--neg);
  --danger-soft: var(--neg-bg);
  --font: var(--txt);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--txt);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.num, .n, .hero-value, .card-value, td.n, th.n {
  font-family: var(--num);
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.hidden { display: none !important; }
.sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
}

/* ícones: SVG inline com traço na cor do texto */
svg.i {
  width: 18px; height: 18px; flex: none;
  stroke: currentColor; fill: none; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- botões ---------- */
.btn,
button.primary,
.primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: border-color .12s, background .12s;
}
.btn:hover, button.primary:hover, .primary:hover { border-color: #C5CBD4; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.btn.blue, button.primary.primary-forte { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.blue:hover, .primary-forte:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn.danger { background: var(--neg); border-color: var(--neg); color: #fff; }
.btn.ghost { border-color: transparent; background: none; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn svg.i { width: 16px; height: 16px; }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
button.primary:hover { background: var(--accent); filter: brightness(1.08); }
button:disabled, .btn:disabled, [disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- campos ---------- */
input[type='text'], input[type='email'], input[type='password'], input[type='search'],
input[type='date'], input[type='number'], input[type='tel'], select, textarea {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 38px;
  max-width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder { color: var(--ink3); }
select {
  appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2378808C' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 16px;
}
[data-theme='dark'] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237F8895' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}
input[type='checkbox'], input[type='radio'] { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- pílulas de status ---------- */
.chip, .status {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600;
  padding: 2px 8px; border-radius: 99px;
  background: var(--surface2); color: var(--ink2);
  white-space: nowrap;
}
.chip.on, .status.active, .status.ok { background: var(--pos-bg); color: var(--pos); }
.chip.off, .status.paused { background: var(--surface2); color: var(--ink3); }
.chip.warn, .status.restricoes { background: var(--warn-bg); color: var(--warn); }
.chip.bad, .status.bad, .status.error { background: var(--neg-bg); color: var(--neg); }

/* ---------- chave liga/desliga ---------- */
.sw, .power-btn {
  position: relative;
  width: 40px; height: 23px; flex: none;
  border: 0; border-radius: 99px;
  background: #C3C9D1; padding: 0;
  transition: background .15s;
}
.sw::after, .power-btn span {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 17px; height: 17px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
  transition: transform .15s;
}
.sw[aria-checked='true'], .power-btn.on { background: var(--pos); }
.sw[aria-checked='true']::after, .power-btn.on span { transform: translateX(17px); }
.sw:disabled, .power-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- cartão / painel ---------- */
.panel, .card-painel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; padding: 1px 7px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 11px; font-weight: 700; border-radius: 99px;
}

/* ---------- tabela ---------- */
table { border-collapse: separate; border-spacing: 0; width: 100%; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line2); white-space: nowrap; text-align: right; }
th {
  font-size: 12px; color: var(--ink3); font-weight: 600;
  background: var(--surface2);
}
td.l, th.l { text-align: left; }
td.n { font-family: var(--num); font-weight: 500; }
.empty { padding: 40px 16px; text-align: center; color: var(--ink3); }
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }

/* contêiner que deixa a tabela larga rolar dentro dela (nunca a página) */
.table-scroll, .tw { overflow-x: auto; max-width: 100%; overscroll-behavior-inline: contain; }

/* ---------- navegação: menu lateral (computador) ---------- */
.side {
  position: fixed; inset: 0 auto 0 0; width: var(--side);
  background: var(--surface); border-right: 1px solid var(--line);
  display: none; flex-direction: column;
  padding: 18px 12px 14px; z-index: 20;
}
.side .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 8px 18px;
  font-family: var(--num); font-weight: 700; font-size: 21px; letter-spacing: -.02em;
  color: var(--ink); text-decoration: none;
}
.side .brand svg { width: 26px; height: 26px; flex: none; }
.side .proj {
  margin: 0 4px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface2); font-weight: 600; min-width: 0;
}
.side .proj small { display: block; font-weight: 500; color: var(--ink3); font-size: 11.5px; }
.side .nav { display: flex; flex-direction: column; gap: 1px; overflow-y: auto; flex: 1; }
.side .nav button, .side .nav a {
  display: flex; align-items: center; gap: 11px; width: 100%;
  border: 0; background: none; padding: 9px 10px; border-radius: 7px;
  color: var(--ink2); font-weight: 500; text-align: left; text-decoration: none;
}
.side .nav button:hover, .side .nav a:hover { background: var(--surface2); color: var(--ink); }
.side .nav button[aria-selected='true'] { background: var(--ink); color: var(--surface); }
.side .nav .badge { margin-left: auto; }
.side .nav .sep { height: 1px; background: var(--line2); margin: 10px 8px; }
.side .foot {
  margin-top: auto; padding: 10px; border-top: 1px solid var(--line2);
  font-size: 12.5px; color: var(--ink3);
}
.side .foot button { display: flex; align-items: center; gap: 9px; width: 100%; border: 0; background: none; padding: 6px 0; color: var(--ink2); font-weight: 600; }
.side .foot button:hover { color: var(--ink); }

/* ---------- navegação: barra inferior (celular) ---------- */
.bnav { display: none; }
.mtop { display: none; }

/* ---------- conteúdo ---------- */
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 28px 48px; }
@media (min-width: 901px) {
  .side { display: flex; }
  main.wrap { margin-left: calc(var(--side) + max(0px, (100vw - var(--side) - 1120px) / 2)); padding-left: 28px; padding-right: 28px; }
}
@media (max-width: 900px) {
  .wrap { padding: 0 16px 104px; overflow-x: hidden; max-width: 100%; box-sizing: border-box; }
  .bnav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    z-index: 50;
  }
  .bnav button, .bnav a {
    border: 0; background: none;
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    font-size: 11px; font-weight: 600; color: var(--ink3);
    padding: 4px 0; position: relative; text-decoration: none;
  }
  .bnav svg.i { width: 22px; height: 22px; }
  .bnav button[aria-selected='true'] { color: var(--ink); }
  .bnav button[aria-selected='true'] svg.i { stroke-width: 2.3; }

  .mtop { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px 4px; min-width: 0; max-width: 100%; box-sizing: border-box; overflow: hidden; }
  .mtop .brand { display: flex; align-items: center; gap: 8px; font-family: var(--num); font-weight: 700; font-size: 19px; color: var(--ink); text-decoration: none; min-width: 0; }
  .mtop .brand svg { width: 22px; height: 22px; }
  .mtop-proj { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--ink3); }
}

/* ---------- folha "Mais" no celular ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(15, 18, 23, .4);
  display: none; align-items: flex-end;
}
.sheet.on { display: flex; }
/* a folha trava a rolagem do fundo enquanto está aberta */
body.sheet-open { overflow: hidden; }
@media (min-width: 901px) { .sheet { display: none !important; } }
.sheet .in {
  background: var(--surface); width: 100%;
  border-radius: 14px 14px 0 0;
  padding: 10px 12px calc(16px + env(safe-area-inset-bottom));
  max-height: 82vh; overflow-y: auto;
}
.sheet .grab { width: 40px; height: 4px; border-radius: 9px; background: var(--line); margin: 0 auto 10px; }
.sheet .in .nav { display: flex; flex-direction: column; gap: 1px; }
.sheet .in button, .sheet .in a {
  display: flex; align-items: center; gap: 11px; width: 100%;
  border: 0; background: none; padding: 11px 10px; border-radius: 7px;
  color: var(--ink2); font-weight: 500; text-align: left; text-decoration: none;
}
.sheet .in button:hover, .sheet .in a:hover { background: var(--surface2); color: var(--ink); }
.sheet .in svg.i { width: 18px; height: 18px; flex: none; }

/* ---------- cabeçalho da área de conteúdo ---------- */
.dash-head {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 18px 0 14px; border-bottom: 1px solid var(--line); margin-bottom: 8px;
  position: relative;
}
.dash-title {
  margin: 0; font-family: var(--num); font-weight: 700;
  font-size: 26px; letter-spacing: -.02em; color: var(--ink);
}
/* F2: a faixa de período rola na horizontal; a sombra da direita diz que ainda tem. */
.dash-periods {
  display: flex; gap: 2px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 3px;
  overflow-x: auto; scrollbar-width: none; max-width: 100%;
  scroll-behavior: smooth; -webkit-overflow-scrolling: touch;
}
.dash-periods::-webkit-scrollbar { display: none; }
.dash-periods.tem-mais {
  -webkit-mask-image: linear-gradient(to right, #000 82%, transparent);
  mask-image: linear-gradient(to right, #000 82%, transparent);
}
.dash-periods .period-btn {
  border: 0; background: none; padding: 5px 11px; border-radius: 6px;
  font-weight: 500; white-space: nowrap; color: var(--ink2);
}
.dash-periods .period-btn[aria-pressed='true'] { background: var(--ink); color: var(--surface); }
.dash-controls-row { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; min-width: 0; }
.dash-export-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.dash-export-actions.topo-agrupado { display: none; }

/* F5: fora do Resumo o topo mostra só o nome da tela — período e projeto somem. */
.dash-head.so-titulo { justify-content: space-between; }
.dash-head.so-titulo .dash-periods,
.dash-head.so-titulo .dash-controls-row,
.dash-head.so-titulo .dash-export-actions { display: none; }
.dash-head.so-titulo .topo-mais,
.dash-head.so-titulo .topo-mais-menu { display: none; }

/* F3: botão e menu "Mais ações" */
.topo-mais {
  display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink2);
  border-radius: 8px; padding: 7px 11px; font-weight: 500; font-size: 13px;
  white-space: nowrap;
}
.topo-mais:hover { border-color: #C5CBD4; color: var(--ink); }
.topo-mais svg.i { width: 15px; height: 15px; }
.topo-mais[aria-expanded='true'] svg.i { transform: rotate(180deg); }
.topo-mais-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60;
  display: flex; flex-direction: column; gap: 4px; min-width: 210px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px; box-shadow: 0 10px 30px rgba(15, 18, 23, .14);
}
.topo-mais-menu > * {
  display: flex; align-items: center; gap: 8px; width: 100%;
  border: 0; background: none; color: var(--ink); text-align: left;
  padding: 9px 10px; border-radius: 7px; font-size: 13.5px; font-weight: 500;
}
.topo-mais-menu > *:hover { background: var(--surface2); }
.topo-mais-menu > *:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

@media (max-width: 1180px) {
  .dash-head { gap: 10px; }
  .dash-periods { order: 3; flex-basis: 100%; }
  .dash-controls-row { flex: 1 1 auto; }
}
@media (max-width: 900px) {
  .dash-controls-row { flex-wrap: wrap; }
  .dash-export-actions { flex-wrap: wrap; }
}
@media (min-width: 1181px) {
  .dash-title { flex: 0 0 auto; }
  .dash-periods { flex: 0 1 auto; }
  .dash-controls-row { margin-left: auto; }
}

/* F4: no celular todo alvo de toque tem pelo menos 40px de altura. */
@media (max-width: 700px) {
  .dash-periods .period-btn { min-height: 40px; padding: 0 13px; display: inline-flex; align-items: center; }
  .topo-mais { min-height: 40px; }
  .topo-mais-menu > * { min-height: 44px; }
  /* F2/F4: a marca do topo vira um alvo de toque do mesmo tamanho dos outros (40px). */
  .mtop .brand { min-height: 40px; }
  .dash-head .top-actions .btn,
  .dash-head .top-actions button,
  .dash-export-actions .btn,
  .dash-export-actions button { min-height: 40px; display: inline-flex; align-items: center; }
}
.mtop-proj {
  margin: 0; padding: 6px 10px; font-size: 13px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface2); color: var(--ink2);
}
.side-help { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 7px; color: var(--ink2); font-weight: 500; text-decoration: none; }
.side-help svg.i { width: 18px; height: 18px; flex: none; }
/* quando o alvo é a tabela de Desempenho, um piscar suave mostra onde você caiu */
.v2-alvo { animation: v2alvo 1.6s ease-out; }
@keyframes v2alvo { 0%, 60% { box-shadow: 0 0 0 3px var(--accent-soft); } 100% { box-shadow: none; } }

/* ---------- telas de entrada (login / definir senha) ---------- */
.login-page {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center; padding: 24px 16px;
  background: var(--bg);
}
.login-card {
  width: 100%; max-width: 380px;
  display: grid; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 26px 22px;
  box-shadow: var(--shadow, 0 6px 24px rgba(15, 18, 23, .07));
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 2px; }
.login-brand strong { font-family: var(--num); font-size: 22px; letter-spacing: -.02em; color: var(--ink); }
.login-titulo { font-size: 16px; margin: 4px 0 0; font-weight: 700; color: var(--ink); }
.login-card p { margin: 0; color: var(--ink2); font-size: 14px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink2); }
.login-card input { background: var(--surface); color: var(--ink); }

/* ---------- avisos / erros ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--surface);
  padding: 10px 16px; border-radius: 9px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: .2s;
  z-index: 90; max-width: calc(100vw - 32px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.error-box { color: var(--neg); }
.confirm-error {
  color: var(--neg) !important;
  background: var(--neg-bg);
  padding: 10px; border-radius: 8px;
}

@media (max-width: 420px) {
  .actgrid .btn { font-size: 12px; }
}
