.table-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  font: 14px "PT Sans", sans-serif;
  overflow: hidden;
  max-width: 100%;
  box-sizing: border-box;

  .table-wrapper {
    overflow-x: auto;
    overflow-y: auto;
    min-height: 0;
    max-width: 100%;
    width: 100%;

    /* Hide scrollbar */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* Internet Explorer 10+ */

    &::-webkit-scrollbar {
      display: none; /* Safari and Chrome */
    }
  }

  .table-component {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 0;
    table-layout: auto;
    display: table;

    th, td {
      text-align: center;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      padding: 4px 6px;
      min-width: 0;
      box-sizing: border-box;
      position: relative;
    }

    th {
      background: white;
      font-weight: 600;
      height: 32px;
      line-height: 32px;
      border-bottom: 1px solid #e0e0e0;
      position: sticky;
      top: 0;
      z-index: 2;
    }

    td {
      height: 23px;
      line-height: 23px;
      border-bottom: 1px solid #e0e0e0;
    }

    /* Sticky left column (selection) */
    .sticky-left {
      position: sticky;
      left: 0;
      z-index: 3;
      background: white;
    }

    /* Sticky right column (settings) */
    .sticky-right {
      position: sticky;
      right: 0;
      z-index: 3;
      background: white;
    }

    .text-left {
      text-align: left;
    }

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

    .text-right {
      text-align: right;
    }

    /* Checkbox wrapper */
    .checkbox-wrapper {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 100%;
    }

    /* Header select-all checkbox: always visible with gray borders (inverse of default white border) */
    thead .checkbox-wrapper .checkbox-container .checkbox {
      border-color: #C2C2C2;
      background: rgba(255, 255, 255, 0.6);
    }
    thead .checkbox-wrapper .checkbox-container .checkbox:hover {
      border-color: #A8A8A8;
    }
    thead .checkbox-wrapper .checkbox-container.checked .checkbox {
      border-color: #C2C2C2;
      background: #FFFFFF;
    }

    /* Sticky selected rows */
    tr.sticky-row {
      position: sticky;
      z-index: 5;
      background: white;
      
      td {
        background: white;
      }
      
      /* Maintain selection styling for sticky rows */
      &.selected td {
        background: var(--sel-color, #e3f2fd);
        cursor: grab;
      }
      
      /* Ensure sticky columns in sticky rows maintain their background */
      td.sticky-left,
      td.sticky-right {
        background: inherit;
      }
      
      &.selected td.sticky-left,
      &.selected td.sticky-right {
        background: var(--sel-color, #e3f2fd);
      }
      
      /* Only show shadow on the last sticky row */
      &.last-sticky {
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
      }
    }

    /* Sortable header styles */
    .sortable {
      cursor: pointer;
      user-select: none;

      .sort-wrap {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        min-width: 0;
      }

      .sort-label {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .sort-arrow {
        flex-shrink: 0;
        font-size: 14px;
        color: #666;
        line-height: 1;
        margin: 0 0 0 4px;
        padding: 0;
        opacity: 0.5;
        transition: all 0.2s ease;
      }

      &.active .sort-arrow {
        color: #FFA600;
        opacity: 1;
      }

      &:hover .sort-arrow {
        color: #FFA600;
        opacity: 1;
      }

      /* Specific alignment overrides for sortable headers */
      &.text-left .sort-wrap {
        justify-content: flex-start;
      }

      &.text-right .sort-wrap {
        justify-content: flex-end;
      }

      &.text-center .sort-wrap {
        justify-content: center;
      }
    }

    /* Row styles */
    tbody tr {
      position: relative;
      z-index: 0;

      > td {
        will-change: background-color;
        transition: background-color 0.2s ease;
      }

      &:hover > td {
        background-color: #F5F5F5
      }

      > td.selected {
        background: #FFF1BF;
      }

      /* Prevent text selection on draggable rows (Safari fix) */
      &[draggable="true"] {
        user-select: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
      }

      /* Disabled row styling */
      &.disabled {
        user-select: none;

        &.faded {
          opacity: 0.4;
          filter: grayscale(100%);

          /* Disable interactions for most elements but allow ID column */
          input, button, a, label, select, textarea {
            pointer-events: none;
          }

          td {
            background: #fafafa;
          }
        }

        &:hover > td {
          background: inherit;
        }
      }
    }

    /* Footer styles */
    tfoot {
      background: white;
      pointer-events: none;
      position: relative;

      /* Ensure footer completely blocks interactions */
      &::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: transparent;
        pointer-events: auto;
        z-index: 3;
      }

      /* Footer overflow support */
      .footer-cell {
        &.footer-overflow {
          overflow: visible;
          position: relative;
        }

        /* Positioned overflow content that doesn't affect layout */
        .footer-overflow-content {
          position: absolute;
          left: 4px;
          top: 50%;
          transform: translateY(-50%);
          white-space: nowrap;
          z-index: 10;
          padding: 0 2px;
        }

        /* Hidden placeholder to maintain cell height */
        .footer-placeholder {
          visibility: hidden;
        }
      }

      &.ship-footer {
        .footer-row {
          font-weight: 600;
          height: 29px;
          line-height: 29px;
          pointer-events: none;

          .footer-cell {
            position: relative;
            z-index: 1;
            border-bottom: none;
            padding: 4px 6px;
            height: 29px;
            line-height: 29px;
          }

          /* Selected footer styling */
          &.selected-footer {
            position: relative;

            .footer-cell {
              z-index: 1;
              border-bottom: none;
              background-color: #FFF1BF;

              &.footer-overflow {
                z-index: 2;
              }
            }

            /* Selected footer sticky columns for non-scrollable tables */
            .sticky-left {
              background: white !important;
              position: relative;

              &::after {
                content: '';
                position: absolute;
                left: 50%;
                top: 0;
                bottom: 0;
                right: 0;
                background: #FFF1BF;
                border-top-left-radius: 8px;
                border-bottom-left-radius: 8px;
              }
            }

            .sticky-right {
              background: white !important;
              position: relative;

              &::before {
                content: '';
                position: absolute;
                right: 50%;
                top: 0;
                bottom: 0;
                left: 0;
                background: #FFF1BF;
                border-top-right-radius: 8px;
                border-bottom-right-radius: 8px;
              }
            }
          }
        }
      }
    }

    /* Numeric column styles */
    .num {
      text-align: right;
      font-variant-numeric: tabular-nums;
    }

    /* Zero value styling */
    .zero {
      color: #8D92A5;
    }

    /* Price column styling */
    .price {
      text-align: right;
      font-variant-numeric: tabular-nums;

      .price-text {
        margin-right: 8px;
      }
    }

    /* Status icon styling */
    .status-icon {
      display: inline-block;
      width: 12px;
      height: 12px;
      margin-right: 3px;
      vertical-align: baseline;
      line-height: 1;

      &.completed svg {
        width: 10px;
        height: 11px;
      }

      &.partial svg {
        width: 10px;
        height: 11px;
      }

      &.error svg {
        width: 12px;
        height: 11px;
      }

      &.empty {
        visibility: hidden;
      }
    }

    /* Date with icon styling */
    .date-with-icon {
      display: inline-block;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      vertical-align: top;
      max-width: 100%;

      & > * {
        display: inline;
        white-space: nowrap;
      }

      .address-info {
        margin-left: 2px;
        display: inline ;
      }

      .company {
        color: #8D92A5;
        font-weight: 500;
        display: inline;
      }

      .msymbol {
        display: inline-block;
        vertical-align: middle;
      }

      time {
        display: inline;
        margin: 0 2px;
        font-weight: 500;
      }
    }

    /* Schedule icon styling */
    .msymbol.schedule {
      margin-left: 3px;
      color: #8D92A5;
      vertical-align: middle;
      font-size: 16px;
      line-height: 1;
    }

    /* Button styling for table actions */
    button {
      font-size: 86%;
      margin: 0 4px;
      padding: 0px 2px;
      color: #666;
      background-color: #f5f5f5;
      border: 1px solid #ccc;
      border-radius: 3px;
      cursor: pointer;

      &:hover {
        background-color: #e8e8e8;
      }
    }

    /* ID column styling */
    .nr {
      color: #E78F00;
      text-decoration: none;
      cursor: pointer;
    }

    /* Receipt icon styling */
    .receipt {
      font-size: 16px;
      color: #8D92A5;
      margin-right: 4px;
      vertical-align: middle;
      padding: 0;
    }

    /* Price with icon styling */
    .price-with-icon {
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 100%;
      gap: 8px; /* Add gap between icon and price */

      .receipt {
        margin-left: 4px;
        flex-shrink: 0;
      }

      .price-text {
        margin-left: auto;
        flex-shrink: 0;
      }
    }

    /* With note styling */
    .with-note {
      position: relative;

      &::after {
        content: "";
        position: absolute;
        top: 0;
        right: 0;
        display: block;
        border-left: 10px solid transparent;
        border-bottom: 10px solid transparent;
        border-top: 10px solid #FF6B35;
      }
    }
  }

  /* Column visibility controls */
  .column-visibility-controls {
    display: flex;
    gap: 8px;
    padding: 8px;
    background: #f5f5f5;
    border-bottom: 1px solid #e0e0e0;
    flex-wrap: wrap;

    .column-toggle {
      display: flex;
      align-items: center;
      padding: 2px 6px;
      border: 1px solid #ccc;
      background: #f5f5f5;
      border-radius: 4px;
      cursor: pointer;
      font-size: 12px;
      transition: all 0.2s ease;

      &:hover {
        background: #e8e8e8;
      }

      &.visible {
        border-color: #4CAF50;
        background: #E8F5E8;

        &:hover {
          background: #d4edda;
        }
      }

      .msymbol {
        font-size: 14px;
        margin-right: 2px;
      }
    }
  }

  &.scrollable {
    position: relative;
    z-index: 1; /* Create stacking context so sticky elements don't overlap dropdowns */
    
    .table-component {
      thead th {
        position: sticky;
        top: 0;
        background: white;
        z-index: 4;
      }

      thead th.sticky-left {
        z-index: 5;
      }

      tfoot.ship-footer {
        position: sticky;
        bottom: 0;
        background: white;
        z-index: 4;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
      }

      /* Ensure tfoot sticky columns work in scrollable mode */
      tfoot .sticky-left {
        position: sticky !important;
        left: 0 !important;
        z-index: 6 !important;
        background: white;
      }

      tfoot .sticky-right {
        position: sticky !important;
        right: 0 !important;
        z-index: 6;
        background: white;
      }

      /* Selected footer sticky columns */
      tfoot .selected-footer .sticky-left {
        position: sticky !important;
        left: 0 !important;
        z-index: 6;
        background: white !important;
        position: relative;
      }

      tfoot .selected-footer .sticky-left::after {
        content: '';
        position: absolute;
        left: 50%;
        top: 0;
        bottom: 0;
        right: 0;
        background: #FFF1BF;
        border-top-left-radius: 8px;
        border-bottom-left-radius: 8px;
      }

      tfoot .selected-footer .sticky-right {
        position: sticky !important;
        right: 0 !important;
        z-index: 6;
        background: white !important;
        position: relative;
      }

      tfoot .selected-footer .sticky-right::before {
        content: '';
        position: absolute;
        right: 50%;
        top: 0;
        bottom: 0;
        left: 0;
        background: #FFF1BF;
        border-top-right-radius: 8px;
        border-bottom-right-radius: 8px;
      }
    }
  }

  .column-dropdown {
    position: fixed;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 15;
    min-width: 200px;
    max-height: 300px;
    overflow-y: auto;

    .dropdown-header {
      padding: 8px 12px;
      font-weight: 600;
      border-bottom: 1px solid #e0e0e0;
      background: #f8f9fa;
    }

    .dropdown-content {
      padding: 8px;
      gap: 8px;
      display: flex;
      flex-direction: column;
    }

    .dropdown-item {
      padding: 0 8px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      cursor: pointer;
      position: relative;
      height: 24px;
      border-radius: 8px;
      transition: background-color 0.2s;
      font: 14px "PT Sans", sans-serif;

      &.toggle-item:hover {
        background: #f0f0f0;
        border-radius: 8px;
      }

      &.category-item:hover {
        background: #f0f0f0;
        border-radius: 8px;
        font-weight: bold;
      }

      &.reset-item {
        font-weight: 500;

        .dropdown-item-text {
          color: #999;
        }

        &:hover {
          background: #f0f0f0;
          border-radius: 8px;

          .dropdown-item-text {
            font-weight: bold;
            color: #333;
          }

          .msymbol {
            color: #FFA600;
          }
        }

        .msymbol {
          font-size: 18px;
          color: #999;
        }
      }
    }

    .dropdown-divider {
      height: 1px;
      background: #e0e0e0;
    }

    .toggle-switch {
      position: relative;
      width: 32px;
      height: 18px;
      background: #ccc;
      border-radius: 9px;
      cursor: pointer;
      transition: background-color 0.2s;
      flex-shrink: 0;

      &.active {
        background: #1E9F22;

        .toggle-knob {
          left: 16px;
        }
      }

      .toggle-knob {
        position: absolute;
        top: 2px;
        left: 2px;
        width: 14px;
        height: 14px;
        background: white;
        border-radius: 50%;
        transition: left 0.2s;
      }
    }

    .category-subdropdown {
      position: fixed;
      right: auto;
      left: auto;
      top: auto;
      background: white;
      border: 1px solid #e0e0e0;
      border-radius: 4px;
      box-shadow: 0 4px 12px rgba(0,0,0,0.15);
      z-index: 9; /* Higher than main dropdown */
      min-width: 180px;
      max-height: 300px;
      overflow-y: auto;
      padding: 8px;
    }
  }

  @media (max-width: 768px) {
    font-size: 12px;

    .table-component {
      th, td {
        padding: 2px 4px;
      }
    }

    .column-dropdown {
      min-width: 180px;
      max-height: 250px;

      .dropdown-item {
        padding: 8px 12px;
      }
    }

    /* Responsive adjustments for sticky elements */
    &.scrollable {
      .table-component {
        thead th {
          box-shadow: 0 1px 4px rgba(0,0,0,0.1);
        }

        tfoot.ship-footer {
          box-shadow: 0 -1px 4px rgba(0,0,0,0.1);
        }

        .selected-footer {
          box-shadow: 0 -1px 4px rgba(0,0,0,0.1);
        }
      }
    }
  }

  .settings-icon, .more-horiz-icon {
    font-size: 18px;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;

    &.active {
      color: #FFA600;
    }
  }

  .sort-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;

    &.justify-start {
      justify-content: flex-start;
    }

    &.justify-end {
      justify-content: flex-end;
    }

    &.justify-center {
      justify-content: center;
    }
  }

  .sort-arrow {
    font-size: 14px;
    color: #666;
    line-height: 1;
    margin: 0;
    padding: 0;
    transition: color 0.2s ease;

    &.active {
      color: #FFA600;
    }
  }

  .table-row {
    height: 29px;
    line-height: 29px;
  }

  .footer-row {
    pointer-events: none;
    height: 40px;
  }

  /* Virtual scrolling spacer rows */
  .virtual-spacer {
    pointer-events: none;
    
    td {
      padding: 0;
      border: none;
      background: transparent;
    }
  }

  /* Simplified scroll mode - hide complex elements during scrolling */
  .table-wrapper.simplified-scroll {
    /* Hide tooltips during scrolling */
    .tooltip,
    .status-icon,
    .msymbol.schedule,
    .msymbol.receipt {
      opacity: 0 !important;
      pointer-events: none !important;
    }

    /* Simplify date formatting */
    .date-with-icon {
      .status-icon,
      .msymbol {
        display: none !important;
      }
    }

    /* Hide company names */
    .company {
      display: none !important;
    }

    /* Disable hover effects */
    .table-component tbody tr:hover > td {
      background-color: inherit !important;
    }
  }

  .checkbox-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
  }

  .dropdown-item-text {
    font-size: 14px;
    color: #333;
    font-family: "PT Sans", sans-serif;
  }

  .category-subdropdown {
    display: none;

    &.visible {
      display: block;
    }
  }

  /* Hover styles for msymbol elements */
  .msymbol:hover {
    color: #FF8C00;
    cursor: pointer;
  }

  /* Specific hover rules for msymbol variants */
  .msymbol.schedule:hover {
    color: #FF8C00;
  }

  .column-visibility-controls .column-toggle .msymbol:hover {
    color: #FF8C00;
  }

  .sort-arrow.msymbol:hover {
    color: #FF8C00;
  }

  .settings-icon.msymbol:hover {
    color: #FF8C00;
  }
}

/* Ellipsis tooltip wrapper */
.ellipsis-wrapper {
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  vertical-align: middle;
}

::highlight(search-highlight) {
  background-color: #FFF3CD;
  color: #856404;
  padding: 2px 4px;
  border-radius: 3px;
  font-weight: 600;
}
