:root {
  --bg: #0b0d12;
  --surface: #14171f;
  --surface-2: #1b1f29;
  --line: rgba(255, 255, 255, 0.06);
  --text: #f3f5f9;
  --muted: #8a92a3;
  --faint: #5a6273;
  --accent: #8ea8ff;
  --accent-ink: #0b0d12;
  --gain: #3ddc97;
  --loss: #ff6b6b;
  --warn: #f5b84a;
  --radius: 18px;
  --radius-sm: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", Roboto, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
img { display: block; }
[hidden] { display: none !important; }

.i {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.i.sm { width: 16px; height: 16px; }
.i.xs { width: 13px; height: 13px; stroke-width: 2.4; }

/* ---------- Shell ---------- */
.app {
  display: flex; flex-direction: column;
  height: 100%; max-width: 560px; margin: 0 auto;
}
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 20px 6px;
}
.top h1 { margin: 0; font-size: 28px; font-weight: 750; letter-spacing: -0.02em; }
.top-right { display: flex; align-items: center; gap: 10px; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); transition: background .3s; }
.conn.ok { background: var(--gain); box-shadow: 0 0 0 4px rgba(61, 220, 151, .12); }
.conn.err { background: var(--loss); }

.icon-btn {
  position: relative;
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface); color: var(--text);
  transition: transform .15s, background .15s;
}
.icon-btn:active { transform: scale(.92); background: var(--surface-2); }
.icon-btn.sm { width: 34px; height: 34px; }
.icon-btn.sm .i { width: 18px; height: 18px; }
.icon-btn.spin .i { animation: spin 1s linear infinite; }
.pip { position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); }

main { flex: 1; overflow: hidden; position: relative; }
.view {
  position: absolute; inset: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 8px 20px 24px;
  opacity: 0; pointer-events: none; transform: translateY(6px);
  transition: opacity .2s, transform .2s;
}
.view.active { opacity: 1; pointer-events: auto; transform: none; }

.tabs {
  display: flex; justify-content: space-around;
  padding: 8px 32px calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(11, 13, 18, .92);
  backdrop-filter: blur(16px);
}
.tab {
  position: relative; width: 64px; height: 44px; border-radius: 14px;
  display: grid; place-items: center; color: var(--faint);
  transition: color .2s, background .2s;
}
.tab.active { color: var(--text); background: var(--surface); }
.tab .i { width: 24px; height: 24px; }
.count {
  position: absolute; top: 4px; right: 12px;
  min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 11px; font-weight: 750; line-height: 17px; text-align: center;
}

.offline {
  display: flex; align-items: center; gap: 10px;
  margin: 4px 20px 0; padding: 10px 14px; border-radius: var(--radius-sm);
  background: rgba(255, 107, 107, .1); color: #ffb4b4; font-size: 14px;
}
.offline .i { width: 18px; height: 18px; }
.offline span { flex: 1; }
.link { color: var(--text); font-weight: 650; }

