/* === VARIÁVEIS === */
:root {
  --primary: #4f5d75;
  --secondary-color: #3498db;
  --highlight-color: #248624;
  --brand: #5f6fff;
  --brand-hover: #3d4ad6;
  --accent: #2d3142;
  --bg: #f6f7fb;
  --text: #222;
  --text-light: #666;
  --border: #e0e3ea;
  --card-bg: #fff;
  --shadow: 0 2px 12px rgba(60, 72, 88, 0.07);
  --radius: 8px;
  --positive-value: #11b911;
  --negative-value: #e91010;
}

body, html {
  margin: 0;
  padding: 0;
  font-family: 'Inter', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased; /* Melhora rendering de fontes no mobile */
  -moz-osx-font-smoothing: grayscale;
}

/* === HEADER === */
.main-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 32px;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo img {
  width: 38px;
  height: 38px;
  border-radius: 8px;
}

.brand-title {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--brand);
}

.header-nav {
  display: flex;
  gap: 28px;
}

.header-nav a {
  text-decoration: none;
  color: var(--text-light);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 6px;
  border-bottom: 2px solid transparent;
  transition: 0.2s;
}

.header-nav a:hover, .header-nav .active, .header-nav a.active {
  color: var(--brand);
  border-bottom: 2px solid var(--brand);
}

/* === LAYOUT === */
.layout {
  display: flex;
  margin-top: 46px;
  min-height: calc(100vh - 64px);
}

.sidebar {
  min-width: 180px;
  background: #f9f9f9;
  border-right: 1px solid var(--border);
  padding-top: 32px;
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  align-items: left;
  padding-left: 14px;
  gap: 18px;
}

.sidebar-link {
  text-decoration: none;
  color: var(--text-light);
  font-weight: 500;
  font-size: 1rem;
  padding: 8px 16px;
  max-width: 160px;
  padding-left: 12px;
  text-align: left;
  border-radius: var(--radius);
  transition: 0.2s;
}

.sidebar-link:hover, .sidebar-link.active {
  background: var(--brand);
  color: white;
}

.main-content {
  flex: 1;
  padding: 30px 26px;
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* === COMPONENTES === */
.card {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  margin-top: 0px;
  margin-bottom: 10px; /* Reduzido para menos espaço vertical */
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.filters-card { 
  margin-bottom: 0;
  margin-top: 0;
}

.search-card { 
  padding: 14px 18px;
  margin-top: 0;
  margin-bottom: 0;
}

.table-card {
  padding: 14px 18px;
  overflow-x: auto;
  display: flex;
  justify-content: center;
  box-sizing: border-box;
  margin-top: 0;
  -webkit-overflow-scrolling: touch;
}

.filters-row,
.search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: flex-end;
  margin-top: 0;
  margin-bottom: 0;
}

.select-group {
  display: flex;
  flex-direction: column;
  min-width: 120px;
  max-width: 180px;
  flex: 1 1 120px;
}

.select-group label {
  font-size: 0.85rem;
  margin-bottom: 4px;
  color: var(--text-light);
}

.select-group select,
.select-group input[type="text"] {
  padding: 4px 10px;
  height: 36px;
  font-size: 0.85rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #f8f9fb;
  box-sizing: border-box;
}

#file-date {
  height: 36px !important;
  padding: 4px 10px !important;
  font-size: 0.85rem !important;
  box-sizing: border-box;
}

.datepicker {
  font-size: 0.85rem;
  height: 32px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #f8f9fb;
}

#search-input {
  flex: 1;
  padding: 6px 10px;
  height: 30px;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

#search-button,
#clear-button {
  height: 44px; /* Mínimo para touch */
  background: var(--brand);
  color: white;
  font-size: 0.85rem;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  padding: 6px 16px;
  cursor: pointer;
  touch-action: manipulation; /* Melhora toques */
}

#search-button:hover,
#clear-button:hover {
  background: var(--brand-hover);
}

.wide-button {
  width: 100%;
  background: var(--brand);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: normal;
  transition: background 0.2s ease;
  max-height: 32px;
}

.wide-button:hover {
  background: var(--brand-hover);
}

.table-container {
  width: 100%;
  overflow-x: auto;
  min-width: 800px;
  -webkit-overflow-scrolling: touch;
}

.performance-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
  table-layout: auto;
}

