:root {
  --bg: #f5f7f8; --panel: #ffffff; --ink: #14171a; --muted: #66717a;
  --green: #20b96f; --green-dark: #12965a; --blue: #4297c6; --magenta: #e5135e;
  --black: #0b0b0d;
  --line: #dfe5e8; --soft-green: #e9f8f0; --soft-blue: #edf6fb; --soft-pink: #fdeaf1;
  --shadow: 0 10px 28px rgba(10, 20, 30, .08); --radius: 18px;
}
* { box-sizing: border-box }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: Inter, Segoe UI, Arial, sans-serif }
button, input, select, textarea { font: inherit }
a { color: inherit; text-decoration: none }

/* ---------- Login / troca de senha forçada (shell único) ---------- */
.login-screen { position: fixed; inset: 0; z-index: 200; background: var(--black); display: flex; align-items: center; justify-content: center }
.login-box { background: white; border-radius: 18px; padding: 28px; width: min(380px, 90vw); box-shadow: 0 30px 90px rgba(0, 0, 0, .35) }
.login-box h2 { margin: 0 0 6px }
.login-box p { margin: 0 0 18px; color: var(--muted); font-size: 14px }
.login-box input { width: 100%; margin-bottom: 10px }
.login-error { color: var(--magenta); font-size: 13px; margin-bottom: 10px; display: none }

