/* JOB9 — Wallet/CA responsive polish (additive).
 * Maps WALLET-001 ui-proof desktop + ~390px patterns onto Build07 selectors.
 * Does NOT rewrite lookout.css / app.css / refinements.css — load AFTER them.
 * Aligns state labels with Jobs 5–8: STALE / UNKNOWN / error / private.
 */

:root {
  --lk-priv: #7aa2ff;
  --lk-pub: #9a7fd1;
  --lk-buy: #3dd68c;
  --lk-sell: #f07178;
  --lk-transfer: #e6c07b;
  --lk-unknown: #7f8ea3;
  --lk-stale: #ffb454;
  --lk-err: #ff6b6b;
}

/* —— Private label / user-reported role (ui-proof badge.priv / badge.pub) —— */
.wallet-detail-head .eyebrow,
.wallet-tile .eyebrow,
[data-wallet-role="private"] .eyebrow {
  color: var(--lk-priv);
}
.wallet-ca-pill,
.lookout-wallet-pill {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  background: #0f1f1a;
  border: 1px solid #243041;
  color: var(--muted, #8b9bb0);
  letter-spacing: .02em;
  vertical-align: middle;
}
.wallet-ca-pill.priv,
.lookout-wallet-pill.priv,
[data-visibility="private"] .wallet-ca-pill {
  color: var(--lk-priv);
  border-color: #2a3f6d;
}
.wallet-ca-pill.pub,
.lookout-wallet-pill.pub,
[data-visibility="user-reported"] .wallet-ca-pill,
[data-wallet-role="user-reported"] .wallet-ca-pill {
  color: var(--lk-pub);
  border-color: #4a3a6d;
}
.wallet-ca-pill.stale,
.lookout-wallet-pill.stale,
[data-stale="1"] .wallet-ca-pill.stale {
  color: var(--lk-stale);
  border-color: #5a4020;
}
.wallet-ca-pill.unknown,
.lookout-wallet-pill.unknown {
  color: var(--lk-unknown);
}
.wallet-ca-pill.err,
.lookout-wallet-pill.err,
[data-provider-error="1"] .wallet-ca-pill.err {
  color: var(--lk-err);
  border-color: #5a2030;
}
.wallet-ca-pill.buy { color: var(--lk-buy); }
.wallet-ca-pill.sell { color: var(--lk-sell); }
.wallet-ca-pill.transfer { color: var(--lk-transfer); }

/* Private label chip next to wallet name (ui-proof "private label") */
.wallet-detail-head h1 .wallet-ca-pill.priv,
.wallet-tile h2 .wallet-ca-pill.priv {
  margin-left: 8px;
  font-size: 10px;
  font-weight: 500;
  vertical-align: middle;
}

/* —— Direction / evidence pills on tape (align Jobs 5–8 labels) —— */
.wallet-direction.unknown,
.wallet-transfer[data-dir="UNKNOWN"] .wallet-direction {
  color: var(--lk-unknown);
}
.wallet-transfer[data-dir="BUY"] .wallet-direction { color: var(--lk-buy); }
.wallet-transfer[data-dir="SELL"] .wallet-direction { color: var(--lk-sell); }
.wallet-transfer[data-stale="1"] {
  outline: 1px dashed rgba(255, 180, 84, .35);
  outline-offset: 2px;
}

/* —— Chart / tape alignment (G-EVID-02 pattern) —— */
.wallet-detail-layout .chart-panel,
.wallet-detail-layout [data-chart-token] {
  min-width: 0;
  overflow: hidden;
}
.wallet-detail-layout .price-chart {
  max-width: 100%;
  height: auto;
}
.wallet-detail-layout .chart-legend {
  gap: 10px;
}
.wallet-ca-align-note {
  font-size: 11px;
  color: var(--muted, #8b9bb0);
  margin: 4px 0 10px;
}
.wallet-ca-align-note[data-stale="1"],
.chart-panel[data-stale="1"] .section-head .small.amber {
  color: var(--lk-stale);
}

/* STALE chart banner (ui-proof stalePill) */
.wallet-ca-stale-banner,
[data-chart-state="STALE"] .wallet-ca-stale-banner {
  display: none;
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #5a4020;
  background: #1a1510;
  color: var(--lk-stale);
  margin: 8px 0;
}
[data-chart-state="STALE"] .wallet-ca-stale-banner,
.chart-panel[data-stale="1"] .wallet-ca-stale-banner {
  display: block;
}

/* —— Receipt drawer states (ui-proof receipt + errbox) —— */
#receipt-dialog {
  max-width: min(480px, calc(100vw - 24px));
}
#receipt-dialog[data-receipt-state="error"] #receipt-content,
#receipt-dialog[data-provider-error="1"] #receipt-content {
  /* error chrome applied via .wallet-ca-errbox child */
}
.wallet-ca-receipt {
  font-size: 12px;
}
.wallet-ca-receipt dt {
  color: var(--muted, #8b9bb0);
  margin-top: 6px;
}
.wallet-ca-receipt dd {
  margin: 0 0 8px;
  overflow-wrap: anywhere;
}
.wallet-ca-errbox {
  border: 1px solid #5a2030;
  background: #1a1014;
  color: #ffb4b4;
  padding: 10px;
  border-radius: 8px;
  margin-top: 8px;
  font-size: 12px;
}
.wallet-ca-errbox[hidden],
.wallet-ca-errbox.is-hidden {
  display: none !important;
}
#receipt-dialog[data-receipt-state="empty"] #receipt-content::before {
  content: "No receipt selected";
  display: block;
  color: var(--muted, #8b9bb0);
  font-size: 12px;
  margin-bottom: 8px;
}
#receipt-dialog[data-receipt-state="open"] .dialog-head h2::after {
  content: " · open";
  font-size: 11px;
  color: var(--muted, #8b9bb0);
  font-weight: 400;
}

/* Selected tape row (ui-proof tr.selected) */
.wallet-transfer.is-selected,
.wallet-transfer[aria-selected="true"] {
  background: #1a2740;
  border-radius: 8px;
  padding-left: 8px;
  padding-right: 8px;
}

/* Viewport tag (ui-proof #vpTag) — optional debug/chrome */
.wallet-ca-viewport-tag {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid #243041;
  color: var(--muted, #8b9bb0);
  margin-left: auto;
}

/* —— Desktop (≥901px): keep 2-col wallet detail, room for rail —— */
@media (min-width: 901px) {
  .wallet-desk,
  .wallet-detail-layout {
    grid-template-columns: minmax(0, 1fr) 290px;
    gap: 20px;
  }
  .wallet-detail-layout .chart-panel .price-chart {
    min-height: 180px;
  }
  .wallet-list {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  }
}

/* —— Tablet / narrow desktop —— */
@media (max-width: 900px) {
  .wallet-desk,
  .wallet-detail-layout {
    grid-template-columns: 1fr;
  }
  .wallet-home {
    flex-wrap: wrap;
  }
  .wallet-home .button {
    width: 100%;
    text-align: center;
  }
  .wallet-detail-head .app-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
  .wallet-detail-head .app-actions .button {
    flex: 1 1 auto;
    min-width: 0;
  }
  .chart-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #receipt-dialog {
    width: calc(100% - 24px);
    margin: auto;
  }
}

/* —— ~390px phone (ui-proof viewport ≤420) —— */
@media (max-width: 420px) {
  .wallet-detail-head h1 {
    font-size: 22px;
    letter-spacing: -0.6px;
    overflow-wrap: anywhere;
  }
  .wallet-detail-head .app-address,
  .wallet-tile .app-address {
    font-size: 11px;
    word-break: break-all;
  }
  .wallet-tile {
    padding: 16px;
  }
  .wallet-tile h2 {
    font-size: 17px;
  }
  .wallet-transfer {
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 8px;
    padding: 12px 0;
  }
  .wallet-transfer .button {
    grid-column: 2;
    justify-self: start;
    min-height: 44px;
  }
  .chart-panel {
    margin: 12px 0;
  }
  .chart-stats {
    grid-template-columns: 1fr 1fr;
  }
  .chart-stats strong {
    font-size: 13px;
  }
  .chart-legend {
    font-size: 10px;
    gap: 8px;
  }
  .price-chart {
    border-radius: 6px;
  }
  /* Receipt as bottom sheet on ~390px (ui-proof drawer feel) */
  #receipt-dialog {
    margin: auto 0 0;
    width: 100%;
    max-width: 100%;
    border-radius: 14px 14px 0 0;
    max-height: 88dvh;
    padding-bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  }
  #receipt-dialog .dialog-head h2 {
    font-size: 18px;
  }
  .wallet-ca-errbox {
    font-size: 11px;
  }
  .wallet-ca-pill,
  .lookout-wallet-pill {
    font-size: 10px;
    padding: 2px 6px;
  }
  /* Prevent horizontal blowout on wallet/CA surfaces */
  .wallet-desk,
  .wallet-detail-layout,
  .wallet-home,
  .chart-panel,
  .wallet-list {
    max-width: 100%;
    overflow-x: clip;
  }
}

