/* QuantLab — interface */
:root {
  color-scheme: light;
  --bg: #f4f4f2; --surface: #fcfcfb; --surface-2: #f0efec; --surface-3: #e6e5e1; --border: #dddcd7; --border-strong: #c7c6c0;
  --text: #0b0b0b; --text-2: #52514e; --muted: #7a7974;
  --accent: #2a78d6; --accent-2: #256abf; --accent-soft: rgba(42,120,214,.12);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --up: #16894a; --down: #d03b3b; --up-soft: rgba(22,137,74,.12); --down-soft: rgba(208,59,59,.12);
  --warn: #b7791f; --div-mid: #f0efec;
  --grid: rgba(0,0,0,.06);
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --r: 10px; --r-sm: 6px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #222220; --surface-3: #2c2c29; --border: #2f2f2c; --border-strong: #45443f;
  --text: #f5f5f2; --text-2: #c3c2b7; --muted: #8d8c85;
  --accent: #3987e5; --accent-2: #5598e7; --accent-soft: rgba(57,135,229,.16);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --up: #2fb36b; --down: #e66767; --up-soft: rgba(47,179,107,.15); --down-soft: rgba(230,103,103,.15);
  --warn: #e0a33a; --div-mid: #383835;
  --grid: rgba(255,255,255,.05);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.25);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 16px; } h3 { font-size: 14px; } h4 { font-size: 13px; color: var(--text-2); }
.muted { color: var(--muted); } .xs { font-size: 11px; } .sm { font-size: 12.5px; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--up); } .neg { color: var(--down); }

/* layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 18px 18px 14px; }
.brand small { font-weight: 500; font-size: 11px; color: var(--muted); margin-left: auto; }
.brand.big { font-size: 22px; padding: 0 0 8px; }
.logo { width: 26px; height: 26px; border-radius: 7px; background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M6 22l6-7 5 4 9-11' stroke='white' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/cover; flex: none; }
nav { padding: 4px 10px; flex: 1; }
.nav-h { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 14px 10px 4px; font-weight: 600; }
nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--r-sm); color: var(--text-2); font-weight: 500; }
nav a i { font-style: normal; width: 18px; text-align: center; opacity: .75; }
nav a:hover { background: var(--surface-2); color: var(--text); }
nav a.on { background: var(--accent-soft); color: var(--accent); }
.side-foot { padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--border); }
.main { min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 10; }
.top h1 { font-size: 18px; }
.top-actions { margin-left: auto; display: flex; gap: 8px; }
#menu-btn { display: none; }
.view { padding: 20px 24px 60px; max-width: 1560px; }

/* cards e grades */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card + .card, .card + .grid, .grid + .card, .grid + .grid { margin-top: 16px; }
.grid > .card, .grid > .card + .card { margin-top: 0; }
.card-h { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-h .right { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-side { grid-template-columns: minmax(0, 1fr) 340px; }
.g-form { grid-template-columns: 330px minmax(0, 1fr); align-items: start; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.sep { height: 1px; background: var(--border); margin: 14px 0; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 12px 14px; }
.kpi .l { font-size: 11.5px; color: var(--muted); display: flex; gap: 4px; align-items: center; }
.kpi .v { font-size: 21px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -.02em; }
.kpi .s { font-size: 11.5px; color: var(--text-2); }
.kpi.hero { background: linear-gradient(135deg, var(--accent-soft), transparent 70%), var(--surface); }
.tip { cursor: help; border-bottom: 1px dotted var(--muted); }

/* formulários */
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); font-weight: 500; min-width: 0; }
label.f > span.h { font-weight: 400; color: var(--muted); font-size: 11px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 7px 10px; outline: none; min-width: 0; width: 100%; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[type=number] { font-variant-numeric: tabular-nums; }
.chk { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--text-2); cursor: pointer; user-select: none; }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fgrid .full { grid-column: 1 / -1; }
details.adv > summary { cursor: pointer; font-size: 12.5px; color: var(--text-2); padding: 6px 0; font-weight: 500; }
details.adv[open] > summary { margin-bottom: 8px; }

.btn { font: inherit; font-weight: 550; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; border-radius: var(--r-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--down); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn.icon { padding: 5px 9px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: wait; }
.btn .spin { width: 13px; height: 13px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs button { font: inherit; font-weight: 550; background: none; border: none; color: var(--muted); padding: 8px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 2px; }
.seg button { font: inherit; font-size: 12px; font-weight: 550; background: none; border: 0; padding: 4px 10px; border-radius: 4px; color: var(--text-2); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); cursor: pointer; user-select: none; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.badge.up { background: var(--up-soft); color: var(--up); } .badge.down { background: var(--down-soft); color: var(--down); }
.badge.acc { background: var(--accent-soft); color: var(--accent); } .badge.warn { background: rgba(224,163,58,.15); color: var(--warn); }

/* tabelas */
.tbl-wrap { overflow: auto; max-width: 100%; border-radius: var(--r-sm); }
.tbl-wrap.tall { max-height: 520px; }
table.t { border-collapse: collapse; width: 100%; font-size: 12.8px; }
.t th, .t td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.t th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.t th.sort { cursor: pointer; } .t th.sort:hover { color: var(--text); }
.t td.r, .t th.r { text-align: right; font-variant-numeric: tabular-nums; }
.t tbody tr:hover td { background: var(--surface-2); }
.t tr.click { cursor: pointer; }
.t td.wrap { white-space: normal; min-width: 220px; }
.heat td.c { text-align: center; font-variant-numeric: tabular-nums; font-size: 12px; padding: 5px 6px; border: 2px solid var(--surface); border-radius: 4px; }
.metric-list { display: grid; grid-template-columns: 1fr auto; gap: 0; font-size: 13px; }
.metric-list > div { padding: 6px 2px; border-bottom: 1px solid var(--border); }
.metric-list > div:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; font-weight: 550; }

/* gráficos */
.chart { width: 100%; position: relative; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.pane-label { position: absolute; left: 8px; top: 4px; font-size: 11px; color: var(--muted); z-index: 3; pointer-events: none; }
.svgchart { width: 100%; display: block; overflow: visible; }
.svgchart text { fill: var(--muted); font-size: 10.5px; font-family: var(--sans); }
.svgchart .axis { stroke: var(--border-strong); }
.svgchart .gridl { stroke: var(--grid); }
.svg-tip { position: fixed; pointer-events: none; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 6px; padding: 6px 9px; font-size: 12px; box-shadow: var(--shadow); z-index: 100; white-space: nowrap; }
.spark { display: block; }

/* editor de código */
.code-editor { position: relative; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface-2); display: grid; grid-template-columns: 44px 1fr; overflow: hidden; min-height: 380px; }
.code-editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ce-gutter { padding: 12px 8px 12px 0; text-align: right; color: var(--muted); font: 13px/1.6 var(--mono); user-select: none; background: var(--surface-3); overflow: hidden; }
.ce-gutter div.err { color: var(--down); font-weight: 700; }
.ce-body { position: relative; overflow: auto; }
.ce-body pre, .ce-body textarea { margin: 0; padding: 12px 14px; font: 13px/1.6 var(--mono); white-space: pre; tab-size: 4; border: 0; min-height: 100%; }
.ce-body pre { pointer-events: none; color: var(--text); position: absolute; inset: 0; overflow: hidden; }
.ce-body textarea { position: relative; background: transparent; color: transparent; caret-color: var(--text); resize: none; width: 100%; height: 100%; min-height: 380px; outline: none; box-shadow: none; overflow: auto; }
.ce-body textarea::selection { background: var(--accent-soft); color: transparent; }
.tk-kw { color: #c678dd; font-weight: 600; } .tk-fn { color: var(--accent); } .tk-num { color: #d19a66; } .tk-str { color: #98c379; }
.tk-cm { color: var(--muted); font-style: italic; } .tk-op { color: #e5c07b; } .tk-ser { color: #56b6c2; } .tk-log { color: #e06c75; font-weight: 600; }
:root:not([data-theme="dark"]) .tk-kw { color: #8b2fc9; } :root:not([data-theme="dark"]) .tk-num { color: #b35c00; }
:root:not([data-theme="dark"]) .tk-str { color: #2d7a1f; } :root:not([data-theme="dark"]) .tk-op { color: #9a6700; }
:root:not([data-theme="dark"]) .tk-ser { color: #0b7a8a; } :root:not([data-theme="dark"]) .tk-log { color: #c0263a; }
.ce-status { font-size: 12.5px; padding: 8px 12px; border-radius: var(--r-sm); margin-top: 8px; }
.ce-status.ok { background: var(--up-soft); color: var(--up); } .ce-status.bad { background: var(--down-soft); color: var(--down); }
.ref-list { max-height: 520px; overflow: auto; }
.ref-item { padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; border-bottom: 1px solid var(--border); }
.ref-item:hover { background: var(--surface-2); }
.ref-item code { color: var(--accent); font-size: 12px; }
.ref-item p { margin: 2px 0 0; font-size: 12px; color: var(--text-2); }

/* biblioteca */
.strat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.strat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.strat:hover { border-color: var(--border-strong); }
.strat h3 { font-size: 14px; display: flex; gap: 8px; align-items: flex-start; }
.strat h3 .star { margin-left: auto; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1; }
.strat h3 .star.on { color: var(--s4); }
.strat p { margin: 0; font-size: 12.5px; color: var(--text-2); flex: 1; }
.strat .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.cat-h { margin: 22px 0 10px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }

/* diversos */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: 6px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.note { font-size: 12.5px; color: var(--text-2); background: var(--surface-2); border-left: 3px solid var(--accent); padding: 10px 12px; border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.note.warn { border-left-color: var(--warn); }
.pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 12px 14px; overflow: auto; font: 12.5px/1.6 var(--mono); white-space: pre; margin: 8px 0; }
.manual h2 { margin: 24px 0 8px; } .manual p, .manual li { color: var(--text-2); max-width: 900px; }
.manual table.t td { white-space: normal; }
.search-drop { position: absolute; z-index: 30; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-sm); box-shadow: var(--shadow); max-height: 280px; overflow: auto; width: 100%; margin-top: 2px; }
.search-drop div { padding: 7px 10px; cursor: pointer; font-size: 13px; }
.search-drop div:hover { background: var(--surface-2); }
.rel { position: relative; }
.progress { height: 3px; background: var(--accent); position: fixed; top: 0; left: 0; z-index: 200; transition: width .3s; }

#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 300; }
.toast { background: var(--surface); border: 1px solid var(--border-strong); border-left: 4px solid var(--accent); border-radius: var(--r-sm); padding: 10px 14px; box-shadow: var(--shadow); max-width: 420px; font-size: 13px; white-space: pre-line; animation: tin .2s ease-out; }
.toast.err { border-left-color: var(--down); } .toast.ok { border-left-color: var(--up); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 250; padding: 20px; }
.modal-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); width: min(760px, 100%); max-height: 88vh; overflow: auto; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.modal-head .btn { margin-left: auto; }
#modal-body { padding: 18px; }
.login { display: grid; place-items: center; min-height: 100vh; }
.login-card { width: 340px; display: flex; flex-direction: column; gap: 12px; }
.err { color: var(--down); font-size: 13px; }

@media (max-width: 1200px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-side { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 980px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; left: -260px; width: 250px; transition: left .2s; }
  .side.open { left: 0; box-shadow: var(--shadow); }
  #menu-btn { display: inline-flex; }
  .g2, .g3, .g-form, .g-side { grid-template-columns: minmax(0, 1fr); }
  .view { padding: 16px; }
}
@media (max-width: 560px) { .g4 { grid-template-columns: 1fr; } .fgrid { grid-template-columns: 1fr; } .top { padding: 12px 16px; } }
@media print {
  .side, .top, .no-print, #toasts { display: none !important; }
  .shell { display: block; } .view { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
}
