/* BKon OS, modo app no celular.
   Tudo aqui só vale com html.bk-app (até 900px de largura, ou instalado em aparelho de toque).
   A classe é posta por js/app-mobile.js. Em tela larga nada muda.
   Usa só os tokens da marca v2 (portal.css): --bg-card, --bg-primary, --accent*, --text-*, --border*. */

html {
  --bk-appbar-h: 52px;
  --bk-tab-h: 58px;
  --bk-safe-top: env(safe-area-inset-top, 0px);
  --bk-safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Peças do app ficam ocultas fora do modo app */
.bk-appbar, .bk-tabbar, .bk-sheet, .bk-ptr, .bk-update, .bk-offline-bar, .bk-offline-full, .bk-ios-dica, .bk-chip-instalar { display: none; }

/* ── Base nativa ───────────────────────────────────── */
html.bk-app {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  overscroll-behavior-y: none;          /* mata o puxar-para-recarregar do navegador */
  scroll-behavior: auto;
}
html.bk-app body {
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
}
html.bk-app :is(a, button, [role="button"], [role="tab"], input, select, textarea, label, summary, .btn) {
  touch-action: manipulation;           /* sem atraso de 300ms nem zoom por toque duplo */
}
html.bk-app :is(button, .btn, [role="button"], .bk-tab, .bk-sheet__item) {
  -webkit-user-select: none;
  user-select: none;
}
html.bk-app :is(button, a.btn, [role="button"]):active {
  transform: scale(0.97);
  filter: brightness(0.94);
  transition-duration: 60ms;
}

/* ── Alvos de toque de 44px e campos sem zoom ──────── */
html.bk-app :is(.btn, button.btn, a.btn) { min-height: 44px; }
html.bk-app .modal__close, html.bk-app .fin-close { min-width: 44px; min-height: 44px; }
html.bk-app :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]), select, textarea) {
  font-size: 16px !important;           /* abaixo de 16px o iPhone dá zoom ao focar */
  min-height: 44px;
}
html.bk-app textarea { min-height: 88px; }
html.bk-app :is(input[type="checkbox"], input[type="radio"]) { width: 22px; height: 22px; }

/* ── Esconde o menu antigo e reorganiza o shell ───── */
html.bk-app .topbar,
html.bk-app .sidebar,
html.bk-app .sidebar-overlay { display: none !important; }
html.bk-app .app-shell { grid-template-columns: minmax(0, 1fr); }
html.bk-app .main-content {
  grid-column: 1;
  min-height: 100dvh;
  padding: calc(var(--bk-appbar-h) + var(--bk-safe-top) + 14px) 14px calc(var(--bk-tab-h) + var(--bk-safe-bottom) + 24px);
  overflow-y: visible;
}
html.bk-app.bk-kb .main-content { padding-bottom: 24px; }
html.bk-app .toast { right: 12px; left: 12px; max-width: none; bottom: calc(var(--bk-tab-h) + var(--bk-safe-bottom) + 12px); }
html.bk-app .chat-shell { height: calc(100dvh - var(--bk-appbar-h) - var(--bk-safe-top) - var(--bk-tab-h) - var(--bk-safe-bottom) - 28px); min-height: 360px; }

