/* ============================================
   BANK LOG TABLE OPTIMIZATIONS
   ============================================ */

/* Main content improvements */
.main-content {
  padding: clamp(16px, 3vw, 32px);
  max-width: 1600px;
  margin: 0 auto;
}

/* Page Header Improvements */
.page-header {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 2px solid var(--color-grey-800);
}

.page-title {
  font-size: clamp(24px, 4vw, 32px);
  font-weight: 800;
  color: var(--color-text-900);
  letter-spacing: -0.02em;
  margin-bottom: 8px;
  line-height: 1.2;
}

.page-description {
  font-size: clamp(14px, 2vw, 16px);
  color: var(--color-text-700);
  font-weight: 400;
  line-height: 1.5;
}

/* Toggle Container Improvements */
.toggle-container {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  padding: 8px;
  background: var(--color-grey-600);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-grey-900);
  width: fit-content;
  flex-wrap: wrap;
}

.toggle-btn {
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.toggle-container .toggle-btn {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  color: var(--color-text-700);
}

.toggle-container .toggle-btn.active {
  background: var(--color-text-900) !important;
  color: var(--color-neutral-white) !important;
  box-shadow: var(--shadow-sm) !important;
}

.toggle-container .toggle-btn:not(.active):hover {
  background-color: var(--color-grey-700) !important;
  color: var(--color-text-900);
}

/* Toggle Content Sections */
.toggle-content {
  display: none;
  animation: fadeIn 0.3s ease-in-out;
}

.toggle-content.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Dashboard Metrics Improvements */
.dashboard.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

/* Controls section improvements */
.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.search-bar {
  flex: 1;
  max-width: 450px;
  min-width: 250px;
}

.button-group {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}

/* Ensure buttons in controls don't shrink */
.controls .btn-md,
.controls .btn-sm {
  flex-shrink: 0;
  white-space: nowrap;
}

/* Table container improvements */
.table-container {
  overflow-x: auto;
  overflow-y: clip; /* 'clip' instead of 'visible' — Safari coerces mixed overflow to 'auto' which breaks sticky headers */
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-grey-900);
  background: var(--color-neutral-white);
  box-shadow: var(--shadow-sm);
  -webkit-overflow-scrolling: touch;
  margin-bottom: 28px;
  position: relative;
}

/* Transaction table layout optimization */
.transaction-table {
  width: 100%;
  border-collapse: separate; /* Better for sticky headers */
  border-spacing: 0;
  background: var(--color-neutral-white);
  table-layout: auto; /* Fluid layout as requested */
  min-width: 100%;
}

/* Table header sticky positioning - account for floating app header */
/* Override excel-filter.css thead sticky */
.transaction-table thead {
  position: relative !important;
  top: auto !important;
  background: var(--color-grey-700);
  z-index: auto;
}

.transaction-table th {
  position: -webkit-sticky !important;
  position: sticky !important;
  top: 0 !important;
  background: var(--color-grey-700);
  z-index: var(--z-sticky);
}

/* Ensure filter dropdowns appear above sticky header */
.excel-filter-dropdown {
  z-index: var(--z-tooltip) !important;
}

th.has-filter {
  z-index: var(--z-dropdown);
}

th.has-filter.dropdown-open {
  z-index: var(--z-modal);
}

/* Column width optimization for better layout */
.transaction-table th,
.transaction-table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  vertical-align: middle;
  box-sizing: border-box;
}

/* Date column - compact */
.transaction-table th:nth-child(2),
.transaction-table td:nth-child(2) {
  min-width: 110px;
  white-space: nowrap;
}

/* Description column - flexible width */
.transaction-table th:nth-child(12),
.transaction-table td:nth-child(12) {
  min-width: 200px;
  white-space: normal;
  word-break: break-word;
}

/* Amount columns - compact */
.transaction-table th:nth-child(4),
.transaction-table td:nth-child(4),
.transaction-table th:nth-child(5),
.transaction-table td:nth-child(5),
.transaction-table th:nth-child(8),
.transaction-table td:nth-child(8),
.transaction-table th:nth-child(9),
.transaction-table td:nth-child(9),
.transaction-table th:nth-child(10),
.transaction-table td:nth-child(10),
.transaction-table th:nth-child(11),
.transaction-table td:nth-child(11) {
  min-width: 120px;
  text-align: right;
  white-space: nowrap;
}

