/* Shell de aplicativo mobile (PWA) */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 64px;
  --topbar-h: 58px;
}

html, body.app-shell {
  overscroll-behavior-x: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-y pinch-zoom;
  max-width: 100%;
}

html {
  overflow-x: hidden;
  overflow-y: auto;
  height: 100%;
}

body.app-shell {
  padding-top: calc(var(--topbar-h) + var(--safe-top));
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  min-height: 100%;
  height: auto;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: auto;
}

body.app-shell[data-app="gestor"] {
  position: relative;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
}

/* Splash */
.app-splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.65rem;
  background: linear-gradient(165deg, #f8f3ec, #efe4d6);
  transition: opacity 0.35s ease, visibility 0.35s ease;
}
.app-splash.dark {
  background: linear-gradient(165deg, #0c1511, #132019);
  color: #eef5f0;
}
.app-splash.hide {
  opacity: 0;
  visibility: hidden;
  pointer-events: none !important;
  display: none !important;
}
.app-splash-mark {
  width: 84px;
  height: 84px;
  border-radius: 22px;
  background: #c45c26;
  color: #fff;
  display: grid;
  place-items: center;
  font-family: "Fraunces", Georgia, serif;
  font-size: 2.2rem;
  font-weight: 700;
  box-shadow: 0 16px 40px rgba(196, 92, 38, 0.35);
  overflow: hidden;
  animation: splash-pop 0.55s cubic-bezier(.2,.9,.2,1) both;
}
.app-splash-mark.dark {
  background: #3ecf8e;
  color: #062416;
  box-shadow: 0 16px 40px rgba(62, 207, 142, 0.25);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
}
.app-splash-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.app-splash strong {
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}
.app-splash small {
  color: #6d6258;
  animation: pulse 1.2s ease infinite;
}
.app-splash.dark small { color: #9bb0a4; }

@keyframes splash-pop {
  from { transform: scale(0.86); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

/* Topbar app */
.app-topbar,
.gestor-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 80;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  background: rgba(246, 241, 234, 0.9);
  border-bottom: 1px solid rgba(28, 23, 18, 0.08);
}
.gestor-topbar {
  display: none;
  background: rgba(15, 26, 21, 0.94);
  border-bottom-color: rgba(238, 245, 240, 0.08);
  color: #eef5f0;
  align-items: center;
  justify-content: space-between;
  padding-left: 0.85rem;
  padding-right: 0.85rem;
  gap: 0.5rem;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.gestor-topbar > div {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.gestor-topbar strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.95rem;
}
.app-topbar-inner {
  height: var(--topbar-h);
  max-width: min(1520px, 100%);
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.brand-fallback {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: #c45c26;
  color: #fff;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 700;
}
.status-dot.on::before,
.status-dot.off::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 0.35rem;
  vertical-align: middle;
}
.status-dot.on::before { background: #1f6b45; box-shadow: 0 0 0 3px rgba(31,107,69,.15); }
.status-dot.off::before { background: #9b2c2c; }

.install-btn {
  border: 0;
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  background: #c45c26;
  color: #fff;
  cursor: pointer;
}
.install-btn.light {
  background: #3ecf8e;
  color: #062416;
}
.top-cart {
  position: relative;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(28, 23, 18, 0.06);
}

/* Tabbar */
.app-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  width: 100%;
  max-width: 100%;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 0.35rem 0.25rem var(--safe-bottom);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  gap: 0.1rem;
  background: rgba(255, 252, 247, 0.94);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid rgba(28, 23, 18, 0.08);
  box-shadow: 0 -10px 30px rgba(60, 30, 10, 0.06);
  box-sizing: border-box;
  overflow: hidden;
}
.app-tabbar.dark {
  background: rgba(12, 21, 17, 0.96);
  border-top-color: rgba(238, 245, 240, 0.08);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.25);
}
.app-tabbar .tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: #6d6258;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 700;
  border-radius: 14px;
  position: relative;
  min-height: 52px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease;
}
.app-tabbar.dark .tab { color: #9bb0a4; }
.app-tabbar .tab svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.app-tabbar .tab.active {
  color: #c45c26;
  background: rgba(196, 92, 38, 0.1);
}
.app-tabbar.dark .tab.active {
  color: #3ecf8e;
  background: rgba(62, 207, 142, 0.12);
}
.app-tabbar .tab:active { transform: scale(0.96); }
.app-tabbar .tab span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-inline: 2px;
}
.tab-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 22px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: #c45c26;
  color: #fff;
  font-size: 0.65rem;
  font-style: normal;
  display: grid;
  place-items: center;
}

/* Bottom sheet */
.app-sheet[hidden] { display: none !important; }
.app-sheet {
  position: fixed;
  inset: 0;
  z-index: 120;
}
.app-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 8, 6, 0.45);
}
.app-sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fffaf4;
  border-radius: 22px 22px 0 0;
  padding: 0.75rem 1rem calc(1.25rem + var(--safe-bottom));
  animation: sheet-up 0.28s ease;
}
.sheet-handle {
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: rgba(28, 23, 18, 0.18);
  margin: 0.15rem auto 0.85rem;
}
.app-sheet-panel h3 {
  margin: 0 0 0.75rem;
  font-family: "Fraunces", Georgia, serif;
}
.sheet-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: rgba(28, 23, 18, 0.04);
  border-radius: 14px;
  padding: 0.95rem 1rem;
  margin-bottom: 0.5rem;
  font: inherit;
  font-weight: 650;
  color: inherit;
  cursor: pointer;
  text-decoration: none;
}
.sheet-note {
  color: #6d6258;
  font-size: 0.82rem;
  margin: 0.75rem 0 0;
}
@keyframes sheet-up {
  from { transform: translateY(100%); }
  to { transform: none; }
}

