/* ==========================================================================
   Portal/Manager — design system + responsivo (mobile-first).

   Duas camadas, escopadas (não afetam admin/médico):
   - VISUAL  → `.portal` E `.portal-theme` (cards, badges, abas, tabelas, fundo).
   - COMPORTAMENTO → só `.portal` (barra inferior app-like, table-stack mobile,
     ações full-width). O manager usa só `.portal-theme` (visual sem o resto).

   Componentes: templates/portal/_macros.html
   ========================================================================== */

/* ---- Tokens (ambas as camadas) ---- */
:is(.portal, .portal-theme) {
  --p-radius: 14px;
  --p-radius-sm: 10px;
  --p-border: #e7eaf0;
  --p-muted: #667085;
  --p-ink: #1d2433;
  --p-bg: #f5f6f9;
  --p-accent: #0d6efd;
  --p-shadow: 0 1px 2px rgba(16,24,40,.04), 0 4px 14px rgba(16,24,40,.05);
  --p-shadow-hover: 0 6px 16px rgba(16,24,40,.08), 0 16px 32px rgba(16,24,40,.08);
  color: var(--p-ink);
  padding-bottom: 1.5rem;
}

/* Fundo cinza suave atrás do conteúdo (cards "flutuam"). */
:is(.portal, .portal-theme)::before {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--p-bg);
  z-index: -1;
}

/* ---- Tipografia ---- */
:is(.portal, .portal-theme) h1,
:is(.portal, .portal-theme) h2,
:is(.portal, .portal-theme) h3,
:is(.portal, .portal-theme) h4,
:is(.portal, .portal-theme) h5 { letter-spacing: -.01em; font-weight: 700; }
:is(.portal, .portal-theme) h4 { font-size: 1.4rem; }
:is(.portal, .portal-theme) h6 { font-weight: 600; }
:is(.portal, .portal-theme) .text-muted { color: var(--p-muted) !important; }
:is(.portal, .portal-theme) .breadcrumb { font-size: .85rem; }

/* ---- Cards ---- */
:is(.portal, .portal-theme) .card {
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius);
  box-shadow: var(--p-shadow);
  background: #fff;
  overflow: hidden;
}
:is(.portal, .portal-theme) .card-header {
  background: #fff;
  border-bottom: 1px solid var(--p-border);
  padding: .85rem 1.1rem;
}
/* Headers com cor própria (bg-success/primary/info…) são utilitários !important
   do Bootstrap e PERMANECEM coloridos — o branco acima só vale p/ headers neutros. */
