/* KaranistaPay — Payment Page Styles
 * v2 Update 2026-04-22: Phase 18b — Mobile-first, Swahili-first, 3G-fast.
 * v2 Update 2026-05-06: Phase E polish — adds .topbar-actions / .lang-toggle
 * (SW · EN switcher), .krn-ref-strip (promoted bill reference at the top
 * of the merchant card), and a 360px-and-below block that tightens
 * paddings + topbar gaps for the smallest viewports (320px / iPhone SE
 * gen-1).
 * Target: any smartphone browser, Tanzanian mobile networks.
 * Tap targets: minimum 48px. Fonts: system stack (zero download weight).
 */

/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green:       #1a8f5a;
  --green-dark:  #136b44;
  --green-light: #e8f5ee;
  --orange:      #e07b00;
  --red:         #c0392b;
  --grey-bg:     #f5f6f8;
  --grey-border: #dde1e7;
  --grey-text:   #6b7280;
  --black:       #111827;
  --white:       #ffffff;
  --radius:      12px;
  --shadow:      0 2px 12px rgba(0,0,0,0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  background: var(--grey-bg);
  color: var(--black);
  min-height: 100vh;
  padding-bottom: 32px;
}

/* ── Page wrapper ──────────────────────────────────────────────────────────── */
.page {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ── Top bar ───────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 10px;
  border-bottom: 1px solid var(--grey-border);
  margin-bottom: 16px;
}

.topbar-logo {
  height: 28px;
  width: auto;
}

.topbar-brand {
  font-size: 13px;
  color: var(--grey-text);
  letter-spacing: 0.3px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-secure {
  font-size: 11px;
  color: var(--green);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Language toggle (SW · EN) ─────────────────────────────────────────────── */
.lang-toggle {
  background: var(--white);
  border: 1px solid var(--grey-border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--green-dark);
  cursor: pointer;
  min-height: 32px;
  min-width: 36px;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, background 0.15s;
}

.lang-toggle:active {
  border-color: var(--green);
  background: var(--green-light);
}

/* ── Card ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
}

.card-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--grey-bg);
}

.card-body {
  padding: 16px 20px;
}

/* ── Merchant info ─────────────────────────────────────────────────────────── */
.merchant-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.merchant-avatar {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: var(--green-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  overflow: hidden;
}

.merchant-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
}

.merchant-name {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
}

.merchant-location {
  font-size: 13px;
  color: var(--grey-text);
  margin-top: 2px;
}

/* ── Bill header ───────────────────────────────────────────────────────────── */
.bill-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--grey-text);
  margin-bottom: 4px;
}

.customer-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

.customer-name {
  font-size: 19px;
  font-weight: 700;
  color: var(--black);
}

.customer-badge {
  background: var(--green-light);
  color: var(--green-dark);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  letter-spacing: 0.3px;
}

.bill-description {
  font-size: 13px;
  color: var(--grey-text);
}

/* ── KaranistaRef strip (promoted bill reference) ──────────────────────────── */
/* Sits at the bottom of the merchant card so the customer can read the
 * reference back to the merchant over the phone without scrolling to
 * the USSD fallback section. */
.krn-ref-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 20px;
  background: var(--green-light);
  border-top: 1px solid #cfe7d9;
}

.krn-ref-info {
  min-width: 0;
  flex: 1;
}

.krn-ref-label {
  font-size: 11px;
  color: var(--green-dark);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  margin-bottom: 2px;
}

.krn-ref-value {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--black);
  font-variant-numeric: tabular-nums;
  word-break: break-all;
  line-height: 1.25;
}

/* ── Items list ────────────────────────────────────────────────────────────── */
.items-list {
  list-style: none;
}

.item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--grey-bg);
  gap: 8px;
}

.item-row:last-child {
  border-bottom: none;
}

.item-name {
  font-size: 14px;
  flex: 1;
}

.item-qty {
  font-size: 12px;
  color: var(--grey-text);
  white-space: nowrap;
}

.item-price {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  text-align: right;
  min-width: 80px;
}

/* ── Total row ─────────────────────────────────────────────────────────────── */
.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: var(--green-light);
  border-top: 2px solid var(--green);
}

.total-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--green-dark);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.total-amount {
  font-size: 24px;
  font-weight: 800;
  color: var(--green-dark);
  letter-spacing: -0.5px;
}

/* ── Expiry countdown ──────────────────────────────────────────────────────── */
.expiry-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: #fffbf0;
  border-top: 1px solid #fde68a;
  font-size: 13px;
  color: var(--orange);
  font-weight: 500;
}

.expiry-icon {
  font-size: 16px;
  flex-shrink: 0;
}

/* ── Payment methods ───────────────────────────────────────────────────────── */
.section-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--grey-text);
  margin-bottom: 12px;
}

