/* Camada visual ISV compartilhada: fonte, cabeçalho, rodapé, versão e foco.
   Tokens vêm de instituto.css (cópia de ../shared/styles/instituto.css). */
@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@600;700;800&display=swap');

:root {
  color-scheme: light;
  --font-title: 'Manrope', 'Segoe UI', system-ui, sans-serif;
  --text-soft: #566376; /* texto pequeno: 4,5:1 ou mais sobre branco e sobre o fundo da página */

  /* tokens semânticos (o tema escuro sobrescreve todos) */
  --navy-deep: #082c47;   /* cabeçalho e painéis de destaque */
  --verde: #27ae60;       /* verde do logo: linha do cabeçalho, ações concluídas */
  --title: #0a3d62;
  --tint: #eaf4fb;
  --soft: #f6f9fc;
  --input-bg: #ffffff;
  --input-bd: #738ca5;          /* campos e botões: 3:1 contra o fundo da página e de dentro (WCAG 1.4.11) */
  --borda-controle: var(--input-bd);
  --instituto-border: #c5d3e1;  /* cartões e divisórias: visíveis sem pesar */
  --c-ok: #17683a;   --ok-bg: #e6f4ec;
  --c-warn: #8f5d09; --warn-bg: #fef5e7; --warn-bd: #f8d9a0;
  --c-err: #c0392b;  --err-bg: #fdecea;  --err-bd: #f5c6c0;
  --alert-err-text: #922b21;
  --alert-warn-text: #6f4607;

  /* gráficos (Chart.js lê estes valores via themeVar) */
  --chart-text: #64748b;
  --chart-border: #dce6f0;
  --chart-grid: rgba(220, 230, 240, .9);
  --chart-bg: #ffffff;
  --chart-title: #0a3d62;
  --chart-body: #2c3e50;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --navy-deep: #061d30;
  --instituto-bg: #0e1a26;
  --instituto-surface: #15283a;
  --instituto-text: #e3ebf3;
  --instituto-border: #27405a;
  --instituto-shadow: 0 2px 12px rgba(0, 0, 0, .35);
  --text-soft: #9fb0c1;

  --title: #8fc7f0;
  --tint: #1d3a56;
  --soft: #1a3045;
  --input-bg: #0e1a26;
  --input-bd: #6a8dac;
  --borda-controle: var(--input-bd);
  --c-ok: #5fd08e;   --ok-bg: rgba(46, 175, 104, .16);
  --c-warn: #f0b44f; --warn-bg: rgba(224, 149, 26, .16); --warn-bd: rgba(240, 180, 79, .35);
  --c-err: #f08a85;  --err-bg: rgba(217, 83, 79, .16);   --err-bd: rgba(240, 138, 133, .35);
  --alert-err-text: #f5b7b4;
  --alert-warn-text: #f3cd8a;

  --chart-text: #9fb0c1;
  --chart-border: #27405a;
  --chart-grid: rgba(39, 64, 90, .8);
  --chart-bg: #15283a;
  --chart-title: #8fc7f0;
  --chart-body: #e3ebf3;
}

* { margin: 0; padding: 0; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  line-height: 1.5;
}

h1, h2, h3 { font-family: var(--font-title); }

.page-header {
  position: relative; z-index: 60;
  padding: 10px 28px;
  gap: 8px 20px;
  background: var(--navy-deep);
  box-shadow: none;
  border-bottom: 3px solid var(--verde);
}
.page-header .brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand__logo {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: #fff;
  padding: 2px;
  flex-shrink: 0;
}
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-header__title { font-family: var(--font-title); font-size: 19px; font-weight: 800; letter-spacing: -.01em; line-height: 1.2; }
.page-header__subtitle { font-size: 13px; margin-top: 1px; }
.page-header__actions { align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.header-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, .35);
  border-radius: 8px;
  color: #fff;
  font-size: 13px; font-weight: 700;
  text-decoration: none;
  transition: background .2s ease, border-color .2s ease;
}
.header-btn:hover { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .6); }

