/* 
 * Tesouro Direto - Modern Financial UI
 * Responsive Table CSS
 */

/* Enhanced Table Responsiveness */
.table-container {
  width: 100%;
  position: relative;
  margin-bottom: var(--spacing-xl);
  background-color: var(--color-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

/* Table Scroll Hint */
.table-scroll-hint {
  display: none;
  text-align: center;
  padding: var(--spacing-sm);
  margin-bottom: 0;
  color: var(--color-text-secondary);
  font-size: 0.875rem;
  background-color: rgba(0, 0, 0, 0.02);
  border-bottom: 1px solid var(--color-border);
}

.table-scroll-hint i {
  animation: scroll-hint 1.5s infinite;
}

@keyframes scroll-hint {
  0% {
    transform: translateX(-5px);
  }
  50% {
    transform: translateX(5px);
  }
  100% {
    transform: translateX(-5px);
  }
}

/* Base Table Styles */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

/* Column Priority System */
.table .priority-high {
  /* These columns will always be visible */
  position: relative;
  z-index: 2;
}

.table .priority-medium {
  /* These columns will be hidden on very small screens */
  position: relative;
  z-index: 1;
}

.table .priority-low {
  /* These columns will be hidden first on small screens */
  position: relative;
  z-index: 0;
}

/* Responsive Breakpoints - Desktop and Tablet Landscape */
@media (min-width: 992px) {
  .table-container {
    overflow-x: visible;
  }

  .table-scroll-hint {
    display: none;
  }

  /* Desktop optimization - readable fonts like the image */
  .table th,
  .table td {
    padding: var(--spacing-sm);
    font-size: 0.95rem;
  }

  /* Keep numeric columns readable and well-spaced */
  .table .numeric {
    font-size: 0.95rem;
    white-space: nowrap;
  }

  /* Allow controlled line breaks in specific columns */
  .table th:nth-child(1),
  .table td:nth-child(1),
  .table th:nth-child(4),
  .table td:nth-child(4),
  .table th:nth-child(12),
  .table td:nth-child(12) {
    white-space: normal;
    line-height: 1.2;
  }

  /* Status column with good visibility */
  .status {
    font-size: 0.8rem;
    padding: 0.3rem 0.7rem;
  }

  /* Flexible table layout that adapts to screen size */
  .table {
    table-layout: auto;
    width: 100%;
  }

  /* Compact column widths with line breaks */
  .table th:nth-child(1) {
    min-width: 90px;
  } /* Nome - compacto com quebra de linha */
  .table th:nth-child(2) {
    min-width: 85px;
  } /* Vencimento */
  .table th:nth-child(3) {
    min-width: 90px;
  } /* Invest. Mínimo */
  .table th:nth-child(4) {
    min-width: 70px;
  } /* Última Taxa - compacto com quebra de linha */
  .table th:nth-child(5) {
    min-width: 65px;
  } /* Mínimo */
  .table th:nth-child(6) {
    min-width: 70px;
  } /* 1º Quartil */
  .table th:nth-child(7) {
    min-width: 65px;
  } /* Mediana */
  .table th:nth-child(8) {
    min-width: 70px;
  } /* 3º Quartil */
  .table th:nth-child(9) {
    min-width: 65px;
  } /* Máximo */
  .table th:nth-child(10) {
    min-width: 65px;
  } /* Média */
  .table th:nth-child(11) {
    min-width: 75px;
  } /* Desvio Padrão */
  .table th:nth-child(12) {
    min-width: 85px;
  } /* Janela - compacto com quebra de linha */
}

/* Tablet View - Horizontal Scroll */
@media (min-width: 768px) and (max-width: 991px) {
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table {
    min-width: 900px;
  }

  .table-scroll-hint {
    display: block;
  }

  .table th,
  .table td {
    padding: var(--spacing-sm);
  }
}

/* Mobile View - Card Layout */
@media (max-width: 767px) {
  /* Hide the scroll hint since we're using cards */
  .table-scroll-hint {
    display: none;
  }

  /* Reset container overflow */
  .table-container {
    overflow-x: visible;
    padding: 0;
  }

  /* Transform table to cards */
  .table,
  .table thead,
  .table tbody,
  .table th,
  .table td,
  .table tr {
    display: block;
  }

  /* Hide table headers */
  .table thead tr {
    position: absolute;
    top: -9999px;
    left: -9999px;
  }

  /* Style each row as a card */
  .table tbody tr {
    margin-bottom: var(--spacing-md);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    background-color: var(--color-card);
    border: 1px solid var(--color-border);
    overflow: hidden;
  }

  /* Style each cell */
  .table td {
    position: relative;
    padding: var(--spacing-sm) var(--spacing-md);
    padding-left: 50%;
    text-align: right;
    border-bottom: 1px solid var(--color-border);
    min-height: 30px;
  }

  .table td:last-child {
    border-bottom: none;
  }

  /* Add labels before each cell */
  .table td:before {
    content: attr(data-label);
    position: absolute;
    top: var(--spacing-sm);
    left: var(--spacing-md);
    width: 45%;
    padding-right: var(--spacing-sm);
    white-space: nowrap;
    text-align: left;
    font-weight: 600;
  }

  /* Make sure the status indicator is centered */
  .table td:last-child {
    text-align: center;
    padding: var(--spacing-md) var(--spacing-lg);
  }

  .table td:last-child .status {
    display: inline-flex;
    width: 100%;
    justify-content: center;
    margin: var(--spacing-sm) 0;
  }

  /* Hide low priority columns on mobile */
  .table td.priority-low {
    display: none;
  }

  /* Optimize font sizes for mobile */
  .table td {
    font-size: 0.9rem;
  }

  .table td.numeric {
    font-size: 0.85rem;
  }

  .status {
    padding: 2px 6px;
    font-size: 0.7rem;
  }
}

/* Very Small Mobile View - Further Optimization */
@media (max-width: 480px) {
  /* Hide medium priority columns on very small screens */
  .table td.priority-medium {
    display: none;
  }

  .table td {
    padding: var(--spacing-xs) var(--spacing-md);
    font-size: 0.85rem;
  }

  .table td:before {
    font-size: 0.85rem;
  }
}

/* Accessibility Enhancements */
.table-container:focus-within {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* High Contrast Mode Support */
@media (forced-colors: active) {
  .table th {
    border: 1px solid CanvasText;
  }

  .table td {
    border: 1px solid CanvasText;
  }

  .table-scroll-hint {
    border: 1px solid CanvasText;
  }

  .table tbody tr {
    border: 2px solid CanvasText;
  }
}

/* Screen reader only class */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}
/* Remove ALL DataTables sorting arrows completely */
.table th.sorting::before,
.table th.sorting::after,
.table th.sorting_asc::before,
.table th.sorting_asc::after,
.table th.sorting_desc::before,
.table th.sorting_desc::after {
  display: none !important;
  content: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
}

/* Remove any padding that was reserved for arrows */
.table th.sorting,
.table th.sorting_asc,
.table th.sorting_desc {
  padding-right: var(--spacing-sm) !important;
  position: relative;
}

/* Ensure no pseudo-elements are created */
.table th.sorting:before,
.table th.sorting:after,
.table th.sorting_asc:before,
.table th.sorting_asc:after,
.table th.sorting_desc:before,
.table th.sorting_desc:after {
  display: none !important;
}

/* Override any DataTables default styles */
table.dataTable thead th.sorting,
table.dataTable thead th.sorting_asc,
table.dataTable thead th.sorting_desc {
  background-image: none !important;
  background-repeat: no-repeat;
  background-position: center right;
  cursor: pointer;
}

/* Remove any background images that might be used for arrows */
table.dataTable thead .sorting,
table.dataTable thead .sorting_asc,
table.dataTable thead .sorting_desc {
  background-image: none !important;
}
/* Force remove DataTables sorting indicators with maximum specificity */
table.dataTable thead th.sorting:after,
table.dataTable thead th.sorting_asc:after,
table.dataTable thead th.sorting_desc:after,
table.dataTable thead th.sorting:before,
table.dataTable thead th.sorting_asc:before,
table.dataTable thead th.sorting_desc:before {
  display: none !important;
  content: "" !important;
  opacity: 0 !important;
  visibility: hidden !important;
  width: 0 !important;
  height: 0 !important;
}

/* Clean header appearance without arrows */
table.dataTable thead th {
  position: relative;
  padding-right: var(--spacing-sm) !important;
}

/* Ensure clickable area remains for sorting functionality */
table.dataTable thead th.sorting,
table.dataTable thead th.sorting_asc,
table.dataTable thead th.sorting_desc {
  cursor: pointer;
  user-select: none;
}

/* Add subtle hover effect to indicate sortable columns */
table.dataTable thead th.sorting:hover,
table.dataTable thead th.sorting_asc:hover,
table.dataTable thead th.sorting_desc:hover {
  background-color: rgba(var(--color-primary-rgb), 0.1);
  color: var(--color-text) !important;
}

/* Ensure text remains visible in light mode */
.light-theme table.dataTable thead th.sorting:hover,
.light-theme table.dataTable thead th.sorting_asc:hover,
.light-theme table.dataTable thead th.sorting_desc:hover,
body:not(.dark-theme) table.dataTable thead th.sorting:hover,
body:not(.dark-theme) table.dataTable thead th.sorting_asc:hover,
body:not(.dark-theme) table.dataTable thead th.sorting_desc:hover {
  color: #333 !important;
  background-color: rgba(59, 130, 246, 0.1);
}
/* ===== SEARCH BOX REDESIGN ===== */

/* CSS Custom Properties for Search Box */
:root {
  --search-bg: #ffffff;
  --search-border: #e2e8f0;
  --search-text: #1a202c;
  --search-placeholder: #9ca3af;
  --search-focus: #3b82f6;
  --search-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --search-focus-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Dark theme variables */
.dark-theme {
  --search-bg: #2d3748;
  --search-border: #4a5568;
  --search-text: #f7fafc;
  --search-placeholder: #a0aec0;
  --search-focus: #63b3ed;
  --search-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --search-focus-shadow: 0 0 0 3px rgba(99, 179, 237, 0.2);
}

/* DataTables search container styling */
.dataTables_filter {
  margin-bottom: 1.5rem !important;
  text-align: center !important;
  display: flex !important;
  justify-content: center !important;
}

.dataTables_filter label {
  display: flex !important;
  align-items: center !important;
  gap: 0.75rem !important;
  font-weight: 500 !important;
  color: var(--search-text) !important;
  margin-bottom: 0 !important;
  flex-direction: row !important;
  position: relative;
  width: 100%;
  max-width: 400px;
}

/* Search input container with modern design */
.dataTables_filter input[type="search"] {
  width: 100% !important;
  padding: 12px 20px !important;
  border: 2px solid var(--search-border) !important;
  border-radius: 12px !important;
  background-color: var(--search-bg) !important;
  color: var(--search-text) !important;
  font-size: 0.875rem !important;
  font-weight: 400 !important;
  line-height: 1.5 !important;
  box-shadow: var(--search-shadow) !important;
  transition: all 0.2s ease-in-out !important;
  outline: none !important;
}

/* Search input placeholder */
.dataTables_filter input[type="search"]::placeholder {
  color: var(--search-placeholder) !important;
  opacity: 1 !important;
}
/* Search icon before the label text */
.dataTables_filter label::before {
  content: "\f002"; /* FontAwesome search icon */
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  position: static;
  color: var(--search-text);
  font-size: 0.875rem;
  margin-right: 0.5rem;
  pointer-events: none;
}

/* Adjust icon color on focus */
.dataTables_filter label:focus-within::before {
  color: var(--search-focus);
}
/* Enhanced input field styling */
.dataTables_filter input[type="search"] {
  /* Remove default search input styling */
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  appearance: none !important;
}

/* Remove the X button in search inputs on WebKit browsers */
.dataTables_filter input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none !important;
  display: none !important;
}

/* Custom focus state */
.dataTables_filter input[type="search"]:focus {
  border-color: var(--search-focus) !important;
  box-shadow: var(--search-focus-shadow) !important;
}

/* Hover state */
.dataTables_filter input[type="search"]:hover:not(:focus) {
  border-color: var(--search-focus) !important;
  box-shadow: var(--search-shadow) !important;
}

/* Responsive design for search box */
@media (max-width: 768px) {
  .dataTables_filter label {
    max-width: 100%;
    flex-direction: column !important;
    gap: 0.5rem !important;
  }

  .dataTables_filter input[type="search"] {
    font-size: 16px !important; /* Prevent zoom on iOS */
    padding: 14px 16px !important;
  }
}

@media (max-width: 480px) {
  .dataTables_filter {
    margin-bottom: 1rem !important;
  }

  .dataTables_filter label {
    flex-direction: column !important;
    gap: 0.5rem !important;
  }

  .dataTables_filter input[type="search"] {
    padding: 12px 14px !important;
    border-radius: 10px !important;
  }

  .dataTables_filter label::before {
    font-size: 0.8rem;
  }
}
/* Mobile status text - keep on single line */
@media (max-width: 767px) {
  .status {
    white-space: nowrap !important;
  }

  .status br {
    display: none !important;
  }

  .status br::before {
    content: " " !important;
    white-space: pre !important;
  }

  /* Force space replacement for br tags */
  .table td:last-child .status {
    line-height: 1.2;
  }
}
/* Mobile layout - Alert card first */
@media (max-width: 767px) {
  .container {
    display: flex;
    flex-direction: column;
  }

  #alerta {
    order: -1; /* Move alert to first position */
  }

  #dashboard {
    order: 0; /* Keep dashboard in normal position */
  }

  .table-container {
    order: 1; /* Table after dashboard */
  }
}
/* Mobile - Increase vertical padding for status elements */
@media (max-width: 767px) {
  .status {
    padding: 0.75rem 1.5rem !important;
    text-align: center !important;
    display: block !important;
    width: 100% !important;
  }
}

/* Very small mobile - adjust padding accordingly */
@media (max-width: 480px) {
  .status {
    padding: 0.7rem 1.2rem !important;
    text-align: center !important;
    display: block !important;
    width: 100% !important;
  }
}
