/* Monitor de mercado · estilos compartilhados (login, senha, painel e erro de CSRF).
   Direção: caderno de laboratório. Papel quente no tema claro, grafite no escuro,
   laranja queimado como marca e azul reservado para a série de preços. */

:root {
  color-scheme: light dark;

  --bg: #f4f3ef;
  --bg-grid: rgba(22, 24, 29, .045);
  --surface: #ffffff;
  --surface-2: #f8f7f4;
  --surface-3: #efede8;
  --ink: #16181d;
  --ink-2: #3a3e48;
  --muted: #5c6170;
  --line: #e5e2db;
  --line-2: #d2cec5;
  --line-3: #b9b4aa;

  --brand: #c2410c;
  --brand-hover: #a3360a;
  --on-brand: #ffffff;
  --brand-soft: #fff1e8;
  --brand-ink: #9a3412;

  --accent: #2547c4;
  --accent-soft: #eef1fd;
  --focus: #2547c4;

  --up: #08744a;   --up-soft: #e3f2ea;
  --down: #bf2f24; --down-soft: #fcebe9;
  --move: #6a3dcc; --move-soft: #f1ebfd;
  --warn: #8a5300; --warn-soft: #fff4e0; --warn-line: #efd29c;
  --info: #2547c4; --info-soft: #eef1fd; --info-line: #cbd5f8;
  --bad: #b42318;  --bad-soft: #fdecea;  --bad-line: #f5c2bd;
  --ok: #08744a;   --ok-soft: #e3f2ea;
  --neutral-soft: #efede8;

  --overlay: rgba(22, 24, 29, .5);
  --tooltip-bg: rgba(255, 255, 255, .98);
  --state-bg: rgba(255, 255, 255, .96);

  --radius: 14px;
  --radius-sm: 9px;
  --shadow-1: 0 1px 0 rgba(22, 24, 29, .04), 0 1px 3px rgba(22, 24, 29, .06);
  --shadow-2: 0 18px 40px -18px rgba(22, 24, 29, .35);

  --font: system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Segoe UI Variable Display", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Cascadia Code", Consolas, "Roboto Mono", Menlo, monospace;

  /* Gráfico (lidos pelo dashboard.js) */
  --c-ink: #16181d;
  --c-muted: #5c6170;
  --c-grid: #eeece6;
  --c-axis: #d2cec5;
  --c-line: #2547c4;
  --c-area-top: rgba(37, 71, 196, .16);
  --c-area-bottom: rgba(37, 71, 196, 0);
  --c-up: #08744a;
  --c-down: #bf2f24;
  --c-move: #6a3dcc;
  --c-vol-up: rgba(8, 116, 74, .28);
  --c-vol-down: rgba(191, 47, 36, .28);
  --c-vol-flat: rgba(92, 97, 112, .22);
  --c-hatch: #e2dfd8;
  --c-cross: #7d8292;
  --c-halo: #ffffff;
  --c-tag-ink: #ffffff;
  --c-hover-bg: #16181d;
  --c-hover-ink: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1015;
    --bg-grid: rgba(236, 238, 242, .035);
    --surface: #151920;
    --surface-2: #1a1f27;
    --surface-3: #222833;
    --ink: #eceef2;
    --ink-2: #c7ccd6;
    --muted: #9aa2b1;
    --line: #262c36;
    --line-2: #353c48;
    --line-3: #4a5260;

    --brand: #ff8f5a;
    --brand-hover: #ffa67a;
    --on-brand: #1b0e06;
    --brand-soft: rgba(255, 143, 90, .12);
    --brand-ink: #ffab80;

    --accent: #86a6ff;
    --accent-soft: rgba(134, 166, 255, .12);
    --focus: #9db6ff;

    --up: #3fcf8e;   --up-soft: rgba(63, 207, 142, .13);
    --down: #ff7a6d; --down-soft: rgba(255, 122, 109, .13);
    --move: #b69cff; --move-soft: rgba(182, 156, 255, .14);
    --warn: #f0b354; --warn-soft: rgba(240, 179, 84, .1); --warn-line: rgba(240, 179, 84, .35);
    --info: #9db6ff; --info-soft: rgba(134, 166, 255, .1); --info-line: rgba(134, 166, 255, .32);
    --bad: #ff8577;  --bad-soft: rgba(255, 122, 109, .1); --bad-line: rgba(255, 122, 109, .36);
    --ok: #3fcf8e;   --ok-soft: rgba(63, 207, 142, .13);
    --neutral-soft: #222833;

    --overlay: rgba(0, 0, 0, .62);
    --tooltip-bg: rgba(26, 31, 39, .98);
    --state-bg: rgba(21, 25, 32, .96);

    --shadow-1: 0 1px 0 rgba(0, 0, 0, .25);
    --shadow-2: 0 18px 40px -16px rgba(0, 0, 0, .7);

    --c-ink: #eceef2;
    --c-muted: #9aa2b1;
    --c-grid: #1f242d;
    --c-axis: #353c48;
    --c-line: #86a6ff;
    --c-area-top: rgba(134, 166, 255, .2);
    --c-area-bottom: rgba(134, 166, 255, 0);
    --c-up: #3fcf8e;
    --c-down: #ff7a6d;
    --c-move: #b69cff;
    --c-vol-up: rgba(63, 207, 142, .3);
    --c-vol-down: rgba(255, 122, 109, .3);
    --c-vol-flat: rgba(154, 162, 177, .25);
    --c-hatch: #2a303a;
    --c-cross: #8a93a3;
    --c-halo: #151920;
    --c-tag-ink: #0d1015;
    --c-hover-bg: #eceef2;
    --c-hover-ink: #0d1015;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, dl, dd { margin: 0; }
h1, h2, h3 { font-family: var(--font-display); }
a { color: var(--accent); text-underline-offset: 2px; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
main:focus { outline: none; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: 12px; top: -64px; z-index: 100;
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 8px; text-decoration: none; font-weight: 600;
}
.skip:focus { top: 12px; }

/* ---------- Botões e campos ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px;
  border-radius: var(--radius-sm); border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 14px; line-height: 1.2;
  text-decoration: none; cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .08s ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--line-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-small { min-height: 34px; padding: 5px 12px; font-size: 13px; }
.btn-ghost { background: transparent; }
.btn-link {
  border: 0; background: none; padding: 2px 0; color: var(--accent); font-weight: 600;
  font-size: 13px; cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}
.btn-link:hover { text-decoration-thickness: 2px; }
.btn-block { width: 100%; }
.btn.is-busy { cursor: progress; opacity: .75; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  font-size: 18px; font-weight: 600; line-height: 1; cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--line-3); }
.icon-btn[aria-disabled="true"] { opacity: .4; cursor: not-allowed; }

.input, .select, .field input, .field select {
  width: 100%; min-height: 42px; padding: 8px 12px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--surface);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.select { width: auto; padding-right: 32px; }
.field .select { width: 100%; }
.input:hover, .select:hover, .field input:hover { border-color: var(--line-3); }
.input:focus-visible, .select:focus-visible, .field input:focus-visible {
  outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--focus);
}
input[aria-invalid="true"] { border-color: var(--bad); }
input[type="date"] { color-scheme: light dark; }

.field { display: grid; gap: 6px; }
.field label { font-weight: 600; font-size: 14px; }
.field-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.field-inline .input { width: auto; min-height: 36px; padding: 4px 8px; }
.field-error { color: var(--bad); font-size: 13px; font-weight: 600; }
.field-error:empty { display: none; }
.hint { color: var(--muted); font-size: 13px; }

/* Senha: botão mostrar/ocultar e aviso de Caps Lock (auth.js) */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 84px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  min-height: 34px; min-width: 72px; padding: 4px 10px;
  border: 0; border-radius: 7px; background: transparent; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--muted);
}
.pw-toggle:hover { color: var(--ink); background: var(--surface-3); }
.caps-hint { display: block; color: var(--warn); font-size: 13px; font-weight: 600; }
.caps-hint:empty { display: none; }

