/* ══ Tokens (los mismos del terminal) ═════════════════════════════════ */
:root,
:root[data-theme='dark'] {
	--bg: #0a0d12; --surface: #10151c; --surface-2: #151b24; --surface-3: #1b2330;
	--line: #1e2733; --line-strong: #2a3545; --text: #e7ecf3; --text-2: #a9b4c3; --muted: #7a8799;
	--ask: #f6465d; --ask-bg: rgba(246, 70, 93, 0.12); --bid: #1fc28b; --bid-bg: rgba(31, 194, 139, 0.12);
	--accent: #5b8cff; --accent-bg: rgba(91, 140, 255, 0.14); --warn: #f0b93a; --warn-bg: rgba(240, 185, 58, 0.13);
	--shadow: 0 12px 40px rgba(0, 0, 0, 0.45); color-scheme: dark;
}
:root[data-theme='light'] {
	--bg: #f3f5f8; --surface: #ffffff; --surface-2: #f6f8fb; --surface-3: #eef1f6;
	--line: #e3e8ef; --line-strong: #d3dae4; --text: #121821; --text-2: #3f4b5b; --muted: #6b7788;
	--ask: #d9304a; --ask-bg: rgba(217, 48, 74, 0.09); --bid: #0f9d6e; --bid-bg: rgba(15, 157, 110, 0.1);
	--accent: #2f6bff; --accent-bg: rgba(47, 107, 255, 0.1); --warn: #b7791f; --warn-bg: rgba(183, 121, 31, 0.12);
	--shadow: 0 12px 40px rgba(16, 24, 40, 0.14); color-scheme: light;
}
:root { --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif; --r: 10px; --r-sm: 7px; }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
body { padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.up { color: var(--bid); }
.down { color: var(--ask); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }

/* ══ Controles ════════════════════════════════════════════════════════ */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--surface-2); padding: 8px 14px; border-radius: var(--r-sm); font-size: 13px; font-weight: 600; }
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface-2); color: var(--text-2); text-decoration: none; }
.icon-btn:hover { color: var(--text); background: var(--surface-3); }
.icon-btn.small { width: 28px; height: 28px; }
.link { background: none; border: 0; color: var(--accent); padding: 0; font-weight: 500; }
.link:hover { text-decoration: underline; }
.small { font-size: 12px; }
.input { width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; font-size: 14px; }
.input:focus { outline: none; border-color: var(--accent); }
.field { display: grid; grid-template-columns: 1fr auto; gap: 5px; font-size: 12px; color: var(--text-2); font-weight: 500; }
.field .unit { color: var(--muted); font-weight: 400; }
.field .input { grid-column: 1 / -1; }
.badge { display: inline-flex; align-items: center; font: 600 11px var(--sans); padding: 2px 8px; border-radius: 999px; background: var(--accent-bg); color: var(--accent); }
.badge.sim { background: var(--warn-bg); color: var(--warn); }
.count { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font: 600 10.5px var(--sans); }
.seg-tabs { display: inline-flex; gap: 2px; background: var(--bg); padding: 3px; border-radius: 8px; border: 1px solid var(--line); max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg-tabs::-webkit-scrollbar { display: none; }
.seg-tab { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; background: none; padding: 5px 11px; border-radius: 6px; font-size: 12.5px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.seg-tab:hover { color: var(--text-2); }
.seg-tab.active { background: var(--surface-3); color: var(--text); }

/* ══ Barra superior ═══════════════════════════════════════════════════ */
.nav { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; height: calc(56px + env(safe-area-inset-top, 0px)); padding: env(safe-area-inset-top, 0px) 16px 0; background: var(--surface); border-bottom: 1px solid var(--line); }
.nav::before { content: ''; position: absolute; left: 0; right: 0; bottom: 100%; height: 160px; background: var(--surface); pointer-events: none; }
.brand { display: flex; align-items: center; gap: 9px; color: var(--text); text-decoration: none; font-weight: 700; }
.brand-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff; }
.nav-spacer { flex: 1; }
.feed { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.feed.live .dot { background: var(--bid); box-shadow: 0 0 0 3px var(--bid-bg); }
:root[data-theme='light'] .i-sun, :root:not([data-theme='light']) .i-moon { display: none; }
.user { display: flex; align-items: center; gap: 8px; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 3px 4px 3px 3px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); font-size: 12.5px; font-weight: 600; }
.avatar { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-bg); color: var(--accent); font-weight: 700; font-size: 12px; text-transform: uppercase; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ══ Portada sin sesión ═══════════════════════════════════════════════ */
.hero { padding: 34px 16px 10px; text-align: center; }
.hero h1 { margin: 0 auto 10px; max-width: 760px; font-size: clamp(24px, 4vw, 36px); line-height: 1.15; letter-spacing: -0.02em; }
.grad { background: linear-gradient(90deg, var(--accent), #9b6bff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { margin: 0 auto 16px; max-width: 640px; color: var(--text-2); font-size: 15.5px; }
.hero-login { display: flex; justify-content: center; align-items: center; gap: 12px; min-height: 48px; margin-bottom: 8px; }
.fine { font-size: 12px; color: var(--muted); margin: 6px 0 0; }

/* ══ Resumen de la cuenta ═════════════════════════════════════════════ */
.summary { display: flex; flex-wrap: wrap; gap: 10px 28px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.sum label { display: block; font-size: 11.5px; color: var(--muted); }
.sum b { font: 600 16px var(--mono); }

/* ══ Distribución ═════════════════════════════════════════════════════ */
.layout { display: grid; gap: 10px; padding: 10px 16px; grid-template-columns: 240px minmax(0, 1fr) 300px; grid-template-areas: 'markets chart order' 'markets bottom bottom'; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); min-width: 0; display: flex; flex-direction: column; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 14px; }
.markets { grid-area: markets; }
.chart-panel { grid-area: chart; }
.order-panel { grid-area: order; padding: 12px; gap: 10px; }
.bottom { grid-area: bottom; }

.mk-cols, .mk { display: grid; grid-template-columns: minmax(0, 1fr) auto 62px; gap: 8px; align-items: center; padding: 6px 12px; }
.mk-cols { font-size: 11px; color: var(--muted); border-bottom: 1px solid var(--line); }
.mk-cols span:not(:first-child), .mk span:not(:first-child) { text-align: right; }
.mk { border: 0; width: 100%; background: none; text-align: left; border-bottom: 1px solid var(--line); font-size: 13px; }
.mk:hover { background: var(--surface-2); }
.mk.active { background: var(--accent-bg); }
.mk b { font-weight: 600; }
.mk small { display: block; color: var(--muted); font-size: 11px; }

.pair { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.pair span { font-size: 15px; font-weight: 600; }
.chg { font: 600 12.5px var(--mono); }
.chart { height: 430px; position: relative; }

.sides { width: 100%; }
.sides .seg-tab { flex: 1; padding: 8px; font-size: 13.5px; font-weight: 600; }
.sides .seg-tab.buy.active { background: var(--bid); color: #fff; }
.sides .seg-tab.sell.active { background: var(--ask); color: #fff; }
.types { width: 100%; }
.types .seg-tab { flex: 1; }
.pcts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.pcts button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 6px; padding: 5px 0; font-size: 12px; color: var(--text-2); }
.pcts button:hover { border-color: var(--line-strong); color: var(--text); }
.exits { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hint { margin: 0; font-size: 12.5px; color: var(--text-2); min-height: 18px; }
.hint b { font-family: var(--mono); color: var(--text); }
.go { padding: 11px; font-size: 14.5px; color: #fff; border: 0; }
.go.buy { background: var(--bid); }
.go.sell { background: var(--ask); }
.go:hover { filter: brightness(1.08); }

/* ══ Tablas de abajo ══════════════════════════════════════════════════ */
.tab-body { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 12px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: 11.5px; color: var(--muted); font-weight: 600; }
td { font-family: var(--mono); font-variant-numeric: tabular-nums; }
td.txt { font-family: var(--sans); }
tr.me td { background: var(--accent-bg); }
.rank-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.rank-status { margin: 0; padding: 10px 12px; font-size: 13px; color: var(--text-2); border-bottom: 1px solid var(--line); }
.rank-status .join { margin-left: 8px; padding: 5px 12px; font-size: 12.5px; background: var(--accent); border-color: var(--accent); color: #fff; }
.rank-status .link { margin-left: 6px; }
.empty { padding: 22px 12px; text-align: center; color: var(--muted); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 999px; font: 600 11px var(--sans); }
.tag.buy { background: var(--bid-bg); color: var(--bid); }
.tag.sell { background: var(--ask-bg); color: var(--ask); }
.tag.neutral { background: var(--surface-3); color: var(--muted); }

.foot { padding: 4px 16px 24px; font-size: 11.5px; color: var(--muted); }
.foot a { color: var(--text-2); }
.toasts { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 50; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { padding: 11px 14px; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--line-strong); box-shadow: var(--shadow); font-size: 13px; }
.toast.bad { border-color: var(--ask); }
.toast.ok { border-color: var(--bid); }

/* ══ Responsive ═══════════════════════════════════════════════════════ */
@media (max-width: 1100px) {
	.layout { grid-template-columns: minmax(0, 1fr) 300px; grid-template-areas: 'markets markets' 'chart order' 'bottom bottom'; }
	.markets #markets { display: flex; overflow-x: auto; scrollbar-width: none; }
	.markets .mk-cols { display: none; }
	.markets .mk { display: block; width: auto; flex: none; min-width: 120px; border-bottom: 0; border-right: 1px solid var(--line); }
	.markets .mk span { display: block; text-align: left !important; }
	.markets .panel-head { display: none; }
}
@media (max-width: 760px) {
	.nav { gap: 8px; padding: env(safe-area-inset-top, 0px) 12px 0; }
	.brand-name, .feed span, .uname { display: none; }
	.layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: 'markets' 'chart' 'order' 'bottom'; padding: 10px 12px; }
	.chart { height: 320px; }
	.summary { gap: 8px 18px; padding: 10px 12px; }
	.sum b { font-size: 14px; }
	.input { font-size: 16px; }
}
