:root {
  --app-accent: #da1a21;
  --app-accent-dark: #b31219;
  --app-ink: #172033;
  --app-muted: #667085;
  --app-line: #d7dee8;
  --app-surface-overlay: rgba(255, 255, 255, .72);
  --app-surface-overlay-strong: rgba(255, 255, 255, .82);
  --app-surface-overlay-muted: rgba(246, 247, 249, .86);
  --app-background: #eef1f4;
  --app-control-radius: .625rem;
  --app-panel-radius: .75rem;
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Microsoft YaHei", Arial, sans-serif;
}

html { min-height: 100%; background: var(--app-background); }
body.public-app, body.public-app * { box-sizing: border-box; }

body.public-app {
  position: relative;
  isolation: isolate;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--app-ink);
  background: var(--app-background);
  -webkit-tap-highlight-color: rgba(218, 26, 33, .1);
}

body.public-app :where(a, button, input, select, textarea):focus-visible {
  border-color: var(--app-accent);
  outline: 3px solid rgba(218, 26, 33, .24);
  outline-offset: 2px;
}

body.public-app :where(button, input, select, textarea) { font: inherit; }
body.public-app :where(input, select, textarea) { accent-color: var(--app-accent); }

.public-candidate-backdrop {
  position: fixed;
  z-index: 0;
  right: 0;
  bottom: 0;
  display: block;
  width: min(34rem, 38vw);
  height: min(78vh, 56rem);
  object-fit: contain;
  object-position: right bottom;
  opacity: .14;
  pointer-events: none;
  user-select: none;
}

body.public-app > :where(header, main, nav) {
  position: relative;
  z-index: 1;
}

/* Persistent public navigation defaults to phone tabs; secondary pages promote it on desktop. */
body.public-app .public-navigation {
  position: relative;
  z-index: 40;
  display: grid;
  min-height: calc(4rem + env(safe-area-inset-bottom));
  flex: 0 0 auto;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--app-line);
  padding: 0 0 env(safe-area-inset-bottom);
  background: var(--app-surface-overlay-strong);
}

body.public-app .public-nav-item {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 4rem;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  gap: .2rem;
  border: 0;
  padding: .45rem .25rem .35rem;
  color: #737e8f;
  background: transparent;
  text-decoration: none;
}

