/* Excel-style column filter styles */

/* Filter icon in headers */
.excel-filter-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.4;
  transition: opacity 0.2s, color 0.2s, background 0.2s;
  margin-left: 8px;
  vertical-align: middle;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-sm);
}

.excel-filter-icon:hover {
  background: var(--color-grey-700);
}

.excel-filter-icon svg {
  width: 12px;
  height: 12px;
  display: block;
}

/* Active filter icon */
.excel-filter-icon.active {
  opacity: 1 !important;
  color: var(--color-information-600) !important;
  background: var(--color-information-100) !important;
}

/* Header cells with filters */
th.has-filter {
  position: relative;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th.has-filter:hover .excel-filter-icon {
  opacity: 0.8;
}

/* Filter dropdown */
.excel-filter-dropdown {
  position: fixed !important;
  background: var(--color-neutral-white);
  border: 1px solid var(--color-grey-900);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-tooltip) !important;
  min-width: 220px;
  max-width: 320px;
  max-height: 420px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: filterDropdownIn 0.15s ease-out;
}

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

/* Search box in dropdown */
.excel-filter-dropdown input[type="text"] {
  padding: 10px 14px;
  border: none;
  border-bottom: 1px solid var(--color-grey-800);
  font-size: 13px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
  background: var(--color-grey-600);
}

.excel-filter-dropdown input[type="text"]::placeholder {
  color: var(--color-text-600);
}

.excel-filter-dropdown input[type="text"]:focus {
  border-bottom-color: var(--color-information-600);
  background: var(--color-neutral-white);
}

/* Select all section */
.excel-filter-dropdown .select-all-container {
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-grey-800);
  background: var(--color-neutral-white);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
}

.excel-filter-dropdown .select-all-container label {
  cursor: pointer;
  flex: 1;
  user-select: none;
  color: var(--color-text-900);
}

/* Values list */
.filter-values-list {
  overflow-y: auto;
  max-height: 260px;
  padding: 6px 0;
}

.filter-values-list::-webkit-scrollbar {
  width: 6px;
}

.filter-values-list::-webkit-scrollbar-track {
  background: transparent;
}

.filter-values-list::-webkit-scrollbar-thumb {
  background: var(--color-grey-800);
  border-radius: 3px;
}

.filter-values-list::-webkit-scrollbar-thumb:hover {
  background: var(--color-grey-900);
}

/* Filter items */
.filter-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}

.filter-item:hover {
  background: var(--color-grey-600);
}

.filter-item input[type="checkbox"] {
  cursor: pointer;
  margin: 0;
  width: 16px;
  height: 16px;
  accent-color: var(--color-information-600);
}

.filter-item label {
  cursor: pointer;
  flex: 1;
  margin: 0;
  color: var(--color-text-800);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Empty state in filter */
.filter-empty {
  padding: 20px 14px;
  text-align: center;
  color: var(--color-text-600);
  font-size: 13px;
}

/* Button container */
.excel-filter-dropdown .button-container {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--color-grey-800);
  background: var(--color-grey-600);
}

.excel-filter-dropdown .button-container button {
  flex: 1;
  font-size: 13px;
  padding: 8px 12px;
}

/* Prevent table layout shift when dropdown opens */
.transaction-table,
.ledger-table,
.trial-balance-table {
  table-layout: auto;
  width: 100%;
  min-width: 100%;
}

/* Ensure table headers don't break */
.transaction-table th,
.ledger-table th,
.trial-balance-table th,
.statement-table th {
  white-space: nowrap;
  position: relative;
  padding-right: 28px; /* Extra space for filter icon */
}

/* Fix for table wrapper to prevent overflow issues */
/* overflow-y: clip prevents Safari from coercing mixed overflow (auto+visible → auto)
   which would break position:sticky on table headers. Unlike overflow:hidden, clip does
   not create a scroll container, so sticky positioning still resolves to the page. */
.table-wrapper,
.table-container,
.ledger-table-wrapper,
.trial-balance-table-wrapper {
  overflow-x: auto;
  overflow-y: clip;
  position: relative;
  width: 100%;
}

/* Specific minimum widths to prevent squishing */
.transaction-table th,
.ledger-table th {
  min-width: 100px;
}

.transaction-table th:first-child,
.ledger-table th:first-child {
  min-width: 100px; /* Date column */
}

.transaction-table th:nth-child(2),
.transaction-table th:nth-child(3),
.ledger-table th:nth-child(2),
.ledger-table th:nth-child(7) {
  min-width: 150px; /* Description columns */
}

/* Actions column - fixed width */
.transaction-table th:last-child,
.ledger-table th:last-child {
  min-width: 100px;
  width: 100px;
}

/* Prevent content from breaking layout */
.transaction-table td,
.ledger-table td {
  padding: 12px 16px;
  vertical-align: middle;
}

/* Allow description columns to wrap if needed */
.transaction-table td:nth-child(2),
.transaction-table td:nth-child(3),
.ledger-table td:nth-child(7) {
  white-space: normal;
  word-break: break-word;
  max-width: 300px;
}

/* Other cells stay nowrap */
.transaction-table td:not(:nth-child(2)):not(:nth-child(3)),
.ledger-table td:not(:nth-child(7)) {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  .excel-filter-dropdown {
    max-width: 250px;
    min-width: 180px;
  }
  
  .transaction-table th,
  .ledger-table th {
    min-width: 80px;
  }
}

/* Fix z-index stacking for dropdowns */
.excel-filter-dropdown {
  z-index: var(--z-tooltip) !important;
}

thead {
  position: relative;
  z-index: var(--z-dropdown);
}

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

/* Ensure table stays within bounds */
.table-wrapper {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: clip; /* must match the rule above — visible causes Safari to coerce to auto */
}

/* Smooth scrolling */
.table-wrapper {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Fix for sticky headers with filters */
.transaction-table thead,
.ledger-table thead {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  background: var(--color-grey-600);
  z-index: var(--z-dropdown);
}
