/* ============================================================
   wyswyg.css — Query card, textarea, accordion, operadores,
                highlight overlay, validação, explainer
   ============================================================ */

/* ─── Section title (específico do query card) ────────────── */
.section-title {
  font-size: calc(11px * var(--font-scale, 1));
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.section-title--row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ─── Query card ──────────────────────────────────────────── */
.query-card {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
  backdrop-filter: blur(7.5px);
  -webkit-backdrop-filter: blur(7.5px);
}
.query-card:focus-within {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}
.query-card .section-title--row {
  margin-bottom: 8px;
}

/* ─── Q row ───────────────────────────────────────────────── */
.q-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 1;
  width: 100%;
}
.q-row--col   { flex-direction: column; gap: var(--spacing-sm); }
.query-bottom { display: flex; gap: 8px; }

.actions {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px var(--spacing-sm);
  background: linear-gradient(to top, var(--primary-1) 65%, transparent);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ─── Alça de redimensionamento da caixa de busca ─────────── */
/* Nativo (resize: vertical) não serve aqui: o grip do navegador fica no canto
   inferior direito do textarea — exatamente DEBAIXO do botão Buscar (.actions,
   z-index 100). A alça custom fica no centro da borda inferior, área livre
   entre os botões. O limite de expansão é aplicado no JS (Q_RESIZE_MAX em
   wyswyg.js) para o card não espremer filtros/resultados. */
.q-resize-handle {
  position: absolute;
  bottom: -3px; left: 50%;
  transform: translateX(-50%);
  width: 64px; height: 12px;
  display: flex; align-items: center; justify-content: center;
  cursor: ns-resize;
  z-index: 101;
  touch-action: none;
}
.q-resize-handle::before {
  content: '';
  width: 44px; height: 5px;
  border-radius: 999px;
  background: var(--border);
  transition: background .15s;
}
.q-resize-handle:hover::before,
.q-resize-handle.dragging::before { background: var(--primary); }

/* ─── Textarea ────────────────────────────────────────────── */
.q-input {
  resize: none;
  border: none;
  background: transparent;
  width: 100%;
  min-height: 124px;
  padding: 0 0 48px 0;
  /* Força mesma fonte do pai — sem isso o browser usa fonte system no textarea
     e o overlay (que herda do pai) diverge progressivamente */
  font: inherit;
  font-size: inherit;
  line-height: inherit;
  letter-spacing: inherit;
}
.q-input:focus { outline: none; }
.q-input::placeholder { color: var(--text-hint); font-family: "Rawline", sans-serif; font-size: calc(13px * var(--font-scale, 1)); }

textarea.filter-input {
  min-height: 60px;
  padding: 10px;
  width: 100%;
  border: none;
  background: rgba(248,248,248,.8);
}

/* ─── Clear button ────────────────────────────────────────── */
.clear-btn {
  position: absolute;
  right: 6px;
  top: 7px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-hint);
  padding: 2px;
  border-radius: var(--radius-sm);
  display: none;
  align-items: center;
  justify-content: center;
  transition: color .1s;
}
.clear-btn:hover   { color: var(--text); }
.clear-btn.visible { display: flex; }

/* ─── Accordion ───────────────────────────────────────────── */
.accordion { flex: 1; }

.acc-header-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.acc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  cursor: pointer;
  background: rgba(255,255,255,.5);
  user-select: none;
  transition: background .15s;
  gap: 8px;
  height: 36px;
  color: var(--surface);
}
.acc-header:hover { background: var(--primary-3); }

.acc-header-row .acc-header {
  border-radius: var(--radius);
  flex: 1;
  background: rgba(255,255,255,.6);
  overflow: hidden;
}

