/* ============================================================================
   X monitor — the home page (live posts → coin ideas → launch), and the launch
   sheet a pick opens over it.

   The feed is laid out and sized like the X Bags monitor page it is fed by
   (bagsfm/xbags web/style.css): a status line with the deploy options, posts
   as cards with their ideas in a column on the right, the watched accounts
   beside them — in this app's own colours (the --x-* names of that sheet are
   mapped onto the theme tokens, so light and dark follow the theme switch).
   The page scrolls; nothing here has a scroll box of its own.
   ========================================================================== */

/* ---------------- the feed ---------------- */
/* --xm-chrome is the height of the page's own bar above the feed (the phone top
   bar; 0 on desktop), set by js/components/x-monitor.js. */
.xm {
  --x-bg: var(--bg); --x-card: var(--bg-2); --x-text: var(--text); --x-muted: var(--muted); --x-line: var(--border); --x-accent: var(--accent); --x-ink: var(--accent-ink, #fff); --x-error: var(--danger, #ff453a);
  --xm-chrome: 0px;
  container: xm / inline-size;
  min-height: calc(100vh - var(--xm-chrome)); min-height: calc(100dvh - var(--xm-chrome));
  background: var(--x-bg); color: var(--x-text);
  font-size: 14px; line-height: 1.45;
}
.xm a { color: inherit; }
.xm-muted, .xm small { color: var(--x-muted); }
.xm small { font-weight: 400; font-size: 12px; }

/* the status line and the deploy options: stays at the top of the page */
.xm-bar {
  position: sticky; top: var(--xm-chrome); z-index: 6; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--x-bg); border-bottom: 1px solid var(--x-line);
}
.xm-lanes { flex: 1; min-width: 200px; font-size: 12px; color: var(--x-muted); }
.xm-lanes::before { content: "●"; margin-right: 4px; color: var(--x-accent); }
.xm-lanes.is-down, .xm-lanes.is-down::before { color: var(--x-error); }
.xm-opt { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--x-muted); white-space: nowrap; cursor: pointer; }
.xm-opt input[type="checkbox"] { accent-color: var(--x-accent); margin: 0; }
.xm-buy { width: 56px; font: inherit; padding: 3px 6px; border: 1px solid var(--x-line); border-radius: 8px; background: var(--x-card); color: var(--x-text); }
.xm-buy:focus, .xm-handle:focus { outline: none; border-color: var(--x-accent); }

.xm-grid { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; padding: 12px 16px 40px; max-width: 1500px; margin: 0 auto; }
.xm-col { min-width: 0; }
.xm-h { display: flex; flex-direction: column; gap: 2px; margin: 8px 0 10px; font-size: 15px; font-weight: 700; line-height: 1.45; letter-spacing: normal; }
.xm-empty { margin: 14px 0; }
.xm-empty[hidden] { display: none; }

/* a post: a card */
.xm-posts { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.xm-post { min-width: 0; padding: 10px 12px; background: var(--x-card); border: 1px solid var(--x-line); border-radius: 12px; }
.xm-post.is-fresh { border-color: var(--x-accent); }
.xm-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.xm-grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xm-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--x-line); flex: none; object-fit: cover; }
.xm-sym { font-weight: 700; text-decoration: underline; }
.xm-num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.xm-kind { flex: none; font-size: 11px; color: var(--x-muted); border: 1px solid var(--x-line); border-radius: 999px; padding: 1px 8px; }
.xm-launch-btn { flex: none; font: inherit; font-weight: 600; font-size: 12px; border: 1px solid currentColor; background: var(--x-card); color: var(--x-accent); border-radius: 999px; padding: 5px 14px; cursor: pointer; }

