/* ========================================
   Table Styles for A2GV2
   Theme-aware table customizations
   ======================================== */

/* CSS Layer - Table styles */
@layer theme-components {
    
    /* ========================================
       Grid Toolbar Layout
       ======================================== */

    .grid-toolbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.5rem 0;
        margin-bottom: 0.25rem;
        gap: 1rem;
    }

    .grid-toolbar-left {
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .grid-toolbar-center {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .grid-toolbar-right {
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    /* Total count badge */
    .grid-total-count {
        font-size: 0.85rem;
        color: var(--text-secondary);
        background-color: var(--bg-tertiary);
        padding: 0.25rem 0.6rem;
        border-radius: var(--bs-border-radius);
        font-weight: 500;
        white-space: nowrap;
    }

    /* ========================================
       Data Grid Table Styling
       ======================================== */

    .data-grid-container {
        border: 1px solid var(--border-color);
        border-radius: var(--bs-border-radius);
        overflow: hidden;
    }

    .data-grid {
        margin-bottom: 0;
        font-size: 0.875rem;
    }

    /* Header row styling - cohesive bar, no gaps */
    .data-grid thead tr:first-child th {
        background-color: var(--bg-header) !important;
        color: var(--text-header) !important;
        font-weight: 500;
        padding: 0.35rem 0.75rem;
        border: none;
        border-bottom: 1px solid var(--primary-light);
        font-size: 0.85rem;
        text-transform: none;
        letter-spacing: 0;
        white-space: nowrap;
        vertical-align: middle;
        cursor: pointer;
        line-height: 1.5;
        border-radius: 0;
    }

    .data-grid thead tr:first-child th:hover {
        background-color: var(--primary-light) !important;
    }

    /* Sort arrow styling - far right */
    .data-grid thead tr:first-child th span.ph,
    .data-grid thead tr:first-child th .sort-arrow,
    .data-grid thead tr:first-child th .sort-icon {
        float: right;
        margin-left: 0.5rem;
        font-size: 0.85rem;
        color: var(--text-header);
        background-color: rgba(255, 255, 255, 0.25);
        padding: 0.1rem 0.25rem;
        border-radius: 3px;
    }

    /* Active sort column highlighting */
    .data-grid thead tr:first-child th[asc-desc],
    .data-grid thead tr:first-child th.sorting {
        background-color: var(--primary-light) !important;
    }

    .data-grid thead tr:first-child th[asc-desc] span.ph,
    .data-grid thead tr:first-child th.sorting span.ph,
    .data-grid thead tr:first-child th.sorting .sort-arrow {
        color: var(--text-header);
    }

    /* Filter row styling */
    .data-grid thead tr:nth-child(2) th {
        background-color: var(--bg-tertiary);
        padding: 0.2rem 0.4rem;
        border-bottom: 1px solid var(--border-color);
    }

    .data-grid thead tr:nth-child(2) th .form-control,
    .data-grid thead tr:nth-child(2) th .form-select {
        font-size: 0.8rem;
        padding: 0.2rem 0.4rem;
        height: auto;
        border-color: var(--border-color);
    }

    .data-grid thead tr:nth-child(2) th .form-control:focus,
    .data-grid thead tr:nth-child(2) th .form-select:focus {
        border-color: var(--bs-primary);
        box-shadow: 0 0 0 0.15rem rgba(var(--bs-primary-rgb), 0.15);
    }

    /* Filter button in header */
    .data-grid thead tr:nth-child(2) th .btn-filter-date {
        font-size: 0.75rem;
        padding: 0.2rem 0.4rem;
        width: 100%;
        background-color: var(--bg-primary);
        border-color: var(--border-color);
        color: var(--text-secondary);
    }

    .data-grid thead tr:nth-child(2) th .btn-filter-date:hover {
        background-color: var(--bg-tertiary);
        border-color: var(--bs-primary);
    }

    /* Body cell styling */
    .data-grid tbody td {
        padding: 0.4rem 0.6rem;
        vertical-align: middle;
        border-bottom: 1px solid var(--border-light);
        color: var(--text-primary);
    }

    .data-grid tbody tr:hover {
        background-color: rgba(var(--bs-primary-rgb), 0.04);
    }

    .data-grid tbody tr:last-child td {
        border-bottom: none;
    }

    /* ========================================
       Empty State
       ======================================== */

    .grid-empty-state {
        text-align: center;
        padding: 2rem;
        color: var(--text-muted);
    }

    .grid-empty-state i {
        font-size: 2.5rem;
        margin-bottom: 0.75rem;
        opacity: 0.5;
    }

    .grid-empty-state p {
        margin: 0;
        font-size: 0.9rem;
    }
}

/* ========================================
   Override Bootstrap table styles for data-grid
   These need to be outside @layer for higher specificity
   ======================================== */

.table.data-grid thead tr:first-child th,
table.data-grid thead tr:first-child th {
    background-color: var(--bg-header) !important;
    color: var(--text-header) !important;
    font-weight: 500;
    padding: 0.35rem 0.75rem !important;
    border: none !important;
    border-bottom: 1px solid var(--primary-light) !important;
    font-size: 0.85rem;
    line-height: 1.5;
    white-space: nowrap;
    vertical-align: middle;
    border-radius: 0 !important;
}

.table.data-grid thead tr:first-child th:hover,
table.data-grid thead tr:first-child th:hover {
    background-color: var(--primary-light) !important;
}

.table.data-grid thead tr:first-child th span.ph,
table.data-grid thead tr:first-child th span.ph,
.table.data-grid thead tr:first-child th .sort-arrow,
table.data-grid thead tr:first-child th .sort-arrow,
.table.data-grid thead tr:first-child th .sort-icon,
table.data-grid thead tr:first-child th .sort-icon {
    float: right;
    margin-left: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-header);
    background-color: rgba(255, 255, 255, 0.25);
    padding: 0.1rem 0.25rem;
    border-radius: 3px;
}

.table.data-grid thead tr:first-child th[asc-desc],
table.data-grid thead tr:first-child th[asc-desc],
.table.data-grid thead tr:first-child th.sorting,
table.data-grid thead tr:first-child th.sorting {
    background-color: var(--primary-light) !important;
}

/* Filter row override for Bootstrap tables */
.table.data-grid thead tr:nth-child(2) th,
table.data-grid thead tr:nth-child(2) th {
    background-color: var(--bg-tertiary) !important;
    padding: 0.2rem 0.4rem !important;
}

/* ========================================
   Grid Toolbar Button Styling
   ======================================== */

/* Clear button - darker charcoal */
.grid-toolbar .btn-theme-secondary {
    background-color: var(--bg-header) !important;
    border-color: var(--bg-header) !important;
    color: var(--text-header) !important;
}

.grid-toolbar .btn-theme-secondary:hover {
    filter: brightness(0.85);
}

/* Active/Inactive/Deleted btn-group - darker selected state */
.grid-toolbar .btn-group .btn-check:checked + .btn-outline-secondary,
.grid-toolbar .btn-group .btn-outline-secondary.active {
    background-color: var(--bg-header) !important;
    border-color: var(--bg-header) !important;
    color: var(--text-header) !important;
}

.grid-toolbar .btn-group .btn-outline-secondary {
    border-color: var(--border-color);
    color: var(--text-primary);
}

.grid-toolbar .btn-group .btn-outline-secondary:hover {
    background-color: var(--bg-tertiary);
    border-color: var(--border-color);
}

/* ========================================
   Find Client results grid in modal
   ======================================== */
.find-client-results-container {
    max-height: min(58vh, 520px);
    overflow: auto;
    background-color: var(--bg-primary);
}

.find-client-grid {
    width: max-content;
    min-width: 100%;
}

.find-client-results-header,
.find-client-result-row {
    display: grid;
    grid-template-columns: var(--find-client-grid-template, minmax(10rem, 2fr) minmax(12rem, 2.5fr) minmax(7rem, 1.2fr) minmax(12rem, 2.5fr));
    align-items: center;
    column-gap: 0.75rem;
    width: 100%;
    box-sizing: border-box;
}

.find-client-results-header {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--primary-light);
    background-color: var(--bg-header);
    color: var(--text-header);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.01em;
}

