/* ==========================================================================
   Componentes de conteúdo (cards, kpis, tabelas, chips, formulários) do
   modelo AK Gestor.html. Escopados em ".ak-page" de propósito: cada página
   migrada envolve seu conteúdo em <div class="ak-page">, então essas regras
   não vazam pro resto do app que ainda está em Bootstrap/AdminLTE puro
   (evita colidir com .card/.btn/table já usados em todo lugar).
   Consome os tokens de template/dist/css/custom.css.
   ========================================================================== */

.ak-page { display: grid; gap: 18px; min-width: 0; }
.ak-page .stack { display: grid; gap: 18px; min-width: 0; }

.ak-page .page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.ak-page .page-head h1 { font-size: 26px; font-weight: 600; }
.ak-page .page-head .eyebrow { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.ak-page .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.ak-page .card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); min-width: 0; }
.ak-page .card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.ak-page .card-h h2 { font-size: 15px; font-weight: 600; display: flex; gap: 8px; align-items: center; margin: 0; }
.ak-page .card-b { padding: 18px; }
.ak-page .card-f { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.ak-page .muted { color: var(--muted); }
.ak-page .small { font-size: 13px; }

/* botões */
.ak-page .btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid transparent; border-radius: 9px; padding: 9px 14px; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; line-height: 1.2; text-decoration: none; }
.ak-page a.btn:hover { text-decoration: none; }
.ak-page .btn svg.i { width: 16px; height: 16px; }
.ak-page .btn-primary { background: var(--blue); color: var(--on-accent); }
.ak-page .btn-primary:hover { filter: brightness(1.07); color: var(--on-accent); }
.ak-page .btn-success { background: var(--green); color: var(--on-accent); }
.ak-page .btn-success:hover { filter: brightness(1.07); color: var(--on-accent); }
.ak-page .btn-ghost { background: var(--surface); border-color: var(--line-2); color: var(--ink); }
.ak-page .btn-ghost:hover { background: var(--surface-2); }
.ak-page .btn-danger-ghost { background: none; border-color: var(--line-2); color: var(--red); }
.ak-page .btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 7px; }
.ak-page .btn-block { width: 100%; justify-content: center; padding: 11px 14px; }
.ak-page .btn[disabled] { opacity: .55; cursor: not-allowed; }

/* formulários */
.ak-page .grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px 16px; }
.ak-page .c2 { grid-column: span 2; } .ak-page .c3 { grid-column: span 3; } .ak-page .c4 { grid-column: span 4; }
.ak-page .c5 { grid-column: span 5; } .ak-page .c6 { grid-column: span 6; } .ak-page .c8 { grid-column: span 8; } .ak-page .c12 { grid-column: span 12; }
@media (max-width: 900px) { .ak-page .c2, .ak-page .c3 { grid-column: span 6; } .ak-page .c4, .ak-page .c5, .ak-page .c6, .ak-page .c8 { grid-column: span 12; } }
@media (max-width: 520px) { .ak-page .c2, .ak-page .c3 { grid-column: span 12; } }
.ak-page .c1 { grid-column: span 1; }

/* Linhas repetíveis (produtos / pagamentos): no desktop um cabeçalho único
   rotula as colunas; em tela estreita cada linha vira um bloco com os
   próprios rótulos, senão os campos ficam longe dos nomes. */
