/* Follow Up Global - folha de estilo unica.
   Cores de dados: paleta categorica validada (ver README, seccao Visualizacao). */

/* ---------------------------------------------------------------------------
   MARCA
   Estes sao os unicos valores a mudar para vestir a aplicacao com outra marca.
   Tudo o resto (interface e graficos) deriva daqui ou da paleta de dados.
   --------------------------------------------------------------------------- */
/* Prime Group (weareprimegroup.com): navy #0F1F4A, verde #23FFA3,
   azul #1F5CFF, cinza #687086, superficie #F7F9FB.
   O site usa FK Grotesk e GT Super Display, que sao fontes comerciais e nao
   podem ser redistribuidas aqui; usamos a mesma cadeia de recurso do site. */
:root {
  --brand: #0f1f4a;              /* navy: botoes principais, barra de topo */
  --brand-hover: #0c183a;        /* navy do rodape do site */
  --brand-ink: #ffffff;          /* texto por cima do navy */
  --brand-accent: #23ffa3;       /* verde: separador activo, destaque do logo */
  --brand-accent-ink: #0f1f4a;   /* texto por cima do verde (nunca branco) */
  --brand-link: #1f5cff;         /* azul da marca, para ligacoes */
  --brand-bar: #0f1f4a;          /* fundo da barra de topo */
  --brand-bar-ink: #ffffff;      /* texto da barra de topo */
  --brand-font: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  --brand-radius: 10px;
}

