:root {
  --bg: #0b0e14;
  --panel: #131823;
  --panel-2: #1a2130;
  --border: #232c3d;
  --text: #e6edf3;
  --muted: #8b97a7;
  --accent: #f7931a;
  /* bitcoin orange */
  --accent-2: #ffb454;
  --bid: #35c98a;
  --ask: #ff6b6b;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0, 0, 0, .35);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 80% -10%, #16202f 0%, var(--bg)
    60%);
  color: var(--text);
  min-height: 100vh;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: .8rem;
}

.hidden {
  display: none !important;
}

.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--panel-2);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: .82rem;
}

/* ── Top bar ─────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 14, 20, .7);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.brand h1 {
  font-size: 1.15rem;
  margin: 0;
  font-weight: 700;
  letter-spacing: -.02em;
}

.brand .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

.session {
  display: flex;
  align-items: center;
  gap: 12px;
}

.session .who {
  font-size: .85rem;
  color: var(--muted);
}

/* ── Beta disclaimer banner ──────────────────────────────── */
.beta-banner {
  padding: 10px 24px;
  font-size: .85rem;
  line-height: 1.4;
  color: var(--accent-2);
  background: rgba(247, 147, 26, .1);
  border-bottom: 1px solid rgba(247, 147, 26, .3);
  text-align: center;
}

.beta-banner strong {
  color: var(--accent);
}

/* ── Layout: full-screen two-column grid ─────────────────── */
main {
  padding: 18px;
}

.layout {
  display: grid;
  /* left = order book (1fr), right = sidebar (capped at 20em). */
  grid-template-columns: 1fr minmax(0, 20em);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    "book side"
    "orders side";
  gap: 16px;
  height: calc(100vh - 65px - 36px);
  /* viewport − topbar − padding */
}

.book-panel {
  grid-area: book;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar {
  grid-area: side;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  min-height: 0;
}

.my-orders-panel {
  grid-area: orders;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card.narrow {
  max-width: 520px;
}

/* Login-gated cards are hidden until authenticated (see body.authed). */
.card.authed {
  display: none;
}

body.authed .card.authed {
  display: flex;
  flex-direction: column;
}

body.authed #signin-cta {
  display: none;
}

/* my-orders panel keeps its own flex layout */
body.authed .my-orders-panel.authed {
  display: flex;
}

/* Balance actions (deposit / withdraw) stack on narrow screens. */
.bal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Fallback pool fields, nested inside the Sell panel. */
#fallback-fields {
  border-top: 1px solid var(--border);
  margin-top: 0.75rem;
  padding-top: 0.75rem;
}

/* Sign-in call to action */
.cta h2 {
  margin: 0 0 6px;
}

.cta p {
  margin: 0 0 14px;
}

.card h2 {
  margin: 0 0 14px;
  font-size: 1.05rem;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-head h2 {
  margin: 0;
}

.btn.icon {
  font-size: 1rem;
  line-height: 1;
  padding: 6px 9px;
}

/* Responsive: stack into one column, natural height. */
@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas: "side" "book" "orders";
    height: auto;
  }

  .sidebar {
    overflow: visible;
  }

  .book-panel {
    min-height: 50vh;
  }
}

