/* Layout: one reading column; summary band (value, period P/L, trend) above tabbed ledgers. */
:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --sunk: #eceef2;
  --ink: #15171c;
  --muted: #5d6370;
  --line: #e0e3e9;
  --accent: #a96d12;       /* coin gold */
  --accent-ink: #ffffff;
  --gain: #12814a;
  --loss: #d12c2c;
  --warn-bg: #fbf1dc;
  --warn-ink: #6d4a0c;
  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-num: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1114; --surface: #171a1f; --sunk: #1d2127; --ink: #e8eaee; --muted: #959baa; --line: #272b33;
    --accent: #e3a540; --accent-ink: #15120b; --gain: #3ccf7f; --loss: #ff5a5a; --warn-bg: #2f2512; --warn-ink: #f1cf8d;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1114; --surface: #171a1f; --sunk: #1d2127; --ink: #e8eaee; --muted: #959baa; --line: #272b33;
  --accent: #e3a540; --accent-ink: #15120b; --gain: #3ccf7f; --loss: #ff5a5a; --warn-bg: #2f2512; --warn-ink: #f1cf8d;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 var(--font-body);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: env(safe-area-inset-top, 0px) env(safe-area-inset-bottom, 0px);
}
a { color: inherit; }
img { max-width: 100%; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.gain { color: var(--gain); }
.loss { color: var(--loss); }
.muted { color: var(--muted); }

/* ---------- brand / buttons ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 650; font-size: 18px; }
.mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
        background: var(--accent); color: var(--accent-ink); font-size: 15px; }
.btn { border: 1px solid var(--line); background: var(--surface); padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--loss); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { padding: 4px 10px; font-size: 13px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
              padding: 28px; display: grid; gap: 12px; }
.login-card .brand { margin-bottom: 8px; }
label { font-size: 13px; color: var(--muted); font-weight: 500; }
input[type="text"], input[type="password"], input[type="number"] {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
.form-error { color: var(--loss); margin: 0; min-height: 1.2em; font-size: 14px; }

/* ---------- app frame ---------- */
.app { max-width: 1160px; margin: 0 auto; padding-bottom: 48px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-block: 18px; }
.top-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.status { color: var(--muted); font-size: 13px; max-width: 46ch; text-align: right; }
.status.working::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
                          background: var(--accent); margin-right: 7px; vertical-align: 1px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .status.working::before { animation: none; } }

.banner { background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--r); padding: 12px 16px; margin-bottom: 16px; font-size: 14px; }
.banner p { margin: 0; }
.banner p + p { margin-top: 4px; }

