/* ═══════════════════════════════════════════════════════════════
   Módulo Gestão de Riscos — prefixo rk-
   Reusa o chassi .fo-shell/.fo-side/.fo-main (gestao_fornecedores.css,
   sempre carregado) — só a cor de marca do módulo (--rk) muda.
   Tokens de global.css. Mobile: tabela com scroll horizontal.
   ═══════════════════════════════════════════════════════════════ */

:root { --rk: var(--chart-series-primary, var(--green)); }

/* ── mod tag / regra ── */
.rk-modtag {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 20px;
  font-size: var(--text-2xs); font-weight: var(--font-bold); letter-spacing: .6px;
  color: var(--green); text-transform: uppercase;
  background: var(--green-soft);
  border-bottom: 1px solid var(--line);
}
.rk-modrule {
  height: 3px;
  background: linear-gradient(90deg, var(--green), transparent 70%);
  margin: 0; border-radius: 0;
}
.fo-side-item.rk-side.active { border-left-color: var(--rk); }

/* ── wrap / cabeçalho de página ── */
.rk-wrap { padding: 4px 4px 24px; }
.rk-head { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.rk-title { font-size: 22px; font-weight: 800; }
.rk-sub { font-size: 12.5px; color: var(--muted); }
.rk-head-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.rk-loading { padding: 40px; text-align: center; color: var(--muted); font-size: 14px; }
.rk-vazio { padding: 18px 16px; color: var(--muted); font-size: 13px; text-align: center; }

/* ── KPIs ── */
.rk-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: 11px; margin-bottom: 14px; }
.rk-kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 15px; }
.rk-kpi .n { font-size: 30px; font-weight: 800; }
.rk-kpi .l { font-size: 11.5px; color: var(--muted); margin-top: 2px; display: flex; align-items: center; gap: 5px; }
.rk-kpi-alert { border-color: rgba(239, 68, 68, .4); }
.rk-kpi-alert .n { color: var(--danger); }
.rk-kpi-warn { border-color: rgba(249, 115, 22, .3); }
.rk-kpi-warn .n { color: var(--rk); }