:root {
  color-scheme: light;
  --surface-1: #ffffff;
  --plane: #f7f9fb;
  --surface-2: #ffffff;
  --text-primary: #0f1f4a;
  --text-secondary: #687086;
  --text-muted: #8a91a3;
  --grid: #e6eaf0;
  --axis: #c7cedb;
  --border: rgba(15, 31, 74, 0.12);
  --border-strong: rgba(15, 31, 74, 0.22);

  --series-1: #1f5cff;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;

  --seq-200: #9ec5f4;
  --seq-450: #1f5cff;
  --seq-600: #184f95;

  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;

  --radius: var(--brand-radius);
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(15, 31, 74, 0.06), 0 4px 14px rgba(15, 31, 74, 0.06);
  --font: var(--brand-font);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    /* marca em fundo escuro */
    --brand: #23ffa3;
    --brand-hover: #16e08c;
    --brand-ink: #0f1f4a;
    --brand-accent: #23ffa3;
    --brand-accent-ink: #0f1f4a;
    --brand-link: #6da7ec;
    --brand-bar: #0c183a;
    --brand-bar-ink: #ffffff;

    --surface-1: #121a2e;
    --plane: #0a1024;
    --surface-2: #18223a;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #233049;
    --axis: #33415e;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --series-1: #1f5cff;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --seq-200: #184f95;
    --seq-450: #1f5cff;
    --seq-600: #9ec5f4;
    --good-text: #0ca30c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  /* marca em fundo escuro */
  --brand: #23ffa3;
  --brand-hover: #16e08c;
  --brand-ink: #0f1f4a;
  --brand-accent: #23ffa3;
  --brand-accent-ink: #0f1f4a;
  --brand-link: #6da7ec;
  --brand-bar: #0c183a;
  --brand-bar-ink: #ffffff;

  --surface-1: #121a2e;
  --plane: #0a1024;
  --surface-2: #18223a;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #233049;
  --axis: #33415e;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --series-1: #1f5cff;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --seq-200: #184f95;
  --seq-450: #1f5cff;
  --seq-600: #9ec5f4;
  --good-text: #0ca30c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

/* O atributo hidden tem de ganhar a qualquer regra de display desta folha. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--plane);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
}

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5rem; font-weight: 650; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .7rem; }
a { color: var(--brand-link); }

.muted { color: var(--text-secondary); font-size: .9rem; }
.tiny { font-size: .8rem; color: var(--text-muted); }
.error { color: var(--critical); font-weight: 600; }
.ok { color: var(--good-text); font-weight: 600; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.tabular { font-variant-numeric: tabular-nums; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.login-card { width: min(380px, 100%); }
.login-logo { display: block; width: 34px; height: 45px; margin-bottom: .9rem; }
.login-logo svg { width: 100%; height: 100%; display: block; }
.login-card label { display: block; margin-bottom: .8rem; font-size: .88rem; color: var(--text-secondary); }
.login-card input { width: 100%; margin-top: .25rem; }
.login-card .btn { width: 100%; }

/* ---------- shell ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: .6rem 1rem;
  background: var(--brand-bar);
  color: var(--brand-bar-ink);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  display: flex; align-items: center; gap: .55rem;
  color: var(--brand-bar-ink);
}
.brand strong { font-weight: 700; letter-spacing: -.01em; }
.brand .sep {
  width: 1px; height: 20px; background: currentColor; opacity: .3; margin: 0 .1rem;
}
.brand .product { font-size: .92rem; opacity: .85; white-space: nowrap; }
.logo { display: inline-flex; width: 22px; height: 29px; }
.logo svg { width: 100%; height: 100%; display: block; }

.tabs { display: flex; gap: .15rem; flex-wrap: wrap; flex: 1; }
.tabs button {
  background: none; border: 0; cursor: pointer;
  padding: .45rem .7rem; border-radius: var(--radius-sm);
  color: var(--brand-bar-ink); opacity: .78; font: inherit; font-size: .9rem;
}
.tabs button:hover {
  background: color-mix(in srgb, var(--brand-bar-ink) 14%, transparent);
  opacity: 1;
}
.tabs button[aria-current="page"] {
  background: var(--brand-accent); color: var(--brand-accent-ink);
  font-weight: 600; opacity: 1;
}
.topbar-right { display: flex; align-items: center; gap: .5rem; }
.who { font-size: .82rem; color: var(--brand-bar-ink); opacity: .8; }
.topbar .btn.ghost { color: var(--brand-bar-ink); opacity: .85; }
.topbar .btn.ghost:hover {
  background: color-mix(in srgb, var(--brand-bar-ink) 14%, transparent);
  color: var(--brand-bar-ink); opacity: 1;
}
.topbar :focus-visible { outline-color: var(--brand-accent); }

.view { padding: 1.1rem; max-width: 1500px; margin: 0 auto; }
.view:focus { outline: none; }

/* ---------- blocos ---------- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
.card > :last-child { margin-bottom: 0; }
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem;
}
.card-head h2, .card-head h3 { margin: 0; }

.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.grid.wide { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
@media (max-width: 960px) { .grid.wide { grid-template-columns: 1fr; } }

/* filtros: uma linha acima dos graficos, tudo assente na mesma base */
.filters {
  display: flex; gap: .75rem 1rem; flex-wrap: wrap; align-items: end;
  padding: .8rem 1rem; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 1rem;
}
.field { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.field > span {
  font-size: .72rem; color: var(--text-muted); text-transform: uppercase;
  letter-spacing: .04em; line-height: 1.2; white-space: nowrap;
}
/* todos os controlos da barra com a mesma altura */
.filters select,
.filters input,
.filters .btn { height: 2.15rem; }
.filters select { min-width: 9rem; }
.filters .btn-row { gap: .4rem; align-items: end; }
/* um grupo de campos dentro da barra nao volta a criar um cartao */
.filters .btn-row > .field { margin: 0; }

/* menu de selecao multipla (empresas) */
.multi { position: relative; }
.multi > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: inline-flex; align-items: center; gap: .4rem;
  height: 2.15rem; padding: 0 .6rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text-primary);
  font-size: .9rem; white-space: nowrap; min-width: 11rem;
}
.multi > summary::-webkit-details-marker { display: none; }
.multi > summary::after { content: '▾'; margin-left: auto; color: var(--text-muted); }
.multi[open] > summary { border-color: var(--brand); }
.multi-panel {
  position: absolute; z-index: 30; top: calc(100% + .25rem); left: 0;
  min-width: 15rem; max-height: 17rem; overflow: auto;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: .35rem;
}
.multi-panel label {
  display: flex; align-items: center; gap: .5rem;
  padding: .3rem .4rem; border-radius: 4px; font-size: .88rem; cursor: pointer;
}
.multi-panel label:hover { background: var(--plane); }
.multi-panel input { height: auto; }
.multi-panel .group {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); padding: .45rem .4rem .2rem;
}
.multi-panel .actions {
  display: flex; gap: .4rem; padding: .35rem .4rem 0;
  border-top: 1px solid var(--grid); margin-top: .3rem;
}

input, select, textarea, button { font: inherit; }
input, select, textarea {
  background: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: .4rem .55rem;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px;
}
input[type="number"] { width: 6.5rem; text-align: right; font-variant-numeric: tabular-nums; }
input:user-invalid { border-color: var(--critical); }
textarea { width: 100%; min-height: 3.5rem; }