/* ---------- Avisos, selos e pílulas ---------- */
.notice {
  border: 1px solid var(--info-line); background: var(--info-soft); color: var(--ink);
  border-radius: 10px; padding: 12px 14px; font-size: 14px;
  border-left-width: 4px;
}
.notice strong { display: block; margin-bottom: 2px; }
.notice p + p { margin-top: 4px; }
.notice .reason { color: var(--ink-2); }
.notice-info { border-color: var(--info-line); border-left-color: var(--info); background: var(--info-soft); }
.notice-warn { border-color: var(--warn-line); border-left-color: var(--warn); background: var(--warn-soft); }
.notice-warn strong { color: var(--warn); }
.notice-bad { border-color: var(--bad-line); border-left-color: var(--bad); background: var(--bad-soft); }
.notice-bad strong { color: var(--bad); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; line-height: 1.4;
  padding: 2px 9px; border-radius: 999px; white-space: nowrap;
  background: var(--neutral-soft); color: var(--ink-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-neutral { background: var(--neutral-soft); color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 6px; width: max-content;
  font-size: 12px; font-weight: 700; letter-spacing: .02em; line-height: 1.4;
  padding: 3px 10px; border-radius: 999px;
}
.pill-private { background: var(--brand-soft); color: var(--brand-ink); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.lock { width: 9px; height: 8px; border-radius: 2px; background: currentColor; position: relative; margin-top: 3px; flex: none; }
.lock::before {
  content: ""; position: absolute; left: 1.5px; top: -5px; width: 6px; height: 6px;
  border: 1.6px solid currentColor; border-bottom: 0; border-radius: 4px 4px 0 0;
}

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }

.spinner {
  width: 16px; height: 16px; border-radius: 50%; flex: none; display: inline-block;
  border: 2px solid var(--line-2); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
.spinner-xs { width: 12px; height: 12px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
/* Entradas só com deslocamento: o conteúdo fica legível desde o primeiro quadro. */
@keyframes rise { from { transform: translateY(6px); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Login, senha e CSRF ---------- */
.auth-page {
  min-height: 100vh; min-height: 100dvh; display: flex;
  background-color: var(--bg);
  background-image:
    radial-gradient(60rem 30rem at 85% -10%, var(--brand-soft), transparent 70%),
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: auto, 32px 32px, 32px 32px;
}
.auth-shell { margin: auto; width: 100%; max-width: 440px; padding: 32px 20px; animation: rise .3s ease-out; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.auth-kicker { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.auth-product { font-family: var(--font-display); font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.auth-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-2); padding: 28px; display: grid; gap: 18px; align-content: start;
}
.auth-card h1 { font-size: 26px; letter-spacing: -.02em; line-height: 1.2; margin-top: 10px; }
.auth-card .pill + h1 { margin-top: 12px; }
.auth-card > h1:first-child { margin-top: 0; }
.auth-sub { color: var(--muted); margin-top: 4px; }
.auth-form { display: grid; gap: 16px; }
.auth-form .btn { min-height: 46px; font-size: 15px; }
.auth-foot { color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); padding-top: 14px; }
.plain-list { margin: 0; padding-left: 20px; color: var(--ink-2); display: grid; gap: 4px; }

/* Login em duas colunas no desktop */
.auth-split { max-width: 940px; display: grid; gap: 0; grid-template-columns: minmax(0, 1fr); }
.auth-aside { padding: 0 4px 20px; }
.auth-aside .auth-brand { margin-bottom: 0; }
.aside-lead, .aside-list { display: none; }
@media (min-width: 860px) {
  .auth-split { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); align-items: stretch; }
  .auth-aside {
    display: grid; align-content: start; gap: 22px;
    padding: 36px 36px 32px; border-radius: var(--radius) 0 0 var(--radius);
    background: #16181d; color: #eceef2;
    background-image:
      radial-gradient(28rem 18rem at 0% 100%, rgba(255, 143, 90, .22), transparent 70%),
      linear-gradient(rgba(255, 255, 255, .05) 1px, transparent 1px),
      linear-gradient(90deg, rgba(255, 255, 255, .05) 1px, transparent 1px);
    background-size: auto, 28px 28px, 28px 28px;
    border: 1px solid #262c36; border-right: 0;
  }
  .auth-aside .auth-kicker { color: #a7aebb; }
  .aside-lead { display: block; font-family: var(--font-display); font-size: 22px; line-height: 1.35; letter-spacing: -.01em; max-width: 26ch; margin-top: 28px; }
  .aside-list { display: grid; gap: 12px; list-style: none; margin: 0; padding: 0; color: #c7ccd6; font-size: 14px; }
  .aside-list li { display: grid; grid-template-columns: 14px 1fr; gap: 10px; align-items: baseline; }
  .aside-dot { width: 8px; height: 8px; border-radius: 2px; background: #ff8f5a; transform: rotate(45deg) translateY(-1px); }
  .auth-split .auth-card { border-radius: 0 var(--radius) var(--radius) 0; padding: 36px; }
}

/* Formulário renderizado pelo Django (form.as_p) */
.django-form > p { display: grid; gap: 6px; }
.django-form label { font-weight: 600; font-size: 14px; }
.django-form input:not([type="hidden"]) {
  width: 100%; min-height: 42px; padding: 8px 12px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--surface);
}
.django-form input:not([type="hidden"]):focus-visible {
  outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--focus);
}
.django-form .pw-wrap input { padding-right: 84px; }
.django-form .helptext { color: var(--muted); font-size: 13px; display: block; }
.django-form .helptext ul { margin: 4px 0 0; padding-left: 18px; display: grid; gap: 2px; }
.django-form .errorlist {
  list-style: none; margin: 0; padding: 10px 12px; border-radius: 8px;
  background: var(--bad-soft); border: 1px solid var(--bad-line); color: var(--bad); font-size: 13px; font-weight: 600;
}

/* ---------- Painel: estrutura ---------- */
.app-page {
  background-image: linear-gradient(var(--bg-grid) 1px, transparent 1px), linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 32px 32px;
  background-attachment: fixed;
}
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--line);
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .topbar { background: var(--surface); }
}
@supports (backdrop-filter: blur(8px)) {
  .topbar { backdrop-filter: saturate(1.2) blur(8px); }
}
.topbar-inner {
  max-width: 1440px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 16px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-size: 15px; }
.brand-text strong { font-weight: 700; }
.topbar-note { margin-left: auto; color: var(--muted); font-size: 13px; }
.logout-form { margin: 0; }
.noscript { max-width: 1440px; margin: 16px auto 0; }

.layout {
  max-width: 1440px; margin: 0 auto; padding: 16px;
  display: grid; gap: 16px;
  grid-template-columns: 300px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "assets main" "catalog main";
  align-items: start;
}
.assets-card { grid-area: assets; }
.catalog-card { grid-area: catalog; }
.main-col { grid-area: main; display: grid; gap: 16px; min-width: 0; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-1); padding: 18px; min-width: 0;
  animation: rise .3s ease-out;
}
.card-title { font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-family: var(--font); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head .card-title { padding-top: 7px; }
.card-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.catalog-card { display: grid; gap: 10px; }
.stack-form { display: grid; gap: 14px; margin-top: 4px; }
.form-msg { font-size: 14px; }
.form-msg:empty { display: none; }
.form-msg.is-ok { color: var(--ok); font-weight: 600; }
.form-msg.is-bad { color: var(--bad); font-weight: 600; }

.state-box:empty { display: none; }
.state-box { font-size: 14px; color: var(--muted); }
.state-line { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.state-empty {
  border: 1px dashed var(--line-2); border-radius: 10px; padding: 16px; color: var(--ink-2);
  display: grid; gap: 6px; background: var(--surface-2);
}
.state-empty strong { color: var(--ink); }
.state-error {
  border: 1px solid var(--bad-line); border-left: 4px solid var(--bad); background: var(--bad-soft); border-radius: 10px;
  padding: 12px 14px; display: grid; gap: 8px; justify-items: start; color: var(--ink);
}
.state-error strong { color: var(--bad); }

.updated { margin-top: 10px; font-size: 12px; color: var(--muted); }
.updated:empty { display: none; }
.updated.is-warn { color: var(--warn); font-weight: 600; }

/* ---------- Lista de ativos ---------- */
.asset-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.asset-item {
  position: relative; width: 100%; text-align: left; cursor: pointer;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px;
  padding: 12px 12px 12px 16px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface);
  transition: border-color .15s ease, background-color .15s ease;
  overflow: hidden;
}
.asset-item::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--line-2);
}
.asset-item.tone-ok::before { background: var(--ok); }
.asset-item.tone-info::before { background: var(--info); }
.asset-item.tone-warn::before { background: var(--warn); }
.asset-item.tone-bad::before { background: var(--bad); }
.asset-item:hover { border-color: var(--line-3); background: var(--surface-2); }
.asset-item[aria-pressed="true"] {
  border-color: var(--accent); background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent);
}
.ai-symbol { font-weight: 700; font-family: var(--mono); font-size: 14px; letter-spacing: -.01em; }
.ai-name { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-price { font-weight: 600; text-align: right; font-family: var(--mono); font-size: 14px; }
.ai-change { font-size: 12.5px; text-align: right; font-weight: 600; font-family: var(--mono); white-space: nowrap; }
.ai-foot {
  grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  margin-top: 8px; font-size: 12px; color: var(--muted);
}
.ai-time.is-late { color: var(--warn); font-weight: 600; }

/* ---------- Cabeçalho do ativo ---------- */
.chart-card { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.chart-card > * { min-width: 0; }
.asset-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--brand-ink); }
.asset-head h1 { font-size: 30px; font-weight: 700; letter-spacing: -.025em; line-height: 1.15; margin-top: 2px; }
.asset-sub { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--muted); font-size: 14px; margin-top: 6px; }
.asset-symbol { font-family: var(--mono); font-weight: 600; color: var(--ink-2); }
.quote { text-align: right; }
.quote-price { font-family: var(--mono); font-size: 32px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.quote-change { font-family: var(--mono); font-size: 14px; font-weight: 600; margin-top: 4px; }

.meta-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: 11px; overflow: hidden;
}
.meta-grid > div { background: var(--surface-2); padding: 10px 12px; min-width: 0; }
.meta-grid dt { font-size: 11.5px; color: var(--muted); font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.meta-grid dd { font-size: 14px; margin-top: 3px; overflow-wrap: anywhere; }
.meta-grid .sub { display: block; color: var(--muted); font-size: 12px; }
.meta-grid .is-late { color: var(--warn); font-weight: 600; }

/* ---------- Barra de filtros ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; }
.toolbar-group { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%; }
.toolbar-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.toolbar .select { min-height: 38px; padding-top: 4px; padding-bottom: 4px; font-size: 14px; }

.seg {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--surface-3); border: 1px solid var(--line); border-radius: 10px;
}
.seg-scroll { overflow-x: auto; max-width: 100%; min-width: 0; scrollbar-width: thin; }
.seg button {
  border: 0; background: transparent; cursor: pointer; white-space: nowrap;
  padding: 5px 11px; min-height: 32px; border-radius: 7px;
  font-size: 13px; font-weight: 600; color: var(--muted);
  transition: background-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] {
  background: var(--surface); color: var(--ink);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .16), 0 0 0 1px var(--line-2);
}
.seg button:focus-visible { outline-offset: -2px; }

.custom-range {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
  padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  animation: fade .18s ease-out both;
}
.custom-range .field-error { flex-basis: 100%; }

.status-lines { display: grid; gap: 2px; }
.status-lines:has(.coverage:empty):has(.marker-status:empty) { display: none; }
.coverage, .marker-status { font-size: 13px; color: var(--muted); }
.coverage:empty, .marker-status:empty { display: none; }
.coverage.is-warn { color: var(--warn); }
.coverage strong { color: var(--ink-2); font-weight: 600; }
.coverage.is-warn strong { color: var(--warn); }
.marker-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.marker-status.is-warn { color: var(--warn); }
.marker-status.is-loading { animation: fade .2s ease-out both; }

/* ---------- Gráfico ---------- */
.chart-frame {
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  padding: 8px 8px 4px;
}
.chart-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 2px 6px 6px; min-height: 40px; }
.zoom-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.zoom-ctl { display: inline-flex; align-items: center; gap: 6px; }
.chart-wrap { position: relative; }
.chart {
  display: block; width: 100%; height: 420px;
  touch-action: pan-y; cursor: crosshair; border-radius: 6px;
}
.chart-wrap.is-zoomed .chart { cursor: grab; }
.chart.is-panning, .chart-wrap.is-zoomed .chart.is-panning { cursor: grabbing; }
.chart:focus-visible { outline-offset: 3px; }
.chart-wrap.is-loading .chart { opacity: .4; transition: opacity .2s ease; }
.chart-wrap .chart { transition: opacity .2s ease; }