/* ── Cabeçalho do app ──────────────────────────────── */
html.bk-app.bk-logado .bk-appbar {
  display: flex; align-items: center; gap: 8px;
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  height: calc(var(--bk-appbar-h) + var(--bk-safe-top));
  padding: var(--bk-safe-top) 8px 0;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.bk-appbar__lado { width: 44px; height: 44px; flex: none; display: flex; align-items: center; justify-content: center; }
.bk-appbar__voltar, .bk-appbar__perfil {
  width: 44px; height: 44px; border: 0; background: transparent; color: var(--text-primary);
  border-radius: 12px; display: flex; align-items: center; justify-content: center; padding: 0; cursor: pointer;
}
.bk-appbar__voltar svg { width: 24px; height: 24px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.bk-appbar__marca { width: 28px; height: 28px; border-radius: 8px; display: block; }
.bk-appbar__titulo {
  flex: 1; min-width: 0; margin: 0; text-align: left;
  font-family: var(--font-display); font-size: 18px; font-weight: 700; letter-spacing: -0.02em;
  color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bk-appbar__perfil .client-avatar { width: 34px; height: 34px; font-size: 12px; }
.bk-appbar__perfil:active { background: var(--bg-raised); }

/* ── Barra de abas ─────────────────────────────────── */
html.bk-app.bk-logado .bk-tabbar {
  display: flex; align-items: stretch; justify-content: space-around;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  height: calc(var(--bk-tab-h) + var(--bk-safe-bottom));
  padding: 0 4px var(--bk-safe-bottom);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
}
html.bk-app.bk-kb .bk-tabbar { display: none; }
.bk-tab {
  flex: 1 1 0; min-width: 0; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: transparent; color: var(--text-muted);
  font-family: var(--font-ui); font-size: 11px; font-weight: 500; letter-spacing: 0.01em;
  padding: 4px 2px 2px; cursor: pointer;
}
.bk-tab__icone {
  position: relative; width: 56px; height: 30px; border-radius: 15px;
  display: flex; align-items: center; justify-content: center;
  transition: background-color 160ms var(--easing-out);
}
.bk-tab svg { width: 24px; height: 24px; stroke: currentColor; stroke-width: 1.7; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.bk-tab__rotulo { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bk-tab[aria-current="page"] { color: var(--accent-text); font-weight: 600; }
.bk-tab[aria-current="page"] .bk-tab__icone { background: var(--accent-soft); }
.bk-tab:active .bk-tab__icone { background: var(--bg-raised); }
.bk-badge {
  position: absolute; top: -3px; right: 6px; min-width: 18px; height: 18px; padding: 0 5px; box-sizing: border-box;
  border-radius: 9px; background: var(--accent); color: #fff; border: 2px solid var(--bg-card);
  font: 600 10px/14px var(--font-ui); text-align: center; pointer-events: none;
}
.bk-badge[hidden] { display: none; }

/* ── Folha (Mais) e modais em folha ────────────────── */
html.bk-app .bk-sheet { position: fixed; inset: 0; z-index: 1200; display: none; }
html.bk-app .bk-sheet.is-open { display: block; }
.bk-sheet__fundo { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.5); animation: bkFade 160ms ease-out both; }
.bk-sheet__painel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88dvh;
  display: flex; flex-direction: column;
  background: var(--bg-card); border-top: 1px solid var(--border-strong);
  border-radius: 20px 20px 0 0; box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.28);
  animation: bkSheetUp 260ms var(--easing-out) both;
  padding-bottom: var(--bk-safe-bottom);
}
.bk-sheet__alca, html.bk-app :is(.modal, .fin-modal, .client-drawer__panel, .crm-drawer__painel, .sp-gaveta__painel)::before {
  content: ''; display: block; flex: none; width: 40px; height: 5px; border-radius: 3px;
  background: var(--border-strong); margin: 8px auto 6px;
}
html.bk-app .modal::before, html.bk-app .fin-modal::before { margin: -10px auto 10px; }
html.bk-app .fin-modal::before { margin: 8px auto 0; }
.bk-sheet__corpo { overflow-y: auto; overscroll-behavior: contain; padding: 4px 16px 16px; }
.bk-sheet__eu { display: flex; align-items: center; gap: 12px; padding: 8px 4px 14px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.bk-sheet__eu-nome { font-weight: 600; font-size: 15px; color: var(--text-primary); overflow-wrap: anywhere; }
.bk-sheet__eu-sub { font-size: 13px; color: var(--text-muted); overflow-wrap: anywhere; }
.bk-sheet__grupo { margin: 10px 0 2px; padding: 0 4px; font: 500 11px/1 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); }
.bk-sheet__item {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 48px; padding: 8px 8px;
  border: 0; border-radius: 12px; background: transparent; cursor: pointer; text-align: left;
  font: 500 15px/1.2 var(--font-ui); color: var(--text-primary);
}
.bk-sheet__item:active { background: var(--bg-raised); transform: none; filter: none; }
.bk-sheet__item svg { width: 22px; height: 22px; flex: none; stroke: currentColor; stroke-width: 1.7; fill: none; stroke-linecap: round; stroke-linejoin: round; color: var(--text-secondary); }
.bk-sheet__item .sp-nav-conta { margin-left: auto; }
.bk-sheet__item--perigo, .bk-sheet__item--perigo svg { color: var(--danger); }
.bk-sheet__rodape { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border); }

html.bk-app .modal-overlay, html.bk-app .fin-overlay { align-items: flex-end; justify-content: center; padding: 0; }
html.bk-app .modal-overlay { animation: bkFade 160ms ease-out both; }
html.bk-app :is(.modal, .fin-modal) {
  max-width: none !important; width: 100%; max-height: 92dvh;
  border-radius: 20px 20px 0 0; border-bottom: 0;
  overflow-y: auto; overscroll-behavior: contain;
  padding-bottom: calc(20px + var(--bk-safe-bottom));
  animation: bkSheetUp 260ms var(--easing-out) both;
}
html.bk-app .fin-modal { padding-bottom: 0; }
html.bk-app .fin-modal__acoes { padding-bottom: calc(14px + var(--bk-safe-bottom)); }
html.bk-app .modal__header { position: sticky; top: 0; background: var(--bg-card); z-index: 1; }

/* Gavetas laterais viram folha que sobe */
html.bk-app .client-drawer { align-items: flex-end; justify-content: center; }
html.bk-app .client-drawer__panel {
  width: 100%; height: 92dvh; border-left: 0; border-radius: 20px 20px 0 0;
  animation: bkSheetUp 260ms var(--easing-out) both;
}
html.bk-app :is(.crm-drawer__painel, .sp-gaveta__painel) {
  top: auto; left: 0; right: 0; width: 100%; height: 92dvh; border-left: 0; border-radius: 20px 20px 0 0;
  animation: bkSheetUp 260ms var(--easing-out) both;
}
html.bk-app :is(.crm-drawer__painel, .sp-gaveta__painel, .client-drawer__panel) { padding-bottom: var(--bk-safe-bottom); }

@keyframes bkSheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes bkFade { from { opacity: 0; } to { opacity: 1; } }

/* ── Puxar para atualizar ──────────────────────────── */
html.bk-app.bk-logado .bk-ptr {
  display: flex; position: fixed; left: 50%; z-index: 55; pointer-events: none;
  top: calc(var(--bk-appbar-h) + var(--bk-safe-top) + 6px);
  width: 40px; height: 40px; margin-left: -20px; border-radius: 50%;
  align-items: center; justify-content: center;
  background: var(--bg-card); border: 1px solid var(--border-strong); box-shadow: var(--shadow-card-hover);
  color: var(--accent-text); opacity: 0; transform: translateY(-60px);
}
.bk-ptr svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2.2; fill: none; stroke-linecap: round; }
.bk-ptr.is-ativo { transition: none; }
.bk-ptr.is-solto { transition: transform 220ms var(--easing-out), opacity 220ms; }
.bk-ptr.is-girando svg { animation: bkGira 700ms linear infinite; }
@keyframes bkGira { to { transform: rotate(360deg); } }

