:root {
  --navy: #173A69;
  --navy-dark: #0F2647;
  --blue: #1D4ED8;
  --orange: #F7931E;
  --orange-dark: #D97706;
  --bg: #FFFFFF;
  --surface: #F8FAFC;
  --border: #E5E7EB;
  --text: #173A69;
  --text-secondary: #64748B;
  --success: #22C55E;
  --warning: #F59E0B;
  --danger: #EF4444;
  --radius: 24px;
  --radius-sm: 14px;
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 28px rgba(15, 23, 42, 0.12);
  --duration: 220ms;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--surface);
  color: var(--text);
  min-height: 100dvh;
}

/* ---------- Screens & transitions ---------- */
.screen {
  position: relative;
  display: none;
  min-height: 100dvh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  text-align: center;
  gap: 20px;
  background: var(--bg);
  opacity: 0;
  transform: translateY(8px);
}

.screen.active {
  display: flex;
  animation: mfl-screen-in var(--duration) ease forwards;
}

/* Login/Setup screen: card surface, responsive phone -> tablet portrait */
#screen-login { background: var(--surface); }
#screen-login .container {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 32px 24px;
  max-width: 420px;
}
@media (min-width: 600px) {
  #screen-login .container { max-width: 480px; padding: 40px 36px; gap: 22px; }
}
@media (min-width: 900px) {
  #screen-login .container { max-width: 520px; padding: 48px 44px; }
}

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

@media (prefers-reduced-motion: reduce) {
  .screen.active { animation: none; opacity: 1; transform: none; }
}

.screen--survey { justify-content: flex-start; padding-top: 0; gap: 0; }

.container {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

/* ---------- Brand block ---------- */
.brand-block { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.logo { width: 170px; height: auto; }

/* ---------- Illustration ---------- */
.illustration { width: 100%; max-width: 280px; }
.illustration-img { width: 100%; height: auto; display: block; }

h1 { font-size: 1.6rem; margin: 0; font-weight: 800; }
h2 { font-size: 1.4rem; margin: 0; font-weight: 800; }
p { margin: 0; line-height: 1.5; }
.muted { color: var(--text-secondary); }

.card {
  width: 100%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: left;
  box-shadow: var(--shadow);
  transition: box-shadow var(--duration) ease, transform var(--duration) ease;
}
@media (hover: hover) {
  .card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

input[type="text"], input[type="tel"], select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input[type="text"]:focus, input[type="tel"]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(247, 147, 30, 0.18);
}

textarea { resize: vertical; min-height: 80px; }

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }

/* ---------- Buttons + ripple ---------- */
button {
  position: relative;
  overflow: hidden;
  cursor: pointer;
  border: none;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  padding: 16px 24px;
  min-height: 52px;
  width: 100%;
  transition: transform 0.1s ease, opacity 0.2s ease, box-shadow 0.15s ease;
}
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.mfl-ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  transform: scale(0);
  animation: mfl-ripple-anim 550ms ease-out;
  pointer-events: none;
}
@keyframes mfl-ripple-anim {
  to { transform: scale(2.6); opacity: 0; }
}

.btn-primary { background: var(--orange); color: #fff; display: flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 6px 16px rgba(247, 147, 30, 0.3); }
.btn-primary:not(:disabled):hover { background: var(--orange-dark); }

.btn-google {
  background: #1A73E8;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 6px 16px rgba(26, 115, 232, 0.3);
}
.btn-google:not(:disabled):hover { background: #1558B0; }

.google-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
}
.google-icon svg { width: 100%; height: 100%; }

/* ---------- Survey header ---------- */
.survey-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.back-btn {
  width: 40px;
  min-height: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  background: var(--surface);
  color: var(--navy);
  font-size: 1.4rem;
  line-height: 1;
  flex-shrink: 0;
  box-shadow: none;
}
.survey-header-text { text-align: left; }
.survey-header-text h2 { font-size: 1.2rem; }
.screen--survey .container { padding: 20px; max-width: 420px; }

/* ---------- Progress tracker ---------- */
.progress-tracker {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}
.progress-tracker-badge {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--duration) ease;
}
.progress-tracker-bar {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.progress-tracker-fill {
  height: 100%;
  width: 25%;
  background: var(--navy);
  border-radius: 999px;
  transition: width var(--duration) ease;
}
.progress-tracker-label {
  flex-shrink: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.survey-intro {
  width: 100%;
  text-align: left;
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
  margin: -6px 0 0;
}

/* ---------- Questions & choice buttons ---------- */
.question { display: flex; flex-direction: column; gap: 10px; align-items: stretch; text-align: left; }
.question-title { font-weight: 700; font-size: 1rem; }

.choices { display: flex; flex-wrap: nowrap; gap: 5px; width: 100%; }
.choice-btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 56px;
  padding: 8px 3px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text-secondary);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  box-shadow: none;
  white-space: normal;
  word-break: break-word;
  display: flex;
  align-items: center;
  justify-content: center;
}

.choice-btn.selected {
  border-color: var(--navy);
  background: var(--navy);
  color: #fff;
  box-shadow: var(--shadow);
}

