/**
 * App shell — the standalone (installed PWA / TWA) presentation.
 *
 * Loaded by all four layouts but inert in a browser tab: apart from the single
 * `.app-only` gate below, EVERY rule in this file is scoped to `html.is-app`,
 * the class <x-app-shell-detect /> adds before first paint. That scoping is the
 * guarantee that the web site cannot shift by a pixel, and it is asserted by
 * tests/Feature/AppShell/AppShellLayoutTest.php — keep it when adding rules.
 *
 * Plain CSS, deliberately: the public site runs on Bootstrap 4 and the client
 * area on Tailwind, so this file has to sit on top of either reset without
 * dragging a second one in. For the same reason every shell element states its
 * own font, colour, border, background and text-decoration instead of
 * inheriting whatever the host page happens to provide.
 *
 * Brand colour is always var(--brand-primary) (emitted per brand by
 * <x-brand-vars />) — never a literal, or the shell would ship one brand's
 * identity to the other brand's domain.
 */

/* ---------------------------------------------------------------- 1. Gate */

.app-only {
  display: none;
}

html.is-app .app-only {
  display: revert;
}

html.is-app .app-hide {
  display: none !important;
}

/* The Bootstrap layout has no Tailwind, so it carries no [x-cloak] rule. */
html.is-app [x-cloak] {
  display: none !important;
}

/* -------------------------------------------------------------- 2. Tokens */

html.is-app {
  --app-ink: #1f1f2e;
  --app-brand-50: #fff3ee;
  --app-brand-100: #ffe2d5;
  --app-brand-200: #ffc4ab;
  --app-brand-700: #bf3300;
  --app-slate-50: #f8fafc;
  --app-slate-100: #f1f5f9;
  --app-slate-200: #e2e8f0;
  --app-slate-400: #94a3b8;
  --app-slate-500: #64748b;
  --app-slate-600: #475569;
  --app-danger: #dc2626;

  --app-r-sheet: 28px;
  --app-r-xl: 20px;
  --app-r-lg: 18px;
  --app-r: 16px;
  --app-r-sm: 14px;
  --app-r-pill: 999px;

  /* Never smaller: the minimum comfortable touch target. */
  --app-touch: 44px;
  --app-tabbar-h: 64px;

  --app-font: Poppins, system-ui, -apple-system, Segoe UI, sans-serif;
}

/* ------------------------------------------------- 3. Document, safe areas */

html.is-app body {
  /* Stops Chrome's pull-to-refresh from reloading the whole screen. */
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
  background: var(--app-slate-50);
}

html.is-app .app-main {
  /* Clears the fixed tab bar plus the gesture bar under it. */
  padding-bottom: calc(104px + env(safe-area-inset-bottom, 0px));
}

/* ---------------------------------------------------- 4. Immersive header */

html.is-app .app-header {
  background: var(--brand-primary);
  color: #fff;
  font-family: var(--app-font);
  /* Starts at y=0, under the translucent status bar; the inset is the padding. */
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 20px 20px;
}

/* Variant A — a tab's root screen: rounded off, with room for the card that
   overlaps it. Variant B (list and detail screens) keeps the square edge. */
html.is-app .app-header--a {
  border-radius: 0 0 30px 30px;
  padding-bottom: 20px;
  /* The search card hangs past the header's rounded edge (see .app-search-card);
     this is the room the next section needs so it cannot slide under it. */
  margin-bottom: 34px;
}

html.is-app .app-header__row {
  display: flex;
  align-items: center;
  gap: 12px;
}

html.is-app .app-header__greeting {
  font-size: 13px;
  opacity: 0.85;
  margin: 0 0 2px;
}

html.is-app .app-header__title {
  font-size: 23px;
  font-weight: 600;
  line-height: 1.25;
  margin: 0;
  color: #fff;
}

html.is-app .app-header--a .app-header__title {
  font-size: 26px;
}

html.is-app .app-header__meta {
  font-size: 13px;
  opacity: 0.85;
  margin: 4px 0 0;
}

html.is-app .app-header__back {
  width: var(--app-touch);
  height: var(--app-touch);
  margin-left: -12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border: 0;
  border-radius: var(--app-r-pill);
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 18px;
  text-decoration: none;
}

html.is-app .app-header__pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--app-r-pill);
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font: 500 13px var(--app-font);
  text-decoration: none;
}

html.is-app .app-header__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