@media (max-width: 900px) {
  .ak-page .c1 { grid-column: span 4; }
  .ak-page #produtos > .grid:first-child, .ak-page #pagamentos > .grid:first-child { display: none; }
  .ak-page .row-produto, .ak-page .row-pagamento { padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
  .ak-page .row-produto > .field::before, .ak-page .row-pagamento > .field::before { font-size: 13px; font-weight: 600; color: var(--ink); }
  .ak-page .row-produto > .field:nth-child(1)::before { content: "Produto"; }
  .ak-page .row-produto > .field:nth-child(2)::before { content: "Quant."; }
  .ak-page .row-produto > .field:nth-child(3)::before { content: "Valor"; }
  .ak-page .row-produto > .field:nth-child(4)::before { content: "Frete"; }
  .ak-page .row-produto > .field:nth-child(5)::before { content: "Impostos"; }
  .ak-page .row-produto > .field:nth-child(6)::before { content: "Taxas"; }
  .ak-page .row-pagamento > .field:nth-child(1)::before { content: "Conta"; }
  .ak-page .row-pagamento > .field:nth-child(2)::before { content: "Data"; }
  .ak-page .row-pagamento > .field:nth-child(3)::before { content: "Valor"; }
  .ak-page .row-pagamento > .field:nth-child(4)::before { content: "Status"; }
}
@media (max-width: 520px) { .ak-page .c1 { grid-column: span 6; } }

/* Barra fixa de totais (compra/venda) não pode cobrir o fim do formulário */
main:has(.container_movimento_fixo) { padding-bottom: 110px; }
.ak-page .field { display: grid; gap: 6px; min-width: 0; }
.ak-page .field label { font-size: 13px; font-weight: 600; color: var(--ink); }
.ak-page .ctrl { width: 100%; border: 1px solid var(--line-2); background-color: var(--surface); border-radius: 8px; padding: 9px 11px; font-size: 14px; min-height: 40px; }
.ak-page .ctrl:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 20%, transparent); }
.ak-page textarea.ctrl { min-height: 84px; resize: vertical; }
.ak-page .ctrl::placeholder { color: var(--muted); opacity: .75; }
.ak-page .ctrl[readonly] { background: var(--surface-2); color: var(--muted); }
.ak-page .with-add { display: flex; }
.ak-page .with-add .ctrl, .ak-page .with-add .combobox-container { flex: 1; min-width: 0; }
.ak-page .with-add .ctrl { border-radius: 0 8px 8px 0; }
.ak-page .with-add .combobox-container input.ctrl { border-radius: 0 8px 8px 0; }
.ak-page .with-add .add { border: 1px solid var(--line-2); border-right: 0; background: var(--surface-2); border-radius: 8px 0 0 8px; width: 40px; flex: none; display: grid; place-items: center; cursor: pointer; color: var(--muted); }

/* bootstrap-combobox gera seu próprio .input-group em volta do <input> que
   substitui visualmente o <select>; sem isso o botão (seta) do combobox não
   alinha, porque o CSS do Bootstrap pro input-group só mira .form-control. */
.ak-page .input-group .ctrl { position: relative; flex: 1 1 auto; width: 1%; min-width: 0; }
.ak-page .input-group-text { border-color: var(--line-2); background: var(--surface-2); color: var(--muted); }

/* tabelas */
.ak-page .table-wrap { overflow-x: auto; }
.ak-page table { width: 100%; border-collapse: collapse; font-size: 14px; }
.ak-page th { font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); }
.ak-page td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.ak-page tbody tr:hover td { background: var(--surface-2); }
.ak-page tbody tr:last-child td { border-bottom: 0; }
.ak-page td.r, .ak-page th.r { text-align: right; }
.ak-page td.id { color: var(--muted); font-variant-numeric: tabular-nums; width: 64px; }
.ak-page .stripe-r td:first-child { box-shadow: inset 3px 0 0 var(--green); }
.ak-page .stripe-d td:first-child { box-shadow: inset 3px 0 0 var(--red); }
.ak-page .table-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.ak-page .pager { display: flex; gap: 4px; }
.ak-page .pager button, .ak-page .pager a { min-width: 34px; height: 34px; border: 1px solid var(--line); background: var(--surface); border-radius: 7px; cursor: pointer; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.ak-page .pager .on, .ak-page .pager .active a { background: var(--blue); border-color: var(--blue); color: var(--on-accent); font-weight: 700; }
.ak-page .empty { padding: 36px 18px; text-align: center; color: var(--muted); }
.ak-page .chart-box { position: relative; height: 300px; }
.ak-page .dropzone.ak-drop { border: 1.5px dashed var(--line-2); border-radius: 10px; background: var(--surface-2); min-height: 140px; padding: 20px; color: var(--muted); }
.ak-page .dropzone.ak-drop:hover { border-color: var(--blue); }
.ak-page .dropzone .dz-message { margin: 2em 0; font-weight: 600; }
.ak-page .chart-box.tall { height: 360px; }
@media (max-width: 600px) { .ak-page .chart-box, .ak-page .chart-box.tall { height: 240px; } }
/* "N registro(s) encontrado(s)." que os busca.php imprimem antes da tabela */
.ak-page .card > div > .small.muted:first-child { padding: 12px 18px 10px; }
.ak-page tbody tr td { transition: background-color var(--t-fast) var(--ease); }
.ak-page .btn { transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), filter var(--t-fast) var(--ease); }
.ak-page .prod { display: flex; gap: 10px; align-items: center; }
.ak-page .thumb { width: 38px; height: 38px; border-radius: 8px; background: var(--blue-soft); display: grid; place-items: center; color: var(--blue-ink); flex: none; font-weight: 700; font-size: 12px; overflow: hidden; }
.ak-page .thumb img { width: 100%; height: 100%; object-fit: cover; }
.ak-page .rowmenu { position: relative; display: inline-block; }

