/*
 * Painel do bot (#4): só o que o design system do ERP não tem. A base é
 * erp.css (cópia do ERP); o registro do que é novo está em
 * docs/design-system.md. Toda cor passa por token.
 */

/* =========================================================
   Tema escuro: os mesmos tokens semânticos do ERP, redefinidos. Os pares de
   texto e fundo passam de 4,5:1 e os controles de 3:1 (test/contrast.test.ts).
   A ação vira um verde claro com texto escuro por cima.
   ========================================================= */
:root {
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-shell: #1c1915;
    --surface-desk: #26211c;
    --surface-field: #26211c;
    --text: #f5ede3;
    --text-weak: #c2b6a8;
    --border: #8c7b6b;
    --action: #5cc3ad;
    --action-text: #0e211d;
    --action-soft: #173a33;
    --action-soft-text: #93e2d1;
    --action-info: #e4a9d9;
    --action-info-soft: #3a2436;
    --focus: #5cc3ad;
    --layer-production: #45b89f;
    --layer-fees: #e29b2b;
    --layer-profit: #e57a93;
    --layer-production-text: #93e2d1;
    --layer-fees-text: #f4c878;
    --layer-profit-text: #f3a9bb;
    --state-positive: #74d6ab;
    --state-warning: #e29b2b;
    --state-warning-soft: #3b2c12;
    --state-warning-text: #f4c878;
    --state-danger: #ff9196;
    --state-danger-soft: #3f2023;
    --shadow: 0 12px 32px rgb(0 0 0 / 35%);
    --shadow-drawer: -12px 0 32px rgb(0 0 0 / 45%);
    --modal-backdrop: rgb(0 0 0 / 55%);
  }

  /* O ERP pinta a marca do aviso de branco literal; no escuro a ação é clara. */
  .toastMark {
    color: var(--action-text);
  }

  .toast {
    box-shadow: var(--shadow);
  }
}

/* =========================================================
   Base que o ERP define tela a tela
   ========================================================= */
textarea {
  display: block;
  min-height: 96px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-field);
  background: var(--surface-field);
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.45;
  resize: vertical;
}

code {
  font-family: var(--font-data);
  font-size: 0.92em;
}

/* "Ir para o conteúdo": só aparece com o foco do teclado. */
.skipLink {
  min-height: 44px;
  position: absolute;
  top: -100px;
  left: 16px;
  z-index: 20;
  padding: 10px 16px;
  border-radius: var(--radius-field);
  background: var(--action);
  color: var(--action-text);
  font-weight: 800;
}

.skipLink:focus {
  top: 8px;
}

.content:focus {
  outline: none;
}

.tabRegister,
.tabItem {
  text-decoration: none;
}

