/* css/app.css (owner: chain): the /app page, plus the page shell shared by /index and /dividends.
   Tokens, fonts and components come from css/base.css; everything here is page-specific. */

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: 0; }

/* ------------------------------------------------------------------ app layout */
.app { padding: calc(var(--nav-h) + 24px) 0 72px; }
.app__wrap { width: 100%; max-width: var(--container); margin: 0 auto; padding: 0 var(--gutter); display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.app__map { position: sticky; top: calc(var(--nav-h) + 16px); min-width: 0; }
.app__scan { min-width: 0; }
@media (max-width: 1023px) {
  .app { padding-top: calc(var(--nav-h) + 16px); }
  .app__wrap { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .app__map { position: static; }
}

/* the map card */
.app-map { overflow: hidden; }
.app-map:hover { transform: none; }
.app-map__canvas-wrap { position: relative; aspect-ratio: 1 / 1; background: radial-gradient(ellipse at 50% 50%, rgba(0, 240, 144, 0.05), transparent 60%), var(--bg); }
@media (min-width: 1024px) { .app-map__canvas-wrap { aspect-ratio: 1 / 0.94; } }
.app-map__canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: manipulation; outline: none; }
.app-map__canvas:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
.app-map__legend { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 10px 16px; border-top: 1px solid var(--line); font: 400 11px/1.4 var(--font-mono); letter-spacing: 0.04em; color: var(--dim); }
.app-map__legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot--green { background: var(--green); }
.dot--green2 { background: var(--green-2); }
.dot--warn { background: var(--warn); }
.dot--down { background: var(--down); }
.app-map__hint { margin-left: auto; }
@media (max-width: 639px) { .app-map__hint { margin-left: 0; flex: 1 1 100%; } }

.app-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
@media (max-width: 479px) { .app-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; } }
.app-stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.app-stat__k { display: block; font: 500 11px/1.3 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }
.app-stat__v { display: block; margin-top: 4px; font-size: 14px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ------------------------------------------------------------------ scanner */
.scan-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px 16px; margin-bottom: 12px; }
.scan-head__title { margin: 0; font: 500 22px/1.1 var(--font-sans); letter-spacing: -0.015em; color: var(--text); }
.scan-head__sub { margin: 6px 0 0; font-size: 13px; line-height: 1.5; color: var(--muted); max-width: 46ch; }
.scan-head__tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.field--search { flex-direction: row; }
.field--search input { height: 36px; width: 140px; max-width: 100%; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--bg); color: var(--text); font: 500 13px/1 var(--font-mono); outline: none; }
.field--search input::placeholder { color: var(--dim); }
.field--search input:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.seg { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line-2); border-radius: var(--radius-pill); background: rgba(255, 255, 255, 0.03); }
.seg__opt { height: 30px; min-width: 44px; padding: 0 12px; border: 0; border-radius: var(--radius-pill); background: none; color: var(--muted); font: 500 12px/1 var(--font-mono); cursor: pointer; }
.seg__opt[aria-checked='true'] { background: var(--text); color: var(--bg); }
.seg__opt:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }

.scan-list { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; max-height: min(64vh, 760px); scrollbar-width: thin; }
.scan-list .empty { margin: 0; padding: 24px 16px; }
@media (max-width: 1023px) { .scan-list { max-height: none; overflow: visible; } }
.scan-row { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 0.9fr) minmax(0, 1fr) auto auto; gap: 10px; align-items: center; width: 100%; min-height: 58px; padding: 10px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--text); text-align: left; font: inherit; cursor: pointer; }
.scan-row:last-child { border-bottom: 0; }
.scan-row:hover { background: rgba(255, 255, 255, 0.025); }
.scan-row:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
.scan-row.is-selected { background: var(--green-soft); box-shadow: inset 3px 0 0 var(--green); }
.scan-row__who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.scan-row__who .logo { flex: none; }
.scan-row__name { display: flex; flex-direction: column; min-width: 0; }
.scan-row__name b { font-weight: 500; font-size: 14px; line-height: 1.2; }
.scan-row__name small, .scan-row__price small, .scan-row__drift small { display: block; margin-top: 2px; font-size: 11px; line-height: 1.3; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scan-row__price, .scan-row__drift { min-width: 0; }
.scan-row__price b, .scan-row__drift b { display: block; font-weight: 500; font-size: 13px; line-height: 1.2; white-space: nowrap; }
.scan-row__edge { justify-self: end; }
.scan-row .chip { height: 26px; padding: 0 9px; font: 500 12px/1 var(--font-mono); white-space: nowrap; }
.score { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; min-width: 46px; height: 38px; padding: 0 6px; border-radius: 10px; border: 1px solid var(--line-2); justify-self: end; }
.score b { font: 500 14px/1 var(--font-mono); }
.score small { margin-top: 3px; font: 400 9px/1 var(--font-mono); letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.85; }
.score--tight { color: var(--green); border-color: rgba(0, 240, 144, 0.3); background: var(--green-soft); }
.score--drifting { color: var(--green-2); border-color: rgba(56, 248, 168, 0.25); }
.score--loose { color: var(--warn); border-color: rgba(255, 209, 102, 0.3); background: rgba(255, 209, 102, 0.08); }
.score--adrift { color: var(--down); border-color: rgba(255, 107, 107, 0.3); background: rgba(255, 107, 107, 0.08); }
@media (max-width: 639px) {
  .scan-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: 'who score' 'price edge' 'drift edge'; row-gap: 6px; }
  .scan-row__who { grid-area: who; }
  .scan-row .score { grid-area: score; }
  .scan-row__price { grid-area: price; }
  .scan-row__drift { grid-area: drift; }
  .scan-row__edge { grid-area: edge; align-self: center; }
}

