/**
 * MOJO Framework Table Styles
 * Custom table components, selection, table pages, and collection select
 * Version: 2.0.0
 *
 * Note: This file contains only custom MOJO table styles.
 * Bootstrap 5 is required as a dependency for base styles.
 */

/* ========================================================================
   TableView density defaults
   ========================================================================
   Bootstrap's `.table` defaults to body-size (16 px) — too loose for
   modern data tables. web-mojo TableView reduces body and header text
   to a denser, more readable scale and tightens cell padding so more
   rows fit above the fold. Scoped to `.table-view-component` so a
   consumer's hand-rolled `<table>` markup is untouched.

   For an even denser variant, opt into Bootstrap's existing `table-sm`
   modifier via `tableOptions: { size: 'sm' }`.
*/
.table-view-component .table {
    font-size: 0.875rem;          /* 14 px */
    --bs-table-cell-padding-y: 0.55rem;
    --bs-table-cell-padding-x: 0.75rem;
}

.table-view-component .table > thead > tr > th {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--bs-secondary-color);
    border-bottom: 1px solid var(--bs-border-color);
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    white-space: nowrap;
}

/* Number-like cells inherit tabular figures for clean column alignment */
.table-view-component .table .font-monospace,
.table-view-component .table code {
    font-variant-numeric: tabular-nums;
}

/* ========================================================================
   MOJO Custom Selection Components
   ======================================================================== */

