@charset "UTF-8";

/* ==========================================================================
   1. Design tokens
   Values mirror res/values/subset.xml (colors + radius).
   ========================================================================== */
:root {
  /* Brand */
  --color-vn-red: #920005;        /* vn_red     – portal background      */
  --color-vn-gold: #bf9722;       /* vn_gold    – portal titles          */
  --color-red-button: #d81e06;    /* red_button – primary buttons/errors */

  /* Neutrals */
  --color-white: #ffffff;
  --color-black: #000000;
  --color-page-bg: #f2f2f2;       /* outside the phone-width column      */
  --color-light-gray: #e1e1e1;    /* light_gray – filled inputs          */
  --color-border-gray: #bbbbbb;   /* border_gray – thin bordered inputs  */
  --color-hint-gray: #999999;     /* hint_gray                           */
  --color-text-gray: #727171;     /* text_gray                           */

  /* Status page */
  --color-success: #0f9d58;
  --color-success-soft: #e6f4ec;

  /* Shape & type */
  --radius-default: 8px;
  --radius-pill: 999px;
  --font-size-body: 17px;
  --font-size-input: 16px;
  --font-size-label: 15px;
  --font-size-error: 13px;
  --font-size-small: 13px;

  /* Spacing */
  --page-padding-x: 16px;
  --page-padding-top: 12px;
  --page-padding-bottom: 24px;
  --label-gap: 8px;
  --field-gap: 16px;
  --control-min-height: 48px;
  --top-bar-height: 52px;
  --phone-max-width: 480px;

  /* Small viewport unit: excludes the mobile browser address bar, so the
     page never jumps when Safari/Chrome collapse their toolbars. */
  --vh-safe: 100vh;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --app-min-height: calc(var(--vh-safe) - var(--safe-top) - var(--safe-bottom));

  --font-stack: system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", "Noto Sans", Arial, sans-serif;

  --shadow-phone: 0 0 0 1px rgba(0, 0, 0, 0.04), 0 12px 40px rgba(0, 0, 0, 0.10);
  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.08);
  --duration: 160ms;
}

/* Prefer small-viewport units where supported (Safari 15.4+, Chrome 108+) */
@supports (height: 100svh) {
  :root {
    --vh-safe: 100svh;
  }
}

/* ==========================================================================
   2. Reset / base
   ========================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  background: var(--color-page-bg);
  /* Keep the viewport still when the mobile keyboard opens/closes */
  overscroll-behavior-y: none;
  scrollbar-gutter: stable;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: var(--app-min-height);
  background: var(--color-page-bg);
  color: var(--color-black);
  font-family: var(--font-stack);
  font-size: var(--font-size-body);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  user-select: none;
}

h1,
p,
label,
span,
li {
  overflow-wrap: break-word;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  /* 16px+ avoids iOS Safari's automatic zoom on focus */
  font-size: max(16px, 1rem);
}

a {
  color: inherit;
}

:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: 3px solid var(--color-red-button);
  outline-offset: 2px;
}

/* Screen-reader-only helper */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   3. Layout shell: phone-width column centred on desktop
   ========================================================================== */
.app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--phone-max-width);
  min-height: var(--app-min-height);
  margin: 0 auto;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  background: var(--color-white);
  overflow-x: hidden;
}

/* Tablets / desktop: show the page as a phone-width column on a grey desk */
@media (min-width: 520px) {
  .app {
    min-height: auto;
    max-height: calc(var(--vh-safe) - 48px);
    margin: 24px auto;
    padding-left: 0;
    padding-right: 0;
    border-radius: 20px;
    box-shadow: var(--shadow-phone);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

/* ==========================================================================
   4. Portal page (gov_service_portal.xml)
   ========================================================================== */
.app--portal {
  background: var(--color-vn-red);
  color: var(--color-white);
}

.portal {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: center;
  padding: 0 15px var(--page-padding-bottom);
  text-align: center;
}

/* Top cluster: emblem / title / subtitle.
   Sizes follow the Android layout (150dp top gap) but shrink on small and
   short screens so the two buttons stay reachable without scrolling. */
.portal__brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: clamp(28px, 12vh, 150px);
}

/* Keeps a balanced gap above the description on tall and short screens */
.portal__spacer {
  flex: 1 1 40px;
  min-height: clamp(16px, 5vh, 64px);
}

.portal__emblem {
  width: clamp(104px, 34vw, 148px);
  height: clamp(104px, 34vw, 148px);
  object-fit: contain;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.28));
}