html.is-app .app-avatar {
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  border-radius: var(--app-r-pill);
  background: rgba(255, 255, 255, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  font: 600 22px var(--app-font);
  color: #fff;
}

/* The card is the header's own slot, so it is pulled DOWN out of the header
   rather than up into it: -54px is the 34px it should overhang plus the 20px of
   padding below it. Pulling it up instead would cover the title. */
html.is-app .app-search-card {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 18px 0 -54px;
  padding: 6px 6px 6px 16px;
  background: #fff;
  border-radius: var(--app-r-xl);
  box-shadow: 0 8px 24px rgba(31, 31, 46, 0.12);
}

html.is-app .app-search-card input {
  flex: 1;
  min-width: 0;
  min-height: var(--app-touch);
  border: 0;
  outline: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
  font: 15px var(--app-font);
  color: var(--app-ink);
}

html.is-app .app-search-card button {
  width: var(--app-touch);
  height: var(--app-touch);
  flex: 0 0 auto;
  border: 0;
  border-radius: var(--app-r-sm);
  background: var(--brand-primary);
  color: #fff;
  font-size: 17px;
}

/* -------------------------------------------------------------- 5. Tab bar */

html.is-app .app-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--app-ink);
  border-radius: 22px 22px 0 0;
  padding: 10px 6px;
  /* 22px floor: Android without a gesture bar reports a 0 inset. */
  padding-bottom: max(22px, calc(env(safe-area-inset-bottom, 0px) + 10px));
  font-family: var(--app-font);
}

html.is-app .app-tabbar__item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: var(--app-touch);
  color: rgba(255, 255, 255, 0.5);
  font-size: 9.5px;
  font-weight: 500;
  line-height: 1.1;
  text-align: center;
  text-decoration: none;
}

html.is-app .app-tabbar__item i {
  font-size: 20px;
  line-height: 1;
}

html.is-app .app-tabbar__item.is-active {
  color: #fff;
  font-weight: 600;
}

html.is-app .app-tabbar__badge {
  position: absolute;
  top: -2px;
  left: calc(50% + 6px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--app-r-pill);
  background: var(--brand-primary);
  color: #fff;
  font-size: 9px;
  font-weight: 600;
  line-height: 16px;
  text-align: center;
}

/* ------------------------------------------- 6. Sections, tiles, carousels */

html.is-app .app-section {
  padding: 22px 20px 0;
  font-family: var(--app-font);
}

html.is-app .app-section__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--app-ink);
  margin: 0 0 12px;
}

html.is-app .app-carousel {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  margin: 0 -20px;
  padding: 2px 20px 6px;
}

html.is-app .app-carousel::-webkit-scrollbar {
  display: none;
}

html.is-app .app-tile {
  flex: 0 0 96px;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 14px 8px;
  background: #fff;
  border: 1px solid var(--app-slate-200);
  border-radius: var(--app-r-lg);
  color: var(--app-ink);
  font: 11.5px/1.2 var(--app-font);
  text-align: center;
  text-decoration: none;
}

html.is-app .app-tile img {
  width: 36px;
  height: 36px;
}

html.is-app .app-tile--more {
  justify-content: center;
  color: var(--app-brand-700);
  background: var(--app-brand-50);
  border-color: var(--app-brand-200);
  font-weight: 600;
}

html.is-app .app-card {
  flex: 0 0 200px;
  scroll-snap-align: start;
  display: block;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--app-slate-200);
  border-radius: var(--app-r-xl);
  color: var(--app-ink);
  font-family: var(--app-font);
  text-decoration: none;
}

html.is-app .app-card__title {
  margin: 0;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
}

html.is-app .app-card img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

html.is-app .app-cta-card {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 22px 20px 0;
  padding: 16px;
  background: var(--app-brand-50);
  border: 1px solid var(--app-brand-200);
  border-radius: var(--app-r-xl);
  color: var(--app-ink);
  font-family: var(--app-font);
  text-decoration: none;
}

html.is-app .app-cta-card i {
  font-size: 22px;
  color: var(--brand-primary);
}

html.is-app .app-cta-card strong {
  display: block;
  font-size: 15px;
}

html.is-app .app-cta-card span {
  font-size: 13px;
  color: var(--app-slate-600);
}

/* ------------------------------------------------------------ 7. List rows */

html.is-app .app-list {
  list-style: none;
  margin: 0;
  padding: 12px 20px 0;
  font-family: var(--app-font);
}

html.is-app .app-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: #fff;
  border: 1px solid var(--app-slate-200);
  border-radius: var(--app-r);
  color: var(--app-ink);
  text-decoration: none;
}

/* A row that is itself a button or a form's submit still fills the list. */
html.is-app button.app-row {
  width: 100%;
  text-align: left;
}

html.is-app .app-row--unread {
  background: var(--app-brand-50);
  border-color: var(--app-brand-200);
}

html.is-app .app-row__icon {
  display: flex;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--app-r-sm);
  background: var(--app-brand-50);
  color: var(--brand-primary);
  font-size: 18px;
}

/* The tappable half of a row that also carries its own action buttons. */
html.is-app .app-row__main {
  display: flex;
  flex: 1;
  min-width: 0;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

html.is-app .app-row__body {
  display: block;
  flex: 1;
  min-width: 0;
}

html.is-app .app-row__title {
  display: block;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--app-ink);
}

html.is-app .app-row__text {
  display: block;
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--app-slate-600);
}

html.is-app .app-row__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--app-slate-500);
}

