/* ==========================================================================
   AutoAgenda — Folha de estilo única. CSS puro, sem framework.

   Mesma paleta e os mesmos componentes do FitMulti (a marca #ff5722, a
   sidebar recolhível, cards, tabelas, badges e modais) — de propósito: os
   dois sistemas são do mesmo fornecedor e precisam parecer a mesma família.
   As cores podem ser sobrescritas em Configurações > Cores, que injeta as
   variáveis de :root no <head> (ver App\Support\Branding::themeTag).
   ========================================================================== */

:root {
  --bg:          #0f1115;
  --surface:     #171a21;
  --surface-2:   #1f232c;
  --border:      #2a2f3a;
  --text:        #e6e8ee;
  --text-muted:  #9aa3b2;
  --brand:       #ff5722;
  --brand-soft:  rgba(255, 87, 34, .14);
  --ok:          #22c55e;
  --ok-soft:     rgba(34, 197, 94, .14);
  --warn:        #f59e0b;
  --warn-soft:   rgba(245, 158, 11, .14);
  --danger:      #ef4444;
  --danger-soft: rgba(239, 68, 68, .14);
  --radius:      10px;
  --shadow:      0 6px 24px rgba(0, 0, 0, .35);
  --font:        system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ==========================================================================
   Layout administrativo + sidebar recolhível
   ========================================================================== */
:root { --sidebar-w: 248px; --sidebar-w-collapsed: 68px; }

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
/* Recolhido: só os ícones. A classe vive no <html>, aplicada antes da pintura. */
html.is-collapsed .layout { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
}

/* ---------- Marca ---------- */
.sidebar-head { padding: 4px 6px 16px; }
.logo {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); text-decoration: none;
}
.logo:hover { text-decoration: none; }
.logo-mark {
  width: 32px; height: 32px; flex-shrink: 0;
  display: grid; place-items: center; border-radius: 9px;
  background: var(--brand); color: #fff; font-weight: 800; font-size: 17px;
}
.logo-text { font-size: 18px; font-weight: 700; letter-spacing: -.4px; white-space: nowrap; }
.logo-text span { color: var(--brand); }
.logo-img { height: 32px; width: auto; max-width: 180px; object-fit: contain; flex-shrink: 0; }
/* Recolhido, encolhe para caber na trilha de ícones em vez de sumir. */
html.is-collapsed .logo-img { height: 28px; max-width: 36px; }