.portal__title {
  margin-top: clamp(16px, 4vh, 30px);
  color: var(--color-vn-gold);
  font-size: var(--font-size-body);
  font-weight: 700;
  letter-spacing: 0.5px;
  line-height: 1.3;
}

.portal__subtitle {
  margin-top: 10px;
  color: var(--color-vn-gold);
  font-size: clamp(13px, 3.6vw, var(--font-size-label));
  font-weight: 500;
  line-height: 1.4;
  text-wrap: balance;
}

.portal__description {
  max-width: 34em;
  color: var(--color-white);
  font-size: clamp(13px, 3.8vw, 14px);
  line-height: 1.55;
  text-align: center;
  text-wrap: pretty;
}

.portal__actions {
  width: 100%;
  max-width: 420px;
  margin-top: clamp(16px, 3.5vh, 20px);
}

/* Second action (outlined) keeps its own top margin, but the first one should not */
.portal__actions .btn + .btn {
  margin-top: clamp(12px, 2.5vh, 20px);
}

/* Footer row: privacy policy (left) / version (right) */
.portal__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 12px;
  width: 100%;
  margin-top: auto;
  padding-top: clamp(24px, 6vh, 40px);
  color: var(--color-white);
  font-size: var(--font-size-small);
}

.portal__footer-version {
  margin-left: auto;
  opacity: 0.9;
}

/* ==========================================================================
   5. Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: var(--control-min-height);
  padding: 12px 16px;
  border: 0;
  border-radius: var(--radius-default);
  font-size: var(--font-size-input);
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--duration) ease,
    border-color var(--duration) ease, opacity var(--duration) ease,
    transform var(--duration) ease;
}

.btn:active {
  transform: scale(0.99);
}

/* Primary – btn_red_bg (normal red_button, pressed vn_red) */
.btn--primary {
  background: var(--color-red-button);
  color: var(--color-white);
  -webkit-text-fill-color: var(--color-white);
}

.btn--primary:hover {
  background: var(--color-vn-red);
}

/* Secondary – input_bg_white_border (2px white stroke, transparent fill) */
.btn--outline {
  background: transparent;
  border: 2px solid var(--color-white);
  color: var(--color-white);
}

.btn--outline:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* On the red portal background, focus rings switch to white */
.portal .btn:focus-visible {
  outline-color: var(--color-white);
  outline-offset: 3px;
}

.btn[disabled],
.btn[aria-disabled="true"] {
  cursor: default;
  opacity: 0.72;
  transform: none;
}

/* ==========================================================================
   6. Form pages (identity_activation.xml)
   ========================================================================== */
.app--form {
  background: var(--color-white);
}

/* Top bar: back arrow + centred bold title */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  min-height: calc(var(--top-bar-height) + var(--safe-top));
  margin: 0 var(--page-padding-x);
  padding-top: var(--safe-top);
  background: rgba(255, 255, 255, 0.94);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.top-bar__back {
  position: absolute;
  top: 50%;
  left: -8px; /* 48px hit area optically aligns with the 16px page edge */
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 12px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  cursor: pointer;
  transform: translateY(-50%);
  transition: background-color var(--duration) ease;
}

.top-bar__back:hover {
  background: rgba(0, 0, 0, 0.06);
}

.top-bar__back svg {
  width: 24px;
  height: 24px;
  color: #333333;
}

