:root {
  --bg: #0b1220;
  --surface: #141c2f;
  --surface-2: #1b2539;
  --muted: #8898b5;
  --fg: #eef2fb;
  --accent: #34d399;
  --accent-2: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top);
  --safe-bot: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); }
body {
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
  min-height: 100vh;
  padding-bottom: calc(72px + var(--safe-bot));
}

a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.5rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.05rem; margin: 1.25rem 0 0.5rem; color: var(--muted); font-weight: 500; }

.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 0.85rem; }

/* App bar */
.app-bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 0.5rem;
  background: var(--surface);
  padding: calc(var(--safe-top) + 0.5rem) 1rem 0.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.brand { font-weight: 600; letter-spacing: 0.3px; }
.spacer { flex: 1; }
.chip {
  background: var(--surface-2); border-radius: 999px;
  padding: 0.25rem 0.65rem; font-size: 0.8rem; color: var(--muted);
}
.icon-btn {
  background: transparent; color: var(--muted); border: 0;
  width: 36px; height: 36px; border-radius: 10px; font-size: 1.1rem;
}
.icon-btn:hover { background: var(--surface-2); color: var(--fg); }

/* Views */
.view { padding: 1rem; max-width: 560px; margin: 0 auto; }
.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 1.25rem; border: 1px solid rgba(255,255,255,0.04);
}
.hero { padding-top: 2rem; padding-bottom: 2rem; }
.hero .logo {
  font-size: 2.4rem; font-weight: 700; letter-spacing: -0.5px; margin-bottom: 0.5rem;
}

/* Forms */
form { display: flex; flex-direction: column; gap: 0.85rem; margin-top: 0.75rem; }
label {
  display: flex; flex-direction: column; gap: 0.3rem;
  font-size: 0.85rem; color: var(--muted);
}
input, select {
  font: inherit; color: var(--fg);
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px; padding: 0.75rem 0.9rem;
  min-height: 44px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  cursor: pointer;
  font: inherit;
  background: var(--surface-2); color: var(--fg);
  border: 0; border-radius: 10px;
  padding: 0.75rem 1rem; min-height: 44px;
}
button.primary {
  background: var(--accent); color: #052016; font-weight: 600;
}
button.primary:disabled { opacity: 0.6; cursor: wait; }
button.link {
  background: transparent; color: var(--muted);
  padding: 0.4rem 0.6rem; min-height: auto;
}

/* Error + toast */
.error {
  background: rgba(239, 68, 68, 0.15); color: #fecaca;
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 10px; padding: 0.6rem 0.8rem; margin-top: 0.75rem;
}
.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-bot));
  transform: translateX(-50%);
  background: var(--surface-2); color: var(--fg);
  border: 1px solid rgba(255,255,255,0.08);
  padding: 0.7rem 1rem; border-radius: 999px; font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4); z-index: 40;
}

/* Dashboard */
.rail {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem; margin-top: 0.5rem;
}
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 0.3rem;
  padding: 0.9rem 0.4rem; background: var(--surface-2);
}
.tile-emoji { font-size: 1.3rem; }
.quotes { display: grid; grid-template-columns: 1fr; gap: 0.5rem; }
.quote {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface-2); border-radius: 10px; padding: 0.8rem 1rem;
}
.quote .sym { font-weight: 600; }
.quote .price { color: var(--accent); }
.quote .side { color: var(--muted); font-size: 0.8rem; }

