* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: #090c13;
  color: #e8ebf1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid #1c2130;
  background: #0c1019;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: linear-gradient(135deg, #14e0ac, #0e8f6f);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  box-shadow: 0 0 0 1px rgba(20, 224, 172, 0.25), 0 4px 14px rgba(20, 224, 172, 0.18);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

header h1 {
  font-size: 19px;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.01em;
  color: #f5f7fb;
}

.brand-subtitle {
  font-size: 12px;
  font-weight: 500;
  color: #6b7686;
}

.ticker-dropdown {
  position: relative;
}

.ticker-dropdown-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  margin: -4px -6px;
  border-radius: 6px;
}

.ticker-dropdown-btn:hover {
  background: #161a22;
}

.ticker-dropdown-caret {
  color: #6b7280;
  font-size: 14px;
  transition: transform 0.15s ease;
}

.ticker-dropdown.open .ticker-dropdown-caret {
  transform: rotate(180deg);
}

.ticker-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 280px;
  max-height: 360px;
  background: #12161f;
  border: 1px solid #262a33;
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  z-index: 50;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ticker-dropdown-menu.hidden {
  display: none;
}

#ticker-dropdown-search {
  margin: 8px;
  padding: 8px 10px;
  background: #090c13;
  border: 1px solid #262a33;
  border-radius: 6px;
  color: #e8ebf1;
  font-size: 13px;
  outline: none;
}

#ticker-dropdown-search:focus {
  border-color: #14e0ac;
}

.ticker-dropdown-list {
  overflow-y: auto;
  padding: 0 6px 6px;
}

.ticker-dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: #e8ebf1;
}

.ticker-dropdown-item:hover {
  background: #1c2130;
}

.ticker-dropdown-item.active {
  background: #161a22;
  color: #14e0ac;
  font-weight: 600;
}

.ticker-dropdown-item .institutional-badge {
  font-size: 10px;
}

.ticker-dropdown-empty {
  padding: 12px 10px;
  color: #6b7280;
  font-size: 12px;
  text-align: center;
}

header a, header button {
  color: #aab2c2;
  text-decoration: none;
  background: #121826;
  border: 1px solid #232b3d;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

header a:hover, header button:hover {
  color: #fff;
  border-color: #3a4459;
  background: #171f30;
}

.header-actions {
  display: flex;
  gap: 10px;
}

#alerts-toggle-btn:not(.muted) {
  color: #ffcd6e;
  border-color: rgba(255, 205, 110, 0.35);
  background: rgba(255, 205, 110, 0.08);
}

#alerts-toggle-btn.muted {
  color: #5a6274;
  border-color: #232b3d;
  opacity: 0.8;
}

#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 320px;
}

.toast {
  background: #131826;
  border: 1px solid #232b3d;
  border-left: 4px solid #16dba0;
  border-radius: 9px;
  padding: 12px 16px;
  font-size: 13px;
  color: #e8ebf1;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.2s ease-out;
}

.toast.sell {
  border-left-color: #ff5b60;
}

.toast strong {
  color: #fff;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

main.main-full-width {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  width: 100%;
  max-width: none;
  margin: 0;
  min-height: 0;
  box-sizing: border-box;
}

/* Faixas verticais agrupando cada par (timeframe + Conf.), pra deixar claro
   visualmente quais duas colunas pertencem ao mesmo tempo grafico. Classes
   aplicadas via Tailwind (index.html/app.js) junto de classes utilitarias. */
.tf-group-1 {
  background: rgba(148, 163, 184, 0.07);
}

.tf-group-2 {
  background: rgba(20, 224, 172, 0.06);
}

th.tf-group-1, th.tf-group-2 {
  background: rgba(148, 163, 184, 0.12) !important;
}

th.tf-group-2 {
  background: rgba(20, 224, 172, 0.12) !important;
}

/* Bolinha de sinal buy/sell/neutro (tamanho original, antes dos badges com seta) */
.dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #2a3142;
}