.chart-state {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 16px; pointer-events: none;
}
.chart-state > div {
  pointer-events: auto; max-width: 420px; text-align: center;
  background: var(--state-bg); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow-2); padding: 14px 18px; display: grid; gap: 6px; justify-items: center;
  font-size: 14px; color: var(--ink-2);
}
.chart-state strong { color: var(--ink); }
.chart-state-loading > div { display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow-1); }
.chart-state-error > div { border-color: var(--bad-line); }
.chart-state-error strong { color: var(--bad); }

.chart-tooltip {
  position: absolute; top: 8px; left: 0; z-index: 5; width: 244px;
  pointer-events: none;
  background: var(--tooltip-bg); border: 1px solid var(--line-2); border-radius: 11px;
  box-shadow: var(--shadow-2);
  padding: 10px 12px; font-size: 12px; line-height: 1.45;
}
.tt-time { font-weight: 700; color: var(--ink); margin-bottom: 6px; }
.tt-grid { display: grid; grid-template-columns: auto 1fr; gap: 1px 12px; }
.tt-grid dt { color: var(--muted); }
.tt-grid dd { text-align: right; font-family: var(--mono); font-size: 11.5px; font-weight: 600; }
.tt-empty { color: var(--muted); }
.tt-events { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); display: grid; gap: 6px; }
.tt-event strong { display: inline-flex; align-items: center; gap: 6px; }
.tt-event p { color: var(--ink-2); }

