/* ==========================================================================
   Pricing — abas e planilha
   ========================================================================== */

body.app { height: 100vh; overflow: hidden; }

.pricing { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ---------- Abas ---------- */

.tabbar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.tabs {
  display: flex;
  align-items: flex-end;
  align-self: stretch;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tab {
  position: relative;
  top: 1px;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 6px 0 14px;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  border: 1px solid transparent;
  border-bottom: none;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text);
  font-weight: 600;
  background: var(--surface);
  border-color: var(--border);
  box-shadow: 0 1px 0 var(--surface);
}

.tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 3px;
  background: none;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  visibility: hidden;
}
.tab:hover .tab-close { visibility: visible; }

.tab-rename {
  height: 22px;
  padding: 0 4px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 3px;
  outline: none;
}
.tab-close:hover { background: var(--surface-2); color: var(--text); }

.tab-add {
  align-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.tab-add:hover,
.tab-add.open { background: var(--surface-2); }

.add-wrap { align-self: center; display: flex; }
.menu.menu-right { left: auto; right: 0; }

/* Submenu das estruturas abre à esquerda do menu do + */
.submenu-wrap { position: relative; }
.menu.submenu { top: -5px; left: auto; right: calc(100% + 6px); min-width: 210px; }
.menu-item.has-sub { justify-content: space-between; }
.menu-item.plain svg { visibility: visible; color: var(--text-muted); }
.menu-item.has-sub svg { order: -1; margin-right: 4px; }
.tab-add svg { width: 16px; height: 16px; }

/* ---------- Área da aba ---------- */

.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
}

.toolbar {
  display: flex;
  gap: 4px;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
}

.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}
.tool:hover { background: var(--surface-2); }
.tool:disabled { opacity: .45; cursor: default; background: var(--surface); }
.tool svg { width: 14px; height: 14px; }

.tool .caret { width: 12px; height: 12px; margin-left: -2px; color: var(--text-muted); }
.tool.open { background: var(--surface-2); }

.tool-sep { width: 1px; align-self: stretch; margin: 2px 6px; background: var(--border); }

.dropdown { position: relative; }

.menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 30;
  min-width: 160px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}
.menu[hidden] { display: none; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 30px;
  padding: 0 10px;
  font: inherit;
  font-size: 13px;
  text-align: left;
  color: var(--text);
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item svg { width: 14px; height: 14px; visibility: hidden; color: var(--accent); }
.menu-item.checked svg { visibility: visible; }

.tool-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: 12px;
  font-size: 12px;
  color: var(--text-muted);
}
.tool-field input {
  height: 28px;
  padding: 0 8px;
  font: inherit;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}

/* ---------- Planilha ---------- */

.sheet-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  outline: none;
}

.sheet {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  width: max-content;
  font-size: 12.5px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.sheet th,
.sheet td {
  position: relative;
  height: 24px;
  padding: 0 6px;
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sheet thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 28px;
  background: var(--head-bg);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  cursor: s-resize;
}

.sheet .rh {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--head-bg);
  color: var(--text-muted);
  font-weight: 500;
  text-align: center;
  cursor: e-resize;
}
.sheet thead .rh { z-index: 3; cursor: default; }
/* Coluna do checkbox (fixa à esquerda, antes do número da linha) */
.sheet .ck {
  position: sticky;
  left: 0;
  z-index: 1;
  padding: 0;
  background: var(--head-bg);
  text-align: center;
  vertical-align: middle;
}
.sheet thead .ck { z-index: 3; }
.sheet .rh { left: 28px; }
.sheet .ck label {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  inset: 0;
  cursor: pointer;
}
.sheet .ck input {
  width: 13px;
  height: 13px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Separação entre estruturas: uma linha vazia */
.sheet tr.gap td {
  height: 12px;
  padding: 0;
  background: var(--surface);
  border-right: none;
  cursor: default;
}
.sheet th.hl { color: var(--accent); background: var(--accent-soft); }

.sheet td {
  background: var(--surface);
  color: var(--text);
  cursor: cell;
}
.sheet td.num { text-align: right; }
.sheet td.date { text-align: center; }
.sheet td.calc { background: var(--calc-bg); }
.sheet td.na { background: var(--na-bg); color: var(--text-muted); text-align: center; }
.sheet td.err { color: var(--negative); }
.sheet td.buy { background: var(--buy-bg); color: var(--buy-text); }
.sheet td.sell { background: var(--sell-bg); color: var(--sell-text); }

/* Zebra: linhas alternadas um tom mais claras, por cima de qualquer cor de célula */
.sheet tbody tr.alt td::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--zebra);
  pointer-events: none;
}

.sheet td.sel { background-image: linear-gradient(var(--sel-bg), var(--sel-bg)); }
.sheet td.cur { box-shadow: inset 0 0 0 2px var(--accent); }

/* ---------- Modal de Payoff / Gregas ---------- */

/* Paleta categórica de referência (validada para daltonismo), ordem fixa:
   1 Hoje · 2 Vencimento · 3 2/3 e curva animada · 4 1/3 */
:root {
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
  }
}
:root[data-theme="dark"] {
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, .55);
}

.modal {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(1400px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .35);
}

.modal-head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { flex: 1; margin: 0; font-size: 15px; font-weight: 600; }