.mojo-select-cell,
.mojo-select-all-cell {
    background-color: transparent;
    cursor: pointer;
    transition: background-color 0.2s ease;
    text-align: center;
    vertical-align: middle;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mojo-select-cell.selected,
.mojo-select-all-cell.selected {
    background-color: transparent;
}

/*.mojo-select-cell:hover,
.mojo-select-all-cell:hover {
    background-color: var(--bs-primary);
}*/

.mojo-checkbox {
    height: 20px;
    width: 20px;
    border-radius: 6px;
    border: 2px solid var(--bs-border-color);
    background-color: var(--bs-body-bg);

    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.mojo-checkbok:focused,
.mojo-checkbok:hover {
    box-shadow: 0 0 0 0.25rem rgba(56, 116, 255, 0.25);
}

.mojo-select-cell:hover .mojo-checkbox {
    box-shadow: 0 0 0 0.25rem rgba(56, 116, 255, 0.25);
}

.mojo-select-cell.selected .mojo-checkbox,
.mojo-select-all-cell.selected .mojo-checkbox {
    color: #fff;
    background-color: var(--bs-primary);
    border-color: var(--bs-primary);
}

/*.mojo-select-cell:hover .mojo-checkbox,
.mojo-select-all-cell:hover .mojo-checkbox {
    border-color: var(--bs-white);
    background-color: var(--bs-white);
}*/

.mojo-checkbox i {
    font-size: 1rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.mojo-select-cell.selected .mojo-checkbox i,
.mojo-select-all-cell.selected .mojo-checkbox i {
    opacity: 1;
}

.mojo-select-all-cell.indeterminate .mojo-checkbox {
    border-color: var(--bs-primary);
    background-color: var(--bs-primary);
}

.mojo-select-all-cell.indeterminate .mojo-checkbox i {
    opacity: 1;
    color: white;
}

/* ========================================================================
   MOJO TablePage Component
   ======================================================================== */

.table-page-container {
    position: relative;
}

.mojo-table-wrapper {
    padding: 1rem;
}

.mojo-table-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background-color: var(--bs-body-bg);
    opacity: 0.8;
    height: 100%;
}

.table-page-header {
    border-bottom: 1px solid var(--bs-border-color);
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
}

/* MOJO Custom Table Container */
.table-container {
    position: relative;
    /*margin: 1rem;*/
    transition: opacity 0.3s ease;
}

.table-container.is-loading {
    opacity: 0.7;
    pointer-events: none;
}

/* MOJO Table Status Bar */
/*.table-status-bar {
    border-top: 1px solid var(--bs-border-color);
    padding-top: 0.75rem;
}*/

.table-status-bar.table-status-top {
    border-top: none;
    border-bottom: 1px solid var(--bs-border-color);
    padding-top: 0;
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
}

.status-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

/* MOJO Loading States */
.table-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bs-body-bg);
    opacity: 0.9;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.loading-content {
    padding: 2rem;
    text-align: center;
}

.loading-message {
    margin-top: 1rem;
    color: var(--bs-secondary-color);
    font-size: 0.95rem;
}

.loading-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.error-indicator {
    animation: mojo-pulse 2s ease-in-out infinite;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

/* MOJO Action Buttons Toolbar */
/*.table-action-buttons {
    border-bottom: 1px solid var(--bs-border-color);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}*/

.table-actions-bottom {
    border-bottom: none;
    border-top: 1px solid var(--bs-border-color);
    padding-top: 1rem;
    padding-bottom: 0;
    margin-top: 1rem;
    margin-bottom: 0;
}

/* MOJO Batch Actions Panel */
.batch-actions-panel {
    position: sticky;
    bottom: 10px;
    box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.4);
    background-color: var(--bs-body-bg);
    height: 60px;
    z-index: 20;
    margin: 0 8px;
}

div.batch-select-count {
    font-size: 1.5rem !important;
    background-color: var(--bs-primary);
    color: var(--bs-white);
    min-width: 50px;
    text-align: center;
    height: 60px;
    line-height: 60px;
}

div.batch-select-title {
    font-size: 1.5rem !important;
    line-height: 60px;
    height: 60px;
}

div.batch-select-action {
    cursor: pointer;
    color: var(--bs-primary-text-emphasis);
    transition: color 0.2s ease;
}

div.batch-select-action:hover {
    color: var(--bs-primary);
}

div.batch-select-end {
    border-radius: 0 4px 4px 0;
    background-color: var(--bs-primary);
    height: 60px;
    width: 10px;
}

/* MOJO Batch Actions Panel - Top Position */
.batch-actions-panel-top {
    border-left: 4px solid var(--bs-primary);
    /*background-color: var(--bs-info-bg-subtle);*/
    border-color: var(--bs-info-border-subtle);
    /*border: none;*/
    margin: 0 !important;
    padding: 0.4rem;
    animation: slideDown 0.3s ease-out;
}

.batch-actions-panel-top .batch-select-count {
    font-weight: bold;
    color: var(--bs-primary);
    font-size: 1.1rem;
}

.batch-actions-panel-top button {
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

.batch-actions-panel-top button:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

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

/* MOJO Button Enhancements */
.btn-refresh:not(:disabled):hover .bi-arrow-clockwise {
    animation: mojo-spin 0.5s ease-in-out;
}

.btn-add:not(:disabled):hover {
    transform: translateY(-1px);
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
}

.btn-export:not(:disabled):hover .bi-download,
.btn-import:not(:disabled):hover .bi-upload {
    animation: mojo-bounce 0.5s ease-in-out;
}

/* ========================================================================
   MOJO Collection Select Component
   ======================================================================== */

.collection-select-view {
    position: relative;
}

.collection-select-view .form-control.is-invalid {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath d='m5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

/* Enhanced dropdown for collection select */
.collection-select-view .dropdown-item:has(.spinner-border) {
    justify-content: center;
    align-items: center;
    min-height: 3rem;
}

.collection-select-view .dropdown-item:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: -2px;
}

/* Custom scrollbar for collection dropdown */
.collection-select-view .dropdown-menu::-webkit-scrollbar {
    width: 6px;
}

.collection-select-view .dropdown-menu::-webkit-scrollbar-track {
    background: var(--bs-secondary-bg);
    border-radius: var(--bs-border-radius-sm);
}

.collection-select-view .dropdown-menu::-webkit-scrollbar-thumb {
    background: var(--bs-border-color);
    border-radius: var(--bs-border-radius-sm);
}

.collection-select-view .dropdown-menu::-webkit-scrollbar-thumb:hover {
    background: var(--bs-secondary);
}

/* Collection select clear button */
.collection-select-view .btn[data-action="clear-selection"] {
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--bs-secondary);
    transition: color 0.15s ease-in-out;
}

.collection-select-view .btn[data-action="clear-selection"]:hover {
    color: var(--bs-danger);
}

.collection-select-view .btn[data-action="clear-selection"]:focus {
    box-shadow: none;
    outline: 2px solid var(--bs-primary);
    outline-offset: 2px;
}

.collection-select-view .btn[data-action="clear-selection"] i {
    font-size: 1rem;
}

/* Adjust input padding when clear button is present */
.collection-select-view .form-control.pe-5 {
    padding-right: 2.5rem !important;
}

/* Dark theme styles for collection select */
/* ========================================================================
   MOJO Table Utilities
   ======================================================================== */

.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.data-view-item .data-view-label {
    font-size: 0.6rem;
}

/* Custom scrollbar for table container */
.table-container::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

.table-container::-webkit-scrollbar-track {
    background: var(--bs-secondary-bg);
    border-radius: var(--bs-border-radius-sm);
}

.table-container::-webkit-scrollbar-thumb {
    background: var(--bs-border-color);
    border-radius: var(--bs-border-radius-sm);
}

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

/* ========================================================================
   MOJO Table Animations
   ======================================================================== */

@keyframes mojo-spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes mojo-pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

@keyframes mojo-bounce {
    0%,
    100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-3px);
    }
}