.acc-left     { display: flex; align-items: center; gap: 6px; min-width: 0; }
.acc-icon     { color: var(--primary); font-size: calc(14px * var(--font-scale, 1)); flex-shrink: 0; }
.acc-title    { font-size: calc(12px * var(--font-scale, 1)); font-weight: 700; color: var(--text); white-space: nowrap; }
.acc-subtitle { font-size: calc(11px * var(--font-scale, 1)); color: var(--text-light); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.acc-chevron      { color: var(--text-light); flex-shrink: 0; transition: transform .2s; display: block; }
.acc-chevron.open { transform: rotate(180deg); }

.acc-body {
  display: none;
  padding: 0;
}
.acc-body.open {
  display: block;
  position: relative;
  top: 0;
  left: 0;
  width: 100%;
  border-top: 1px solid #334155;
  background: #1e293b;
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ─── Dark overrides — tabs ──────────────────────────────── */
.acc-body.open .tabs {
  background: rgba(0,0,0,.25);
  border-color: #334155;
}
.acc-body.open .tab          { color: #cdd6e4; }
.acc-body.open .tab:hover    { background: rgba(255,255,255,.08); color: #ffffff; }
.acc-body.open .tab.active   { background: #2563eb; color: #ffffff; border-color: #2563eb; box-shadow: none; }
.acc-body.open .tab-close    { color: #c4c9d0; }
.acc-body.open .tab-close:hover { background: rgba(255,255,255,.06); color: #dde0e5; }

/* ─── Dark overrides — op-btns ───────────────────────────── */
.acc-body.open .op-btn         { background: rgba(255,255,255,.03); border-color: #2d3f55; }
.acc-body.open .op-btn:hover   { background: rgba(99,179,237,.1); border-color: #4a90d9; box-shadow: none; }
.acc-body.open .op-btn .op-name { color: #e2e8f0; }
.acc-body.open .op-btn .op-desc { color: #98a4b5; }
.acc-body.open .hint            { color: #475569; }


.acc-actions { display: flex; gap: 6px; flex-shrink: 0; }
.acc-actions button {
  height: 36px;
  font-size: calc(12px * var(--font-scale, 1));
  padding: 0 16px 2px;
  border-radius: var(--radius);
}

/* ─── Tabs ────────────────────────────────────────────────── */
.tabs-wrap {
  padding: 8px 8px 6px;
}
.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 8px;
  background: var(--bg-filters, var(--primary-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
}
.tab {
  flex: 1;
  font-size: calc(11px * var(--font-scale, 1));
  font-weight: 700;
  padding: 4px 4px 5px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  transition: background .15s, color .15s;
  font-family: inherit;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
}
.tab:hover  { background: var(--primary-3); color: var(--primary); }
.tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 1px 3px rgba(0,0,0,.18);
}

/* Botão × embutido na barra de tabs */
.tab-close {
  flex: 0 0 auto;
  width: 26px;
  padding: 4px 0 5px;
  color: var(--text-hint);
  font-size: calc(13px * var(--font-scale, 1));
  border-color: transparent;
}
.tab-close:hover { background: var(--primary-3); color: var(--primary); }

.tab-content        { display: none; }
.tab-content.active { display: block; }

/* ─── Operator buttons ────────────────────────────────────── */
.ops-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 6px;
}
.op-btn {
  background: var(--bg-filters, var(--primary-1));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  cursor: pointer;
  text-align: left;
  height: auto;
  transition: border-color .15s, background .15s, box-shadow .15s;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.op-btn:hover  {
  border-color: var(--primary);
  background: var(--primary-3);
  box-shadow: var(--shadow-sm);
}
.op-btn:active { transform: scale(0.97); }

.op-btn .op-name  { font-size: calc(12px * var(--font-scale, 1)); font-weight: 700; color: var(--text); line-height: 1.3; word-break: break-word; font-family: "Courier New", monospace; }
.op-btn .op-desc  { font-size: calc(10px * var(--font-scale, 1)); color: var(--text-hint); line-height: 1.4; }
.op-btn .op-badge { font-size: calc(9px * var(--font-scale, 1)); padding: 1px 5px; border-radius: var(--radius-sm); float: right; margin-left: 4px; font-weight: 700; line-height: 1.5; }

.badge-bool    { background: var(--primary-4); color: var(--primary); }
.badge-text    { background: #e3f5ec; color: #1b7a3e; }
.badge-range   { background: #fff3cd; color: #7d5a00; }
.badge-boost   { background: #fdecea; color: #b00020; }
.badge-prox    { background: #e8f4fd; color: #0c5e8a; }
.badge-special { background: #f0f0f0; color: #444444; }

.hint { font-size: calc(11px * var(--font-scale, 1)); color: var(--text-hint); margin: 0; padding: 8px 4px 0; font-style: italic; text-align: center; }

/* ─── Modal (query operators) ─────────────────────────────── */
.modal-bg {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.modal-bg .modal {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1.25rem;
  max-width: 95vw;
  box-shadow: var(--shadow-md);
  width: auto;
  max-height: none;
  flex-direction: column;
}
.modal-bg .modal h3    { font-size: calc(14px * var(--font-scale, 1)); font-weight: 600; margin: 0 0 10px 0; color: var(--text); }
.modal-bg .modal label { font-size: calc(12px * var(--font-scale, 1)); color: var(--text-light); display: block; margin-bottom: 3px; margin-top: 8px; font-weight: 500; }
.modal-bg .modal input {
  width: 100%;
  font-size: calc(13px * var(--font-scale, 1));
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  font-family: inherit;
  color: var(--text);
}
.modal-bg .modal input:focus { border-color: var(--primary); box-shadow: var(--focus-ring); }
.modal-bg .modal .row { display: flex; gap: 6px; margin-top: 14px; }

/* ─── Highlight overlay ───────────────────────────────────── */
/* Wrapper sem padding — âncora para o overlay */
.ql-wrap {
  position: relative;
  width: 100%;
}

.ql-overlay {
  position: absolute;
  top: var(--spacing-sm); left: var(--spacing-sm); right: var(--spacing-sm); bottom: var(--spacing-sm);
  z-index: 0;
  pointer-events: none;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: hidden;
  /* Mesmos valores que .q-input — não mudar um sem o outro */
  padding: 0 0 48px 0;
  font: inherit;
  font-size: inherit;
  line-height: inherit;
  letter-spacing: inherit;
  background: transparent;
  border-radius: var(--radius);
}

/* Textarea transparente — mostra apenas o overlay colorido */
.ql-transparent {
  position: relative;
  z-index: 1;
  color: transparent !important;
  caret-color: var(--text);
  background: transparent !important;
}

/* ⚠ NUNCA usar font-weight/letter-spacing aqui: o overlay precisa ter EXATAMENTE
   as mesmas métricas de glifo do textarea transparente por baixo — negrito é
   mais LARGO e descolava o cursor do texto conforme a query crescia (pior com
   os nomes longos dos campos de data). O "peso" visual vem de text-shadow,
   que não altera a largura. */
.ql-field         { color: var(--primary); text-shadow: 0 0 .6px currentColor; }
.ql-field-unknown { color: #b45309; text-shadow: 0 0 .6px currentColor; text-decoration: underline wavy #ef4444; }
.ql-colon         { color: var(--text-light); }
.ql-string        { color: #15803d; }
.ql-val           { color: #15803d; }
.ql-op            { color: #7c3aed; text-shadow: 0 0 .6px currentColor; }
.ql-modifier      { color: #0891b2; }
.ql-bracket       { color: #d97706; text-shadow: 0 0 .6px currentColor; }
[data-theme="dark"] .ql-string,
[data-theme="dark"] .ql-val { color: #4ade80; }
[data-theme="dark"] .ql-field-unknown { color: #fbbf24; }

/* ─── Validação ───────────────────────────────────────────── */
.query-input--error {
  border-color: #ef4444 !important;
  box-shadow: 0 0 0 2px rgba(239,68,68,.15) !important;
}
.query-error {
  margin-top: 6px;
  padding: 6px 10px;
  background: #fff1f2;
  border: 1px solid #fecdd3;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.query-error span { font-size: calc(11px * var(--font-scale, 1)); color: #b91c1c; font-weight: 500; }

/* ─── Flash no input ao atualizar ─────────────────────────── */
@keyframes queryUpdated {
  0%   { box-shadow: 0 0 0 0 rgba(0,52,116,0);    border-color: var(--border); }
  25%  { box-shadow: 0 0 0 4px rgba(0,52,116,.25); border-color: var(--primary); }
  60%  { box-shadow: 0 0 0 6px rgba(0,52,116,.1);  border-color: var(--primary); }
  100% { box-shadow: 0 0 0 0 rgba(0,52,116,0);    border-color: var(--border); }
}
.query-updated { animation: queryUpdated .6s ease-out; }

/* ─── Explainer ───────────────────────────────────────────── */
.explain-panel {
  background: var(--primary-8);
  border-bottom: 1px solid var(--border-darker);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: var(--spacing-sm);
  font-size: calc(12px * var(--font-scale, 1));
  line-height: 1.8;
}
.explain-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: calc(10px * var(--font-scale, 1));
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.explain-body { color: var(--text); display: flex; flex-direction: column; gap: 2px; }

/* ── Linha de condição ── */
.qe-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  padding: 4px 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.qe-field {
  font-size: calc(10px * var(--font-scale, 1));
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-4);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.qe-verb {
  font-size: calc(11px * var(--font-scale, 1));
  color: var(--text-light);
  white-space: nowrap;
}
.qe-val {
  font-size: calc(11px * var(--font-scale, 1));
  background: #fff3cd;
  color: #7d5a00;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-family: "Courier New", monospace;
  white-space: nowrap;
}
.qe-boost {
  font-size: calc(10px * var(--font-scale, 1));
  color: #b45309;
  background: #fdecea;
  padding: 1px 5px;
  border-radius: var(--radius-sm);
}

/* ── Conector AND / OR ── */
.qe-connector {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px;
}
.qe-connector::before,
.qe-connector::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.qe-op {
  display: inline-block;
  background: var(--primary-4);
  color: var(--primary);
  font-weight: 700;
  font-size: calc(10px * var(--font-scale, 1));
  padding: 1px 8px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.5px;
  white-space: nowrap;
}

/* ── Grupo aninhado ── */
.qe-group {
  border-left: 2px solid var(--primary-3);
  padding-left: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-left: 4px;
}

.qe-all { color: var(--text-light); font-style: italic; }
.qe-err { color: #b91c1c; }


/* ─── Escopo do texto livre ("só conteúdo") ─────────────────── */
.q-scope-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: calc(12px * var(--font-scale, 1));
  color: var(--text-light);
  cursor: pointer;
  user-select: none;
  /* Nunca transborda o painel (com o painel contraído, o texto vazava por
     cima da alça de toggle e ROUBAVA o clique — travava o fechar/abrir). */
  max-width: 100%;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.q-scope-row input { accent-color: var(--primary); cursor: pointer; }

/* Botão Buscar em modo "Interromper" durante o loading */
.submit.searching { background: #b45309; }
.submit.searching:hover { background: #92400e; }
.submit.searching i { margin-right: 6px; }

/* Aviso com ação no explicador (lote 35): número de processo digitado como
   texto livre. Informativo — a busca funciona; os botões só oferecem as duas
   formas de restringir ao processo. */
.qe-hint {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 9px 11px;
  margin-bottom: 10px;
  background: var(--primary-1, #f0f4fb);
  border: 1px solid var(--primary-3, #dbe6f6);
  border-radius: var(--radius, 6px);
  font-size: calc(11.5px * var(--font-scale, 1));
  line-height: 1.45;
  color: var(--text, #333);
}
.qe-hint-txt { display: flex; gap: 7px; align-items: flex-start; }
.qe-hint-txt i { color: var(--primary, #1351b4); margin-top: 2px; flex-shrink: 0; }
.qe-hint-acoes { display: flex; gap: 6px; flex-wrap: wrap; }
.qe-hint-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px;
  border: 1px solid var(--primary, #1351b4);
  border-radius: 999px;
  background: var(--bg, #fff);
  color: var(--primary, #1351b4);
  font-size: calc(11px * var(--font-scale, 1));
  font-family: inherit;
  cursor: pointer;
  height: auto;
  transition: background .15s, color .15s;
}
.qe-hint-btn:hover { background: var(--primary, #1351b4); color: #fff; }