/* Error / UNKNOWN surface chrome (provider failure) */
[data-wallet-surface-state="error"] .wallet-detail-head .eyebrow,
[data-provider-error="1"] .wallet-detail-head .eyebrow {
  color: var(--lk-err);
}
[data-wallet-surface-state="STALE"] .wallet-detail-head .eyebrow {
  color: var(--lk-stale);
}


/* MH-08 — surface rail wrap at ~390 (no redesign) */
#mh04-surface-rail .section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
}
#mh04-surface-rail .section-head .small.muted {
  white-space: normal;
  overflow-wrap: anywhere;
  max-width: 100%;
}
@media (max-width: 420px) {
  #mh04-surface-rail .section-head h2 {
    flex: 1 1 auto;
  }
  #mh04-surface-rail .section-head .small.muted {
    flex: 1 1 100%;
  }
}


/* MH-08 — surface rail wrap v2 */
#mh04-surface-rail .section-head {
  display: flex !important;
  flex-wrap: wrap !important;
  align-items: flex-start;
  gap: 4px 8px;
  overflow: visible !important;
  white-space: normal !important;
}
#mh04-surface-rail .section-head h2 {
  white-space: normal !important;
}
#mh04-surface-rail .section-head .small.muted {
  display: block;
  flex: 1 1 100%;
  white-space: normal !important;
  overflow: visible !important;
  text-overflow: clip !important;
  overflow-wrap: anywhere;
  max-width: 100%;
}


/* MH-08 — surface tags full width under heading */
#mh04-surface-rail .mh04-surface-tags {
  display: block;
  width: 100%;
  margin-top: 4px;
  white-space: normal;
  overflow-wrap: anywhere;
}