/* ── Transição entre telas ─────────────────────────── */
html.bk-app .page.bk-ent-frente { animation: bkEntraFrente 240ms var(--easing-out) backwards; }
html.bk-app .page.bk-ent-volta  { animation: bkEntraVolta 240ms var(--easing-out) backwards; }
html.bk-app .page.bk-ent-aba    { animation: bkEntraAba 200ms var(--easing-out) backwards; }
@keyframes bkEntraFrente { from { opacity: 0; transform: translateX(22px); } to { opacity: 1; transform: none; } }
@keyframes bkEntraVolta  { from { opacity: 0; transform: translateX(-22px); } to { opacity: 1; transform: none; } }
@keyframes bkEntraAba    { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Avisos: nova versão, offline, instalar ────────── */
.bk-update, .bk-offline-bar { z-index: 1300; }
html.bk-app .bk-update.is-visivel, .bk-update.is-visivel {
  display: flex; align-items: center; gap: 12px; position: fixed; left: 12px; right: 12px; z-index: 1300;
  bottom: calc(var(--bk-tab-h) + var(--bk-safe-bottom) + 12px);
  padding: 12px 14px; border-radius: 14px; border: 1px solid var(--accent-border);
  background: var(--bg-card); color: var(--text-primary); box-shadow: var(--shadow-card-hover);
  font: 500 14px/1.3 var(--font-ui);
}
html:not(.bk-app) .bk-update.is-visivel { left: auto; right: 20px; bottom: 20px; max-width: 360px; }
html:not(.bk-logado) .bk-update.is-visivel { bottom: calc(var(--bk-safe-bottom) + 12px); }
.bk-update button { margin-left: auto; flex: none; min-height: 40px; padding: 0 14px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font: 600 14px var(--font-ui); cursor: pointer; }

.bk-offline-bar.is-visivel {
  display: block; position: fixed; left: 0; right: 0; z-index: 1300; text-align: center;
  top: calc(var(--bk-appbar-h) + var(--bk-safe-top));
  padding: 6px 12px; background: var(--warning, #B54708); color: #fff; font: 500 13px/1.3 var(--font-ui);
}
html:not(.bk-logado) .bk-offline-bar.is-visivel { top: 0; padding-top: calc(6px + var(--bk-safe-top)); }

.bk-offline-full.is-visivel {
  display: flex; position: fixed; inset: 0; z-index: 2000; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: calc(24px + var(--bk-safe-top)) 24px calc(24px + var(--bk-safe-bottom));
  background: var(--bg-primary); color: var(--text-primary);
}
.bk-offline-full__icone { width: 60px; height: 60px; border-radius: 18px; background: var(--bg-card); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; color: var(--accent-text); }
.bk-offline-full__icone svg { width: 28px; height: 28px; stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; }
.bk-offline-full h2 { font-family: var(--font-display); font-size: 22px; margin: 18px 0 8px; }
.bk-offline-full p { margin: 0 0 24px; color: var(--text-secondary); line-height: 1.5; max-width: 300px; }
.bk-offline-full button { min-height: 48px; padding: 0 28px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font: 600 16px var(--font-ui); cursor: pointer; }

.bk-chip-instalar.is-visivel {
  display: flex; align-items: center; gap: 8px; position: fixed; left: 50%; transform: translateX(-50%); z-index: 70;
  bottom: calc(var(--bk-safe-bottom) + 14px); min-height: 44px; padding: 0 8px 0 16px;
  border-radius: 22px; border: 1px solid var(--border-strong); background: var(--bg-card); color: var(--text-primary);
  box-shadow: var(--shadow-card-hover); font: 500 14px var(--font-ui); white-space: nowrap;
}
.bk-chip-instalar button { border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; min-height: 44px; }
.bk-chip-instalar__ok { color: var(--accent-text); font-weight: 600; }
.bk-chip-instalar__x { width: 36px; color: var(--text-muted); font-size: 18px; }
html.bk-logado .bk-chip-instalar { display: none !important; }

.bk-ios-dica.is-visivel {
  display: block; position: fixed; left: 12px; right: 12px; z-index: 1100;
  bottom: calc(var(--bk-tab-h) + var(--bk-safe-bottom) + 12px); padding: 14px 16px; border-radius: 14px;
  background: var(--bg-card); border: 1px solid var(--accent-border); box-shadow: var(--shadow-card-hover);
  font: 400 14px/1.45 var(--font-ui); color: var(--text-secondary);
}
.bk-ios-dica strong { color: var(--text-primary); }
.bk-ios-dica svg { width: 16px; height: 16px; vertical-align: -3px; stroke: var(--accent-text); stroke-width: 2; fill: none; }
.bk-ios-dica button { display: block; margin: 10px 0 0 auto; min-height: 40px; padding: 0 16px; border: 0; border-radius: 10px; background: var(--accent-soft); color: var(--accent-text); font: 600 14px var(--font-ui); cursor: pointer; }

/* Safe area no login (notch e barra de gestos) */
html.bk-app .screen--login { padding-top: var(--bk-safe-top); padding-bottom: var(--bk-safe-bottom); min-height: 100dvh; }

@media (prefers-reduced-motion: reduce) {
  html.bk-app .page.bk-ent-frente, html.bk-app .page.bk-ent-volta, html.bk-app .page.bk-ent-aba,
  .bk-sheet__painel, .bk-sheet__fundo, html.bk-app :is(.modal, .fin-modal, .client-drawer__panel, .crm-drawer__painel, .sp-gaveta__painel),
  html.bk-app .modal-overlay { animation: none !important; }
  .bk-tab__icone, .bk-ptr.is-solto { transition: none; }
  html.bk-app :is(button, a.btn, [role="button"]):active { transform: none; }
}
