/* Table Components - ROA2WEB */

/* Base Table Styles */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  color: var(--color-text);
  background: var(--color-bg);
  border-radius: var(--card-radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.table th {
  background: var(--color-bg-muted);
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  border-bottom: 2px solid var(--color-border);
  font-weight: var(--font-semibold);
  color: var(--color-text);
  font-size: var(--text-sm);
  position: sticky;
  top: 0;
  z-index: 1;
}

.table td {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: middle;
}

.table tbody tr:hover {
  background: var(--color-bg-secondary);
}

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

/* Table Variants */
.table-striped tbody tr:nth-child(even) {
  background: var(--color-bg-secondary);
}

.table-striped tbody tr:nth-child(even):hover {
  background: var(--color-bg-muted);
}

.table-bordered {
  border: 1px solid var(--color-border);
}

.table-bordered th,
.table-bordered td {
  border: 1px solid var(--color-border);
}

.table-borderless th,
.table-borderless td {
  border: none;
}

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

.table-lg th,
.table-lg td {
  padding: var(--space-md) var(--space-lg);
}

/* Responsive Table */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-responsive .table {
  min-width: 600px;
}

/* Sortable Headers */
.table th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: var(--space-xl);
}

.table th.sortable:hover {
  background: var(--color-border);
}

.table th.sortable::after {
  content: "↕";
  position: absolute;
  right: var(--space-sm);
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.5;
  font-size: var(--text-xs);
}

.table th.sortable.sorted-asc::after {
  content: "↑";
  opacity: 1;
  color: var(--color-primary);
}

.table th.sortable.sorted-desc::after {
  content: "↓";
  opacity: 1;
  color: var(--color-primary);
}

/* Table Status Colors */
.table .cell-success,
.table .text-success {
  color: var(--color-success);
  font-weight: var(--font-medium);
}

.table .cell-warning,
.table .text-warning {
  color: var(--color-warning);
  font-weight: var(--font-medium);
}

.table .cell-error,
.table .text-error {
  color: var(--color-error);
  font-weight: var(--font-medium);
}

.table .cell-info,
.table .text-info {
  color: var(--color-info);
  font-weight: var(--font-medium);
}

.table .cell-muted,
.table .text-muted {
  color: var(--color-text-muted);
}

/* Table Row States */
.table .row-selected {
  background: rgba(37, 99, 235, 0.1);
  border-color: var(--color-primary);
}

.table .row-active {
  background: rgba(16, 185, 129, 0.1);
}

.table .row-warning {
  background: rgba(245, 158, 11, 0.1);
}

.table .row-error {
  background: rgba(239, 68, 68, 0.1);
}

/* Editable Cells */
.table .cell-editable {
  cursor: pointer;
  position: relative;
}

.table .cell-editable:hover {
  background: rgba(37, 99, 235, 0.05);
}

.table .cell-input {
  width: 100%;
  padding: var(--space-xs);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-sm);
  font-size: inherit;
  font-family: inherit;
  color: inherit;
  background: var(--color-bg);
}

.table .cell-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

/* Action Buttons in Tables */
.table .table-actions {
  display: flex;
  gap: var(--space-xs);
  justify-content: flex-end;
}

.table .table-action-btn {
  padding: var(--space-xs);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

.table .table-action-btn:hover {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
}

/* Table Pagination */
.table-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md);
  background: var(--color-bg-secondary);
  border-top: 1px solid var(--color-border);
}

.pagination-info {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.pagination-btn {
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  transition: all var(--transition-fast);
}

.pagination-btn:hover:not(:disabled) {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
}

.pagination-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination-current {
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--text-sm);
  color: var(--color-text);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-radius: var(--radius-sm);
}

/* Table Search and Filters */
.table-filters {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md);
  background: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border);
  gap: var(--space-md);
  flex-wrap: wrap;
}

.table-search {
  flex: 1;
  min-width: 200px;
}

.table-filter-group {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.table-filter-label {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--color-text-secondary);
  white-space: nowrap;
}

/* Data Table Stats */
.table-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-md);
  padding: var(--space-md);
  background: var(--color-bg-muted);
  border-bottom: 1px solid var(--color-border);
}

.table-stat {
  text-align: center;
}

.table-stat-value {
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  color: var(--color-text);
  display: block;
  margin-bottom: var(--space-xs);
}

