:root {
  --bg: #eef6f8;
  --card: rgba(255,255,255,.94);
  --ink: #17253b;
  --muted: #74849b;
  --line: #dde8ef;
  --teal: #0eb6a6;
  --teal-dark: #078c87;
  --blue: #1d75e8;
  --violet: #725ee9;
  --danger: #df4664;
  --shadow: 0 10px 30px rgba(34,76,104,.08);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 8% 0%, rgba(28,191,175,.14), transparent 28%),
    radial-gradient(circle at 98% 12%, rgba(39,118,231,.12), transparent 30%),
    linear-gradient(180deg, #f8fcfd 0%, #eef6f8 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 680px);
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 10px max(14px, env(safe-area-inset-bottom));
}

.topbar {
  min-height: 92px;
  padding: 13px 14px;
  border-radius: 22px;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background:
    radial-gradient(circle at 15% 12%, rgba(255,255,255,.22), transparent 18%),
    linear-gradient(120deg, #0b999f 0%, #0fb7a6 54%, #2478e8 126%);
  box-shadow: 0 14px 32px rgba(13,127,145,.18);
  overflow: hidden;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.app-icon {
  width: 48px; height: 48px; border-radius: 14px; object-fit: cover; flex: 0 0 auto;
  box-shadow: 0 7px 18px rgba(8,55,87,.20), inset 0 0 0 1px rgba(255,255,255,.22);
}
.brand-text { min-width: 0; }
.brand-text strong { display: block; font-size: 27px; line-height: 1; letter-spacing: .7px; }
.brand-text span { display: block; margin-top: 4px; font-size: 11px; font-weight: 650; opacity: .92; white-space: nowrap; }
.offline-state {
  flex: 0 0 auto;
  max-width: 142px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.20);
  font-size: 9.5px;
  font-weight: 750;
  line-height: 1.2;
}
.state-dot { width: 6px; height: 6px; border-radius: 50%; background: #dce6ee; flex: 0 0 auto; }
.offline-state.ready .state-dot { background: #caffef; box-shadow: 0 0 0 3px rgba(202,255,239,.12); }
.offline-state.offline .state-dot { background: #ffe28b; }

.panel {
  margin-top: 10px;
  padding: 13px;
  border: 1px solid rgba(216,229,238,.95);
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.section-title { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.section-title h1, .section-title h2 { margin: 0; font-size: 15px; font-weight: 850; }
.compact-title { margin-top: 10px; }
.step {
  width: 25px; height: 25px; border-radius: 9px; display: grid; place-items: center;
  color: #fff; font-size: 11px; font-weight: 900;
  background: linear-gradient(145deg, #0dad9f, #1685dc);
  box-shadow: 0 5px 12px rgba(16,145,163,.18);
}

.wallet-grid, .type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.select-card {
  position: relative;
  border: 1.5px solid #e0e9ef;
  border-radius: 15px;
  background: linear-gradient(180deg, #fff, #fbfdfe);
  color: var(--ink);
  cursor: pointer;
  transition: transform .14s ease, border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
.select-card:active { transform: scale(.985); }
.select-card.active {
  border-color: rgba(14,182,166,.82);
  background: linear-gradient(180deg, #f8fffd, #ebfbf8);
  box-shadow: 0 8px 18px rgba(14,151,145,.11), inset 0 0 0 1px rgba(255,255,255,.65);
}
.select-check {
  position: absolute; top: 6px; right: 6px;
  width: 17px; height: 17px; border-radius: 50%;
  display: grid; place-items: center;
  color: transparent; background: #eef3f6; border: 1px solid #dce6ec;
  font-size: 10px; font-weight: 950;
}
.select-card.active .select-check { color: #fff; background: var(--teal); border-color: transparent; }
.wallet-card {
  min-height: 66px;
  padding: 8px 10px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.wallet-logo { width: 36px; height: 36px; object-fit: contain; filter: drop-shadow(0 3px 7px rgba(33,64,91,.08)); }
.wallet-card strong, .type-card strong { font-size: 13px; font-weight: 850; }
.type-card {
  min-height: 58px;
  padding: 7px 8px;
  display: flex; align-items: center; justify-content: center; gap: 7px;
}
.type-icon {
  width: 31px; height: 31px; border-radius: 10px;
  display: grid; place-items: center; flex: 0 0 auto;
}
.type-icon.friend { color: #079b8f; background: #e7f9f5; }
.type-icon.merchant { color: #6c57db; background: #efecff; }
.type-icon svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.type-card[data-type="merchant"].active { border-color: rgba(114,94,233,.78); background: linear-gradient(180deg, #fdfcff, #f1efff); }
.type-card[data-type="merchant"].active .select-check { background: var(--violet); }

.reveal[hidden] { display: none; }
.reveal.is-entering { animation: revealIn .24s ease both; }
@keyframes revealIn { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: none; } }

.form-reveal { margin-top: 10px; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(92px, .75fr); gap: 8px; }
.field { display: block; min-width: 0; }
.field > span { display: block; margin: 0 3px 5px; font-size: 10.5px; color: #5c6f88; font-weight: 800; }
.field > span em { font-style: normal; color: #99a4b3; font-weight: 600; }
.note-field { grid-column: 1 / -1; }
.input-box {
  min-height: 44px;
  display: flex; align-items: center; gap: 7px;
  padding: 0 10px;
  border: 1.5px solid #dfe8ee;
  border-radius: 13px;
  background: #fbfdfe;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
.input-box:focus-within { border-color: rgba(29,117,232,.55); background: #fff; box-shadow: 0 0 0 3px rgba(29,117,232,.07); }
.input-box svg { width: 17px; flex: 0 0 auto; fill: none; stroke: #74849a; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.input-box input {
  width: 100%; min-width: 0; border: 0; outline: 0; background: transparent;
  color: var(--ink); font-size: 15px; text-align: right;
}
.phone-field input, .amount-field input { direction: ltr; }
.note-field input { direction: rtl; }
.input-box input::placeholder { color: #bac4ce; opacity: 1; }
.error { display: block; min-height: 11px; margin: 3px 3px 0; color: var(--danger); font-size: 9px; }

.code-row {
  margin-top: 2px;
  padding: 7px 9px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 1px dashed #cddce5;
  border-radius: 11px;
  background: #f7fafc;
}
.code-row span { flex: 0 0 auto; font-size: 9.5px; font-weight: 800; color: #8391a4; }
.code-row code { direction: ltr; unicode-bidi: plaintext; min-width: 0; overflow-wrap: anywhere; color: #285477; font-size: 10.5px; }
.call-button {
  width: 100%; min-height: 49px; margin-top: 8px;
  border: 0; border-radius: 14px; cursor: pointer;
  color: #fff;
  background: linear-gradient(105deg, #1c72e8 0%, #1684df 40%, #0dbca6 100%);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 10px 22px rgba(25,118,213,.18), inset 0 1px 0 rgba(255,255,255,.22);
}
.call-button:active { transform: translateY(1px); }
.call-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.call-button strong { font-size: 16px; }

.history-panel { padding: 0; overflow: hidden; }
.history-toggle {
  width: 100%; min-height: 48px; padding: 9px 12px;
  border: 0; background: transparent; color: var(--ink); cursor: pointer;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.history-heading { display: inline-flex; align-items: center; gap: 7px; }
.history-heading > svg { width: 20px; fill: none; stroke: #3974c9; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.history-heading strong { font-size: 13px; }
.history-count {
  min-width: 21px; height: 21px; padding: 0 6px; border-radius: 999px;
  display: inline-grid; place-items: center;
  background: #eef4fb; color: #4e6d91; font-size: 10px; font-weight: 900;
}
.chevron { width: 18px; fill: none; stroke: #7a8ca2; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s ease; }
.history-toggle[aria-expanded="true"] .chevron { transform: rotate(180deg); }
.history-body { padding: 0 11px 11px; border-top: 1px solid #edf2f5; }
.history-tools { min-height: 35px; display: flex; align-items: center; justify-content: space-between; gap: 8px; color: #8a98a9; font-size: 9.5px; }
.clear-history { border: 0; border-radius: 9px; padding: 6px 8px; background: #fff1f4; color: #cf3f5c; font-size: 9.5px; font-weight: 850; cursor: pointer; }
.history-list { display: grid; gap: 6px; }
.history-item {
  padding: 8px;
  border: 1px solid #e7eef2;
  border-radius: 12px;
  background: #fff;
  display: grid; grid-template-columns: 30px minmax(0,1fr) auto; align-items: center; gap: 7px;
}
.history-logo-box { width: 30px; height: 30px; border-radius: 9px; background: #f2f7fa; display: grid; place-items: center; }
.history-logo-box img { width: 22px; height: 22px; object-fit: contain; }
.history-main { min-width: 0; }
.history-top { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.history-top strong { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-amount { margin-right: auto; color: #078d78; font-size: 12px; font-weight: 900; white-space: nowrap; }
.history-meta { margin-top: 2px; color: #8997a8; font-size: 8.8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-note { margin-top: 2px; color: #65758a; font-size: 9.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-actions { display: flex; gap: 4px; }
.history-action {
  width: 29px; height: 29px; border-radius: 9px; border: 1px solid #e4ebf0; background: #f9fbfc;
  display: grid; place-items: center; cursor: pointer;
}
.history-action.call { color: #078e80; background: #effaf7; border-color: #d9f1ea; }
.history-action.delete { color: #d44864; background: #fff3f5; border-color: #f8dfe5; }
.history-action svg { width: 15px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.empty-history { padding: 15px 8px 8px; text-align: center; color: #8b99a9; font-size: 10.5px; }

.footer { padding: 10px 4px 2px; text-align: center; color: #7c8ca0; font-size: 10.5px; }
.footer strong { color: #536980; }
.toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 20;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  min-width: min(84vw, 300px); max-width: 86vw;
  padding: 9px 12px; border-radius: 12px;
  background: rgba(21,37,58,.96); color: #fff; text-align: center;
  font-size: 11px; font-weight: 750; box-shadow: 0 12px 28px rgba(13,28,45,.18);
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 340px) {
  .brand-text span { display: none; }
  .offline-state { max-width: 105px; font-size: 8.5px; }
  .form-grid { grid-template-columns: 1fr; }
  .note-field { grid-column: auto; }
}

@media (min-width: 600px) {
  .app-shell { padding-left: 16px; padding-right: 16px; }
  .topbar { padding: 15px 18px; }
  .panel { padding: 15px; }
  .history-panel { padding: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
