/**
 * TECHERP data surfaces
 * Global, CSS-only treatment for Bootstrap tables and DataTables. Existing
 * markup, IDs, exports, sorting, filtering and responsive behaviour stay intact.
 */

@media screen {
    body:not(.lockscreen) .dataTables_wrapper {
        --table-accent: var(--primary, #6d42f5);
        position: relative;
        clear: both;
        width: 100%;
        padding: 1.15rem;
        background:
            radial-gradient(circle at 0 0, color-mix(in srgb, var(--table-accent) 7%, transparent) 0, transparent 28%),
            var(--surface);
        border: 1px solid color-mix(in srgb, var(--border) 86%, var(--table-accent));
        border-radius: 1.15rem;
        box-shadow: 0 14px 36px rgba(24, 19, 53, 0.055);
        color: var(--text-primary);
    }

    body:not(.lockscreen) .dataTables_wrapper::after {
        content: "";
        display: table;
        clear: both;
    }

    /* DataTables control bar */
    body:not(.lockscreen) .dataTables_wrapper .dataTables_length,
    body:not(.lockscreen) .dataTables_wrapper .dataTables_filter,
    body:not(.lockscreen) .dataTables_wrapper .dt-buttons {
        min-height: 2.75rem;
        margin: 0 0 1rem;
    }

    body:not(.lockscreen) .dataTables_wrapper .dataTables_length {
        float: left;
        display: inline-flex;
        align-items: center;
        margin-right: 0.75rem;
        color: var(--text-secondary);
        font-size: 0.84rem;
        font-weight: 600;
    }

    body:not(.lockscreen) .dataTables_wrapper .dataTables_length label,
    body:not(.lockscreen) .dataTables_wrapper .dataTables_filter label {
        display: inline-flex;
        align-items: center;
        gap: 0.55rem;
        margin: 0;
        color: var(--text-secondary);
        font-weight: 600;
    }

    body:not(.lockscreen) .dataTables_wrapper .dataTables_length select {
        width: 5rem;
        min-width: 5rem;
        height: 2.75rem;
        margin: 0 !important;
        padding: 0 2rem 0 0.8rem;
        color: var(--text-primary);
        background-color: var(--surface);
        border: 1px solid var(--border);
        border-radius: 0.75rem;
        box-shadow: 0 3px 10px rgba(24, 19, 53, 0.035);
        font-weight: 700;
        outline: none;
    }

    body:not(.lockscreen) .dataTables_wrapper .dataTables_filter {
        position: relative;
        float: right;
        display: inline-flex;
        align-items: center;
        justify-content: flex-end;
    }

    body:not(.lockscreen) .dataTables_wrapper .dataTables_filter label::before {
        content: "\f002";
        position: absolute;
        left: 0.95rem;
        top: 50%;
        z-index: 2;
        transform: translateY(-50%);
        color: var(--text-muted);
        font-family: "Font Awesome 5 Free", "FontAwesome";
        font-size: 0.78rem;
        font-weight: 900;
        pointer-events: none;
    }

    body:not(.lockscreen) .dataTables_wrapper .dataTables_filter input[type="search"] {
        width: clamp(13rem, 17vw, 18rem);
        height: 2.75rem;
        margin: 0 !important;
        padding: 0 0.9rem 0 2.55rem;
        color: var(--text-primary);
        background: color-mix(in srgb, var(--surface-secondary) 56%, var(--surface));
        border: 1px solid var(--border);
        border-radius: 0.8rem;
        box-shadow: inset 0 1px 0 color-mix(in srgb, #fff 65%, transparent);
        outline: none;
        transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
    }

    body:not(.lockscreen) .dataTables_wrapper .dataTables_filter input[type="search"]:focus {
        background: var(--surface);
        border-color: color-mix(in srgb, var(--table-accent) 68%, var(--border));
        box-shadow: 0 0 0 3px color-mix(in srgb, var(--table-accent) 13%, transparent);
    }

    body:not(.lockscreen) .dataTables_wrapper .dt-buttons {
        float: left;
        display: inline-flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 0.38rem;
        margin-right: 0.75rem;
    }

    body:not(.lockscreen) .dataTables_wrapper .dt-buttons .btn,
    body:not(.lockscreen) .dataTables_wrapper .dt-buttons a.btn,
    body:not(.lockscreen) .dataTables_wrapper .dt-button {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        gap: 0.42rem;
        min-height: 2.35rem;
        margin: 0 !important;
        padding: 0.48rem 0.72rem !important;
        color: var(--text-secondary) !important;
        background: var(--surface) !important;
        border: 1px solid var(--border) !important;
        border-radius: 0.66rem !important;
        box-shadow: 0 3px 10px rgba(24, 19, 53, 0.035) !important;
        font-size: 0.78rem !important;
        font-weight: 700 !important;
        line-height: 1 !important;
        text-decoration: none !important;
        transition: transform 150ms ease, color 150ms ease, border-color 150ms ease, background 150ms ease, box-shadow 150ms ease;
    }

    body:not(.lockscreen) .dataTables_wrapper .dt-buttons .btn:hover,
    body:not(.lockscreen) .dataTables_wrapper .dt-buttons a.btn:hover,
    body:not(.lockscreen) .dataTables_wrapper .dt-button:hover {
        color: var(--table-accent) !important;
        background: color-mix(in srgb, var(--table-accent) 7%, var(--surface)) !important;
        border-color: color-mix(in srgb, var(--table-accent) 30%, var(--border)) !important;
        box-shadow: 0 7px 16px color-mix(in srgb, var(--table-accent) 12%, transparent) !important;
        transform: translateY(-1px);
    }

    body:not(.lockscreen) .dataTables_wrapper .dt-buttons .btn i,
    body:not(.lockscreen) .dataTables_wrapper .dt-button i {
        color: color-mix(in srgb, var(--table-accent) 78%, var(--text-secondary));
    }

    /* Data surface */
    body:not(.lockscreen) .dataTables_wrapper .dataTables_scroll,
    body:not(.lockscreen) .dataTables_wrapper > table.dataTable,
    body:not(.lockscreen) .dataTables_wrapper > .table-responsive {
        clear: both;
    }

    body:not(.lockscreen) table.table,
    body:not(.lockscreen) table.dataTable {
        width: 100% !important;
        margin: 0.15rem 0 0.8rem !important;
        color: var(--text-primary);
        background: transparent;
        border: 0 !important;
        border-collapse: separate !important;
        border-spacing: 0 0.32rem !important;
    }

    body:not(.lockscreen) table.table > thead > tr > th,
    body:not(.lockscreen) table.dataTable > thead > tr > th {
        height: 2.8rem;
        padding: 0.72rem 0.78rem !important;
        color: color-mix(in srgb, var(--text-secondary) 92%, var(--table-accent));
        background: color-mix(in srgb, var(--surface-secondary) 78%, var(--surface));
        border-top: 1px solid var(--border) !important;
        border-bottom: 1px solid var(--border) !important;
        border-left: 0 !important;
        border-right: 0 !important;
        font-size: 0.72rem;
        font-weight: 800;
        letter-spacing: 0.045em;
        line-height: 1.35;
        text-transform: uppercase;
        vertical-align: middle;
        white-space: nowrap;
    }

    body:not(.lockscreen) table.table > thead > tr > th:first-child,
    body:not(.lockscreen) table.dataTable > thead > tr > th:first-child {
        border-left: 1px solid var(--border) !important;
        border-radius: 0.78rem 0 0 0.78rem;
    }

    body:not(.lockscreen) table.table > thead > tr > th:last-child,
    body:not(.lockscreen) table.dataTable > thead > tr > th:last-child {
        border-right: 1px solid var(--border) !important;
        border-radius: 0 0.78rem 0.78rem 0;
    }

    body:not(.lockscreen) table.table > tbody > tr > td,
    body:not(.lockscreen) table.dataTable > tbody > tr > td {
        padding: 0.78rem !important;
        color: var(--text-primary);
        background: color-mix(in srgb, var(--surface) 96%, var(--surface-secondary));
        border-top: 1px solid color-mix(in srgb, var(--border) 78%, transparent) !important;
        border-bottom: 1px solid color-mix(in srgb, var(--border) 78%, transparent) !important;
        border-left: 0 !important;
        border-right: 0 !important;
        vertical-align: middle;
        transition: background 150ms ease, border-color 150ms ease;
    }

    body:not(.lockscreen) table.table > tbody > tr > td:first-child,
    body:not(.lockscreen) table.dataTable > tbody > tr > td:first-child {
        border-left: 1px solid color-mix(in srgb, var(--border) 78%, transparent) !important;
        border-radius: 0.7rem 0 0 0.7rem;
    }

    body:not(.lockscreen) table.table > tbody > tr > td:last-child,
    body:not(.lockscreen) table.dataTable > tbody > tr > td:last-child {
        border-right: 1px solid color-mix(in srgb, var(--border) 78%, transparent) !important;
        border-radius: 0 0.7rem 0.7rem 0;
    }

    body:not(.lockscreen) table.table > tbody > tr:hover > td,
    body:not(.lockscreen) table.dataTable > tbody > tr:hover > td {
        background: color-mix(in srgb, var(--table-accent) 5%, var(--surface));
        border-color: color-mix(in srgb, var(--table-accent) 17%, var(--border)) !important;
    }

    /* DataTables scroll mode keeps a sizing-only header inside the body table. */
    body:not(.lockscreen) .dataTables_scrollBody table.dataTable > thead > tr > th,
    body:not(.lockscreen) .dataTables_scrollBody table.dataTable > thead > tr > td {
        height: 0 !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
        color: transparent !important;
        background: transparent !important;
        border-top: 0 !important;
        border-bottom: 0 !important;
        line-height: 0 !important;
    }

    body:not(.lockscreen) .dataTables_scrollBody {
        border-bottom: 0 !important;
    }

    body:not(.lockscreen) table.dataTable thead .sorting::after,
    body:not(.lockscreen) table.dataTable thead .sorting_asc::after,
    body:not(.lockscreen) table.dataTable thead .sorting_desc::after,
    body:not(.lockscreen) table.dataTable thead .sorting::before,
    body:not(.lockscreen) table.dataTable thead .sorting_asc::before,
    body:not(.lockscreen) table.dataTable thead .sorting_desc::before {
        color: color-mix(in srgb, var(--table-accent) 58%, var(--text-muted)) !important;
        opacity: 0.62 !important;
    }

    /* Empty data becomes a useful, intentional state. */
    body:not(.lockscreen) .dataTables_wrapper table.dataTable tbody td.dataTables_empty {
        padding: 2.5rem 1rem !important;
        color: var(--text-secondary);
        background: color-mix(in srgb, var(--surface-secondary) 50%, var(--surface));
        border: 1px dashed color-mix(in srgb, var(--table-accent) 24%, var(--border)) !important;
        border-radius: 0.9rem !important;
        font-size: 0.92rem;
        font-weight: 700;
        text-align: center;
    }

    body:not(.lockscreen) .dataTables_wrapper table.dataTable tbody td.dataTables_empty::before {
        content: "\f03a";
        display: grid;
        place-items: center;
        width: 2.85rem;
        height: 2.85rem;
        margin: 0 auto 0.65rem;
        color: var(--table-accent);
        background: color-mix(in srgb, var(--table-accent) 11%, var(--surface));
        border: 1px solid color-mix(in srgb, var(--table-accent) 17%, var(--border));
        border-radius: 0.85rem;
        font-family: "Font Awesome 5 Free", "FontAwesome";
        font-size: 1rem;
        font-weight: 900;
    }

    body:not(.lockscreen) .dataTables_wrapper table.dataTable tbody td.dataTables_empty::after {
        content: "Records will appear here as soon as they are available.";
        display: block;
        margin-top: 0.28rem;
        color: var(--text-muted);
        font-size: 0.74rem;
        font-weight: 500;
    }

    /* Footer / pagination */
    body:not(.lockscreen) .dataTables_wrapper .dataTables_info {
        float: left;
        display: inline-flex;
        align-items: center;
        min-height: 2.5rem;
        padding: 0 !important;
        color: var(--text-muted);
        font-size: 0.78rem;
        font-weight: 600;
    }

    body:not(.lockscreen) .dataTables_wrapper .dataTables_paginate {
        float: right;
        display: inline-flex;
        align-items: center;
        gap: 0.25rem;
        min-height: 2.5rem;
        padding: 0 !important;
    }

    body:not(.lockscreen) .dataTables_wrapper .dataTables_paginate > .paginate_button,
    body:not(.lockscreen) .dataTables_wrapper .pagination > li > a,
    body:not(.lockscreen) .dataTables_wrapper .pagination > li > span {
        min-width: 2.35rem;
        min-height: 2.35rem;
        margin: 0 0.12rem !important;
        padding: 0.52rem 0.75rem !important;
        color: var(--text-secondary) !important;
        background: var(--surface) !important;
        border: 1px solid var(--border) !important;
        border-radius: 0.65rem !important;
        box-shadow: none !important;
        font-size: 0.78rem;
        font-weight: 700;
        line-height: 1.2;
        transition: color 150ms ease, background 150ms ease, border-color 150ms ease, transform 150ms ease;
    }

    body:not(.lockscreen) .dataTables_wrapper .dataTables_paginate > .paginate_button:hover,
    body:not(.lockscreen) .dataTables_wrapper .pagination > li > a:hover {
        color: var(--table-accent) !important;
        background: color-mix(in srgb, var(--table-accent) 7%, var(--surface)) !important;
        border-color: color-mix(in srgb, var(--table-accent) 28%, var(--border)) !important;
        transform: translateY(-1px);
    }

    body:not(.lockscreen) .dataTables_wrapper .dataTables_paginate > .paginate_button.current,
    body:not(.lockscreen) .dataTables_wrapper .dataTables_paginate > .paginate_button.current:hover,
    body:not(.lockscreen) .dataTables_wrapper .pagination > .active > a,
    body:not(.lockscreen) .dataTables_wrapper .pagination > .active > span {
        color: #fff !important;
        background: linear-gradient(135deg, var(--table-accent), #4e7df5) !important;
        border-color: transparent !important;
        box-shadow: 0 7px 16px color-mix(in srgb, var(--table-accent) 22%, transparent) !important;
    }

    body:not(.lockscreen) .dataTables_wrapper .dataTables_paginate > .paginate_button.disabled,
    body:not(.lockscreen) .dataTables_wrapper .pagination > .disabled > a,
    body:not(.lockscreen) .dataTables_wrapper .pagination > .disabled > span {
        color: var(--text-muted) !important;
        background: color-mix(in srgb, var(--surface-secondary) 55%, var(--surface)) !important;
        border-color: color-mix(in srgb, var(--border) 72%, transparent) !important;
        opacity: 0.62;
        transform: none !important;
    }

    /* Dashboard data cards should remain compact when empty. */
    body:not(.lockscreen) .ds-dashboard-insights .dataTables_wrapper {
        box-shadow: none;
    }

    body:not(.lockscreen) .ds-dashboard-insights .dataTables_wrapper table.dataTable tbody td.dataTables_empty {
        padding-block: 2rem !important;
    }

    [data-theme="dark"] body:not(.lockscreen) .dataTables_wrapper {
        box-shadow: 0 18px 42px rgba(0, 0, 0, 0.22);
    }

    [data-theme="dark"] body:not(.lockscreen) .dataTables_wrapper .dataTables_filter input[type="search"] {
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.025);
    }
}

@media screen and (max-width: 767px) {
    body:not(.lockscreen) .dataTables_wrapper {
        padding: 0.82rem;
        border-radius: 0.95rem;
    }

    body:not(.lockscreen) .dataTables_wrapper .dataTables_length,
    body:not(.lockscreen) .dataTables_wrapper .dataTables_filter,
    body:not(.lockscreen) .dataTables_wrapper .dt-buttons {
        float: none;
        width: 100%;
        min-height: auto;
        margin: 0 0 0.7rem;
        justify-content: flex-start;
    }

    body:not(.lockscreen) .dataTables_wrapper .dataTables_filter label,
    body:not(.lockscreen) .dataTables_wrapper .dataTables_filter input[type="search"] {
        width: 100%;
    }

    body:not(.lockscreen) .dataTables_wrapper .dataTables_filter label::before {
        left: 1rem;
    }

    body:not(.lockscreen) .dataTables_wrapper .dt-buttons {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    body:not(.lockscreen) .dataTables_wrapper .dt-buttons .btn,
    body:not(.lockscreen) .dataTables_wrapper .dt-buttons a.btn,
    body:not(.lockscreen) .dataTables_wrapper .dt-button {
        width: 100%;
    }

    body:not(.lockscreen) table.table,
    body:not(.lockscreen) table.dataTable {
        min-width: 43rem;
    }

    body:not(.lockscreen) .dataTables_wrapper .dataTables_info,
    body:not(.lockscreen) .dataTables_wrapper .dataTables_paginate {
        float: none;
        width: 100%;
        justify-content: center;
        text-align: center;
    }

    body:not(.lockscreen) .dataTables_wrapper .dataTables_info {
        margin-bottom: 0.65rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    body:not(.lockscreen) .dataTables_wrapper *,
    body:not(.lockscreen) .dataTables_wrapper *::before,
    body:not(.lockscreen) .dataTables_wrapper *::after {
        transition: none !important;
    }
}