/* ── dashboard grids ── */
.rk-dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; margin-bottom: 13px; }
.rk-pan-title { font-size: 13px; font-weight: 700; padding: 12px 15px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rk-chart-box { position: relative; box-sizing: border-box; padding: 14px; height: 230px; min-height: 230px; overflow: hidden; }
.rk-chart-box > canvas { display: block; max-width: 100%; max-height: 100%; }
.rk-mini-row { display: flex; align-items: center; gap: 10px; padding: 9px 15px; border-bottom: 1px solid var(--line); font-size: 12.5px; cursor: pointer; }
.rk-mini-row:last-child { border-bottom: none; }
.rk-mini-row:hover { background: rgba(148, 163, 184, .05); }
.rk-mini-row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* barras por processo */
.rk-sbar-row { display: flex; align-items: center; gap: 10px; padding: 9px 15px; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.rk-sbar-row:last-child { border-bottom: none; }
.rk-sbar-nm { flex: 0 0 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk-sbar-track { flex: 1; height: 7px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line); overflow: hidden; }
.rk-sbar-fill { height: 100%; border-radius: 99px; background: var(--rk); }
.rk-sbar-n { font-size: 12px; font-weight: 800; min-width: 22px; text-align: right; }

/* ── filtros ── */
.rk-filtros-card { margin-bottom: 13px; }
.rk-filtros { display: grid; grid-template-columns: minmax(220px, 1.8fr) repeat(4, minmax(145px, 1fr)) auto auto; gap: 9px; padding: 13px 15px; align-items: end; }
.rk-filtros-acoes { display: flex; gap: 8px; align-items: center; justify-content: flex-start; }
.rk-filtros-novo { justify-self: end; }
.rk-filtros-novo .btn { white-space: nowrap; }

/* ── tabela lista ── */
.rk-tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.rk-tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 900px; }
.rk-tbl th { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); text-align: left; padding: 9px 13px; border-bottom: 1px solid var(--line); }
.rk-tbl td { padding: 10px 13px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.rk-tbl tbody tr.rk-linha { cursor: pointer; }
.rk-tbl tbody tr:hover td { background: rgba(148, 163, 184, .05); }
.rk-tbl tbody tr:last-child td { border-bottom: none; }
.rk-tbl-falha { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk-acoes { display: flex; gap: 6px; white-space: nowrap; }
.rk-paginacao { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 11px 15px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.rk-pag-center, .rk-pag-jump { display: flex; align-items: center; gap: 5px; }
.rk-pag-jump { justify-self: end; }
.rk-pag-jump .input { width: 58px; min-height: 30px; padding: 4px 7px; }
.rk-pag-num.active { background: var(--rk); border-color: var(--rk); color: var(--on-primary, #fff); }

/* ── overlay / modal ── */
.rk-overlay { position: fixed; inset: 0; background: var(--overlay, rgba(0,0,0,.72)); display: flex; align-items: flex-start; justify-content: center; padding: 30px 14px; overflow-y: auto; z-index: 1000; }
.rk-modal { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; width: 100%; max-width: 900px; max-height: 90vh; overflow-y: auto; margin: auto 0; }
.rk-modal-head { position: sticky; top: 0; background: var(--rk); color: #fff; padding: 16px 20px; display: flex; justify-content: space-between; align-items: center; border-radius: 18px 18px 0 0; z-index: 2; font-size: 16px; font-weight: 800; }
.rk-modal-x { cursor: pointer; font-size: 18px; background: none; border: none; color: #fff; }
.rk-modal-tabs { display: flex; gap: 2px; padding: 0 20px; border-bottom: 1px solid var(--line); overflow-x: auto; position: sticky; top: 53px; background: var(--panel); z-index: 2; }
.rk-modal-tab { padding: 12px 16px; font-size: 13px; font-weight: 500; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; flex-shrink: 0; }
.rk-modal-tab.active { color: var(--rk); border-color: var(--rk); }
.rk-modal-body { padding: 20px; display: flex; flex-direction: column; gap: 20px; min-height: 200px; }
.rk-modal-foot { display: flex; justify-content: space-between; padding: 16px 20px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--panel); border-radius: 0 0 18px 18px; }

.rk-panel-title { font-size: 18px; font-weight: 700; margin: 0 0 4px; }
.rk-panel-desc { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.rk-section { border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.rk-stitle { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 12px; font-weight: 700; }
.rk-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.rk-grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.rk-full { grid-column: 1 / -1; }
.rk-help-q { display: inline-flex; align-items: center; justify-content: center; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); color: #000; font-size: 10px; font-weight: 700; cursor: help; margin-left: 4px; }

.rk-npr-box { display: flex; align-items: center; gap: 16px; background: var(--surface-alt, var(--panel2)); border-radius: 12px; padding: 16px; margin-top: 12px; }
.rk-npr-num { font-size: 28px; font-weight: 800; }
.rk-npr-info { font-size: 12px; color: var(--muted); }
.rk-npr-info b { display: block; font-size: 13px; color: var(--text); }

.rk-status-flow { display: flex; gap: 8px; flex-wrap: wrap; }
.rk-status-chip { padding: 8px 14px; border-radius: 999px; font-size: 12px; font-weight: 700; border: 1px solid var(--line); background: transparent; cursor: pointer; }

.rk-chip-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.rk-chip { display: flex; align-items: center; gap: 6px; background: var(--surface-alt, var(--panel2)); border: 1px solid var(--line); border-radius: 999px; padding: 6px 8px 6px 12px; font-size: 12px; }
.rk-chip button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; padding: 2px; }

.rk-link-row { display: flex; justify-content: space-between; align-items: center; background: var(--surface-alt, var(--panel2)); border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-top: 8px; }
.rk-link-row small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }

.rk-history-tbl { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 4px; }
.rk-history-tbl th { text-align: left; color: var(--muted); padding: 6px 8px; font-weight: 500; border-bottom: 1px solid var(--line); }
.rk-history-tbl td { padding: 6px 8px; border-bottom: 1px solid var(--line); }

.rk-ibox { display: flex; align-items: flex-start; gap: 8px; padding: 12px 14px; border-radius: 10px; font-size: 13px; }
.rk-ibox-info { background: rgba(56,189,248,.08); border: 1px solid rgba(56,189,248,.25); color: var(--muted); }

/* ── formulário inline (não é popup) — cabeçalho e abas ── */
.rk-form-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.rk-form-tabs { display: flex; gap: 2px; padding: 0; border-bottom: 1px solid var(--line); overflow-x: auto; margin-bottom: 20px; }
.rk-form-tab { padding: 12px 14px; font-size: 12.5px; font-weight: 500; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; flex-shrink: 0; }
.rk-form-tab.active { color: var(--rk); border-color: var(--rk); }
.field { display: flex; flex-direction: column; gap: 4px; }
.rk-section .field label, .rk-form-head .field label { font-size: 11.5px; font-weight: 600; color: var(--muted); }

/* ── diagrama de causa e efeito (mapa Resultado/Falha/Causa/Efeito) ── */
.diagram-wrap { position: relative; }
.diagram { position: relative; overflow: auto; max-height: 72vh; padding: 4px 4px 24px; border: 1px solid var(--line); border-radius: 12px; background: rgba(0,0,0,.08); }
.dcol-header { position: absolute; top: 8px; display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); z-index: 3; }
.dcol-header .dot-legend { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dcol-add { width: 18px; height: 18px; border-radius: 4px; border: 1px solid var(--rk); background: transparent; color: var(--rk); font-size: 12px; font-weight: 900; cursor: pointer; line-height: 1; padding: 0; flex-shrink: 0; }
.dcol-add:hover { background: rgba(234,88,12,.15); }
.dnode { position: absolute; display: flex; flex-direction: column; background: var(--panel2); border: 1.5px solid var(--line); border-left: 4px solid var(--rk); border-radius: 10px; padding: 8px 10px 8px 18px; box-sizing: border-box; }
.dnode.linked { border-color: var(--rk); }
.dnode-texto { flex: 1; width: 100%; resize: none; background: transparent; border: none; color: var(--text); font-size: 13px; font-family: inherit; line-height: 1.4; outline: none; padding: 0; margin-top: 2px; }
.dnode-texto::placeholder { color: var(--muted); }
.dnode-texto:focus { background: rgba(255,255,255,.03); border-radius: 6px; }
.dnode .dnode-rm { position: absolute; left: -9px; top: -9px; width: 19px; height: 19px; border-radius: 50%; background: var(--danger); color: #fff; border: 2px solid var(--panel); font-weight: 900; font-size: 10px; cursor: pointer; z-index: 7; padding: 0; line-height: 1; }
.dnode .dnode-rm:hover { filter: brightness(1.15); }
.dnode-badge { display: inline-block; margin-top: 5px; align-self: flex-start; }
.dnode-resize { position: absolute; right: 2px; bottom: 2px; width: 14px; height: 14px; cursor: nwse-resize; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); opacity: .5; z-index: 7; }
.dnode-resize:hover { opacity: 1; border-color: var(--rk); }
.dnode-drag { position: absolute; left: 2px; top: 8px; bottom: 8px; width: 12px; display: flex; align-items: center; justify-content: center; cursor: grab; color: var(--muted); font-size: 12px; letter-spacing: -2px; line-height: 1; user-select: none; z-index: 7; }
.dnode-drag:active { cursor: grabbing; }
.dnode-drag:hover { color: var(--rk); }
.danchor { position: absolute; width: 13px; height: 13px; border-radius: 50%; background: #8b5cf6; border: 2px solid var(--panel2); cursor: crosshair; z-index: 6; }
.danchor[data-face="top"] { left: 50%; top: -7px; transform: translateX(-50%); }
.danchor[data-face="right"] { right: -7px; top: 50%; transform: translateY(-50%); }
.danchor[data-face="bottom"] { left: 50%; bottom: -7px; transform: translateX(-50%); }
.danchor[data-face="left"] { left: -7px; top: 50%; transform: translateY(-50%); }
.danchor:hover { background: var(--rk); }
.diagram-svg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }

/* ── cards de avaliação por falha (accordion) ── */
.falha-card { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; overflow: hidden; }
.falha-card-h { display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer; background: var(--panel2); }
.falha-card-h .txt { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.falha-card-h .chevron { color: var(--muted); font-size: 12px; transition: transform .15s; display: inline-block; }
.falha-card.open .chevron { transform: rotate(90deg); }
.falha-card-body { padding: 16px; border-top: 1px solid var(--line); }

/* ── lista adicionável de Ações ── */
.acoes-list { display: flex; flex-direction: column; gap: 10px; }
.acao-row { display: flex; align-items: center; gap: 10px; }
.acao-row .n { width: 26px; height: 26px; border-radius: 50%; background: var(--surface-alt, var(--panel2)); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: var(--muted); flex-shrink: 0; }
.acao-row .input { flex: 1; }

/* ── Configurações — seções, chips e escalas ── */
.rk-cfg-section { margin-bottom: 20px; }
.rk-cfg-h { display: flex; align-items: center; justify-content: space-between; padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 13.5px; font-weight: 700; flex-wrap: wrap; gap: 10px; }
.rk-cfg-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 16px; align-items: center; }
.rk-cfg-chip { display: inline-flex; align-items: center; gap: 6px; border: 1.5px solid var(--line); border-radius: 99px; padding: 5px 10px 5px 12px; font-size: 12.5px; font-weight: 600; color: var(--text); background: var(--panel2); }
.rk-cfg-rm { width: 18px; height: 18px; border-radius: 50%; background: rgba(148,163,184,.15); display: flex; align-items: center; justify-content: center; font-size: 9px; cursor: pointer; color: var(--muted); transition: all 150ms; }
.rk-cfg-rm:hover { background: rgba(239,68,68,.2); color: var(--danger); }
.rk-cfg-chip-add { display: inline-flex; align-items: center; gap: 6px; border: 1.5px dashed var(--rk); border-radius: 99px; padding: 5px 12px; font-size: 12.5px; font-weight: 600; color: var(--rk); cursor: pointer; }
.rk-cfg-inline-add { display: flex; align-items: center; gap: 8px; padding: 0 16px 14px; flex-wrap: wrap; }
.rk-cfg-inline-add.hidden { display: none; }

.rk-scale-tbl { width: 100%; min-width: 620px; border-collapse: collapse; font-size: 13px; }
.rk-scale-value-col { width: 104px; min-width: 104px; }
.rk-scale-tbl th { text-align: left; color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; padding: 9px 13px; border-bottom: 1px solid var(--line); }
.rk-scale-tbl td { padding: 10px 13px; border-bottom: 1px solid var(--line); }
.rk-scale-tbl tr:last-child td { border-bottom: none; }

/* ── Responsivo ── */
@media (max-width: 820px) {
  .rk-dash-grid { grid-template-columns: 1fr; }
  .rk-filtros { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
  .rk-filtros-novo { justify-self: start; }
}
@media (max-width: 700px) {
  .rk-wrap { padding: 4px 0 24px; }
  .rk-grid2, .rk-grid3 { grid-template-columns: 1fr; }
  .rk-kpis { grid-template-columns: repeat(2, 1fr); }
  .rk-filtros { grid-template-columns: 1fr; }
  .rk-filtros-acoes, .rk-filtros-novo { justify-self: stretch; }
  .rk-filtros-acoes { justify-content: stretch; }
  .rk-filtros-acoes .btn { flex: 1; }
  .rk-filtros-novo .btn { width: 100%; }
  .diagram { max-height: 60vh; }
  .rk-form-tabs { padding-bottom: 2px; }
  .rk-paginacao { grid-template-columns: 1fr; justify-items: center; }
  .rk-pag-info, .rk-pag-jump { justify-self: center; }
}
