/*
 * Modo de alto contraste opcional (seção 210). Claro reforçado, nível AAA da WCAG: texto a 7:1 do fundo,
 * bordas e ícones a pelo menos 3:1.
 *
 * Tudo aqui vive sob html[data-visual="alto-contraste"], ligado por app-visual.js. Sem o atributo nada muda:
 * o visual padrão é o mesmo de antes. Primeiro os tokens (o app inteiro já os usa); depois o Bootstrap, que
 * tem as cores dele; por último as cores fixas de componentes que não passam por token.
 */

/* ---------- Tokens do app ---------- */
html[data-visual="alto-contraste"] {
  --app-primary: #0b3d91;          /* 10,4:1 no branco */
  --app-primary-dark: #062a66;
  --app-primary-light: #e6ecf7;
  --app-secondary: #0a4a54;
  --app-secondary-light: #e3f1f3;
  --app-accent: #5c3d00;
  --app-accent-hover: #452e00;
  --app-success: #0a5233;
  --app-success-light: #e3f4ea;
  --app-warning: #5c3b00;
  --app-warning-light: #fff1d0;
  --app-danger: #8a1c1c;
  --app-danger-light: #fbe5e6;
  --app-info: #0a4570;
  --app-info-light: #e5f1fa;
  --app-bg: #ffffff;
  --app-surface: #ffffff;
  --app-surface-muted: #f2f2f2;
  --app-text: #000000;
  --app-text-muted: #333333;       /* 12,6:1 */
  --app-border: #595959;           /* 7:1, borda de campo e cartão bem visível */
  --app-shadow-sm: none;
  --app-shadow-md: 0 0 0 2px #000000;
  --sidebar-bg: #000000;
  --sidebar-bg-alt: #1a1a1a;
  --sidebar-active: #ffffff;
  --sidebar-text: #ffffff;
  --sidebar-text-muted: #e6e6e6;
  --sidebar-muted: #d9d9d9;
  --sidebar-accent: #ffd400;

  /* Cores fixas de componentes e de telas passam por estes tokens, com a cor de hoje como reserva:
     color: var(--hc-texto-secundario, oklch(0.5 0.02 255)). Fora do modo eles não existem e nada muda. */
  --hc-texto: #000000;
  --hc-texto-secundario: #333333;
  --hc-texto-perigo: #8a1c1c;
  --hc-texto-atencao: #5c3b00;
  --hc-texto-sucesso: #0a5233;
  --hc-texto-info: #0b3d91;
  --hc-primaria: #0b3d91;
  --hc-primaria-escura: #062a66;

  /* ---------- Bootstrap ---------- */
  --bs-body-color: #000000;
  --bs-body-color-rgb: 0, 0, 0;
  --bs-body-bg: #ffffff;
  --bs-emphasis-color: #000000;
  --bs-secondary-color: #333333;
  --bs-secondary-color-rgb: 51, 51, 51;
  --bs-tertiary-color: #333333;
  --bs-tertiary-color-rgb: 51, 51, 51;
  --bs-secondary-bg: #f2f2f2;
  --bs-tertiary-bg: #f2f2f2;
  --bs-border-color: #595959;
  --bs-border-color-translucent: #595959;
  --bs-link-color: #0b3d91;
  --bs-link-color-rgb: 11, 61, 145;
  --bs-link-hover-color: #062a66;
  --bs-link-hover-color-rgb: 6, 42, 102;
  --bs-primary: #0b3d91;
  --bs-primary-rgb: 11, 61, 145;
  --bs-secondary: #333333;
  --bs-secondary-rgb: 51, 51, 51;
  --bs-success: #0a5233;
  --bs-success-rgb: 10, 82, 51;
  --bs-info: #0a4570;
  --bs-info-rgb: 10, 69, 112;
  --bs-warning: #5c3b00;
  --bs-warning-rgb: 92, 59, 0;
  --bs-danger: #8a1c1c;
  --bs-danger-rgb: 138, 28, 28;
  --bs-dark: #000000;
  --bs-dark-rgb: 0, 0, 0;
  --bs-primary-text-emphasis: #062a66;
  --bs-secondary-text-emphasis: #000000;
  --bs-success-text-emphasis: #0a5233;
  --bs-info-text-emphasis: #0a4570;
  --bs-warning-text-emphasis: #5c3b00;
  --bs-danger-text-emphasis: #8a1c1c;
  --bs-primary-bg-subtle: #e6ecf7;
  --bs-success-bg-subtle: #e3f4ea;
  --bs-info-bg-subtle: #e5f1fa;
  --bs-warning-bg-subtle: #fff1d0;
  --bs-danger-bg-subtle: #fbe5e6;
  --bs-secondary-bg-subtle: #f2f2f2;
  --bs-primary-border-subtle: #0b3d91;
  --bs-success-border-subtle: #0a5233;
  --bs-info-border-subtle: #0a4570;
  --bs-warning-border-subtle: #5c3b00;
  --bs-danger-border-subtle: #8a1c1c;
  --bs-secondary-border-subtle: #595959;
  --bs-focus-ring-color: rgba(0, 0, 0, 0.9);
}

