
/* ════════════════════════════════════════════════════════════════════════
   MASTER-DETAIL — Gerenciar Consultores AMS/N2
   Story 2.4.2 · Fonte: geral-gerenciar-final.html linhas 243-839
   ════════════════════════════════════════════════════════════════════════ */

/* ── AC7: Split layout via st.columns([1, 2]) ──
   Motivo: st.markdown open-close div NÃO funciona como container Streamlit.
   O HTML5 parser fecha cada div unclosed ao fim do stMarkdownContainer —
   .arh-mg-split-layout ficava vazia, display:grid sem filhos (KB §1).
   Solução: st.columns cria stHorizontalBlock → stColumn → stVerticalBlock
   real que aceita widgets Python como filhos.

   Sentinels identificam as colunas corretas para estilização via :has().
   KB §5.2: :has() é estável no Streamlit 1.55+ (Chrome 105+).
   KB §4: [data-testid="stColumn"] é seletor estável. */

/* Coluna master (esquerda) — min-height: 600px fiel ao modelo geral-gerenciar-final.html .master-panel */
[data-testid="stColumn"]:has(.arh-mg-master-col-sentinel) {
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md, 8px);
  overflow: hidden;
  min-height: 600px;
}

/* Coluna detail (direita) — min-height: 600px fiel ao modelo .detail-panel */
[data-testid="stColumn"]:has(.arh-mg-detail-col-sentinel) {
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md, 8px);
  overflow: hidden;
  min-height: 600px;
}

/* Gap 3.1: stVerticalBlock dentro da coluna master usa flex-column
   para que a stats bar fique na parte INFERIOR (modelo geral-gerenciar-final.html).
   KB §2: stVerticalBlock é flex-column nativo; forçar height:100% propaga o flex.
   KB §5.2: :has(.sentinel) estável no Streamlit 1.55+. */
[data-testid="stColumn"]:has(.arh-mg-master-col-sentinel)
> [data-testid="stVerticalBlock"] {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 600px;
}

/* Gap 3.1: stats bar cola no fundo via margin-top:auto
   (funciona quando o stVerticalBlock pai é flex-column). */
[data-testid="stColumn"]:has(.arh-mg-master-col-sentinel)
> [data-testid="stVerticalBlock"]
> [data-testid="stElementContainer"]:has(.arh-mg-master-stats-bar) {
  margin-top: auto;
}

/* Gap 3.2: lista de consultores com scroll fixo (modelo: max-height ~420px).
   KB §5.2: :has(.arh-mg-master-list) no stVerticalBlock aninhado da coluna.
   O .arh-mg-master-list é div HTML dentro de stMarkdownContainer —
   o stElementContainer pai recebe o overflow indireto via o filho scrollável. */
[data-testid="stColumn"]:has(.arh-mg-master-col-sentinel)
[data-testid="stElementContainer"]:has(.arh-mg-master-list) {
  max-height: 420px;
  overflow-y: auto;
  flex: 1;
}

/* Ocultar sentinels — não participam do layout visual */
.arh-mg-master-col-sentinel,
.arh-mg-detail-col-sentinel {
  display: none;
}

/* ── Master toolbar ── */
.arh-mg-master-toolbar {
  padding: 14px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface-sunken);
  flex-shrink: 0;
}

.arh-mg-master-toolbar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.arh-mg-master-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
}

.arh-mg-sort-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  border-radius: var(--radius-base, 4px);
  font-family: inherit;
  transition: background-color 150ms ease;
}

.arh-mg-sort-btn:hover { background: var(--surface-hover); }
.arh-mg-sort-btn.active { color: var(--accent-brand-text); }
.arh-mg-sort-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── AC7: Segmented Todos/AMS/N2 (count=3) ── */
.arh-mg-seg-control {
  display: flex;
  background: var(--surface-base);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 2px;
  gap: 1px;
}

/* AC7: .arh-mg-seg-btn count === 3 */
.arh-mg-seg-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 6px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: background-color 150ms ease, color 150ms ease;
}