.top-bar__title {
  max-width: calc(100% - 96px);
  color: var(--color-black);
  font-size: clamp(16px, 4.6vw, var(--font-size-body));
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.form {
  flex: 1 1 auto;
  width: 100%;
  padding: var(--page-padding-top) var(--page-padding-x)
    calc(var(--page-padding-bottom) + var(--safe-bottom));
}

.form__field {
  margin-top: var(--field-gap);
}

.form__label {
  display: block;
  color: var(--color-black);
  font-size: var(--font-size-label);
  font-weight: 500;
  line-height: 1.35;
}

/* Inputs: min-height 48, 16px text, 12px inner padding, 8px below label */
.form__input {
  display: block;
  width: 100%;
  min-height: var(--control-min-height);
  margin-top: var(--label-gap);
  padding: 12px;
  border-radius: var(--radius-default);
  /* Never below 16px: iOS Safari zooms the page when focusing smaller text */
  font-size: max(16px, var(--font-size-input));
  line-height: 1.3;
  -webkit-appearance: none;
  appearance: none;
  background-clip: padding-box;
  transition: border-color var(--duration) ease, box-shadow var(--duration) ease,
    background-color var(--duration) ease;
}

/* Password field with its show/hide button */
.form__input--password {
  padding-right: 64px;
}

.form__field--relative {
  position: relative;
}

/* Wrapper keeps the input aligned with the other fields and anchors the toggle */
.form__password {
  position: relative;
  margin-top: var(--label-gap);
}

.form__password .form__input {
  margin-top: 0;
}

.form__password-toggle {
  position: absolute;
  top: 50%;
  right: 4px;
  min-width: 56px;
  min-height: 40px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-default);
  background: transparent;
  color: var(--color-text-gray);
  font-size: var(--font-size-small);
  font-weight: 600;
  cursor: pointer;
  transform: translateY(-50%);
}

.form__password-toggle:hover,
.form__password-toggle[aria-pressed="true"] {
  color: var(--color-red-button);
}

.form__password-toggle:hover,
.form__password-toggle[aria-pressed="true"] {
  color: var(--color-red-button);
}

.form__input::placeholder {
  color: var(--color-hint-gray);
  opacity: 1;
}

/* Native date picker icon: keep it dark on the white/thin-bordered inputs */
.form__input--outlined::-webkit-calendar-picker-indicator,
.form__input--filled::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.75;
}

/* Modifier: gray-filled box (input_bg_gray_filled) */
.form__input--filled {
  border: 2px solid transparent;
  background-color: var(--color-light-gray);
}

.form__input--filled:focus {
  border-color: var(--color-red-button);
  background-color: var(--color-white);
}

/* Modifier: thin 1px border (input_bg_thin_border) */
.form__input--outlined {
  border: 1px solid var(--color-border-gray);
  background-color: var(--color-white);
}

.form__input--outlined:focus {
  border-color: var(--color-red-button);
  box-shadow: 0 0 0 3px rgba(216, 30, 6, 0.12);
}

.form__input:focus-visible {
  outline: 3px solid rgba(216, 30, 6, 0.55);
  outline-offset: 1px;
}

/* Invalid state */
.form__input.is-invalid,
.form__input[aria-invalid="true"] {
  border-color: var(--color-red-button);
}

.form__input.is-invalid:focus,
.form__input[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px rgba(216, 30, 6, 0.16);
}

/* Inline error text (role="alert") */
.form__error {
  display: none;
  margin-top: 6px;
  padding-left: 2px;
  color: var(--color-red-button);
  font-size: var(--font-size-error);
  line-height: 1.3;
}

.form__error.is-visible {
  display: block;
}

/* When an error is visible, keep the following input from crowding it */
.form__error.is-visible + .form__input {
  margin-top: 10px;
}

/* Stacked inputs in one field group */
.form__field .form__input + .form__input {
  margin-top: 8px;
}

/* A visible error already provides its own 6px gap */
/* A visible error adds its own 6px gap; 8px keeps the next input clear */
.form__field .form__error.is-visible + .form__input {
  margin-top: 8px;
}

.form__submit {
  margin-top: 24px;
}

