.cw-table {
    --cw-table-control-bg: var(--cw-bg-card);
    --cw-table-header-bg: rgba(148, 163, 184, 0.1);
    --cw-table-row-bg: var(--cw-bg-card);
    --cw-table-row-hover: rgba(13, 148, 136, 0.075);
    --cw-table-row-border: var(--cw-border);
    position: relative;
    isolation: isolate;
    width: 100%;
    min-width: 0;
}

.cw-table-toolbar,
.cw-table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.cw-table-toolbar {
    min-height: 4.5rem;
    padding: 1rem 1.25rem;
    background: var(--cw-table-header-bg);
    border-bottom: 1px solid var(--cw-border);
}

.cw-table-length,
.cw-table-search {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin: 0;
    color: var(--cw-text-muted);
}

.cw-table-control-label {
    color: var(--cw-text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0;
    text-transform: uppercase;
    white-space: nowrap;
}

.cw-table-length .form-select,
.cw-table-search .form-control {
    height: 2.375rem;
    border: 1px solid var(--cw-border);
    border-radius: 8px;
    background-color: var(--cw-table-control-bg);
    color: var(--cw-text);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    transition: border-color 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
}

.cw-table-length .form-select:hover,
.cw-table-search .form-control:hover {
    border-color: #94a3b8;
}

.cw-table-length .form-select:focus,
.cw-table-search .form-control:focus {
    border-color: var(--cw-primary);
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.14);
}

.cw-table-length .form-select {
    width: 5rem;
    min-width: 5rem;
    padding-left: 0.75rem;
}

.cw-table-search {
    margin-left: auto;
}

.cw-table-search .form-control {
    width: min(19rem, 40vw);
    padding-left: 0.875rem;
    padding-right: 0.875rem;
}

.cw-table-search .form-control::placeholder {
    color: var(--cw-text-light);
    opacity: 1;
}

.cw-table > table.cw-table-grid {
    width: calc(100% - 1.5rem) !important;
    margin: 0.15rem 0.75rem 0.65rem !important;
    border-collapse: separate !important;
    border-spacing: 0 0.45rem !important;
    background: transparent;
}

.cw-table > table.cw-table-grid thead th {
    height: 2.75rem;
    padding: 0.65rem 0.875rem !important;
    border: 0 !important;
    background: transparent;
    color: var(--cw-text-muted);
    font-size: 0.6875rem;
    font-weight: 750;
    line-height: 1.2;
    letter-spacing: 0;
    text-transform: uppercase;
    vertical-align: middle;
}

.cw-table > table.cw-table-grid tbody td {
    padding: 0.875rem !important;
    border-top: 1px solid var(--cw-table-row-border) !important;
    border-bottom: 1px solid var(--cw-table-row-border) !important;
    background: var(--cw-table-row-bg);
    color: var(--cw-text);
    vertical-align: middle;
    transition: background-color 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.cw-table > table.cw-table-grid tbody td:first-child {
    border-left: 1px solid var(--cw-table-row-border) !important;
    border-radius: 7px 0 0 7px;
    box-shadow: inset 3px 0 0 transparent;
}

.cw-table > table.cw-table-grid tbody td:last-child {
    border-right: 1px solid var(--cw-table-row-border) !important;
    border-radius: 0 7px 7px 0;
}

.cw-table > table.cw-table-grid tbody tr:hover td {
    border-color: rgba(13, 148, 136, 0.32) !important;
    background: var(--cw-table-row-hover);
}

.cw-table > table.cw-table-grid tbody tr:hover td:first-child {
    box-shadow: inset 3px 0 0 var(--cw-primary);
}

.cw-table > table.cw-table-grid tbody .btn-group,
.cw-table > table.cw-table-grid tbody .btn-list {
    gap: 0.3rem;
}

.cw-table > table.cw-table-grid tbody .btn-ghost-primary,
.cw-table > table.cw-table-grid tbody .btn-ghost-danger {
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 6px;
}

.cw-table > table.cw-table-grid tbody .btn-ghost-primary:hover {
    border-color: rgba(13, 148, 136, 0.22);
    background: rgba(13, 148, 136, 0.11);
}

.cw-table > table.cw-table-grid tbody .btn-ghost-danger:hover {
    border-color: rgba(239, 68, 68, 0.22);
    background: rgba(239, 68, 68, 0.1);
}

.cw-table > table.cw-table-grid thead th.cw-table-sortable {
    position: relative;
    padding-right: 2rem !important;
    cursor: pointer;
    user-select: none;
}

th.cw-table-sortable:hover {
    color: var(--cw-text);
}

th.cw-table-sortable:focus-visible {
    outline: 2px solid var(--cw-primary);
    outline-offset: -3px;
    border-radius: 5px;
}

.cw-sort-indicator {
    position: absolute;
    top: 50%;
    right: 0.75rem;
    width: 0.5rem;
    height: 0.875rem;
    color: var(--cw-text-light);
    transform: translateY(-50%);
}

.cw-sort-indicator::before,
.cw-sort-indicator::after {
    content: "";
    position: absolute;
    left: 0;
    border-right: 4px solid transparent;
    border-left: 4px solid transparent;
    opacity: 0.4;
}

.cw-sort-indicator::before {
    top: 0;
    border-bottom: 5px solid currentColor;
}

.cw-sort-indicator::after {
    bottom: 0;
    border-top: 5px solid currentColor;
}

th.cw-sort-asc,
th.cw-sort-desc {
    color: var(--cw-primary) !important;
}

th.cw-sort-asc .cw-sort-indicator::before,
th.cw-sort-desc .cw-sort-indicator::after {
    color: var(--cw-primary);
    opacity: 1;
}

.cw-table-empty {
    height: 8rem;
    padding: 2rem 1rem !important;
    border: 1px dashed var(--cw-border) !important;
    border-radius: 7px !important;
    background: transparent !important;
    box-shadow: none !important;
}

.cw-table-footer {
    min-height: 4.25rem;
    padding: 0.875rem 1.25rem;
    border-top: 1px solid var(--cw-border);
    background: var(--cw-table-header-bg);
}

.cw-table-info {
    color: var(--cw-text-muted);
    font-size: 0.8125rem;
    font-weight: 550;
}

.cw-table-pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.cw-table-pagination .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.125rem;
    height: 2.125rem;
    padding: 0 0.6rem;
    border-color: var(--cw-border);
    border-radius: 6px;
    background: var(--cw-bg-card);
    color: var(--cw-text-muted);
    font-size: 0.75rem;
    font-weight: 650;
    box-shadow: none;
}

