:root {
  --pwa-safe-top: env(safe-area-inset-top, 0px);
  --pwa-safe-bottom: env(safe-area-inset-bottom, 0px);
  --pwa-safe-left: env(safe-area-inset-left, 0px);
  --pwa-safe-right: env(safe-area-inset-right, 0px);
}

.pwa-splash-overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #ffffff url("../img/splash_horizontal.png") center center / cover no-repeat;
  z-index: 9999;
  opacity: 1;
  transition: opacity 0.35s ease;
}

.pwa-splash-overlay--hidden {
  opacity: 0;
  pointer-events: none;
}

html.pwa-standalone,
html.pwa-standalone body {
  background-color: var(--surface-bg, #f7f9fc);
}

html.pwa-standalone body {
  min-height: 100dvh;
}

html.pwa-standalone #app-header,
html.pwa-standalone body.chat-container header {
  padding-top: calc(var(--pwa-safe-top) + 6px);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  border-bottom-color: transparent;
}

html.pwa-standalone #app-shell {
  padding-top: calc(var(--pwa-safe-top) + 64px);
}

@media (max-width: 768px) {
  .pwa-splash-overlay {
    background-image: url("../img/splash.png");
  }

  html.pwa-standalone #app-main,
  html.pwa-standalone body.chat-container main {
    padding-bottom: calc(96px + var(--pwa-safe-bottom));
  }

  html.pwa-standalone .pwa-mobile-toolbar {
    position: sticky;
    top: calc(var(--pwa-safe-top) + 8px);
    z-index: 32;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(18px);
  }
  html.pwa-standalone .pwa-mobile-toolbar[data-pwa-sticky="false"] {
    position: static;
    top: auto;
    z-index: auto;
    box-shadow: none;
    backdrop-filter: none;
  }

  html.pwa-standalone .pwa-mobile-toolbar__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.4);
    background: #fff;
    color: #0f172a;
  }

  html.pwa-standalone .pwa-mobile-toolbar__title {
    font-size: 1.05rem;
    font-weight: 600;
    color: #0f172a;
    line-height: 1.25;
  }

  html.pwa-standalone .pwa-mobile-toolbar__eyebrow {
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #64748b;
    display: block;
  }

  html.pwa-standalone .pwa-mobile-toolbar__badge {
    border-radius: 999px;
    background: rgba(59, 130, 246, 0.12);
    color: #2563eb;
    font-weight: 600;
    font-size: 0.82rem;
    padding: 0.35rem 0.85rem;
  }

  html.pwa-standalone .pwa-mobile-toolbar__progress {
    font-weight: 600;
    font-size: 0.95rem;
    color: #0f172a;
  }

  html.pwa-standalone .pwa-bottom-actions {
    position: sticky;
    bottom: calc(var(--pwa-safe-bottom) + 12px);
    z-index: 40;
    width: 100%;
    margin-bottom: 0;
  }

  html.pwa-standalone .pwa-bottom-actions > div,
  html.pwa-standalone footer.pwa-bottom-actions > div {
    border-radius: 20px;
    background: #ffffff;
    box-shadow: 0 24px 55px rgba(15, 23, 42, 0.25);
  }

  html.pwa-standalone .pwa-bottom-actions .btn {
    flex: 1;
    min-width: 140px;
    justify-content: center;
  }

  html.pwa-standalone .pwa-card-stack {
    display: grid !important;
    gap: 1rem !important;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }

  html.pwa-standalone .pwa-card-stack > * {
    margin-top: 0 !important;
  }

  html.pwa-standalone .pwa-card {
    border-radius: 20px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.12);
    background: #fff;
  }

  html.pwa-standalone .pwa-card .template-card__title {
    font-size: 1.05rem;
  }

  html.pwa-standalone .pwa-card .template-card__badge {
    font-size: 0.7rem;
    padding: 0.25rem 0.65rem;
  }

  html.pwa-standalone .pwa-chip-row {
    gap: 0.35rem;
  }

  html.pwa-standalone .pwa-card .ui-card {
    border-radius: 20px;
  }

  html.pwa-standalone .pwa-card .ui-card,
  html.pwa-standalone .pwa-card.ui-card {
    border: none;
    box-shadow: none;
  }

  html.pwa-standalone .pwa-card .flex.gap-2 {
    flex-wrap: wrap;
  }
}