/* ---------- summary ---------- */
.summary { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.5fr) minmax(0, 1fr); gap: 20px;
           align-items: stretch; padding: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.eyebrow { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.total-value { font-family: var(--font-display); font-weight: 650; font-size: clamp(34px, 5vw, 48px); line-height: 1.1;
               font-variant-numeric: tabular-nums; margin-top: 6px; letter-spacing: -0.02em; }
.total-split { color: var(--muted); font-size: 13px; margin-top: 6px; }
.periods { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.period { background: var(--sunk); border-radius: var(--r); padding: 10px 12px; min-width: 0; }
.period .label { font-size: 12px; color: var(--muted); font-weight: 500; }
.period .pl { font-family: var(--font-num); font-size: 17px; font-weight: 500; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.period .pct { font-family: var(--font-num); font-size: 12.5px; }
.period .note { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.trend { margin: 0; display: flex; flex-direction: column; min-width: 0; }
.trend svg { width: 100%; height: 96px; display: block; }
.trend-cap { font-size: 12px; color: var(--muted); margin-top: 6px; }
@media (max-width: 900px) {
  .summary { grid-template-columns: 1fr; }
}

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; margin: 22px 0 12px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; font-weight: 500; color: var(--muted);
               border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.count { font-family: var(--font-num); font-size: 12px; color: var(--muted); margin-left: 2px; }

/* ---------- ledger table ---------- */
.ledger { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.lrow { display: grid; grid-template-columns: minmax(180px, 2fr) repeat(6, minmax(0, 1fr)); gap: 12px; align-items: center;
        padding: 11px 16px; border-top: 1px solid var(--line); }
.lrow:first-child { border-top: 0; }
.lhead { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--sunk); }
.lhead > div { text-align: right; }
.lhead > div:first-child { text-align: left; }
.lrow.clickable { cursor: pointer; }
.lrow.clickable:hover { background: var(--sunk); }
.cell { text-align: right; min-width: 0; }
.cell .sub { display: block; font-size: 12px; color: var(--muted); }
.asset { display: flex; align-items: center; gap: 10px; min-width: 0; }
.asset-text { min-width: 0; }
.asset .sym { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.asset .name { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.logo { width: 30px; height: 30px; border-radius: 50%; background: var(--sunk); flex: none; object-fit: cover;
        display: grid; place-items: center; font-size: 11px; font-weight: 600; color: var(--muted); overflow: hidden; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.chip { font-size: 10.5px; padding: 1px 6px; border-radius: 99px; background: var(--sunk); color: var(--muted); font-weight: 500; white-space: nowrap; }
.chip.warn { background: var(--warn-bg); color: var(--warn-ink); }
.empty { padding: 28px 16px; color: var(--muted); text-align: center; }
.section-note { font-size: 13px; color: var(--muted); margin: 10px 2px 0; }
details.extra { margin-top: 14px; }
details.extra summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 6px 2px; }

@media (max-width: 760px) {
  .lhead { display: none; }
  .lrow { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; }
  .lrow .cell { display: none; }
  .lrow .cell.m-show { display: block; }
}

/* ---------- NFT grid ---------- */
.nft-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 14px; }
.nft { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; cursor: pointer; }
.nft:hover { border-color: var(--muted); }
.nft-img { aspect-ratio: 1; background: var(--sunk); width: 100%; object-fit: cover; display: block; max-width: 100%; }
.nft-body { padding: 10px 12px 12px; display: grid; gap: 6px; min-width: 0; }
.nft-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nft-col { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nft-kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 12.5px; }
.nft-kv dt { color: var(--muted); }
.nft-kv dd { margin: 0; text-align: right; font-family: var(--font-num); }

/* ---------- wallets ---------- */
.wallet-add { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: grid;
              grid-template-columns: minmax(0, 2.4fr) minmax(0, 1fr) auto; gap: 10px; align-items: end; margin-bottom: 14px; }
.wallet-add .field { display: grid; gap: 4px; min-width: 0; }
.detect { font-size: 12px; color: var(--muted); min-height: 1.2em; }
@media (max-width: 760px) { .wallet-add { grid-template-columns: 1fr; } }
.wrow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }
.wrow:first-child { border-top: 0; }
.waddr { font-family: var(--font-num); font-size: 13px; overflow-wrap: anywhere; }
.wmeta { font-size: 12.5px; color: var(--muted); }
.wactions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.werr { color: var(--loss); font-size: 12.5px; }

/* ---------- drawer ---------- */
.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(10, 12, 16, .45); }
.drawer-panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--bg);
                border-left: 1px solid var(--line); display: flex; flex-direction: column;
                padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
                padding-right: env(safe-area-inset-right, 0px); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-family: var(--font-display); font-weight: 650; font-size: 20px; text-wrap: balance; }
.drawer-body { overflow-y: auto; padding: 16px 18px 32px; display: grid; gap: 14px; align-content: start; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.fact { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; }
.fact .label { font-size: 12px; color: var(--muted); }
.fact .v { font-family: var(--font-num); font-size: 15px; margin-top: 2px; overflow-wrap: anywhere; }
.txlist { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.tx { padding: 11px 14px; border-top: 1px solid var(--line); display: grid; gap: 4px; }
.tx:first-child { border-top: 0; }
.tx-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.tx-kind { font-weight: 600; }
.tx-date { font-size: 12.5px; color: var(--muted); }
.tx-line { font-size: 13.5px; }
.tx-edit { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.tx-edit input { width: 130px; padding: 5px 8px; }
.tx a { font-size: 12.5px; color: var(--muted); }

/* ---------- NFT trash controls ---------- */
.nft-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
           margin-bottom: 12px; color: var(--muted); font-size: 14px; }
.nft-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.nft-blank { display: grid; place-items: center; color: var(--muted); font-size: 12px; }

.nft-bar-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.nft-value { display: grid; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.nft-value .facts { margin-top: 8px; }

/* ---------- search ---------- */
.tabs { align-items: center; }
.search { margin-left: auto; padding: 4px 0 6px 8px; flex: 0 1 260px; min-width: 150px; }
.search input { width: 100%; padding: 7px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (max-width: 760px) { .tabs { flex-wrap: wrap; } .search { flex: 1 1 100%; margin-left: 0; padding-left: 0; order: 9; } }
.chip.stale { background: var(--warn-bg); color: var(--warn-ink); }

/* ---------- NFT views ---------- */
.seg { display: inline-flex; gap: 2px; background: var(--sunk); padding: 2px; border-radius: 9px; }
.seg .btn { border-color: transparent; }
.seg .btn.on { background: var(--surface); border-color: var(--line); }
/* Tiles: compact, 2 across on a phone */
.nft-grid.view-tiles { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
@media (max-width: 520px) { .nft-grid.view-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.nft.tile .nft-body { padding: 8px 10px 10px; gap: 4px; }
.nft.tile .nft-name { font-size: 13px; }
.tile-nums { display: flex; justify-content: space-between; gap: 6px; font-family: var(--font-num); font-size: 12.5px; }
/* Large: big pictures, 1 across on a phone */
.nft-grid.view-large { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
@media (max-width: 520px) { .nft-grid.view-large { grid-template-columns: minmax(0, 1fr); } }
/* Detailed: one row per NFT */
.nft-grid.view-list { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.nft-row { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); cursor: pointer; }
.nft-row:first-child { border-top: 0; }
.nft-row:hover { background: var(--sunk); }
.nft-thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: var(--sunk); max-width: 100%; }
.nft-row-main { min-width: 0; display: grid; gap: 2px; }
.nft-row-nums { display: grid; grid-auto-flow: column; gap: 14px; margin: 0; text-align: right; font-size: 12.5px; }
.nft-row-nums dt { color: var(--muted); font-size: 11px; }
.nft-row-nums dd { margin: 0; font-family: var(--font-num); }
@media (max-width: 620px) {
  .nft-row { grid-template-columns: 48px minmax(0, 1fr); }
  .nft-thumb { width: 48px; height: 48px; }
  .nft-row-nums { grid-column: 2; grid-auto-flow: row; grid-template-columns: repeat(3, minmax(0, 1fr)); text-align: left; gap: 4px 10px; }
}
.drawer-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- value chart: ranges + hover ---------- */
.trend-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.range { display: inline-flex; gap: 2px; background: var(--sunk); padding: 2px; border-radius: 8px; }
.range button { border: 0; background: none; padding: 3px 9px; border-radius: 6px; font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer; }
.range button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }
.trend-change { font-size: 13px; font-weight: 500; }
.trend-plot { position: relative; touch-action: pan-y; cursor: crosshair; }
.trend-cross { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px dashed var(--muted); pointer-events: none; }
.trend-dot { position: absolute; left: -4.5px; width: 9px; height: 9px; margin-top: -4.5px; border-radius: 50%; background: var(--line-color, var(--accent)); box-shadow: 0 0 0 2px var(--surface); }
.trend-tip { position: absolute; top: -6px; transform: translate(-50%, -100%); background: var(--ink); color: var(--bg); padding: 4px 8px; border-radius: 6px;
             font-size: 12px; white-space: nowrap; pointer-events: none; display: grid; gap: 1px; text-align: center; z-index: 2; }
.trend-tip span { opacity: .75; font-size: 11px; }

.tile-reset { float: right; border: 0; background: none; color: var(--muted); font-size: 11px; cursor: pointer; padding: 0; text-decoration: underline; }
.tile-reset[data-confirm="1"] { color: var(--loss); }
