/* ---------- Buttons: one height, one radius ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: var(--control-h); padding: 0 var(--sp-5); border-radius: var(--r-md);
  border: 1px solid transparent; font-size: var(--fs-md); font-weight: 600; line-height: 1;
  text-decoration: none; transition: background-color .15s, border-color .15s, opacity .15s;
  -webkit-tap-highlight-color: transparent; user-select: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--card); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--input); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { color: var(--text); background: var(--card); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2f2f; }
.btn-danger-outline { background: transparent; color: var(--danger); border-color: var(--border); }
.btn-danger-outline:hover { background: var(--danger-tint); }
.btn-block { width: 100%; }
.btn-sm { height: var(--control-h-sm); padding: 0 var(--sp-4); font-size: var(--fs-sm); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; pointer-events: none; }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: var(--tap); height: var(--tap);
  border-radius: var(--r-md); border: 0; background: transparent; color: var(--text); position: relative;
}
.icon-btn:hover { background: var(--card); text-decoration: none; }

/* ---------- Forms ---------- */
.field { display: block; }
.field > label, .field-label { display: block; font-size: var(--fs-sm); color: var(--text-2); margin-bottom: var(--sp-2); font-weight: 500; }
.input-wrap { position: relative; display: flex; align-items: center; }
.input, .select, .textarea {
  width: 100%; height: var(--control-h); padding: 0 var(--sp-4); background: var(--input);
  color: var(--text); border: 1px solid var(--border); border-radius: var(--r-md); font-size: var(--fs-md);
  transition: border-color .15s; appearance: none; -webkit-appearance: none;
}
.textarea { height: auto; min-height: 96px; padding: var(--sp-3) var(--sp-4); resize: vertical; }
.select { padding-right: 40px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23A0A0A0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; }
.input:hover, .select:hover { border-color: #353535; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); }
.input:disabled, .select:disabled { opacity: .5; cursor: not-allowed; }
.input-wrap .input-icon { position: absolute; left: var(--sp-4); color: var(--muted); pointer-events: none; display: flex; }
.input-wrap .input-icon + .input { padding-left: 44px; }
.input-wrap .input-action { position: absolute; right: 4px; }
.field.has-error .input, .field.has-error .select { border-color: var(--danger); }
.field-error { display: none; margin-top: var(--sp-2); font-size: var(--fs-sm); color: var(--danger); }
.field.has-error .field-error { display: block; }
.field-hint { margin-top: var(--sp-2); font-size: var(--fs-xs); color: var(--muted); }
.check { display: flex; align-items: flex-start; gap: var(--sp-3); font-size: var(--fs-sm); color: var(--text-2); }
.check input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--primary); flex: none; }