/* chips / valores */
.ak-page .chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.ak-page .chip.g { background: var(--green-soft); color: var(--green); }
.ak-page .chip.r { background: var(--red-soft); color: var(--red); }
.ak-page .chip.b { background: var(--blue-soft); color: var(--blue-ink); }
.ak-page .chip.a { background: var(--amber-soft); color: var(--amber); }
.ak-page .chip.n { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.ak-page .chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.ak-page .chip.nodot::before { display: none; }
.ak-page .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ak-page .amt.pos { color: var(--green); }
.ak-page .amt.neg { color: var(--red); }
.ak-page .paybar { display: grid; gap: 5px; min-width: 130px; }
.ak-page .paybar .bar { height: 6px; border-radius: 9px; background: var(--line); overflow: hidden; }
.ak-page .paybar .bar i { display: block; height: 100%; background: var(--green); border-radius: 9px; }
.ak-page .paybar.zero .bar i { background: var(--red); }

/* td.stack: célula com conteúdo rico (várias linhas, chip, negrito) que não
   cabe no padrão "rótulo à esquerda, valor à direita" do celular (definido
   em ak-base.css pra .table-wrap) — empilha como bloco, à esquerda. */
@media (max-width: 720px) {
  .ak-page .table-wrap td.stack { display: block !important; text-align: left !important; }
  .ak-page .table-wrap td.stack::before { display: block; margin-bottom: 6px; }
}
.ak-page td.stack > * + * { margin-top: 6px; }

/* entidades (empresas) */
.ak-page .ent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.ak-page .ent { padding: 18px; display: grid; gap: 14px; }
.ak-page .ent h3 { font-size: 17px; margin: 0; }
.ak-page .ent .bal { display: flex; justify-content: space-between; align-items: center; background: var(--green-soft); color: var(--green); padding: 10px 12px; border-radius: 9px; font-weight: 700; }
.ak-page .ent-new { border: 1.5px dashed var(--line-2); border-radius: var(--r-lg); display: grid; place-items: center; gap: 8px; padding: 24px; color: var(--muted); cursor: pointer; background: none; min-height: 180px; font-weight: 600; text-decoration: none; }
.ak-page .ent-new:hover { border-color: var(--blue); color: var(--blue-ink); }

/* integrações */
.ak-page .int-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.ak-page .int { padding: 18px; display: grid; gap: 12px; align-content: start; text-align: left; }
.ak-page .int .hd { display: flex; align-items: center; gap: 12px; }
.ak-page .int .lg { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-family: var(--f-display); font-weight: 700; font-size: 14px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); flex: none; }
.ak-page .int h3 { font-size: 16px; font-weight: 600; margin: 0; }
.ak-page .int p { margin: 0; color: var(--muted); font-size: 14px; }