/* ---------- Itens ---------- */
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-link {
  display: flex; align-items: center; gap: 11px;
  width: 100%; padding: 9px 11px; border-radius: 9px;
  color: var(--text-muted); font-size: 14px; font-family: inherit;
  background: none; border: 0; cursor: pointer; text-align: left;
  text-decoration: none; position: relative;
  transition: background .12s, color .12s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

/* Ícones herdam a cor do item — nenhum tem cor própria. */
.nav-link .icon { flex-shrink: 0; opacity: .85; }
.nav-link:hover .icon,
.nav-link.active .icon { opacity: 1; }

.nav-link.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
/* Barra de destaque do item ativo */
.nav-link.active::before {
  content: ''; position: absolute; left: -10px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 0 3px 3px 0;
  background: var(--brand);
}

.nav-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Submenus (accordion) ---------- */
.nav-caret {
  flex-shrink: 0; opacity: .6;
  transition: transform .18s ease;
}
.nav-section.open > .nav-toggle .nav-caret { transform: rotate(90deg); }
.nav-section.open > .nav-toggle { color: var(--text); }

.nav-sub {
  display: grid;
  grid-template-rows: 0fr;            /* animação de altura sem JS medir nada */
  transition: grid-template-rows .2s ease;
  margin-left: 21px;
  border-left: 1px solid var(--border);
  padding-left: 7px;
}
.nav-section.open > .nav-sub { grid-template-rows: 1fr; }

/**
 * Filho ÚNICO, obrigatoriamente. `grid-template-rows: 0fr` dimensiona só a
 * primeira linha; qualquer irmão vira linha implícita `auto` e o submenu não
 * fecha nunca. O min-height:0 permite o colapso e o overflow:hidden esconde o
 * conteúdo durante a transição.
 */
.nav-sub-inner {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-sub-title { display: none; }     /* só aparece no flyout do modo recolhido */

/* Navegadores que não animam 0fr: alterna display, sem transição. */
@supports not (grid-template-rows: 0fr) {
  .nav-sub { display: none; }
  .nav-section.open > .nav-sub { display: block; }
}

.nav-child { font-size: 13.5px; padding: 8px 10px; }
.nav-child.active::before { left: -8px; height: 16px; }

/* ---------- Botão de recolher ---------- */
.sidebar-collapse { margin-top: 8px; flex-shrink: 0; }
html.is-collapsed .sidebar-collapse .icon { transform: scaleX(-1); }

.topbar-burger {
  display: none;
  background: none; border: 0; cursor: pointer;
  color: var(--text-muted); padding: 6px; border-radius: 8px;
}
.topbar-burger:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Estado recolhido ---------- */
/**
 * `overflow: visible` é obrigatório aqui. Com o overflow-y:auto do estado
 * expandido, tooltips e flyouts posicionados em `left: 100%` são recortados
 * pela própria sidebar e nunca aparecem.
 *
 * Trocar o scroll por visible é seguro neste estado: recolhida a sidebar tem
 * só ícones (~350px de altura), e abaixo de 900px ela vira gaveta.
 */
html.is-collapsed .sidebar { padding: 14px 10px; overflow: visible; }
html.is-collapsed .logo-text,
html.is-collapsed .nav-label,
html.is-collapsed .nav-caret { display: none; }
html.is-collapsed .nav-link { justify-content: center; padding: 10px; }
html.is-collapsed .nav-link.active::before { left: -10px; }

/* Recolhido, o submenu vira flyout no hover — não empurra o layout. */
html.is-collapsed .nav-sub {
  position: absolute; left: 100%; top: 0; z-index: 60;
  display: block; grid-template-rows: none;
  min-width: 208px; margin-left: 6px; padding: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow);
  opacity: 0; visibility: hidden; transform: translateX(-6px);
  transition: opacity .14s, transform .14s, visibility .14s;
}
/* No flyout a altura é livre: o wrapper não pode mais cortar o conteúdo. */
html.is-collapsed .nav-sub-inner { overflow: visible; min-height: auto; }
html.is-collapsed .nav-section { position: relative; }

/**
 * Ponte invisível sobre o vão de 6px entre o ícone e o flyout. Sem ela o mouse
 * sai do .nav-section ao atravessar o espaço, o hover cai e o menu pisca —
 * torna impossível alcançar os itens.
 *
 * Fica no .nav-section, não no .nav-sub: o flyout tem overflow-y:auto e
 * recortaria um pseudo-elemento posicionado fora do seu box.
 *
 * pointer-events só no hover — do contrário esta faixa de 12px ficaria
 * permanentemente sobre o conteúdo, engolindo cliques ao lado do menu.
 */
html.is-collapsed .nav-section::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0; left: 100%;
  width: 12px;
  pointer-events: none;
}
html.is-collapsed .nav-section:hover::after,
html.is-collapsed .nav-section:focus-within::after { pointer-events: auto; }

html.is-collapsed .nav-section:hover > .nav-sub,
html.is-collapsed .nav-section:focus-within > .nav-sub {
  opacity: 1; visibility: visible; transform: translateX(0);
}

/* Grupo do rodapé não pode empurrar o flyout para fora da tela. */
html.is-collapsed .nav-sub {
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  scrollbar-width: thin;
}
html.is-collapsed .nav-sub-title {
  display: block; padding: 4px 10px 8px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted); border-bottom: 1px solid var(--border); margin-bottom: 6px;
}
html.is-collapsed .nav-child { justify-content: flex-start; padding: 8px 10px; }
html.is-collapsed .nav-child .nav-label { display: block; }

/* Tooltip dos itens simples quando recolhido.
   Os grupos ficam de fora: neles o próprio flyout já mostra o nome no título. */
html.is-collapsed .nav-link[data-tip]:not(.nav-toggle)::after {
  content: attr(data-tip);
  position: absolute; left: 100%; top: 50%; transform: translate(-6px, -50%);
  margin-left: 10px; padding: 6px 10px; z-index: 70;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px;
  font-size: 12.5px; font-weight: 400; white-space: nowrap;
  box-shadow: var(--shadow); pointer-events: none;
  opacity: 0; visibility: hidden;
  /* Atraso na entrada evita tooltip piscando ao varrer o menu de cima a baixo;
     na saída some na hora. */
  transition: opacity .12s, transform .12s, visibility .12s;
  transition-delay: 0s;
}
html.is-collapsed .nav-link[data-tip]:not(.nav-toggle):hover::after,
html.is-collapsed .nav-link[data-tip]:not(.nav-toggle):focus-visible::after {
  opacity: 1; visibility: visible; transform: translate(0, -50%);
  transition-delay: .35s;
}