/* A barra de baixo do painel tem três colunas: Regras, o "+" e Atividade. */
.tabBar {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* O "Sair" é um formulário (POST com CSRF): o form não pode quebrar a linha. */
.appMenuFoot form {
  margin: 0;
}

/* =========================================================
   Cabeçalho da tela: na mesa, o título (30/36) com a linha embaixo e a ação
   à direita; no celular, a barra do topo já diz o nome, e o título fica só
   para o leitor de tela, como no ERP.
   ========================================================= */
.screenHead {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.screenHead > div {
  display: grid;
  gap: 4px;
}

.screenTitle {
  font-size: 30px;
  line-height: 36px;
}

.screenAction .shellIcon {
  width: 20px;
  height: 20px;
}

@media (max-width: 899.98px) {
  .screenTitle {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  /* O "+" da barra de baixo já é a Nova regra. */
  .screenAction {
    display: none;
  }
}

/* =========================================================
   Faixa da pausa geral: embaixo da barra do topo, em toda tela com sessão,
   no tom do alerta de atenção. Tem o botão que desliga a pausa ali mesmo.
   ========================================================= */
.pauseBand {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  border-left: 5px solid var(--state-warning);
  background: var(--state-warning-soft);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
}

.pauseBand p {
  flex: 1 1 260px;
  max-width: 72ch;
}

.pauseBand strong {
  font-weight: 800;
}

.pauseBand form {
  margin: 0;
}

@media (min-width: 900px) {
  .pauseBand {
    padding: 12px var(--gutter);
  }
}

/* =========================================================
   Etiqueta neutra: o que não pede atenção nem é sucesso ("desligada").
   ========================================================= */
.priceTag.muted {
  border: 1px solid var(--border);
  background: var(--surface-shell);
  color: var(--text-weak);
}

.priceTag {
  gap: 4px;
  vertical-align: 2px;
}

/* =========================================================
   Listas: a nota de cima, o vazio e o "mostrar mais".
   ========================================================= */
.listNote,
.listEmpty {
  color: var(--text-weak);
  font-size: 13px;
  font-weight: 600;
  line-height: 18px;
}

.listEmpty {
  font-size: 14px;
  line-height: 20px;
}

.listMore {
  display: flex;
  justify-content: center;
}

.listMore .tertiaryAction {
  display: inline-flex;
  align-items: center;
  min-height: var(--button-height);
}

/* Vazio com a mascote (design system: a mascote mora no vazio). */
.emptyState {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface-desk);
}

.emptyState img {
  flex: none;
  object-fit: contain;
}

.emptyState p + p {
  color: var(--text-weak);
  font-size: 14px;
  font-weight: 600;
}

/* =========================================================
   Atividade: cada linha é um comentário que acionou uma regra, com a DM e a
   resposta pública. Não é link: lê-se a linha.
   ========================================================= */
.activityFilters {
  display: grid;
  gap: 12px;
}

.activityFilters form {
  display: grid;
  min-width: 0;
  margin: 0;
}

.activityRow {
  display: grid;
  gap: 4px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.activityList > li:last-child {
  border-bottom: 0;
}

.activityHead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
}

.activityWho {
  font-size: 16px;
  font-weight: 700;
  line-height: 22px;
  overflow-wrap: anywhere;
}

.activityWhen {
  color: var(--text-weak);
  font-size: 13px;
  font-weight: 600;
  line-height: 18px;
  white-space: nowrap;
}

.activityComment {
  font-size: 15px;
  line-height: 22px;
  overflow-wrap: anywhere;
}

.activityTags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.activityError {
  padding: 6px 10px;
  border-left: 3px solid var(--state-danger);
  border-radius: 0 var(--radius-data) var(--radius-data) 0;
  background: var(--state-danger-soft);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 18px;
  overflow-wrap: anywhere;
}

@media (min-width: 900px) {
  .activityFilters {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    gap: 12px 16px;
  }

  .activityList {
    padding: 0 24px;
  }
}

/* =========================================================
   Formulário da regra: painéis de seção, um campo embaixo do outro.
   ========================================================= */
.ruleForm {
  display: grid;
  gap: 16px;
  max-width: 880px;
}

.formPanel {
  display: grid;
  gap: 16px;
  box-shadow: var(--shadow);
}

.formPanel h2 {
  font-size: 20px;
  line-height: 26px;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field > label:not(.switch) {
  font-size: 13px;
  font-weight: 700;
  line-height: 18px;
}

.fieldHelp {
  color: var(--text-weak);
  font-size: 13px;
  font-weight: 600;
  line-height: 18px;
}

.fieldError {
  color: var(--state-danger);
  font-size: 13px;
  font-weight: 700;
  line-height: 18px;
}

[aria-invalid="true"] {
  border-color: var(--state-danger);
  box-shadow: inset 0 0 0 1px var(--state-danger);
}

/* O aviso preso ao campo, como no ERP (Campos). */
.fieldNotice {
  padding: 8px 12px;
  border-left: 3px solid var(--state-warning);
  border-radius: 0 var(--radius-data) var(--radius-data) 0;
  background: var(--state-warning-soft);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 18px;
}

.formSummary {
  display: grid;
  gap: 6px;
  border-radius: 0 var(--radius-field) var(--radius-field) 0;
}

.formSummary ul {
  margin: 0;
  padding-left: 18px;
}

.formSummary a {
  color: inherit;
  font-weight: 800;
}

.formSummary:focus {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* O interruptor ocupa a largura toda: o alvo é a linha inteira. */
.field > .switch {
  justify-content: flex-start;
  padding: 0;
}

.actionBar a {
  text-decoration: none;
}

/* A página reserva a altura da barra de ação no fim, no celular. */
@media (max-width: 899.98px) {
  .ruleForm {
    padding-bottom: calc(var(--action-bar-height) + env(safe-area-inset-bottom, 0px));
  }

  .actionBar > .secondaryButton {
    width: auto;
  }
}

/* =========================================================
   Seletor do post: "Qualquer post", os posts recentes com a miniatura e a
   legenda, e "Outro post, pelo link". O marcado leva a borda de ação, o
   fundo menta e o "✓", não só a cor.
   ========================================================= */
.postPicker {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.postOption {
  position: relative;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: 8px 12px 8px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-field);
  background: var(--surface-desk);
  cursor: pointer;
}

.postOption input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.postOption::after {
  content: "";
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-radius: 50%;
  font-size: 14px;
  font-weight: 900;
}

.postOption:has(input:checked) {
  border-color: var(--action);
  background: var(--action-soft);
  box-shadow: inset 0 0 0 1px var(--action);
}

.postOption:has(input:checked)::after {
  content: "✓";
  border-color: var(--action);
  background: var(--action);
  color: var(--action-text);
}

.postOption:has(input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.postThumb {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-data);
  background: var(--surface-shell);
  object-fit: cover;
}

.postThumbIcon {
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  color: var(--text-weak);
}

.postText {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.postCaption {
  display: -webkit-box;
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  line-height: 20px;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.postOption:has(input:checked) .postCaption {
  color: var(--action-soft-text);
}

.postDate {
  color: var(--text-weak);
  font-size: 12px;
  font-weight: 600;
  line-height: 17px;
}

/* O link só aparece com "Outro post, pelo link" marcado. */
.postLinkField {
  display: none;
  margin-top: 4px;
}

.postPicker:has(input[value="link"]:checked) .postLinkField,
.postLinkField:has([aria-invalid="true"]) {
  display: grid;
}

@media (min-width: 900px) {
  .postPicker {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .postLinkField {
    grid-column: 1 / -1;
  }
}

/* =========================================================
   Configurações
   ========================================================= */
.settingState {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.formPanel form {
  margin: 0;
}

/* Avisos no Telegram (#6): os interruptores em dois grupos, cada um com o seu título. */
.settingsForm,
.alertGroup {
  display: grid;
  gap: 16px;
}

.alertGroup h3 {
  font-size: 16px;
  line-height: 22px;
}

/* O texto do aviso, como saiu no Telegram: as quebras de linha ficam. */
.alertText {
  font-size: 14px;
  line-height: 20px;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

@media (prefers-reduced-motion: reduce) {
  .skipLink {
    transition: none;
  }
}

/* O primário que é link ("Nova regra") não leva o sublinhado do link. */
a.primary,
a.secondary {
  text-decoration: none;
}

/* =========================================================
   Filtro de spam (#7): a linha do escondido e a seção de Configurações.
   ========================================================= */
/* "Mostrar de novo" fica embaixo da linha, alinhado à esquerda. */
.hiddenAction {
  margin: 6px 0 0;
}

.spamForm {
  display: grid;
  gap: 16px;
  max-width: 720px;
}

.spamForm > button {
  justify-self: start;
}

/* Os interruptores dos padrões, um embaixo do outro, com a legenda no desenho do rótulo do campo. */
.spamPatterns {
  display: grid;
  gap: 12px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.spamPatterns legend {
  margin-bottom: 4px;
  padding: 0;
  font-size: 13px;
  font-weight: 700;
  line-height: 18px;
}

/* =========================================================
   Direct (#5): a seção das Configurações e o canal da Atividade.
   ========================================================= */
.directSettings {
  display: grid;
  gap: 16px;
}

.dayField {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.dayField legend {
  margin-bottom: 6px;
  padding: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  line-height: 20px;
}

/* Os dias em Interruptores, duas colunas no celular e quatro na mesa. */
.dayGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 12px;
}

.timeRow {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
}

.timeRow .fieldHelp,
.timeRow .fieldError {
  grid-column: 1 / -1;
}

.channelSwitch {
  margin: 0;
}

.channelSwitch .segmentedButtons button {
  min-height: 44px;
}

@media (min-width: 900px) {
  .dayGrid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .timeRow {
    max-width: 420px;
  }

  .channelSwitch {
    justify-self: start;
  }
}
