.apt-container {
    max-width: 100%;
    margin: 20px 0;
    position: relative;
}

.apt-product-table {
    background: #ffffff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.06);
    border: 1px solid #e9ecef;
    transition: box-shadow 0.3s ease, transform 0.3s ease;
}

.apt-product-table:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.apt-table-title {
    padding: 18px 24px;
    font-weight: 600;
    display: flex;
    align-items: center;
    user-select: none;
    transition: background-color 0.3s ease;
    position: relative;
}

.apt-table-title[data-accordion='true'] {
    cursor: pointer;
}

.apt-title-text {
    display: inline-block;
}

.apt-table-title.apt-title-has-absolute-toggle .apt-accordion-toggle {
    position: absolute;
    right: 18px;
    top: 50%;
    transform: translateY(-50%);
}

.apt-table-title.apt-title-has-absolute-toggle .apt-accordion-toggle:hover {
    transform: translateY(-50%);
}

.apt-accordion-toggle {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: transform 0.3s ease, background-color 0.3s ease;
    flex-shrink: 0;
    font-size: 20px;
    line-height: 1;
}

.apt-accordion-toggle::before {
    transition: transform 0.3s ease;
}

.apt-accordion-toggle.apt-open::before {
    content: "−";
}

.apt-accordion-toggle.apt-closed::before {
    content: "+";
    transform: rotate(90deg);
}

.apt-table-wrapper {
    transition: max-height 0.4s ease-in-out, opacity 0.4s ease;
    overflow: hidden;
}

.apt-table-wrapper.apt-accordion-closed {
    max-height: 0 !important;
    opacity: 0;
}

.apt-table-wrapper.apt-scrollable-horizontal {
    overflow-x: auto;
}

.apt-table-wrapper.apt-scrollable-horizontal[data-draggable-scroll="true"] {
    cursor: grab;
}

.apt-table-wrapper.apt-scrollable-horizontal[data-draggable-scroll="true"].dragging {
    cursor: grabbing !important;
}

.apt-table-wrapper.dragging .apt-specs-table tbody tr {
    cursor: grabbing !important;
}

.apt-table-wrapper.apt-scrollable-vertical {
    overflow-y: auto !important;
}

.apt-table-wrapper::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
.apt-table-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}
.apt-table-wrapper::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}
.apt-table-wrapper::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

.apt-specs-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
    margin: 0 !important;
    margin-bottom: 0 !important;
}

/* Allow dynamic CSS to override table-layout when widths are defined */
.apt-specs-table[style*="table-layout"] {
    /* Dynamic CSS will set table-layout: fixed !important when needed */
}

.apt-specs-table.apt-has-custom-widths {
    width: auto !important;
    min-width: 100%;
}