.arh-mg-seg-btn:hover:not(.active) {
  background: var(--surface-hover);
  color: var(--text-secondary);
}

.arh-mg-seg-btn.active {
  background: var(--accent-brand);
  color: #fff;
}

/* N2 ativo: estilo neutro (sem dados ainda) */
.arh-mg-seg-btn.active.n2-style {
  background: #2A3F58;
  color: var(--text-primary);
}

.arh-mg-seg-btn:focus-visible {
  outline: 2px solid var(--focus-ring, var(--accent-brand));
  outline-offset: 2px;
}

/* HIGH-1 (Echo WCAG 2.4.7 / 1.4.11) — focus-visible em todos os controles interativos
   Story 2.4.2 patch · --focus-ring token canonical (#4D9FFF dark / #1D4ED8 light) */
.arh-mg-btn:focus-visible,
.arh-mg-status-pill:focus-visible,
.arh-mg-status-opt:focus-visible,
.arh-mg-row:focus-visible,
.arh-mg-grupo-card:focus-visible,
.arh-mg-subgrupo-chip:focus-visible,
.arh-radio-opt:focus-visible,
.arh-mg-sort-btn:focus-visible {
  outline: 2px solid var(--focus-ring, #4D9FFF);
  outline-offset: 2px;
}

.arh-mg-mseg-count {
  font-size: 0.65rem;
  font-weight: 500;
  opacity: .75;
}

/* ── AC8: Badges AMS/N2 por row ── */
.arh-mg-row-tipo-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.58rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 10px;
  letter-spacing: .03em;
  flex-shrink: 0;
}

.arh-mg-badge-ams {
  background: rgba(29,78,216,.15);
  color: var(--accent-brand-text);
}

.arh-mg-badge-n2 {
  background: rgba(42,63,88,.6);
  color: var(--text-muted);
}

/* ── Search input ── */
.arh-mg-search-wrap { position: relative; }

.arh-mg-search-icon {
  position: absolute;
  left: 9px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-disabled);
  font-size: 0.8rem;
  pointer-events: none;
}

.arh-mg-search-input {
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-base, 4px);
  padding: 6px 10px 6px 30px;
  font-size: 0.82rem;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  width: 100%;
  transition: border-color 150ms ease;
}

