:root {
  --bg: #0b0f14;
  --surface: #121921;
  --surface-2: #1a232d;
  --line: #24303c;
  --text: #e8eef4;
  --muted: #8a99a8;
  --up: #22c55e;
  --down: #f05252;
  --accent: #4f8cff;
  --buy: #22c55e;
  --sell: #f05252;
  --level: #f5a524;
  --c-up: #4e9a76;
  --c-down: #c06a6a;
  --up-bg: rgba(34, 197, 94, .14);
  --down-bg: rgba(240, 82, 82, .14);
  --level-bg: rgba(245, 165, 36, .14);
  --accent-bg: rgba(79, 140, 255, .14);
  --radius: 8px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #eef1f5;
    --line: #e1e6ec;
    --text: #0f1720;
    --muted: #5d6b79;
    --up: #13a150;
    --down: #dc3a3a;
    --accent: #2f6fe6;
    --c-up: #5c9c7d;
    --c-down: #c27474;
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + var(--safe-b));
  overscroll-behavior-y: contain;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); }

/* ---------- topo ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px 10px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
}
.topbar h1 { font-size: 22px; margin: 0; letter-spacing: -.02em; }
.status { margin: 2px 0 0; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.dot.open { background: var(--up); box-shadow: 0 0 0 3px var(--up-bg); }
.top-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center;
}
.icon-btn svg, .tab svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.banner {
  margin: 0 16px 10px; padding: 10px 12px; border-radius: var(--radius);
  background: var(--accent-bg); display: flex; gap: 10px; align-items: center; justify-content: space-between;
  font-size: 13px;
}

main { padding: 0 16px; }
.view { display: none; }
.view.active { display: block; }

/* ---------- botões / chips ---------- */
.btn {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 6px;
  padding: 10px 14px; font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--down); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 4px; margin-bottom: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: 6px 12px; font-size: 13px; white-space: nowrap; color: var(--muted);
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- resumo ---------- */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; text-align: left;
}
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.toolbar .chips { flex: 1; min-width: 0; margin: 0; padding: 0; }
.toolbar select, .field input, .field select {
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px;
}
.toolbar select { flex: none; font-size: 13px; padding: 6px 8px; }

