:root {
  --paper: #F5F7F6;
  --surface: #FFFFFF;
  --ink: #15201D;
  --muted: #5E6E69;
  --line: #DCE4E1;
  --buy: #0F6B4E;
  --buy-soft: #E3F1EB;
  --sell: #B4442B;
  --sell-soft: #F7E7E2;
  --escrow: #B7821A;
  --escrow-soft: #F6EEDB;
  --focus: #2F6FDB;
  --on-buy: #FFFFFF;
  --on-sell: #FFFFFF;
  --radius-s: 8px;
  --radius-l: 18px;
  --font: "Noto Sans", "Noto Sans Ethiopic", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --paper: #0E1513;
  --surface: #17211E;
  --ink: #E8EFEC;
  --muted: #93A49E;
  --line: #26332F;
  --buy: #3FB488;
  --buy-soft: #173229;
  --sell: #E27759;
  --sell-soft: #3A2019;
  --escrow: #E0AB45;
  --escrow-soft: #33291A;
  --focus: #7FA8F0;
  --on-buy: #06150F;
  --on-sell: #1A0A05;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
.num { font-variant-numeric: tabular-nums; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
a { color: var(--buy); }

#app { min-height: 100vh; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

/* ---------------------------------------------------------------- header */
.top {
  display: flex; justify-content: space-between; align-items: flex-end;
  padding: 14px 16px 12px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.top-bal { display: flex; flex-direction: column; cursor: pointer; }
.top-label { font-size: 12px; color: var(--muted); }
.top-amt { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.top-amt small { font-size: 13px; font-weight: 600; color: var(--muted); }
.top-escrow { font-size: 12px; color: var(--escrow); font-weight: 600; }
.top-rate { text-align: right; font-size: 12px; color: var(--muted); }
.top-rate strong { display: block; font-size: 15px; color: var(--ink); font-variant-numeric: tabular-nums; }

.banner { margin: 12px 16px 0; padding: 10px 12px; border-radius: var(--radius-s); background: var(--sell-soft); color: var(--sell); font-size: 14px; }

.view { padding: 0 0 16px; }

/* ---------------------------------------------------------------- tabs */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  position: relative; background: none; border: 0; padding: 8px 0 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.active { color: var(--buy); }
.tabs .dot { position: absolute; top: 6px; left: calc(50% + 8px); width: 8px; height: 8px; border-radius: 50%; background: var(--sell); }

/* ---------------------------------------------------------------- layout pieces */
.section { padding: 16px 16px 4px; }
.section h2 { font-size: 18px; margin: 0 0 4px; letter-spacing: -0.01em; }
.section p.lead { margin: 0; color: var(--muted); font-size: 14px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; margin: 14px 16px 0;
  padding: 4px; background: var(--line); border-radius: 12px; }
.seg button { border: 0; border-radius: 9px; padding: 8px 0; background: transparent; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 16px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 500; cursor: pointer; }
.chip.on { border-color: var(--ink); background: var(--ink); color: var(--paper); }

.list { margin: 8px 0 0; background: var(--surface); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.row { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row.tap { cursor: pointer; }
.row-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.row-sub { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 6px; font-size: 13px; color: var(--muted); }
.who { font-weight: 600; }
.who small { font-weight: 400; color: var(--muted); margin-left: 6px; }
.price { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.price small { font-size: 12px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.methods { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.method { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--paper); border: 1px solid var(--line); }

.empty { padding: 40px 24px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }
.empty .btn { margin-top: 16px; width: auto; padding: 10px 20px; }

.status { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; white-space: nowrap; }
.st-wait { background: var(--escrow-soft); color: var(--escrow); }
.st-ok { background: var(--buy-soft); color: var(--buy); }
.st-bad { background: var(--sell-soft); color: var(--sell); }
.st-off { background: var(--paper); color: var(--muted); border: 1px solid var(--line); }

/* ---------------------------------------------------------------- buttons & forms */
.btn { display: block; width: 100%; border: 0; border-radius: 12px; padding: 13px 16px; font-weight: 700; font-size: 15px; cursor: pointer; text-align: center; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-buy { background: var(--buy); color: var(--on-buy); }
.btn-sell { background: var(--sell); color: var(--on-sell); }
.btn-escrow { background: var(--escrow); color: #1D1405; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn-small { width: auto; display: inline-block; padding: 7px 14px; font-size: 13px; border-radius: 9px; }
.btn-link { background: none; border: 0; color: var(--buy); font-weight: 600; padding: 0; cursor: pointer; font-size: 14px; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

.form { padding: 4px 16px 0; }
.field { margin-top: 14px; }
.field label, .field .label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.input { display: flex; align-items: center; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 0 12px; }
.input:focus-within { border-color: var(--focus); }
.input input, .input select, .input textarea { flex: 1; border: 0; background: transparent; padding: 12px 0; min-width: 0; outline: none; font-size: 16px; }
.input textarea { resize: vertical; min-height: 64px; }
.input .unit { color: var(--muted); font-weight: 600; font-size: 14px; margin-left: 8px; }
.input .max { margin-left: 8px; }
.grid2 { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 10px; }
.grid2 > * { min-width: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; cursor: pointer; font-size: 14px; background: var(--surface); }
.check input { accent-color: var(--buy); }
.summary { margin-top: 16px; padding: 12px; border-radius: 12px; background: var(--paper); border: 1px solid var(--line); font-size: 14px; }
.summary div { display: flex; justify-content: space-between; padding: 3px 0; }
.summary div span:last-child { font-weight: 600; font-variant-numeric: tabular-nums; }
.summary .total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; font-size: 15px; }
.err { color: var(--sell); font-size: 13px; margin-top: 8px; min-height: 1em; }

/* ---------------------------------------------------------------- sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(8,14,12,.45); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 92vh; overflow-y: auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 8px 0 calc(20px + env(safe-area-inset-bottom));
  animation: rise .22s ease-out;
}
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 8px; }
.sheet h3 { margin: 4px 16px 0; font-size: 18px; }
.sheet .sub { margin: 2px 16px 0; color: var(--muted); font-size: 14px; }
.sheet .actions { padding: 18px 16px 0; }
@keyframes rise { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }

/* ---------------------------------------------------------------- order ticket (the signature element) */
.ticket-wrap { padding: 16px; }
.ticket { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); overflow: hidden; }
.ticket-head { padding: 18px 18px 16px; }
.ticket-kicker { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.ticket-amount { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 6px; }
.ticket-etb { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.ticket-etb small { font-size: 16px; color: var(--muted); font-weight: 600; margin-left: 4px; }
.ticket-usdt { font-size: 14px; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
.ring { width: 64px; height: 64px; flex: none; position: relative; }
.ring svg { width: 64px; height: 64px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 5; }
.ring .bg { stroke: var(--line); }
.ring .fg { stroke: var(--escrow); stroke-linecap: round; transition: stroke-dashoffset 1s linear; }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ring.late .fg { stroke: var(--sell); }

.perf { position: relative; height: 0; border-top: 2px dashed var(--line); margin: 0 14px; }
.perf::before, .perf::after { content: ""; position: absolute; top: -12px; width: 22px; height: 22px; border-radius: 50%; background: var(--paper); border: 1px solid var(--line); }
.perf::before { left: -26px; }
.perf::after { right: -26px; }

.track { display: grid; grid-template-columns: repeat(3, 1fr); padding: 16px 18px; gap: 6px; }
.step { position: relative; font-size: 12px; color: var(--muted); padding-top: 14px; }
.step::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px; border-radius: 2px; background: var(--line); }
.step.done { color: var(--ink); font-weight: 600; }
.step.done::before { background: var(--buy); }
.step.now { color: var(--escrow); font-weight: 700; }
.step.now::before { background: var(--escrow); }
.step.bad { color: var(--sell); font-weight: 700; }
.step.bad::before { background: var(--sell); }

.ticket-body { padding: 0 18px 18px; }
.note { font-size: 14px; padding: 12px; border-radius: 12px; background: var(--escrow-soft); color: var(--ink); }
.note.good { background: var(--buy-soft); }
.note.bad { background: var(--sell-soft); }
.note strong { display: block; margin-bottom: 2px; }

.payto { margin-top: 14px; border: 1px solid var(--line); border-radius: 12px; }
.payto-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
.payto-row:last-child { border-bottom: 0; }
.payto-row span:first-child { color: var(--muted); }
.payto-row .val { font-weight: 600; text-align: right; word-break: break-all; }
.copy { border: 0; background: var(--paper); border-radius: 6px; padding: 3px 8px; font-size: 12px; font-weight: 600; color: var(--buy); cursor: pointer; margin-left: 6px; }

.ticket-actions { display: grid; gap: 8px; margin-top: 14px; }
.receipt-img { width: 100%; border-radius: 12px; border: 1px solid var(--line); margin-top: 12px; display: block; }
.upload { display: block; border: 1.5px dashed var(--line); border-radius: 12px; padding: 14px; text-align: center; font-size: 14px; color: var(--muted); cursor: pointer; margin-top: 14px; }
.upload input { display: none; }
.upload.has { border-color: var(--buy); color: var(--buy); font-weight: 600; }

/* chat */
.chat { padding: 0 16px; }
.chat h4 { margin: 8px 0 8px; font-size: 15px; }
.msgs { display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 82%; padding: 8px 12px; border-radius: 14px; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.msg time { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.msg.me { align-self: flex-end; background: var(--buy); color: var(--on-buy); border-bottom-right-radius: 4px; }
.msg.me time { color: var(--on-buy); opacity: .75; }
.msg.them { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.system { align-self: center; background: transparent; color: var(--muted); font-size: 12.5px; text-align: center; max-width: 92%; padding: 4px 8px; }
.msg.support { align-self: stretch; max-width: 100%; background: var(--escrow-soft); border-left: 3px solid var(--escrow); border-radius: 8px; }
.composer { display: flex; gap: 8px; margin-top: 10px; }
.composer input { flex: 1; border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; background: var(--surface); font-size: 16px; }

/* wallet */
.bal-block { padding: 18px 16px 6px; }
.bal-big { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.bal-big small { font-size: 16px; color: var(--muted); }
.bal-split { display: flex; gap: 20px; margin-top: 4px; font-size: 13px; color: var(--muted); }
.bal-split b { color: var(--ink); font-variant-numeric: tabular-nums; }
.bal-split .esc b { color: var(--escrow); }
.wallet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px 16px 0; }
.qr { display: block; width: 188px; height: 188px; margin: 16px auto 0; border-radius: 12px; background: #fff; padding: 6px; }
.addr { margin: 14px 16px 0; padding: 12px; border-radius: 12px; background: var(--paper); border: 1px solid var(--line); font-size: 14px; font-weight: 600; word-break: break-all; text-align: center; font-variant-numeric: tabular-nums; }
.warnlist { margin: 14px 16px 0; padding: 0; list-style: none; font-size: 13px; color: var(--muted); }
.warnlist li { padding: 4px 0 4px 16px; position: relative; }
.warnlist li::before { content: ""; position: absolute; left: 2px; top: 11px; width: 6px; height: 6px; border-radius: 50%; background: var(--escrow); }
.warnlist li.red::before { background: var(--sell); }

.amt-in { color: var(--buy); font-weight: 700; }
.amt-out { color: var(--ink); font-weight: 700; }

/* profile */
.profile-head { padding: 20px 16px 8px; display: flex; gap: 14px; align-items: center; }
.avatar { width: 52px; height: 52px; border-radius: 50%; background: var(--buy-soft); color: var(--buy); display: grid; place-items: center; font-weight: 700; font-size: 20px; }
.profile-head h2 { margin: 0; font-size: 19px; }
.profile-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 8px 16px 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.stats div { padding: 12px; text-align: center; border-right: 1px solid var(--line); }
.stats div:last-child { border-right: 0; }
.stats b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--muted); }
.x { border: 0; background: none; color: var(--muted); font-size: 20px; cursor: pointer; padding: 0 4px; line-height: 1; }

/* toast */
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 40;
  background: var(--ink); color: var(--paper); padding: 12px 14px; border-radius: 12px; font-size: 14px; text-align: center; }
.toast.bad { background: var(--sell); color: #fff; }

.skeleton { padding: 18px 16px; color: var(--muted); font-size: 14px; }

@media (min-width: 640px) {
  #app { max-width: 560px; margin: 0 auto; }
  .tabs, .sheet { max-width: 560px; margin: 0 auto; }
}
@media (prefers-reduced-motion: reduce) {
  .sheet { animation: none; }
  .ring .fg { transition: none; }
}