.arh-mg-search-input:focus {
  outline: 2px solid var(--focus-ring, #4D9FFF);
  outline-offset: -1px;
  border-color: var(--accent-brand);
  box-shadow: 0 0 0 2px var(--focus-ring-glow, rgba(77,159,255,.20));
}

/* ── Status pills ── */
.arh-mg-status-pills { display: flex; gap: 4px; flex-wrap: wrap; }

.arh-mg-status-pill {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.71rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

.arh-mg-status-pill:hover { background: var(--surface-hover); }
.arh-mg-status-pill.active { background: var(--accent-brand); border-color: var(--accent-brand); color: #fff; }
.arh-mg-status-pill.ativo.active   { background: rgba(46,204,113,.18); border-color: var(--state-success); color: var(--state-success); }
.arh-mg-status-pill.inativo.active { background: rgba(231,76,60,.18);  border-color: var(--state-danger);  color: var(--state-danger); }
.arh-mg-status-pill.pendente.active{ background: rgba(217,160,32,.18); border-color: var(--state-warning); color: var(--state-warning); }

/* ── Oculta botões Streamlit nativos de seleção de row (#5 fix-v3 2026-05-08) ──
   HISTÓRICO DE FALHAS:
   - fix-v2: usava `.arh-mg-master-list ~ [data-testid="stElementContainer"]`.
     Falhou por Task #98 regra D-01: combinador ~ NÃO cruza stElementContainer.
     `.arh-mg-master-list` é div HTML dentro de stMarkdownContainer — não é
     sibling de stElementContainer no DOM Streamlit (KB §2 + §6).

   SOLUÇÃO fix-v3: usar sentinel span + adjacent sibling + no stVerticalBlock.
   Em geral.py: cada row emite st.markdown(<span class="arh-mg-sel-sentinel">)
   seguido de st.button(sel_xxx). No DOM Streamlit ambos ficam em stElementContainers
   consecutivos NO MESMO stVerticalBlock — o combinador + funciona entre irmãos diretos.

   Seletor: stElementContainer que tem .arh-mg-sel-sentinel (container do sentinel)
   SEGUIDO por (+) stElementContainer do botão (container do sel_xxx button).
   :has() no sentinel container garante que só os botões-row são afetados —
   não toca botões Salvar/Detectar/Cadastrar (que não têm sentinel irmão anterior).

   KB §4: [data-testid="stBaseButton-secondary"] é seletor estável até Streamlit 1.55.
   KB §5.2: must target stElementContainer, não o div interno. */
[data-testid="stElementContainer"]:has(.arh-mg-sel-sentinel)
+ [data-testid="stElementContainer"]:has([data-testid="stBaseButton-secondary"]) {
  height: 0 !important;
  overflow: hidden !important;
  padding: 0 !important;
  margin: 0 !important;
  min-height: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden !important;  /* Echo a11y: remove do tab order e AT (WCAG 2.1.1) */
}

/* ── Master list ── */
.arh-mg-master-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.arh-mg-master-list::-webkit-scrollbar { width: 4px; }
.arh-mg-master-list::-webkit-scrollbar-track { background: transparent; }
.arh-mg-master-list::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 4px; }

/* AC8: cada .arh-mg-row deve ter .arh-mg-row-tipo-badge quando filtroTipo='todos' */
.arh-mg-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background-color 120ms ease;
}

.arh-mg-row:hover  { background: var(--surface-hover); }
.arh-mg-row.active {
  background: rgba(29,78,216,.1);
  border-left-color: var(--accent-brand);
}

.arh-mg-row-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.68rem; font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.arh-mg-row-status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.arh-mg-row-info { min-width: 0; }

.arh-mg-row-nome {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.arh-mg-row-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.arh-mg-row-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}

/* ── Empty state lista N2 ── */
.arh-mg-master-list-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 32px 20px;
  color: var(--text-muted);
  text-align: center;
}

.arh-mg-master-list-empty-icon {
  font-size: 2rem;
  opacity: .4;
}

.arh-mg-master-list-empty-text {
  font-size: 0.78rem;
  line-height: 1.5;
  max-width: 220px;
}

/* ── Master stats bar (rodapé) ── */
/* Modelo: geral-gerenciar-final.html .master-stats-bar — padding:10px 14px + gap:12px */
.arh-mg-master-stats-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-sunken);
  flex-shrink: 0;
}

.arh-mg-mstat {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.arh-mg-mstat-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Detail panel — estados ── */
.arh-mg-detail-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  padding: 40px;
}

.arh-mg-detail-empty-text {
  font-size: 0.85rem;
  text-align: center;
  line-height: 1.5;
}

/* ── N2 detail empty state ── */
.arh-mg-n2-detail-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 48px 40px;
  text-align: center;
}

.arh-mg-n2-detail-icon {
  width: 64px; height: 64px;
  border-radius: 16px;
  background: var(--surface-sunken);
  border: 1px solid var(--border-default);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; color: var(--text-muted);
}

.arh-mg-n2-detail-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.arh-mg-n2-detail-sub {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.6;
  max-width: 420px;
}

.arh-mg-n2-fields-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 420px;
}

.arh-mg-n2-field-placeholder {
  background: var(--surface-sunken);
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-md, 8px);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

.arh-mg-n2-field-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
}

.arh-mg-n2-field-value {
  font-size: 0.78rem;
  color: var(--border-default);
  font-style: italic;
}

/* Botão disabled com tooltip CSS-only */
.arh-mg-btn-disabled {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-base, 4px);
  font-size: 0.83rem;
  font-weight: 500;
  background: var(--surface-sunken);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: .6;
  position: relative;
  font-family: inherit;
}