.modal-tabs { display: flex; gap: 2px; padding: 2px; background: var(--surface-2); border-radius: 6px; }
.modal-tabs button {
  height: 28px;
  padding: 0 14px;
  font: inherit;
  font-size: 13px;
  color: var(--text-muted);
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.modal-tabs button[aria-selected="true"] { color: var(--text); background: var(--surface); font-weight: 600; }

.modal-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
}
.day-label { min-width: 150px; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-left: auto; font-size: 12.5px; color: var(--text-muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-item i, .tip-row i { width: 14px; height: 3px; border-radius: 2px; }

.charts { padding: 4px 16px 16px; }
.charts.greeks { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
.charts.greeks .chart:nth-child(-n+3) { grid-column: span 2; }
.charts.greeks .chart:nth-child(n+4) { grid-column: span 3; }

.chart { margin: 0; min-width: 0; }
.chart figcaption { margin: 0 0 2px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.chart svg { display: block; max-width: 100%; height: auto; font-family: var(--font-sans); }
.chart .grid { stroke: var(--grid-line); stroke-width: 1; }
.chart .zero { stroke: var(--text-muted); stroke-width: 1; }
.chart .spot { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 4; }
.chart .tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .tick.pct { font-size: 10.5px; opacity: .85; }
.chart .axis-name { fill: var(--text-muted); font-size: 10.5px; font-weight: 600; }
.chart .curve { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .cross { stroke: var(--text-muted); stroke-width: 1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: crosshair; }

.chart-tip {
  position: absolute;
  z-index: 2;
  min-width: 170px;
  padding: 8px 10px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
  pointer-events: none;
}
.tip-head { margin-bottom: 4px; font-weight: 600; color: var(--text-muted); }
.tip-row { display: flex; align-items: center; gap: 6px; line-height: 1.7; }
.tip-row b { margin-left: auto; padding-left: 12px; font-weight: 600; }

.tip-grid {
  display: grid;
  grid-template-columns: auto auto auto auto;
  column-gap: 14px;
  align-items: center;
  line-height: 1.7;
}
.tip-grid b { text-align: right; font-weight: 600; }
.tip-col { text-align: right; font-size: 11px; color: var(--text-muted); }
.tip-name { display: flex; align-items: center; gap: 6px; }
.tip-name i { width: 14px; height: 3px; border-radius: 2px; }

@media (max-width: 760px) {
  .charts.greeks { grid-template-columns: 1fr; }
  .charts.greeks .chart:nth-child(n) { grid-column: auto; }
}

/* ---------- Modal de nova cotação ---------- */

.modal.modal-small { width: min(620px, 100%); }
.modal.modal-small .modal-head { padding: 16px 22px; }
.modal.modal-small .modal-head h2 { font-size: 17px; }
.nq-form { display: flex; flex-direction: column; gap: 16px; padding: 22px; }
.nq-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.nq-field input,
.nq-field select {
  height: 40px;
  padding: 0 12px;
  font: inherit;
  font-size: 15px;
  font-weight: 400;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.nq-field input { text-transform: uppercase; }
.nq-field input:focus, .nq-field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.nq-row { display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 10px; }
.nq-row .nq-field { min-width: 0; }
.nq-row input { min-width: 0; width: 100%; }
.modal.modal-small { overflow-x: hidden; }
.nq-symbol { min-height: 16px; margin-top: -6px; font-size: 12px; color: var(--text-muted); }
.nq-status { min-height: 18px; font-size: 12.5px; color: var(--text-muted); }
.nq-status.err { color: var(--negative); }
.nq-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.nq-actions .tool { height: 36px; padding: 0 18px; font-size: 14px; }
.modal-small .progress { height: 22px; }
.modal-small .progress-pct { font-size: 12px; }
.modal-small .nq-status { font-size: 13.5px; }
.tool.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.tool.primary:hover { background: var(--accent); filter: brightness(1.08); }

.progress {
  position: relative;
  height: 18px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.progress[hidden] { display: none; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .15s ease-out; }
.progress-pct {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  mix-blend-mode: normal;
}

/* ---------- Linha comum (estruturas) ---------- */

.common-wrap {
  flex: 0 0 auto;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.common-wrap { outline: none; }
.sheet.common thead th { position: static; cursor: default; }

/* Só a área com foco (linha comum ou pontas) mostra a seleção, como uma célula ativa só no Excel */
.common-wrap:not(:focus-within) .sheet td.sel { background-image: none; }
.common-wrap:not(:focus-within) .sheet td.cur { box-shadow: none; }
.workspace:has(.common-wrap:focus-within) .sheet-wrap td.sel { background-image: none; }
.workspace:has(.common-wrap:focus-within) .sheet-wrap td.cur { box-shadow: none; }

/* ---------- Consolidados ---------- */

.cons-wrap {
  flex: 0 0 auto;
  max-height: 38%;
  overflow: auto;
  border-top: 1px solid var(--border);
}
.sheet.cons { user-select: text; }
.sheet.cons thead th { cursor: default; }
.sheet.cons th.grp {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--head-bg);
  color: var(--text);
  font-weight: 600;
  text-align: left;
}
.sheet.cons td { cursor: text; }
.sheet.cons td.debit { color: var(--negative); }
.sheet.cons td.credit { color: var(--positive); }

.sheet td input,
.sheet td select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0 6px;
  border: none;
  border-radius: 0;
  z-index: 1;
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--surface);
}
.sheet td.num input { text-align: right; }