.sidebar-backdrop { display: none; }

/* ---------- Conteúdo ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 40;
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; }
.content { padding: 24px; flex: 1; }

/* ---------- Seletor de unidade (Admin) ----------------------------------- */
.unit-switch {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 10px;
}
.unit-switch label { font-size: 12px; color: var(--text-muted); }
.unit-switch select {
  background: transparent; border: 0; color: var(--text);
  font-size: 14px; font-weight: 600; outline: none; cursor: pointer;
}
.unit-switch select option { background: var(--surface-2); }

/* ---------- Cartões e KPIs ----------------------------------------------- */
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.card h2, .card h3 { margin: 0 0 14px; font-size: 15px; font-weight: 600; }

.kpi .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase;
  letter-spacing: .05em; }
.kpi .value { font-size: 30px; font-weight: 700; line-height: 1.15; margin-top: 6px; }
.kpi .hint  { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.kpi.ok     .value { color: var(--ok); }
.kpi.warn   .value { color: var(--warn); }
.kpi.danger .value { color: var(--danger); }

/* ---------- Abas (Configurações) ------------------------------------------ */
.tabs {
  display: flex; gap: 4px; border-bottom: 1px solid var(--border);
  margin-bottom: 20px; flex-wrap: wrap;
}
.tab-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 16px; background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--text-muted); font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- Marca (logo/favicon) ------------------------------------------ */
.brand-upload { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand-preview {
  width: 88px; height: 88px; border-radius: 12px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border);
  display: grid; place-items: center; flex-shrink: 0;
}
.brand-preview img { width: 100%; height: 100%; object-fit: contain; }
.brand-preview.is-favicon { width: 56px; height: 56px; border-radius: 8px; }
.brand-preview .empty-icon { color: var(--text-muted); opacity: .5; }

/* ---------- Banners da landing --------------------------------------------- */
.banner-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.banner-row:last-child { border-bottom: 0; }
.banner-row-thumb {
  width: 72px; height: 44px; border-radius: 6px; object-fit: cover; flex-shrink: 0;
  background: var(--surface-2); border: 1px solid var(--border);
}
.banner-row-info { flex: 1; min-width: 0; }
.banner-row-info strong { display: block; font-size: 14px; }
.banner-row-info span { font-size: 12px; color: var(--text-muted); }

/* ---------- Barra de busca / ações no topo de listas --------------------- */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 16px;
}
.toolbar-form {
  display: flex; gap: 8px; flex: 1 1 320px; min-width: 0; max-width: 520px;
}
/*
 * O item flex de verdade é o `.field` que ENVOLVE o input (o filho direto de
 * `.toolbar-form`) — não o <input> em si. `flex:` num descendente que não é
 * item flex não faz nada; sem isso, o wrapper do campo de busca encolhe pro
 * min-content de um <input type="search"> (praticamente zero), enquanto o
 * de um <select> fica largo por causa do texto da opção mais comprida —
 * daí a busca aparecer espremida do lado dos filtros normais.
 */
.toolbar-form .field:has(> input[type="search"]) { flex: 1 1 200px; min-width: 140px; }
.toolbar-form input[type="search"] { min-width: 0; }
.toolbar-form select { flex: 0 0 auto; width: auto; }
.toolbar-hint { font-size: 12px; color: var(--text-muted); }