.arh-mg-btn-disabled-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-base, 4px);
  padding: 6px 10px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  pointer-events: none;
  z-index: 200;
}

.arh-mg-btn-disabled:hover .arh-mg-btn-disabled-tooltip { display: block; }

.arh-mg-n2-roadmap-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  background: var(--surface-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ── AC9: Detail content (consultor selecionado) ── */
.arh-mg-detail-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.arh-mg-detail-header {
  padding: 24px 24px 18px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: flex-start;
  gap: 18px;
  flex-shrink: 0;
}

.arh-mg-detail-avatar-lg {
  width: 56px; height: 56px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.arh-mg-detail-header-info { flex: 1; min-width: 0; }

.arh-mg-detail-nome-input {
  font-size: 1.1rem;
  font-weight: 700;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-base, 4px);
  color: var(--text-primary);
  padding: 3px 6px;
  font-family: inherit;
  width: 100%;
  transition: border-color 150ms ease, background-color 150ms ease;
}

.arh-mg-detail-nome-input:hover {
  border-color: var(--border-default);
  background: var(--surface-sunken);
}

.arh-mg-detail-nome-input:focus {
  outline: 2px solid var(--focus-ring, #4D9FFF);
  outline-offset: -1px;
  border-color: var(--accent-brand);
  background: var(--surface-sunken);
}

/* AC9: sub-info com '—' para omissões (sem mock SLA/aberturas) */
.arh-mg-detail-sub-info {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 6px;
}

.arh-mg-status-select-wrap { margin-top: 8px; padding: 0 6px; }

.arh-mg-status-select { display: inline-flex; gap: 6px; }

.arh-mg-status-opt {
  padding: 3px 12px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-subtle);
  background: transparent;
  font-family: inherit;
  transition: background-color 150ms ease;
}

.arh-mg-status-opt.ativo    { color: var(--state-success); border-color: var(--state-success); }
.arh-mg-status-opt.inativo  { color: var(--state-danger);  border-color: var(--state-danger); }
.arh-mg-status-opt.pendente { color: var(--state-warning); border-color: var(--state-warning); }
.arh-mg-status-opt.selected.ativo    { background: rgba(46,204,113,.15); }
.arh-mg-status-opt.selected.inativo  { background: rgba(231,76,60,.15); }
.arh-mg-status-opt.selected.pendente { background: rgba(217,160,32,.15); }
/* BLOCKER-7 fix (Echo Gate 2 2026-05-09): --state-danger dark #E74C3C sobre
   surface-raised #16202E = 4.29:1 e sobre selected bg = 3.74:1, ambos < 4.5 FALHA.
   Override dark usa #F87171 (red-400) = 5.93:1 / 5.16:1 PASS. */
[data-theme="dark"] .arh-mg-status-opt.inativo         { color: #F87171; border-color: #F87171; }
[data-theme="dark"] .arh-mg-status-opt.selected.inativo { background: rgba(248,113,113,.12); }

/* ── Detail body ── */
/* GAP 2-C (Onda 3): overflow-y + max-height para scroll interno quando conteúdo
   excede viewport — sem overflow a coluna direita quebra o layout.
   KB §5.1: !important não necessário aqui — classe própria, sem conflito emotion-cache. */
.arh-mg-detail-body {
  flex: 1;
  overflow-y: auto;
  max-height: calc(100vh - 180px);
  padding: 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.arh-mg-detail-body::-webkit-scrollbar { width: 4px; }
.arh-mg-detail-body::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 4px; }

.arh-mg-detail-section { display: flex; flex-direction: column; gap: 12px; }

.arh-mg-detail-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

/* ── Grupos grid no detail ── */
.arh-mg-grupos-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.arh-mg-grupo-card {
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-md, 8px);
  padding: 12px 10px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 150ms ease, background-color 150ms ease;
}

.arh-mg-grupo-card:hover { border-color: var(--border-default); background: var(--surface-hover); }

.arh-mg-grupo-card.selected {
  border-color: var(--accent-brand);
  background: rgba(29,78,216,.06);
}

.arh-mg-grupo-card-name { font-size: 0.72rem; font-weight: 700; }
.arh-mg-grupo-card-dot  { width: 8px; height: 8px; border-radius: 50%; }
.arh-mg-grupo-card-header { display: flex; align-items: center; gap: 6px; }

/* ── Sub-grupos TÉCNICO ── */
.arh-mg-subgrupos-grid { display: flex; gap: 6px; flex-wrap: wrap; }

.arh-mg-subgrupo-chip {
  padding: 4px 12px;
  border-radius: var(--radius-base, 4px);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  transition: background-color 150ms ease;
}

.arh-mg-subgrupo-chip:hover { background: var(--surface-hover); }

.arh-mg-subgrupo-chip.selected {
  background: rgba(153,64,16,.15);
  border-color: #994010;
  color: #994010;
}

/* ── Detail footer ── */
.arh-mg-detail-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-sunken);
  flex-shrink: 0;
}

