/* ==================================================================
   AppCamera — tema escuro
   Paleta calibrada para leitura longa: fundo azulado profundo (não preto
   puro, que cansa a vista), superfícies com borda de 1px para separar os
   blocos sem precisar de sombra forte, e texto secundário com contraste
   suficiente para ser lido (>= 4.5:1), não cinza apagado.
   ================================================================== */
:root {
  --bg: #0b0e14;
  --surface: #141922;
  --surface-alt: #1c2230;
  --surface-hover: #222a3a;
  --border: #252d3d;
  --border-soft: #1e2532;

  --text: #e8edf5;
  --text-dim: #b6c0d0;
  --muted: #8f9bb0;

  --primary: #3b82f6;
  --primary-soft: #60a5fa;
  --primary-bg: rgba(59, 130, 246, .14);
  --danger: #f0616d;
  --danger-bg: rgba(240, 97, 109, .14);
  --success: #35c98a;
  --success-bg: rgba(53, 201, 138, .14);
  --warning: #f0b429;
  --warning-bg: rgba(240, 180, 41, .14);

  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  /* system-ui é evitado de propósito: no Windows ele às vezes resolve para
     uma fonte de display arredondada e o painel inteiro fica com cara errada. */
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-soft); text-decoration: none; }
a:hover { color: #93c0ff; }

h1, h2, h3 { margin: 0 0 12px; letter-spacing: -.01em; line-height: 1.3; }
h1 { font-size: 21px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 600; }

.muted { color: var(--muted); }
.text-center { text-align: center; }

/* ---------- Topbar (área do usuário) ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 15px; color: var(--text); letter-spacing: -.01em; }
.topnav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topnav a { color: var(--muted); font-weight: 500; padding: 6px 10px; border-radius: 8px; }
.topnav a:hover { color: var(--text); background: var(--surface-alt); }
.topnav a.is-active { color: var(--primary-soft); background: var(--primary-bg); }
.topbar-user { display: flex; align-items: center; gap: 12px; color: var(--muted); }

.container { max-width: 1100px; margin: 0 auto; padding: 24px; }

/* ---------- Botões ---------- */
.btn, button.btn {
  display: inline-block; background: var(--primary); color: #fff;
  border: 1px solid transparent; border-radius: var(--radius);
  padding: 10px 16px; font-size: 14px; font-weight: 600;
  font-family: inherit; cursor: pointer; text-align: center;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: #2f74e8; color: #fff; }
.btn-block { display: block; width: 100%; }
.btn-ghost {
  display: inline-block; background: var(--surface-alt); border: 1px solid var(--border);
  color: var(--text-dim); border-radius: 8px; padding: 7px 13px;
  font-size: 13px; font-weight: 550; font-family: inherit; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); border-color: #34405a; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #dc4f5b; }
.btn-outline { background: transparent; border: 1px solid var(--primary); color: var(--primary-soft); }
.btn-outline:hover { background: var(--primary-bg); color: var(--primary-soft); }
.btn-ghost.btn-danger { color: #fff; border-color: transparent; }
.btn-ghost.btn-danger:hover { color: #fff; }

/* ---------- Formulários ---------- */
label { display: block; margin: 14px 0 6px; color: var(--text-dim); font-size: 13px; font-weight: 550; }
input[type=text], input[type=email], input[type=password],
input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 10px 13px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 14px; font-family: inherit;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-bg);
}
input::placeholder, textarea::placeholder { color: #6b7689; }
input[readonly] { color: var(--muted); background: var(--surface-alt); cursor: text; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
  linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.check input { width: auto; }
.check label, label.check { margin: 0; }
small.muted { display: block; margin: 6px 0 0; font-size: 12px; line-height: 1.45; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }

/* ---------- Flash ---------- */
.flash {
  padding: 11px 15px; border-radius: var(--radius); margin-bottom: 18px;
  font-size: 14px; font-weight: 550; border: 1px solid transparent;
}
.flash-success { background: var(--success-bg); color: var(--success); border-color: rgba(53, 201, 138, .3); }
.flash-error { background: var(--danger-bg); color: var(--danger); border-color: rgba(240, 97, 109, .3); }

/* ---------- Cartões ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow);
  container-type: inline-size;   /* permite o gráfico reagir à largura do card */
}
.card > h2:first-child, .card > h1:first-child { margin-top: 0; }

/* Cabeçalho de cartão: título à esquerda, número/ação à direita */
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.card-head h2 { margin: 0; }
.card-head .card-sub { color: var(--muted); font-size: 12px; }

/* ---------- Autenticação ---------- */
body.centered { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 20px; }
.auth-wrap { width: 100%; max-width: 400px; }
.auth-wrap .card { padding: 28px; }
.card h1 { text-align: center; }

/* ---------- Grades ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 18px; }

/* ---------- Câmeras ---------- */
.device-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden; transition: border-color .15s;
}
.device-card:hover { border-color: #34405a; }
.device-thumb { aspect-ratio: 16/9; background: var(--surface-alt); position: relative;
  display: flex; align-items: center; justify-content: center; color: var(--muted); }
.device-thumb .play { font-size: 42px; color: rgba(255,255,255,.7); position: absolute; }
.badge { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.65);
  padding: 3px 10px; border-radius: 20px; font-size: 12px; display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.online { background: var(--success); box-shadow: 0 0 0 3px var(--success-bg); }
.device-body { padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; }
.device-body b { font-size: 14px; }
/* Ações do card. Ficam fora do link de "ao vivo" porque link dentro de link
   não é HTML válido — o navegador desmonta a marcação e o clique erra o alvo. */
.device-links { display: flex; gap: 4px; padding: 0 10px 6px; }
/* O padding aqui é área de toque, não enfeite: sem ele o link fica com 20px de
   altura e erra o dedo no celular. */
.device-links a { font-size: 13px; color: var(--muted); padding: 8px 10px; border-radius: 8px; }
.device-links a:hover { color: var(--text); background: var(--surface-alt); }

.page-head { display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-actions { display: flex; align-items: center; gap: 10px;
  justify-content: flex-end; margin-bottom: 18px; flex-wrap: wrap; }

/* ---------- Player ao vivo ---------- */
/* O 16/9 é só o palpite inicial: o app.js troca pela proporção real do quadro
   quando o vídeo chega. O teto de altura existe para câmera de quadro em pé
   (duas lentes empilhadas) não empurrar os controles para fora da tela, e o
   `contain` garante que sobre tarja preta em vez de distorcer a imagem. */
.player { display: block; margin: 0 auto; width: auto; height: auto;
  max-width: 100%; max-height: 70vh; min-height: 220px; aspect-ratio: 16/9;
  object-fit: contain; background: #000; border-radius: var(--radius-lg); }
.ptz { display: grid; grid-template-columns: repeat(3, 56px); grid-auto-rows: 56px;
  gap: 8px; justify-content: center; margin: 16px 0; }
.ptz button { background: var(--surface); border: 1px solid var(--border); color: var(--text);
  border-radius: 12px; height: 56px; font-size: 22px; cursor: pointer; }
.ptz button:hover { background: var(--surface-hover); }
.ptz button:active { background: var(--primary); border-color: var(--primary); }

/* Cada seta tem lugar marcado na grade, em vez de espaçadores vazios entre elas.
   Duas razões, as duas já custaram caro:

   1. Os espaçadores usavam class="empty", que também é o bloco de estado vazio
      do painel — e aquele tem `padding: 56px 20px`. Escondido pelo
      `visibility: hidden`, o vão continuava lá: toda linha com um espaçador
      virava 112px de altura e a cruz aparecia esticada.
   2. No modo agente o botão ■ não existe. Com posição automática, tirá-lo
      empurrava ▶ e ▼ uma célula para trás e a cruz saía torta.

   Com a posição explícita, botão que falta deixa o buraco no lugar certo. */
.ptz [data-ptz="tilt_up"]   { grid-area: 1 / 2; }
.ptz [data-ptz="pan_left"]  { grid-area: 2 / 1; }
.ptz [data-ptz="stop"]      { grid-area: 2 / 2; }
.ptz [data-ptz="pan_right"] { grid-area: 2 / 3; }
.ptz [data-ptz="tilt_down"] { grid-area: 3 / 2; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 16px 0; }

/* Comandos para o usuário copiar. Rola de lado em vez de quebrar a linha:
   comando quebrado no meio é comando colado errado. */
.bloco { background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; overflow-x: auto; font-family: ui-monospace, Consolas, monospace;
  font-size: 12.5px; color: var(--text-dim); margin: 8px 0 16px; }

/* ---------- Tabelas ---------- */
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border-soft); font-size: 13.5px; }
th {
  color: var(--muted); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: .05em;
  background: var(--surface-alt); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tr:last-child td { border-bottom: 0; }
.table-wrap {
  overflow-x: auto; border: 1px solid var(--border);
  border-radius: var(--radius-lg); background: var(--surface);
}
.table-wrap table { min-width: 720px; }
.card .table-wrap { border: 0; border-radius: 0; }
.card .table-wrap table { min-width: 420px; }

/* ---------- Selos ---------- */
.pill, .tag {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--surface-hover); color: var(--text-dim);
}
.pill.active, .pill.online, .pill.approved, .tag-ok { background: var(--success-bg); color: var(--success); }
.pill.offline, .pill.suspended, .pill.rejected { background: var(--danger-bg); color: var(--danger); }
.pill.pending, .tag-warn { background: var(--warning-bg); color: var(--warning); }

code {
  background: var(--surface-alt); border: 1px solid var(--border-soft);
  padding: 1px 6px; border-radius: 6px; font-size: 12px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; color: var(--text-dim);
}

/* ---------- Layout do admin ---------- */
body.admin { display: flex; min-height: 100vh; }

.sidebar {
  width: 218px; background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 14px; flex-shrink: 0;
}
.sidebar .brand { display: block; margin: 4px 8px 18px; }
.sidebar nav a {
  display: block; padding: 8px 12px; border-radius: 8px;
  color: var(--muted); margin-bottom: 2px; font-size: 13.5px; font-weight: 550;
  transition: background .12s, color .12s;
}
.sidebar nav a:hover { background: var(--surface-alt); color: var(--text); }
.sidebar nav a.is-active { background: var(--primary-bg); color: var(--primary-soft); }
.sidebar hr { border: 0; border-top: 1px solid var(--border); margin: 14px 4px; }

.admin-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.admin-header {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 14px 26px; border-bottom: 1px solid var(--border);
  background: rgba(20, 25, 34, .85); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 5;
}
.admin-header h1 { margin: 0; }
.admin-content { padding: 24px 26px 48px; flex: 1; }

/* ---------- Indicadores ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 15px 16px; box-shadow: var(--shadow);
}
.stat .num {
  font-size: 24px; font-weight: 700; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; line-height: 1.2;
}
.stat .label {
  color: var(--muted); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; margin-top: 4px;
}
.stat.is-money .num { color: var(--success); }
.stat.is-primary .num { color: var(--primary-soft); }

/* ---------- Vazio ---------- */
.empty { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty .icon { font-size: 40px; opacity: .8; }
.empty h2 { color: var(--text); margin-top: 8px; }

/* ---------- Filtros ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.filters input[type=text] { flex: 1 1 240px; min-width: 200px; }
.filters select { flex: 0 1 180px; }
.filters input[type=date] { flex: 0 1 150px; }
.filters button, .filters a { flex: 0 0 auto; }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }

/* ---------- Barras horizontais (receita por mês) ---------- */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 52px 1fr 150px; align-items: center; gap: 12px; }
.bar-label { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.bar-track { background: var(--surface-alt); border-radius: 6px; height: 20px; overflow: hidden; }
.bar-fill { background: linear-gradient(90deg, var(--primary), var(--primary-soft));
  height: 100%; border-radius: 6px; transition: width .3s; }
.bar-value { font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; }

/* ==================================================================
   Gráfico de colunas (HTML/CSS — ver chart_bars() em app/helpers.php)
   Em HTML, e não em SVG, para o texto não escalar junto com o card.
   ================================================================== */
.chart { --chart-h: 200px; width: 100%; }

.chart-plot {
  display: flex; align-items: flex-end; gap: 5px;
  height: var(--chart-h); padding-top: 20px;
  border-bottom: 1px solid var(--border);
  /* linhas-guia horizontais: dão noção de escala sem poluir */
  background-image: repeating-linear-gradient(
    to top, var(--border) 0 1px, transparent 1px 25%);
}
.chart-col {
  flex: 1 1 0; min-width: 0; height: 100%;
  display: flex; flex-direction: column; align-items: center;
}
.chart-track { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; min-height: 0; }
.chart-fill {
  width: min(72%, 38px); border-radius: 4px 4px 0 0; position: relative;
  background: linear-gradient(180deg, var(--primary-soft), var(--primary));
  transition: filter .15s;
}
.chart-fill.is-zero { height: 3px; background: var(--border); border-radius: 2px; }
.chart-col:hover .chart-fill { filter: brightness(1.2); }

.chart-tip {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  margin-bottom: 5px; font-size: 11px; font-weight: 600; color: var(--text);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.chart-dense .chart-tip { opacity: 0; transition: opacity .15s; }
.chart-dense .chart-col:hover .chart-tip { opacity: 1; }

.chart-lbl {
  margin-top: 8px; font-size: 11px; color: var(--muted);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.chart-foot {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: 12px; font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
}
.chart-foot strong { color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* Card estreito: mostra um rótulo sim, outro não, para não empilhar texto */
@container (max-width: 520px) {
  .chart-dense .chart-col:nth-child(even) .chart-lbl { visibility: hidden; }
}

/* ---------- Detalhes expansíveis (payload/metadata) ---------- */
details summary { cursor: pointer; user-select: none; color: var(--primary-soft); font-size: 13px; }
details pre {
  background: var(--bg); border: 1px solid var(--border); padding: 10px;
  border-radius: 8px; font-size: 11.5px; max-width: 480px; max-height: 260px;
  overflow: auto; white-space: pre-wrap; word-break: break-all; margin-top: 8px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; color: var(--text-dim);
}

/* ==================================================================
   Menu móvel
   O botão é o próprio <input type=checkbox> estilizado: assim ele abre
   sem uma linha de JavaScript, recebe foco pelo teclado e a barra de
   espaço já funciona. Nenhum script para falhar.
   ================================================================== */
/* O ícone vai como imagem de fundo, e não em ::before: pseudo-elemento
   dentro de <input> não renderiza no Firefox nem no Safari. */
.menu-toggle {
  display: none;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 21px 21px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23e8edf5' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 7h16M4 12h16M4 17h16'/%3E%3C/svg%3E");
}
.menu-toggle:checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23e8edf5' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 6l12 12M18 6L6 18'/%3E%3C/svg%3E");
}

.menu-backdrop { display: none; }

/* ---------- Responsivo ---------- */
@media (max-width: 860px) {
  /* --- botão do menu (fixo no topo, sobre o cabeçalho) --- */
  .menu-toggle {
    display: flex; align-items: center; justify-content: center;
    position: fixed; top: 10px; z-index: 50;
    width: 42px; height: 42px; margin: 0; padding: 0;
    appearance: none; -webkit-appearance: none;
    /* background-color, e não o atalho background: o atalho apagaria
       a imagem do ícone definida acima */
    background-color: var(--surface-alt); border: 1px solid var(--border);
    border-radius: 10px; color: var(--text); font-size: 18px;
    cursor: pointer; line-height: 1;
  }
  .menu-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

  /* trava o fundo enquanto a gaveta está aberta */
  body:has(.menu-toggle:checked) { overflow: hidden; }

  /* --- admin: gaveta lateral --- */
  body.admin .menu-toggle { left: 14px; }
  .admin-header { padding-left: 68px; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 40;
    width: 252px; max-width: 82vw; padding-top: 62px;
    overflow-y: auto; transform: translateX(-100%);
    transition: transform .22s ease;
  }
  .menu-toggle:checked ~ .sidebar {
    transform: translateX(0); box-shadow: 8px 0 32px rgba(0, 0, 0, .5);
  }
  .menu-backdrop {
    display: block; position: fixed; inset: 0; z-index: 30;
    background: rgba(0, 0, 0, .55); opacity: 0; pointer-events: none;
    transition: opacity .22s;
  }
  .menu-toggle:checked ~ .menu-backdrop { opacity: 1; pointer-events: auto; }
  .sidebar nav a { padding: 11px 12px; font-size: 14.5px; }

  /* --- área do usuário: painel que desce da barra --- */
  body:not(.admin) .menu-toggle { right: 14px; }
  .topbar { padding-right: 68px; gap: 10px; }
  .topbar .brand { flex: 1; }
  /* só a barra do usuário vira painel — o cabeçalho do admin mantém o
     nome e o botão Sair visíveis */
  .topbar .topnav, .topbar .topbar-user {
    display: none; flex-basis: 100%; order: 3;
    padding-top: 10px; border-top: 1px solid var(--border);
  }
  .menu-toggle:checked ~ .topnav { display: flex; flex-direction: column; gap: 2px; }
  .menu-toggle:checked ~ .topbar-user { display: flex; justify-content: space-between; }
  .topnav a { padding: 11px 12px; font-size: 14.5px; }

  /* cabeçalho do admin: espaço para o botão e nome do usuário encurtado */
  .admin-header .topbar-user { font-size: 13px; gap: 8px; }
  .admin-header .topbar-user a {
    max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }

  /* --- conteúdo --- */
  /* cartão um pouco mais largo e número menor: "R$ 18.240,50" não cabia
     em duas linhas sem ficar feio no tablet */
  .stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
  .stat .num { font-size: 20px; }
  .admin-content { padding: 18px 16px 40px; }
  .container { padding: 18px 16px 40px; }
  .grid-2 { grid-template-columns: 1fr; }

  /* fonte 16px evita o zoom automático do iOS ao focar um campo */
  input[type=text], input[type=email], input[type=password],
  input[type=number], input[type=date], select, textarea { font-size: 16px; }
  .btn, button.btn { padding: 12px 18px; }
  .btn-ghost { padding: 9px 14px; }
  /* Alvo de toque confortável nas ações do card da câmera. */
  .device-links a { padding: 12px 14px; font-size: 14px; }

  /* --- tabelas: rolagem lateral com a 1ª coluna fixa --- */
  /* sem largura mínima: cada coluna fica na largura natural e o dedo
     rola de lado. Espremer 9 colunas em 375px quebra tudo em 3 linhas. */
  .table-wrap table { min-width: 0; }
  .table-wrap td, .table-wrap th { white-space: nowrap; }
  .table-wrap td small.muted { white-space: normal; }
  .table-wrap th:first-child, .table-wrap td:first-child {
    position: sticky; left: 0; z-index: 1;
    background: var(--surface); box-shadow: 1px 0 0 var(--border);
  }
  .table-wrap th:first-child { background: var(--surface-alt); }
  .table-wrap::after {
    content: "deslize para o lado para ver mais →";
    display: block; position: sticky; left: 0;
    padding: 7px 12px; font-size: 11px; color: var(--muted);
    border-top: 1px solid var(--border-soft);
  }
  .card .table-wrap::after { content: none; }
}

/* O hover só existe em quem tem mouse: no toque ele "gruda" e estraga
   o fundo opaco da coluna fixa. */
@media (hover: hover) {
  tbody tr:hover td { background: rgba(255, 255, 255, .022); }
}

@media (max-width: 640px) {
  .bar-row { grid-template-columns: 44px 1fr; }
  .bar-value { grid-column: 2; text-align: left; }
  /* evita "R$ 18.240,50" quebrando em duas linhas no cartão estreito */
  .stat .num { font-size: 20px; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
  .card { padding: 16px; }
  h1 { font-size: 18px; }

  /* filtros e ações viram blocos de largura cheia, fáceis de tocar */
  .filters { flex-direction: column; align-items: stretch; }
  .filters input[type=text], .filters select, .filters input[type=date],
  .filters button, .filters a { width: 100%; flex: 1 1 auto; }
  .page-actions .btn, .page-actions .btn-ghost,
  .page-head .btn, .page-head .btn-ghost { flex: 1 1 auto; text-align: center; }
  /* título em cima, botão de largura cheia embaixo */
  .page-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .actions > form, .actions > .btn, .actions > .btn-ghost, .actions > a { flex: 1 1 auto; }
  .actions button, .actions form .btn, .actions form .btn-ghost { width: 100%; }
  .form-row { grid-template-columns: 1fr; }
  /* botão de envio ocupa a largura do cartão: alvo grande para o dedo */
  .card > form > button.btn, .card > form > .btn { width: 100%; }
}