.methods-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.method-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 8px;
  border: 2px solid var(--grey-border);
  border-radius: 10px;
  background: var(--white);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--black);
  min-height: 72px;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.method-btn:active,
.method-btn.selected {
  border-color: var(--green);
  background: var(--green-light);
  color: var(--green-dark);
}

.method-icon {
  font-size: 24px;
  line-height: 1;
}

/* ── Phone input panel ─────────────────────────────────────────────────────── */
.phone-panel {
  display: none;
  margin-top: 8px;
}

.phone-panel.visible {
  display: block;
}

.phone-label {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--black);
}

.phone-note {
  font-size: 12px;
  color: var(--grey-text);
  margin-bottom: 8px;
}

.phone-input-row {
  display: flex;
  gap: 8px;
}

.phone-prefix {
  background: var(--grey-bg);
  border: 2px solid var(--grey-border);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--grey-text);
  display: flex;
  align-items: center;
  white-space: nowrap;
  flex-shrink: 0;
}

.phone-input {
  flex: 1;
  border: 2px solid var(--grey-border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 1px;
  outline: none;
  min-height: 52px;
  -webkit-appearance: none;
}

.phone-input:focus {
  border-color: var(--green);
}

/* ── PKR amount form (Phase F Round 1) ─────────────────────────────────────── */
/* Shown only when projection.kind === "pkr". Replaces the fixed-total card
 * for the customer-types-amount flow (debt / installment / akiba / rental
 * payments — the "lipa kiasi gani?" experience the spec §1.3 mandates). */
.pkr-amount-panel {
  display: none;
  margin-top: 12px;
  padding: 14px 14px 12px;
  background: #fffaf2;
  border: 1px solid #ffe2bd;
  border-radius: 12px;
}

.pkr-amount-panel.visible {
  display: block;
}

.pkr-amount-hint {
  font-size: 12px;
  color: var(--grey-text);
  margin: 4px 0 10px;
  line-height: 1.4;
}

.pkr-amount-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.pkr-amount-prefix {
  background: var(--grey-bg);
  border: 2px solid var(--grey-border);
  border-radius: 10px;
  padding: 0 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--grey-text);
  display: flex;
  align-items: center;
  white-space: nowrap;
  flex-shrink: 0;
}

.pkr-amount-input {
  flex: 1;
  border: 2px solid var(--grey-border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.5px;
  outline: none;
  min-height: 56px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  -webkit-appearance: none;
}

.pkr-amount-input:focus {
  border-color: #ff6b00;
  background: #fff;
}

.pkr-quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.pkr-quick-chip {
  flex: 1 1 auto;
  min-width: 64px;
  background: #fff;
  border: 1.5px solid #ffd9a8;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  color: #8a4a00;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.pkr-quick-chip:hover {
  background: #fff1de;
}

.pkr-quick-chip:active {
  background: #ffe2bd;
}

.pkr-quick-chip-all {
  background: #ff6b00;
  border-color: #ff6b00;
  color: #fff;
}

.pkr-quick-chip-all:hover {
  background: #e55c00;
}

.pkr-amount-error {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--red);
  line-height: 1.4;
}

.pkr-amount-error.hidden {
  display: none;
}

/* ── Pay button ────────────────────────────────────────────────────────────── */
.pay-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 16px;
  background: var(--green);
  color: var(--white);
  border: none;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  min-height: 56px;
  margin-top: 14px;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}

.pay-btn:active {
  background: var(--green-dark);
}

.pay-btn:disabled {
  background: #9ca3af;
  cursor: not-allowed;
}

.pay-btn-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}

.pay-btn.loading .pay-btn-spinner { display: block; }
.pay-btn.loading .pay-btn-text { opacity: 0.7; }

/* ── Waiting state ─────────────────────────────────────────────────────────── */
.waiting-panel {
  display: none;
  text-align: center;
  padding: 24px 16px;
}

.waiting-panel.visible {
  display: block;
}

.waiting-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--green-light);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 0 auto 16px;
}

.waiting-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 6px;
}

.waiting-subtitle {
  font-size: 14px;
  color: var(--grey-text);
  line-height: 1.5;
}

/* ── Success state ─────────────────────────────────────────────────────────── */
.success-panel {
  display: none;
  text-align: center;
  padding: 24px 16px;
}

.success-panel.visible {
  display: block;
}

.success-icon {
  width: 72px;
  height: 72px;
  background: var(--green);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  margin: 0 auto 16px;
  animation: pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.success-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--green-dark);
  margin-bottom: 6px;
}

.success-subtitle {
  font-size: 15px;
  color: var(--grey-text);
  line-height: 1.5;
}

.success-ref {
  margin-top: 16px;
  background: var(--grey-bg);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13px;
  color: var(--grey-text);
}