.dot.buy { background: #16dba0; box-shadow: 0 0 8px rgba(22, 219, 160, 0.45); }
.dot.sell { background: #ff5b60; box-shadow: 0 0 8px rgba(255, 91, 96, 0.45); }

/* Toggle estilo "switch" (usado no checkbox Institucional, no formulario e na
   coluna da tabela) em vez do checkbox nativo do navegador. */
.toggle-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 38px;
  height: 22px;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  z-index: 1;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: #232b3d;
  border: 1px solid #2e3750;
  border-radius: 999px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #aab2c2;
  transition: transform 0.15s ease, background 0.15s ease;
}

.toggle-switch input:checked ~ .toggle-track {
  background: #0e8f6f;
  border-color: #14e0ac;
}

.toggle-switch input:checked ~ .toggle-track::after {
  transform: translateX(16px);
  background: #fff;
}

.toggle-switch input:disabled ~ .toggle-track {
  opacity: 0.5;
  cursor: not-allowed;
}

.institutional-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: #f0b429;
  background: rgba(240, 180, 41, 0.12);
  border: 1px solid rgba(240, 180, 41, 0.4);
  border-radius: 999px;
  padding: 2px 10px;
  margin-left: 8px;
  vertical-align: middle;
}

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  background: #161a22;
  padding: 32px;
  border-radius: 10px;
  width: 320px;
  border: 1px solid #262a33;
}

.login-box h1 {
  font-size: 20px;
  margin: 0 0 20px;
  text-align: center;
}

.login-box input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: #0e1117;
  border: 1px solid #333947;
  color: #e6e6e6;
  border-radius: 6px;
  font-size: 14px;
}

.login-box .password-field {
  position: relative;
}

.login-box .password-field input {
  padding-right: 40px;
}

.login-box .password-field button {
  position: absolute;
  right: 6px;
  top: 0;
  bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  background: none;
  border: none;
  color: #6b7280;
  cursor: pointer;
  padding: 0;
}

.login-box .password-field button:hover,
.login-box .password-field button.active {
  color: #e6e6e6;
}

.login-box button[type="submit"] {
  width: 100%;
  padding: 10px;
  background: #26a69a;
  border: none;
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}

.login-box button[type="submit"]:hover { background: #2fbfb0; }

/* Chart page */
.toolbars-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 8px;
}

.chart-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.chart-toolbar button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #161a22;
  border: 1px solid #333947;
  color: #9ba3af;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.chart-toolbar button svg {
  flex-shrink: 0;
}

.chart-toolbar button.active {
  color: #fff;
  border-color: #26a69a;
  background: #1c2b29;
}

.drawing-toolbar-row {
  margin: 10px 0 0;
  padding: 10px 0;
  border-top: 1px solid #1f2530;
  border-bottom: 1px solid #1f2530;
}

.session-levels-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #9ba3af;
  font-size: 13px;
  padding: 0 4px;
  cursor: pointer;
  user-select: none;
}

.volume-color-legend {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #9ba3af;
  font-size: 12px;
  padding: 0 4px;
  cursor: default;
  user-select: none;
}

.volume-color-legend .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 2px;
}

.volume-color-legend .dot:not(:first-child) {
  margin-left: 10px;
}

#drawing-toolbar button {
  font-size: 12px;
  padding: 6px 10px;
}

#clear-drawings-btn {
  border-color: #4a2a2a !important;
  color: #ef8a8a !important;
}

#clear-drawings-btn:hover {
  border-color: #ef5350 !important;
  color: #ef5350 !important;
}

#drawing-hint {
  font-size: 12px;
  color: #f0b429;
}

#drawing-hint:empty {
  display: none;
}

#drawings-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

#drawings-list:not(:empty) {
  margin: 8px 0;
}

.drawing-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #161a22;
  border: 1px solid #333947;
  border-radius: 14px;
  padding: 3px 6px 3px 10px;
  font-size: 12px;
  color: #9ba3af;
}

.drawing-chip button {
  background: none;
  border: none;
  color: #6b7280;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 2px 4px;
}

.drawing-chip button:hover {
  color: #ef5350;
}

.analysis-panel-header {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

#analysis-collapse-toggle {
  background: none;
  border: none;
  color: #6b7280;
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
}

#analysis-collapse-toggle:hover {
  color: #e6e6e6;
}

#analysis-collapse-icon {
  display: inline-block;
  transition: transform 0.15s ease;
}

#analysis-collapse-toggle.collapsed #analysis-collapse-icon {
  transform: rotate(-90deg);
}

#analysis-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  margin-bottom: 8px;
}

#analysis-panel.collapsed .analysis-item .detail {
  display: none;
}

.analysis-summary {
  display: none;
}

.analysis-item {
  flex: 1 1 150px;
  background: #161a22;
  border: 1px solid #262a33;
  border-radius: 8px;
  padding: 8px 12px;
}

.analysis-item .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
  margin-bottom: 2px;
}

.analysis-item .value {
  font-size: 14px;
  font-weight: 600;
  color: #e6e6e6;
}