.btn {
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: .42rem .8rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.ghost { background: none; border-color: transparent; color: var(--text-secondary); }
.btn.ghost:hover { background: var(--plane); color: var(--text-primary); }
.btn.danger { border-color: var(--critical); color: var(--critical); background: none; }
.btn.icon { padding: .35rem .5rem; font-size: 1rem; }
.btn.small { padding: .25rem .5rem; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ---------- tabelas ---------- */
.table-wrap { overflow: auto; max-height: 68vh; border-radius: var(--radius-sm); }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: .4rem .55rem; border-bottom: 1px solid var(--grid); }
th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-1); color: var(--text-secondary);
  font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em;
  white-space: nowrap;
}
th.group { text-align: center; border-bottom-color: var(--axis); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--plane); }
tr.subtotal { background: var(--plane); font-weight: 600; }

/* quadro de alteracoes: blocos por empresa, linhas paradas em segundo plano */
table.matrix tr.company-row > td {
  background: var(--plane);
  border-top: 2px solid var(--axis);
  border-bottom: 1px solid var(--axis);
  font-weight: 600;
}
table.matrix tr.company-row > td .tiny { font-weight: 400; }
table.matrix tr.quiet > td { color: var(--text-muted); }
table.matrix tr.quiet:hover > td { color: var(--text-primary); }
table.matrix td.dept { padding-left: 1.4rem; }
/* as duas primeiras colunas acompanham o scroll horizontal */
table.matrix .stick { position: sticky; background: var(--surface-1); z-index: 1; }
table.matrix .stick-1 { left: 0; min-width: 8.5rem; }
table.matrix .stick-2 { left: 8.5rem; min-width: 13rem; box-shadow: 1px 0 0 var(--grid); }
table.matrix thead .stick { z-index: 3; }
table.matrix tr.company-row .stick { background: var(--plane); }
table.matrix tbody tr:hover .stick { background: var(--plane); }
tr.subtotal td { border-bottom-color: var(--axis); }
tfoot td { font-weight: 700; border-top: 2px solid var(--axis); border-bottom: 0; }
caption { caption-side: top; text-align: left; color: var(--text-muted); font-size: .8rem; padding-bottom: .4rem; }

/* delta: sinal + cor + rotulo, nunca so a cor */
.delta { font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta.up { color: var(--good-text); }
.delta.down { color: var(--critical); }
.delta.flat { color: var(--text-muted); }

.pill {
  display: inline-block; padding: .08rem .45rem; border-radius: 999px;
  font-size: .74rem; font-weight: 600; border: 1px solid var(--border-strong);
  white-space: nowrap;
}
.pill.submitted { color: var(--good-text); border-color: var(--good); }
.pill.draft { color: var(--serious); border-color: var(--serious); }
.pill.missing { color: var(--critical); border-color: var(--critical); }
.pill.reopened { color: var(--series-7); border-color: var(--series-7); }

/* ---------- KPI ---------- */
.kpis { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 1rem; }
.kpi {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .75rem .9rem;
}
.kpi .label { font-size: .76rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.kpi .value { font-size: 1.75rem; font-weight: 650; line-height: 1.1; margin: .15rem 0; }
.kpi .sub { font-size: .8rem; }

/* ---------- graficos ---------- */
.chart { width: 100%; display: block; overflow: visible; }
.chart text { font-family: var(--font); }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--text-muted); font-size: 11px; }
.chart .series-line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart .series-dot { stroke: var(--surface-1); stroke-width: 2; }
.chart .end-label { font-size: 11px; font-weight: 600; fill: var(--text-secondary); }
.chart .bar { }
.chart .hover-band { fill: transparent; }
.chart .hover-band:hover { fill: color-mix(in srgb, var(--text-primary) 5%, transparent); }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; }
.legend { display: flex; gap: .9rem; flex-wrap: wrap; font-size: .82rem; color: var(--text-secondary); margin-top: .4rem; }
.legend .item { display: inline-flex; align-items: center; gap: .35rem; }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.tooltip {
  position: fixed; pointer-events: none; z-index: 60;
  background: var(--surface-2); color: var(--text-primary);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: .4rem .55rem; font-size: .82rem; box-shadow: var(--shadow);
  max-width: 260px;
}
.tooltip .t-title { font-weight: 650; margin-bottom: .2rem; }
.tooltip .t-row { display: flex; gap: .5rem; justify-content: space-between; }
.tooltip .t-row b { font-variant-numeric: tabular-nums; }

/* ---------- formulario de reporte ---------- */
/* passos do reporte */
.steps { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .9rem; }
.steps .step {
  border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text-secondary); border-radius: 999px;
  padding: .35rem .85rem; font: inherit; font-size: .85rem; cursor: pointer;
}
.steps .step.current {
  background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600;
}
.steps .step.done { border-color: var(--good); color: var(--good-text); }
.steps .step.locked { opacity: .45; cursor: not-allowed; }
.steps .step:not(.locked):hover { border-color: var(--brand); }