.performance-table thead th {
  background-color: var(--brand);
  color: white;
  text-transform: uppercase;
  text-align: center;
  font-size: 0.75rem;
  padding: 10px;
  white-space: nowrap;
}

.performance-table td {
  padding: 8px;
  border-bottom: 1px solid #e0e0e0;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

.performance-table .positive {
  color: var(--positive-value);
  font-weight: normal;
}

.performance-table .negative {
  color: var(--negative-value);
  font-weight: normal;
}

.performance-table td:first-child {
  text-align: left;
}

.performance-table td:first-child::first-line {
  font-weight: bold;
}

.performance-table td:first-child a {
  font-weight: normal !important;
}

.performance-table th {
  background-color: #f0f5ff;
  text-align: center;
  padding: 8px;
  font-weight: 600;
  white-space: nowrap;
}

.performance-table thead th {
  background-color: var(--brand);
  color: white;
  text-transform: uppercase;
  text-align: center;
  font-size: 0.75rem;
  padding: 10px;
}

.performance-table td {
  padding: 8px;
  border-bottom: 1px solid #e0e0e0;
  text-align: center;
  vertical-align: middle;
  padding: 8px;
}

.performance-table td:first-child {
  text-align: center;
}

.performance-table td:first-child::first-line {
  font-weight: bold;
}

.performance-table td:first-child a {
  font-weight: normal !important;
}

.table-header {
  text-align: center;
  font-weight: bold;
  font-size: 1rem;
  margin: 8px 0;
  color: var(--accent);
}

.table-header-2 {
  text-align: center;
  font-weight: bold;
  font-size: 1rem;
  color: var(--accent);
}

.metric-box {
  background-color: white;
  border: 1px solid #ddd;
  border-radius: 12px;
  width: 120px;
  height: 70px;
  padding: 8px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  justify-content: center;
  transition: transform 0.2s ease-in-out;
}

.metric-box label {
  font-size: 0.75rem;
  font-weight: 500;
  color: #444;
  margin-bottom: 4px;
  font-weight: 300;
}

.metric-value {
  font-size: 0.7rem;
  font-weight: 400;
}

.metric-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f8f9fa;
}

.metric-value {
  font-weight: bold;
  font-size: 16px;
  display: inline-block;
  margin-top: 8px;
}

.metric-value.positive {
  color: var(--positive-value)
}

.metric-value.negative {
  color: var(--negative-value)
}

.metric-value.green { color: var(--positive-value); }
.metric-value.red { color: var(--negative-value); }
.metric-value.gray { color: #636058; }

.metric-line {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}

.metrics-container {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-bottom: 20px;
}

#etf-table thead th {
  font-size: 0.7rem; /* Aumentado ligeiramente para melhor legibilidade */
  white-space: nowrap;
  padding: 6px;
  background: var(--brand);
  color: white;
  text-align: center;
  cursor: pointer;
  position: relative;
  user-select: none;
}

#etf-table thead th[data-sort='asc']::after {
  content: ' ▲';
  color: #fff;
}

#etf-table thead th[data-sort='desc']::after {
  content: ' ▼';
  color: #fff;
}

#etf-table td {
  font-size: 0.7rem;
  white-space: nowrap;
  padding: 6px;
  text-align: center;
}

#etf-table tbody tr:nth-child(even) {
  background: #f2f3f7;
}

#etf-table tbody tr:nth-child(odd) {
  background: #ffffff;
}

#etf-table .ticker-symbol {
  font-weight: bold;
}

#etf-table .ticker-links {
  font-weight: normal;
  margin-left: 4px;
}

.pagination-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  font-size: 0.85rem;
  flex-direction: row; /* Mantém row por padrão */
}

.pagination-container > a,
.pagination-container > button {
  margin: 0 1px;
  min-height: 44px; /* Touch-friendly */
  touch-action: manipulation;
}

.pagination-container select,
.pagination-container button,
.pagination-container a {
  height: 32px;
  padding: 0 10px;
  background: var(--brand);
  color: white;
  font-size: 0.8rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  min-width: 40px; /* Evita botões muito estreitos */
}

.pagination-container select {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
}

.pagination-container a.active {
  background: var(--brand-hover);
  font-weight: bold;
}

.page-footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-light);
  padding-top: 10px;
  border-top: 1px solid var(--border);
  background: transparent;
}

/* === UTILITÁRIOS === */
.align-button-bottom { margin-top: 18px; }
.return { font-weight: bold; }

