/*
  MICRO-EDGE LIVE OBSERVER -- PANEL STYLES.

  A SEPARATE STYLESHEET on purpose. arbitrage.css is a production
  surface for a live trading product; this panel is a research
  instrument that happens to share the page. Keeping the rules apart
  means a change here cannot restyle the arbitrage desk, and the
  cascade cannot collide across the two files.

  It inherits the desk's palette through CSS variables where they
  exist, and falls back to its own values where they do not, so the
  panel reads as part of the page without depending on internals it
  does not own.

  THE VIRTUAL BANNER IS NOT DECORATION. Everything in this panel is a
  hypothetical. The surface is tinted, bordered and labelled so that no
  screenshot of it could be mistaken for a real account, and the label
  is on the panel itself rather than only in a heading -- a heading
  scrolls away, a border does not.
*/

#microedge-panel {
  --me-virtual: #b8862b;
  --me-virtual-dim: rgba(184, 134, 43, 0.12);
  --me-green: #2f9e68;
  --me-red: #c24b4b;
  --me-orange: #c4873d;
  --me-ink: var(--ink, #e8edf3);
  --me-ink-dim: var(--ink-dim, #8c98a6);
  --me-rule: var(--rule, rgba(255, 255, 255, 0.08));
  --me-surface: var(--surface, #121821);
  --me-surface-2: var(--surface-2, #0e141c);

  border: 1px solid var(--me-virtual);
  border-left-width: 3px;
  background: linear-gradient(var(--me-virtual-dim), transparent 120px),
              var(--me-surface);
}

#microedge-panel .me-virtual-flag {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.15em 0.55em;
  border: 1px solid var(--me-virtual);
  border-radius: 2px;
  color: var(--me-virtual);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  white-space: nowrap;
}

#microedge-panel .me-absent {
  padding: 1.6rem 0;
  color: var(--me-ink-dim);
  font-size: 0.9rem;
  line-height: 1.55;
}

/* ---------------------------------------------------------------- */
/* ACCOUNT AREA                                                      */
/* ---------------------------------------------------------------- */

.me-account {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1px;
  background: var(--me-rule);
  border: 1px solid var(--me-rule);
  margin-bottom: 1.25rem;
}

.me-cell {
  background: var(--me-surface-2);
  padding: 0.7rem 0.8rem;
  min-width: 0;
}

.me-cell-label {
  display: block;
  color: var(--me-ink-dim);
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.me-cell-value {
  display: block;
  color: var(--me-ink);
  font-size: 1.02rem;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  letter-spacing: -0.01em;
}

.me-cell.me-wide { grid-column: span 2; }
.me-cell-value.me-lg { font-size: 1.35rem; }
.me-cell-value.me-pos { color: var(--me-green); }
.me-cell-value.me-neg { color: var(--me-red); }
.me-cell-value.me-proj { color: var(--me-orange); }

.me-cell-note {
  display: block;
  margin-top: 0.25rem;
  color: var(--me-ink-dim);
  font-size: 0.6rem;
  letter-spacing: 0.04em;
}

/* ---------------------------------------------------------------- */
/* SECTIONS AND TABLES                                               */
/* ---------------------------------------------------------------- */

.me-section { margin-bottom: 1.5rem; }

.me-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 0.4rem;
  margin-bottom: 0.6rem;
  border-bottom: 1px solid var(--me-rule);
}

.me-section-title {
  color: var(--me-ink);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.me-section-meta {
  color: var(--me-ink-dim);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* Wide tables scroll in their OWN container. The page body must never
   scroll sideways, on any viewport. */
.me-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.me-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.74rem;
  font-variant-numeric: tabular-nums;
}

.me-table th {
  color: var(--me-ink-dim);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  text-align: right;
  padding: 0.4rem 0.55rem;
  border-bottom: 1px solid var(--me-rule);
  white-space: nowrap;
}

.me-table th:first-child,
.me-table td:first-child { text-align: left; }

.me-table td {
  color: var(--me-ink);
  padding: 0.42rem 0.55rem;
  border-bottom: 1px solid var(--me-rule);
  text-align: right;
  white-space: nowrap;
}

.me-table tbody tr.me-expandable { cursor: pointer; }
.me-table tbody tr.me-expandable:hover { background: var(--me-virtual-dim); }
.me-table tbody tr.me-expandable:focus-visible {
  outline: 2px solid var(--me-virtual);
  outline-offset: -2px;
}

.me-empty {
  padding: 1rem 0.55rem;
  color: var(--me-ink-dim);
  font-size: 0.78rem;
  text-align: left;
}

/* ---------------------------------------------------------------- */
/* STATUS SEMANTICS -- STRICT                                        */
/* ---------------------------------------------------------------- */

.me-status {
  display: inline-block;
  padding: 0.1em 0.45em;
  border-radius: 2px;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* GREEN is reserved: closed, fills defensible, funding REALIZED, all
   mandatory costs known, accounting reconciled, TRUE NET > 0. */
.me-status-verified-positive {
  background: rgba(47, 158, 104, 0.16);
  color: var(--me-green);
  border: 1px solid rgba(47, 158, 104, 0.5);
}

.me-status-verified-negative {
  background: rgba(194, 75, 75, 0.14);
  color: var(--me-red);
  border: 1px solid rgba(194, 75, 75, 0.45);
}

/* Everything projected, open, unverified or incomplete is ORANGE. A
   projected positive never turns green. */
.me-status-unverified,
.me-status-incomplete,
.me-status-open {
  background: rgba(196, 135, 61, 0.14);
  color: var(--me-orange);
  border: 1px solid rgba(196, 135, 61, 0.45);
}

.me-status-failed {
  background: rgba(194, 75, 75, 0.2);
  color: var(--me-red);
  border: 1px solid var(--me-red);
}

/* ---------------------------------------------------------------- */
/* EXPANDED TRADE VIEW                                               */
/* ---------------------------------------------------------------- */

.me-detail-row > td {
  padding: 0;
  border-bottom: 1px solid var(--me-rule);
  background: var(--me-surface-2);
}

.me-detail {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.1rem;
  padding: 0.95rem 0.8rem;
  text-align: left;
}

.me-detail h4 {
  margin: 0 0 0.45rem;
  color: var(--me-ink-dim);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.me-kv {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.16rem 0;
  font-size: 0.72rem;
  line-height: 1.4;
}

.me-kv dt { color: var(--me-ink-dim); }
.me-kv dd {
  margin: 0;
  color: var(--me-ink);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.me-kv.me-total {
  margin-top: 0.3rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--me-rule);
  font-weight: 600;
}

.me-prov {
  margin-left: 0.4em;
  color: var(--me-ink-dim);
  font-size: 0.58rem;
  letter-spacing: 0.05em;
}

/* ---------------------------------------------------------------- */
/* HEALTH                                                            */
/* ---------------------------------------------------------------- */

.me-health {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.5rem 1.1rem;
  font-size: 0.72rem;
}

.me-health .me-kv { padding: 0.1rem 0; }

.me-bands {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1px;
  background: var(--me-rule);
  border: 1px solid var(--me-rule);
}

.me-band {
  background: var(--me-surface-2);
  padding: 0.55rem 0.65rem;
}

.me-band-label {
  display: block;
  color: var(--me-ink-dim);
  font-size: 0.6rem;
  letter-spacing: 0.05em;
  margin-bottom: 0.2rem;
  white-space: nowrap;
}

.me-band-count {
  display: block;
  color: var(--me-ink);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- */
/* MOBILE                                                            */
/* ---------------------------------------------------------------- */

@media (max-width: 640px) {
  .me-account { grid-template-columns: repeat(2, 1fr); }
  .me-cell.me-wide { grid-column: span 2; }
  .me-cell-value { font-size: 0.94rem; }
  .me-cell-value.me-lg { font-size: 1.18rem; }
  .me-detail { grid-template-columns: 1fr; gap: 0.9rem; }
  .me-health { grid-template-columns: 1fr 1fr; }
  .me-section-head { flex-direction: column; align-items: flex-start; }
  .me-section-meta { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  #microedge-panel * { transition: none !important; animation: none !important; }
}

/* ---------------------------------------------------------------- */
/* FRESHNESS -- stale data must never read as live                   */
/* ---------------------------------------------------------------- */

.me-freshness {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.9rem;
  border: 1px solid var(--me-rule);
  background: var(--me-surface-2);
}

.me-freshness .me-cell-note { margin-top: 0; }

/* The PANEL carries the freshness state, so a stale run is visible
   without reading a single field. The left border is the signal: it
   stays in view while the account area scrolls past. */
#microedge-panel[data-freshness="STALE"] {
  border-color: var(--me-orange);
  background: linear-gradient(rgba(196, 135, 61, 0.14), transparent 120px),
              var(--me-surface);
}

#microedge-panel[data-freshness="OFFLINE"],
#microedge-panel[data-freshness="UNREACHABLE"] {
  border-color: var(--me-red);
  background: linear-gradient(rgba(194, 75, 75, 0.14), transparent 120px),
              var(--me-surface);
}

/* When the source is not fresh, the account figures are dimmed: they
   describe a past moment, and presenting them at full strength beside
   a STALE badge invites the reader to treat them as current. */
#microedge-panel[data-freshness="OFFLINE"] .me-account,
#microedge-panel[data-freshness="UNREACHABLE"] .me-account,
#microedge-panel[data-freshness="STALE"] .me-account {
  opacity: 0.55;
}

/* ---------------------------------------------------------------- */
/* MOBILE: equity, TRUE NET, health first                            */
/* ---------------------------------------------------------------- */

@media (max-width: 640px) {
  .me-freshness {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }
  /* The two figures that matter on a phone span the full width and
     lead the grid; the rest follow in source order below them. */
  .me-cell.me-wide { grid-column: 1 / -1; }
}