.analysis-item .value.up { color: #26a69a; }
.analysis-item .value.down { color: #ef5350; }
.analysis-item .value.neutral { color: #9ba3af; }

.analysis-item .value span.up { color: #26a69a; }
.analysis-item .value span.down { color: #ef5350; }
.analysis-item .value span.neutral { color: #6b7280; }
.analysis-item .value span {
  font-size: 12px;
  font-weight: 600;
  margin-left: 4px;
}

.analysis-item .detail {
  font-size: 11px;
  color: #8a8f98;
  margin-top: 2px;
}

#chart-container {
  width: 100%;
  height: 420px;
  margin-top: 10px;
  background: #161a22;
  border-radius: 8px 8px 0 0;
}

#rsi-container {
  width: 100%;
  height: 140px;
  background: #161a22;
  border-radius: 0 0 8px 8px;
  border-top: 1px solid #22262f;
}

.main-full-width #chart-container {
  flex: 3 1 0;
  height: auto;
  min-height: 0;
}

.main-full-width #rsi-container {
  flex: 1 1 0;
  height: auto;
  min-height: 0;
}

/* Mobile */
@media (max-width: 640px) {
  header {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
  }

  header h1 {
    font-size: 16px;
  }

  .header-actions {
    flex-wrap: wrap;
  }

  main.main-full-width {
    padding: 12px;
  }

  .toolbars-row {
    gap: 8px;
  }

  .analysis-item {
    flex: 1 1 calc(50% - 8px);
  }

  /* No mobile os 6 cards de analise sozinhos ja ocupam boa parte da tela;
     mostra por padrao so um resumo de uma linha (clicavel) e esconde os
     cards completos ate o usuario tocar pra expandir. */
  .analysis-summary {
    display: block;
    width: 100%;
    text-align: left;
    background: #161a22;
    border: 1px solid #262a33;
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 8px;
    color: #e6e6e6;
    font-size: 12px;
    cursor: pointer;
  }

  .analysis-summary-caret {
    float: right;
    color: #6b7280;
    transition: transform 0.15s ease;
  }

  .analysis-summary.expanded .analysis-summary-caret {
    transform: rotate(180deg);
  }

  #analysis-panel {
    display: none;
  }

  #analysis-panel.expanded {
    display: flex;
  }

  .main-full-width #chart-container {
    flex: 2 1 0;
  }

  #chart-container,
  #rsi-container {
    min-height: 200px;
  }
}

/* Celular em orientacao paisagem (largura grande, altura pequena): o layout
   flex de main-full-width divide a altura sobrando entre header/toolbars/
   analise/grafico/RSI, e com pouca altura de viewport essa sobra vira zero,
   fazendo o grafico sumir (altura calculada = 0px) sem nenhum jeito de rolar
   ate ele. Correcao: abaixo de uma altura minima, para de forcar tudo a
   caber na tela (permite rolagem normal da pagina) e garante uma altura
   minima de verdade pro grafico e RSI, em vez de flex: N 1 0 (que pode
   encolher ate 0). Baseado em altura, nao largura, entao pega o landscape
   independente do tamanho do aparelho. */
@media (max-height: 450px) {
  body {
    overflow-y: auto;
    height: auto;
    min-height: 100vh;
  }

  main.main-full-width {
    flex: 0 0 auto;
    overflow: visible;
  }

  .toolbars-row {
    gap: 6px;
  }

  #drawing-hint,
  #drawings-list {
    min-height: 0;
  }

  /* Mesmo resumo compacto usado no breakpoint de largura estreita: em
     paisagem a largura costuma ser grande (nao entra no @media de largura),
     mas a altura ainda eh curta, entao os cards completos empurrariam o
     grafico pra bem abaixo da dobra. */
  .analysis-summary {
    display: block;
    width: 100%;
    text-align: left;
    background: #161a22;
    border: 1px solid #262a33;
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 8px;
    color: #e6e6e6;
    font-size: 12px;
    cursor: pointer;
  }

  .analysis-summary-caret {
    float: right;
    color: #6b7280;
    transition: transform 0.15s ease;
  }

  .analysis-summary.expanded .analysis-summary-caret {
    transform: rotate(180deg);
  }

  #analysis-panel {
    display: none;
  }

  #analysis-panel.expanded {
    display: flex;
  }

  .main-full-width #chart-container {
    flex: none;
    height: 280px;
    min-height: 280px;
  }

  .main-full-width #rsi-container {
    flex: none;
    height: 120px;
    min-height: 120px;
  }
}