.apt-specs-table th,
.apt-specs-table td {
    padding: 14px 20px;
    text-align: left;
    border-bottom: 1px solid #e9ecef;
    vertical-align: top;
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.apt-specs-table th {
    background-color: #f8f9fa;
    font-weight: 600;
    font-size: 0.9em;
    position: sticky;
    top: 0;
    z-index: 2;
    min-height: 45px;
}

.apt-specs-table th:empty {
    min-height: 45px;
}

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

.apt-specs-table th .apt-column-separator {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 1px;
}

.apt-container.apt-selection-enabled .apt-specs-table tbody tr {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.3s ease;
}

.apt-specs-table tbody tr.apt-row-selected {
}

@keyframes aptRowSelect {
    0% {
        opacity: 0.7;
    }
    100% {
        opacity: 1;
    }
}

.apt-specs-table tbody tr.apt-row-selected {
    animation: aptRowSelect 0.2s ease-out;
}

/* Ensure fixed column cells also get selected styling */
.apt-specs-table tbody tr.apt-row-selected td.apt-row-selected,
.apt-specs-table tbody tr.apt-row-selected td:first-child,
.apt-specs-table tbody tr.apt-row-selected td:nth-child(2) {
    background-color: inherit !important;
}

.apt-container.apt-selection-enabled .apt-specs-table tbody tr:focus {
    outline: none !important;
}

.apt-container.apt-selection-enabled .apt-specs-table tbody tr:focus-visible {
    outline: none !important;
}

.apt-container[data-selection-mode="multi"] .apt-table-title::after {
    content: attr(data-selection-count);
    display: none;
    margin-left: 10px;
    padding: 2px 8px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    font-size: 0.85em;
    font-weight: 600;
}

.apt-container[data-selection-mode="multi"][data-selection-count]:not([data-selection-count=""])::after {
    display: inline-block;
}

.apt-table-wrapper.apt-scrollable-horizontal .apt-specs-table {
    white-space: nowrap;
}

.apt-table-wrapper.apt-scrollable-horizontal .apt-specs-table td,
.apt-table-wrapper.apt-scrollable-horizontal .apt-specs-table th {
    white-space: normal;
}

.apt-container .apt-table-wrapper {
    min-width: 100%;
}

.apt-container .apt-table-wrapper.apt-scrollable-horizontal {
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
}

/* Better mobile handling for fixed width tables */
@media (max-width: 768px) {
    .apt-table-wrapper.apt-scrollable-horizontal {
        -webkit-overflow-scrolling: touch;
    }
}

.apt-swipe-hint {
    display: none;
    text-align: center;
    font-size: 12px;
    color: #6c757d;
    padding: 8px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
}

/* Force-disable any legacy pseudo-element hint that might still be applied */
.apt-table-wrapper.apt-scrollable-horizontal::after {
    content: none !important;
    display: none !important;
}
/* Extra hardening against theme or cached CSS rules */
.apt-table-wrapper::after {
    content: none !important;
    display: none !important;
}
@media (max-width: 1024px) {
    .apt-table-wrapper::after { content: none !important; display: none !important; }
}
@media (max-width: 768px) {
    .apt-table-wrapper::after { content: none !important; display: none !important; }
}

/* --- Enhanced Responsive Design --- */
@media (max-width: 1024px) {
    .apt-table-title {
        padding: 16px 20px;
        font-size: 16px;
    }
    .apt-specs-table th,
    .apt-specs-table td {
        padding: 12px 16px;
        font-size: 14px;
    }
}

@media (max-width: 768px) {
    .apt-table-title {
        padding: 16px;
        font-size: 16px;
    }
    .apt-specs-table th,
    .apt-specs-table td {
        padding: 12px 16px;
        font-size: 14px;
    }
    
    .apt-specs-table th,
    .apt-specs-table td {
        padding: 10px 12px;
    }
    
    /* Mobile-optimized row selection */
    .apt-container.apt-selection-enabled .apt-specs-table tbody tr {
        -webkit-tap-highlight-color: rgba(44, 90, 160, 0.1);
    }
    
    /* Increase tap target size on mobile */
    .apt-container.apt-selection-enabled .apt-specs-table tbody tr td {
        padding: 16px 12px;
    }
}

/* --- Column Width Override Classes --- */
.apt-container.apt-has-fixed-widths .apt-table-wrapper.apt-scrollable-horizontal {
    overflow-x: auto;
    overflow-y: visible;
}

.apt-container.apt-has-fixed-widths .apt-specs-table {
    table-layout: fixed;
    min-width: 100%;
}

.apt-container.apt-has-fixed-widths .apt-specs-table th,
.apt-container.apt-has-fixed-widths .apt-specs-table td {
    overflow: hidden;
    text-overflow: ellipsis;
    word-wrap: break-word;
}

.apt-container.apt-has-fixed-widths .apt-specs-table th:first-child,
.apt-container.apt-has-fixed-widths .apt-specs-table td:first-child {
    white-space: normal;
    text-overflow: unset;
    overflow: visible;
}

/* --- Performance Optimizations --- */
.apt-specs-table {
    will-change: scroll-position;
}

.apt-table-wrapper.apt-scrollable-horizontal {
    will-change: scroll-position;
    transform: translateZ(0);
}

/* --- Accessibility Improvements --- */
.apt-table-wrapper:focus {
    outline: 2px solid #2c5aa0;
    outline-offset: 2px;
}

.apt-table-title[data-accordion='true']:focus {
    outline: 2px solid #2c5aa0;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .apt-specs-table th,
    .apt-specs-table td {
        border-bottom: 2px solid #000;
    }
    
    .apt-product-table {
        border: 2px solid #000;
    }
    
    /* Improve contrast of the selected line. */
    .apt-specs-table tbody tr.apt-row-selected {
        border: 2px solid #000 !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .apt-product-table,
    .apt-table-wrapper,
    .apt-accordion-toggle,
    .apt-accordion-toggle::before,
    .apt-specs-table tbody tr,
    .apt-specs-table tbody tr.apt-row-selected {
        transition: none;
        animation: none;
    }
}

@media print {
    .apt-container {
        margin: 0;
        break-inside: avoid;
    }
    
    .apt-product-table {
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .apt-table-wrapper {
        overflow: visible !important;
        max-height: none !important;
    }
    
    .apt-specs-table {
        width: 100% !important;
        table-layout: auto !important;
    }
    
    .apt-accordion-toggle {
        display: none !important;
    }
    
    .apt-table-wrapper.apt-accordion-closed {
        max-height: none !important;
        opacity: 1 !important;
    }
    
    /* Ensure hover colors don't affect printing */
    .apt-specs-table tbody tr {
        background-color: inherit !important;
    }
    
    /* Show selected lines with a simple border. */
    .apt-specs-table tbody tr.apt-row-selected {
        border: 2px solid #000 !important;
    }
}

@media (prefers-color-scheme: dark) {
    .apt-product-table {
        background: #1e1e1e;
        border-color: #3a3a3a;
        color: #e0e0e0;
    }
    
    .apt-specs-table th {
        background-color: #2a2a2a;
        color: #e0e0e0;
    }
    
    .apt-specs-table th,
    .apt-specs-table td {
        border-bottom-color: #3a3a3a;
    }
    
    .apt-table-wrapper::-webkit-scrollbar-track {
        background: #2a2a2a;
    }
    
    .apt-table-wrapper::-webkit-scrollbar-thumb {
        background: #4a4a4a;
    }
    
    .apt-table-wrapper::-webkit-scrollbar-thumb:hover {
        background: #5a5a5a;
    }
}

.apt-container.apt-loading {
    opacity: 0.6;
    pointer-events: none;
}

.apt-container.apt-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #2c5aa0;
}

.apt-mobile-fullscreen-btn {
    position: absolute;
    bottom: 15px;
    right: 15px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #2c5aa0;
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
    z-index: 100;
    transition: all 0.3s ease;
    padding: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.apt-mobile-fullscreen-btn:hover,
.apt-mobile-fullscreen-btn:focus {
    background: #1e3d72;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
    transform: scale(1.05);
    outline: none;
}

.apt-mobile-fullscreen-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.apt-mobile-fullscreen-btn svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    stroke-width: 2.5;
    flex-shrink: 0;
}

@media (min-width: 769px) {
    .apt-mobile-fullscreen-btn {
        display: none !important;
    }
}

@media (max-width: 768px) {
    .apt-container .apt-mobile-fullscreen-btn {
        position: absolute;
        bottom: 15px;
        right: 15px;
        z-index: 100;
    }
}

.apt-container.apt-mobile-fullscreen-active {
    position: fixed !important;
    width: 100dvh !important;
    height: 100dvw !important;
    max-width: 100dvh !important;
    max-height: 100dvw !important;
    z-index: 999999 !important;
    background: #ffffff;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    transform: rotate(90deg) !important;
    transform-origin: center center !important;
    left: 50% !important;
    top: 50% !important;
    margin-left: -50dvh !important;
    margin-top: -50dvw !important;
    overscroll-behavior: none !important;
    touch-action: pan-x pan-y !important;
}

.apt-container.apt-mobile-fullscreen-active .apt-product-table {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    display: flex;
    flex-direction: column;
    border-radius: 0 !important;
}

.apt-container.apt-mobile-fullscreen-active .apt-product-table {
    width: 100% !important;
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
}

.apt-container.apt-mobile-fullscreen-active .apt-table-wrapper {
    flex: 1 !important;
    overflow-x: auto !important;
    overflow-y: auto !important;
    width: 100% !important;
    max-width: 100dvw !important;
    max-height: 100dvh !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    overscroll-behavior-x: contain;
    overscroll-behavior-y: contain;
}

.apt-container.apt-mobile-fullscreen-active .apt-specs-table {
    width: 100% !important;
    max-width: 100% !important;
}

.apt-container.apt-mobile-fullscreen-active .apt-specs-table th,
.apt-container.apt-mobile-fullscreen-active .apt-specs-table td {
    white-space: nowrap;
}

.apt-container.apt-mobile-fullscreen-active .apt-table-wrapper.apt-scrollable-horizontal {
    overflow-x: auto !important;
    overflow-y: auto !important;
}

.apt-container.apt-mobile-fullscreen-active .apt-mobile-fullscreen-expand {
    display: none !important;
}

.apt-container.apt-mobile-fullscreen-active .apt-mobile-fullscreen-collapse {
    display: flex !important;
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    z-index: 1000000 !important;
    width: 44px !important;
    height: 44px !important;
    transform: rotate(-90deg) !important;
}

/* Hide swipe hint when in fullscreen mode */
.apt-container.apt-mobile-fullscreen-active .apt-swipe-hint {
    display: none !important;
}

.apt-container.apt-mobile-fullscreen-active .apt-mobile-fullscreen-collapse svg {
    width: 22px !important;
    height: 22px !important;
}


body.apt-mobile-fullscreen-body {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
    overscroll-behavior: none !important;
    touch-action: none !important;
}

@keyframes aptSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}