/**
 * ISO 14046 Water Footprint - Table Styles (HydroBlue ISO Theme)
 * Consistent table styling across the application
 */

/* ============================================
   CSS VARIABLES - HydroBlue ISO
   ============================================ */

:root {
  /* HydroBlue ISO Color Palette */
  --primary-blue: #0b61ff;
  --primary-blue-dark: #084fd8;
  --dark-navy: #072035;
  --dark-text: #07122a;
  --light-blue-bg: #f4f7fb;
  --light-blue-border: #e6eef9;
  --light-blue-subtle: #eef2ff;
  --white: #ffffff;
  --off-white: #fbfdff;
  --slate-gray: #475569;
  --light-gray: #64748b;
  --border-gray: #f1f5f9;
  --success-green: #065f46;
  --success-bg: #ecffef;
  --warning-orange: #f97316;
  --warning-bg: #fffbeb;
  --error-red: #ef4444;
  --error-bg: #fef2f2;
  
  /* Typography */
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  --font-mono: 'SF Mono', 'Roboto Mono', Monaco, Consolas, monospace;
  --font-size-xs: 11px;
  --font-size-sm: 12px;
  --font-size-base: 13px;
  --font-size-md: 14px;
  --font-size-lg: 16px;
  
  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 12px;
  --spacing-lg: 16px;
  --spacing-xl: 20px;
  
  /* Borders */
  --border-radius-sm: 6px;
  --border-radius-md: 8px;
  --border-radius-lg: 10px;
}

/* ============================================
   TABLE BASE STYLES
   ============================================ */

.table-container {
  margin: var(--spacing-xl) 0;
  overflow-x: auto;
  border-radius: var(--border-radius-md);
  border: 1px solid var(--light-blue-border);
  background: var(--white);
  box-shadow: 0 4px 12px rgba(12, 22, 42, 0.04);
  font-family: var(--font-main);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--font-size-base);
  color: var(--dark-text);
}

/* ============================================
   TABLE HEADER STYLES
   ============================================ */

thead {
  background: var(--off-white);
  border-bottom: 2px solid var(--light-blue-border);
}

thead th {
  padding: var(--spacing-lg) var(--spacing-md);
  font-weight: 600;
  text-align: left;
  color: var(--dark-navy);
  text-transform: uppercase;
  font-size: var(--font-size-xs);
  letter-spacing: 0.5px;
  white-space: nowrap;
  position: relative;
}

thead th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background 0.2s ease;
}

thead th.sortable:hover {
  background: var(--light-blue-subtle);
}

thead th.sortable::after {
  content: '↕';
  margin-left: var(--spacing-sm);
  opacity: 0.3;
  font-size: 10px;
  font-weight: 700;
}

thead th.sortable.asc::after {
  content: '↑';
  opacity: 1;
  color: var(--primary-blue);
}

thead th.sortable.desc::after {
  content: '↓';
  opacity: 1;
  color: var(--primary-blue);
}

/* ============================================
   TABLE BODY STYLES
   ============================================ */

tbody tr {
  border-bottom: 1px solid var(--light-blue-border);
  transition: background-color 0.2s ease;
}

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

tbody tr:hover {
  background: var(--light-blue-subtle);
}

tbody tr.selected {
  background: var(--light-blue-subtle);
  border-left: 3px solid var(--primary-blue);
}

tbody td {
  padding: var(--spacing-lg) var(--spacing-md);
  vertical-align: middle;
  border-bottom: 1px solid var(--light-blue-border);
  color: var(--dark-text);
  font-size: var(--font-size-base);
}

/* ============================================
   TABLE CELL CONTENT STYLES
   ============================================ */