/* ---------- lista ---------- */
.asset-list, .timeline, .news-list { list-style: none; margin: 0; padding: 0; }
.asset {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 8px; cursor: pointer;
}
.asset.hot { border-color: color-mix(in srgb, var(--buy) 55%, var(--line)); }
.asset.hot.sell { border-color: color-mix(in srgb, var(--sell) 55%, var(--line)); }
.asset-row { display: grid; grid-template-columns: 1fr 84px auto; gap: 10px; align-items: center; }
.asset .tk { font-weight: 700; font-size: 16px; letter-spacing: .01em; }
.asset .nm { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asset .px { text-align: right; }
.asset .px b { display: block; font-size: 16px; }
.pill {
  display: inline-block; border-radius: 5px; padding: 1px 7px; font-size: 13px; font-weight: 600;
}
.pill.up { background: var(--up-bg); }
.pill.down { background: var(--down-bg); }
.spark { width: 84px; height: 32px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag {
  font-size: 12px; border-radius: 5px; padding: 3px 8px; background: var(--surface-2); color: var(--muted);
}
.tag.buy { background: var(--up-bg); color: var(--buy); }
.tag.sell { background: var(--down-bg); color: var(--sell); }
.tag.level { background: var(--level-bg); color: var(--level); }
.tag.strong { font-weight: 700; }

.fab {
  position: fixed; right: 18px; bottom: calc(84px + var(--safe-b)); width: 54px; height: 54px;
  border-radius: 12px; border: 0; background: var(--accent); color: #fff; font-size: 28px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35); z-index: 5;
}

.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* ---------- alertas ---------- */
.day { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 16px 0 8px; }
.alert {
  display: grid; grid-template-columns: 36px 1fr auto; gap: 10px; align-items: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 8px;
}
.alert .ic { width: 36px; height: 36px; border-radius: 6px; display: grid; place-items: center; background: var(--surface-2); font-size: 17px; }
.alert.zone .ic { background: var(--up-bg); }
.alert.general .ic { background: var(--level-bg); }
.alert.summary .ic { background: var(--accent-bg); }
.alert b { display: block; font-size: 14px; }
.alert p { margin: 2px 0 0; font-size: 13px; color: var(--muted); white-space: pre-line; }
.alert time { font-size: 12px; color: var(--muted); }

/* ---------- notícias ---------- */
.news {
  display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 8px; text-decoration: none; color: inherit;
}
.news .meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.news h3 { font-size: 15px; margin: 4px 0 0; font-weight: 600; line-height: 1.35; }
.news .tk { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 5px; background: var(--surface-2); color: var(--text); }

/* ---------- juros ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px;
}
.card h2 { font-size: 13px; margin: 0 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.rates-grid { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.rates-grid .card { margin: 0; }
.big { font-size: 30px; font-weight: 750; letter-spacing: -.02em; }
.mid { font-size: 20px; font-weight: 700; }
.copom-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.countdown { font-size: 13px; color: var(--accent); font-weight: 600; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 44px; gap: 8px; align-items: center; margin: 7px 0; font-size: 13px; }
.bar { height: 8px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.bar-row.top .bar i { background: var(--up); }
.focus-box { background: var(--surface-2); border-radius: 6px; padding: 10px 12px; margin: 10px 0; font-size: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
td, th { padding: 7px 0; border-bottom: 1px solid var(--line); text-align: left; }
th { font-size: 12px; color: var(--muted); font-weight: 500; }
td:last-child, th:last-child { text-align: right; }
tr:last-child td { border-bottom: 0; }
.src { font-size: 11px; color: var(--muted); margin-top: 8px; }
.src a { color: inherit; }

/* ---------- abas ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding: 6px 0 calc(6px + var(--safe-b));
}
.tab {
  background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--muted); padding: 4px 0;
}
.tab.active { color: var(--accent); }

/* ---------- sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 30; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; max-height: 92vh;
  background: var(--bg); border-radius: 14px 14px 0 0; border-top: 1px solid var(--line);
  display: flex; flex-direction: column; animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 4px; flex: none; }
.sheet-body { overflow-y: auto; padding: 8px 16px calc(24px + var(--safe-b)); }
@media (min-width: 720px) {
  .sheet { left: 50%; width: 640px; transform: translateX(-50%); bottom: 4vh; border-radius: 14px; border: 1px solid var(--line); }
  @keyframes up { from { opacity: .4; } }
  main, .banner { max-width: 760px; margin-left: auto; margin-right: auto; }
  main { padding: 0 16px; }
}

.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.detail-head h2 { margin: 0; font-size: 24px; }
.detail-head .nm { color: var(--muted); font-size: 13px; }
.detail-head .px { text-align: right; }
.detail-head .px b { font-size: 24px; display: block; }
.chart-ctl { display: flex; gap: 6px; align-items: center; margin: 6px 0; }
.ranges { display: flex; gap: 3px; flex: 1; min-width: 0; flex-wrap: nowrap; }
.ranges .chip { padding: 4px 0; font-size: 13px; flex: 1; text-align: center; }
#chart-wrap { touch-action: none; user-select: none; -webkit-user-select: none; }
.chart { width: 100%; height: 230px; display: block; cursor: crosshair; }
.chart text.tag { fill: #fff; stroke: none; font-weight: 600; }
.chart text { font-size: 10px; fill: var(--muted); paint-order: stroke; stroke: var(--bg); stroke-width: 3px; stroke-linejoin: round; }
.chart-foot { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.chart-tip { font-size: 12px; color: var(--muted); flex: 1; min-width: 0; line-height: 1.3; }
.chart-foot .btn { flex: none; padding: 4px 9px; font-size: 12px; }
.btn.toggle.on { background: var(--level-bg); color: var(--level); border-color: color-mix(in srgb, var(--level) 45%, transparent); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 16px; }
.stats div { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
.stats span { display: block; font-size: 11px; color: var(--muted); }
.stats b { font-size: 14px; white-space: nowrap; }
.stats b.sm { font-size: 12.5px; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 18px 0 8px; }
.section-title h3 { margin: 0; font-size: 16px; }

.zone-item {
  display: grid; grid-template-columns: 6px 1fr auto; gap: 10px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px;
}
.zone-item .stripe { align-self: stretch; border-radius: 3px; background: var(--buy); }
.zone-item.sell .stripe { background: var(--sell); }
.zone-item.off { opacity: .5; }
.zone-item b { font-size: 15px; }
.zone-item small { display: block; color: var(--muted); font-size: 12px; }
.zone-meter { height: 6px; border-radius: 4px; background: var(--surface-2); margin-top: 6px; position: relative; overflow: hidden; }
.zone-meter i { position: absolute; top: 0; bottom: 0; left: 0; background: var(--buy); border-radius: 4px; }
.zone-item.sell .zone-meter i { background: var(--sell); }

.form { display: grid; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 8px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.field input, .field select { color: var(--text); font-size: 16px; width: 100%; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 6px; padding: 3px; }
.seg button { border: 0; background: none; padding: 8px; border-radius: 6px; font-weight: 600; color: var(--muted); }
.seg button.on.buy { background: var(--buy); color: #fff; }
.seg button.on.sell { background: var(--sell); color: #fff; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; }

.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.setting input[type=number] { width: 72px; text-align: right; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; color: var(--text); }
.switch { appearance: none; width: 44px; height: 26px; border-radius: 13px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; font-weight: 500;
  max-width: calc(100% - 32px);
}

.login { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 320px; display: grid; gap: 12px; text-align: center; justify-items: center; }
.login-card img { border-radius: 10px; }
.login-card h1 { margin: 0; }
.login-card input { width: 100%; padding: 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); font-size: 16px; }
.login-card .btn { width: 100%; }
.error { color: var(--down); font-size: 13px; min-height: 18px; margin: 0; }

.mini-seg { display: flex; background: var(--surface-2); border-radius: 6px; padding: 2px; }
.mini-seg button { border: 0; background: none; padding: 0; border-radius: 5px; font-size: 13px; font-weight: 600; color: var(--muted); display: grid; place-items: center; width: 26px; height: 26px; }
.mini-seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.mini-seg button:disabled { opacity: .35; }
.chart-empty { height: 230px; display: grid; place-items: center; }
