:root {
  --bg: #0e1117;
  --panel: #151a22;
  --panel-2: #1b212b;
  --line: #262d38;
  --text: #e6e9ef;
  --muted: #8b95a5;
  --accent: #4c8dff;
  --up: #26a69a;
  --down: #ef5350;
  --list-w: 320px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
button { font: inherit; color: inherit; cursor: pointer; }
.up { color: var(--up); }
.down { color: var(--down); }

/* topo */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 48px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { font-size: 17px; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; }
.brand b { color: var(--accent); }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--down); box-shadow: 0 0 8px var(--down); animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.topbar-right { display: flex; gap: 12px; align-items: center; }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); }
.badge-off { background: #3a1b1d; color: #ff8a80; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 4px; background: #3a2f12; color: #f5c451; }

/* layout */
.layout { flex: 1; display: grid; grid-template-columns: var(--list-w) 1fr; min-height: 0; }

/* watchlist */
.watchlist { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.add-form { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); }
.add-form input {
  flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 8px 10px; font: inherit; text-transform: uppercase;
}
.add-form input::placeholder { text-transform: none; color: var(--muted); }
.add-form input:focus { outline: none; border-color: var(--accent); }
.add-form button { width: 38px; border: 0; border-radius: 6px; background: var(--accent); color: #fff; font-size: 20px; line-height: 1; }
.add-error { margin: 0; padding: 6px 12px; color: var(--down); font-size: 12px; }
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.row {
  position: relative; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid #1c222c; cursor: pointer; border-left: 3px solid transparent;
}
.row:hover { background: var(--panel-2); }
.row:focus-visible { outline: 1px solid var(--accent); outline-offset: -1px; }
.row.active { background: var(--panel-2); border-left-color: var(--accent); }
.row-main { min-width: 0; }
.row-ticker { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.row-mkt { font-size: 10px; font-weight: 500; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; }
.row-name { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-quote { text-align: right; font-variant-numeric: tabular-nums; transition: transform .15s; }
.row-price { font-weight: 600; border-radius: 3px; padding: 0 3px; }
.row-chg { font-size: 12px; }
.row-del {
  position: absolute; right: 4px; top: 4px; width: 20px; height: 20px; border: 0; border-radius: 4px;
  background: transparent; color: var(--muted); font-size: 15px; line-height: 1; opacity: 0;
}
.row:hover .row-del, .row:focus-within .row-del { opacity: 1; }
.row:hover .row-quote, .row:focus-within .row-quote { transform: translateX(-18px); }
.row-del:hover { color: var(--down); background: #2a1b1d; }
.row-error .row-name { color: var(--down); }
.flash-up { animation: fup .9s; }
.flash-down { animation: fdown .9s; }
@keyframes fup { from { background: rgba(38,166,154,.45); } }
@keyframes fdown { from { background: rgba(239,83,80,.45); } }
.list-hint { margin: 0; padding: 8px 12px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--line); }

/* gráfico */
.chart-panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chart-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px 4px; }
.back-btn { display: none; border: 0; background: var(--panel-2); border-radius: 6px; width: 34px; height: 34px; font-size: 22px; }
.c-symbol { font-size: 20px; font-weight: 700; }
.c-name { color: var(--muted); }
.c-price { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.c-change { font-variant-numeric: tabular-nums; margin-left: 6px; }
.c-stale { font-size: 11px; color: #f5c451; margin-left: 8px; white-space: nowrap; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 16px 8px; }
.toolbar .seg { flex: 0 1 auto; }
/* médias móveis: tipo + 3 campos de período (amarela, azul, branca) */
.ma { display: inline-flex; align-items: center; gap: 2px; flex: 0 0 auto; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 2px 4px; }
.ma select { background: transparent; color: var(--muted); border: 0; font: inherit; font-size: 12px; padding: 4px 2px; cursor: pointer; }
.ma select option { background: var(--panel); color: var(--text); }
.ma-field { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px; border-radius: 5px; }
.ma-field:focus-within { background: var(--panel-2); }
.ma-field i { width: 12px; height: 3px; border-radius: 2px; background: var(--c); flex: none; }
.ma-field input {
  width: 40px; background: transparent; border: 0; border-bottom: 1px solid var(--line); color: var(--text);
  font: inherit; font-size: 13px; text-align: center; padding: 2px 0; -moz-appearance: textfield; appearance: textfield;
}
.ma-field input::-webkit-outer-spin-button, .ma-field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ma-field input:focus { outline: none; border-bottom-color: var(--c); }
.ma-field input.bad { border-bottom-color: var(--down); }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 2px; overflow-x: auto; max-width: 100%; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 5px 10px; border-radius: 5px; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--accent); color: #fff; }
/* indicadores fundamentalistas: mesma linha dos timeframes/tipos; explicação ao passar o mouse */
.fund { display: flex; flex: 1 1 300px; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 2px; overflow-x: auto; scrollbar-width: thin; scrollbar-color: #3a4352 transparent; }
.fund::-webkit-scrollbar { height: 4px; }
.fund::-webkit-scrollbar-thumb { background: #3a4352; border-radius: 2px; }
.fund-item { flex: 0 0 auto; border: 0; background: transparent; padding: 5px 7px; font-size: 13px; border-radius: 5px; white-space: nowrap; cursor: help; font-variant-numeric: tabular-nums; }
.fund-item:hover, .fund-item:focus-visible, .fund-item.open { background: var(--panel-2); outline: none; }
.fund-item .k { color: var(--muted); margin-right: 4px; font-size: 11.5px; }
.fund-item .v { color: var(--text); font-weight: 600; }
.fund-item .v.na { color: var(--muted); font-weight: 400; }
.fund-item .v.neg { color: var(--down); }
.fund.loading .v { opacity: .4; }
.fund-tip {
  position: fixed; z-index: 50; max-width: 300px; padding: 10px 12px; border-radius: 8px;
  background: #222a36; border: 1px solid #36404f; box-shadow: 0 8px 24px rgba(0,0,0,.45);
  font-size: 12.5px; line-height: 1.45; color: var(--text); pointer-events: none;
}
.fund-tip b { display: block; font-size: 13px; margin-bottom: 4px; }
.fund-tip .val { color: var(--accent); font-weight: 600; }
.fund-tip .note { display: block; margin-top: 6px; color: var(--muted); font-size: 11.5px; }
.chart-wrap { position: relative; flex: 1; min-height: 260px; margin: 0 8px 8px; }
.chart { position: absolute; inset: 0; }
.legend {
  position: absolute; top: 6px; left: 10px; z-index: 3; display: flex; gap: 12px; flex-wrap: wrap;
  font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; pointer-events: none;
}
.legend b { font-weight: 500; }
.chart-empty, .chart-loading {
  position: absolute; inset: 0; z-index: 4; display: flex; align-items: center; justify-content: center;
  color: var(--muted); background: var(--bg);
}
.chart-loading { background: rgba(14,17,23,.6); }
[hidden] { display: none !important; }

.footer { font-size: 11px; color: var(--muted); padding: 4px 16px calc(4px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.footer a { color: var(--muted); }

/* celular: uma tela por vez */
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .chart-panel { display: none; }
  .layout.show-chart .watchlist { display: none; }
  .layout.show-chart .chart-panel { display: flex; }
  .back-btn { display: block; }
  .row-del { opacity: 1; position: static; order: 3; }
  .row:hover .row-quote, .row:focus-within .row-quote { transform: none; }
  .list-hint { display: none; }
  .fund { flex-basis: 100%; }
}
.ma-field.off i { opacity: .25; }
.ma-field.off input { color: var(--muted); }

/* modo TV (Fire TV): foco bem visível para o controle remoto */
.tv :focus { outline: none; }
.tv :focus-visible, .tv button:focus, .tv input:focus, .tv select:focus, .tv .row:focus {
  outline: 3px solid #ffd54f; outline-offset: -3px; border-radius: 6px;
}
.tv .row:focus { background: var(--panel-2); }
.tv .seg button:focus.on { outline-color: #fff; }
.tv .list-hint { display: none; }

/* conta (login Google / pareamento da TV) */
.acct-btn { border: 1px solid var(--line); background: transparent; color: var(--muted); padding: 3px 10px; border-radius: 5px; font: inherit; font-size: 13px; cursor: pointer; }
.acct-btn:hover { color: var(--text); }
.acct-btn.on { color: var(--up); border-color: #1f4d48; }
.acct-panel { position: fixed; top: 52px; right: 12px; z-index: 50; width: min(360px, calc(100vw - 24px)); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.acct-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.acct-x { border: 0; background: transparent; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; }
.acct-msg { margin: 6px 0; font-size: 13px; line-height: 1.4; }
.acct-msg.muted, .acct-panel .muted { color: var(--muted); font-size: 12px; }
.acct-msg.err { color: var(--down); }
.acct-msg a { color: var(--accent); }
.acct-act { display: block; width: 100%; margin-top: 10px; border: 0; border-radius: 6px; background: var(--accent); color: #fff; padding: 8px; font: inherit; cursor: pointer; }
.acct-out { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.acct-code { margin: 10px 0 4px; font-size: 30px; font-weight: 700; letter-spacing: 4px; text-align: center; font-variant-numeric: tabular-nums; }
.acct-code.dead { opacity: .3; text-decoration: line-through; }
.acct-sub { margin-top: 12px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.acct-dev { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.acct-dev button { border: 0; background: transparent; color: var(--down); cursor: pointer; font: inherit; font-size: 12px; }
.acct-steps { margin: 6px 0 8px 18px; padding: 0; font-size: 13px; line-height: 1.5; }
.acct-row { display: flex; gap: 8px; align-items: stretch; }
.acct-row .acct-act { width: auto; margin: 0; padding: 0 14px; }
.acct-input { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 8px 10px; font-size: 20px; letter-spacing: 2px; font-variant-numeric: tabular-nums; }
.acct-google { min-height: 44px; margin-top: 8px; }
.tv .acct-panel { width: 460px; font-size: 16px; }
.tv .acct-msg, .tv .acct-steps { font-size: 16px; }

/* commodities */
.cmd-btn { margin: 0 10px 8px; padding: 6px; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; }
.cmd-btn:hover, .cmd-btn:focus { color: var(--text); border-color: var(--accent); outline: none; }
.cmd-panel { right: auto; left: 12px; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 70px); overflow-y: auto; }
.cmd-group { margin-bottom: 4px; }
.cmd-group .acct-sub { margin: 10px 0 6px; }
.cmd-chip { margin: 0 6px 6px 0; padding: 5px 10px; border: 1px solid var(--line); border-radius: 14px; background: transparent; color: var(--text); font: inherit; font-size: 13px; cursor: pointer; }
.cmd-chip:hover, .cmd-chip:focus { border-color: var(--accent); outline: none; }
.cmd-chip.on { border-color: #1f4d48; color: var(--up); }
.tv .cmd-btn, .tv .cmd-chip { font-size: 16px; }
.tv .cmd-panel { width: 640px; }
.tv .cmd-chip:focus, .tv .cmd-btn:focus { box-shadow: 0 0 0 3px var(--accent); }