.table-stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  font-weight: var(--font-medium);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Empty State */
.table-empty {
  text-align: center;
  padding: var(--space-3xl) var(--space-xl);
  color: var(--color-text-secondary);
}

.table-empty-icon {
  font-size: var(--text-4xl);
  margin-bottom: var(--space-lg);
  opacity: 0.5;
}

.table-empty-message {
  font-size: var(--text-lg);
  margin-bottom: var(--space-sm);
}

.table-empty-description {
  font-size: var(--text-sm);
  opacity: 0.8;
}

/* Trends Section Styling */
.trends-container {
  padding: var(--space-xl);
  min-height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.trend-placeholder {
  text-align: center;
  padding: var(--space-xl);
  background: var(--color-bg-secondary);
  border-radius: var(--radius-lg);
  color: var(--color-text-secondary);
  border: 2px dashed var(--color-border);
  max-width: 500px;
}

.placeholder-icon {
  font-size: 48px;
  color: var(--color-primary);
  margin-bottom: var(--space-lg);
  opacity: 0.7;
}

.trend-placeholder h3 {
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: var(--color-text);
  margin: 0 0 var(--space-md) 0;
}

.trend-placeholder p {
  font-size: var(--text-base);
  margin: 0 0 var(--space-md) 0;
  line-height: 1.6;
}

.trend-placeholder ul {
  text-align: left;
  display: inline-block;
  margin: 0;
  padding-left: var(--space-lg);
}

.trend-placeholder li {
  margin-bottom: var(--space-xs);
  line-height: 1.5;
  color: var(--color-text-secondary);
}

/* Chart Container for future charts */
.chart-container {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin: var(--space-md) 0;
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Loading States */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-3xl);
  color: var(--color-text-secondary);
  text-align: center;
  min-height: 200px;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: var(--space-lg);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Enhanced Responsive Table Container */
.table-container {
  overflow: auto;
  max-height: 500px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-light);
}

.table-container::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.table-container::-webkit-scrollbar-track {
  background: var(--color-bg-secondary);
}

.table-container::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}

.table-container::-webkit-scrollbar-thumb:hover {
  background: var(--color-border-dark);
}

/* Mobile Table Styles */
@media (max-width: 768px) {
  .table-mobile-stack {
    display: block;
  }

  .table-mobile-stack thead {
    display: none;
  }

  .table-mobile-stack tbody,
  .table-mobile-stack tr,
  .table-mobile-stack td {
    display: block;
    width: 100%;
  }

  .table-mobile-stack tr {
    border: 1px solid var(--color-border);
    border-radius: var(--card-radius);
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    background: var(--color-bg);
    box-shadow: var(--shadow-sm);
  }

  .table-mobile-stack td {
    border: none;
    position: relative;
    padding: var(--space-sm) 0;
    text-align: left;
  }

  .table-mobile-stack td::before {
    content: attr(data-label) ": ";
    font-weight: var(--font-semibold);
    color: var(--color-text-secondary);
    display: inline-block;
    width: 40%;
    margin-right: var(--space-sm);
  }

  .table-filters {
    flex-direction: column;
    align-items: stretch;
  }

  .table-filter-group {
    justify-content: space-between;
  }

  .table-pagination {
    flex-direction: column;
    gap: var(--space-md);
    text-align: center;
  }

  .table-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .table-stats {
    grid-template-columns: 1fr;
  }

  .table-mobile-stack td::before {
    width: 100%;
    display: block;
    margin-bottom: var(--space-xs);
    margin-right: 0;
  }

  /* Dashboard-specific mobile styles */
  .dashboard-table {
    font-size: var(--text-xs);
  }

  .dashboard-table th,
  .dashboard-table td {
    padding: var(--space-sm) var(--space-md);
  }

  .name-cell {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .trends-container {
    padding: var(--space-lg);
  }

  .placeholder-icon {
    font-size: 36px;
  }

  .trend-placeholder h3 {
    font-size: var(--text-lg);
  }
}

/* Professional Dashboard Table Styles */
.dashboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  color: var(--color-text);
  background: var(--color-bg);
  border-radius: var(--card-radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-light);
}