.table-cell {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.cell-icon {
  width: 16px;
  height: 16px;
  color: var(--light-gray);
  flex-shrink: 0;
}

.cell-text {
  flex: 1;
  min-width: 0; /* For text truncation */
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell-actions {
  display: flex;
  gap: var(--spacing-xs);
  opacity: 0;
  transition: opacity 0.2s ease;
}

tr:hover .cell-actions {
  opacity: 1;
}

.cell-action-btn {
  background: var(--white);
  border: 1px solid var(--light-blue-border);
  border-radius: var(--border-radius-sm);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--slate-gray);
  font-size: 12px;
}

.cell-action-btn:hover {
  background: var(--light-blue-subtle);
  border-color: var(--primary-blue);
  color: var(--primary-blue);
}

/* ============================================
   TABLE DATA TYPE STYLES
   ============================================ */

/* Text cells */
td.text-cell {
  font-weight: 500;
  color: var(--dark-text);
}

td.text-cell.truncate {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Number cells */
td.number-cell {
  font-family: var(--font-mono);
  font-weight: 600;
  text-align: right;
  font-size: var(--font-size-base);
}

td.number-cell.positive {
  color: var(--success-green);
}

td.number-cell.negative {
  color: var(--error-red);
}

td.number-cell.neutral {
  color: var(--slate-gray);
}

/* Status cells */
.status-cell {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.status-draft {
  background: var(--warning-bg);
  color: var(--warning-orange);
}

.status-in-progress {
  background: #f0f9ff;
  color: #0369a1;
}

.status-complete {
  background: var(--success-bg);
  color: var(--success-green);
}

.status-approved {
  background: #ecffef;
  color: #065f46;
}

.status-rejected {
  background: var(--error-bg);
  color: var(--error-red);
}

/* Badge cells */
.badge-cell {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  background: var(--off-white);
  color: var(--slate-gray);
  border: 1px solid var(--light-blue-border);
}

.badge-cell.primary {
  background: var(--light-blue-subtle);
  color: var(--primary-blue);
  border-color: rgba(11, 97, 255, 0.2);
}

.badge-cell.success {
  background: var(--success-bg);
  color: var(--success-green);
  border-color: rgba(6, 95, 70, 0.2);
}

.badge-cell.warning {
  background: var(--warning-bg);
  color: var(--warning-orange);
  border-color: rgba(249, 115, 22, 0.2);
}

.badge-cell.error {
  background: var(--error-bg);
  color: var(--error-red);
  border-color: rgba(239, 68, 68, 0.2);
}

/* Progress cells */
.progress-cell {
  min-width: 100px;
}

.progress-bar {
  height: 6px;
  background: var(--light-blue-border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--primary-blue), #3b82f6);
  transition: width 0.3s ease;
}

.progress-fill.success {
  background: linear-gradient(90deg, #10b981, #34d399);
}

.progress-fill.warning {
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
}

.progress-fill.error {
  background: linear-gradient(90deg, #ef4444, #f87171);
}

.progress-text {
  font-size: var(--font-size-xs);
  color: var(--light-gray);
  margin-top: var(--spacing-xs);
  text-align: center;
  font-weight: 500;
}

/* ============================================
   TABLE VARIATIONS
   ============================================ */

/* Compact table */
.table-compact thead th,
.table-compact tbody td {
  padding: var(--spacing-md) var(--spacing-sm);
  font-size: var(--font-size-sm);
}

/* Bordered table */
.table-bordered {
  border: 1px solid var(--light-blue-border);
}

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

/* Striped table */
.table-striped tbody tr:nth-child(even) {
  background: var(--off-white);
}

.table-striped tbody tr:hover {
  background: var(--light-blue-subtle);
}

/* Hover table */
.table-hover tbody tr {
  cursor: pointer;
}

.table-hover tbody tr:hover {
  background: var(--light-blue-subtle);
}

/* ============================================
   TABLE ACTIONS & CONTROLS
   ============================================ */

.table-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-lg);
  background: var(--off-white);
  border-top: 1px solid var(--light-blue-border);
}

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

.table-pagination button {
  padding: 6px 10px;
  border: 1px solid var(--light-blue-border);
  background: var(--white);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-main);
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--dark-navy);
  min-width: 32px;
  min-height: 32px;
}

.table-pagination button:hover:not(:disabled) {
  background: var(--light-blue-subtle);
  border-color: var(--primary-blue);
}

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

.table-pagination button.active {
  background: var(--primary-blue);
  border-color: var(--primary-blue);
  color: white;
}

.table-pagination .page-info {
  font-size: var(--font-size-sm);
  color: var(--slate-gray);
  font-weight: 500;
  margin: 0 var(--spacing-sm);
}

/* ============================================
   TABLE FILTERS & SEARCH
   ============================================ */

.table-filters {
  padding: var(--spacing-lg);
  background: var(--off-white);
  border-bottom: 1px solid var(--light-blue-border);
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-md);
  align-items: center;
}

.table-search {
  position: relative;
  max-width: 300px;
  flex: 1;
  min-width: 200px;
}

.table-search input {
  width: 100%;
  padding: 8px 32px 8px 12px;
  border: 1px solid var(--light-blue-border);
  border-radius: var(--border-radius-md);
  background: var(--white);
  font-size: var(--font-size-base);
  font-family: var(--font-main);
  color: var(--dark-text);
  transition: all 0.2s ease;
}