/* ------------------------------------------------------------------ detail: a card on desktop, a sheet on phones */
.detail { margin-top: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 18px 16px; opacity: 0; transform: translateY(6px); transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease); }
.detail.is-open { opacity: 1; transform: none; }
.detail.is-sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; margin: 0; max-height: 88vh; max-height: 88dvh; overflow: auto; border-radius: 20px 20px 0 0; padding-bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateY(100%); opacity: 1; }
.detail.is-sheet.is-open { transform: none; }
.detail-backdrop { position: fixed; inset: 0; z-index: 59; background: rgba(0, 0, 0, 0.55); }
body.detail-open { overflow: hidden; }
.detail__head { display: flex; align-items: flex-start; gap: 12px; }
.detail__id { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 auto; }
.detail__logo .logo { width: 44px; height: 44px; }
.detail__sym { margin: 0; font: 500 22px/1 var(--font-sans); letter-spacing: -0.01em; color: var(--text); }
.detail__label { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.detail__price { text-align: right; min-width: 0; }
.detail__true { display: block; font-size: 20px; font-weight: 500; color: var(--text); white-space: nowrap; }
.detail__src { display: block; margin-top: 3px; font-size: 11px; color: var(--dim); }
.detail__close { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line-2); background: none; color: var(--muted); cursor: pointer; }
.detail__close:hover { color: var(--text); border-color: var(--text); }
@media (min-width: 1024px) { .detail__close { display: none; } }
@media (max-width: 359px) { .detail__head { flex-wrap: wrap; } .detail__price { text-align: left; } }
.detail__chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.detail__chips .chip { height: 26px; padding: 0 9px; font-size: 12px; }
.detail__block { margin-top: 18px; }
.detail__row-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 10px; margin-bottom: 8px; }
.detail__k { font: 500 11px/1.3 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }
.detail__meta { font-size: 11px; color: var(--dim); }
.routes { display: grid; gap: 6px; }
.routes .empty { margin: 0; padding: 12px; font-size: 13px; }
.route { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--bg); color: var(--text); text-align: left; font: inherit; cursor: pointer; }
.route.is-on { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.route__label { font-size: 14px; font-weight: 500; line-height: 1.3; }
.route__meta { font-size: 11px; color: var(--dim); }
.t-up { color: var(--up); }
.sizes { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
@media (max-width: 479px) { .sizes { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.size { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0; min-height: 48px; padding: 8px 4px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--bg); color: var(--text); font: inherit; cursor: pointer; }
.size b { font-weight: 500; font-size: 13px; }
.size small { max-width: 100%; font-size: 10.5px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.size.is-up small { color: var(--up); }
.size.is-down small { color: var(--down); }
.size.is-off { opacity: 0.55; }
.size.is-on { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.quote { margin-top: 18px; padding: 12px 14px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.quote__row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; color: var(--muted); }
.quote__row .mono { color: var(--text); white-space: nowrap; }
.quote__row--total { border-bottom: 0; color: var(--text); font-weight: 500; }
.quote__row--total .mono { color: var(--green); font-size: 16px; }
.quote[data-state='loading'] .quote__row .mono { opacity: 0.6; }
.quote__note { margin: 10px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.detail__action { margin-top: 18px; }
.detail__run { width: 100%; justify-content: center; }
.detail__run.is-busy { opacity: 0.7; }
.detail__note { margin: 8px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--muted); text-align: center; }
.runlog { margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: #0b0d0f; border: 1px solid var(--line); font-size: 12px; line-height: 1.6; color: var(--text-2); }
.runlog__line { margin: 0; overflow-wrap: anywhere; }
.runlog__line--muted { color: var(--dim); }
.runlog__line--err { color: var(--down); }
.runlog__line--ok { color: var(--up); }
.runlog a { color: var(--green); text-decoration: underline; text-underline-offset: 2px; }
.detail__fine { margin: 16px 0 0; font-size: 12px; line-height: 1.55; color: var(--dim); }

/* wallet sheet content */
.wallets { display: grid; gap: 8px; }
.wallet-opt { display: flex; align-items: center; gap: 12px; height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--bg); color: var(--text); font: 500 14px/1 var(--font-sans); cursor: pointer; }
.wallet-opt:hover { border-color: var(--text); }
.wallet-opt img { border-radius: 6px; }
.wallet-opt__ph { width: 24px; height: 24px; border-radius: 6px; background: var(--panel-2); }
.wallets__msg { margin: 10px 0 0; min-height: 1em; font-size: 13px; color: var(--muted); }
.wallets__msg.is-err { color: var(--down); }
.wallets__fine { margin: 10px 0 0; font-size: 12px; line-height: 1.5; color: var(--dim); }
.wallet-menu__addr { margin: 0; font-size: 13px; overflow-wrap: anywhere; color: var(--text); }
.wallet-menu__meta { margin: 6px 0 0; font-size: 13px; color: var(--muted); }

/* ------------------------------------------------------------------ data pages: /index and /dividends */
.page { padding: calc(var(--nav-h) + 40px) 0 80px; }
.page__head { margin-bottom: 28px; }
.page__head .t-h2 { margin: 10px 0 14px; }
.page__head .t-body { max-width: 62ch; }
.page__src { margin: 10px 0 0; font: 400 12px/1.5 var(--font-mono); color: var(--dim); overflow-wrap: anywhere; }
.page__stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 22px; }
@media (max-width: 767px) { .page__stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.page__stats .app-stat__v { font-size: 18px; }
.page section + section { margin-top: 28px; }

.ix th button { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.ix th button::after { content: ''; width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 5px solid currentColor; opacity: 0.35; }
.ix th[aria-sort='ascending'] button::after { transform: rotate(180deg); opacity: 1; }
.ix th[aria-sort='descending'] button::after { opacity: 1; }
.ix th[aria-sort='ascending'] button, .ix th[aria-sort='descending'] button { color: var(--text); }
.ix tbody tr[data-sym] { cursor: pointer; }
.ix tbody tr.is-open { background: rgba(255, 255, 255, 0.03); }
.ix .table__who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ix .table__who .logo { flex: none; }
.ix .table__name { display: flex; flex-direction: column; min-width: 0; }
.ix .table__name b { font-weight: 500; color: var(--text); }
.ix .table__name small { font-size: 11px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ix td small { display: block; margin-top: 2px; font-size: 11px; color: var(--dim); white-space: nowrap; }
.ix .drawer td { padding: 0 16px 14px; background: rgba(255, 255, 255, 0.02); }
.pools { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 13px; }
.pools th { text-align: left; font: 500 10.5px/1.3 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); padding: 8px 10px; border-bottom: 1px solid var(--line); }
.pools td { padding: 8px 10px; border-bottom: 1px solid var(--line); color: var(--text-2); }
.pools tr:last-child td { border-bottom: 0; }
.pools .is-num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pools .is-thin td { color: var(--dim); }
.drawer__parts { margin: 10px 0 0; font: 400 12px/1.6 var(--font-mono); color: var(--dim); }
.method { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 24px; }
.method h2 { margin: 0 0 12px; font: 500 20px/1.2 var(--font-sans); letter-spacing: -0.01em; color: var(--text); }
.method ol { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.method li { font-size: 14px; line-height: 1.55; color: var(--muted); }
.method li::marker { font-family: var(--font-mono); color: var(--green); }
.prose { max-width: 68ch; }
.prose p { margin: 0 0 12px; font-size: var(--fs-body); line-height: 1.6; color: var(--muted); }
.prose h2 { margin: 0 0 12px; font: 500 var(--fs-h3)/1.15 var(--font-sans); letter-spacing: -0.015em; color: var(--text); }

@media (max-width: 639px) {
  /* stacked rows: every cell becomes a labelled line */
  .ix .table thead { display: none; }
  .ix .table tbody tr { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line); }
  .ix .table tbody tr.drawer { padding: 0 14px 14px; }
  .ix .table tbody tr:last-child { border-bottom: 0; }
  .ix .table td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 5px 0; border: 0; text-align: right; }
  .ix .table td.td-who { justify-content: flex-start; text-align: left; padding-bottom: 8px; }
  .ix .table td[data-label]::before { content: attr(data-label); flex: none; font: 500 10.5px/1.3 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); text-align: left; }
  .ix .table td small { white-space: normal; }
  .ix .drawer td { display: block; padding: 0; }
  .pools { font-size: 12px; }
  .pools th, .pools td { padding: 6px 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .detail, .detail.is-sheet { transition: none; }
}