/* ── Fields / buttons ────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field > span {
  font-size: .8rem;
  color: var(--muted);
}

input,
textarea,
select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .9rem;
  width: 100%;
  font-family: inherit;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: .88rem;
  font-weight: 600;
  transition: filter .12s, transform .05s;
}

.btn:hover {
  filter: brightness(1.15);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1200;
}

.btn.ghost {
  background: transparent;
}

.btn.small {
  padding: 6px 10px;
  font-size: .78rem;
}

.btn.block {
  width: 100%;
  margin-top: 4px;
}

/* ── Account ─────────────────────────────────────────────── */
.kv {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.kv > span {
  font-size: .75rem;
  color: var(--muted);
}

.kv code {
  flex: 1;
  min-width: 0;
}

.bal-main {
  margin-bottom: 12px;
}

.bal-big {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 2px;
}

.bal-big strong {
  font-size: 1.8rem;
  font-variant-numeric: tabular-nums;
}

.bal-big em {
  font-size: .75rem;
  color: var(--muted);
  font-style: normal;
}

.bal-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.bal-row strong {
  display: block;
  font-size: .95rem;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

/* ── Segments (buy/sell) ─────────────────────────────────── */
.seg {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

.segbtn {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 9px;
  border-radius: 8px;
  cursor: pointer;
  font-size: .85rem;
  font-weight: 700;
}

.segbtn.active {
  color: #1a1200;
}

.segbtn[data-side="buy"].active {
  background: var(--bid);
  border-color: var(--bid);
}

.segbtn[data-side="sell"].active {
  background: var(--ask);
  border-color: var(--ask);
}

/* ── ETA box ─────────────────────────────────────────────── */
.eta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
}

.eta strong {
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

.eta.warn {
  border-color: var(--ask);
}

.eta.warn strong {
  color: var(--ask);
}

/* ── Amount chips ────────────────────────────────────────── */
.chips {
  display: flex;
  gap: 6px;
  margin: -4px 0 12px;
}

.chip {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 7px;
  border-radius: 8px;
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
}

.chip:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* ── Login modal ─────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 6, 10, .72);
  backdrop-filter: blur(3px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text);
}

/* ── Connect prompt (client-initiated nostrconnect) ──────── */
.connect-prompt {
  margin-top: 16px;
  padding: 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.qr {
  background: #fff;
  padding: 10px;
  border-radius: 8px;
  line-height: 0;
}

.qr img,
.qr canvas,
.qr svg {
  display: block;
  width: 200px;
  height: 200px;
}

.uri-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.uri-row code {
  flex: 1;
}

.advanced {
  margin-top: 18px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.advanced summary {
  cursor: pointer;
  color: var(--muted);
  font-size: .85rem;
  list-style: none;
  user-select: none;
}

.advanced summary::-webkit-details-marker {
  display: none;
}

.advanced summary::before {
  content: "▸ ";
}

.advanced[open] summary::before {
  content: "▾ ";
}

.advanced .field {
  margin-top: 12px;
}

/* ── Deposit sheet ───────────────────────────────────────── */
.invoice-amount {
  text-align: center;
  margin: 14px 0 6px;
}

.invoice-amount strong {
  font-size: 1.6rem;
  font-variant-numeric: tabular-nums;
}

.invoice-amount em {
  color: var(--muted);
  font-style: normal;
  font-size: .8rem;
}

#dep-qr {
  margin: 8px auto 0;
  width: max-content;
}

.poll {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  color: var(--accent-2);
  font-size: .85rem;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.poll.ok {
  color: var(--bid);
}

.poll.ok .spinner {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Bottom-sheet behaviour on mobile */
.sheet-card {
  max-width: 420px;
}

@media (max-width: 600px) {
  .modal.sheet {
    align-items: flex-end;
    padding: 0;
  }

  .sheet-card {
    max-width: 100%;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    animation: sheet-up .25s ease;
  }

  @keyframes sheet-up {
    from {
      transform: translateY(100%);
    }

    to {
      transform: translateY(0);
    }
  }
}

/* ── Order book ──────────────────────────────────────────── */
.book {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  flex: 1;
  min-height: 0;
}

.book-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.book-title {
  font-size: .8rem;
  font-weight: 700;
  padding: 0 6px 8px;
}

.book-title.bid {
  color: var(--bid);
}

.book-title.ask {
  color: var(--ask);
}

/* Column tracks defined once on .book-grid; header + rows reuse them via subgrid. */
.book-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-auto-rows: min-content;
  overflow-y: auto;
  flex: 1;
  font-size: .85rem;
}

.book-colhead,
.book-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  border-bottom: 1px solid var(--border);
}

.book-colhead {
  position: sticky;
  top: 0;
  background: var(--panel);
  font-size: .75rem;
  font-weight: 500;
}

.book-colhead > span,
.book-row > span {
  padding: 6px;
  font-variant-numeric: tabular-nums;
}

.book-colhead > span:last-child,
.book-row > span:last-child {
  text-align: right;
}

#bids .price {
  color: var(--bid);
}

#asks .price {
  color: var(--ask);
}

.book-rows {
  display: contents;
}

.book-grid .empty {
  grid-column: 1 / -1;
  color: var(--muted);
  text-align: center;
  padding: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}

th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: .75rem;
  padding: 4px 6px;
}

td {
  padding: 6px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

/* ── My orders ───────────────────────────────────────────── */
.table-wrap {
  overflow: auto;
  flex: 1;
  min-height: 0;
}

table.orders td {
  font-variant-numeric: tabular-nums;
}

table.orders th {
  position: sticky;
  top: 0;
  background: var(--panel);
}

/* Empty-orders state: centered, no table borders, breathing room. */
.orders .empty-row td {
  border: none;
  padding: 0;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
  line-height: 1.5;
}

/* Seller connection instructions block. */
.connect-steps {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.connect-steps h3 {
  margin: 0 0 6px;
  font-size: .95rem;
}

.connect-steps .kv {
  margin-top: 8px;
}

/* Readonly field + copy button rows. */
.copy-field {
  margin-bottom: 10px;
}

.copy-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
}

.copy-row input[readonly] {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .8rem;
  cursor: text;
  background: var(--bg, #0e0e10);
}

.copy-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.pill {
  font-size: .72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.pill.buy {
  color: var(--bid);
}

.pill.sell {
  color: var(--ask);
}

/* ── Status / toast ──────────────────────────────────────── */
.status {
  font-size: .8rem;
  margin: 8px 0 0;
  min-height: 1em;
}

.status.ok {
  color: var(--bid);
}

.status.err {
  color: var(--ask);
}

.status.pending {
  color: var(--accent-2);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 50;
  font-size: .85rem;
}

.toast.err {
  border-color: var(--ask);
}

.toast.ok {
  border-color: var(--bid);
}

/* Inline hint under a form field (e.g. accepted pool address formats). */
.field small.muted {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.78rem;
  line-height: 1.4;
}

.field small.muted code {
  background: var(--panel, rgba(255, 255, 255, 0.05));
  border-radius: 3px;
  padding: 0 0.25rem;
}