/* Currency column - very compact */
.transaction-table th:nth-child(7),
.transaction-table td:nth-child(7) {
  min-width: 70px;
  text-align: center;
  white-space: nowrap;
}

/* Exchange Rate column */
.transaction-table th:nth-child(6),
.transaction-table td:nth-child(6) {
  min-width: 100px;
  text-align: right;
  white-space: nowrap;
}

/* Journal ID column */
.transaction-table th:nth-child(1),
.transaction-table td:nth-child(1) {
  min-width: 100px;
  white-space: nowrap;
}

/* Source Log column */
.transaction-table th:nth-child(3),
.transaction-table td:nth-child(3) {
  min-width: 100px;
  white-space: nowrap;
}

/* Ensure proper spacing for filter icons */
.transaction-table th {
  padding: var(--space-3) var(--space-4);
  position: relative;
  vertical-align: middle; /* Ensure vertical centering */
}

/* Reserve space for filter icon and position it absolutely */
.transaction-table th.has-filter {
  padding-right: 32px; /* Space for icon */
}

.transaction-table th .excel-filter-icon {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 0;
}

/* Better header styling */
.transaction-table th {
  background: var(--color-grey-700);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-700);
  border-bottom: 1px solid var(--color-grey-800);
  user-select: none;
  background-clip: padding-box;
  white-space: nowrap; /* Force single line for headers */
  height: 48px; /* Fixed height for consistency */
}

/* Row hover effect */
.transaction-table tbody tr {
  transition: background-color 0.15s ease, transform 0.1s ease;
  cursor: default;
}

.transaction-table tbody tr:hover {
  background: var(--color-grey-700);
  transform: translateX(2px);
}

/* Cell content styling */
.transaction-table td {
  border-bottom: 1px solid var(--color-grey-800);
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-text-800);
  min-height: 48px;
}

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

/* Number alignment for amounts */
.transaction-table td:nth-child(3),
.transaction-table td:nth-child(5) {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  font-weight: 600;
}