button.header-btn { background: none; font-family: inherit; cursor: pointer; }
.theme-toggle { width: 38px; padding: 0; }
.theme-toggle svg { width: 18px; height: 18px; flex-shrink: 0; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

.version-badge {
  display: inline-flex; align-items: center;
  min-height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  font-size: 12px; font-weight: 700;
}

.app-footer {
  padding: 14px 32px;
  background: var(--instituto-surface);
  border-top: 1px solid var(--instituto-border);
  color: var(--text-soft);
  font-size: 13px;
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px 16px;
}

/* selo de aviso curto ao lado de um título */
.selo-exemplo {
  display: inline-block; margin-left: 8px; padding: 1px 10px; border-radius: 999px; vertical-align: middle;
  font-size: 12px; font-weight: 700; background: var(--warn-bg); color: var(--alert-warn-text);
}

/* usuário logado no cabeçalho: iniciais + nome e perfil */
.user-chip { display: inline-flex; align-items: center; gap: 10px; color: #fff; margin-right: 4px; }
.user-chip__avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: #1e8449; color: #fff; /* verde do logo é claro demais para texto branco (2,9:1) */
  font: 800 13px var(--font-title);
}
.user-chip__txt { display: flex; flex-direction: column; line-height: 1.2; }
.user-chip__txt b { font-size: 14px; }
.user-chip__txt small { font-size: 12px; opacity: .8; }

/* login e troca de senha */
.auth-card {
  width: 100%; max-width: 400px; margin: 24px auto;
  padding: 28px 24px;
  border: 1px solid var(--instituto-border);
}
.auth-card h2 { font-size: 20px; color: var(--title); margin-bottom: 4px; }
.auth-card > p { color: var(--text-soft); font-size: 14px; margin-bottom: 20px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 14px; font-weight: 600; }
.field input {
  min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--input-bd); border-radius: 10px;
  background: var(--input-bg); color: var(--instituto-text);
  font: inherit; font-size: 15px;
}
.btn-block { width: 100%; min-height: 44px; }
.show-pass { display: flex; align-items: center; gap: 8px; min-height: 44px; font-size: 14px; cursor: pointer; }
.show-pass input { width: 18px; height: 18px; }
.index-status { max-width: 520px; margin: 18px auto 0; text-align: center; }
.form-msg { min-height: 20px; margin-bottom: 12px; font-size: 14px; white-space: pre-line; }
.form-msg.erro { color: var(--c-err); }
.form-msg.ok { color: var(--c-ok); }

/* avisos em faixa (teste, carregando, erro) */
.notice {
  padding: 12px 16px; border-radius: 10px; margin-bottom: 16px;
  font-size: 14px; background: var(--tint); color: var(--instituto-text);
  border: 1px solid var(--instituto-border);
}
.notice.ok { background: var(--ok-bg); border-color: var(--c-ok); color: var(--c-ok); font-weight: 600; }
.notice.warn { background: var(--warn-bg); border-color: var(--warn-bd); color: var(--alert-warn-text); }
.notice.erro { background: var(--err-bg); border-color: var(--err-bd); color: var(--alert-err-text); white-space: pre-line; }
.notice[hidden] { display: none; }

/* esqueleto: ocupa o lugar do conteúdo enquanto ele chega (no lugar de "Carregando…") */
.skeleton {
  display: block; border-radius: 8px;
  background: linear-gradient(100deg, var(--soft) 30%, var(--tint) 50%, var(--soft) 70%) 0 0 / 200% 100%;
  animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

:focus-visible { outline: 3px solid var(--instituto-secondary); outline-offset: 2px; }

@media (max-width: 900px) {
  .app-footer { padding: 12px 16px; }
}

@media (max-width: 720px) {
  .user-chip__txt { display: none; }
  .page-header { padding: 8px 14px; }
}

@media (max-width: 560px) {
  .page-header__actions { width: 100%; justify-content: flex-end; }
  .header-btn { min-height: 44px; }
  .theme-toggle { width: 44px; }
  .hide-xs { display: none; }
  .brand__logo { width: 36px; height: 36px; }
  .page-header__title { font-size: 16px; }
  .page-header__subtitle { display: none; }
  .header-btn { min-height: 44px; padding: 0 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* rodapé: links de ajuda e aviso de servidor lento */
.app-footer { flex-wrap: wrap; gap: 4px 16px; }
.rodape-links a { color: inherit; font-weight: 600; text-underline-offset: 3px; }
.rodape-links a:hover { color: var(--title); }
.aviso-lento {
  position: fixed; left: 50%; bottom: 72px; transform: translateX(-50%); z-index: 300;
  max-width: calc(100vw - 32px); padding: 10px 18px; border-radius: 999px;
  background-color: var(--instituto-surface); background-image: linear-gradient(var(--warn-bg), var(--warn-bg));
  color: var(--alert-warn-text); border: 1px solid var(--c-warn);
  font-size: 14px; font-weight: 600; box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
}

/* migalhas e rodapé: links com alvo de toque de 44 px no celular */
@media (max-width: 720px) {
  .rodape-links a { display: inline-block; padding: 13px 6px; }
  .app-footer { padding-top: 4px; padding-bottom: 4px; }
}
a.fech-selo, .fech-link { position: relative; }
a.fech-selo::after { content: ""; position: absolute; inset: -8px -2px; }
@media (max-width: 720px) { .fech-unidade b .fech-link { padding: 12px 0; } }

@media (max-width: 640px) { .header-btn { min-width: 44px; justify-content: center; } }