body.public-app .public-nav-item:hover { color: #344054; background: var(--app-surface-overlay-muted); }
body.public-app .public-nav-item.active { color: var(--app-accent-dark); }

body.public-app .public-nav-item.active::before {
  position: absolute;
  top: 0;
  width: 2rem;
  height: 3px;
  background: var(--app-accent);
  content: "";
}

body.public-app .public-nav-item svg {
  display: block;
  width: 1.35rem;
  height: 1.35rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

body.public-app .public-nav-item span {
  overflow: hidden;
  max-width: 100%;
  font-size: .65rem;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Every secondary public page uses one fixed-height app shell. */
body.public-content-page {
  --surface: var(--app-surface-overlay);
  display: flex;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  flex-direction: column;
  line-height: 1.5;
}

body.public-content-page .app-header {
  position: relative;
  z-index: 50;
  display: block;
  min-height: 0;
  flex: 0 0 auto;
  border-bottom: 3px solid var(--app-accent);
  padding: 0;
  color: var(--app-ink);
  background: var(--app-surface-overlay-strong);
  box-shadow: none;
}

body.public-content-page .header-inner {
  display: grid;
  width: 100%;
  min-height: 4.25rem;
  grid-template-columns: 2.75rem minmax(0, 1fr) auto;
  align-items: center;
  gap: .6rem;
  margin: 0 auto;
  padding: max(.55rem, env(safe-area-inset-top)) .7rem .55rem;
}

body.public-content-page .app-header :where(.icon-button, .back-button) {
  display: grid;
  width: 2.75rem;
  height: 2.75rem;
  place-items: center;
  border: 0;
  border-radius: var(--app-control-radius);
  padding: 0;
  color: #344054;
  background: var(--app-surface-overlay-muted);
  text-decoration: none;
}

body.public-content-page .app-header :where(.icon-button, .back-button):hover { background: rgba(233, 237, 242, .9); }
body.public-content-page .app-header :where(.icon-button, .back-button) svg { width: 1.25rem; height: 1.25rem; }
body.public-content-page .header-title { min-width: 0; }

body.public-content-page .header-title p {
  overflow: hidden;
  margin: 0 0 .08rem;
  color: var(--app-muted);
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .025em;
  line-height: 1.25;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

body.public-content-page .header-title h1 {
  overflow: hidden;
  margin: 0;
  color: var(--app-ink);
  font-size: 1.02rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.public-content-page .header-actions { display: flex; min-width: 0; align-items: center; gap: .35rem; }

body.public-content-page .language-control select,
body.public-content-page :where(.identity-button, .account-button) {
  min-height: 2.75rem;
  border: 1px solid var(--app-line);
  border-radius: var(--app-control-radius);
  padding: .4rem .55rem;
  color: #344054;
  background: var(--app-surface-overlay-strong);
  font-size: .73rem;
  font-weight: 700;
}

body.public-content-page .language-control select:hover,
body.public-content-page :where(.identity-button, .account-button):hover { background: var(--app-surface-overlay-muted); }

body.public-content-page :where(.page-shell, .join-content) {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 0;
  flex: 1 1 auto;
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: .7rem .55rem 1.25rem;
  scrollbar-gutter: stable;
}

body.public-content-page :where(
  .notice,
  #submitPanel,
  #queryPanel,
  #listPanel,
  .content-panel,
  .poll-detail,
  .article-detail,
  .chat-panel,
  .cloud-section,
  .submission-section
) {
  border: 1px solid var(--app-line);
  border-radius: var(--app-panel-radius);
  background: var(--app-surface-overlay);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
}

body.public-content-page :where(#submitPanel, #queryPanel, #listPanel, .content-panel, .poll-detail, .article-detail, .chat-panel, .cloud-section) { overflow: hidden; }

body.public-content-page .section-heading {
  border-bottom-color: var(--app-line);
  padding: .9rem 1rem;
  background: var(--app-surface-overlay-muted);
}

body.public-content-page .section-heading h2 { color: var(--app-ink); }

body.public-content-page :where(
  input[type="text"],
  input[type="search"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  input[type="date"],
  input[type="file"],
  select,
  textarea
) { border-radius: var(--app-control-radius); }

body.public-content-page :where(.primary-button, .secondary-button, .location-button, .consult-button, .join-button) {
  min-height: 3rem;
  border-radius: var(--app-control-radius);
}

body.public-content-page :where(.primary-button, .consult-button) { background: rgba(218, 26, 33, .92); }
body.public-content-page .primary-button:hover,
body.public-content-page .consult-button:hover { background: rgba(179, 18, 25, .96); }

body.public-content-page :where(.secondary-button, .location-button, .share-link, .share-button, .back-to-faq, .dialog-close) { background: var(--app-surface-overlay-strong); }
body.public-content-page :where(.secondary-button, .location-button, .share-link, .share-button, .back-to-faq, .dialog-close):hover { background: var(--app-surface-overlay-muted); }
body.public-content-page .message-actions button { background: rgba(218, 26, 33, .92); }
body.public-content-page .message-actions button:hover { background: rgba(179, 18, 25, .96); }
body.public-content-page .poll-row { background: transparent; }
body.public-content-page .poll-row:hover { background: var(--app-surface-overlay-muted); }

body.public-content-page :where(.pdpa-box, .form-message, .result-panel, .choice-row, .reference-image, .record) { border-radius: var(--app-control-radius); }
body.public-content-page :where(.poll-row img, .poll-cover-placeholder, .thumbnail-wrap) { overflow: hidden; border-radius: .5rem; }
body.public-content-page :where(.status, .result-bar, .result-bar span) { border-radius: 999px; }
body.public-content-page .back-row { min-height: 2.75rem; padding-inline: .25rem; color: #344054; }

body.public-content-page .app-dialog,
body.public-content-page .identity-dialog {
  border-radius: var(--app-panel-radius);
  box-shadow: 0 8px 24px rgba(15, 23, 42, .2);
}

body.public-app .powered-by {
  position: static;
  z-index: auto;
  display: flex;
  width: max-content;
  min-height: 2.5rem;
  justify-content: center;
  margin: 1.25rem auto .25rem;
  transform: none;
  border-radius: var(--app-control-radius);
  box-shadow: none;
}

/* WhatsApp remains task-focused while retaining the same shell. */
body.whatsapp-page .header-inner { grid-template-columns: 2.75rem minmax(0, 1fr) auto; }

body.whatsapp-page .join-content {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

body.whatsapp-page .intake-subtitle { margin: 0; color: #344054; font-size: 1rem; line-height: 1.4; }
body.whatsapp-page .qr-frame { width: min(19rem, 78vw); margin-top: 1.25rem; overflow: hidden; border: 1px solid var(--app-line); border-radius: var(--app-panel-radius); padding: .7rem; background: #fff; }
body.whatsapp-page .join-button:not(.is-disabled) { background: #008069; }
body.whatsapp-page .join-button:not(.is-disabled):hover { background: #006b58; }
body.whatsapp-page .join-button.is-disabled { background: #9aa5ab; }

@media (max-width: 899px) {
  html { height: 100%; overflow: hidden; }
  .public-candidate-backdrop { display: none; }
  body.public-content-page .header-title p { display: none; }
  body.public-content-page .identity-button { max-width: 5.75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  body.topics-page .account-button span { display: none; }
}

@media (max-width: 390px) {
  body.public-content-page .header-inner { gap: .4rem; padding-inline: .5rem; }
  body.public-content-page .language-control select { max-width: 4.15rem; padding-inline: .35rem; }
  body.public-content-page .identity-button { max-width: 4.5rem; padding-inline: .4rem; }
}

/* Desktop is a full-width workspace, not a centred phone frame. */
@media (min-width: 900px) {
  body.public-content-page { background: var(--app-background); }
  body.public-content-page .app-header { order: 1; }

  body.public-content-page .header-inner {
    width: min(1180px, calc(100% - 3rem));
    min-height: 4.75rem;
    gap: .85rem;
    padding: .65rem 0;
  }

  body.public-content-page .header-title p { font-size: .68rem; }
  body.public-content-page .header-title h1 { font-size: 1.08rem; }

  body.public-content-page .public-navigation {
    min-height: 3.55rem;
    order: 2;
    grid-template-columns: repeat(4, minmax(8.5rem, 10.5rem));
    justify-content: center;
    border-top: 0;
    border-bottom: 1px solid var(--app-line);
    padding: 0;
  }

  body.public-content-page .public-nav-item {
    min-height: 3.55rem;
    flex-direction: row;
    gap: .55rem;
    border-bottom: 3px solid transparent;
    padding: .55rem 1rem .45rem;
  }

  body.public-content-page .public-nav-item.active { border-bottom-color: var(--app-accent); background: #fff7f7; }
  body.public-content-page .public-nav-item.active::before { display: none; }
  body.public-content-page .public-nav-item svg { width: 1.15rem; height: 1.15rem; }
  body.public-content-page .public-nav-item span { font-size: .82rem; }

  body.public-content-page :where(.page-shell, .join-content) {
    width: min(1180px, calc(100% - 3rem));
    order: 3;
    margin: 0 auto;
    padding: 1.5rem 0 3rem;
    overscroll-behavior: auto;
  }

  body.public-content-page .notice { padding: 1.1rem 1.25rem; }
  body.whatsapp-page .join-content { width: min(48rem, calc(100% - 3rem)); }

}

@media (prefers-reduced-motion: reduce) {
  body.public-app { scroll-behavior: auto; }
}