.table-search input:focus {
  outline: none;
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 3px rgba(11, 97, 255, 0.1);
}

.table-search::after {
  content: '🔍';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.5;
  pointer-events: none;
  font-size: 14px;
}

/* ============================================
   EMPTY TABLE STATES
   ============================================ */

.table-empty {
  padding: var(--spacing-3xl) var(--spacing-lg);
  text-align: center;
  color: var(--light-gray);
  background: var(--white);
}

.table-empty-icon {
  font-size: 32px;
  margin-bottom: var(--spacing-lg);
  opacity: 0.5;
}

.table-empty-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  margin-bottom: var(--spacing-sm);
  color: var(--dark-navy);
}

.table-empty-description {
  font-size: var(--font-size-base);
  max-width: 400px;
  margin: 0 auto var(--spacing-xl);
  color: var(--slate-gray);
  line-height: 1.5;
}

/* ============================================
   TABLE RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 768px) {
  .table-container {
    border-radius: var(--border-radius-sm);
    margin: var(--spacing-lg) 0;
    border-left: none;
    border-right: none;
  }
  
  table {
    font-size: var(--font-size-sm);
  }
  
  thead th,
  tbody td {
    padding: var(--spacing-md) var(--spacing-sm);
  }
  
  .table-actions {
    flex-direction: column;
    gap: var(--spacing-md);
    align-items: stretch;
  }
  
  .cell-actions {
    opacity: 1; /* Always show actions on mobile */
  }
  
  .table-filters {
    flex-direction: column;
    align-items: stretch;
  }
  
  .table-search {
    max-width: 100%;
    min-width: auto;
  }
}

@media (max-width: 480px) {
  .table-container {
    margin: var(--spacing-md) -12px;
    border-radius: 0;
  }
  
  .status-cell,
  .badge-cell {
    font-size: 10px;
    padding: 2px 8px;
  }
  
  .progress-cell {
    min-width: 80px;
  }
  
  .table-pagination {
    flex-wrap: wrap;
    justify-content: center;
  }
}

/* ============================================
   TABLE EDITING STYLES
   ============================================ */

td.editing {
  background: var(--light-blue-subtle);
  position: relative;
}

td.editing::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border: 2px solid var(--primary-blue);
  border-radius: var(--border-radius-sm);
  pointer-events: none;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* ============================================
   TABLE VALIDATION STATES
   ============================================ */

td.error {
  background: var(--error-bg);
  border-color: var(--error-red);
}

td.warning {
  background: var(--warning-bg);
  border-color: var(--warning-orange);
}

td.success {
  background: var(--success-bg);
  border-color: var(--success-green);
}

/* ============================================
   TABLE EXPORT & PRINT STYLES
   ============================================ */

@media print {
  .table-container {
    border: none;
    overflow: visible;
    box-shadow: none;
    margin: 0;
  }
  
  .table-actions,
  .table-filters,
  .cell-actions {
    display: none !important;
  }
  
  table {
    break-inside: avoid;
    font-size: 11pt;
  }
  
  thead {
    display: table-header-group;
    background: #f8f9fa !important;
    -webkit-print-color-adjust: exact;
  }
  
  tbody tr {
    break-inside: avoid;
  }
  
  .status-cell,
  .badge-cell {
    -webkit-print-color-adjust: exact;
  }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

/* Screen reader only text */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus styles for keyboard navigation */
table:focus-within {
  outline: 2px solid var(--primary-blue);
  outline-offset: 2px;
}

th:focus,
td:focus {
  outline: 2px solid var(--primary-blue);
  outline-offset: -2px;
  position: relative;
  z-index: 1;
}

/* ============================================
   TABLE SORTING INDICATORS
   ============================================ */

.sort-indicator {
  display: inline-flex;
  flex-direction: column;
  margin-left: var(--spacing-xs);
  vertical-align: middle;
}

.sort-arrow {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  margin: 1px 0;
}

.sort-arrow.up {
  border-bottom: 4px solid var(--light-gray);
}

.sort-arrow.down {
  border-top: 4px solid var(--light-gray);
}

.sort-arrow.active.up {
  border-bottom-color: var(--primary-blue);
}

.sort-arrow.active.down {
  border-top-color: var(--primary-blue);
}

/* ============================================
   TABLE LOADING STATE
   ============================================ */

.table-loading {
  position: relative;
}

.table-loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.table-loading::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24px;
  height: 24px;
  border: 3px solid var(--light-blue-border);
  border-top-color: var(--primary-blue);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  z-index: 11;
}

@keyframes spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}