.find-client-header-button {
    border: none;
    background: transparent;
    color: inherit;
    padding: 0;
    margin: 0;
    text-align: left;
    font: inherit;
    font-size: inherit;
    font-weight: inherit;
    text-transform: inherit;
    letter-spacing: inherit;
    cursor: pointer;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.find-client-header-button:hover,
.find-client-header-button:focus-visible {
    text-decoration: underline;
}

.find-client-results-body {
    display: block;
    width: 100%;
}

.find-client-result-row {
    width: 100%;
    padding: 0.45rem 0.75rem;
    border: none;
    border-bottom: 1px solid var(--border-light);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    text-align: left;
}

.find-client-result-row:hover,
.find-client-result-row:focus-visible {
    background-color: rgba(var(--bs-primary-rgb), 0.08);
}

.find-client-result-row.active {
    background-color: var(--bg-header);
    color: var(--text-header);
}

.find-client-result-row.active .find-client-cell {
    color: inherit;
}

.find-client-cell {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.find-client-col-name {
    font-weight: 600;
}

@media (max-width: 992px) {
    .find-client-results-header,
    .find-client-result-row {
        column-gap: 0.6rem;
    }
}

@media (max-width: 768px) {
    .find-client-results-container {
        max-height: min(55vh, 460px);
    }

    .find-client-results-header,
    .find-client-result-row {
        column-gap: 0.5rem;
    }

    .find-client-results-header {
        padding: 0.45rem 0.6rem;
        font-size: 0.75rem;
    }

    .find-client-result-row {
        padding: 0.4rem 0.6rem;
    }
}