/* ========================================================================
   Responsive Design
   ======================================================================== */

@media (max-width: 768px) {
    .table-page-header {
        padding-bottom: 0.75rem;
        margin-bottom: 1rem;
    }

    /* Batch actions panel top - responsive */
    .batch-actions-panel-top {
        padding: 0.75rem !important;
    }

    .batch-actions-panel-top .d-flex {
        flex-direction: column;
        gap: 0.75rem;
    }

    .batch-actions-panel-top .batch-select-count {
        font-size: 1rem;
    }

    .page-title {
        font-size: 1.5rem;
    }

    .page-description {
        font-size: 0.9rem;
    }

    .table-status-bar {
        padding: 0.5rem 0.75rem;
    }

    .status-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .collection-select-view .dropdown-menu {
        max-height: 200px;
    }

    .collection-select-view .dropdown-item {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }
}

@media (max-width: 576px) {
    .table-container {
        overflow-x: auto;
    }

    .page-title {
        font-size: 1.25rem;
    }

    .loading-content {
        padding: 1rem;
    }

    /* Batch actions panel top - mobile */
    .batch-actions-panel-top button {
        font-size: 0.875rem;
        padding: 0.25rem 0.5rem;
    }

    .batch-actions-panel-top .btn-group {
        flex-wrap: wrap;
    }
}

/* ========================================================================
   Dark Theme Support
   ======================================================================== */

[data-bs-theme="dark"] .table-loading-overlay {
    background: var(--bs-dark);
    opacity: 0.9;
}

[data-bs-theme="dark"] .batch-actions-panel {
    background-color: var(--bs-dark);
}

[data-bs-theme="dark"] .batch-actions-panel-top {
    background-color: rgba(13, 110, 253, 0.1);
    border-color: rgba(13, 110, 253, 0.3);
}

[data-bs-theme="dark"] .collection-select-view .dropdown-menu::-webkit-scrollbar-track {
    background: var(--bs-secondary-bg);
}

[data-bs-theme="dark"] .collection-select-view .dropdown-menu::-webkit-scrollbar-thumb {
    background: var(--bs-border-color);
}

[data-bs-theme="dark"] .collection-select-view .dropdown-menu::-webkit-scrollbar-thumb:hover {
    background: var(--bs-secondary-color);
}

/* Dark theme clear button */
[data-bs-theme="dark"] .collection-select-view .btn[data-action="clear-selection"] {
    color: var(--bs-secondary);
}

[data-bs-theme="dark"] .collection-select-view .btn[data-action="clear-selection"]:hover {
    color: var(--bs-danger);
}

[data-bs-theme="dark"] .collection-select-view .btn[data-action="clear-selection"]:focus {
    outline-color: var(--bs-primary);
}