/* Currency badge styling */
.transaction-table td:nth-child(4) {
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Source column badge */
.transaction-table td:nth-child(10) {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.8;
}

/* Suspicious score visual indicators */
.transaction-table td:nth-child(9) {
  font-weight: 600;
}

.transaction-table td:nth-child(9) .score-high {
  color: var(--color-danger-500);
}

.transaction-table td:nth-child(9) .score-medium {
  color: var(--color-warning-500);
}

.transaction-table td:nth-child(9) .score-low {
  color: var(--color-success-500);
}

/* Positive/negative amount styling */
.transaction-table .amount-positive {
  color: var(--color-success-500);
}

.transaction-table .amount-negative {
  color: var(--color-danger-500);
}

.transaction-table .amount-neutral {
  color: var(--color-text-800);
}

/* Responsive adjustments for tablets */
@media (max-width: 1024px) {
  .transaction-table th,
  .transaction-table td {
    padding: 12px 14px;
  }
  
  .transaction-table th {
    font-size: 10px;
  }
  
  .transaction-table td {
    font-size: 12px;
  }
  
  /* Adjust column widths for tablets */
  .transaction-table th:nth-child(2),
  .transaction-table td:nth-child(2) {
    min-width: 150px;
  }
}

/* Responsive adjustments for mobile */
@media (max-width: 768px) {
  .table-container {
    border-radius: var(--radius-sm);
    margin-left: -12px;
    margin-right: -12px;
    border-left: none;
    border-right: none;
    /* Ensure smooth scrolling on mobile */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  
  .transaction-table th,
  .transaction-table td {
    padding: 10px 12px;
  }
  
  .transaction-table th {
    font-size: 10px; /* Slightly larger for readability */
    letter-spacing: 0.05em;
    padding-right: 24px; /* Adjusted for icon */
    top: 0 !important; /* Offset removed as requested */
    height: 44px; /* Taller touch target */
  }
  
  .transaction-table td {
    font-size: 12px;
  }
  
  /* Compact columns on mobile */
  .transaction-table th:nth-child(1),
  .transaction-table td:nth-child(1) {
    min-width: 90px;
    white-space: nowrap;
  }
  
  .transaction-table th:nth-child(2),
  .transaction-table td:nth-child(2) {
    min-width: 120px;
    white-space: normal;
  }
  
  .transaction-table th:nth-child(3),
  .transaction-table td:nth-child(3),
  .transaction-table th:nth-child(5),
  .transaction-table td:nth-child(5) {
    min-width: 100px;
    white-space: nowrap;
  }
  
  .transaction-table th:nth-child(4),
  .transaction-table td:nth-child(4) {
    min-width: 60px;
    white-space: nowrap;
  }
  
  .transaction-table th:nth-child(6),
  .transaction-table td:nth-child(6),
  .transaction-table th:nth-child(7),
  .transaction-table td:nth-child(7) {
    min-width: 110px;
    white-space: nowrap;
  }
  
  .transaction-table th:nth-child(8),
  .transaction-table td:nth-child(8) {
    min-width: 120px;
    white-space: nowrap;
  }
  
  .transaction-table th:nth-child(9),
  .transaction-table td:nth-child(9) {
    min-width: 80px;
    white-space: nowrap;
  }
  
  .transaction-table th:nth-child(10),
  .transaction-table td:nth-child(10) {
    min-width: 70px;
    white-space: nowrap;
  }
}

/* Print optimization */
@media print {
  .table-container {
    border: 1px solid #000;
    box-shadow: none;
    overflow: visible;
  }
  
  .transaction-table {
    page-break-inside: avoid;
  }
  
  .transaction-table th {
    background: #f0f0f0 !important;
    color: #000 !important;
  }
  
  .transaction-table tbody tr:hover {
    transform: none;
    background: transparent;
  }
}

/* Loading state */
.transaction-table.loading {
  opacity: 0.6;
  pointer-events: none;
}

/* Empty state — only shown when JS has NOT yet touched the tbody.
   The skeleton renderer and TransactionTable.render() always insert at least
   one <tr>, so :empty only fires if JS hasn't run at all (e.g. blocked). */
.transaction-table tbody:empty::after {
  content: 'Loading transactions…';
  display: block;
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text-600);
  font-size: 14px;
}

/* Scrollbar styling for table container */
.table-container::-webkit-scrollbar {
  height: 10px;
}

.table-container::-webkit-scrollbar-track {
  background: var(--color-grey-600);
  border-radius: var(--radius-sm);
}

.table-container::-webkit-scrollbar-thumb {
  background: var(--color-grey-900);
  border-radius: var(--radius-sm);
  transition: background 0.2s ease;
}

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

/* Firefox scrollbar styling */
.table-container {
  scrollbar-width: thin;
  scrollbar-color: var(--color-grey-900) var(--color-grey-600);
}

/* ============================================
   PAGINATION IMPROVEMENTS
   ============================================ */

.pagination {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 24px;
  padding: 20px;
  background: var(--color-grey-600);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-grey-900);
}

.pagination-info {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-900);
  text-align: center;
  letter-spacing: -0.01em;
}

.pagination-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

/* Pagination responsive adjustments */
@media (max-width: 768px) {
  .pagination {
    padding: 16px;
    gap: 12px;
    margin-top: 16px;
  }
  
  .pagination-info {
    font-size: 13px;
  }
  
  .pagination-controls {
    gap: 8px;
  }
}

@media (max-width: 480px) {
  .pagination {
    padding: 14px;
  }
  
  .pagination-info {
    font-size: 12px;
  }
}

/* ============================================
   MOBILE-SPECIFIC IMPROVEMENTS
   ============================================ */

/* Better touch targets for mobile */
@media (hover: none) and (pointer: coarse) {
  .transaction-table th {
    min-height: 44px;
  }
  
  /* Disable transform effects on touch devices */
  .transaction-table tbody tr:hover {
    transform: none;
  }
  
  /* Make sortable headers more obvious on touch */
  .transaction-table th[data-sort]::after {
    content: '⇅';
    margin-left: 4px;
    opacity: 0.4;
    font-size: 10px;
  }
}

