/* ==========================================================================
   Componentes de risco: níveis, barras empilhadas, matriz/mapa de calor,
   indicadores, listas de atenção e situação do mapa. Usado por /js/risk.js.
   Médio e Extremo têm hachura para não depender só da cor (daltonismo).
   ========================================================================== */
:root {
  --risk-baixo: #2f855a;
  --risk-medio: #a16207;
  --risk-alto: #c2410c;
  --risk-extremo: #b91c1c;
  --risk-none: #d6d3d1;
  --risk-baixo-tint: #edf7f1;
  --risk-medio-tint: #fdf6e3;
  --risk-alto-tint: #fdeee6;
  --risk-extremo-tint: #fce8e8;
  --risk-baixo-ink: #22673f;
  --risk-medio-ink: #854d0e;
  --risk-alto-ink: #b13a09;
  --risk-extremo-ink: #a11a1a;
}

/* ---- preenchimentos por nível ---- */
.lvl-baixo   { background: var(--risk-baixo); }
.lvl-medio   { background: repeating-linear-gradient(135deg, var(--risk-medio) 0 6px, #b7791f 6px 9px); }
.lvl-alto    { background: var(--risk-alto); }
.lvl-extremo { background: repeating-linear-gradient(135deg, var(--risk-extremo) 0 6px, #d33a3a 6px 9px); }
.lvl-none    { background: var(--risk-none); }

/* quadradinho da legenda / do nível */
.gr-sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; }
.gr-legend { display: flex; flex-wrap: wrap; gap: 1rem; font-size: .8rem; color: var(--gr-text); }
.gr-legend span { display: inline-flex; align-items: center; gap: .35rem; }

/* etiqueta de nível (texto colorido sobre fundo claro) */
.gr-lvl { display: inline-flex; align-items: center; gap: .3rem; padding: .08rem .45rem; border-radius: 5px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.gr-lvl.baixo   { background: var(--risk-baixo-tint);   color: var(--risk-baixo-ink); }
.gr-lvl.medio   { background: var(--risk-medio-tint);   color: var(--risk-medio-ink); }
.gr-lvl.alto    { background: var(--risk-alto-tint);    color: var(--risk-alto-ink); }
.gr-lvl.extremo { background: var(--risk-extremo-tint); color: var(--risk-extremo-ink); }
.gr-lvl.none    { background: #f5f5f4; color: var(--gr-muted); }

/* trajetória 81 → ■ Alto 54 → 17 */
.gr-traj { display: inline-flex; align-items: center; gap: .4rem; font-size: .86rem; color: var(--gr-muted); white-space: nowrap; }
.gr-traj b { color: var(--gr-text); font-weight: 600; display: inline-flex; align-items: center; gap: .3rem; }
.gr-traj .arr { color: var(--gr-subtle); }
.gr-traj-note { font-size: .76rem; color: #b45309; }

/* ---- cabeçalho de página ---- */
.gr-page-head { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; }
.gr-page-head h2 { font-size: 1.35rem; font-weight: 600; margin: 0; }
.gr-page-head .sub { color: var(--gr-muted); font-size: .86rem; margin-top: .2rem; }
.gr-page-head .actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---- indicadores ---- */
.gr-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .9rem; margin-bottom: 1rem; }
.gr-kpi { background: var(--gr-surface); border: 1px solid var(--gr-border); border-radius: var(--gr-radius); padding: .9rem 1rem; }
.gr-kpi .lbl { font-size: .8rem; color: var(--gr-muted); }
.gr-kpi .val { font-size: 1.7rem; font-weight: 600; line-height: 1.2; margin: .15rem 0; }
.gr-kpi .val small { font-size: .95rem; font-weight: 400; color: var(--gr-muted); }
.gr-kpi .hint { font-size: .78rem; color: var(--gr-muted); }
.gr-kpi.danger .val { color: var(--risk-extremo-ink); }
.gr-kpi.warn .val { color: #a16207; }

/* ---- painel (cartão com cabeçalho) ---- */
.gr-panel { background: var(--gr-surface); border: 1px solid var(--gr-border); border-radius: var(--gr-radius); margin-bottom: 1rem; }
.gr-panel-h { display: flex; align-items: flex-start; gap: .75rem; padding: .9rem 1rem; border-bottom: 1px solid var(--gr-border); }
.gr-panel-h h3 { font-size: .98rem; font-weight: 600; margin: 0; }
.gr-panel-h .desc { font-size: .8rem; color: var(--gr-muted); margin-top: .15rem; }
.gr-panel-h .tools { margin-left: auto; display: flex; gap: .4rem; align-items: center; flex: 0 0 auto; white-space: nowrap; }
.gr-panel-b { padding: .9rem 1rem; }
.gr-panel-b.p0 { padding: 0; }
.gr-empty { color: var(--gr-muted); font-size: .86rem; padding: 1rem; }

/* ---- barras empilhadas ---- */
.gr-bars { display: grid; grid-template-columns: minmax(90px, 220px) 1fr 36px; gap: .55rem .75rem; align-items: center; font-size: .84rem; }
.gr-bars .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gr-bars a.lbl { text-decoration: none; }
.gr-bars a.lbl:hover { text-decoration: underline; }
.gr-bars .tot { text-align: right; color: var(--gr-muted); }
.gr-sbar { display: flex; gap: 2px; height: 20px; min-width: 0; }
.gr-sbar .seg { border-radius: 4px; color: #fff; font-size: .7rem; font-weight: 600; display: flex; align-items: center; justify-content: center; min-width: 18px; overflow: hidden; }
.gr-sbar.neutral .seg { background: #3f3f46; }
.gr-sbar.thin { height: 8px; }
.gr-sbar.thin .seg { min-width: 4px; font-size: 0; border-radius: 3px; }

/* ---- matriz / mapa de calor ---- */
.gr-heat-wrap { display: flex; align-items: stretch; gap: .5rem; overflow-x: auto; }
.gr-heat-axis-y { writing-mode: vertical-rl; transform: rotate(180deg); text-align: center; font-size: .7rem; letter-spacing: .12em; color: var(--gr-muted); font-weight: 600; }
.gr-heat { display: grid; grid-template-columns: auto repeat(5, minmax(46px, 1fr)); gap: 5px; flex: 1; min-width: 320px; }
.gr-heat .rl { font-size: .76rem; color: var(--gr-muted); display: flex; align-items: center; justify-content: flex-end; text-align: right; padding-right: .35rem; line-height: 1.15; }
.gr-heat .cl { font-size: .74rem; color: var(--gr-muted); text-align: center; line-height: 1.15; padding-top: .2rem; }
.gr-heat .axis-x { grid-column: 2 / -1; text-align: center; font-size: .7rem; letter-spacing: .12em; color: var(--gr-muted); font-weight: 600; }
.gr-cell { aspect-ratio: 1.35 / 1; border-radius: 6px; border: 1.5px solid transparent; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: .95rem; cursor: default; user-select: none; transition: box-shadow .1s; }
.gr-cell.baixo   { background: var(--risk-baixo-tint);   color: var(--risk-baixo-ink); }
.gr-cell.medio   { background: var(--risk-medio-tint);   color: var(--risk-medio-ink); }
.gr-cell.alto    { background: var(--risk-alto-tint);    color: var(--risk-alto-ink); }
.gr-cell.extremo { background: var(--risk-extremo-tint); color: var(--risk-extremo-ink); }
.gr-cell.zero { color: rgba(0,0,0,.28); font-weight: 400; }
.gr-cell.has { cursor: pointer; }
.gr-cell.has.baixo   { border-color: var(--risk-baixo); }
.gr-cell.has.medio   { border-color: var(--risk-medio); }
.gr-cell.has.alto    { border-color: var(--risk-alto); }
.gr-cell.has.extremo { border-color: var(--risk-extremo); }
.gr-cell.has:hover { box-shadow: 0 0 0 3px rgba(0,0,0,.06); }
.gr-cell.sel { border-color: var(--gr-primary) !important; border-width: 2px; box-shadow: 0 0 0 3px rgba(0,0,0,.08); }
.gr-heat.compact { grid-template-columns: auto repeat(5, minmax(30px, 1fr)); gap: 4px; min-width: 240px; }
.gr-heat.compact .gr-cell { font-size: .82rem; aspect-ratio: 1.2 / 1; }

/* mini matriz (caminho do risco) */
.gr-mini { display: grid; grid-template-columns: repeat(5, 12px); gap: 2px; }
.gr-mini i { width: 12px; height: 12px; border-radius: 2px; opacity: .35; font-style: normal; font-size: 7px; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.gr-mini i.on { opacity: 1; outline: 1.5px solid var(--gr-primary); }

/* ---- segmentado (abas pequenas) ---- */
.gr-seg { display: inline-flex; background: #f0efed; border-radius: 8px; padding: 3px; gap: 2px; }
.gr-seg button { border: 0; background: transparent; padding: .25rem .7rem; border-radius: 6px; font-size: .82rem; color: var(--gr-muted); }
.gr-seg button.on { background: #fff; color: var(--gr-text); box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 500; }

/* ---- listas (atenção, mapas, linhas) ---- */
.gr-list { list-style: none; margin: 0; padding: 0; }
.gr-list > li { border-top: 1px solid var(--gr-border); }
.gr-list > li:first-child { border-top: 0; }
.gr-item { display: flex; align-items: center; gap: .8rem; padding: .75rem 1rem; color: inherit; text-decoration: none; }
a.gr-item:hover { background: var(--gr-surface-2); }
.gr-item .ico { color: var(--gr-muted); font-size: 1.05rem; flex: 0 0 auto; }
.gr-item .ico.danger { color: var(--risk-extremo); }
.gr-item .ico.warn { color: #a16207; }
.gr-item .main { min-width: 0; flex: 1; }
.gr-item .t { font-weight: 500; }
.gr-item .t.danger { color: var(--risk-extremo-ink); }
.gr-item .s { font-size: .8rem; color: var(--gr-muted); }
.gr-item .chev { color: var(--gr-subtle); flex: 0 0 auto; }
.gr-item .bar-l { width: 4px; align-self: stretch; border-radius: 2px; flex: 0 0 auto; }
.gr-group-label { font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; color: var(--gr-subtle); font-weight: 600; padding: .8rem 1rem .2rem; }
.gr-tag { display: inline-block; font-size: .72rem; padding: .05rem .4rem; border-radius: 4px; background: #f0efed; color: var(--gr-muted); margin-left: .35rem; }
.gr-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; color: var(--gr-muted); }

/* contadores em caixinha (2 prazos vencidos) */
.gr-counters { display: flex; gap: .5rem; flex-wrap: wrap; padding: .75rem 1rem 0; }
.gr-counter { border: 1px solid var(--gr-border); border-radius: 8px; padding: .3rem .6rem; font-size: .8rem; }
.gr-counter b { font-size: .95rem; margin-right: .3rem; }
.gr-counter.danger b { color: var(--risk-extremo-ink); }
.gr-counter.warn b { color: #a16207; }

/* ---- situação do mapa ---- */
.gr-status { display: inline-flex; align-items: center; gap: .35rem; font-size: .78rem; font-weight: 500; padding: .12rem .55rem; border-radius: 999px; white-space: nowrap; }
.gr-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.gr-status.rascunho { background: #f0efed; color: #57534e; }
.gr-status.em_elaboracao { background: #e8f0fb; color: #1e4f91; }
.gr-status.em_revisao { background: #fdf3dc; color: #8a5a00; }
.gr-status.aprovado { background: var(--risk-baixo-tint); color: var(--risk-baixo-ink); }

/* meta do mapa (prazo · pessoas · atualizado · matriz · apetite) */
.gr-meta { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; align-items: center; font-size: .84rem; color: var(--gr-muted); }
.gr-meta i { margin-right: .25rem; }

/* filtros em botões (chips) */
.gr-chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.gr-chip { border: 1px solid var(--gr-border-strong); background: var(--gr-surface); border-radius: 999px; padding: .32rem .85rem; font-size: .84rem; color: var(--gr-text); cursor: pointer; }
.gr-chip:hover { background: var(--gr-surface-2); }
.gr-chip.on { background: var(--gr-primary); border-color: var(--gr-primary); color: #fff; }
.gr-chip .n { margin-left: .3rem; opacity: .7; font-size: .76rem; }

/* grade principal dos painéis */
.gr-grid-2 { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.gr-grid-2e { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: start; }
@media (max-width: 1199.98px) { .gr-grid-2, .gr-grid-2e { grid-template-columns: minmax(0, 1fr); } }

/* tabela simples dos "Ver tabela" */
.gr-table { width: 100%; font-size: .84rem; }
.gr-table th { color: var(--gr-muted); font-weight: 500; padding: .45rem .6rem; border-bottom: 1px solid var(--gr-border); text-align: right; }
.gr-table th:first-child, .gr-table td:first-child { text-align: left; }
.gr-table td { padding: .45rem .6rem; border-bottom: 1px solid var(--gr-border); text-align: right; }

.gr-skel { height: 120px; border-radius: var(--gr-radius); background: linear-gradient(90deg, #f0efed, #f7f7f5, #f0efed); background-size: 200% 100%; animation: grskel 1.2s infinite; }
@keyframes grskel { to { background-position: -200% 0; } }

/* progresso (ex.: 1 de 9 revisadas) */
.gr-progress { display: inline-block; width: 70px; height: 5px; border-radius: 3px; background: #e7e5e4; overflow: hidden; vertical-align: middle; }
.gr-progress > span { display: block; height: 100%; background: var(--gr-primary); }