/* ---------- Primitivas compartilhadas ---------- */
.control { background: white; border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; min-height: 44px; width: 100% }
.btn { border: 0; border-radius: 12px; padding: 10px 14px; cursor: pointer; font-weight: 700; background: var(--black); color: white }
.btn.secondary { background: white; color: var(--ink); border: 1px solid var(--line) }
.btn.green { background: var(--green-dark) }
.btn.danger { background: var(--magenta) }
.btn:disabled { opacity: .5; cursor: not-allowed }
.btn.sm { padding: 6px 10px; font-size: 12px; border-radius: 9px }
.btn-with-help { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap }
.badge { font-size: 11px; font-weight: 800; border-radius: 999px; padding: 4px 8px; background: var(--soft-blue); color: #24617e }
.badge.green { background: var(--soft-green); color: #0d7746 }
.badge.pink { background: var(--soft-pink); color: #a80f45 }
.badge.gray { background: #f0f2f3; color: #576168 }
.badge.purple { background: #efe8fb; color: #5a2fb8 }

/* ---------- Layout do shell ---------- */
/* height fixo (não min-height) + overflow hidden: o menu lateral (item flex
   comum, sem posição própria) passa a ter sempre a altura exata da tela —
   antes, com min-height, o .app crescia junto com o conteúdo do .main e o
   menu "subia junto" (saía de vista ao rolar uma página comprida, tipo
   Farmácias). Agora só o .main rola, o menu fica fixo na tela inteira. */
.app { display: flex; height: 100vh; overflow: hidden }
.sidebar { width: 240px; flex: 0 0 auto; background: var(--black); color: white; padding: 20px 14px; position: relative; overflow-y: auto; display: flex; flex-direction: column; transition: width .18s ease, padding .18s ease }
.sidebar::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: linear-gradient(var(--green), var(--blue), var(--magenta)) }
.sidebar h1 { font-size: 17px; margin: 0 0 4px; padding-left: 6px }
.sidebar .who { font-size: 12px; color: #9aa4ab; margin: 0 0 18px; padding-left: 6px }
.menu-item { display: block; width: 100%; text-align: left; background: transparent; border: 0; color: #cfd6da; padding: 11px 12px; border-radius: 10px; cursor: pointer; font-size: 14px; margin-bottom: 3px }
.menu-item:hover { background: rgba(255, 255, 255, .06) }
.menu-item.active { background: rgba(32, 185, 111, .18); color: white; font-weight: 700 }
.menu-item:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px }
.sidebar-footer { margin-top: auto; padding-top: 10px }
.sidebar-close { display: none }
.main { flex: 1; min-width: 0; padding: 26px 30px; height: 100vh; overflow-y: auto }

/* ---------- Recolher/expandir o menu (só desktop — no mobile o menu já usa
   o off-canvas do hambúrguer/sidebar-close acima, não mexe nisso) ----------
   Botão fica FORA do <aside> (irmão dele no HTML) e com position:fixed —
   por isso continua visível e clicável mesmo com o menu totalmente fechado
   (width:0). "left" muda entre encostado na borda do menu aberto (225px,
   metade do botão sobre a borda) e perto da tela quando fechado (14px). */
.sidebar-collapse-btn {
  border: 0; background: var(--black); color: white;
  width: 28px; height: 28px; border-radius: 8px; cursor: pointer;
  position: fixed; top: 18px; left: 225px; z-index: 90; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .3);
  transition: left .18s ease;
}
.sidebar-collapse-btn:hover { background: #1c2024 }
@media (min-width: 901px) {
  .app.sidebar-collapsed .sidebar { width: 0; padding: 0; overflow: hidden }
  .app.sidebar-collapsed .sidebar-content, .app.sidebar-collapsed .sidebar-footer { display: none }
  .app.sidebar-collapsed .sidebar-collapse-btn { left: 14px }
  /* respiro extra à esquerda só com o menu fechado, pro título da página
     (que começa colado no padding normal do .main) não ficar embaixo do
     botão flutuante */
  .app.sidebar-collapsed .main { padding-left: 60px }
}
.page-title { font-size: 22px; font-weight: 800; margin: 0 0 4px; display: flex; align-items: center; gap: 2px }
.page-sub { color: var(--muted); font-size: 13px; margin: 0 0 20px }

/* ---------- Barra superior + menu hambúrguer (só mobile) ---------- */
.mobile-topbar { display: none }
.mobile-menu-btn { background: rgba(255, 255, 255, .14); border: 0; color: white; width: 40px; height: 40px; border-radius: 10px; font-size: 19px; cursor: pointer; flex: 0 0 auto }
.sidebar-close { border: 0; background: rgba(255, 255, 255, .12); color: white; width: 34px; height: 34px; border-radius: 50%; font-size: 19px; cursor: pointer; position: absolute; top: 12px; right: 12px }

/* ---------- Cartão genérico (dashboards, tabelas, formulários administrativos) ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow) }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px }
.stat span { display: block; color: var(--muted); font-size: 12px }
.stat strong { display: block; font-size: 22px; margin-top: 4px }
table { width: 100%; border-collapse: collapse; font-size: 13px }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line) }
th { color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase }
.section { display: none }
.section.active { display: block }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px }
.progress { height: 10px; border-radius: 999px; background: #eef1f2; overflow: hidden }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--green), var(--blue)) }

/* ---------- Fila de revisão manual de correspondência Google (Enriquecimento) ---------- */
.match-queue-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px }
.match-queue-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 2px }
.match-queue-cnpj { font-size: 12px; color: var(--muted); margin: 0 0 8px }
.match-queue-candidate { font-size: 13px; line-height: 1.6; margin-bottom: 6px }
.match-queue-conflicts { margin: 0 0 8px 18px; padding: 0; color: #a80f45; font-size: 13px }
.match-queue-conflicts li { margin-bottom: 2px }
/* :not([hidden]) em vez de display:flex direto — um display fixo na classe
   teria a mesma especificidade do [hidden]{display:none} do UA stylesheet e,
   por vir depois no cascade, o formulário apareceria sempre aberto mesmo com
   o atributo hidden setado via JS (mesmo bug já visto em pharmacy-detail.js). */
.match-queue-resolve-form:not([hidden]) { margin-top: 8px; display: flex; flex-direction: column; gap: 6px }
.match-queue-resolve-form textarea { width: 100%; min-height: 50px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; resize: vertical; font-size: 13px }
.match-queue-receita-search { background: #fafbfb; border: 1px dashed var(--line); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px }
.match-queue-receita-search .row { margin-bottom: 0 }
.match-queue-receita-search input { min-height: 34px; padding: 6px 10px }
.match-queue-receita-results { margin-top: 6px; display: flex; flex-direction: column; gap: 4px }
.match-queue-receita-hit { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; border-top: 1px dashed var(--line); padding-top: 4px }
.match-queue-receita-hit:first-child { border-top: 0; padding-top: 0 }

/* ---------- Modais administrativos (senha, usuários) ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .42); display: none; align-items: center; justify-content: center; z-index: 100 }
.modal-overlay.show { display: flex }
.modal-box { background: white; border-radius: 18px; padding: 22px; width: min(440px, 92vw); box-shadow: 0 30px 90px rgba(0, 0, 0, .35) }
.modal-box h3 { margin: 0 0 12px }
.field-group { margin-bottom: 10px }
.field-group label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px }
.temp-pass { background: #0e1113; color: #20e08a; font-family: monospace; padding: 12px; border-radius: 10px; font-size: 16px; text-align: center; margin: 10px 0; letter-spacing: 1px; user-select: all; cursor: text; word-break: break-all }

/* Dashboard (Visão geral): grids de tabelas lado a lado, colapsam em 1 coluna no mobile */
.ov-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px }
.ov-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px }

/* Qualquer tabela "crua" dentro de um .card ganha rolagem horizontal própria
   em vez de estourar a largura da tela no mobile — cobre Visão geral,
   Usuários, Auditoria, Importações/Exportações, Campanhas/Respostas de
   Pesquisas etc. sem precisar embrulhar cada tabela manualmente no JS. */
@media (max-width: 720px) {
  .card:has(table) { overflow-x: auto; -webkit-overflow-scrolling: touch }
  table { min-width: 460px }
  /* alvo de toque maior nos botões de ação compactos (tabelas, listas densas) */
  .btn.sm { padding: 8px 12px; min-height: 34px }
}

@media (max-width: 900px) {
  .app { flex-direction: column }
  /* .sidebar já vira position:fixed aqui embaixo (some do fluxo normal) —
     .main passa a ser o único item de fluxo dentro do .app (junto da
     .mobile-topbar), então usa flex:1 pra ocupar o espaço restante da
     coluna em vez do height:100vh fixo do desktop (que sobraria da tela
     e ficaria cortado pelo overflow:hidden do .app). */
  .main { padding: 18px 16px; height: auto; flex: 1 }
  .ov-grid-3 { grid-template-columns: 1fr 1fr }

  .mobile-topbar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 45;
    background: var(--black); color: white; padding: 12px 16px;
  }
  .mobile-topbar strong { font-size: 15px; letter-spacing: .02em }

  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: min(280px, 84vw);
    transform: translateX(-100%); transition: transform .22s ease;
    z-index: 80; box-shadow: 16px 0 45px rgba(0, 0, 0, .3);
  }
  .sidebar.open { transform: translateX(0) }
  .sidebar-close { display: flex; align-items: center; justify-content: center }
  .sidebar-collapse-btn { display: none }
}

@media (max-width: 650px) {
  .ov-grid-2, .ov-grid-3 { grid-template-columns: 1fr }
}

/* ---------- Elegibilidade pré-enriquecimento ---------- */
.eligibility-rule-card { margin-bottom: 16px; box-shadow: none; background: #fbfcfc }
.eligibility-metrics { margin-bottom: 16px }
.eligibility-controls { margin-bottom: 14px }
.eligibility-list { display: grid; gap: 10px; margin-top: 14px }
.eligibility-item { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden }
.eligibility-item[open] { box-shadow: var(--shadow) }
.eligibility-item summary { list-style: none; cursor: pointer; padding: 15px 16px }
.eligibility-item summary::-webkit-details-marker { display: none }
.eligibility-main { display: flex; justify-content: space-between; align-items: center; gap: 14px }
.eligibility-name { display: block; font-size: 15px; line-height: 1.3 }
.eligibility-location { display: block; margin-top: 4px; color: var(--muted); font-size: 12px }
.eligibility-tags { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap }
.elig-tier { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 9px; font-size: 11px; font-weight: 800 }
.elig-tier-a { background: var(--soft-green); color: #0d7746 }
.elig-tier-b { background: #fff5d6; color: #805d00 }
.elig-tier-c { background: var(--soft-pink); color: #a80f45 }
.eligibility-detail { border-top: 1px solid var(--line); padding: 16px; background: #fbfcfc }
.eligibility-data-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px }
.eligibility-data-grid > div { background: white; border: 1px solid var(--line); border-radius: 10px; padding: 10px }
.eligibility-data-grid span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 4px }
.eligibility-data-grid strong { font-size: 12px; line-height: 1.35; overflow-wrap: anywhere }
.eligibility-why { margin-top: 14px; padding: 12px 14px; border-left: 3px solid var(--blue); background: white; border-radius: 0 10px 10px 0 }
.eligibility-why p { margin: 6px 0; color: var(--muted); font-size: 13px }
.eligibility-why ul { margin: 6px 0 0 18px; padding: 0; font-size: 12px; line-height: 1.55 }
.eligibility-review-box { margin-top: 14px; display: grid; grid-template-columns: minmax(190px, .7fr) minmax(260px, 1.3fr); gap: 10px; align-items: end }
.eligibility-review-box .field-group { margin: 0 }
.eligibility-review-actions { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap }
.elig-exclude { color: #a80f45 !important; border-color: #efb1c8 !important }
.eligibility-pagination { display: flex; justify-content: center; align-items: center; gap: 12px; margin: 16px 0 4px }
@media (max-width: 1000px) {
  .eligibility-data-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) }
}
@media (max-width: 700px) {
  .eligibility-main { align-items: flex-start; flex-direction: column }
  .eligibility-tags { justify-content: flex-start }
  .eligibility-data-grid { grid-template-columns: 1fr }
  .eligibility-review-box { grid-template-columns: 1fr }
}