.app-tabbar.tabs-2 {
  grid-template-columns: 1fr 1fr;
}
.app-tabbar.tabs-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

/* Banner instalar PWA — topo */
.install-top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding-top: var(--safe-top);
  background: #1c1712;
  color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  animation: rise 0.3s ease both;
}
.install-top[hidden] { display: none !important; }
.install-top-inner {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.75rem 0.6rem;
  max-width: 1120px;
  margin: 0 auto;
}
.install-top-copy {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 0.05rem;
}
.install-top-copy strong { font-size: 0.9rem; }
.install-top-copy span {
  font-size: 0.75rem;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.install-top-btn {
  border: 0;
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  background: #c45c26;
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.install-top-close {
  border: 0;
  background: transparent;
  color: #fff;
  opacity: 0.7;
  font-size: 1.35rem;
  line-height: 1;
  padding: 0.2rem 0.35rem;
  cursor: pointer;
}

body.has-install-banner {
  --install-h: 52px;
  padding-top: calc(var(--topbar-h) + var(--safe-top) + var(--install-h));
}
body.has-install-banner .app-topbar {
  top: calc(var(--safe-top) + var(--install-h));
}
body.has-install-banner .toast-flash,
body.has-install-banner .app-toast {
  /* toast fica embaixo; banner de instalar no topo */
}

/* legado bottom banner (gestor ainda usa) */
.install-banner {
  position: fixed;
  left: 0.75rem;
  right: 0.75rem;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.85rem 0.9rem;
  border-radius: 18px;
  background: #1c1712;
  color: #fff;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  animation: rise 0.35s ease both;
}
.install-banner.dark {
  background: #102019;
  border: 1px solid rgba(62, 207, 142, 0.25);
}
.install-banner[hidden] { display: none !important; }
.install-banner > div {
  flex: 1;
  display: grid;
  gap: 0.1rem;
  min-width: 0;
}
.install-banner strong { font-size: 0.92rem; }
.install-banner span {
  font-size: 0.78rem;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.install-banner button {
  border: 0;
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
  font: inherit;
  font-weight: 700;
  background: #c45c26;
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.install-banner.dark button { background: #3ecf8e; color: #062416; }
.install-dismiss {
  background: transparent !important;
  color: inherit !important;
  opacity: 0.7;
  padding: 0.35rem 0.45rem !important;
  font-size: 1.2rem !important;
}

.toast-flash,
.app-toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  top: auto;
  right: auto;
  transform: translateX(-50%);
  z-index: 200;
  width: min(420px, calc(100vw - 1.5rem));
  max-width: calc(100vw - 1.5rem);
  margin: 0;
  padding: 0.85rem 1.1rem;
  border-radius: 14px;
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.35;
  text-align: center;
  color: #062416;
  background: #3ecf8e;
  border: 0;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  animation: toast-in 0.28s ease both;
  pointer-events: none;
}
.app-toast.err,
.toast-flash.flash-err {
  background: #ef6b6b;
  color: #1a0a0a;
}
body[data-app="store"] .app-toast.ok,
body[data-app="store"] .toast-flash.flash-ok {
  background: #1f6b45;
  color: #fff;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (min-width: 900px) {
  body.app-shell .app-toast,
  body.app-shell .toast-flash {
    bottom: 1.5rem;
  }
}

/* Hide old store header/footer in app shell */
body.app-shell .store-header,
body.app-shell .store-footer { display: none !important; }

/* Mobile-first content tweaks */
@media (max-width: 899px) {
  .desktop-only { display: none !important; }
  .desktop-nav { display: none !important; }
  .gestor-topbar { display: flex; }
  body.gestor-body.app-shell {
    padding-top: calc(var(--topbar-h) + var(--safe-top));
    padding-left: 0;
    padding-right: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    height: auto;
    min-height: 100%;
  }
  body.gestor-body.app-shell.auth-only-body {
    padding-top: 0;
    padding-bottom: 0;
  }
  body.gestor-body.app-shell.auth-only-body .app-tabbar {
    display: none !important;
  }
  .gestor-wrap.with-side {
    margin-left: 0 !important;
    width: 100%;
    max-width: 100%;
    display: block;
  }
  .gestor-main { padding: 0.85rem 0.85rem 1.25rem; max-width: 100%; }
  .store-main.app-content { padding: 0.85rem 1rem 1rem; }

  .hero {
    grid-template-columns: 1fr;
    min-height: auto;
    gap: 0.85rem;
    margin-bottom: 1rem;
  }
  .hero-copy { padding: 0.35rem 0 0; }
  .hero h1 { font-size: clamp(1.9rem, 8vw, 2.5rem); }
  .hero-visual {
    min-height: 160px;
    border-radius: 20px;
  }
  .product-grid { grid-template-columns: 1fr 1fr; gap: 0.7rem; }
  .product-tile { border-radius: 16px; }
  .product-body { padding: 0.75rem; }
  .product-body h3 { font-size: 0.92rem; }
  .product-detail,
  .checkout-grid { grid-template-columns: 1fr; gap: 1rem; }
  .detail-media img { aspect-ratio: 4/3; }
  .cart-item { padding: 0.85rem; }
  .btn-primary, .btn-sm { min-height: 44px; }
  .table { font-size: 0.88rem; }
  .table th:nth-child(n+4),
  .table td:nth-child(n+4) { /* keep usable */ }
  .page-head h1 { font-size: 1.45rem; }
  .stats { grid-template-columns: 1fr; }
}

@media (min-width: 900px) {
  body[data-app="store"] .app-tabbar,
  body[data-app="gestor"] .app-tabbar { display: none; }
  body.app-shell,
  body.has-install-banner {
    padding-top: 0;
    padding-bottom: 0;
  }
  .app-topbar,
  body.has-install-banner .app-topbar {
    position: sticky;
    top: 0;
    height: auto;
    padding-top: 0;
  }
  .app-topbar-inner { height: auto; padding-block: 0.85rem; }
  body[data-app="gestor"] .gestor-topbar { display: none; }
  body[data-app="store"] .install-banner,
  body[data-app="gestor"] .install-banner { display: none !important; }
  .install-top {
    position: sticky;
    top: 0;
    z-index: 95;
  }
  body.app-shell .store-header { display: block !important; }
  .toast-flash,
  .app-toast {
    bottom: 1.5rem;
  }
}

/* Standalone (instalado) — esconde chrome de browser residual */
@media (display-mode: standalone), (display-mode: fullscreen) {
  body.app-shell.standalone .install-banner,
  body.app-shell.standalone .install-top { display: none !important; }
  body.app-shell.standalone .install-btn { display: none !important; }
  body.app-shell.standalone .notify-banner:not([hidden]) {
    display: flex !important;
  }
}