/* ---------- Tabelas ------------------------------------------------------ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
tbody tr:hover { background: var(--surface-2); }
.empty { padding: 32px; text-align: center; color: var(--text-muted); }

/* ---------- Badges ------------------------------------------------------- */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.badge.ok     { background: var(--ok-soft);     color: var(--ok); }
.badge.warn   { background: var(--warn-soft);   color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.muted  { background: var(--surface-2);   color: var(--text-muted); }

/* ---------- Formulários -------------------------------------------------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; font-family: inherit; font-size: 14px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
.field .error { color: var(--danger); font-size: 12px; margin-top: 4px; display: block; }
input.invalid { border-color: var(--danger); }

/* ---------- Campo de busca com sugestões (Fit.buscaComCriacao / buscaRemota) --- */
.busca-campo { position: relative; }
.busca-lista {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 40;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); max-height: 220px; overflow-y: auto;
}
.busca-opcao { padding: 9px 12px; font-size: 14px; cursor: pointer; }
.busca-opcao:hover { background: var(--surface-2); }
.busca-opcao-criar { color: var(--brand); font-weight: 600; border-top: 1px solid var(--border); }
.busca-opcao-vazia { color: var(--text-muted); cursor: default; }
.busca-opcao-vazia:hover { background: transparent; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text);
  font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn:hover { border-color: var(--text-muted); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger  { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { padding: 5px 12px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- Alertas / toasts --------------------------------------------- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert.success { background: var(--ok-soft);     color: var(--ok);     border: 1px solid var(--ok); }
.alert.error   { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger); }
.alert.warn    { background: var(--warn-soft);   color: var(--warn);   border: 1px solid var(--warn); }

#toast-area { position: fixed; top: 18px; right: 18px; z-index: 999; display: grid; gap: 8px; }
.toast {
  padding: 12px 18px; border-radius: 8px; box-shadow: var(--shadow);
  font-size: 14px; font-weight: 500; background: var(--surface-2);
  border-left: 4px solid var(--brand); animation: slide-in .2s ease;
}
.toast.success { border-left-color: var(--ok); }
.toast.error   { border-left-color: var(--danger); }
@keyframes slide-in { from { opacity: 0; transform: translateX(16px); } }

/* ==========================================================================
   PORTARIA — precisa ser lida a 3 metros de distância.
   ========================================================================== */
.gate { min-height: 100vh; display: grid; grid-template-columns: 1.2fr 1fr; }
.gate-scan {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px; gap: 24px; transition: background .25s;
}
.gate-scan.liberado  { background: linear-gradient(160deg, rgba(34,197,94,.22), transparent 60%); }
.gate-scan.bloqueado { background: linear-gradient(160deg, rgba(239,68,68,.22), transparent 60%); }

#scan-input {
  font-size: 26px; text-align: center; letter-spacing: .12em;
  padding: 18px; max-width: 460px;
}

.gate-result {
  width: 100%; max-width: 520px; border-radius: 16px; padding: 32px;
  text-align: center; border: 3px solid var(--border); background: var(--surface);
}
.gate-result.liberado  { border-color: var(--ok);     background: var(--ok-soft); }
.gate-result.bloqueado { border-color: var(--danger); background: var(--danger-soft); }
.gate-result .status { font-size: 46px; font-weight: 800; letter-spacing: -1px; }
.gate-result.liberado  .status { color: var(--ok); }
.gate-result.bloqueado .status { color: var(--danger); }
.gate-result .student-name { font-size: 26px; font-weight: 600; margin-top: 10px; }
.gate-result .detail { color: var(--text-muted); margin-top: 8px; font-size: 16px; }
.gate-result .photo {
  width: 110px; height: 110px; border-radius: 50%; object-fit: cover;
  border: 3px solid currentColor; margin-bottom: 14px;
}
.gate-result .photo-fallback {
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--text-muted);
  font-size: 40px; font-weight: 700; margin-left: auto; margin-right: auto;
}

.gate-feed { background: var(--surface); border-left: 1px solid var(--border); padding: 20px; overflow-y: auto; }
.gate-feed h2 { font-size: 15px; margin: 0 0 12px; }
.feed-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border-radius: 8px; margin-bottom: 6px; background: var(--surface-2);
  border-left: 4px solid var(--border); animation: slide-in .2s ease;
}
.feed-item.liberado  { border-left-color: var(--ok); }
.feed-item.bloqueado { border-left-color: var(--danger); }
.feed-item .avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  object-fit: cover; background: var(--surface); color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; border: 1px solid var(--border);
}

