/* Cloud Tables Frontend Styles */

/* Main Container */
.ct-table-wrap {
  background: #f2f4ff;
  padding: 20px;
  border-radius: 4px;
  margin: 20px 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

/* Table Container with Horizontal Scroll */
.ct-table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 15px 0;
  border-radius: 4px;
}

/* Top Controls Bar */
.ct-table-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  gap: 15px;
}

/* Entries Selector */
.ct-entries-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #333;
}
.ct-entries-selector select {
  padding: 4px 8px;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 13px;
  background: white;
}

/* Search Box */
.ct-search-box {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ct-search-label {
  font-size: 13px;
  color: #333;
  white-space: nowrap;
}
.ct-search-input {
  padding: 6px 30px 6px 10px;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 13px;
  width: 200px;
  transition: border-color 0.2s ease;
  background: white;
}
.ct-search-input:focus {
  outline: none;
  border-color: #999;
}
.ct-search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 16px;
  color: #999;
  cursor: pointer;
  padding: 0;
  width: 18px;
  height: 18px;
  display: none;
  line-height: 1;
}
.ct-search-clear:hover {
  color: #333;
}
.ct-search-input:not(:placeholder-shown) + .ct-search-clear {
  display: block;
}

/* Table Styling */
.ct-table {
  width: 100%; /* Use full container width on desktop */
  min-width: 600px; /* Ensure minimum width for horizontal scroll */
  border-collapse: separate;
  border-spacing: 0;
  background: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  font-size: 13px;
  table-layout: auto; /* Allow columns to auto-size based on content */
}

/* Table Header */
.ct-table thead tr.ct-header-row {
  background: #ff5e00;
}
.ct-table thead tr.ct-column-search-row {
  background: #ff5e00;
}
.ct-table th {
  padding: 12px 15px;
  text-align: left;
  font-weight: 600;
  color: white;
  border: 1px solid #cf4d02;
  border-bottom: 1px solid #cf4d02;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap; /* Prevent text wrapping in headers */
  min-width: 120px; /* Minimum width for all columns */
}
.ct-table th:first-child {
  border-left: 1px solid #cf4d02;
}
.ct-table th:last-child {
  border-right: 1px solid #cf4d02;
}

/* Column Search Row */
.ct-column-search-cell {
  padding: 6px 8px !important;
  vertical-align: middle;
  position: relative;
}
.ct-column-search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}
.ct-column-search-input {
  width: 100%; /* Fill the full width of the column */
  min-width: 0; /* Remove any minimum width constraint */
  margin: auto;
  padding: 4px 8px;
  border: 1px solid #dee2e6;
  border-radius: 4px 0 0 4px;
  background: white;
  color: #212529;
  font-size: 12px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  box-sizing: border-box;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  height: 28px;
}
.ct-column-search-wrapper:not(:has(.ct-filter-dropdown-btn))
  .ct-column-search-input {
  border-radius: 4px;
}
.ct-column-search-input:focus {
  outline: none;
  border-color: #6c757d;
  background: white;
  box-shadow: 0 0 0 2px rgba(108, 117, 125, 0.1);
}
.ct-column-search-input::placeholder {
  color: #6c757d;
  font-style: italic;
  font-weight: 300;
}

/* Filter Dropdown */
.ct-filter-dropdown-btn {
  background: #f8f9fa;
  border: 1px solid #dee2e6;
  border-left: none;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 11px;
  color: #495057;
  font-weight: 500;
  border-radius: 0 4px 4px 0;
  transition: background-color 0.2s ease, border-color 0.2s ease;
  height: 28px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ct-filter-dropdown-btn:hover {
  background: #e9ecef;
  border-color: #adb5bd;
}
.ct-filter-dropdown-btn:active {
  background: #dee2e6;
}
.ct-filter-dropdown-btn:focus {
  outline: none;
  box-shadow: none;
}
/* Portal container for dropdowns */
#ct-dropdown-portal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  pointer-events: none;
  z-index: 10000;
}

.ct-filter-dropdown {
  position: absolute;
  background: white;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  z-index: 10000;
  display: none;
  max-height: 200px;
  overflow-y: auto;
  margin-top: 2px;
  will-change: transform, opacity;
  transition: opacity 0.15s ease-out, transform 0.15s ease-out;
  pointer-events: auto;
}

.ct-filter-dropdown.show {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

.ct-filter-dropdown.closing {
  opacity: 0 !important;
  transform: translateY(-10px) !important;
  pointer-events: none;
}

/* Ensure proper stacking context */
.ct-table-container {
  position: relative;
  z-index: 1;
}
@keyframes dropdownFadeIn {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes dropdownFadeOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-5px);
  }
}
.ct-filter-option {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  color: #212529;
  border-bottom: 1px solid #f8f9fa;
  transition: background-color 0.15s ease;
  font-weight: 400;
}
.ct-filter-option:hover {
  background: #f8f9fa;
  color: #212529;
}
.ct-filter-option:last-child {
  border-bottom: none;
}