/* o "i" ao lado de cada campo */
.help-wrap { position: relative; display: inline-block; }
.help-dot {
  width: 1.05rem; height: 1.05rem; margin-left: .4rem; padding: 0;
  border: 1px solid var(--border-strong); border-radius: 50%;
  background: var(--surface-2); color: var(--text-secondary);
  font: inherit; font-size: .68rem; font-style: italic; font-weight: 700;
  line-height: 1; cursor: pointer; vertical-align: text-top;
}
.help-dot:hover, .help-dot[aria-expanded="true"] {
  border-color: var(--brand); color: var(--brand); background: var(--surface-2);
}
.help-dot.empty { opacity: .45; }
.help-note {
  position: absolute; z-index: 40; top: calc(100% + .35rem); left: -.5rem;
  width: min(22rem, 70vw); padding: .6rem .75rem;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  font-size: .84rem; font-weight: 400; line-height: 1.45; white-space: normal;
}
.help-note strong { display: block; margin-bottom: .25rem; color: var(--brand); }
.help-note p { margin: 0; }

.metric-grid { display: grid; gap: .35rem .75rem; grid-template-columns: 1fr auto; align-items: center; }
.metric-grid .label { font-size: .88rem; }
.metric-grid .group-title {
  grid-column: 1 / -1; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); margin-top: .6rem; padding-top: .4rem; border-top: 1px solid var(--grid);
}
.metric-grid .total { grid-column: 1 / -1; display: flex; justify-content: space-between;
  font-weight: 650; padding-top: .35rem; border-top: 1px solid var(--grid); }

.admin-table td { padding: .25rem .3rem; }
.admin-table input, .admin-table select { width: 100%; padding: .3rem .4rem; }
.admin-table input[type="checkbox"] { width: auto; }
.admin-table td.act { width: 2.2rem; }

.issues { margin: .6rem 0 0; padding: .6rem .8rem; border-radius: var(--radius-sm); font-size: .86rem; }
.issues.errors { border: 1px solid var(--critical); background: color-mix(in srgb, var(--critical) 8%, transparent); }
.issues.warnings { border: 1px solid var(--warning); background: color-mix(in srgb, var(--warning) 12%, transparent); }
.issues ul { margin: .3rem 0 0; padding-left: 1.1rem; }
.issues .head { font-weight: 650; }

.dropzone {
  border: 2px dashed var(--border-strong); border-radius: var(--radius);
  padding: 1.1rem; text-align: center; color: var(--text-secondary);
  background: var(--plane);
}
.dropzone.over { border-color: var(--brand); color: var(--text-primary); }

.toast {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
  background: var(--text-primary); color: var(--plane);
  padding: .55rem 1rem; border-radius: 999px; z-index: 80; font-size: .88rem;
  box-shadow: var(--shadow); max-width: 90vw;
}
.toast.bad { background: var(--critical); color: #fff; }

details.drill { margin-top: .5rem; }
details.drill summary { cursor: pointer; font-size: .85rem; color: var(--brand-link); }
.names { font-size: .82rem; color: var(--text-secondary); }

.spinner { color: var(--text-muted); padding: 2rem; text-align: center; }

/* edicao dos textos de ajuda */
.guidance-row {
  display: grid; gap: .6rem; align-items: start;
  grid-template-columns: minmax(10rem, 14rem) minmax(0, 1fr) auto;
  padding: .55rem 0; border-bottom: 1px solid var(--grid);
}
.guidance-row textarea { min-height: 2.8rem; }
.guidance-row .btn-row { align-items: center; }
@media (max-width: 860px) {
  .guidance-row { grid-template-columns: 1fr; }
}

/* quadro secundario, como o desdobramento dos IC */
.subpanel {
  margin: 1rem 0 0; padding: .9rem 1rem;
  background: var(--plane);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand-accent);
  border-radius: var(--radius-sm);
}
.subpanel .card-head { margin-bottom: .6rem; }
.subpanel h3 { margin: 0; font-size: .95rem; }
.subpanel .metric-grid { max-width: 30rem; }
.subpanel strong { text-align: right; }

/* Aviso dentro de um cartão: a mesma linguagem dos avisos do reporte. */
.card.warn {
  border-left: 4px solid var(--warning);
  background: color-mix(in srgb, var(--warning) 10%, var(--surface-1));
}