/* Miniatura de foto do aluno — listas e fichas do admin/gerente/instrutor. */
.avatar-mini {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  object-fit: cover; background: var(--surface-2); color: var(--text-muted);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; border: 1px solid var(--border);
}
.avatar-mini.lg { width: 56px; height: 56px; font-size: 20px; }
.feed-item .who { flex: 1; font-weight: 600; font-size: 14px; }
.feed-item .when { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.feed-item .why { font-size: 12px; color: var(--text-muted); display: block; font-weight: 400; }

/* ==========================================================================
   ÁREA DO ALUNO — mobile-first (o aluno usa o celular na academia).
   ========================================================================== */
.client-shell { max-width: 620px; margin: 0 auto; padding: 16px 16px 90px; }
.client-header { display: flex; align-items: center; gap: 12px; padding: 12px 0 20px; }
.client-header .avatar {
  width: 46px; height: 46px; border-radius: 50%; background: var(--brand-soft);
  color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 18px;
  flex-shrink: 0; overflow: hidden; text-decoration: none;
}
.client-header .avatar:hover { text-decoration: none; filter: brightness(1.1); }
.client-header .avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Botão de escanear no canto superior direito */
.scan-btn {
  width: 42px; height: 42px; flex-shrink: 0;
  display: grid; place-items: center; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text); padding: 0;
}
.scan-btn:hover { border-color: var(--brand); color: var(--brand); }
.scan-btn:active { transform: scale(.94); }
.scan-btn svg { width: 22px; height: 22px; }

