:root {
  --bg: #0f0f10;
  --surface: #18181a;
  --surface-2: #202023;
  --border: #2a2a2e;
  --text: #f5f5f7;
  --muted: #9b9ba3;
  --faint: #6b6b73;
  --accent: #fc72ff;
  --accent-soft: rgba(252, 114, 255, 0.14);
  --green: #40b66b;
  --green-soft: rgba(64, 182, 107, 0.14);
  --red: #ff5f52;
  --red-soft: rgba(255, 95, 82, 0.14);
  --amber: #ffbf17;
  --amber-soft: rgba(255, 191, 23, 0.14);
  --radius: 16px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 14px; line-height: 1.45; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 24px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: rgba(15, 15, 16, 0.92); backdrop-filter: blur(8px); z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: -0.01em; }
.brand .sub { margin: 0; color: var(--muted); font-size: 12px; }
.logo { width: 34px; height: 34px; border-radius: 10px; background: url("/favicon.svg") center / cover; }
.status { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.sync::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); margin-right: 6px; vertical-align: 1px; }
.sync.live::before { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.sync.stale::before { background: var(--amber); }
.sync.error::before { background: var(--red); }

main { max-width: 1240px; margin: 0 auto; padding: 20px 24px 40px; }

.btn { border: 1px solid var(--border); background: var(--surface-2); border-radius: 12px; padding: 9px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #3a3a40; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1b041c; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; padding: 6px 10px; font-size: 16px; line-height: 1; }
.btn:disabled { opacity: 0.5; cursor: default; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.wallet-form { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(0, 1fr) auto; gap: 8px; }
.wallet-form input { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 9px 12px; min-width: 0; }
.wallet-form input:focus, select:focus { outline: none; border-color: var(--accent); }
.form-error { color: var(--red); margin: 6px 2px 0; min-height: 0; font-size: 13px; }
.form-error:empty { display: none; }
.wallet-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.wallet-list:empty { display: none; }
.wallet-chip { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 7px 8px 7px 12px; }
.wallet-chip .name { font-weight: 600; }
.wallet-chip .addr { color: var(--muted); font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }
.wallet-chip .meta { color: var(--muted); font-size: 12px; }
.wallet-chip button { border: 0; background: transparent; color: var(--faint); cursor: pointer; font-size: 16px; padding: 0 4px; line-height: 1; }
.wallet-chip button:hover { color: var(--red); }
.empty-hint { color: var(--muted); margin: 10px 2px 0; }

.sweep { margin-top: 12px; color: var(--muted); font-size: 12px; }
.progress { height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width 0.4s; }

.banner { border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; font-size: 13px; }
.banner.error { background: var(--red-soft); color: #ffb3ad; border: 1px solid rgba(255, 95, 82, 0.35); }
.banner.warn { background: var(--amber-soft); color: #ffe08a; border: 1px solid rgba(255, 191, 23, 0.3); }

.totals { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 16px 0; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--muted); font-size: 12px; }
.tile .value { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; }
.tile .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tile .value.green { color: var(--green); }
.tile .value.red { color: var(--red); }
.tile .value.amber { color: var(--amber); }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 12px; cursor: pointer; color: var(--muted); }
.chip .n { color: var(--faint); margin-left: 4px; }
.chip.active { background: var(--accent-soft); border-color: rgba(252, 114, 255, 0.45); color: var(--text); }
.toolbar-right { display: flex; gap: 8px; }
select { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 7px 10px; }

.positions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.card.danger { border-color: rgba(255, 95, 82, 0.55); }
.card.warn { border-color: rgba(255, 191, 23, 0.45); }
.card.closed { opacity: 0.7; }

.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.pair { display: flex; align-items: center; gap: 10px; min-width: 0; }
.icons { display: flex; flex: none; }
.icon { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; border: 2px solid var(--surface); color: #111; }
.icon + .icon { margin-left: -9px; }
.pair-name { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badges { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 3px; }
.badge { font-size: 11px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; white-space: nowrap; }
.badge.warn { color: var(--amber); border-color: rgba(255, 191, 23, 0.35); }
.badge.bad { color: var(--red); border-color: rgba(255, 95, 82, 0.4); }
.badge.ok { color: var(--green); border-color: rgba(64, 182, 107, 0.35); }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.in { color: var(--green); background: var(--green-soft); }
.pill.out { color: var(--red); background: var(--red-soft); }
.pill.closed { color: var(--muted); background: var(--surface-2); }
.head-right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.edge-alert { font-size: 12px; font-weight: 600; }
.edge-alert.danger { color: var(--red); }
.edge-alert.warn { color: var(--amber); }

.money { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.money .label { color: var(--muted); font-size: 12px; }
.money .big { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.money .big.fees { color: var(--green); }
.token-line { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); margin-top: 2px; }
.token-line b { color: var(--text); font-weight: 500; }
.comp { display: flex; height: 4px; border-radius: 4px; overflow: hidden; margin-top: 8px; background: var(--surface-2); }
.comp > span:first-child { background: var(--accent); }
.comp > span:last-child { background: #7c8cff; }

.range { background: var(--surface-2); border-radius: 12px; padding: 12px; }
.range-head { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.range-head button { border: 1px solid var(--border); background: transparent; border-radius: 8px; padding: 2px 8px; cursor: pointer; color: var(--muted); }
.range-head button:hover { color: var(--text); }
.bar { position: relative; height: 10px; margin: 6px 6px 12px; }
.bar .track { position: absolute; inset: 3px 0; border-radius: 4px; background: #2d2d33; }
.bar .fill { position: absolute; top: 3px; bottom: 3px; border-radius: 4px; background: var(--green-soft); border: 1px solid rgba(64, 182, 107, 0.5); }
.bar.out .fill { background: var(--red-soft); border-color: rgba(255, 95, 82, 0.45); }
.bar .dot { position: absolute; top: -3px; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%; background: var(--text); border: 3px solid var(--surface-2); box-shadow: 0 0 0 1px #555; }
.bar.out .dot { background: var(--red); }
.bar.edge .dot { background: var(--amber); }
.bar.closed .fill { background: #2d2d33; border-color: #3a3a40; }
.bar.closed .dot { background: var(--faint); }
.prices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; text-align: center; }
.prices .k { color: var(--muted); font-size: 11px; }
.prices .v { font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.prices .v.cur { color: var(--accent); }
.distances { display: flex; justify-content: space-between; gap: 8px; margin-top: 10px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.distances b { font-variant-numeric: tabular-nums; }
.distances .near { color: var(--amber); }
.distances .danger { color: var(--red); }
.out-note { margin-top: 10px; font-size: 12px; color: #ffb3ad; }

.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; flex-wrap: wrap; }
.links { display: flex; gap: 12px; }
.links a { color: var(--muted); text-decoration: none; }
.links a:hover { color: var(--accent); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

.placeholder { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 48px 16px; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.foot { max-width: 1240px; margin: 0 auto; padding: 0 24px 32px; color: var(--faint); font-size: 12px; }
sub { font-size: 0.7em; vertical-align: -0.25em; }

/* wallet connection */
.wallet-button { position: relative; }
.wallet-btn { display: inline-flex; align-items: center; gap: 8px; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }
.wallet-btn.warn { border-color: rgba(255, 191, 23, 0.5); color: var(--amber); }
.wallet-btn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.wallet-btn .dot.warn { background: var(--amber); }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 6px; z-index: 20; box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45); }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: transparent; border: 0; border-radius: 8px; padding: 9px 10px; cursor: pointer; color: var(--text); }
.menu button:hover { background: var(--surface); }
.menu img { width: 20px; height: 20px; border-radius: 5px; }
.menu-empty { color: var(--muted); font-size: 13px; padding: 8px 10px; max-width: 280px; }
.connect-hint { margin-top: 12px; color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.connect-hint[hidden] { display: none; }
.wallet-chip.connected { border-color: rgba(64, 182, 107, 0.45); }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn.wide { width: 100%; padding: 12px; font-size: 15px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* remove / collect dialog */
.dialog { border: 1px solid var(--border); border-radius: 20px; background: var(--surface); color: var(--text); padding: 0; width: min(460px, calc(100vw - 24px)); max-height: calc(100vh - 24px); }
.dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.dialog-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.dialog-title { font-size: 18px; font-weight: 600; }
.muted { color: var(--muted); font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.field-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }
.field-head b { color: var(--text); font-size: 20px; }
.field input[type="range"] { width: 100%; accent-color: var(--accent); }
.preview { background: var(--surface-2); border-radius: 12px; padding: 12px; min-height: 48px; }
.preview.muted { display: grid; place-items: center; }
.preview-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; color: var(--muted); font-size: 13px; }
.preview-head b { color: var(--text); font-size: 20px; }
.preview-sub { color: var(--faint); font-size: 12px; margin-top: 10px; }
.sim { margin-top: 10px; font-size: 13px; }
.sim.ok { color: var(--green); }
.sim.bad { color: var(--red); }
.tx-list { display: flex; flex-direction: column; gap: 6px; }
.tx-line { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.tx-line a { color: var(--accent); text-decoration: none; }
.tx-line.success span:last-child { color: var(--green); }
.tx-line.reverted span:last-child { color: var(--red); }
.dialog-status { font-size: 13px; color: var(--muted); }
.dialog-status.ok { color: var(--green); font-weight: 600; }
.dialog-error { font-size: 13px; color: #ffb3ad; background: var(--red-soft); border-radius: 10px; padding: 8px 10px; }
.fineprint { margin: 0; color: var(--faint); font-size: 11px; }
.amount-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px; }
.amount-box:focus-within { border-color: rgba(252, 114, 255, 0.55); }
.amount-box.off { opacity: 0.5; }
.amount-row { display: flex; align-items: center; gap: 10px; }
.amount-row input { flex: 1; min-width: 0; background: transparent; border: 0; outline: none; font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.amount-row input:disabled { cursor: not-allowed; }
.amount-symbol { font-weight: 600; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; white-space: nowrap; max-width: 45%; overflow: hidden; text-overflow: ellipsis; }
.amount-meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; margin-top: 4px; min-height: 16px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: 12px; }
.link:disabled { color: var(--faint); cursor: default; }
.preview-sub.warn { color: var(--amber); }

@media (max-width: 900px) {
  .positions { grid-template-columns: minmax(0, 1fr); }
  .totals { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  main { padding: 14px 12px 32px; }
  .topbar { padding: 10px 12px; }
  .brand .sub { display: none; }
  .sync { display: none; }
  .wallet-form { grid-template-columns: minmax(0, 1fr); }
  .toolbar-right { width: 100%; }
  .toolbar-right select { flex: 1; min-width: 0; }
  .money { grid-template-columns: minmax(0, 1fr); }
  .tile .value { font-size: 20px; }
}