/* Inline spinner (white, for the red submit button) */
.spinner {
  display: inline-block;
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: var(--color-white);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.form-status {
  min-height: 1.2em;
  margin-top: 10px;
  color: var(--color-text-gray);
  font-size: var(--font-size-small);
  text-align: center;
}

/* ==========================================================================
   7. Status page (submit success → waiting for approval)
   ========================================================================== */
.app--status {
  background: var(--color-white);
}

.status {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: center;
  padding: 8px var(--page-padding-x) 0;
}

.status__card {
  width: 100%;
  margin-top: 8px;
  padding: 28px 20px 24px;
  border: 1px solid #ececec;
  border-radius: 16px;
  background: var(--color-white);
  box-shadow: var(--shadow-card);
  text-align: center;
  animation: fade-in-up 320ms ease-out both;
}

.status__icon {
  width: 72px;
  height: 72px;
  margin: 0 auto;
}

.status__icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

.status__icon-circle {
  fill: var(--color-success-soft);
  stroke: var(--color-success);
  stroke-width: 2;
}

.status__icon-check {
  fill: none;
  stroke: var(--color-success);
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Draw-on animation for the check mark */
.status__icon-check {
  stroke-dasharray: 60;
  stroke-dashoffset: 60;
  animation: check-draw 420ms ease-out 180ms forwards;
}

@keyframes check-draw {
  to {
    stroke-dashoffset: 0;
  }
}

.status__message {
  margin-top: 16px;
  color: #333333;
  font-size: var(--font-size-input);
  line-height: 1.5;
}

.status__waiting {
  margin-top: 18px;
  color: var(--color-red-button);
  font-size: var(--font-size-label);
  font-weight: 600;
  line-height: 1.45;
}

.status__note {
  margin-top: 4px;
  color: var(--color-hint-gray);
  font-size: var(--font-size-small);
  line-height: 1.45;
}

/* Indeterminate loading indicator */
.status__loading {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 20px;
}

.spinner--lg {
  width: 24px;
  height: 24px;
  border-width: 3px;
  border-color: rgba(216, 30, 6, 0.18);
  border-top-color: var(--color-red-button);
}

/* Step list */
.steps {
  width: 100%;
  margin: 24px 0 0;
  padding: 0;
  list-style: none;
  text-align: left;
}

.steps__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 4px 0;
  color: var(--color-hint-gray);
  font-size: var(--font-size-label);
}

/* Connecting rail between the dots */
.steps__item::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 10px;
  width: 2px;
  height: calc(100% + 8px);
  background: #e3e3e3;
}

.steps__item:last-child::before {
  display: none;
}

.steps__dot {
  position: relative;
  z-index: 1;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 2px solid #d9d9d9;
  border-radius: 50%;
  background: var(--color-white);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.steps__label {
  font-weight: 500;
}

/* State: done */
.steps__item.is-done {
  color: #222222;
}

.steps__item.is-done .steps__dot {
  border-color: var(--color-success);
  background: var(--color-success);
  color: var(--color-white);
}

.steps__item.is-done::before {
  background: var(--color-success);
  opacity: 0.35;
}

/* State: current / in progress */
.steps__item.is-current {
  color: var(--color-red-button);
  font-weight: 600;
}

.steps__item.is-current .steps__dot {
  border-color: var(--color-red-button);
  background: var(--color-white);
}

.steps__item.is-current .steps__dot::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-red-button);
  animation: pulse 1.4s ease-in-out infinite;
}

.status {
  min-height: 100%;
}

.status__footer {
  width: 100%;
  margin-top: auto;
  padding: 24px 0 calc(20px + var(--safe-bottom));
  color: var(--color-hint-gray);
  font-size: var(--font-size-small);
  text-align: center;
}

/* ==========================================================================
   8. Animations
   ========================================================================== */
/* shake.xml: fromX -12 → +12, 80ms, 6 repeats (reverse mode) */
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  12.5% {
    transform: translateX(-12px);
  }
  37.5% {
    transform: translateX(12px);
  }
  62.5% {
    transform: translateX(-12px);
  }
  87.5% {
    transform: translateX(12px);
  }
}