.dashboard-table th {
  background: var(--color-bg-muted);
  padding: var(--space-md) var(--space-lg);
  text-align: left;
  border-bottom: 2px solid var(--color-border);
  font-weight: var(--font-semibold);
  color: var(--color-text);
  font-size: var(--text-sm);
  position: sticky;
  top: 0;
  z-index: 10;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  font-size: var(--text-xs);
}

.dashboard-table th.text-right {
  text-align: right;
}

.dashboard-table td {
  padding: var(--space-sm) var(--space-lg);
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: middle;
  transition: background-color var(--transition-fast);
}

.dashboard-table td.text-right {
  text-align: right;
}

.dashboard-table tbody tr:hover {
  background: var(--color-bg-secondary);
}

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

/* Enhanced Table Cell Types */
.dashboard-table .category-cell {
  font-weight: var(--font-medium);
  color: var(--color-text);
}

.dashboard-table .name-cell {
  font-weight: var(--font-medium);
  color: var(--color-text);
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-table .amount-cell {
  font-family: var(--font-mono);
  font-weight: var(--font-medium);
  text-align: right;
  white-space: nowrap;
}

.dashboard-table .status-cell {
  text-align: center;
}

/* Enhanced Status Badge */
.status-badge {
  display: inline-block;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid transparent;
}

.status-badge.activ {
  background: var(--color-success-bg);
  color: var(--color-success);
  border-color: var(--color-success);
}

.status-badge.restant {
  background: var(--color-warning-bg);
  color: var(--color-warning);
  border-color: var(--color-warning);
}

.status-badge.inactiv {
  background: var(--color-error-bg);
  color: var(--color-error);
  border-color: var(--color-error);
}

/* Balance Color Classes */
.positive {
  color: var(--color-success) !important;
  font-weight: var(--font-semibold);
}

.negative {
  color: var(--color-error) !important;
  font-weight: var(--font-semibold);
}

.neutral {
  color: var(--color-text) !important;
}

/* Grand Total Row Enhancement */
.grand-total-row {
  background: var(--color-bg-muted);
  font-weight: var(--font-semibold);
  border-top: 2px solid var(--color-border);
  border-bottom: 2px solid var(--color-border);
}

.grand-total-row td {
  padding: var(--space-md) var(--space-lg);
  color: var(--color-text);
  font-size: var(--text-sm);
}

.grand-total-row:hover {
  background: var(--color-bg-muted) !important;
}

/* Section Styling */
.dashboard-section {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--card-radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-xl);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-lg) var(--space-xl);
  background: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
  gap: var(--space-md);
}

.section-title {
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: var(--color-text);
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.section-controls {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-wrap: wrap;
}

/* Control Groups */
.control-group {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.control-group label {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.detail-select,
.detail-input,
.trend-select {
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  min-width: 120px;
  background: var(--color-bg);
  color: var(--color-text);
  transition:
    border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.detail-select:focus,
.detail-input:focus,
.trend-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(var(--color-primary-rgb), 0.2);
}

/* Enhanced Pagination */
.table-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) var(--space-xl);
  background: var(--color-bg-secondary);
  border-top: 1px solid var(--color-border);
  flex-wrap: wrap;
  gap: var(--space-md);
}

.pagination-info {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  font-weight: var(--font-medium);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.page-info {
  font-size: var(--text-sm);
  color: var(--color-text);
  font-weight: var(--font-medium);
  padding: var(--space-xs) var(--space-sm);
  background: var(--color-bg-muted);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}

/* Print Styles */
@media print {
  .table {
    font-size: 12px;
  }

  .table-filters,
  .table-pagination,
  .table-actions {
    display: none;
  }

  .table th,
  .table td {
    padding: 4px 8px;
  }

  .dashboard-table {
    font-size: 10px;
    box-shadow: none;
    border: 1px solid #000 !important;
  }

  .dashboard-table th {
    background: #f5f5f5 !important;
    color: #000 !important;
    border: 1px solid #000 !important;
    padding: 4px 6px;
  }

  .dashboard-table td {
    border: 1px solid #000 !important;
    padding: 4px 6px;
    background: white !important;
    color: #000 !important;
  }

  .grand-total-row td {
    background: #f0f0f0 !important;
    font-weight: bold;
    border: 2px solid #000 !important;
  }

  .section-header {
    display: none;
  }

  .dashboard-section {
    page-break-inside: avoid;
    margin-bottom: 20px;
    box-shadow: none;
  }
}