/* Utilitários de texto do Bootstrap usam !important: só se vence com outro. */
html[data-visual="alto-contraste"] .text-muted,
html[data-visual="alto-contraste"] .text-secondary,
html[data-visual="alto-contraste"] .text-body-secondary,
html[data-visual="alto-contraste"] .text-body-tertiary {
  color: #333333 !important;
}

html[data-visual="alto-contraste"] .text-success { color: #0a5233 !important; }
html[data-visual="alto-contraste"] .text-danger { color: #8a1c1c !important; }
html[data-visual="alto-contraste"] .text-warning { color: #5c3b00 !important; }
html[data-visual="alto-contraste"] .text-info { color: #0a4570 !important; }
html[data-visual="alto-contraste"] .text-primary { color: #0b3d91 !important; }

/* Selos (badge) com fundo forte: texto branco no tom escuro. */
html[data-visual="alto-contraste"] .text-bg-primary { background-color: #0b3d91 !important; color: #fff !important; }
html[data-visual="alto-contraste"] .text-bg-secondary { background-color: #333333 !important; color: #fff !important; }
html[data-visual="alto-contraste"] .text-bg-success { background-color: #0a5233 !important; color: #fff !important; }
html[data-visual="alto-contraste"] .text-bg-danger { background-color: #8a1c1c !important; color: #fff !important; }
html[data-visual="alto-contraste"] .text-bg-warning { background-color: #5c3b00 !important; color: #fff !important; }
html[data-visual="alto-contraste"] .text-bg-info { background-color: #0a4570 !important; color: #fff !important; }
html[data-visual="alto-contraste"] .text-bg-light { background-color: #f2f2f2 !important; color: #000 !important; border: 1px solid #595959; }

/* Botões do Bootstrap: cada variante tem as próprias variáveis. */
html[data-visual="alto-contraste"] .btn-primary {
  --bs-btn-bg: #0b3d91;
  --bs-btn-border-color: #0b3d91;
  --bs-btn-hover-bg: #062a66;
  --bs-btn-hover-border-color: #000;
  --bs-btn-active-bg: #062a66;
  --bs-btn-disabled-bg: #595959;
  --bs-btn-disabled-border-color: #595959;
  --bs-btn-disabled-color: #fff;
}

html[data-visual="alto-contraste"] .btn-success { --bs-btn-bg: #0a5233; --bs-btn-border-color: #0a5233; --bs-btn-hover-bg: #063a24; }
html[data-visual="alto-contraste"] .btn-danger { --bs-btn-bg: #8a1c1c; --bs-btn-border-color: #8a1c1c; --bs-btn-hover-bg: #661414; }
html[data-visual="alto-contraste"] .btn-warning { --bs-btn-bg: #5c3b00; --bs-btn-border-color: #5c3b00; --bs-btn-color: #fff; --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #452e00; }
html[data-visual="alto-contraste"] .btn-info { --bs-btn-bg: #0a4570; --bs-btn-border-color: #0a4570; --bs-btn-color: #fff; --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #073352; }
html[data-visual="alto-contraste"] .btn-secondary { --bs-btn-bg: #333; --bs-btn-border-color: #333; --bs-btn-hover-bg: #000; }

html[data-visual="alto-contraste"] .btn-outline-primary { --bs-btn-color: #0b3d91; --bs-btn-border-color: #0b3d91; --bs-btn-hover-bg: #0b3d91; --bs-btn-hover-color: #fff; }
html[data-visual="alto-contraste"] .btn-outline-secondary { --bs-btn-color: #000; --bs-btn-border-color: #333; --bs-btn-hover-bg: #000; --bs-btn-hover-color: #fff; --bs-btn-active-bg: #000; --bs-btn-active-color: #fff; --bs-btn-active-border-color: #000; }
html[data-visual="alto-contraste"] .btn-outline-success { --bs-btn-color: #0a5233; --bs-btn-border-color: #0a5233; --bs-btn-hover-bg: #0a5233; --bs-btn-hover-color: #fff; }
html[data-visual="alto-contraste"] .btn-outline-danger { --bs-btn-color: #8a1c1c; --bs-btn-border-color: #8a1c1c; --bs-btn-hover-bg: #8a1c1c; --bs-btn-hover-color: #fff; }
html[data-visual="alto-contraste"] .btn-outline-warning { --bs-btn-color: #5c3b00; --bs-btn-border-color: #5c3b00; --bs-btn-hover-bg: #5c3b00; --bs-btn-hover-color: #fff; }
html[data-visual="alto-contraste"] .btn-outline-info { --bs-btn-color: #0a4570; --bs-btn-border-color: #0a4570; --bs-btn-hover-bg: #0a4570; --bs-btn-hover-color: #fff; }
html[data-visual="alto-contraste"] .btn-link { --bs-btn-color: #0b3d91; --bs-btn-hover-color: #062a66; text-decoration: underline; }

/* Alertas: texto escuro, borda visível. */
html[data-visual="alto-contraste"] .alert {
  --bs-alert-color: #000;
  --bs-alert-border-color: currentColor;
  border-width: 2px;
}

/* ---------- Leitura ---------- */

/* Link dentro de texto corrido fica sublinhado: cor sozinha não basta para dizer que é link. Cartões e botões
   clicáveis já se mostram pela forma, e sublinhá-los só poluía a tela. */
html[data-visual="alto-contraste"] :is(p, li, td, dd, small, label, .callout-text, .auth-field-row) > a:not(.btn) {
  text-decoration: underline;
}

html[data-visual="alto-contraste"] ::placeholder {
  color: #4d4d4d;
  opacity: 1;
}

html[data-visual="alto-contraste"] .form-control,
html[data-visual="alto-contraste"] .form-select,
html[data-visual="alto-contraste"] .form-check-input {
  border: 2px solid #595959;
}

html[data-visual="alto-contraste"] .form-control:disabled,
html[data-visual="alto-contraste"] .form-control[readonly],
html[data-visual="alto-contraste"] .form-select:disabled {
  background-color: #f2f2f2;
  color: #000;
}

/* Foco: contorno preto grosso com halo amarelo, visível em qualquer fundo. */
html[data-visual="alto-contraste"] :focus-visible {
  outline: 3px solid #000 !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 6px #ffd400 !important;
}

/* No menu escuro, o foco inverte. */
html[data-visual="alto-contraste"] .app-sidebar :focus-visible {
  outline-color: #ffd400 !important;
  box-shadow: 0 0 0 6px #000 !important;
}

/* Item ativo do menu: fundo branco, texto preto, em vez de um véu translúcido. */
html[data-visual="alto-contraste"] .app-nav a.active {
  background: #ffffff;
  color: #000000;
}

html[data-visual="alto-contraste"] .app-nav a.active .app-nav-icon {
  color: #000000;
}

html[data-visual="alto-contraste"] .app-card,
html[data-visual="alto-contraste"] .app-panel,
html[data-visual="alto-contraste"] .card,
html[data-visual="alto-contraste"] .modal-content,
html[data-visual="alto-contraste"] .app-dropdown-menu {
  border: 2px solid #595959;
}

/* Botão do topo e do login mostram o estado também pela forma, não só pela cor. */
html[data-visual="alto-contraste"] [data-visual-alternar][aria-pressed="true"] {
  background: #000;
  color: #ffd400;
  border-color: #000;
}