[data-bs-theme="dark"] .table-container::-webkit-scrollbar-track {
    background: var(--bs-secondary-bg);
}

[data-bs-theme="dark"] .table-container::-webkit-scrollbar-thumb {
    background: var(--bs-border-color);
}

[data-bs-theme="dark"] .table-container::-webkit-scrollbar-thumb:hover {
    background: var(--bs-secondary-color);
}

/* ========================================================================
   MOJO Table Fullscreen Mode
   ======================================================================== */

.table-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 9999 !important;
    background: var(--bs-body-bg) !important;
    padding: 1rem !important;
    overflow: auto !important;
}

/* Modal z-index is handled by Dialog.js getFullscreenAwareZIndex() */

.table-fullscreen .mojo-table-wrapper {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 0;
}

.table-fullscreen .table-container {
    flex: 1;
    overflow: auto;
    margin-bottom: 1rem;
}

.table-fullscreen .table {
    margin-bottom: 0;
}

/* Optimize pagination for fullscreen */
.table-fullscreen .table-status-bar {
    flex-shrink: 0;
    margin-top: auto;
    border-top: 1px solid var(--bs-border-color);
    padding-top: 1rem;
    background: var(--bs-body-bg);
}

/* Fullscreen button animation */
.btn-fullscreen {
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

.btn-fullscreen:hover {
    transform: scale(1.05);
}

.table-fullscreen .btn-fullscreen {
    background-color: var(--bs-primary);
    color: var(--bs-white);
    border-color: var(--bs-primary);
}

.table-fullscreen .btn-fullscreen:hover {
    background-color: var(--bs-primary);
    border-color: var(--bs-primary);
    opacity: 0.9;
}

/* Improve scrolling in fullscreen */
.table-fullscreen .table-container::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.table-fullscreen .table-container::-webkit-scrollbar-track {
    background: var(--bs-secondary-bg);
}

.table-fullscreen .table-container::-webkit-scrollbar-thumb {
    background: var(--bs-secondary);
    border-radius: 6px;
}

.table-fullscreen .table-container::-webkit-scrollbar-thumb:hover {
    background: var(--bs-secondary-color);
}

/* Dark theme support for fullscreen */
[data-bs-theme="dark"] .table-fullscreen {
    background: var(--bs-dark) !important;
}

[data-bs-theme="dark"] .table-fullscreen .table-status-bar {
    background: var(--bs-dark);
}

/* ========================================================================
   MOJO Table Footer Totals
   ======================================================================== */

.table-totals-row {
    background-color: var(--bs-light);
    border-top: 2px solid var(--bs-primary);
    font-weight: 500;
}

.table-footer-label {
    color: var(--bs-emphasis-color);
    font-weight: 600;
}

.table-footer-total {
    color: var(--bs-primary);
    font-weight: 600;
    text-align: right;
}

/* Dark theme support for footer totals */
[data-bs-theme="dark"] .table-totals-row {
    background-color: var(--bs-dark);
    border-top-color: var(--bs-primary);
}

[data-bs-theme="dark"] .table-footer-label {
    color: var(--bs-light);
}

[data-bs-theme="dark"] .table-footer-total {
    color: var(--bs-primary);
}

/* ========================================================================
   MOJO Table Inline Editing Styles
   ======================================================================== */

.editable-cell {
    cursor: pointer;
    position: relative;
}

.editable-cell:hover {
    background-color: rgba(13, 110, 253, 0.05);
}

.editable-cell.editing {
    background-color: rgba(13, 110, 253, 0.1);
}

.cell-editor {
    width: 100%;
    max-width: 100%;
}

.cell-editor .form-control,
.cell-editor .form-select {
    flex: 1;
    min-width: 0;
}

.cell-editor .btn {
    white-space: nowrap;
    flex-shrink: 0;
    min-width: auto;
    width: 2rem;
    height: 2rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cell-editor .form-check {
    margin-bottom: 0;
}

/* Focus styles for editing */
.cell-editor .form-control:focus,
.cell-editor .form-select:focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* Ensure proper spacing in editor buttons */
.cell-editor .d-flex.gap-1 > * {
    flex-shrink: 0;
}

/* Special styling for switch editors */
.cell-editor .form-switch .form-check-input {
    margin-left: 0;
}

/* Hover effect for editable cells */
.editable-cell .cell-content {
    padding: 2px 4px;
    border-radius: 3px;
    transition: background-color 0.15s ease-in-out;
}

.editable-cell:hover .cell-content {
    background-color: rgba(13, 110, 253, 0.1);
}

/* Small visual indicator for editable cells */
.editable-cell::after {
    content: "";
    position: absolute;
    top: 4px;
    right: 4px;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-top: 4px solid rgba(108, 117, 125, 0.3);
    opacity: 0;
    transition: opacity 0.15s ease-in-out;
}

.editable-cell:hover::after {
    opacity: 1;
}

/* Loading state for saving */
.cell-editor.saving {
    opacity: 0.7;
    pointer-events: none;
}

.cell-editor.saving .btn {
    disabled: true;
}

/* Error state for failed saves */
.cell-editor.saving-error {
    border-left: 3px solid var(--bs-danger);
    background-color: rgba(220, 53, 69, 0.1);
}

.cell-editor.saving-error .form-control,
.cell-editor.saving-error .form-select {
    border-color: var(--bs-danger);
}

/* Dark theme support for inline editing */
[data-bs-theme="dark"] .editable-cell:hover {
    background-color: rgba(13, 110, 253, 0.1);
}

[data-bs-theme="dark"] .editable-cell.editing {
    background-color: rgba(13, 110, 253, 0.15);
}

[data-bs-theme="dark"] .editable-cell:hover .cell-content {
    background-color: rgba(13, 110, 253, 0.15);
}

[data-bs-theme="dark"] .editable-cell::after {
    border-top-color: rgba(255, 255, 255, 0.3);
}

/* ========================================================================
   Accessibility
   ======================================================================== */

@media (prefers-contrast: high) {
    .collection-select-view .dropdown-item.active {
        background-color: var(--bs-emphasis-color);
        color: var(--bs-body-bg);
    }

    .mojo-checkbox {
        border-width: 2px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .table-container,
    .mojo-checkbox,
    .batch-select-action,
    .batch-actions-panel-top,
    .batch-actions-panel-top button {
        transition: none;
    }

    @keyframes slideDown {
        from,
        to {
            opacity: 1;
            transform: none;
        }
    }

    .btn-refresh:not(:disabled):hover .bi-arrow-clockwise,
    .btn-export:not(:disabled):hover .bi-download,
    .btn-import:not(:disabled):hover .bi-upload {
        animation: none;
    }
}

/* ========================================================================
   Row stripe (severity-coded left-edge color)

   TableView companion to `list-view.css` — same `rowStripe:` callback,
   same Bootstrap variant tokens. Rows are `<tr>`s, so we paint the
   stripe with `box-shadow: inset` on the leftmost `<td>` rather than
   `border-left` on the row (the row-level border doesn't render under
   `border-collapse: separate`, which is Bootstrap's `.table` default,
   and `border-left` on the cell would push column widths).

   When the table is selectable, `td:first-child` is the checkbox cell
   — that's the intended leftmost-edge placement.
   ======================================================================== */

.table-view-component .table > tbody > tr.list-row-stripe-danger    > td:first-child { box-shadow: inset 4px 0 0 var(--bs-danger); }
.table-view-component .table > tbody > tr.list-row-stripe-warning   > td:first-child { box-shadow: inset 4px 0 0 var(--bs-warning); }
.table-view-component .table > tbody > tr.list-row-stripe-info      > td:first-child { box-shadow: inset 4px 0 0 var(--bs-info); }
.table-view-component .table > tbody > tr.list-row-stripe-success   > td:first-child { box-shadow: inset 4px 0 0 var(--bs-success); }
.table-view-component .table > tbody > tr.list-row-stripe-primary   > td:first-child { box-shadow: inset 4px 0 0 var(--bs-primary); }
.table-view-component .table > tbody > tr.list-row-stripe-secondary > td:first-child { box-shadow: inset 4px 0 0 var(--bs-secondary); }
