/* ==========================================================================
   LH Sales Toolkit — Reset, app shell, layout
   Mobile is the base layout. Desktop layout is opt-in via html.pv-desktop
   (set by assets/js/preview.js), so a phone and LINE in-app never pay for it.
   ========================================================================== */

*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-14);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2, h3, h4, p, figure, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }

/* The hidden attribute must win over any display a class sets. */
[hidden] { display: none !important; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  margin: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--lh-navy-500);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* --------------------------------------------------------------------------
   App shell
   .device is display:contents by default — it only becomes a phone bezel
   in desktop "mobile preview" mode (see preview.css).
   -------------------------------------------------------------------------- */

.device { display: contents; }

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background: var(--bg);
}

/* ---- App bar (LIFF header) --------------------------------------------- */

.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  /* .app is a constrained flex column in the preview bezel, so without this
     the bar shrinks below its own content and the subtitle gets clipped. */
  flex: 0 0 auto;
  display: grid;
  /* Both side slots grow equally, so the title stays centred even when the
     right slot holds a labelled action wider than the 40px back button. */
  grid-template-columns: minmax(max-content, 1fr) auto minmax(max-content, 1fr);
  align-items: center;
  gap: 4px;
  min-height: var(--appbar-h);
  padding: 0 6px;
  padding-top: env(safe-area-inset-top);
  color: var(--text-on-dark);
  background: var(--primary);
  box-shadow: var(--sh-1);
}

.appbar__icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: var(--text-on-dark);
  border-radius: var(--r-pill);
  transition: background var(--t-fast);
}
.appbar__icon:hover { background: rgba(255, 255, 255, .12); }
.appbar__icon[aria-pressed="true"] { background: rgba(255, 255, 255, .2); }
.appbar > :first-child { justify-self: start; }
.appbar > :last-child { justify-self: end; }

/* Labelled page action in the right slot, e.g. สร้างลีด on ลีดใหม่. */
.appbar__action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  padding: 0 13px 0 10px;
  font-size: var(--fs-13);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  color: var(--text-on-dark);
  background: rgba(255, 255, 255, .16);
  border: 1px solid rgba(255, 255, 255, .24);
  border-radius: var(--r-pill);
  transition: background var(--t-fast);
}
.appbar__action:hover { background: rgba(255, 255, 255, .26); }
.appbar__action:active { background: rgba(255, 255, 255, .34); }

.appbar__titles { min-width: 0; text-align: center; }

.appbar__title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: var(--fs-15);
  font-weight: 600;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.appbar__sub {
  font-size: var(--fs-11);
  color: rgba(255, 255, 255, .66);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


/* ---- Main scroll region ------------------------------------------------ */

.main {
  flex: 1 1 auto;
  padding: var(--gutter);
  padding-bottom: calc(var(--gutter) + 8px);
}

.main--flush { padding-left: 0; padding-right: 0; }

.app--has-tabbar .main {
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--gutter));
}

/* ---- Tab bar (mirrors the 4-button Rich Menu) -------------------------- */

.tabbar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: var(--sh-up);
}

.tabbar__item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: var(--tabbar-h);
  padding: 7px 2px 8px;
  font-size: var(--fs-11);
  font-weight: 500;
  color: var(--text-3);
  text-align: center;
  transition: color var(--t-fast);
}

.tabbar__item svg { width: 22px; height: 22px; }
.tabbar__item.is-active { color: var(--primary); font-weight: 600; }

.tabbar__item.is-active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 26px;
  height: 3px;
  background: var(--accent);
  border-radius: 0 0 var(--r-pill) var(--r-pill);
  transform: translateX(-50%);
}

.tabbar__count {
  position: absolute;
  top: 5px;
  left: 50%;
  margin-left: 6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  color: var(--text-on-dark);
  background: var(--danger);
  border-radius: var(--r-pill);
}

/* Switched off in LH.NAV: still drawn, so the 2x2 grid matches the Rich
   Menu image, but greyed out and not a link. */
.tabbar__item.is-disabled {
  color: var(--text-3);
  opacity: .42;
  cursor: default;
}

/* --------------------------------------------------------------------------
   Desktop layout — opt in with html.pv-desktop
   The tab bar unpins from the bottom and becomes a top nav row, and content
   is capped and centred instead of running the full width of a monitor.
   -------------------------------------------------------------------------- */

@media (min-width: 768px) {
  .pv-desktop .app { min-height: 100dvh; }

  .pv-desktop .appbar {
    grid-template-columns: 40px 1fr auto;
    min-height: 58px;
    padding: 0 18px;
  }

  .pv-desktop .appbar__titles { text-align: left; }
  .pv-desktop .appbar__title { justify-content: flex-start; }

  .pv-desktop .tabbar {
    position: sticky;
    top: 58px;
    display: flex;
    justify-content: center;
    gap: 4px;
    padding: 6px max(18px, calc((100% - var(--page-max)) / 2));
    border-top: 0;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--sh-1);
  }

  .pv-desktop .tabbar__item {
    flex-direction: row;
    gap: 8px;
    min-height: 42px;
    padding: 0 16px;
    font-size: var(--fs-13);
    border-radius: var(--r-pill);
  }

  .pv-desktop .tabbar__item.is-active { background: var(--lh-navy-050); }
  .pv-desktop .tabbar__item.is-active::before { display: none; }
  .pv-desktop .tabbar__count { position: static; margin: 0; }

  .pv-desktop .app--has-tabbar .main { padding-bottom: 32px; }

  .pv-desktop .main {
    width: 100%;
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 22px 18px 32px;
  }

  /* Lists get a second column once there is room for one. */
  .pv-desktop .grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    align-items: start;
  }
}

/* --------------------------------------------------------------------------
   Utilities
   -------------------------------------------------------------------------- */

.stack > * + * { margin-top: 10px; }
.stack-lg > * + * { margin-top: 18px; }
.row { display: flex; align-items: center; gap: 8px; }
.row--between { justify-content: space-between; }
.row--wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.center { text-align: center; }
.mt-0 { margin-top: 0; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  padding: 0 2px;
  font-size: var(--fs-12);
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--text-2);
  text-transform: uppercase;
}

.section-title__ref {
  font-size: var(--fs-11);
  font-weight: 600;
  letter-spacing: 0;
  color: var(--text-3);
  text-transform: none;
}
