:root {
  color-scheme: dark;
  --bg: #07111f;
  --surface: #0d1d2f;
  --surface-2: #122840;
  --line: #203c58;
  --text: #f5f8fc;
  --muted: #8fa9c3;
  --blue: #2d94ff;
  --blue-2: #146fd1;
  --green: #3ed59a;
  --red: #ff7180;
  --amber: #ffc45d;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { padding-bottom: 86px; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted, .small { color: var(--muted); }
.small { display: block; font-size: 12px; line-height: 1.4; }
.app { width: min(100%, 660px); margin: 0 auto; padding: 18px 16px 30px; }

.header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.brand { display: flex; align-items: center; gap: 11px; font-size: 21px; font-weight: 850; }
.logo { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 14px; background: linear-gradient(145deg, #49aeff, #156ed2); box-shadow: 0 9px 25px #0d67bd55; }
.chip, .verified, .demo-chip, .side-chip, .status { display: inline-flex; align-items: center; border-radius: 999px; white-space: nowrap; }
.chip { padding: 7px 10px; font-size: 11px; font-weight: 750; }
.chip.neutral { color: var(--amber); background: #5c431f77; }
.chip.success { color: var(--green); background: #14503f88; }
.chip.danger { color: var(--red); background: #5c293088; }

.screen { display: none; animation: appear .2s ease; }
.screen.active { display: block; }
@keyframes appear { from { opacity: 0; transform: translateY(4px); } }
h1, h2, p { margin: 0; }
h1 { font-size: 27px; line-height: 1.12; }
h2 { font-size: 18px; margin-top: 2px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin: 22px 0 14px; }
.section-head p { color: var(--muted); margin-top: 5px; font-size: 14px; }

.card { background: linear-gradient(145deg, #102239, #0b1a2b); border: 1px solid var(--line); border-radius: 20px; padding: 17px; box-shadow: 0 18px 40px #0002; }
.market-hero { display: flex; justify-content: space-between; align-items: center; gap: 18px; background: radial-gradient(circle at right top, #1b70b955, transparent 55%), var(--surface); }
.reference { margin-top: 5px; }
.reference strong { font-size: 27px; }
.reference span { color: var(--muted); }
.source-link { color: #75bdff; text-decoration: none; font-size: 13px; }
.icon-button { width: 38px; height: 38px; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; font-size: 20px; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); padding: 4px; gap: 3px; border-radius: 14px; background: #06101d; border: 1px solid #142c43; margin-bottom: 14px; }
.segmented button { padding: 10px 5px; color: var(--muted); background: transparent; border: 0; border-radius: 10px; font-size: 13px; font-weight: 700; }
.segmented button.active { color: var(--text); background: var(--surface-2); }
.stack { display: grid; gap: 13px; }
.empty { display: grid; gap: 6px; text-align: center; padding: 34px 20px; }

.offer-head, .trade-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.maker { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 auto; border-radius: 50%; color: #07111f; background: #8ecbff; font-weight: 900; }
.maker-name { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.verified, .demo-chip { padding: 3px 6px; font-size: 9px; font-weight: 850; }
.verified { color: var(--green); background: #154d3c; }
.demo-chip { color: var(--amber); background: #4e3b20; }
.side-chip, .status { padding: 6px 9px; font-size: 10px; font-weight: 800; }
.side-chip.sell { color: #70c8ff; background: #174266; }
.side-chip.buy { color: #6be1ad; background: #174c3b; }
.offer-rate { display: flex; flex-wrap: wrap; align-items: baseline; margin: 18px 0; }
.offer-rate > strong { font-size: 25px; }
.deviation { width: 100%; color: var(--amber); font-size: 11px; margin-top: 4px; }
.deviation.near { color: var(--green); }
.offer-details { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 15px; }
.offer-details > div { display: grid; gap: 4px; padding: 9px; background: #081625; border-radius: 11px; }
.offer-details strong { font-size: 12px; }

.primary, .secondary { min-height: 49px; border-radius: 14px; border: 0; padding: 12px 15px; font-weight: 850; }
.primary { color: white; background: linear-gradient(135deg, var(--blue), #1ba6f2); box-shadow: 0 8px 24px #137bd23a; }
.primary:active { background: var(--blue-2); }
.secondary { color: var(--text); background: #142a42; border: 1px solid #294761; }
.full-width { width: 100%; }

.form-grid { display: grid; gap: 15px; }
label { display: grid; gap: 7px; color: #b4c8da; font-size: 13px; font-weight: 650; }
input, select { width: 100%; min-height: 49px; border: 1px solid #25435f; border-radius: 13px; padding: 11px 13px; background: #081522; color: var(--text); outline: 0; }
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #2d94ff22; }
.two-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-note { font-size: 11px; color: var(--muted); }
.fee-box, .warning-box, .instruction { display: grid; gap: 5px; border-radius: 14px; padding: 13px; }
.fee-box { background: #143050; color: #b9ddff; }
.fee-box span, .warning-box span, .instruction span { font-size: 12px; line-height: 1.45; }
.warning-box { margin-bottom: 13px; background: #4b292f; border: 1px solid #7f3c48; color: #ffc6cc; }
.consent { grid-template-columns: 22px 1fr; align-items: start; }
.consent input { min-height: auto; width: 18px; height: 18px; }
.profile-summary { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 13px; }
.profile-summary > div { display: grid; gap: 5px; }

.trade-head > div { display: grid; gap: 3px; }
.status { color: #b9ddff; background: #173a5d; }
.status.completed { color: var(--green); background: #154d3c; }
.status.disputed, .status.cancelled { color: #ffabb4; background: #54272e; }
.trade-amount { margin: 17px 0 12px; font-size: 20px; font-weight: 900; }
.summary-list { display: grid; gap: 0; }
.summary-list > div { display: flex; justify-content: space-between; gap: 18px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.summary-list > div:last-child { border-bottom: 0; }
.summary-list.compact { color: var(--muted); font-size: 12px; }
.summary-list strong { color: var(--text); text-align: right; }
.instruction { margin: 12px 0; background: #122d48; color: #c7e5ff; }
.counterparty { color: var(--muted); font-size: 12px; margin: 11px 0; }
.counterparty summary { cursor: pointer; }
.counterparty-data { display: grid; gap: 5px; margin-top: 9px; padding: 10px; background: #081522; border-radius: 10px; word-break: break-word; }
.trade-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }

.tabs { position: fixed; z-index: 20; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 660px); display: grid; grid-template-columns: repeat(4, 1fr); background: #071320ed; border-top: 1px solid #1c3852; backdrop-filter: blur(14px); padding: 7px 7px calc(7px + env(safe-area-inset-bottom)); }
.tab { display: grid; place-items: center; gap: 2px; min-height: 55px; border: 0; border-radius: 12px; color: var(--muted); background: transparent; font-size: 10px; }
.tab strong { font-size: 18px; }
.tab.active { color: #4eaeff; background: #12273b; }

.modal { position: fixed; z-index: 50; inset: 0; display: none; align-items: flex-end; justify-content: center; padding: 16px; background: #020811bb; backdrop-filter: blur(5px); }
.modal.visible { display: flex; }
.modal-card { width: min(100%, 500px); background: #0d1e31; border: 1px solid #2a4964; border-radius: 22px; padding: 20px; box-shadow: 0 25px 80px #0009; }
.modal-title { font-size: 23px; font-weight: 900; margin-bottom: 7px; }
.modal-field { margin: 17px 0 5px; }
.modal-card .primary { width: 100%; margin-top: 12px; }
.modal-card .secondary { margin-top: 8px; }
.toast { position: fixed; z-index: 80; left: 50%; bottom: 90px; transform: translate(-50%, 20px); width: min(calc(100% - 32px), 520px); padding: 13px 15px; border-radius: 13px; color: white; background: #187550; box-shadow: 0 15px 45px #0007; opacity: 0; pointer-events: none; transition: .2s ease; text-align: center; font-size: 13px; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #a63b4b; }
.auth-error { display: grid; gap: 6px; max-width: 660px; margin: 40px auto; padding: 20px; color: #ffc7ce; background: #4b292f; border: 1px solid #8c4651; border-radius: 16px; }

/* Admin */
body.admin-page { padding: 0; }
.admin-shell { width: min(calc(100% - 32px), 1180px); margin: 0 auto; padding: 28px 0 60px; }
.admin-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.admin-title { display: flex; align-items: center; gap: 12px; }
.admin-title h1 { font-size: 30px; }
.admin-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 18px; }
.metric { padding: 15px; background: var(--surface); border: 1px solid var(--line); border-radius: 15px; }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 7px; font-size: 22px; }
.panel { margin-top: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 18px; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 15px; }
.rate-controls { display: grid; grid-template-columns: minmax(160px, 240px) auto auto; align-items: end; gap: 8px; }
.rate-controls button { min-height: 49px; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 800px; }
.data-table th, .data-table td { padding: 11px 9px; border-bottom: 1px solid var(--line); text-align: left; font-size: 12px; vertical-align: top; }
.data-table th { color: var(--muted); }
.data-table select { min-height: 36px; padding: 6px 8px; font-size: 12px; }
.login-card { width: min(calc(100% - 32px), 430px); margin: 12vh auto; }

@media (max-width: 780px) {
  .admin-grid { grid-template-columns: repeat(2, 1fr); }
  .rate-controls { grid-template-columns: 1fr; }
}
@media (max-width: 390px) {
  .app { padding-inline: 12px; }
  .two-columns { grid-template-columns: 1fr; }
  .offer-details { grid-template-columns: 1fr 1fr; }
  .chip { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
}