html.is-app .app-row__value {
  display: block;
  flex: 0 0 auto;
  max-width: 45%;
  font-size: 13px;
  color: var(--app-slate-500);
  text-align: right;
}

html.is-app .app-row__chevron {
  flex: 0 0 auto;
  color: var(--app-slate-400);
  font-size: 14px;
}

html.is-app .app-row__cta {
  margin-top: 10px;
}

html.is-app .app-row__trailing {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

html.is-app .app-row__action {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--app-r-sm);
  background: transparent;
  color: var(--app-slate-500);
  font-size: 19px;
}

html.is-app .app-row__action--danger {
  color: var(--app-danger);
}

/* ------------------------------------------------------ 8. Pills and chips */

html.is-app .app-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--app-r-pill);
  font: 600 11.5px var(--app-font);
}

html.is-app .app-pill--new {
  background: var(--brand-primary);
  color: #fff;
}

html.is-app .app-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 14px 20px 4px;
  scrollbar-width: none;
}

html.is-app .app-chips::-webkit-scrollbar {
  display: none;
}

html.is-app .app-chip {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--app-slate-200);
  border-radius: var(--app-r-pill);
  background: #fff;
  color: var(--app-slate-600);
  font: 500 13px var(--app-font);
}

html.is-app .app-chip.is-active {
  background: var(--app-ink);
  border-color: var(--app-ink);
  color: #fff;
}

/* -------------------------------------------------------------- 9. Buttons */

html.is-app .app-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--app-touch);
  padding: 0 18px;
  border: 0;
  border-radius: var(--app-r-sm);
  font: 600 14px var(--app-font);
  text-decoration: none;
}

html.is-app .app-btn--primary {
  background: var(--brand-primary);
  color: #fff;
}

html.is-app .app-btn--ghost {
  background: var(--app-slate-100);
  color: var(--app-ink);
}

html.is-app .app-btn--outline-danger {
  background: transparent;
  border: 1.5px solid var(--app-danger);
  color: var(--app-danger);
}

html.is-app .app-btn--danger {
  background: var(--app-danger);
  color: #fff;
}

html.is-app .app-btn--block {
  width: 100%;
}

html.is-app .app-page-actions {
  padding: 24px 20px 0;
}

/* ------------------------------------------------------------- 10. Sheets */

html.is-app .app-sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  font-family: var(--app-font);
}

html.is-app .app-sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(31, 31, 46, 0.45);
}

html.is-app .app-sheet__panel {
  position: relative;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  background: #fff;
  border-radius: var(--app-r-sheet) var(--app-r-sheet) 0 0;
  padding: 12px 20px calc(env(safe-area-inset-bottom, 0px) + 20px);
}

html.is-app .app-sheet__handle {
  width: 40px;
  height: 4px;
  margin: 0 auto 14px;
  border-radius: var(--app-r-pill);
  background: var(--app-slate-200);
}

html.is-app .app-sheet__title {
  margin: 0 0 14px;
  font-size: 17px;
  font-weight: 600;
  color: var(--app-ink);
}

html.is-app .app-sheet__text {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--app-slate-600);
}

html.is-app .app-field {
  margin-bottom: 14px;
}

html.is-app .app-field > label {
  display: block;
  margin-bottom: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--app-slate-500);
}

/* .form-control is here for <x-register.address-fields />, Bootstrap markup
   reused inside the address sheet. */
html.is-app .app-sheet input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]),
html.is-app .app-sheet select,
html.is-app .app-sheet textarea,
html.is-app .app-sheet .form-control {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--app-slate-200);
  border-radius: var(--app-r-sm);
  background: #fff;
  box-shadow: none;
  font: 15px var(--app-font);
  color: var(--app-ink);
}

/* Sticky so a long form (the address sheet) never hides its own save button
   below the fold of the panel's own scroll. */
html.is-app .app-sheet__actions {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 10px;
  margin-top: 18px;
  padding: 10px 0 2px;
  background: #fff;
}

html.is-app .app-sheet__actions .app-btn {
  flex: 1;
}

/* ---------------------------------------------------- 11. Settings groups */

html.is-app .app-settings-group {
  margin: 18px 20px 0;
  font-family: var(--app-font);
}

html.is-app .app-settings-group__title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--app-slate-400);
}

html.is-app .app-settings-group__list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--app-slate-200);
  border-radius: var(--app-r-xl);
}

html.is-app .app-settings-group__list .app-row {
  width: 100%;
  margin: 0;
  border-width: 0 0 1px;
  border-radius: 0;
  background: transparent;
  text-align: left;
}

html.is-app .app-settings-group__list .app-row:last-child {
  border-bottom: 0;
}

/* --------------------------------------------------- 12. Fixed CTA footer */

html.is-app .app-cta-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--app-tabbar-h) + env(safe-area-inset-bottom, 0px));
  z-index: 39;
  padding: 12px 20px;
  background: linear-gradient(transparent, var(--app-slate-50) 30%);
}