/* ---------- Result screens ---------- */
.result-icon-img {
  width: 96px;
  height: 96px;
  display: block;
  animation: mfl-emoji-pop 450ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes mfl-emoji-pop {
  0% { transform: scale(0.4); opacity: 0; }
  70% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .result-icon-img { animation: none; }
}

.done-check { width: 100px; height: 100px; animation: mfl-emoji-pop 450ms cubic-bezier(0.34, 1.56, 0.64, 1); }
.done-check svg { width: 100%; height: 100%; display: block; }

.star-rating { position: relative; display: inline-block; height: 34px; }
.star-rating .stars-back,
.star-rating .stars-front {
  font-size: 1.9rem;
  line-height: 1;
  letter-spacing: 6px;
  white-space: nowrap;
}
.star-rating .stars-back { color: var(--border); }
.star-rating .stars-front {
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
  color: var(--warning);
}

.qr-box {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-box canvas, .qr-box img { display: block; width: 220px; height: 220px; }
.qr-hint { font-size: 0.85rem; color: var(--text-secondary); margin-top: -6px; }

.hint-box,
.countdown-box {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: left;
  opacity: 1;
  transition: opacity 300ms ease;
}
.countdown-box { background: #EFF4FC; }
.countdown-box strong { color: var(--navy); }
.hint-box { background: #EFF4FC; }
.hint-box-icon { flex-shrink: 0; }

.countdown-box.pending-reveal { opacity: 0; }

/* ---------- Buttons: link-style secondary action ("Nanti Saja") ---------- */
.btn-link {
  background: none;
  color: var(--text-secondary);
  width: auto;
  min-height: auto;
  padding: 6px 8px;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: none;
}
.btn-link:hover { color: var(--navy); text-decoration: underline; }

/* ---------- Inline field validation reminder ---------- */
.field-error {
  min-height: 1.1em;
  margin: 6px 0 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--danger);
}
.field-error--tight { min-height: 0; margin: 2px 0 0; }
.field-error--tight:empty { margin: 0; }

.field--inline input.invalid, .field--inline select.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

/* Groups the Nama Anda / Transaksi Anda fields with tight internal
   spacing, separate from the page's larger outer gap between sections. */
.form-fields { display: flex; flex-direction: column; gap: 6px; width: 100%; }
#screen-login .form-fields { padding-left: 10px; }

/* ---------- Inline field: label beside its input, not stacked above ---------- */
.field--inline {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  margin-bottom: 0;
}
.field--inline label {
  flex: 0 0 150px;
  margin-bottom: 0;
  white-space: nowrap;
  font-weight: 700;
}
.field--inline input, .field--inline select { flex: 1; min-width: 0; }

/* ---------- Feedback field (plain, no card surface) ---------- */
.feedback-field { width: 100%; text-align: center; }
.feedback-field label {
  display: block;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
}
.feedback-field textarea { text-align: left; min-height: 96px; }
.feedback-field.hidden-field { display: none; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 999;
  max-width: 90vw;
}
.toast.show { opacity: 1; }

.hidden { display: none !important; }

@media (min-width: 480px) {
  h1 { font-size: 2rem; }
}

/* ---------- Login / Setup screen — official MFlash logo (real image
   asset, served as a normal file — see assets/logo.jpg) ---------- */
.login-logo { display: flex; justify-content: center; }
.login-logo-img { width: 260px; height: auto; }

/* ---------- Welcome screen — smaller logo above the SMILE title ---------- */
.welcome-logo { display: flex; justify-content: center; }
.welcome-logo-img { width: 200px; height: auto; }

/* ---------- Logout / reset-branch button (top-right corner) ---------- */
.logout-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  min-height: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-secondary);
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}
.logout-btn svg { width: 20px; height: 20px; }
.logout-btn:hover { color: var(--danger); background: var(--surface); }

/* ---------- Custom confirmation modal (replaces native window.confirm,
   which can be silently blocked in sandboxed/embedded preview contexts) ---------- */
.confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 2000;
}
.confirm-overlay.show { display: flex; }
.confirm-box {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.confirm-message { font-size: 0.95rem; color: var(--text); line-height: 1.5; margin: 0; }
.confirm-actions { display: flex; gap: 10px; margin-top: 18px; }
.btn-ghost-confirm, .btn-confirm-danger {
  flex: 1;
  min-height: 46px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 700;
  box-shadow: none;
}
.btn-ghost-confirm { background: var(--surface); color: var(--text-secondary); }
.btn-ghost-confirm:hover { background: var(--border); }
.btn-confirm-danger { background: var(--danger); color: #fff; }
.btn-confirm-danger:hover { background: #DC2626; }

/* ---------- Mobile-specific fixes (narrow phone viewports) ---------- */
@media (max-width: 480px) {
  /* 1. Widen the value side of every inline field (Nama Cabang, Nama
     Staff, Nama Anda, No Telepon, Transaksi Anda) — the fixed-width
     label was eating too much space on narrow screens, clipping values
     like branch names. */
  .field--inline label { flex-basis: 92px; font-size: 0.78rem; }

  /* 2. Fit the Welcome screen within a single mobile viewport, no
     scrolling needed. */
  #screen-landing.screen { padding: 56px 20px; gap: 10px; }
  #screen-landing .container { gap: 10px; }
  #screen-landing .welcome-logo-img { width: 130px; }
  #screen-landing .illustration { max-width: 210px; }
  #screen-landing h1 { font-size: 1.25rem; }
  #screen-landing .muted { font-size: 0.85rem; }
  #screen-landing .form-fields { gap: 4px; }

  /* 3. Give question 4's longer choice labels (Tidak Bersedia, Belum
     Bersedia, Sangat Bersedia) enough room to avoid wrapping mid-word. */
  .card { padding: 14px 10px; }
  .choices { gap: 4px; }
  .choice-btn { font-size: 0.6rem; padding: 6px 2px; }
}