.xm-post-body { display: grid; grid-template-columns: minmax(0, 1fr) 210px; gap: 12px; margin-top: 8px; }
.xm-post-main { min-width: 0; }
.xm-text { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.xm-ref { margin: 8px 0 0; padding: 8px 10px; border-left: 3px solid var(--x-line); color: var(--x-muted); overflow-wrap: anywhere; white-space: pre-wrap; }
.xm-ref b { color: var(--x-text); font-weight: 700; }
.xm-media { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.xm-media img { max-width: 100%; max-height: 220px; border-radius: 10px; border: 1px solid var(--x-line); }

/* coin ideas: a column of small cards beside the post */
.xm-ideas { display: grid; gap: 4px; align-content: start; min-width: 0; }
.xm-idea { display: flex; align-items: center; gap: 8px; width: 100%; min-width: 0; padding: 4px; border: 1px solid var(--x-line); border-radius: 10px; background: var(--x-bg); color: var(--x-text); font: inherit; text-align: left; cursor: pointer; }
.xm-idea:hover:not(:disabled) { border-color: var(--x-accent); }
.xm-idea:disabled { opacity: 0.5; cursor: default; }
.xm.is-armed .xm-idea { border-color: var(--x-accent); }
.xm-idea-img { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; flex: none; }
.xm-idea-art .xm-idea-img { background: #000; }
.xm-idea-label { display: grid; flex: 1; min-width: 0; font-size: 12px; line-height: 1.3; }
.xm-idea-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xm-idea-note { margin: 0; font-size: 12px; }
.xm-idea-score { flex: none; margin-left: auto; min-width: 26px; padding: 1px 5px; border-radius: 999px; border: 1px solid var(--x-line); font-size: 11px; font-variant-numeric: tabular-nums; text-align: center; color: var(--x-muted); }
.xm-idea-top .xm-idea-score { color: var(--x-ink); background: var(--x-accent); border-color: var(--x-accent); font-weight: 700; }
.xm-rating { margin: 2px 0 0; font-size: 11px; color: var(--x-muted); }

/* "N new posts ↑": rides under the bar without taking a line of the feed */
.xm-new-wrap { position: sticky; top: calc(var(--xm-chrome) + 56px); z-index: 5; height: 0; display: flex; justify-content: center; pointer-events: none; }
.xm-new { pointer-events: auto; flex: none; font: inherit; font-weight: 600; padding: 8px 16px; border: 0; border-radius: 999px; background: var(--x-accent); color: var(--x-ink); box-shadow: 0 6px 20px rgb(0 0 0 / 0.35); cursor: pointer; white-space: nowrap; }
.xm-new[hidden] { display: none; }

/* watching: beside the feed, in view while it scrolls */
.xm-watch { position: sticky; top: calc(var(--xm-chrome) + 56px); }
.xm-add { display: flex; gap: 6px; margin: 10px 0; }
.xm-handle { flex: 1; min-width: 0; font: inherit; padding: 6px 10px; border: 1px solid var(--x-line); border-radius: 10px; background: var(--x-card); color: var(--x-text); }
.xm-handle::placeholder { color: var(--x-muted); }
.xm-note { margin: 0 0 10px; }
.xm-accounts { display: flex; flex-wrap: wrap; gap: 6px; }
.xm-account { font-size: 12px; border: 1px solid var(--x-line); background: var(--x-card); color: var(--x-text); border-radius: 999px; padding: 3px 10px; text-decoration: none; }
.xm-account:hover { border-color: var(--x-accent); color: var(--x-accent); }

/* one column: the account search sits above the feed, since the feed never ends */
@container xm (max-width: 860px) {
  .xm-grid { grid-template-columns: minmax(0, 1fr); }
  .xm-watch { order: -1; position: static; }
}
/* phones */
@media (max-width: 700px) { .xm { font-size: 15px; } .xm-buy, .xm-handle { font-size: 16px; } }
@container xm (max-width: 700px) {
  .xm-bar { padding-left: 12px; padding-right: 12px; gap: 10px; justify-content: space-between; }
  .xm-lanes:not(.is-down) { display: none; }   /* two short rows at most: the status line only shows when the stream is down */
  .xm-grid { padding: 10px 10px calc(90px + env(safe-area-inset-bottom)); gap: 10px; }
  .xm-watch .xm-h { flex-direction: row; align-items: baseline; gap: 8px; margin: 0 0 6px; }
  .xm-note { display: none; }
  .xm-post { padding: 12px; border-radius: 14px; }
  .xm-post > .xm-row { flex-wrap: wrap; row-gap: 6px; }
  .xm-post > .xm-row .xm-grow { flex-basis: calc(100% - 46px); }
  .xm-launch-btn { padding: 9px 16px; font-size: 14px; }
  .xm-post > .xm-row .xm-launch-btn { margin-left: auto; }
  .xm-media img { max-height: 300px; width: 100%; object-fit: cover; }
  /* ideas become a row you swipe sideways, so a post stays short */
  .xm-post-body { grid-template-columns: minmax(0, 1fr); }
  .xm-ideas { display: flex; overflow-x: auto; gap: 8px; margin: 0 -12px; padding: 2px 12px 6px; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .xm-ideas::-webkit-scrollbar { display: none; }
  .xm-idea { flex: 0 0 auto; width: 172px; padding: 6px; min-height: 56px; scroll-snap-align: start; }
  .xm-idea-img { width: 44px; height: 44px; }
  .xm-idea-label { font-size: 13px; }
  .xm-idea-note { padding: 4px 0; flex: none; }
  .xm-rating { flex: none; align-self: center; }
  .xm-account { padding: 8px 12px; font-size: 14px; }
}

/* ---------------- the launch sheet (js/components/launch-sheet.js) ---------------- */
/* The launch form over the feed: a header and the Launch bar that stay put, the
   form scrolling between them. Below modal.js's layer (100) and the pair
   picker's (200): the form and the wallet card open those on top of it. */
.xs-overlay {
  position: fixed; inset: 0; z-index: 90; display: flex; justify-content: center; align-items: flex-start;
  padding: 5vh 12px 0; background: var(--overlay);
}
.xs {
  flex: none; display: flex; flex-direction: column; width: 100%; max-width: 620px; max-height: 90vh; max-height: 90dvh; outline: none; overflow: hidden;
  background: var(--bg-2, var(--bg)); border: 1px solid var(--border-2, var(--border)); border-radius: 16px;
  box-shadow: var(--shadow, 0 14px 40px -18px rgba(0, 0, 0, 0.7)); animation: modal-in 0.15s ease-out;
}
@media (prefers-reduced-motion: reduce) { .xs { animation: none; } }
.xs-head { flex: none; display: flex; align-items: center; gap: 8px; min-height: 54px; padding: 0 16px 0 8px; border-bottom: 1px solid var(--border); }
.xs-close { flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: var(--text); }
.xs-close:hover { background: var(--hover); }
.xs-title { flex: none; margin: 0; font-size: 18px; font-weight: 800; line-height: 1.2; letter-spacing: -0.022em; }
.xs-from { margin-left: auto; min-width: 0; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xs-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; padding: 18px 18px 20px; }
/* The Launch panel's parts, borrowed with its class: only its place in a row of panels is undone. */
.xs .pnl-launch { position: static; top: auto; flex: none; }
.xs-launch { margin-top: 22px; }
.xs-launch[hidden], .xs-foot[hidden] { display: none; }
/* the page behind does not scroll while the sheet is up (a class: modal.js resets the inline lock when its own dialog closes) */
body.has-sheet { overflow: hidden; }
/* a long error stays inside the footer, and messages rise above the Launch bar instead of sitting on it */
.xs-foot .lc-error { max-height: 28vh; overflow-y: auto; overscroll-behavior: contain; }
@media (min-width: 705px) { body.has-sheet .toast { bottom: calc(5vh + 96px); } }
.xs .xs-foot { flex: none; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.xs-foot .lx-launch-actions:not(:empty) { margin-top: 0; }
/* one row: the secondary action beside a Launch button that takes the rest */
.xs .xs-foot .lx-form-mount .lc-actions { flex-direction: row; align-items: stretch; gap: 10px; box-shadow: none; border: 0; }
.xs .xs-foot .lx-form-mount .lc-launch { order: 2; flex: 1 1 auto; width: auto; height: 50px; }
.xs .xs-foot .lx-form-mount .lc-intent { order: 1; flex: none; width: auto; height: 50px; padding: 0 18px; }
.xs .lc-success .lc-title { display: block; }
.xs .lc-success { padding: 26px 0 10px; }
@media (max-width: 704px) {
  .xs-overlay { padding: 0; }
  .xs { max-width: none; height: 100%; max-height: none; border: 0; border-radius: 0; box-shadow: none; }
  .xs-head { padding-top: env(safe-area-inset-top); }
  .xs-body { padding: 16px 16px 20px; }
  .xs .xs-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
}
@media (max-width: 420px) { .xs .xs-foot .lx-form-mount .lc-intent { padding: 0 12px; font-size: 14px; } }