.cw-table-pagination .btn:hover:not(:disabled):not(.active) {
    border-color: rgba(13, 148, 136, 0.45);
    background: rgba(13, 148, 136, 0.08);
    color: var(--cw-primary-dark);
}

.cw-table-pagination .btn.active {
    border-color: var(--cw-primary);
    background: var(--cw-primary);
    color: #fff;
}

.cw-table-pagination .btn:disabled {
    border-color: transparent;
    background: transparent;
    color: var(--cw-text-light);
    opacity: 0.62;
}

.cw-table-pagination .btn:first-child,
.cw-table-pagination .btn:last-child {
    min-width: 5.25rem;
}

.cw-table-ellipsis {
    padding: 0 0.2rem;
    color: var(--cw-text-light);
}

.cw-table-loading::after {
    content: "";
    position: absolute;
    z-index: 3;
    top: 4.4rem;
    left: 0;
    width: 28%;
    height: 2px;
    background: var(--cw-primary);
    animation: cw-table-progress 1s ease-in-out infinite alternate;
}

.cw-table-loading > table tbody {
    opacity: 0.58;
}

@keyframes cw-table-progress {
    from {
        left: 0;
    }

    to {
        left: 72%;
    }
}

[data-bs-theme="dark"] .cw-table {
    --cw-table-control-bg: #111c2f;
    --cw-table-header-bg: rgba(15, 23, 42, 0.52);
    --cw-table-row-bg: #1b293d;
    --cw-table-row-hover: rgba(20, 184, 166, 0.1);
}

[data-bs-theme="dark"] .cw-table-length .form-select,
[data-bs-theme="dark"] .cw-table-search .form-control {
    border-color: var(--cw-border);
    background-color: var(--cw-table-control-bg);
    color: var(--cw-text);
}

[data-bs-theme="dark"] .cw-table-pagination .btn {
    border-color: var(--cw-border);
    background: #162337;
    color: var(--cw-text-muted);
}

[data-bs-theme="dark"] .cw-table-pagination .btn.active {
    border-color: var(--cw-primary-light);
    background: var(--cw-primary);
    color: #fff;
}

[data-bs-theme="dark"] .cw-table-pagination .btn:disabled {
    border-color: transparent;
    background: transparent;
}