.is-shaking {
  animation: shake 80ms linear 6 alternate;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.35;
    transform: scale(0.75);
  }
}

@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Respect reduced-motion: stop non-essential motion, keep a static hint */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .is-shaking {
    animation: none !important;
  }

  /* Spinners stay visible but still convey progress via a static arc */
  .spinner {
    animation: none !important;
    border-top-color: rgba(255, 255, 255, 0.4);
    border-right-color: var(--color-white);
  }

  .spinner--lg {
    animation: none !important;
    border-top-color: rgba(216, 30, 6, 0.18);
    border-right-color: var(--color-red-button);
  }

  .steps__item.is-current .steps__dot::after {
    animation: none !important;
  }

  .status__icon-check {
    animation: none !important;
    stroke-dashoffset: 0;
  }
}

/* ==========================================================================
   9. Responsive breakpoints
   --------------------------------------------------------------------------
   ≤360px : compact phones  (iPhone SE, 320–360px)
   ≤400px : most phones     (iPhone 12 mini → 15, older Android)
   ≥520px : tablet / desk   (phone column becomes a rounded card)
   横屏低高度 (≤480px 高)    : 门户页允许滚动，表单去掉多余留白
   ========================================================================== */

/* --- Compact phones ------------------------------------------------ */
@media (max-width: 360px) {
  :root {
    --page-padding-x: 14px;
    --field-gap: 14px;
  }

  .portal__brand {
    padding-top: clamp(16px, 4.5vh, 40px);
  }

  /* On 320px-wide phones every extra gap costs a scroll */
  .portal__spacer {
    flex: 0 0 0;
    min-height: 20px;
  }

  .portal__actions {
    margin-top: 16px;
  }

  .portal__footer {
    padding-top: 20px;
  }

  .portal__title {
    font-size: 16px;
  }

  .portal__subtitle {
    font-size: 12.5px;
    letter-spacing: 0;
  }

  .portal__description {
    font-size: 12.5px;
    line-height: 1.5;
  }

  /* Subtitle + description wrap too much on 320px: give the footer its own row */
  .portal__footer {
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: 12px;
  }

  .portal__footer-version {
    margin-left: 0;
  }

  .status__card {
    padding: 22px 16px 20px;
  }

  .status__icon {
    width: 60px;
    height: 60px;
  }

  .status__message,
  .steps__item {
    font-size: 14.5px;
  }

  .form__submit {
    margin-top: 20px;
  }
}

/* --- Most phones: keep tap targets comfortable ---------------------- */
@media (max-width: 400px) {
  .btn {
    padding: 12px 14px;
    font-size: 15.5px;
    line-height: 1.3;
  }

  /* Long Vietnamese labels wrap onto two lines, keep them centred */
  .btn--outline {
    text-wrap: balance;
  }
}

/* --- Landscape phones: don't squeeze, just let the portal scroll ------- */
@media (max-height: 480px) and (orientation: landscape) {
  .portal__brand {
    padding-top: 12px;
  }

  .portal__emblem {
    width: 72px;
    height: 72px;
  }

  .portal__title {
    margin-top: 12px;
  }

  .portal__description {
    margin: 8px auto 0;
    max-width: 32em;
    font-size: 13px;
  }

  .portal__title {
    font-size: 16px;
  }

  .portal__subtitle {
    margin-top: 4px;
  }

  .portal__spacer {
    flex: 0 0 0;
    min-height: 12px;
  }

  .portal__footer {
    padding-top: 16px;
  }

  .form {
    padding-bottom: calc(16px + var(--safe-bottom));
  }

  .top-bar {
    position: relative;
  }
}

/* --- Tablet / desktop: card look ------------------------------------ */
@media (min-width: 520px) {
  .app--form,
  .app--status {
    display: flex;
    flex-direction: column;
  }

  .portal {
    min-height: 100%;
  }
}