/* Trade */
.seg {
  display: flex; background: var(--surface-2);
  border-radius: 999px; padding: 4px; margin: 0.75rem 0;
}
.seg-btn {
  flex: 1; background: transparent; color: var(--muted); border-radius: 999px;
  min-height: 36px; padding: 0 0.75rem;
}
.seg-btn.active { background: var(--accent); color: #052016; font-weight: 600; }

.quote-box {
  background: var(--surface-2); border-radius: 10px; padding: 0.65rem 0.85rem;
  font-size: 0.95rem;
}
.result {
  background: rgba(52, 211, 153, 0.12); color: #86efac;
  border: 1px solid rgba(52, 211, 153, 0.35);
  border-radius: 10px; padding: 0.75rem; margin-top: 0.75rem;
  white-space: pre-wrap; word-break: break-word;
}

/* History / Admin lists */
.list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.6rem; }
.row {
  background: var(--surface-2); border-radius: 10px; padding: 0.75rem 0.9rem;
  display: flex; flex-direction: column; gap: 0.25rem;
}
.row .head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 0.5rem;
}
.row .head strong { font-size: 0.95rem; }
.row .body { font-size: 0.8rem; color: var(--muted); }
.badge {
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.3px;
  padding: 0.15rem 0.5rem; border-radius: 999px; text-transform: uppercase;
}
.b-pending  { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
.b-completed{ background: rgba(52, 211, 153, 0.2); color: #86efac; }
.b-failed   { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.b-approved { background: rgba(52, 211, 153, 0.2); color: #86efac; }
.b-rejected { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.b-default  { background: rgba(136, 152, 181, 0.18); color: var(--muted); }

.row .actions { display: flex; gap: 0.5rem; margin-top: 0.4rem; flex-wrap: wrap; }
.row .actions button { min-height: 36px; padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.row .actions .approve { background: var(--accent); color: #052016; }
.row .actions .reject  { background: var(--danger); color: #fff; }

/* KYC */
.kyc-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin-top: 0.75rem;
}
.kyc-slot {
  background: var(--surface-2); border-radius: 10px; padding: 0.75rem;
  display: flex; flex-direction: column; gap: 0.4rem; min-height: 110px;
}
.slot-label { font-size: 0.85rem; color: var(--muted); }
.slot-label small { color: var(--muted); font-weight: 400; }
.slot-status { font-size: 0.75rem; color: var(--accent); min-height: 1rem; }
input[type="file"] {
  padding: 0.35rem; background: transparent; border: 1px dashed rgba(255,255,255,0.18);
}

/* Tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid rgba(255,255,255,0.06);
  padding-bottom: var(--safe-bot);
  z-index: 10;
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 0.2rem;
  padding: 0.5rem 0.25rem; background: transparent; color: var(--muted);
  font-size: 0.75rem; border-radius: 0;
}
.tab.active { color: var(--accent); }
.tab span:first-child { font-size: 1.15rem; }

.install {
  position: fixed; bottom: calc(84px + var(--safe-bot)); left: 1rem; right: 1rem;
  background: var(--surface-2); color: var(--fg); border-radius: 10px;
  padding: 0.75rem 1rem; display: flex; align-items: center; gap: 0.5rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 30;
}
.install button { min-height: 36px; padding: 0.35rem 0.8rem; }
.install button:not(.link) { background: var(--accent); color: #052016; }

/* Wider screens */
@media (min-width: 720px) {
  .kyc-grid { grid-template-columns: repeat(4, 1fr); }
  .rail { grid-template-columns: repeat(4, 1fr); }
}

/* Balance pill shown above Convert inputs */
.balance-row {
  display: flex; justify-content: space-between; align-items: baseline;
  background: var(--surface-2);
  padding: 0.55rem 0.8rem;
  border-radius: 10px;
  margin-bottom: 0.6rem;
  font-size: 0.92rem;
}
.balance-row .bal-label { color: var(--muted); font-size: 0.8rem; }
.balance-row .bal-value { font-weight: 600; }
.balance-row .bal-after { color: var(--accent); font-weight: 600; }
.balance-row.insufficient .bal-after { color: var(--danger); }

.input-with-max { position: relative; }
.input-with-max input { padding-right: 3.3rem; }
.max-btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: rgba(52, 211, 153, 0.15); color: var(--accent);
  border: 1px solid rgba(52, 211, 153, 0.35);
  padding: 0.18rem 0.55rem; border-radius: 8px;
  font-size: 0.78rem; font-weight: 600; min-height: 28px;
}
.max-btn:active { transform: translateY(-50%) scale(0.96); }

/* ------------- iOS / touch polish ------------- */
html { -webkit-text-size-adjust: 100%; }
body {
  overscroll-behavior-y: contain;           /* no rubber-band on PWA pages */
  -webkit-overflow-scrolling: touch;
  -webkit-tap-highlight-color: transparent; /* kill the grey flash on taps */
  touch-action: manipulation;               /* no 300 ms tap delay */
}
button, .tile, .seg-btn, .tab { touch-action: manipulation; }
input, select, textarea { font-size: 16px; }   /* prevents iOS auto-zoom */

/* ------------- STK-push waiter overlay ------------- */
/* The `hidden` HTML attribute maps to display:none in the UA stylesheet, but
   our `.waiter { display: flex }` below has the same specificity and loads
   later, so without this guard the overlay would show on every page load and
   block interaction (incl. the login form). */
[hidden] { display: none !important; }

.waiter {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 11, 24, 0.72);
  -webkit-backdrop-filter: saturate(1.1) blur(10px);
          backdrop-filter: saturate(1.1) blur(10px);
  z-index: 100;
  padding: calc(var(--safe-top) + 1rem) 1rem calc(var(--safe-bot) + 1rem);
  animation: waiter-in 0.18s ease-out;
}
@keyframes waiter-in { from { opacity: 0 } to { opacity: 1 } }

.waiter-card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 18px;
  padding: 1.5rem 1.25rem;
  text-align: center;
  box-shadow: 0 30px 60px rgba(0,0,0,0.45);
}
.waiter-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.25rem; }
.waiter-sub   { color: var(--muted); font-size: 0.95rem; line-height: 1.35; }
.waiter-hint  { color: var(--muted); font-size: 0.8rem; margin-top: 0.9rem; }

.waiter-spinner {
  width: 68px; height: 68px;
  margin: 0.4rem auto 1rem;
  position: relative;
}
.waiter-spinner::before,
.waiter-spinner::after {
  content: ""; position: absolute; inset: 0;
  border-radius: 50%;
  border: 3px solid transparent;
}
.waiter-spinner::before {
  border-top-color: var(--accent);
  border-right-color: var(--accent);
  animation: spin 0.9s cubic-bezier(0.5, 0.05, 0.4, 0.95) infinite;
}
.waiter-spinner::after {
  border: 2px dashed rgba(52, 211, 153, 0.25);
  animation: spin 3.5s linear infinite reverse;
}
@keyframes spin { to { transform: rotate(360deg); } }

.waiter-steps { display: flex; justify-content: space-between; gap: 0.25rem;
                margin: 1rem 0 0.2rem; font-size: 0.72rem; color: var(--muted); }
.waiter-step { flex: 1; position: relative; padding-top: 0.9rem; }
.waiter-step::before {
  content: ""; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--surface-2);
  outline: 2px solid rgba(255,255,255,0.08);
  transition: background 0.25s, box-shadow 0.25s;
}
.waiter-step.active::before {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.18);
}
.waiter-step.done::before {
  background: var(--accent-2);
}

.waiter-cancel {
  margin-top: 1.1rem;
  background: transparent; color: var(--muted);
  border: 1px solid rgba(255,255,255,0.08);
  padding: 0.45rem 0.9rem; border-radius: 10px;
  min-height: 36px; font-size: 0.85rem;
}

/* ------------- Success bloom toast (fulfillment) ------------- */
.bloom {
  position: fixed; left: 50%; top: 20%;
  transform: translate(-50%, -10px) scale(0.95);
  background: linear-gradient(140deg, #16362a, #1b4b38 60%, #1f6b4f);
  color: #eafff4;
  border: 1px solid rgba(52, 211, 153, 0.35);
  border-radius: 16px;
  padding: 0.9rem 1.2rem;
  box-shadow: 0 20px 40px rgba(0,0,0,0.5), 0 0 0 6px rgba(52, 211, 153, 0.08);
  z-index: 110;
  min-width: 260px; max-width: min(86vw, 420px);
  text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease, transform 0.35s cubic-bezier(0.2, 1.2, 0.4, 1);
}
.bloom.show { opacity: 1; transform: translate(-50%, 0) scale(1); pointer-events: auto; }
.bloom .bloom-title { font-weight: 600; margin-bottom: 0.15rem; }
.bloom .bloom-sub   { font-size: 0.88rem; opacity: 0.92; }
.bloom .bloom-check {
  display: inline-flex; width: 44px; height: 44px; margin-bottom: 0.35rem;
  align-items: center; justify-content: center;
  background: rgba(52, 211, 153, 0.22);
  border-radius: 50%;
  font-size: 1.4rem;
  animation: pop 0.45s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes pop {
  0%   { transform: scale(0.4); opacity: 0; }
  60%  { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}