/* Table Body */
.ct-table tbody tr {
  transition: background-color 0.15s ease;
}
.ct-table tbody tr:hover {
  background-color: #f9f9f9;
}
.ct-table td {
  padding: 12px 15px;
  color: #333;
  border: 1px solid #f2f2f2;
  vertical-align: middle;
  white-space: nowrap; /* Prevent text wrapping in cells */
  min-width: 50px; /* Minimum width for all columns */
}
.ct-table tbody tr:first-child td {
  border-top: 1px solid #f2f2f2;
}
.ct-table tbody tr:last-child td {
  border-bottom: 1px solid #f2f2f2;
}
.ct-table td:first-child {
  border-left: 1px solid #f2f2f2;
}
.ct-table td:last-child {
  border-right: 1px solid #f2f2f2;
}

/* Pagination Area */
.ct-pagination-area {
  margin-top: 15px;
  display: flex;
  justify-content: center;
}
.ct-pagination-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.ct-search-results {
  color: #ff6622;
  font-weight: 600;
  font-size: 13px;
}
.ct-no-results {
  color: #d63638;
  font-weight: 600;
  font-size: 13px;
}
.ct-pagination-info {
  font-size: 13px;
  color: #666;
}

/* Search Highlighting */
.ct-search-highlight {
  background: #fff3cd;
  color: #856404;
  padding: 2px 4px;
  border-radius: 2px;
  font-weight: 600;
}

/* Column Search Highlighting */
.ct-column-search-highlight {
  background: #d1ecf1;
  color: #0c5460;
  padding: 2px 4px;
  border-radius: 2px;
  font-weight: 600;
  border: 1px solid #bee5eb;
}

/* No Results Row */
.ct-no-results-row {
  text-align: center;
  color: #999;
  font-style: italic;
  padding: 30px;
}

/* Pagination Controls */
.ct-pagination {
  display: flex;
  align-items: center;
  gap: 3px;
}
.ct-page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border: 2px solid #e0e0e0;
  background: white;
  color: #555;
  text-decoration: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s ease;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.ct-page-btn:hover {
  background: #f8f9fa;
  border-color: #ff5e00;
  color: #ff5e00;
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}
.ct-page-btn.ct-current {
  background: #ff5e00;
  color: white;
  border-color: #ff5e00;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(255, 94, 0, 0.3);
}
.ct-page-btn.ct-current:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 12px rgba(255, 94, 0, 0.4);
}
.ct-page-btn.ct-disabled {
  background: #f5f5f5;
  color: #ccc;
  border-color: #e0e0e0;
  cursor: not-allowed;
  opacity: 0.6;
}
.ct-page-btn.ct-disabled:hover {
  transform: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.ct-page-btn.ct-first,
.ct-page-btn.ct-last,
.ct-page-btn.ct-prev,
.ct-page-btn.ct-next {
  font-size: 16px;
  font-weight: 600;
}
.ct-page-dots {
  padding: 0 8px;
  color: #999;
  font-size: 16px;
  font-weight: bold;
}

/* Responsive Design */
@media (max-width: 768px) {
  .ct-table-wrap {
    padding: 15px;
  }
  .ct-table-container {
    margin: 10px -20px; /* Extend to edges on mobile */
    padding: 0 20px;
    border-radius: 0;
  }
  .ct-table-controls {
    flex-direction: column;
    align-items: stretch;
  }
  .ct-entries-selector,
  .ct-search-box {
    justify-content: space-between;
  }
  .ct-search-input {
    width: auto;
    flex: 1;
  }
  .ct-table {
    font-size: 12px;
    min-width: 500px; /* Smaller minimum width on mobile */
  }
  .ct-table th,
  .ct-table td {
    padding: 8px 10px;
  }
  .ct-pagination-area {
    text-align: center;
  }
  .ct-pagination-section {
    align-items: center;
  }
  .ct-pagination {
    justify-content: center;
  }
  .ct-page-btn {
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    font-size: 12px;
  }
  .ct-page-dots {
    display: none; /* Hide dots on mobile */
  }
}

@media (max-width: 480px) {
  .ct-table-wrap {
    padding: 10px;
    margin: 10px 0;
  }
  .ct-table {
    font-size: 11px;
  }
  .ct-table th,
  .ct-table td {
    padding: 6px 8px;
  }
}

/* High-Performance Loading States */
.ct-loading {
  position: relative;
}

.ct-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  border-radius: 4px;
}

.ct-loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid #ff5e00;
  border-radius: 50%;
  animation: ct-spin 1s linear infinite;
  margin-bottom: 10px;
}

.ct-loading-text {
  color: #666;
  font-size: 14px;
  font-weight: 500;
}

@keyframes ct-spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Error States */
.ct-error-row {
  text-align: center;
  padding: 30px;
}

.ct-error-message {
  color: #d63638;
  font-size: 14px;
  padding: 15px;
  background: #fef7f7;
  border: 1px solid #f5c6cb;
  border-radius: 4px;
  display: inline-block;
}

/* Performance Optimizations */
.ct-table-container {
  contain: layout style paint;
  will-change: scroll-position;
}

.ct-table tbody tr {
  contain: layout style;
}

/* Smooth transitions */
.ct-table tbody {
  transition: opacity 0.2s ease;
}

.ct-loading .ct-table tbody {
  opacity: 0.5;
}
