/* Global PowerGrid / Tabler datatable fixes for ALL modules */

.table-responsive {
    max-width: 100%;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
}

.table.datatable,
.card-table > .table,
table.table.datatable {
    width: 100% !important;
    min-width: 100% !important;
    table-layout: auto !important;
    border-collapse: separate;
    border-spacing: 0;
}

/* Override legacy `table thead { text-transform:uppercase; font-size:.75rem }` from app.min.css */
.table.datatable thead,
.card-table > .table > thead,
table.table.datatable thead {
    color: var(--tblr-secondary, #626976) !important;
    font-size: 0.8125rem !important;
    text-transform: none !important;
}

.table.datatable th,
.card-table > .table > thead > tr > th,
table.table.datatable thead th,
.table.datatable td,
.card-table > .table > tbody > tr > td,
table.table.datatable tbody td {
    padding: 0.7rem 1rem !important;
    vertical-align: middle !important;
    border-right: none !important;
    box-sizing: border-box;
    white-space: normal !important;
}

.table.datatable th,
.card-table > .table > thead > tr > th,
table.table.datatable thead th {
    font-weight: 600 !important;
    font-size: 0.8125rem !important;
    letter-spacing: 0.01em;
    text-transform: none !important;
    color: var(--tblr-secondary, #626976) !important;
    background-color: var(--tblr-bg-surface, #fff);
    white-space: nowrap !important;
}

.table.datatable thead th:not(.w-1):not([data-column='id']):not([data-column='checkbox']),
.card-table > .table > thead > tr > th:not(.w-1):not([data-column='id']) {
    min-width: 7.5rem;
}

.table.datatable td,
.card-table > .table > tbody > tr > td,
table.table.datatable tbody td {
    font-size: 0.875rem;
}

/* Compact utility / checkbox / detail columns */
.table.datatable th.w-1,
.table.datatable td.w-1,
.table.datatable th[data-column='checkbox'],
.table.datatable td[data-column='checkbox'],
.table.datatable thead th:has(input[type='checkbox']),
.table.datatable tbody td:has(input[type='checkbox']) {
    width: 2.75rem !important;
    min-width: 2.75rem !important;
    max-width: 2.75rem !important;
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
}

.table.datatable th[data-column='details'],
.table.datatable td[data-column='details'] {
    width: 2.75rem !important;
    min-width: 2.75rem !important;
    max-width: 2.75rem !important;
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
    text-align: center !important;
}

.table.datatable th[data-column='checkbox'],
.table.datatable td[data-column='checkbox'] {
    border-right: 1px solid var(--tblr-border-color, #e6e7e9) !important;
}

.table.datatable th[data-column='id'],
.table.datatable td[data-column='id'] {
    border-left: 1px solid var(--tblr-border-color, #e6e7e9) !important;
    white-space: nowrap !important;
}

.pg-header-top {
    background: var(--tblr-bg-surface, #fff);
}

@media (min-width: 992px) {
    /* Constrain width/wrap without clipping dropdown menus */
    .navbar > .container-xl > .navbar-nav:not(.order-md-last) {
        min-width: 0;
        width: 100%;
        max-width: 100%;
        flex-wrap: wrap;
        overflow: visible;
    }

    .navbar > .container-xl > .navbar-nav:not(.order-md-last) > .nav-item.dropdown > .dropdown-menu {
        z-index: 1050;
    }
}

.quote-detail-actions > * {
    margin: 0 !important;
}

.quote-profile-summary-main {
    flex: 2 1 16rem;
    min-width: 0;
    overflow-wrap: anywhere;
}

.quote-profile-summary-company {
    flex: 1 1 14rem;
    min-width: 0;
    overflow-wrap: anywhere;
}

.quote-profile-information .datagrid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
}

.quote-detail-totals {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr));
    gap: 0.5rem;
    margin-left: 0;
    margin-right: 0;
}

.quote-detail-totals > [class*="col"] {
    width: auto;
    padding: 0;
    margin-bottom: 0 !important;
}

.quote-detail-totals .card-body {
    padding: 0.5rem 0.75rem;
}

body.quote-detail-expanded {
    overflow: hidden !important;
}

.quote-detail-panel {
    --quote-index-width: 4rem;
    --quote-name-width: clamp(12rem, 20vw, 16rem);
    min-width: 0;
}

.quote-detail-panel-expanded {
    position: fixed;
    inset: 0.5rem;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    background: var(--tblr-bg-surface, #fff);
    border: 1px solid var(--tblr-border-color, #dce1e7);
    border-radius: 0.5rem;
    box-shadow: 0 0 0 0.5rem var(--tblr-bg-surface, #fff);
}

.quote-detail-panel-expanded .quote-detail-toolbar,
.quote-detail-panel-expanded .quote-detail-actions {
    flex-shrink: 0;
}

.quote-detail-panel-expanded .quote-detail-totals {
    display: none;
}

.quote-detail-panel-expanded .quote-detail-table {
    flex: 1;
    min-height: 0;
    max-height: none;
}

.quote-detail-table {
    max-width: 100%;
    max-height: calc(100dvh - 10rem);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.quote-detail-table > table {
    min-width: 1100px;
    border-collapse: separate;
    border-spacing: 0;
    margin-bottom: 0;
}

.quote-detail-table > table > tbody > tr > td {
    white-space: nowrap;
}

.quote-detail-table > table > thead > tr > th {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--tblr-bg-surface, #fff);
}

.quote-detail-table > table > thead > tr > th:first-child,
.quote-detail-table > table > tbody > tr > :first-child {
    position: sticky;
    left: 0;
    z-index: 4;
    width: var(--quote-index-width);
    min-width: var(--quote-index-width);
    max-width: var(--quote-index-width);
    background: var(--tblr-bg-surface, #fff);
}

.quote-detail-table > table > thead > tr > th:nth-child(2),
.quote-detail-table > table > tbody > tr > :nth-child(2):not([colspan]) {
    position: sticky;
    left: var(--quote-index-width);
    z-index: 4;
    width: var(--quote-name-width);
    min-width: var(--quote-name-width);
    max-width: var(--quote-name-width);
    white-space: normal;
    overflow-wrap: anywhere;
    background: var(--tblr-bg-surface, #fff);
    box-shadow: 0.5rem 0 0.75rem -0.75rem rgba(31, 41, 55, 0.55);
}

.quote-detail-table > table > thead > tr > th:first-child,
.quote-detail-table > table > thead > tr > th:nth-child(2) {
    z-index: 7;
}

.quote-detail-table > table > tbody > tr:nth-of-type(odd):not(.table-primary) > :first-child,
.quote-detail-table > table > tbody > tr:nth-of-type(odd):not(.table-primary) > :nth-child(2):not([colspan]) {
    background: var(--tblr-bg-surface-secondary, #f6f8fb);
}

.quote-detail-table > table > tbody > tr.table-primary > :first-child,
.quote-detail-table .table-primary > .quote-detail-group-label {
    background: var(--tblr-primary-lt, #dbeafe);
}

/* The bundled UI stylesheet also freezes the second cell. A group cell spans
   several columns, so freezing it would cover the separate action button. */
.quote-detail-table > table > tbody > tr > .quote-detail-group-label[colspan] {
    position: static;
    left: auto;
    z-index: auto;
    width: auto;
    min-width: 0;
    max-width: none;
    box-shadow: none;
}

.quote-detail-group-label > b {
    position: sticky;
    left: calc(var(--quote-index-width) + 0.75rem);
    display: inline-block;
    white-space: normal;
}

.quote-detail-table > table > tbody > tr > .quote-detail-note {
    white-space: normal;
    min-width: 8rem;
    max-width: 16rem;
    overflow-wrap: anywhere;
}

.table.datatable th[data-column='id'],
.table.datatable td[data-column='id'] {
    width: 4rem !important;
    min-width: 4rem !important;
    max-width: 5rem !important;
}

.table.datatable th[data-column='actions'],
.table.datatable td[data-column='actions'] {
    min-width: 8rem !important;
}

.table.datatable td[data-column='actions'] .pg-actions,
.table.datatable td[data-column='actions'] [x-data*='pgRenderActions'] {
    width: 100%;
    min-width: 0;
}

/* Keep selection and identity columns visible while a wide table scrolls. */
.table.datatable th.w-1:first-child,
.table.datatable td.w-1:first-child {
    position: sticky;
    left: 0;
    background-color: var(--tblr-bg-surface, #fff) !important;
    z-index: 4;
    box-shadow: 0.375rem 0 0.75rem -0.75rem rgba(31, 41, 55, 0.65);
}

.table.datatable th:has(input[type='checkbox']),
.table.datatable td:has(input[type='checkbox']) {
    position: sticky;
    left: 2.75rem;
    background-color: var(--tblr-bg-surface, #fff) !important;
    z-index: 4;
}

.table.datatable th:has(input[type='checkbox']) .form-check,
.table.datatable td:has(input[type='checkbox']) .form-check {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-left: 0;
    margin-bottom: 0;
}

.table.datatable th:has(input[type='checkbox']) .form-check-input,
.table.datatable td:has(input[type='checkbox']) .form-check-input {
    position: relative !important;
    inset: auto !important;
    margin: 0 !important;
}

.table.datatable th[data-column='id'],
.table.datatable td[data-column='id'] {
    position: sticky;
    left: 2.75rem;
    background-color: var(--tblr-bg-surface, #fff) !important;
    z-index: 3;
    border-left: 1px solid var(--tblr-border-color, #e6e7e9) !important;
}

.table.datatable:has(th.w-1 + th.w-1) th[data-column='id'],
.table.datatable:has(th.w-1 + th.w-1) td[data-column='id'] {
    left: 5.5rem;
}

/* Readable widths for common text columns across modules */
.table.datatable th[data-column='name'],
.table.datatable td[data-column='name'],
.table.datatable th[data-column='title'],
.table.datatable td[data-column='title'],
.table.datatable th[data-column='company'],
.table.datatable td[data-column='company'],
.table.datatable th[data-column='company_name'],
.table.datatable td[data-column='company_name'],
.table.datatable th[data-column='company_names'],
.table.datatable td[data-column='company_names'],
.table.datatable th[data-column='full_name'],
.table.datatable td[data-column='full_name'],
.table.datatable th[data-column='contact_name'],
.table.datatable td[data-column='contact_name'],
.table.datatable th[data-column='contract_type'],
.table.datatable td[data-column='contract_type'],
.table.datatable th[data-column='address'],
.table.datatable td[data-column='address'],
.table.datatable th[data-column='note'],
.table.datatable td[data-column='note'],
.table.datatable th[data-column='content'],
.table.datatable td[data-column='content'],
.table.datatable th[data-column='code'],
.table.datatable td[data-column='code'] {
    min-width: 14rem !important;
    max-width: 22rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

.table.datatable th > div,
.table.datatable th .d-flex {
    display: inline-flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
    flex-wrap: nowrap !important;
    max-width: none !important;
}

.table.datatable th > div > span[data-value],
.table.datatable th span[data-value] {
    display: inline-block;
    white-space: nowrap !important;
    overflow: visible !important;
    text-overflow: unset !important;
    max-width: none !important;
    text-transform: none !important;
}

.table.datatable thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    box-shadow: inset 0 -1px 0 var(--tblr-border-color, #e6e7e9);
}

[data-bs-theme='dark'] .table.datatable thead th {
    background-color: var(--tblr-bg-surface, #1e293b);
}

.table.datatable tbody tr:hover > * {
    background-color: rgba(var(--tblr-primary-rgb, 32, 107, 196), 0.04);
}

.datatable-hide-on-desktop {
    display: flex;
}

@media (min-width: 768px) {
    .datatable-hide-on-desktop {
        display: none !important;
    }
}

.datatable-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 2rem 1rem;
    color: var(--tblr-secondary, #626976);
}

.datatable-empty-state .datatable-empty-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--tblr-body-color, #1e293b);
}

.datatable-empty-state .datatable-empty-hint {
    font-size: 0.8125rem;
    max-width: 28rem;
}

.datatable-view-toggle {
    padding: 0 0.25rem;
}

.card-table .table.datatable tbody td[data-column='actions'] .d-flex,
.card-table .table.datatable tbody td[data-column='actions'] > div {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.35rem;
}

/* Collapsible filter sidebars — default to full-width table */
.crm-list-layout .crm-list-main {
    min-width: 0;
}

.crm-list-layout[data-filter-open='false'] > .crm-list-filter {
    display: none !important;
}

.crm-list-layout[data-filter-open='false'] > .crm-list-main {
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 100% !important;
}

.crm-filter-toggle {
    margin-bottom: 0.75rem;
}

/* Datatable toolbar buttons (export / toggle columns) — were unstyled because tabler.css was never loaded */
.pg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    min-height: 2.25rem;
    padding: 0.5625rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1;
    border-radius: 0.375rem;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    text-decoration: none;
    appearance: none;
    -webkit-appearance: none;
    background-image: none;
}

.pg-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.pg-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pg-btn-outline {
    background-color: var(--tblr-bg-surface, #fff);
    border-color: var(--tblr-border-color, #d9dbde);
    color: var(--tblr-body-color, #1e293b);
}

.pg-btn-outline:hover:not(:disabled) {
    background-color: var(--tblr-bg-surface-secondary, #f8fafc);
    border-color: var(--tblr-border-color-active, #b8bcc3);
}

.pg-btn-outline:active:not(:disabled) {
    background-color: var(--tblr-bg-muted, #f1f5f9);
}

.pg-btn-primary {
    background-color: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

.pg-btn-primary:hover:not(:disabled) {
    background-color: #1d4ed8;
    border-color: #1d4ed8;
}

.pg-dropdown-menu {
    min-width: 180px;
    padding: 0.375rem;
    border: 1px solid var(--tblr-border-color, #d9dbde);
    border-radius: 0.5rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
    background-color: var(--tblr-bg-surface, #fff);
}

.pg-dropdown-header {
    padding: 0.5rem 0.75rem 0.375rem;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--tblr-muted, #64748b);
}

.pg-dropdown-divider {
    height: 0;
    margin: 0.375rem 0;
    border-top: 1px solid var(--tblr-border-color, #e2e8f0);
}

.pg-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    color: var(--tblr-body-color, #1e293b);
    text-decoration: none;
    border-radius: 0.375rem;
    cursor: pointer;
}

.pg-dropdown-item:hover {
    background-color: var(--tblr-bg-surface-secondary, #f8fafc);
    color: var(--tblr-body-color, #1e293b);
    text-decoration: none;
}

.pg-dropdown-item.disabled {
    opacity: 0.5;
    pointer-events: none;
}

.pg-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.125rem;
    padding: 0 0.375rem;
    margin-left: auto;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--tblr-muted, #64748b);
    background-color: var(--tblr-bg-muted, #f1f5f9);
    border-radius: 0.25rem;
}

.pg-columns-menu {
    min-width: 220px;
    max-width: 280px;
    padding: 0;
    border: 1px solid var(--tblr-border-color, #e2e8f0);
    border-radius: 0.625rem;
    box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.05);
    background-color: var(--tblr-bg-surface, #fff);
    overflow: hidden;
}

.pg-columns-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--tblr-border-color, #e2e8f0);
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--tblr-body-color, #1e293b);
}

.pg-columns-list {
    padding: 0.375rem;
    max-height: 320px;
    overflow-y: auto;
}

.pg-column-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.5rem 0.625rem;
    border-radius: 0.375rem;
    cursor: pointer;
}

.pg-column-item:hover {
    background-color: var(--tblr-bg-surface-secondary, #f8fafc);
}

.pg-column-name {
    flex: 1;
    font-size: 0.8125rem;
    color: var(--tblr-body-color, #1e293b);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pg-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 2.25rem;
    height: 1.25rem;
    padding: 0;
    border: none;
    border-radius: 0.625rem;
    background-color: var(--tblr-border-color, #d1d5db);
    cursor: pointer;
    flex-shrink: 0;
}

.pg-switch-thumb {
    position: absolute;
    left: 2px;
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    background-color: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease;
}

.pg-switch.active {
    background-color: var(--tblr-primary, #2563eb);
}

.pg-switch.active .pg-switch-thumb {
    transform: translateX(1rem);
}

[data-bs-theme='dark'] .pg-btn-outline {
    background-color: var(--tblr-bg-surface, #1e293b);
    border-color: var(--tblr-border-color, #334155);
    color: var(--tblr-body-color, #e2e8f0);
}

/* Keep generated row actions compact, aligned and keyboard-accessible. */
.pg-actions [x-data^='pgRenderActions'] {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.25rem;
}

.pg-actions .btn-sm:has(> svg),
.pg-actions .btn-sm:has(> .tooltip-wrapper) {
    width: var(--crm-control-height-compact, 2rem);
    height: var(--crm-control-height-compact, 2rem);
    min-height: var(--crm-control-height-compact, 2rem);
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.pg-actions .btn-sm .tooltip-wrapper,
.pg-actions .btn-sm .tooltip-wrapper > svg,
.pg-actions .btn-sm > svg {
    width: 1rem;
    height: 1rem;
}

.pg-actions .btn-sm {
    height: var(--crm-control-height-compact, 2rem) !important;
    min-height: var(--crm-control-height-compact, 2rem) !important;
    padding-top: 0.3125rem !important;
    padding-bottom: 0.3125rem !important;
    line-height: 1.25rem !important;
}

/* Quote actions keep a short visible label so their purpose is clear without hover. */
.pg-actions .quote-action-btn {
    width: auto !important;
    min-width: 0 !important;
    padding: 0.3125rem 0.5rem !important;
    gap: 0.3rem;
    white-space: nowrap;
}

.pg-actions .quote-action-btn .quote-action-icon,
.pg-actions .quote-action-btn .quote-action-icon > svg {
    width: 1rem;
    height: 1rem;
    flex: 0 0 auto;
}