.chart-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 20px; align-items: flex-start; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.chart-foot .hint { font-size: 12px; max-width: 60ch; }
.readout { font-size: 13px; color: var(--ink-2); min-height: 1.5em; }

.lg { display: inline-block; width: 12px; height: 12px; flex: none; }
.lg-line { height: 3px; border-radius: 2px; background: var(--accent); }
.lg-move, .shape-price_move { background: var(--move); clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.lg-buy, .shape-buy_signal { background: var(--up); clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.lg-sell, .shape-sell_signal { background: var(--down); clip-path: polygon(0 0, 100% 0, 50% 100%); }
.lg-gap {
  border: 1px solid var(--line-2); border-radius: 2px;
  background: repeating-linear-gradient(135deg, var(--c-hatch) 0 2px, var(--surface) 2px 5px);
}
.shape { display: inline-block; width: 10px; height: 10px; flex: none; }

/* ---------- Eventos ---------- */
.table-wrap { overflow-x: auto; }
.events-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.events-table th {
  text-align: left; font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--line-2); white-space: nowrap;
}
.events-table th.th-num, .events-table td.td-num { text-align: right; }
.events-table td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.events-table tbody tr { transition: background-color .15s ease; }
.events-table tbody tr:hover { background: var(--surface-2); }
.events-table tbody tr:last-child td { border-bottom: 0; }
.events-table tbody tr.is-target { background: var(--accent-soft); }
.td-num { white-space: nowrap; font-family: var(--mono); font-size: 13px; }
.ev-type { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; white-space: nowrap; }
.ev-type.t-price_move { color: var(--move); }
.ev-type.t-buy_signal { color: var(--up); }
.ev-type.t-sell_signal { color: var(--down); }
.ev-actions { margin-top: 4px; }
.ev-reasons { margin: 0; padding-left: 16px; color: var(--ink); }
.ev-reasons:only-child { padding-left: 0; list-style: none; }
.ev-rule { color: var(--muted); font-size: 12px; margin-top: 4px; font-family: var(--mono); }
.ev-sub { display: block; color: var(--muted); font-size: 12px; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.pager-label { font-size: 13px; color: var(--muted); }

/* ---------- Sessão expirada ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: var(--overlay);
  animation: fade .2s ease-out both;
}
.dialog {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; max-width: 400px; width: 100%;
  box-shadow: var(--shadow-2); display: grid; gap: 10px; justify-items: start;
  animation: rise .25s ease-out both;
}
.dialog h2 { font-size: 20px; }

/* ---------- Responsivo ---------- */
@media (min-width: 1280px) {
  .chart { height: 460px; }
}

@media (max-width: 1100px) {
  .meta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-template-areas: "assets" "main" "catalog";
    padding: 12px; gap: 12px;
  }
  .main-col { gap: 12px; }
  .asset-list {
    grid-auto-flow: column; grid-auto-columns: minmax(230px, 78%);
    overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: 6px;
    overscroll-behavior-x: contain;
  }
  .asset-list > li { scroll-snap-align: start; }
  .topbar-note { display: none; }
  .logout-form { margin-left: auto; }
}

@media (max-width: 760px) {
  .events-table thead {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
  }
  .events-table, .events-table tbody, .events-table tr, .events-table td { display: block; }
  .events-table tr {
    border: 1px solid var(--line); border-radius: 11px; padding: 8px 12px; margin-bottom: 10px;
  }
  .events-table tbody tr:last-child td { border-bottom: 0; }
  .events-table td {
    border: 0; padding: 5px 0; display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 10px;
  }
  .events-table td.td-num { text-align: left; }
  .events-table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600; padding-top: 2px; font-family: var(--font); }
}