.success-ref strong {
  color: var(--black);
  display: block;
  font-size: 15px;
  margin-bottom: 2px;
}

/* ── Error state ───────────────────────────────────────────────────────────── */
.error-panel {
  display: none;
  text-align: center;
  padding: 24px 16px;
}

.error-panel.visible {
  display: block;
}

.error-icon {
  font-size: 52px;
  margin-bottom: 12px;
}

.error-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--red);
  margin-bottom: 6px;
}

.error-msg {
  font-size: 14px;
  color: var(--grey-text);
  line-height: 1.5;
  margin-bottom: 16px;
}

.retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 12px 24px;
  background: var(--white);
  border: 2px solid var(--grey-border);
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--black);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ── USSD fallback section ─────────────────────────────────────────────────── */
.ussd-section {
  margin-top: 4px;
}

.ussd-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.ussd-divider-line {
  flex: 1;
  height: 1px;
  background: var(--grey-border);
}

.ussd-divider-text {
  font-size: 12px;
  color: var(--grey-text);
  white-space: nowrap;
  font-weight: 500;
}

.ussd-instruction {
  font-size: 13px;
  color: var(--grey-text);
  line-height: 1.5;
  margin-bottom: 10px;
}

.ussd-ref-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--grey-bg);
  border: 1px solid var(--grey-border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
  gap: 8px;
}

.ussd-ref-info {}

.ussd-ref-label {
  font-size: 11px;
  color: var(--grey-text);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.ussd-ref-value {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--black);
  font-variant-numeric: tabular-nums;
}

.copy-btn {
  background: var(--white);
  border: 1px solid var(--grey-border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--green-dark);
  flex-shrink: 0;
  min-height: 36px;
  -webkit-tap-highlight-color: transparent;
}

.copy-btn.copied {
  color: var(--green);
  border-color: var(--green);
}

/* ── Footer ────────────────────────────────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 16px 0 4px;
  font-size: 12px;
  color: var(--grey-text);
  line-height: 1.6;
}

.footer-logos {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
}

.footer-lock {
  font-size: 14px;
}

/* ── Loading skeleton ──────────────────────────────────────────────────────── */
.skeleton-loading {
  display: block;
  background: linear-gradient(90deg, #e8e8e8 25%, #f5f5f5 50%, #e8e8e8 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
  height: 1em;
  margin-bottom: 6px;
}

/* ── Animations ────────────────────────────────────────────────────────────── */
@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pop {
  0%   { transform: scale(0); }
  80%  { transform: scale(1.1); }
  100% { transform: scale(1); }
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Utility ───────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }

/* ── Small-viewport sweep (≤360px — iPhone SE gen-1, Android Go) ──────────── */
/* Mobile-first base already accommodates 375px+ comfortably; this block
 * tightens paddings + topbar gaps for the smallest live phones (320px /
 * iPhone SE gen-1 / older Android Go devices) so nothing overflows or
 * wraps awkwardly. */
@media (max-width: 360px) {
  .page              { padding: 0 12px; }
  .topbar            { padding: 12px 0 8px; }
  .topbar-actions    { gap: 6px; }
  .lang-toggle       { padding: 6px 8px; min-width: 32px; }
  .topbar-secure     { font-size: 10px; }
  .topbar-secure span:first-child { font-size: 12px; }

  .card-header       { padding: 14px 16px 10px; }
  .card-body         { padding: 14px 16px; }
  .total-row         { padding: 12px 16px; }
  .expiry-bar        { padding: 9px 16px; }
  .krn-ref-strip     { padding: 10px 16px; }
  .krn-ref-value     { font-size: 15px; letter-spacing: 0.5px; }

  .merchant-name     { font-size: 16px; }
  .customer-name     { font-size: 18px; }
  .total-amount      { font-size: 22px; letter-spacing: -0.4px; }

  .methods-grid      { gap: 8px; }
  .method-btn        { min-height: 68px; padding: 12px 6px; font-size: 12px; }
  .method-icon       { font-size: 22px; }

  .phone-input-row   { gap: 6px; }
  .phone-prefix      { padding: 0 10px; font-size: 14px; }
  .phone-input       { padding: 11px 12px; font-size: 17px; }

  .pkr-amount-panel  { padding: 12px 12px 10px; }
  .pkr-amount-row    { gap: 6px; }
  .pkr-amount-prefix { padding: 0 10px; font-size: 14px; }
  .pkr-amount-input  { padding: 11px 12px; font-size: 19px; min-height: 50px; }
  .pkr-quick-chip    { padding: 6px 10px; font-size: 12px; min-width: 56px; }

  .pay-btn           { padding: 14px; font-size: 16px; min-height: 52px; }
}