@media (max-width: 767.98px) {
    .card:has(> .table-responsive > .cw-table) {
        overflow: visible;
        border: 0;
        background: transparent;
        box-shadow: none;
    }

    .card:has(> .table-responsive > .cw-table) > .card-header {
        padding-right: 0;
        padding-left: 0;
        border-bottom: 0;
        background: transparent;
    }

    .table-responsive:has(> .cw-table) {
        overflow-x: visible !important;
    }

    .cw-table {
        background: transparent;
    }

    .cw-table-toolbar {
        align-items: stretch;
        flex-direction: column;
        min-height: 0;
        margin-bottom: 0.75rem;
        padding: 0.875rem;
        border: 1px solid var(--cw-border);
        border-radius: 8px;
        background: var(--cw-bg-card);
        box-shadow: var(--cw-shadow-sm);
    }

    .cw-table-search {
        order: -1;
        margin-left: 0;
    }

    .cw-table-length,
    .cw-table-search {
        align-items: stretch;
        flex-direction: column;
        gap: 0.4rem;
        width: 100%;
    }

    .cw-table-length {
        display: grid;
        grid-template-columns: 1fr 5rem;
        align-items: center;
    }

    .cw-table-length .form-select,
    .cw-table-search .form-control {
        width: 100%;
    }

    .cw-table > table.cw-table-grid {
        width: 100% !important;
        margin: 0 !important;
        border-spacing: 0 !important;
    }

    .cw-table .cw-table-grid.table-cards tbody tr {
        display: block;
        overflow: hidden;
        margin: 0 0 0.75rem;
        padding: 0;
        border: 1px solid var(--cw-border);
        border-radius: 8px;
        background: var(--cw-bg-card);
        box-shadow: var(--cw-shadow-sm);
    }

    .cw-table .cw-table-grid.table-cards tbody tr:hover {
        border-color: rgba(13, 148, 136, 0.35);
        background: var(--cw-bg-card);
    }

    .cw-table .cw-table-grid.table-cards tbody td {
        display: grid;
        grid-template-columns: minmax(6.5rem, 36%) minmax(0, 1fr);
        align-items: center;
        gap: 0.75rem;
        min-height: 2.75rem;
        padding: 0.6rem 0.75rem !important;
        border: 0 !important;
        border-bottom: 1px solid var(--cw-border) !important;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
        font-size: 0.8125rem;
        text-align: right;
        white-space: normal;
    }

    .cw-table .cw-table-grid.table-cards tbody td:first-child {
        padding-top: 0.8rem !important;
        border-left: 3px solid var(--cw-primary) !important;
        font-weight: 650;
    }

    .cw-table .cw-table-grid.table-cards tbody td:last-child {
        padding-bottom: 0.8rem !important;
        border-bottom: 0 !important;
    }

    .cw-table .cw-table-grid.table-cards tbody td::before {
        min-width: 0;
        margin: 0;
        color: var(--cw-text-muted);
        font-size: 0.6875rem;
        font-weight: 700;
        line-height: 1.2;
        letter-spacing: 0;
        text-align: left;
        text-transform: uppercase;
    }

    .cw-table .cw-table-grid.table-cards tbody td > * {
        min-width: 0;
        justify-self: end;
    }

    .cw-table .cw-table-grid.table-cards tbody td .btn-group,
    .cw-table .cw-table-grid.table-cards tbody td .btn-list {
        justify-content: flex-end;
        width: 100%;
    }

    .cw-table .cw-table-grid.table-cards tbody td.cw-table-empty {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 8rem;
        border: 1px dashed var(--cw-border) !important;
        text-align: center;
    }

    .cw-table .cw-table-grid.table-cards tbody td.cw-table-empty::before {
        display: none;
    }

    .cw-table-footer {
        align-items: stretch;
        flex-direction: column;
        min-height: 0;
        gap: 0.75rem;
        padding: 0.25rem 0 0;
        border-top: 0;
        background: transparent;
    }

    .cw-table-info {
        text-align: center;
    }

    .cw-table-pagination {
        justify-content: center;
        width: 100%;
    }

    .cw-table-pagination .btn:first-child,
    .cw-table-pagination .btn:last-child {
        flex: 1 1 6.5rem;
        min-width: 0;
    }

    .cw-table-loading::after {
        top: 0;
    }
}

@media (max-width: 399.98px) {
    .cw-table .cw-table-grid.table-cards tbody td {
        grid-template-columns: minmax(5.5rem, 34%) minmax(0, 1fr);
        gap: 0.5rem;
        padding-right: 0.65rem !important;
        padding-left: 0.65rem !important;
    }

    .cw-table-pagination {
        gap: 0.25rem;
    }

    .cw-table-pagination .btn {
        min-width: 2rem;
        padding: 0 0.45rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cw-table-loading::after {
        animation: none;
        width: 100%;
    }

    .cw-table > table.cw-table-grid tbody td,
    .cw-table-length .form-select,
    .cw-table-search .form-control {
        transition: none;
    }
}