/* layout de duas colunas */
.ak-page .half { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
@media (max-width: 860px) { .ak-page .half { grid-template-columns: 1fr; } }

/* kpis */
.ak-page .kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 1100px) { .ak-page .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.ak-page .kpi { padding: 16px 18px; display: grid; gap: 10px; }
.ak-page .kpi .lbl { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.ak-page .kpi .dot { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; flex: none; }
.ak-page .kpi .dot svg { width: 16px; height: 16px; }
.ak-page .kpi .val { font-family: var(--f-display); font-size: 26px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.ak-page .kpi .foot { font-size: 13px; color: var(--muted); }

/* ==========================================================================
   Celular
   ========================================================================== */

/* iOS dá zoom em campo com fonte < 16px ao tocar, desalinhando a página. */
@media (max-width: 900px) {
  .ctrl, .form-control, .ak-page .ctrl, .ak-page .form-control, .ak-page input, .ak-page select, .ak-page textarea, .auth-card .ctrl { font-size: 16px; }
}

@media (max-width: 720px) {
  /* Tabelas viram cartões: cada célula "rótulo  valor" (rótulo vem do
     data-label que static/js/ak-shell.js copia do cabeçalho). */
  .ak-page .table-wrap { overflow: visible; }
  .ak-page .table-wrap table,
  .ak-page .table-wrap tbody,
  .ak-page .table-wrap tr,
  .ak-page .table-wrap td { display: block; width: 100%; }
  .ak-page .table-wrap thead { display: none; }
  .ak-page .table-wrap tbody tr { position: relative; padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .ak-page .table-wrap tbody tr:last-child { border-bottom: 0; }
  .ak-page .table-wrap tbody tr:hover td { background: none; }
  .ak-page .table-wrap td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 5px 0; border: 0; text-align: right; min-width: 0; overflow-wrap: anywhere;
  }
  .ak-page .table-wrap td::before {
    content: attr(data-label); flex: none; max-width: 45%; text-align: left;
    font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted);
  }
  .ak-page .table-wrap td[data-label=""]::before,
  .ak-page .table-wrap td:not([data-label])::before { display: none; }
  .ak-page .table-wrap td[colspan] { display: block; text-align: center; }
  .ak-page .table-wrap td.id { width: auto; }
  .ak-page .table-wrap td.id::before { content: "#"; }
  .ak-page .table-wrap td.id { justify-content: flex-start; gap: 2px; font-size: 13px; }
  /* Botão "..." vai pro canto do cartão */
  .ak-page .table-wrap tbody tr:has(.rowmenu) { padding-right: 56px; }
  .ak-page .table-wrap td:has(> .rowmenu) { position: absolute; top: 8px; right: 8px; width: auto; padding: 0; }
  .ak-page .table-wrap td:has(> .rowmenu)::before { display: none; }
  /* Faixa verde/vermelha de receita/despesa passa pro cartão */
  .ak-page .stripe-r td:first-child, .ak-page .stripe-d td:first-child { box-shadow: none; }
  .ak-page .table-wrap tr.stripe-r { box-shadow: inset 3px 0 0 var(--green); }
  .ak-page .table-wrap tr.stripe-d { box-shadow: inset 3px 0 0 var(--red); }
  /* Célula sem conteúdo (ex.: marca em branco) não precisa de linha */
  .ak-page .table-wrap td:empty { display: none; }
  /* Coluna com o item principal (produto) vira o título do cartão */
  .ak-page .table-wrap td:has(> .prod) { justify-content: flex-start; padding-bottom: 8px; }
  .ak-page .table-wrap td:has(> .prod)::before { display: none; }
  .ak-page .table-wrap td .prod { text-align: left; }

  /* Início: indicadores em 2 colunas e mais compactos */
  .ak-page .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .ak-page .kpi { padding: 12px 14px; gap: 6px; }
  .ak-page .kpi .val { font-size: 19px; }
  .ak-page .kpi .foot { font-size: 12px; line-height: 1.3; }
  .ak-page .kpi .lbl { font-size: 12.5px; }

  .ak-page .empty { padding: 20px 14px; }
  .ak-page .page-head h1 { font-size: 23px; }
}

/* Card "Filtro" recolhível no celular (comportamento em ak-shell.js) */
.ak-page .filter-toggle { display: none; }
@media (max-width: 720px) {
  .ak-page .filter-card > .card-h { cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; }
  .ak-page .filter-toggle { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; }
  .ak-page .filter-toggle .chev { color: var(--muted); transition: transform var(--t-fast) var(--ease); }
  .ak-page .filter-card:not(.collapsed) .filter-toggle .chev { transform: rotate(180deg); }
  .ak-page .filter-card.collapsed > .card-h { border-bottom: 0; }
  .ak-page .filter-card.collapsed > .card-b,
  .ak-page .filter-card.collapsed > .card-f,
  .ak-page .filter-card.collapsed > form { display: none; }
}