.arh-mg-detail-footer-right { margin-left: auto; }

.arh-mg-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-base, 4px);
  font-size: 0.83rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  font-family: inherit;
  transition: background-color 150ms ease, border-color 150ms ease;
}

.arh-mg-btn-secondary {
  background: var(--btn-secondary-bg);
  border-color: var(--btn-secondary-border);
  color: var(--btn-secondary-text);
}

.arh-mg-btn-secondary:hover { background: var(--btn-secondary-bg-hover); }

.arh-mg-btn-primary {
  background: var(--btn-primary-bg);
  border-color: var(--btn-primary-border);
  color: var(--btn-primary-text);
}

.arh-mg-btn-primary:hover { background: var(--btn-primary-bg-hover); }

.arh-mg-btn-danger {
  background: rgba(231,76,60,.1);
  border-color: rgba(231,76,60,.3);
  color: var(--state-danger);
}

.arh-mg-btn-danger:hover { background: rgba(231,76,60,.18); }

/* ── Modal Cadastro / Excluir (AC10) ── */
/* Usa @st.dialog() nativo Streamlit — CSS suporta layout interno */
.arh-mg-modal-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.arh-mg-modal-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 18px;
  line-height: 1.5;
}

/* Field group no modal */
.arh-mg-field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.arh-mg-field-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}

/* AC10: Radio AMS/N2 — N2 disabled */
.arh-mg-radio-group { display: flex; gap: 8px; }

/* AC10: .arh-radio-opt[name=ams] e .arh-radio-opt[name=n2] (disabled) */
.arh-radio-opt {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-base, 4px);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  position: relative;
  transition: border-color 150ms ease, background-color 150ms ease;
}

.arh-radio-opt:hover:not([disabled]) {
  border-color: var(--border-default);
  background: var(--surface-hover);
}

.arh-radio-opt.selected-ams {
  border-color: var(--accent-brand);
  background: rgba(29,78,216,.08);
  color: var(--accent-brand-text);
}

.arh-radio-opt[disabled],
.arh-radio-opt.disabled {
  opacity: .5;
  cursor: not-allowed;
}

.arh-radio-opt .arh-badge-soon-mini {
  font-size: 0.6rem;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 8px;
  background: var(--surface-hover);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

/* Tooltip CSS-only no radio N2 disabled */
.arh-radio-opt[disabled] .arh-radio-tooltip,
.arh-radio-opt.disabled .arh-radio-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-base, 4px);
  padding: 6px 10px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  pointer-events: none;
  z-index: 300;
}

.arh-radio-opt[disabled]:hover .arh-radio-tooltip,
.arh-radio-opt.disabled:hover .arh-radio-tooltip { display: block; }

/* ── GAP 2-B (Onda 3): botão Salvar Streamlit disabled — cursor + opacity ──
   KB §5.1: !important permitido para override emotion-cache em botão disabled.
   Streamlit aplica opacity via emotion mas NÃO aplica cursor:not-allowed.
   Seletor data-testid="stBaseButton-primary" estável (KB §4). */