@media (max-width: 640px) {
  .card { padding: 14px; }
  .asset-head h1 { font-size: 24px; }
  .quote { text-align: left; }
  .quote-price { font-size: 28px; }
  .chart { height: 320px; }
  .chart-frame { padding: 6px 4px 2px; margin: 0 -4px; }

  /* Metadados logo abaixo do gráfico e da legenda: continuam visíveis, mas o gráfico
     sobe para perto da primeira dobra. Não há controles no bloco, então a ordem de
     foco do teclado não muda. Avisos de estado continuam acima do gráfico. */
  .chart-card > .meta-grid { order: 1; }

  /* Período ocupa a linha inteira; tipo de evento e modo dividem a linha seguinte,
     com o rótulo acima do controle. */
  .toolbar {
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px 12px; align-items: end;
  }
  .toolbar-group:first-child { grid-column: 1 / -1; width: 100%; }
  .toolbar-group:not(:first-child) { flex-direction: column; align-items: stretch; gap: 4px; }
  .toolbar-group:not(:first-child) .select { width: 100%; }
  .toolbar-group:not(:first-child) .seg button { flex: 1; }
  .chart-tooltip { width: 210px; }
  .pager .btn { padding: 5px 10px; }
  .brand .pill { display: none; }
  .auth-card { padding: 22px; }
}

/* Em 360 px ou mais, os metadados seguem em duas colunas (definidas em 1100 px). */

/* Fallback para telas bem estreitas: uma coluna e controles em linhas inteiras,
   sem reduzir fonte nem alvos de toque. */
@media (max-width: 359px) {
  .meta-grid { grid-template-columns: minmax(0, 1fr); }
  .toolbar { grid-template-columns: minmax(0, 1fr); }
  .layout { padding: 10px; }
}

/* Alvos de toque maiores em telas sensíveis ao toque */
@media (pointer: coarse) {
  .btn-small { min-height: 44px; }
  .seg button { min-height: 40px; padding: 6px 14px; }
  .icon-btn { width: 44px; height: 44px; }
  .toolbar .select, .select, .input { min-height: 44px; }
  .btn-link { padding: 8px 0; }
  .pw-toggle { min-height: 40px; }
}

@media (forced-colors: active) {
  .asset-item[aria-pressed="true"] { outline: 2px solid Highlight; }
  .seg button[aria-pressed="true"] { outline: 2px solid Highlight; }
  .badge::before, .lg, .shape { forced-color-adjust: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important;
  }
  .spinner { animation: none !important; border-color: var(--accent); border-right-color: var(--line-2); }
}