/* ---------- Amounts (Value / RAP) ---------- */
.amt { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt .i { width: 13px; height: 13px; }
.amt.rap { color: var(--muted); font-weight: 600; }
.amt.rap .i { width: 12px; height: 12px; }
.dot-sep { display: inline-block; width: 3px; height: 3px; border-radius: 50%; background: var(--faint); margin: 0 10px; vertical-align: middle; }
.i.muted { color: var(--faint); }

/* ---------- Avatars ---------- */
.avatar {
  border-radius: 50%; background: var(--surface-2); object-fit: cover; flex: none;
  display: grid; place-items: center; color: var(--muted); font-weight: 700; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Portfolio ---------- */
.accounts { display: flex; gap: 8px; margin: 6px 0 4px; overflow-x: auto; scrollbar-width: none; }
.accounts::-webkit-scrollbar { display: none; }
.acct {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 14px 4px 4px; border-radius: 999px;
  background: var(--surface); color: var(--muted); font-weight: 600; font-size: 14px;
  border: 1px solid transparent; transition: all .2s; flex: none;
}
.acct .avatar { width: 30px; height: 30px; font-size: 13px; position: relative; }
.acct.active { color: var(--text); border-color: rgba(142, 168, 255, .45); background: rgba(142, 168, 255, .08); }
.acct .live { width: 6px; height: 6px; border-radius: 50%; background: var(--gain); }

.hero { padding: 18px 0 20px; }
.hero-value { font-size: 46px; font-weight: 780; letter-spacing: -0.035em; line-height: 1; font-variant-numeric: tabular-nums; }
.hero-value .amt { gap: 10px; font-weight: 780; }
.hero-value .amt .i { width: 30px; height: 30px; }
.hero-sub { margin-top: 10px; color: var(--muted); font-size: 14px; display: flex; align-items: center; }

.goal {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px; margin-bottom: 10px;
  background: var(--surface); border-radius: var(--radius);
}
.goal .thumb { width: 52px; height: 52px; }
.goal-body { flex: 1; min-width: 0; }
.goal-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.goal-name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.goal-pct { font-weight: 750; font-variant-numeric: tabular-nums; }
.bar { height: 6px; margin: 8px 0 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg, #6f8cff, #b1c2ff); transition: width .6s cubic-bezier(.2, .8, .2, 1); }
.goal-sub { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.goal-sub .amt { color: var(--text); }

.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.tile {
  position: relative; text-align: left; min-width: 0;
  background: var(--surface); border-radius: var(--radius); padding: 8px 8px 10px;
  transition: transform .15s;
}
.tile:active { transform: scale(.96); }
.tile .thumb { width: 100%; aspect-ratio: 1; }
.tile-name { margin-top: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-amts { display: flex; flex-direction: column; gap: 1px; margin-top: 2px; }
.tile .flag {
  position: absolute; top: 8px; right: 8px;
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(11, 13, 18, .75);
}
.flag.hold { color: var(--warn); }
.flag.rise { color: var(--gain); }
.flag.fall { color: var(--loss); }

.thumb {
  border-radius: 12px; background: radial-gradient(circle at 50% 35%, #232838, #171a23);
  display: grid; place-items: center; overflow: hidden; color: var(--faint);
}
.thumb img { width: 88%; height: 88%; object-fit: contain; }
.thumb img ~ .i { display: none; }

/* ---------- Trades ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 10px 0 10px; }
.section-head h2 { margin: 0; font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; background: var(--surface); border-radius: var(--radius-sm); margin-bottom: 8px;
}
.row .avatar { width: 38px; height: 38px; font-size: 15px; }
.row-body { flex: 1; min-width: 0; }
.row-title { font-weight: 650; display: flex; align-items: center; gap: 6px; }
.row-sub { color: var(--muted); font-size: 13px; }
.dir-out { color: var(--accent); }
.dir-in { color: var(--gain); }

.card { background: var(--surface); border-radius: var(--radius); padding: 14px; }
.card.done { opacity: .55; }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-head .avatar { width: 34px; height: 34px; font-size: 14px; }
.card-head .who { flex: 1; min-width: 0; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side { margin-top: 14px; }
.side-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 12px; color: var(--faint); text-transform: uppercase; letter-spacing: .08em; }
.side-total { display: flex; gap: 10px; font-size: 15px; letter-spacing: 0; text-transform: none; color: var(--text); }
.ti-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.ti { min-width: 0; display: flex; flex-direction: column; gap: 1px; font-size: 12px; }
.ti .thumb { width: 100%; aspect-ratio: 1; margin-bottom: 4px; }
.ti-name { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ti .amt .i { width: 11px; height: 11px; }
.deltas { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0 12px; }
.pill { display: flex; align-items: center; justify-content: center; gap: 5px; height: 34px; border-radius: 10px; font-variant-numeric: tabular-nums; font-size: 14px; }
.pill .i { width: 14px; height: 14px; }
.pill span { opacity: .75; font-size: 12px; }
.pill.pos { background: rgba(61, 220, 151, .1); color: var(--gain); }
.pill.neg { background: rgba(255, 107, 107, .1); color: var(--loss); }
.pill.flat { background: var(--surface-2); color: var(--muted); }
.delta { font-weight: 750; font-variant-numeric: tabular-nums; font-size: 15px; }
.delta.pos { color: var(--gain); }
.delta.neg { color: var(--loss); }
.delta.flat { color: var(--muted); }


.why { color: var(--muted); font-size: 13px; line-height: 1.45; margin: 10px 0 0; }

.actions { display: flex; gap: 8px; }
.btn {
  flex: 1; height: 44px; border-radius: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--surface-2); font-weight: 650; font-size: 15px;
  transition: transform .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--text); color: var(--bg); }
.btn.danger { background: rgba(255, 107, 107, .12); color: var(--loss); }
.btn.square { flex: none; width: 44px; }
.btn .i { width: 18px; height: 18px; }
.status { font-size: 12px; font-weight: 650; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); text-transform: capitalize; }
.status.sent { color: var(--gain); background: rgba(61, 220, 151, .1); }
.status.staged { color: var(--accent); background: rgba(142, 168, 255, .1); }
.status.error { color: var(--loss); background: rgba(255, 107, 107, .1); }

.empty { text-align: center; color: var(--faint); padding: 48px 0 24px; }
.empty .i { width: 34px; height: 34px; margin-bottom: 10px; }

/* ---------- Chat ---------- */
.view.chat { display: flex; flex-direction: column; padding-bottom: 12px; overflow: hidden; }
.messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 0 12px; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: 18px; font-size: 15px; line-height: 1.45; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--text); color: var(--bg); border-bottom-right-radius: 6px; }
.msg.agent { align-self: flex-start; background: var(--surface); border-bottom-left-radius: 6px; }
.msg p { margin: 0 0 8px; } .msg p:last-child { margin: 0; }
.msg ul { margin: 4px 0 8px; padding-left: 18px; }
.msg code { font: 13px ui-monospace, Menlo, monospace; background: rgba(255, 255, 255, .07); padding: 1px 5px; border-radius: 5px; }
.msg pre { background: rgba(0, 0, 0, .3); padding: 10px; border-radius: 10px; overflow-x: auto; }
.msg pre code { background: none; padding: 0; }
.msg a { color: var(--accent); }
.typing { display: inline-flex; gap: 4px; padding: 14px 16px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 8px 14px; border-radius: 999px; background: var(--surface); color: var(--muted); font-size: 14px; font-weight: 550; }
.chip:active { color: var(--text); }
.composer { display: flex; gap: 8px; align-items: center; padding: 6px 6px 6px 16px; background: var(--surface); border-radius: 999px; }
.composer input { flex: 1; background: none; border: 0; outline: 0; height: 36px; min-width: 0; }
.composer input::placeholder { color: var(--faint); }
.send { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--text); color: var(--bg); }
.send:disabled { opacity: .4; }
.send .i { width: 18px; height: 18px; }

/* ---------- Sheet ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); opacity: 0; transition: opacity .25s; z-index: 10; }
.scrim.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  max-width: 560px; margin: 0 auto; max-height: 88vh; overflow-y: auto;
  padding: 8px 20px calc(24px + var(--safe-bottom));
  background: var(--surface); border-radius: 24px 24px 0 0;
  transform: translateY(105%); transition: transform .3s cubic-bezier(.2, .8, .2, 1);
}
.sheet.show { transform: none; }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--surface-2); margin: 0 auto 14px; }
.sheet h3 { margin: 0 0 14px; font-size: 20px; font-weight: 720; }

.detail-img { width: 168px; height: 168px; margin: 4px auto 14px; border-radius: 24px; }
.detail-name { text-align: center; font-size: 20px; font-weight: 720; }
.detail-value { display: flex; justify-content: center; align-items: center; gap: 10px; text-align: center; font-size: 34px; font-weight: 780; letter-spacing: -0.03em; margin: 6px 0 16px; font-variant-numeric: tabular-nums; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.fact { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.fact b { display: flex; align-items: center; gap: 6px; font-size: 16px; font-variant-numeric: tabular-nums; }
.fact span { font-size: 12px; color: var(--muted); }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; margin-bottom: 10px; }
.seg button { flex: 1; height: 36px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 14px; }
.seg button.active { background: var(--bg); color: var(--text); }
.field { width: 100%; height: 44px; padding: 0 14px; border-radius: 12px; border: 0; outline: 0; background: var(--surface-2); margin-bottom: 10px; font-size: 14px; }
.setting { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.setting:first-of-type { border-top: 0; }
.setting .row-body { flex: 1; }
.label { font-size: 12px; color: var(--faint); text-transform: uppercase; letter-spacing: .08em; margin: 18px 0 8px; }
.shot { width: 100%; border-radius: 14px; margin-top: 12px; background: var(--surface-2); }

/* ---------- Toast / skeleton ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + var(--safe-bottom)); z-index: 20;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 40px); padding: 11px 18px; border-radius: 999px;
  background: var(--text); color: var(--bg); font-weight: 600; font-size: 14px;
  transition: all .25s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.skel, .skel-text {
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 10px; color: transparent !important;
}
.skel-text { display: inline-block; min-width: 140px; }
.tile.skel { height: 150px; }

@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

@media (max-width: 360px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero-value { font-size: 40px; }
}

a.btn { display: flex; width: 100%; color: var(--text); text-decoration: none; }

/* ---------- Agent ---------- */
.agent-ind {
  height: 32px; min-width: 32px; padding: 0 10px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 6px; background: var(--surface);
}
.agent-ind b { font-size: 12px; font-weight: 750; color: var(--accent-ink); }
.agent-ind.needs { background: var(--warn); }
.agent-ind.needs .dots i { background: var(--accent-ink); }
.dots { display: inline-flex; gap: 3px; align-items: center; }
.dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--gain); opacity: .35; }
.dots i:nth-child(2) { opacity: .65; }
.dots i:nth-child(3) { opacity: 1; }
/* Idle: one slow breath. Busy: the three dots take turns, like someone typing. */
.agent-ind:not(.busy) .dots i, .agent-status:not(.busy) .dots i { animation: breathe 3.2s ease-in-out infinite; }
.busy .dots i { background: var(--accent); opacity: .25; animation: blink 1.1s infinite; }
.busy .dots i:nth-child(2) { animation-delay: .18s; }
.busy .dots i:nth-child(3) { animation-delay: .36s; }
.paused .dots i { background: var(--faint); animation: none; }
@keyframes breathe { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }

.agent-status {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 14px; margin-bottom: 8px; border-radius: 14px;
  background: var(--surface); color: var(--muted); font-size: 13px; text-align: left;
}
.agent-status .as-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-status .as-plan { color: var(--text); font-weight: 650; }
.agent-status.needs { color: var(--warn); }
.agent-status.busy .as-text { color: var(--text); }

.count.warn { background: var(--warn); }

.msg-trigger { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--faint); margin: 6px 0 -4px 4px; }
.msg-tools { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 2px 4px; }
.msg-tools span { font-size: 11px; color: var(--faint); background: var(--surface); padding: 3px 9px; border-radius: 999px; }