[data-testid="stBaseButton-primary"][disabled],
[data-testid="stBaseButton-primary"]:disabled {
  cursor: not-allowed !important;
  opacity: 0.45 !important;
}

/* ── Story 2.13 (Item 2 Onda 3): Mini chart histórico no detail panel ──
   Placeholder visual fiel ao modelo geral-gerenciar-final.html .mini-chart
   Dados ilustrativos (Art. IV — sem dados fabricados em produção). */
.arh-mg-mini-chart {
  background: var(--surface-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md, 8px);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.arh-mg-mini-chart-bar {
  flex: 1;
  border-radius: 3px 3px 0 0;
  transition: opacity 150ms ease;
}
.arh-mg-mini-chart-bar:hover { opacity: 1 !important; }

/* ── GAP-7 fix: Detail footer — estiliza botões Streamlit nativos como footer bar ──
   Os botões Salvar/Desfazer/Excluir ficam em stElementContainers consecutivos após
   o detail-body. Aplicamos visual de footer-bar via seletor :has(.arh-mg-footer-sentinel).
   KB §5.2: :has() no stElementContainer + seletor adjacent. */

/* Marcador de início do bloco footer — emitido antes dos botões */
.arh-mg-footer-sentinel { display: none; }
.arh-mg-cadastrar-sentinel { display: none !important; }
.arh-mg-btn-novo-sentinel { display: none !important; }
.arh-grupos-nav-sentinel { display: none !important; }

/* Esconder st.button real do nav Gerenciar (bridge JS clica nele) */
[data-testid="stElementContainer"]:has(.arh-grupos-nav-sentinel)
+ [data-testid="stElementContainer"]:has([data-testid="stBaseButton-secondary"]) {
  display: none !important;
}

/* Fix M2 — sentinel isola o "+ Cadastrar novo" do min-height global de _final_touches */
[data-testid="stElementContainer"]:has(.arh-mg-cadastrar-sentinel)
+ [data-testid="stElementContainer"] [data-testid="stBaseButton-secondary"] {
  min-height: 32px !important;
  height: auto !important;
  padding: 6px 14px !important;
  font-size: 13px !important;
  font-weight: 600 !important;
}

/* 2026-05-20: botão "+ Cadastrar novo" movido p/ master toolbar.
   O st.button real fica OCULTO (o pill HTML decorativo .arh-mg-btn-novo
   na toolbar dispara o click via bridge JS data-arh-mg-novo). */
[data-testid="stElementContainer"]:has(.arh-mg-btn-novo-sentinel)
+ [data-testid="stElementContainer"]:has([data-testid="stBaseButton-secondary"]) {
  display: none !important;
}

/* Pill decorativo "+ Novo" — coerente com .arh-grupos-btn-gerenciar (mesmo
   accent-brand soft) para harmonia cross-tela. Posicionado no header da
   master toolbar à direita do título "Consultores". */
.arh-mg-btn-novo {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(29, 78, 216, 0.4);
  background: rgba(29, 78, 216, 0.08);
  color: var(--accent-brand-text);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  transition: background-color 150ms ease, border-color 150ms ease;
}
.arh-mg-btn-novo:hover {
  background: rgba(29, 78, 216, 0.15);
  border-color: rgba(29, 78, 216, 0.65);
}
.arh-mg-btn-novo:focus-visible {
  outline: 2px solid var(--accent-brand);
  outline-offset: 2px;
}

/* Light mode — botão coerente com Light-B (text-primary #0A0907) */
[data-theme="light"] .arh-mg-btn-novo {
  color: var(--accent-brand);
  background: rgba(29, 78, 216, 0.06);
  border-color: rgba(29, 78, 216, 0.35);
}
[data-theme="light"] .arh-mg-btn-novo:hover {
  background: rgba(29, 78, 216, 0.12);
  border-color: rgba(29, 78, 216, 0.55);
}

/* Matias R11 2026-05-21: botão Voltar = SÓ ÍCONE (sem texto). Discreto.
   R12 2026-05-21: !important + cobertura :hover/:focus/:visited/:active —
   sublinhado vinha de user-agent stylesheet do <a>. */
.arh-mg-btn-voltar,
.arh-mg-btn-voltar:link,
.arh-mg-btn-voltar:visited,
.arh-mg-btn-voltar:hover,
.arh-mg-btn-voltar:active,
.arh-mg-btn-voltar:focus,
.arh-mg-btn-voltar:focus-visible {
  text-decoration: none !important;
}
.arh-mg-btn-voltar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}
.arh-mg-btn-voltar:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  border-color: var(--border-default);
}
.arh-mg-btn-voltar:focus-visible {
  outline: 2px solid var(--accent-brand);
  outline-offset: 2px;
}