/* === RESPONSIVO === */
@media (max-width: 768px) {
  .main-content { 
    padding: 15px;
    gap: 12px; /* Reduz gap geral */
  }
  
  .sidebar { 
    width: 100%; 
    height: auto; 
    position: relative; 
    top: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 15px;
  }
  
  .layout { 
    flex-direction: column; 
  }
  
  .filters-row,
  .search-row,
  .metrics-container,
  .metrics-wrapper {
    flex-direction: column;
    align-items: stretch;
    gap: 12px; /* Gap menor */
  }
  
  .select-group,
  #search-input,
  #search-button,
  #clear-button {
    width: 100%;
    max-width: none;
  }
  
  .date-nav-wrapper {
    justify-content: center; /* Centraliza para melhor alinhamento */
    width: 100%;
    gap: 6px;
  }
  
  .nav-button,
  .styled-button {
    padding: 6px 10px;
    min-height: 44px;
    touch-action: manipulation;
  }
  
  .table-card,
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0;
  }
  
  #etf-table,
  .performance-table {
    min-width: 800px;
    font-size: 0.7rem;
  }
  
  #etf-table th,
  #etf-table td,
  .performance-table th,
  .performance-table td {
    padding: 4px 6px;
  }
  
  .pagination-container {
    flex-direction: row; /* Horizontal com wrap */
    flex-wrap: wrap;
    gap: 6px; /* Gap menor para compactar */
    justify-content: center;
  }
  
  .pagination-container select,
  .pagination-container button,
  .pagination-container a {
    width: auto; /* Não full-width, para caberem em linha */
    margin: 4px;
    min-width: 40px;
  }
  
  h1#ranking-title {
    font-size: 1.2rem;
    word-break: break-word;
  }
  
  .page-footer {
    font-size: 0.7rem;
  }
}

/* Para telas muito pequenas (ex: < 480px) */
@media (max-width: 480px) {
  body {
    font-size: 0.9rem;
  }
  
  #etf-table th,
  #etf-table td,
  .performance-table th,
  .performance-table td {
    font-size: 0.65rem;
    padding: 3px 5px;
  }
  
  .select-group label,
  .select-group select,
  input[type="text"] {
    font-size: 0.8rem;
  }

  .pagination-container {
    gap: 4px;
  }
}

/* novo seletor para corretoras */
#broker-select {
  min-width: 180px;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 0.85rem;
  height: auto;
  max-height: 36px;
  overflow-y: auto;
}

#broker-select[multiple] {
  height: auto;
  max-height: 36px;
  overflow-y: auto;
}

.ts-wrapper {
  height: auto !important;
  min-height: 36px !important;
  max-height: 36px;
  border-radius: 6px;
}

.ts-wrapper.focus {
  max-height: 250px;
  overflow-y: auto;
}

.ts-control {
  min-height: 36px;
  padding: 2px 8px;
  font-size: 0.85rem;
}

.ts-wrapper.multi .ts-control {
  flex-wrap: nowrap;
  overflow-x: auto;
  padding: 6px 6px;
  font-size: 0.82rem;
  height: 36px;
}

.ts-dropdown {
  max-height: 220px;
  overflow-y: auto;
  font-size: 0.82rem;
}

#results-table td.ret-pos {
  color: var(--positive-value);
  font-weight: normal;
  font-size: 0.75rem;
  
}

#results-table td.ret-neg {
  color: var(--negative-value);
  font-weight: normal;
  font-size: 0.75rem;
  
}


.nav-button {
  padding: 4px 10px;
  font-size: 1rem;
  border: 1px solid var(--border-light);
  background-color: var(--background-light);
  cursor: pointer;
  border-radius: var(--radius);
  transition: background 0.2s ease;
  height: 34px;
}

.nav-button:hover {
  background-color: var(--brand-hover);
}

.date-nav-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.styled-button {
  padding: 6px 12px;
  font-size: 14px;
  background-color: var(--brand);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.styled-button:hover {
  background-color: var(--brand-hover);
}

.styled-input {
  width: 130px;
  padding: 6px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 14px;
}

.loading-text {
  text-align: center;
  font-size: 1rem;
  color: #666;
  margin: 20px 0;
}

.date-ms {
  text-align: center;
  font-size: 0.5rem;
  color: #ffffff;
}

.broaker-link {
  font-size: 0.65rem;
  color: var(--brand);
}

.broaker-link:hover {
  background-color: var(--brand-hover);
  color: #ffffff;
}