.card.approval { border: 1px solid rgba(245, 184, 74, .35); align-self: stretch; }
.card.approval:not(.pending) { border-color: transparent; }
.card.approval.denied, .card.approval.expired { opacity: .55; }
.ap-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.ap-verb { font-size: 12px; font-weight: 700; color: var(--warn); text-transform: uppercase; letter-spacing: .08em; }
.card.approval:not(.pending) .ap-verb { color: var(--faint); }
.card.approval .card-head { margin-top: 8px; }
.flag-line { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--warn); margin: 0 0 8px; }
.flag-line .i { margin-top: 1px; flex: none; }
.tags { display: flex; gap: 6px; margin: 10px 0; }
.chip.sm { padding: 4px 10px; font-size: 12px; }

.plan-text { font-size: 15px; line-height: 1.5; }
.plan-text p { margin: 0 0 8px; }
.plan-text ul { margin: 0 0 8px; padding-left: 18px; }
.muted { color: var(--muted); }
.field.area { height: 96px; padding: 12px 14px; resize: none; line-height: 1.4; }
.watch { display: flex; flex-direction: column; gap: 6px; }
.watch-row { display: flex; flex-direction: column; background: var(--surface-2); border-radius: 12px; padding: 9px 12px; font-size: 13px; }
.watch-row span { color: var(--muted); }