/* Editor de avatar (tela de perfil) */
.avatar-editor { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.avatar-preview {
  width: 96px; height: 96px; border-radius: 50%; overflow: hidden; flex-shrink: 0;
  background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-size: 34px; font-weight: 700;
  border: 2px solid var(--border);
}
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Scanner em tela cheia ---------------------------------------- */
.scanner {
  position: fixed; z-index: 1000;
  /* top/right/bottom/left antes de `inset`: navegadores anteriores a 2021
     ignoram `inset` e continuam ocupando a tela toda. */
  top: 0; right: 0; bottom: 0; left: 0;
  inset: 0;
  background: rgba(8, 9, 12, .97);
  display: flex; flex-direction: column; align-items: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
/* `[hidden]` sozinho perde para `display:flex` — precisa desta regra. */
.scanner[hidden] { display: none !important; }

.scanner-top {
  width: 100%; max-width: 460px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 2px 16px;
}
.scanner-title { font-size: 17px; font-weight: 600; }
.scanner-close {
  background: none; border: 0; color: var(--text-muted);
  font-size: 32px; line-height: 1; cursor: pointer; padding: 0 8px;
}
.scanner-close:hover { color: var(--text); }

.scanner-stage {
  position: relative; width: 100%; max-width: 380px;
  border-radius: 18px; overflow: hidden; background: #000;
  display: grid; place-items: center;
  /* Quadrado sem aspect-ratio (Safari < 15): o padding cria a altura. */
  height: 0; padding-bottom: 100%;
}
@supports (aspect-ratio: 1) {
  .scanner-stage { aspect-ratio: 1; height: auto; padding-bottom: 0; }
}
.scanner-stage video {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%; object-fit: cover; background: #000;
}
.scanner-placeholder {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  display: grid; place-items: center; color: var(--border);
}
.scanner-placeholder svg { width: 44%; height: 44%; }

/* Cantos do enquadramento */
.scanner-frame {
  position: absolute;
  top: 14%; right: 14%; bottom: 14%; left: 14%;
  inset: 14%;
  pointer-events: none;
}
.scanner-frame span {
  position: absolute; width: 34px; height: 34px;
  border: 3px solid var(--brand);
}
.scanner-frame span:nth-child(1) { top: 0; left: 0;  border-right: 0; border-bottom: 0; border-radius: 10px 0 0 0; }
.scanner-frame span:nth-child(2) { top: 0; right: 0; border-left: 0;  border-bottom: 0; border-radius: 0 10px 0 0; }
.scanner-frame span:nth-child(3) { bottom: 0; right: 0; border-left: 0; border-top: 0;  border-radius: 0 0 10px 0; }
.scanner-frame span:nth-child(4) { bottom: 0; left: 0;  border-right: 0; border-top: 0; border-radius: 0 0 0 10px; }

.scanner-hint {
  max-width: 380px; margin: 18px auto 0; text-align: center;
  font-size: 14px; color: var(--text-muted); line-height: 1.6;
}
.scanner-actions {
  margin-top: 18px; display: flex; gap: 10px;
  flex-wrap: wrap; justify-content: center;
}

/* Diagnóstico — só aparece quando a câmera falha */
.scanner-diag {
  margin-top: 18px; width: 100%; max-width: 380px;
  font-size: 13px; color: var(--text-muted);
}
.scanner-diag summary { cursor: pointer; padding: 6px 0; }
.scanner-diag ul { list-style: none; padding: 8px 0 0; margin: 0; }
.scanner-diag li { padding: 3px 0; font-family: monospace; font-size: 12px; }
.scanner-diag li.ok   { color: var(--ok); }
.scanner-diag li.no   { color: var(--danger); }
.scanner-diag li.info { color: var(--text-muted); word-break: break-all; }

/* Resultado do check-in dentro do scanner */
.scan-result {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%; padding: 24px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 10px;
}
.scan-result.liberado  { background: var(--ok-soft); }
.scan-result.bloqueado { background: var(--danger-soft); }
.scan-result-icon {
  width: 76px; height: 76px; border-radius: 50%;
  display: grid; place-items: center; font-size: 42px; font-weight: 700;
}
.scan-result.liberado  .scan-result-icon { background: var(--ok);     color: #07130a; }
.scan-result.bloqueado .scan-result-icon { background: var(--danger); color: #1a0707; }
.scan-result-status { font-size: 21px; font-weight: 800; letter-spacing: .02em; }
.scan-result.liberado  .scan-result-status { color: var(--ok); }
.scan-result.bloqueado .scan-result-status { color: var(--danger); }
.scan-result-msg  { font-size: 15px; color: var(--text); }
.scan-result-unit { font-size: 13px; color: var(--text-muted); }
.client-nav {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex;
  background: var(--surface); border-top: 1px solid var(--border);
}
.client-nav a {
  flex: 1; text-align: center; padding: 12px 4px; font-size: 12px; color: var(--text-muted);
}
.client-nav a.active { color: var(--brand); font-weight: 600; }

/* ==========================================================================
   Cronômetro de descanso entre séries
   ========================================================================== */
.rest-bar {
  position: fixed;
  left: 0; right: 0;
  /* Acima da navegação inferior do aluno, respeitando a área segura do iPhone. */
  bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  z-index: 90;
  display: flex; align-items: center; gap: 16px;
  max-width: 620px; margin: 0 auto;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, .45);
}
.rest-bar[hidden] { display: none !important; }

/* Sem isso o card cobre o fim do formulário. */
body.has-rest-bar { padding-bottom: 96px; }

.rest-ring { position: relative; width: 72px; height: 72px; flex-shrink: 0; }
.rest-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.rest-track {
  fill: none; stroke: var(--surface-2); stroke-width: 9;
}
.rest-progress {
  fill: none; stroke: var(--brand); stroke-width: 9; stroke-linecap: round;
  transition: stroke-dashoffset .2s linear, stroke .2s;
}
.rest-time {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  display: grid; place-items: center;
  font-size: 17px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.rest-info { flex: 1; min-width: 0; }
.rest-label { display: block; font-size: 14px; margin-bottom: 8px; }
.rest-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Últimos 5 segundos: pulsa em laranja. */
.rest-bar.urgente .rest-progress { stroke: var(--warn); }
.rest-bar.urgente .rest-time { color: var(--warn); }
.rest-bar.urgente .rest-ring { animation: rest-pulse .9s ease-in-out infinite; }

.rest-bar.paused { opacity: .75; }
.rest-bar.paused .rest-progress { stroke: var(--text-muted); }

/* Concluído: verde e piscando — no iOS não há vibração, então o visual
   precisa ser impossível de ignorar. */
.rest-bar.done {
  border-color: var(--ok);
  animation: rest-flash 1s ease-in-out 3;
}
.rest-bar.done .rest-progress { stroke: var(--ok); }
.rest-bar.done .rest-time { color: var(--ok); font-size: 15px; }
.rest-bar.done .rest-label { color: var(--ok); font-weight: 700; }

@keyframes rest-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}
@keyframes rest-flash {
  0%, 100% { background: var(--surface); }
  50%      { background: var(--ok-soft); }
}

/* Quem pediu menos movimento recebe a cor, não a animação. */
@media (prefers-reduced-motion: reduce) {
  .rest-bar.done, .rest-bar.urgente .rest-ring { animation: none; }
  .rest-progress { transition: none; }
}

/* Atalhos de tempo dentro do formulário */
.rest-presets { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

.metric-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.metric {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
.metric .value { font-size: 24px; font-weight: 700; }
.metric .label { font-size: 12px; color: var(--text-muted); }
.delta.up   { color: var(--ok); }
.delta.down { color: var(--danger); }

.qr-box { background: #fff; padding: 20px; border-radius: 12px; display: grid; place-items: center; }
.qr-box canvas, .qr-box img { max-width: 100%; }

/* ---------- Modal genérico (Novo contrato, Novo instrutor, etc.) -------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0, 0, 0, .6);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; visibility: hidden;
  transition: opacity .18s ease, visibility .18s ease;
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  padding: 24px; position: relative;
  transform: translateY(14px) scale(.98);
  transition: transform .18s ease;
}
.modal-overlay.open .modal-box { transform: translateY(0) scale(1); }
.modal-close {
  position: absolute; top: 14px; right: 14px;
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 6px; border-radius: 8px; line-height: 0;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-box h2 { margin-top: 0; padding-right: 24px; }

/* ---------- Gráficos (SVG puro, sem biblioteca) -------------------------- */
.chart { width: 100%; height: 220px; }
.chart .line { fill: none; stroke: var(--brand); stroke-width: 2; }
.chart .area { fill: var(--brand-soft); }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart .label { fill: var(--text-muted); font-size: 10px; }
.chart .bar { fill: var(--brand); }
.chart .bar.alt { fill: var(--danger); }

.heatmap { display: grid; grid-template-columns: 40px repeat(24, 1fr); gap: 2px; font-size: 10px; }
.heatmap .cell { aspect-ratio: 1; border-radius: 2px; background: var(--surface-2); }
.heatmap .row-label { color: var(--text-muted); display: grid; place-items: center; }

/* ---------- Impressão ------------------------------------------------------
   Regra geral pra qualquer tela do painel (Admin/Gerente): some com a
   navegação (sidebar, topbar, botões de ação) e deixa só o conteúdo, largura
   cheia. Elementos específicos de uma tela usam .no-print pra se esconder
   também (ex.: botão "Imprimir" do próprio dashboard).
---------------------------------------------------------------------------- */
@media print {
  @page { margin: 12mm; }
  body { background: #fff; color: #000; font-size: 12px; }
  .no-print, .print-only { display: none !important; }
  .sidebar, .topbar-burger, .unit-switch, .scan-btn, .client-nav, .client-header
    { display: none !important; }
  .layout, html.is-collapsed .layout { display: block; }
  .main { display: block; }
  .content { padding: 0; }
  .topbar { border: none; padding: 0 0 8px; min-height: 0; }
  .topbar h1 { font-size: 18px; }

  /* Só aparece impresso: título/unidade não cabiam de forma legível na tela
     comum, então esse bloco fica escondido o tempo todo e só é revelado aqui. */
  .print-only { display: block !important; margin: 0 0 12px; }

  /* Colunas fixas: o auto-fit da tela deixa "órfãos" numa página mais
     estreita (ex.: 4 cards em 190px cabem só 3 por linha em A4 retrato,
     sobrando 1 sozinho). Fixando o número de colunas, cada linha preenche
     por completo — o mesmo aproveitamento de espaço da tela. */
  .grid { gap: 8px; margin-bottom: 8px !important; }
  .grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
  .grid.cols-2 { grid-template-columns: repeat(2, 1fr); }

  .card {
    break-inside: avoid; box-shadow: none; border: 1px solid #ccc;
    padding: 10px; border-radius: 6px;
  }
  .card h2, .card h3 { margin: 0 0 6px; font-size: 12px; }
  .kpi .label { font-size: 9px; }
  .kpi .value { font-size: 18px; margin-top: 2px; }
  .kpi .hint { font-size: 9px; margin-top: 2px; }

  /* O card "Taxas e Custos" é escuro de propósito na tela — no papel isso
     é tinta/toner desperdiçado e ilegível em preto-e-branco; imprime claro. */
  .mp-fees-card {
    background: #fff !important; color: #000 !important;
    border: 1px solid #ccc !important;
  }
  .mp-fees-header h2, .mp-fees-total, .mp-fees-installments,
  .mp-fees-banner-value { color: #000 !important; }
  .mp-fees-panel { background: #fafafa !important; border-color: #ddd !important; }
  .mp-fees-banner { background: #fafafa !important; border-color: #ccc !important; }

  table { font-size: 11px; }
  .table-wrap { overflow: visible; }

  /* ---- Etiquetas para impressão ---- */
  .label-sheet { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10mm; }
  .label-card { border: 1px dashed #999; padding: 8mm; text-align: center; break-inside: avoid; }
}

/* ---------- Grid de vídeos (YouTube/Vimeo) --------------------------------
   Compartilhado entre o painel de equipamentos e o Inspire-se — ver
   assets/js/video-embed.js para a lógica de miniatura/player.
---------------------------------------------------------------------------- */
.video-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 640px) { .video-grid { grid-template-columns: repeat(4, 1fr); } }
.video-thumb {
  position: relative; aspect-ratio: 16/9; border-radius: 8px; overflow: hidden;
  background: var(--surface-2); cursor: pointer;
}
.video-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-thumb-play {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .35); color: #fff; font-size: 18px;
}
.video-fullscreen-overlay { position: fixed; inset: 0; z-index: 2000; background: #000; }
.video-fullscreen-overlay iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-fullscreen-close {
  position: absolute; top: 12px; right: 12px; z-index: 2001;
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 20px; line-height: 1;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}

/* ---------- Imagem em tela cheia (ver assets/js/image-viewer.js) ---------- */
.img-fullscreen-overlay {
  position: fixed; inset: 0; z-index: 2000; background: rgba(0, 0, 0, .92);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.img-fullscreen-overlay img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.img-fullscreen-close {
  position: absolute; top: 12px; right: 12px; z-index: 2001;
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 20px; line-height: 1;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}

/* ---------- Responsivo --------------------------------------------------- */
@media (max-width: 900px) {
  /* No celular a sidebar vira gaveta sobreposta — coluna fixa comeria a tela. */
  .layout,
  html.is-collapsed .layout { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 80;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow);
  }
  /* A gaveta é sempre "expandida": ícone sozinho não ajuda em tela pequena. */
  body.drawer-open .sidebar { transform: translateX(0); }
  html.is-collapsed .logo-text,
  html.is-collapsed .nav-label,
  html.is-collapsed .nav-caret { display: revert; }
  html.is-collapsed .nav-link { justify-content: flex-start; padding: 9px 11px; }
  html.is-collapsed .nav-sub {
    position: static; opacity: 1; visibility: visible; transform: none;
    background: none; border: 0; box-shadow: none; padding: 0;
    margin-left: 21px; border-left: 1px solid var(--border); padding-left: 7px;
    display: grid; grid-template-rows: 0fr; min-width: 0;
  }
  html.is-collapsed .nav-section.open > .nav-sub { grid-template-rows: 1fr; }
  /* Volta a cortar: na gaveta o accordion é acordeão de novo, não flyout. */
  html.is-collapsed .nav-sub-inner { overflow: hidden; min-height: 0; }

  /* A gaveta mostra o menu inteiro e precisa rolar; o `overflow: visible` do
     estado recolhido só faz sentido para os flyouts do desktop. */
  html.is-collapsed .sidebar { overflow-x: hidden; overflow-y: auto; }
  html.is-collapsed .nav-sub { max-height: none; overflow: visible; }

  /* Sem hover no toque, a ponte só atrapalharia. */
  html.is-collapsed .nav-section::after { content: none; }
  html.is-collapsed .nav-sub-title { display: none; }
  html.is-collapsed .nav-link[data-tip]::after { content: none; }

  .sidebar-collapse { display: none; }   /* fechar é pelo backdrop ou por um link */
  .topbar-burger { display: grid; place-items: center; }

  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; z-index: 70;
    background: rgba(0, 0, 0, .55);
    opacity: 0; visibility: hidden; transition: opacity .22s, visibility .22s;
  }
  body.drawer-open .sidebar-backdrop { opacity: 1; visibility: visible; }
  body.drawer-open { overflow: hidden; }

  .gate { grid-template-columns: 1fr; }
  .gate-feed { border-left: 0; border-top: 1px solid var(--border); max-height: 40vh; }

  /**
   * iOS Safari dá zoom automático ao focar um <input> com font-size < 16px —
   * é o que fazia o campo "buscar" (e qualquer outro campo) parecer quebrado
   * no celular: a página inteira saltava de tamanho ao tocar o campo.
   */
  input, select, textarea { font-size: 16px; }

  /* Barra de busca empilha em tela estreita — em vez de espremer input,
     seletor e botão numa linha só que não cabe. */
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-form { max-width: none; width: 100%; }
  .toolbar-form select { flex: 1 1 110px; }
  .toolbar > .btn { width: 100%; text-align: center; }
}