:is(.portal, .portal-theme) .card-header h5,
:is(.portal, .portal-theme) .card-header h6 { font-weight: 600; }
:is(.portal, .portal-theme) .card-body { padding: 1.1rem; }
:is(.portal, .portal-theme) .card-body.p-0 { padding: 0; }
:is(.portal, .portal-theme) .bg-light { background: #f6f8fb !important; }
:is(.portal, .portal-theme) .rounded { border-radius: var(--p-radius-sm) !important; }

/* Cards clicáveis de listagem ganham leve elevação no hover (desktop). */
@media (hover: hover) {
  :is(.portal, .portal-theme) .case-card-col .card,
  :is(.portal, .portal-theme) .col-xl-4 > .card,
  :is(.portal, .portal-theme) .col-lg-4 > .card {
    transition: transform .15s ease, box-shadow .15s ease;
  }
  :is(.portal, .portal-theme) .case-card-col .card:hover,
  :is(.portal, .portal-theme) .col-xl-4 > .card:hover,
  :is(.portal, .portal-theme) .col-lg-4 > .card:hover {
    transform: translateY(-2px);
    box-shadow: var(--p-shadow-hover);
  }
}

/* ---- Badges → pílulas com tom suave ---- */
:is(.portal, .portal-theme) .badge {
  font-weight: 600;
  border-radius: 999px;
  padding: .36em .72em;
  letter-spacing: .01em;
}
:is(.portal, .portal-theme) .badge.bg-success   { background: #e7f6ec !important; color: #1a7f37 !important; }
:is(.portal, .portal-theme) .badge.bg-warning   { background: #fff4e5 !important; color: #b54708 !important; }
:is(.portal, .portal-theme) .badge.bg-danger    { background: #fdeceb !important; color: #b42318 !important; }
:is(.portal, .portal-theme) .badge.bg-primary   { background: #e8f0fe !important; color: #1750c4 !important; }
:is(.portal, .portal-theme) .badge.bg-info      { background: #e4f5f8 !important; color: #0e7490 !important; }
:is(.portal, .portal-theme) .badge.bg-secondary { background: #eef1f5 !important; color: #475467 !important; }
:is(.portal, .portal-theme) .badge.bg-light     { background: #f2f4f7 !important; color: #475467 !important; }
:is(.portal, .portal-theme) .badge.bg-dark      { background: #e7eaf0 !important; color: #344054 !important; }
:is(.portal, .portal-theme) a.badge:hover { filter: brightness(.97); text-decoration: none; }

/* ---- Botões ---- */
:is(.portal, .portal-theme) .btn { border-radius: var(--p-radius-sm); font-weight: 500; }
:is(.portal, .portal-theme) .btn-sm { border-radius: 8px; }
:is(.portal, .portal-theme) .btn-primary { box-shadow: 0 1px 2px rgba(13,110,253,.25); }

/* ---- Tabelas ---- */
:is(.portal, .portal-theme) .table { margin-bottom: 0; }
:is(.portal, .portal-theme) .table > :not(caption) > * > * { padding: .8rem 1.05rem; }
:is(.portal, .portal-theme) .table thead th {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--p-muted);
  font-weight: 600;
  background: #fafbfd;
  border-bottom: 1px solid var(--p-border);
}
:is(.portal, .portal-theme) .table tbody td,
:is(.portal, .portal-theme) .table tbody th { border-color: #f0f2f6; vertical-align: middle; }
:is(.portal, .portal-theme) .table-hover > tbody > tr:hover > * { background: #f7f9fc; }
:is(.portal, .portal-theme) .table tfoot th { background: #fafbfd; border-top: 2px solid var(--p-border); }

/* ---- Abas no topo (desktop) — sublinhado limpo ---- */
:is(.portal, .portal-theme) .nav-tabs { border-bottom: 1px solid var(--p-border); gap: .15rem; }
:is(.portal, .portal-theme) .nav-tabs .nav-link {
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--p-muted);
  font-weight: 500;
  padding: .6rem .95rem;
  transition: color .12s ease, border-color .12s ease;
}
:is(.portal, .portal-theme) .nav-tabs .nav-link:hover { color: var(--p-accent); border-bottom-color: #cfe0ff; background: transparent; }
:is(.portal, .portal-theme) .nav-tabs .nav-link.active { color: var(--p-accent); background: transparent; border-bottom-color: var(--p-accent); }

/* ==========================================================================
   COMPORTAMENTO — só `.portal` (não no manager)
   ========================================================================== */

/* 1. Tabela que vira "cards empilhados" no celular (< 768px). */
@media (max-width: 767.98px) {
  .portal .table-stack thead { display: none; }
  .portal .table-stack,
  .portal .table-stack tbody,
  .portal .table-stack tr,
  .portal .table-stack td { display: block; width: 100%; }
  /* Linha = registro que ocupa a largura TODA do card (sem caixa-dentro-de-caixa).
     Registros são separados por uma faixa; dentro do registro, divisórias finas. */
  .portal .table-stack tr {
    border: 0;
    border-bottom: 6px solid var(--p-bg);
    padding: .25rem 1rem .35rem;
    margin: 0;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
  }
  .portal .table-stack tr:last-child { border-bottom: 0; }
  .portal .table-stack td {
    border: 0;
    border-bottom: 1px solid #f2f4f7;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: .6rem 0;
    text-align: right;
  }
  .portal .table-stack tr > td:last-child { border-bottom: 0; }
  .portal .table-stack td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--p-muted);
    text-align: left;
    flex: 0 0 auto;
    font-size: .82rem;
  }
  .portal .table-stack td[data-label=""]::before,
  .portal .table-stack td:not([data-label])::before { content: ""; }
  .portal .table-stack td.cell-actions { justify-content: flex-end; }
  .portal .table-stack tfoot, .portal .table-stack tfoot tr, .portal .table-stack tfoot th { display: block; width: 100%; }
}

/* 2. Barra de navegação inferior (app-like) — só no celular. */
.portal-bottomnav { display: none; }

@media (max-width: 767.98px) {
  .portal { padding-bottom: 5.5rem; }

  .portal-bottomnav {
    display: flex;
    flex-wrap: nowrap;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 1030;
    background: rgba(255,255,255,.94);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--p-border);
    box-shadow: 0 -4px 16px rgba(16,24,40,.06);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .portal-bottomnav .nav-link {
    position: relative;
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    min-height: 58px;
    padding: .45rem .25rem;
    color: #667085;            /* contraste AA sobre branco (era #98a2b3) */
    font-size: .66rem;
    font-weight: 500;
    line-height: 1;
    border: 0;
    background: transparent;
    text-align: center;
    transition: color .12s ease;
  }
  .portal-bottomnav .nav-link i { font-size: 1.3rem; }
  .portal-bottomnav .nav-link.active { color: var(--p-accent); }
  .portal-bottomnav .nav-link.active::before {
    content: "";
    position: absolute;
    top: 0; left: 50%;
    transform: translateX(-50%);
    width: 26px; height: 3px;
    border-radius: 0 0 4px 4px;
    background: var(--p-accent);
  }
  .portal-bottomnav .nav-link span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* 3. Toque/UX no mobile (só portal) */
@media (max-width: 767.98px) {
  .portal .btn-mobile-block { width: 100%; }
  .portal .btn { min-height: 44px; }
  .portal .btn-group-sm .btn,
  .portal .table .btn-sm { min-height: 38px; }
  .portal .portal-pageheader { flex-direction: column; align-items: stretch; gap: .75rem; }
  .portal h4 { font-size: 1.2rem; }
}

/* ---- Cabeçalho de caso (macro case_header) ---- */
:is(.portal, .portal-theme) .portal-casehead h4 { line-height: 1.2; word-break: break-word; }

/* Voltar = link-fantasma sutil (não um CTA pesado). Alinha à borda esquerda,
   tom neutro, vira accent no hover. Área de toque preservada (min-height 40). */
:is(.portal, .portal-theme) .portal-back {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: .25rem .5rem .25rem 0;
  margin-left: -.15rem;
  color: var(--p-muted);
  font-weight: 500;
}
:is(.portal, .portal-theme) .portal-back:hover,
:is(.portal, .portal-theme) .portal-back:focus-visible {
  color: var(--p-accent);
  background: transparent;
}
:is(.portal, .portal-theme) .portal-back i { font-size: 1.05rem; }

/* ---- Guia "Próximos passos" (macro journey_panel) ---- */
:is(.portal, .portal-theme) .portal-journey .journey-ico { font-size: 1.25rem; line-height: 1.4; flex: 0 0 auto; }
:is(.portal, .portal-theme) .portal-journey .journey-title { font-weight: 600; }
:is(.portal, .portal-theme) .portal-journey .journey-done .journey-ico { color: #1a7f37; }
:is(.portal, .portal-theme) .portal-journey .journey-done .journey-title { color: var(--p-muted); font-weight: 500; }
:is(.portal, .portal-theme) .portal-journey .journey-todo .journey-ico,
:is(.portal, .portal-theme) .portal-journey .journey-optional .journey-ico { color: #b4bcc9; }
:is(.portal, .portal-theme) .portal-journey .journey-now { background: #f3f8ff; border-left: 3px solid var(--p-accent); }
:is(.portal, .portal-theme) .portal-journey .journey-now .journey-ico { color: var(--p-accent); }
:is(.portal, .portal-theme) .portal-journey .journey-blocked { background: #fff8ef; border-left: 3px solid #f59e0b; }
:is(.portal, .portal-theme) .portal-journey .journey-blocked .journey-ico { color: #b54708; }

/* ---- Lista de definições (rótulo à esquerda, valor à direita) ----
   Substitui o dl.row col-5/col-7, que quebrava rótulos longos ("Nº do /
   Processo") no celular. Rótulo nunca quebra; valor alinha à direita. */
:is(.portal, .portal-theme) .portal-deflist > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: .45rem 0;
  border-bottom: 1px solid #f2f4f7;
}
:is(.portal, .portal-theme) .portal-deflist > div:last-child { border-bottom: 0; }
:is(.portal, .portal-theme) .portal-deflist dt { margin: 0; color: var(--p-muted); font-weight: 500; white-space: nowrap; }
:is(.portal, .portal-theme) .portal-deflist dd { margin: 0; text-align: right; }

/* ---- Cards de estatística (Contratado/Pago/Saldo) ----
   Moeda NÃO pode quebrar no meio ("R$ 1.470 ,00"). No celular, as 3 colunas
   ficam apertadas → reduzir fonte/padding e travar nowrap no valor. */
:is(.portal, .portal-theme) .portal-stats .fs-5 { white-space: nowrap; }
@media (max-width: 767.98px) {
  /* 3 colunas apertam a moeda → vira lista vertical: rótulo à esquerda,
     valor à direita. Sempre cabe, qualquer valor. */
  .portal .portal-stats > [class*="col-"] { flex: 0 0 100%; max-width: 100%; }
  .portal .portal-stats .p-2,
  .portal .portal-stats .p-md-3 {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: .75rem;
    text-align: left !important;
    padding: .65rem .85rem !important;
  }
  .portal .portal-stats .text-muted.small { font-size: .8rem; }
  .portal .portal-stats .fs-5 { font-size: 1.1rem; margin-left: auto; }
  .portal .portal-stats .badge { flex: 0 0 auto; }

  /* Variante "flat" (card de caso no dashboard): sem caixa interna — a própria
     coluna vira a linha (rótulo à esquerda, valor à direita). */
  .portal .portal-stats--flat > [class*="col-"] {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: .75rem; text-align: left !important; padding: .5rem .1rem;
  }
  .portal .portal-stats--flat > [class*="col-"] + [class*="col-"] { border-top: 1px solid var(--p-border); }
  .portal .portal-stats--flat .text-muted { flex: 0 0 auto; }
  .portal .portal-stats--flat .fw-semibold { margin-left: auto; white-space: nowrap; }
}

/* ---- table-stack: 1ª coluna (nome longo) empilha rótulo-acima-valor à esquerda,
   usando a largura toda em vez de quebrar o texto à direita. ---- */
@media (max-width: 767.98px) {
  .portal .table-stack td:first-child,
  .portal .table-stack td.cell-wide { display: block; text-align: left; }
  .portal .table-stack td:first-child::before,
  .portal .table-stack td.cell-wide::before { display: block; margin-bottom: .15rem; }
}

/* ---- Acessibilidade ---- */
/* Foco visível por teclado em abas, links e botões do portal/tema. */
:is(.portal, .portal-theme) .nav-link:focus-visible,
:is(.portal, .portal-theme) .btn:focus-visible,
:is(.portal, .portal-theme) a:focus-visible {
  outline: 2px solid var(--p-accent);
  outline-offset: 2px;
  border-radius: 6px;
}
/* Respeita "reduzir movimento": sem hover-lift nem transições. */
@media (prefers-reduced-motion: reduce) {
  :is(.portal, .portal-theme) * { transition: none !important; }
  :is(.portal, .portal-theme) .case-card-col .card:hover,
  :is(.portal, .portal-theme) .col-xl-4 > .card:hover,
  :is(.portal, .portal-theme) .col-lg-4 > .card:hover { transform: none; }
}