/* Improve table readability on small screens */
@media (max-width: 480px) {
  /* Stack controls vertically on very small screens */
  .controls {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  
  .search-bar {
    max-width: 100%;
    width: 100%;
  }
  
  .button-group {
    flex-direction: column;
    width: 100%;
  }
  
  .button-group .btn-md,
  .button-group .btn-sm {
    width: 100%;
    justify-content: center;
  }
  
  /* Make toggle container full width on very small screens */
  .toggle-container {
    width: 100%;
    justify-content: center;
  }
  
  /* Adjust page header for very small screens */
  .page-header {
    margin-bottom: 20px;
    padding-bottom: 16px;
  }
  
  .page-title {
    font-size: 20px;
  }
  
  .page-description {
    font-size: 13px;
  }
  
  /* Compact dashboard metrics */
  .dashboard.metrics {
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 16px;
  }
}

/* ============================================
   MODAL IMPROVEMENTS FOR BANK UPLOAD
   ============================================ */

#upload-modal .modal-content {
  max-width: 480px;
  width: 90%;
  padding: 0;
  background: var(--color-neutral-white);
}

#upload-modal .modal-body {
  padding: 0;
}

@media (max-width: 768px) {
  #upload-modal .modal-content {
    width: 95%;
    max-width: none;
  }
}

/* Data Health Banner */
.data-health-banner {
  margin-bottom: 16px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.health-loading {
  padding: 12px 16px;
  background: var(--color-grey-600);
  color: var(--color-text-600);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.health-loading::before {
  content: '';
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-grey-800);
  border-top-color: var(--color-information-500);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

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

.health-status {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.health-status.healthy {
  background: var(--color-success-100);
  border: 1px solid var(--color-success-300);
  color: var(--color-success-700);
}

.health-status.needs-fix {
  background: var(--color-warning-100);
  border: 1px solid var(--color-warning-300);
  color: var(--color-warning-700);
}

.health-status.error {
  background: var(--color-danger-100);
  border: 1px solid var(--color-danger-300);
  color: var(--color-danger-700);
}

.health-icon {
  font-size: 18px;
  font-weight: bold;
  flex-shrink: 0;
}

.health-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.health-text {
  font-weight: 500;
}

.health-issues {
  font-size: 12px;
  opacity: 0.8;
}

.health-close {
  margin-left: auto;
  padding: 4px 8px;
  font-size: 18px;
  line-height: 1;
  opacity: 0.6;
}

.health-close:hover {
  opacity: 1;
}

/* ============================================
   ATTACHMENT BUTTON STYLES
   ============================================ */

/* Attachment cell */
.attachment-cell {
  padding: 4px 8px !important;
  text-align: center;
}

/* Attachment button base styles */
.btn-attachment {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--color-grey-900);
  border-radius: var(--radius-sm);
  background: var(--color-grey-600);
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--color-text-600);
}

.btn-attachment:hover {
  background: var(--color-grey-700);
  border-color: var(--color-grey-900);
  color: var(--color-text-800);
}

.btn-attachment svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}

/* Upload button - dashed border */
.btn-upload-attachment {
  border-style: dashed;
  color: var(--color-text-500);
}

.btn-upload-attachment:hover {
  border-color: var(--color-information-500);
  color: var(--color-information-500);
  background: var(--color-information-100);
}

/* View button - solid with accent */
.btn-view-attachment {
  background: var(--color-information-100);
  border-color: var(--color-information-500);
  color: var(--color-information-500);
}

.btn-view-attachment:hover {
  background: var(--color-information-500);
  color: var(--color-neutral-white);
}

/* Attachment modal styles */
.attachment-modal {
  max-width: 500px;
}

.attachment-modal .modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-grey-800);
}

.attachment-modal .modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.attachment-modal .modal-body {
  padding: 20px;
}

.attachment-modal .modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 20px;
  border-top: 1px solid var(--color-grey-800);
  background: var(--color-grey-500);
}

/* ============================================
   STATUS BADGE STYLES (Bank-Ledger Connection)
   ============================================ */

.status-cell {
  padding: 4px 6px !important;
  text-align: center;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-md);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  cursor: default;
}

.status-badge svg {
  flex-shrink: 0;
}

.status-linked {
  background: rgba(16, 185, 129, 0.12);
  color: var(--color-success-700);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-truth {
  background: rgba(59, 130, 246, 0.12);
  color: var(--color-information-700);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.status-unlinked {
  background: transparent;
  color: var(--color-text-500);
  border: 1px solid transparent;
  opacity: 0.5;
}

.status-unlinked svg {
  opacity: 0.4;
}