/* Lista master compacta — Matias R8 2026-05-21: consultores estavam muito
   distantes. Reduzir gap entre rows + padding interno. */
/* Matias R10 2026-05-21: ajuste fino — gap:0 absoluto causava overlap (-16px).
   Sentinel container zerado MAS gap:4px entre stElementContainers preserva
   separação mínima sem espaçamento exagerado. Row HTML interno tem padding
   próprio do .arh-mg-row (11px/14px) — só ajustamos containers Streamlit. */
[data-testid="stElementContainer"]:has(.arh-mg-sel-sentinel) {
  height: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  min-height: 0 !important;
  overflow: hidden !important;
}
/* Gap entre rows — Matias R11 2026-05-21: 8px (compacto, ~16px visual final). */
[data-testid="stColumn"]:has(.arh-mg-master-col-sentinel)
[data-testid="stVerticalBlock"] {
  gap: 8px !important;
}
/* Cada .arh-mg-row sem margem externa — gap entre containers já dá separação */
.arh-mg-row {
  margin: 0 !important;
}

/* Fix M1 (2026-05-18 audit Nyx): seletor anterior `:has() + stElementContainer`
   falhava porque o próximo irmão é stHorizontalBlock (não stElementContainer).
   Novo: estiliza o stHorizontalBlock que CONTÉM o sentinel + os botões filhos. */
[data-testid="stHorizontalBlock"]:has(.arh-mg-footer-sentinel) {
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-sunken);
  padding: 16px 24px 14px !important;
  margin-top: 0 !important;
}

/* Botões dentro do footer — neutraliza min-height global de _final_touches.py:215,246 */
[data-testid="stHorizontalBlock"]:has(.arh-mg-footer-sentinel)
  [data-testid="stBaseButton-secondary"],
[data-testid="stHorizontalBlock"]:has(.arh-mg-footer-sentinel)
  [data-testid="stBaseButton-primary"] {
  min-height: 32px !important;
  height: auto !important;
  padding: 6px 14px !important;
  font-size: 13px !important;
}

/* GAP-3 / M-2 fix (audit 2026-05-09): ocultar o st.text_input nativo de busca
   que fica dentro da coluna master. O sentinel .arh-mg-busca-native-sentinel é
   emitido imediatamente antes do widget. O stElementContainer com o sentinel é
   seguido pelo stElementContainer do input nativo — ocultar ambos.

   O search input visual no toolbar HTML (.arh-mg-search-input) é o elemento visual.
   A busca real usa o widget nativo (servidor-side via rerun quando o usuário digita).

   KB §4: [data-testid="stTextInput"] é seletor estável.
   KB §5.2: :has() estável no Streamlit 1.55+. */
[data-testid="stElementContainer"]:has(.arh-mg-busca-native-sentinel) {
  height: 0 !important;
  overflow: hidden !important;
  padding: 0 !important;
  margin: 0 !important;
  min-height: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden !important;
}

[data-testid="stElementContainer"]:has(.arh-mg-busca-native-sentinel)
+ [data-testid="stElementContainer"]:has([data-testid="stTextInput"]) {
  height: 0 !important;
  overflow: hidden !important;
  padding: 0 !important;
  margin: 0 !important;
  min-height: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden !important;
}

.arh-mg-busca-native-sentinel { display: none; }
