:root {
  --bg: #0b0f17;
  --surface: #121826;
  --surface-2: #182033;
  --border: #243049;
  --text: #e6ebf5;
  --muted: #8a96ad;
  --accent: #f7931a;
  --accent-2: #ffb454;
  --good: #3ecf8e;
  --warn: #f5b942;
  --bad: #ff5d6c;
  --radius: 12px;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body.busy { cursor: progress; }

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.good { color: var(--good); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }

/* ---------- header */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(18, 24, 38, 0.9);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(8px);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.logo {
  width: 22px; height: 22px; border-radius: 50%;
  background: conic-gradient(var(--accent), var(--accent-2), var(--accent));
  box-shadow: 0 0 12px rgba(247, 147, 26, 0.5);
}
.tag {
  font-size: 11px; font-weight: 500; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px;
}

.wallet { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.pill {
  border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px;
  font-size: 12px; color: var(--muted); background: var(--surface);
}
.pill.ok { color: var(--good); border-color: rgba(62, 207, 142, 0.4); }

/* ---------- layout */
.container { max-width: 1180px; margin: 0 auto; padding: 24px 24px 64px; }

.notice {
  border: 1px solid rgba(245, 185, 66, 0.4);
  background: rgba(245, 185, 66, 0.08);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 18px;
}
.notice code {
  display: block; margin: 4px 0; padding: 6px 10px; border-radius: 6px;
  background: var(--surface-2); font-family: var(--mono); font-size: 12px; overflow-x: auto;
}

.fee-banner {
  display: flex; gap: 14px; align-items: center;
  padding: 14px 18px; margin-bottom: 18px;
  border-radius: var(--radius);
  border: 1px solid rgba(247, 147, 26, 0.35);
  background: linear-gradient(90deg, rgba(247, 147, 26, 0.14), rgba(247, 147, 26, 0.03));
}
.fee-banner strong { font-size: 26px; color: var(--accent-2); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 22px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-value.small { font-size: 15px; }
.bar { height: 6px; border-radius: 999px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; transition: width 0.3s; }
.bar-fill.good { background: var(--good); }
.bar-fill.warn { background: var(--warn); }
.bar-fill.bad { background: var(--bad); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  background: none; border: 0; color: var(--muted); padding: 10px 14px; cursor: pointer;
  font: inherit; font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.panel h2 { font-size: 15px; margin: 18px 0 8px; }

/* ---------- tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-size: 12px; font-weight: 600; background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.sub { color: var(--muted); font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 28px; }
.actions { text-align: right; }
.actions .btn + .btn { margin-left: 6px; }

.asset { display: flex; align-items: center; gap: 10px; }
.sym { font-weight: 650; }
.icon {
  --h: 30;
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  font-size: 9px; font-weight: 700; letter-spacing: -0.02em;
  background: hsl(var(--h) 60% 22%); color: hsl(var(--h) 90% 75%);
  border: 1px solid hsl(var(--h) 60% 35%);
}

/* ---------- controls */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); padding: 8px 14px;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1205; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.danger { background: rgba(255, 93, 108, 0.15); border-color: rgba(255, 93, 108, 0.5); color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 12px; }

input, select {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
}
input:focus, select:focus { outline: 2px solid rgba(247, 147, 26, 0.5); outline-offset: 0; }

.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; transition: 0.2s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; border-radius: 50%; background: var(--muted); transition: 0.2s; }
.switch input:checked + span { background: rgba(62, 207, 142, 0.25); border-color: var(--good); }
.switch input:checked + span::before { transform: translateX(16px); background: var(--good); }
.switch input:disabled + span { opacity: 0.4; cursor: not-allowed; }

/* ---------- dev tools */
.dev-grid { 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; }
.card.wide { grid-column: 1 / -1; }
.card h3 { margin: 0 0 6px; font-size: 15px; }
.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.liq-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; }
.liq-form label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.liq-form label.check { flex-direction: row; align-items: center; gap: 8px; }
.price-controls { display: flex; gap: 6px; }
.price-controls input { width: 140px; }

/* ---------- modal */
dialog {
  width: min(460px, calc(100vw - 32px));
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 16px; padding: 22px;
}
dialog::backdrop { background: rgba(3, 6, 12, 0.7); backdrop-filter: blur(2px); }
dialog h3 { margin: 0 0 14px; }
.field { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.field-top { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.amount { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.amount input { flex: 1; min-width: 0; border: 0; background: transparent; font-size: 24px; padding: 2px 0; }
.amount input:focus { outline: none; }
.error { color: var(--bad); font-size: 12px; min-height: 18px; }
.fee-note { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
.preview { margin: 14px 0; display: grid; gap: 6px; }
.preview .row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.preview .row span:first-child { color: var(--muted); }
.preview .row span:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- rate chooser & loan chips */
.rate-chooser { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; border: 0; padding: 0; margin: 12px 0 0; }
.rate-chooser legend { float: left; margin-right: 6px; color: var(--muted); font-size: 12px; }
.seg { position: relative; }
.seg input { position: absolute; opacity: 0; }
.seg span {
  display: inline-block; padding: 6px 14px; border-radius: 8px; cursor: pointer; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
}
.seg input:checked + span { border-color: var(--accent); color: var(--accent-2); background: rgba(247, 147, 26, 0.12); }
.seg input:focus-visible + span { outline: 2px solid rgba(247, 147, 26, 0.5); }
.seg input:disabled + span { opacity: 0.4; cursor: not-allowed; }
.chip {
  display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 1px 7px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); margin-right: 4px;
}
.chip.fixed { border-color: rgba(62, 207, 142, 0.5); color: var(--good); }

/* ---------- toasts */
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 20; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 10px 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); word-break: break-word;
}
.toast.success { border-left-color: var(--good); }
.toast.error { border-left-color: var(--bad); }

@media (max-width: 760px) {
  .container { padding: 16px 16px 48px; }
  .topbar { padding: 12px 16px; }
  .stats, .dev-grid, .liq-form { grid-template-columns: minmax(0, 1fr); }
  .fee-banner { flex-direction: column; align-items: flex-start; }
}