/* Choice chips (e.g. Crypto / Forex / Both) built on radio inputs */
.choice-group { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); }
.choice { position: relative; }
.choice input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
.choice span {
  display: flex; align-items: center; justify-content: center; gap: var(--sp-2); height: 44px;
  border: 1px solid var(--border); background: var(--input); border-radius: var(--r-md);
  font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); transition: border-color .15s, color .15s, background-color .15s;
}
.choice input:checked + span { border-color: var(--primary); color: var(--text); background: var(--primary-tint); }
.choice input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Tabs / segmented control ---------- */
.tabs { display: flex; padding: 4px; gap: 4px; background: var(--card); border: 1px solid var(--border); border-radius: var(--r-md); }
.tab {
  flex: 1; height: 38px; display: inline-flex; align-items: center; justify-content: center; border: 0; background: transparent;
  color: var(--text-2); border-radius: 9px; font-size: var(--fs-sm); font-weight: 600; text-decoration: none;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab[aria-selected="true"], .tab.is-active { background: var(--primary); color: #fff; }

/* ---------- Cards ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-5); }
.card-flush { padding: 0; overflow: hidden; }
.card-title { font-size: var(--fs-sm); color: var(--text-2); font-weight: 500; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: var(--sp-6) 0 var(--sp-3); }
.section-head h2 { font-size: var(--fs-lg); }

.figure { font-size: var(--fs-figure); font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.figure-sm { font-size: var(--fs-xl); font-weight: 600; }
.delta { font-size: var(--fs-sm); font-weight: 600; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: var(--r-full); font-size: var(--fs-xs); font-weight: 600; background: var(--input); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.badge-success { background: var(--success-tint); color: var(--success); border-color: transparent; }
.badge-danger { background: var(--danger-tint); color: var(--danger); border-color: transparent; }
.badge-warning { background: var(--warning-tint); color: var(--warning); border-color: transparent; }
.badge-primary { background: var(--primary-tint); color: #A98DF5; border-color: transparent; }
.badge-sim { background: transparent; color: var(--warning); border: 1px solid var(--warning); letter-spacing: .02em; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot-success { background: var(--success); } .dot-danger { background: var(--danger); } .dot-warning { background: var(--warning); }

/* ---------- List rows ---------- */
.list { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: var(--sp-3); min-height: 56px; padding: var(--sp-3) var(--sp-4); color: var(--text); border-top: 1px solid var(--border); text-decoration: none; }
.list-row:first-child { border-top: 0; }
a.list-row:hover { background: var(--input); text-decoration: none; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .lead { color: var(--text-2); display: flex; }
.list-row .trail { color: var(--muted); display: flex; }
.coin { width: 36px; height: 36px; border-radius: 50%; background: var(--input); border: 1px solid var(--border); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: var(--fs-xs); color: var(--text); flex: none; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Tables (stack into labelled rows on mobile) ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th { text-align: left; color: var(--muted); font-weight: 500; padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: 0; }
.table .t-right { text-align: right; }
@media (max-width: 640px) {
  .table.table-stack thead { display: none; }
  .table.table-stack, .table.table-stack tbody, .table.table-stack tr, .table.table-stack td { display: block; width: 100%; }
  .table.table-stack tr { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
  .table.table-stack tr:last-child { border-bottom: 0; }
  .table.table-stack td { display: flex; justify-content: space-between; gap: var(--sp-4); padding: 6px 0; border: 0; text-align: right; }
  .table.table-stack td::before { content: attr(data-label); color: var(--muted); text-align: left; }
}

/* ---------- Alerts / states ---------- */
.alert { display: flex; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); font-size: var(--fs-sm); border: 1px solid var(--border); background: var(--card); color: var(--text-2); }
.alert .icon { flex: none; margin-top: 1px; }
.alert-info .icon { color: var(--primary); }
.alert-success { background: var(--success-tint); border-color: transparent; color: var(--text); } .alert-success .icon { color: var(--success); }
.alert-warning { background: var(--warning-tint); border-color: transparent; color: var(--text); } .alert-warning .icon { color: var(--warning); }
.alert-danger { background: var(--danger-tint); border-color: transparent; color: var(--text); } .alert-danger .icon { color: var(--danger); }

.state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-3); padding: var(--sp-10) var(--sp-6); color: var(--text-2); }
.state .icon { color: var(--muted); }
.state h3 { color: var(--text); font-size: var(--fs-md); }
.state p { font-size: var(--fs-sm); max-width: 320px; }

.skeleton { background: var(--input); border-radius: var(--r-sm); min-height: 14px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

.toast-region { position: fixed; z-index: 100; left: 0; right: 0; bottom: calc(var(--bottomnav-h) + 16px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); pointer-events: none; padding: 0 var(--sp-4); }
.toast { pointer-events: auto; display: flex; align-items: center; gap: var(--sp-3); max-width: 420px; width: 100%; padding: var(--sp-3) var(--sp-4); background: var(--card); border: 1px solid var(--border); border-radius: var(--r-md); font-size: var(--fs-sm); }
.toast.success { border-left: 3px solid var(--success); } .toast.error { border-left: 3px solid var(--danger); } .toast.info { border-left: 3px solid var(--primary); }

.progress { height: 6px; background: var(--input); border-radius: var(--r-full); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: var(--r-full); }

.risk-note { font-size: var(--fs-xs); color: var(--muted); line-height: 1.5; }
.avatar { width: 64px; height: 64px; border-radius: 50%; background: var(--primary-tint); color: #fff; border: 1px solid var(--primary); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: var(--fs-lg); }

@media (min-width: 1024px) { .toast-region { bottom: 24px; } }

.form-alert[hidden] { display: none; }
.legal { max-width: 560px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: var(--fs-sm); }
.field > label.check { display: flex; margin-bottom: 0; font-weight: 400; }

/* Notifications bell */
.bell-dot { position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--primary); color: #fff; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }

/* Stat tiles */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.stat { background: var(--input); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4); }
.stat .label { font-size: var(--fs-xs); color: var(--muted); }
.stat .value { font-size: var(--fs-lg); font-weight: 600; margin-top: 2px; }
.settings-list .list-row .lead { width: 36px; height: 36px; border-radius: var(--r-md); background: var(--input); align-items: center; justify-content: center; }
.row-pending { opacity: .6; }
.price-cell { text-align: right; }
.unread-row { border-left: 3px solid var(--primary); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); min-height: 56px; padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border); }
.switch-row:first-child { border-top: 0; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: var(--r-full); background: var(--input); border: 1px solid var(--border); transition: background-color .15s; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--text-2); transition: transform .15s, background-color .15s; }
.switch input:checked + span { background: var(--primary); border-color: var(--primary); }
.switch input:checked + span::after { transform: translateX(18px); background: #fff; }
.switch input:disabled { cursor: not-allowed; } .switch input:disabled + span { opacity: .55; }
.switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.block { display: block; }
.btn.disabled { opacity: .45; pointer-events: none; }

/* Plans */
.plan-group { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.plan { position: relative; display: block; }
.plan input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.plan-body { display: flex; flex-direction: column; gap: 4px; align-items: center; text-align: center; padding: var(--sp-5) var(--sp-3); background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg); transition: border-color .15s, background-color .15s; }
.plan input:checked + .plan-body { border-color: var(--primary); background: var(--primary-tint); }
.plan input:focus-visible + .plan-body { outline: 2px solid var(--primary); outline-offset: 2px; }
/* Order progress */
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-3); }
.steps li { display: flex; align-items: center; gap: var(--sp-3); color: var(--muted); font-size: var(--fs-sm); }
.steps .dotn { width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--border); display: inline-flex; align-items: center; justify-content: center; font-size: var(--fs-xs); flex: none; }
.steps li.now { color: var(--text); } .steps li.now .dotn { border-color: var(--primary); color: var(--primary); }
.steps li.done { color: var(--text-2); } .steps li.done .dotn { background: var(--success); border-color: var(--success); color: #fff; }
.coin-lg { width: 52px; height: 52px; align-self: center; }
.left { text-align: left; } .pre { white-space: pre-wrap; }
.stack > .steps { margin-top: var(--sp-4); }

/* Wallet */
.row-center { justify-content: center; } .right { text-align: right; min-width: 0; overflow-wrap: anywhere; }
.center-badge { align-self: center; }
.addr { font-size: var(--fs-xs); word-break: break-all; text-align: left; }
.qr { width: 208px; max-width: 100%; margin: 0 auto; padding: var(--sp-3); background: #fff; border-radius: var(--r-md); min-height: 208px; }
.qr svg { display: block; width: 100%; height: auto; }
.max-btn { right: 6px; }
.progress > span.w-0 { width: 0; } .progress > span.w-5 { width: 5%; } .progress > span.w-10 { width: 10%; } .progress > span.w-15 { width: 15%; } .progress > span.w-20 { width: 20%; } .progress > span.w-25 { width: 25%; }
.progress > span.w-30 { width: 30%; } .progress > span.w-35 { width: 35%; } .progress > span.w-40 { width: 40%; } .progress > span.w-45 { width: 45%; } .progress > span.w-50 { width: 50%; } .progress > span.w-55 { width: 55%; }
.progress > span.w-60 { width: 60%; } .progress > span.w-65 { width: 65%; } .progress > span.w-70 { width: 70%; } .progress > span.w-75 { width: 75%; } .progress > span.w-80 { width: 80%; } .progress > span.w-85 { width: 85%; }
.progress > span.w-90 { width: 90%; } .progress > span.w-95 { width: 95%; } .progress > span.w-100 { width: 100%; }

/* ---------- Trading (Phase 7) ---------- */
.dialog { border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--card); color: var(--text); padding: var(--sp-6); max-width: 420px; width: calc(100% - 32px); }
.dialog::backdrop { background: rgba(0,0,0,.7); }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.btn-row > .btn { flex: 1 1 140px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.status-dot.on { background: var(--success); }
.status-dot.warn { background: var(--warning); }
.status-dot.off { background: var(--danger); }
.pos-card { background: var(--input); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--sp-4); }
.pos-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: var(--sp-3); margin-top: var(--sp-3); }
.pos-grid .label { font-size: var(--fs-xs); color: var(--muted); }
.feed { max-height: 360px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--input); }
.feed-row { display: flex; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); border-top: 1px solid var(--border); font-size: var(--fs-sm); }
.feed-row:first-child { border-top: 0; }
.feed-row time { color: var(--muted); flex: none; font-variant-numeric: tabular-nums; }
.feed-row.success .msg { color: var(--success); } .feed-row.warning .msg { color: var(--warning); } .feed-row.error .msg { color: var(--danger); }
.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-2); }
.checklist li { display: flex; gap: var(--sp-3); align-items: flex-start; font-size: var(--fs-sm); }
.checklist .ok { color: var(--success); } .checklist .no { color: var(--danger); }
.chart-box { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-3); }
.chart-box canvas { width: 100%; height: 320px; display: block; }
.seg { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.cfg-grid { display: grid; grid-template-columns: 1fr; gap: var(--sp-4); }
@media (min-width: 640px) { .cfg-grid { grid-template-columns: 1fr 1fr; } }
.check-list { display: grid; gap: var(--sp-2); }
.mini-bars { display: flex; align-items: flex-end; gap: 2px; height: 80px; }
.mini-bars span { flex: 1; min-width: 2px; background: var(--success); border-radius: 2px 2px 0 0; }
.mini-bars span.neg { background: var(--danger); }
