/*
 |--------------------------------------------------------------------------
 | KPF - Backpack/Tabler modern list table skin
 |--------------------------------------------------------------------------
 | Visual-only layer for Backpack ListOperation/DataTables.
 | It keeps the real table, filters, pagination, ordering and Backpack JS.
 |
 | Load after Backpack/DataTables CSS.
 | Real selectors used by this project:
 | - body[bp-layout]
 | - #crudTable
 | - #crudTable_wrapper
 | - #datatable_search_stack
 | - #datatable_info_stack
 | - html[data-bs-theme="dark"]
 */

:root {
    --kpf-list-bg: #ffffff;
    --kpf-list-soft: #f8fafc;
    --kpf-list-soft-2: #f1f5f9;
    --kpf-list-border: rgba(15, 23, 42, .075);
    --kpf-list-border-strong: rgba(15, 23, 42, .12);
    --kpf-list-text: #201827;
    --kpf-list-muted: #7b7285;
    --kpf-list-heading: #4d4358;
    --kpf-list-primary: #ef1d14;
    --kpf-list-primary-dark: #d51b11;
    --kpf-list-primary-soft: rgba(239, 29, 20, .075);
    --kpf-list-radius: 18px;
    --kpf-list-shadow: 0 18px 45px rgba(15, 23, 42, .055);
}

html[data-bs-theme="dark"] {
    --kpf-list-bg: #231b28;
    --kpf-list-soft: #2a2130;
    --kpf-list-soft-2: #312738;
    --kpf-list-border: rgba(255, 255, 255, .08);
    --kpf-list-border-strong: rgba(255, 255, 255, .14);
    --kpf-list-text: #f8fafc;
    --kpf-list-muted: #b8aebf;
    --kpf-list-heading: #f3edf7;
    --kpf-list-primary-soft: rgba(239, 29, 20, .16);
    --kpf-list-shadow: 0 18px 45px rgba(0, 0, 0, .20);
}

/* --------------------------------------------------------------------------
   Backpack/DataTables layout wrappers
-------------------------------------------------------------------------- */

body[bp-layout] #crudTable_wrapper {
    color: var(--kpf-list-text);
}

body[bp-layout] #crudTable_wrapper .row,
body[bp-layout] #crudTable_wrapper .dataTables_scroll,
body[bp-layout] #crudTable_wrapper .dataTables_scrollBody {
    max-width: 100%;
}

body[bp-layout] #crudTable_wrapper .dataTables_scrollBody {
    border: 0 !important;
}

body[bp-layout] #crudTable_wrapper .dataTables_info,
body[bp-layout] #datatable_info_stack {
    color: var(--kpf-list-muted) !important;
    font-size: .875rem;
    font-weight: 500;
}

body[bp-layout] #datatable_info_stack strong,
body[bp-layout] #datatable_info_stack b {
    color: var(--kpf-list-heading);
    font-weight: 800;
}

/* --------------------------------------------------------------------------
   Search / length controls
-------------------------------------------------------------------------- */

body[bp-layout] #datatable_search_stack .input-icon {
    width: min(100%, 520px);
}

body[bp-layout] #datatable_search_stack .input-icon input,
body[bp-layout] #crudTable_wrapper .dataTables_filter input,
body[bp-layout] #crudTable_filter input {
    height: 46px !important;
    border-radius: 14px !important;
    border: 1px solid var(--kpf-list-border-strong) !important;
    background: var(--kpf-list-bg) !important;
    color: var(--kpf-list-text) !important;
    box-shadow: 0 10px 24px rgba(15, 23, 42, .05) !important;
    padding-left: 42px !important;
    transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

body[bp-layout] #datatable_search_stack .input-icon input:focus,
body[bp-layout] #crudTable_wrapper .dataTables_filter input:focus,
body[bp-layout] #crudTable_filter input:focus {
    border-color: rgba(239, 29, 20, .35) !important;
    box-shadow: 0 0 0 4px rgba(239, 29, 20, .085), 0 12px 28px rgba(15, 23, 42, .08) !important;
}

body[bp-layout] #crudTable_wrapper .dataTables_length select {
    min-width: 86px;
    height: 44px !important;
    border-radius: 12px !important;
    border: 1px solid var(--kpf-list-border) !important;
    background-color: var(--kpf-list-bg) !important;
    color: var(--kpf-list-text) !important;
    box-shadow: 0 8px 18px rgba(15, 23, 42, .04) !important;
}

body[bp-layout] #crudTable_wrapper .dataTables_length label {
    color: var(--kpf-list-muted);
    font-size: .875rem;
    font-weight: 500;
}

/* --------------------------------------------------------------------------
   Table: real Backpack ListOperation table
-------------------------------------------------------------------------- */

body[bp-layout] #crudTable {
    width: 100% !important;
    margin: 0 !important;
    border: 1px solid var(--kpf-list-border) !important;
    border-radius: var(--kpf-list-radius) !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    overflow: hidden !important;
    background: var(--kpf-list-bg) !important;
    box-shadow: var(--kpf-list-shadow) !important;
}

body[bp-layout] #crudTable thead th {
    position: relative;
    background: var(--kpf-list-soft) !important;
    color: var(--kpf-list-heading) !important;
    border-top: 0 !important;
    border-bottom: 1px solid var(--kpf-list-border) !important;
    padding: 16px 18px !important;
    font-size: .735rem !important;
    font-weight: 800 !important;
    letter-spacing: .055em !important;
    text-transform: uppercase !important;
    vertical-align: middle !important;
    white-space: nowrap;
}

body[bp-layout] #crudTable thead th:first-child {
    border-top-left-radius: var(--kpf-list-radius) !important;
}

body[bp-layout] #crudTable thead th:last-child {
    border-top-right-radius: var(--kpf-list-radius) !important;
}

body[bp-layout] #crudTable tbody tr {
    background: var(--kpf-list-bg) !important;
    transition: background .16s ease, transform .16s ease;
}

body[bp-layout] #crudTable tbody td {
    background: transparent !important;
    color: var(--kpf-list-text) !important;
    border-top: 0 !important;
    border-bottom: 1px solid var(--kpf-list-border) !important;
    padding: 18px !important;
    font-size: .94rem !important;
    line-height: 1.35 !important;
    vertical-align: middle !important;
}

body[bp-layout] #crudTable tbody tr:last-child td {
    border-bottom: 0 !important;
}

body[bp-layout] #crudTable tbody tr:hover > * {
    background: linear-gradient(90deg, rgba(239, 29, 20, .055), rgba(255, 255, 255, 0)) !important;
}

html[data-bs-theme="dark"] body[bp-layout] #crudTable tbody tr:hover > * {
    background: linear-gradient(90deg, rgba(239, 29, 20, .14), rgba(255, 255, 255, 0)) !important;
}

/* Remove old heavy table/striped feeling while preserving table behavior */
body[bp-layout] #crudTable.table-striped tbody tr:nth-of-type(odd),
body[bp-layout] #crudTable.table-striped tbody tr:nth-of-type(even) {
    background-color: var(--kpf-list-bg) !important;
}

body[bp-layout] #crudTable.table-hover tbody tr:hover {
    background-color: transparent !important;
}

/* Optional footer duplicated by DataTables/Backpack: keep hidden for cleaner list UI */
body[bp-layout] #crudTable tfoot {
    display: none !important;
}

/* --------------------------------------------------------------------------
   Content polish inside cells
-------------------------------------------------------------------------- */

body[bp-layout] #crudTable tbody td a:not(.btn):not(.dropdown-item) {
    color: var(--kpf-list-primary) !important;
    font-weight: 700;
    text-decoration: none !important;
}

body[bp-layout] #crudTable tbody td a:not(.btn):not(.dropdown-item):hover {
    color: var(--kpf-list-primary-dark) !important;
    text-decoration: underline !important;
    text-underline-offset: 3px;
}

body[bp-layout] #crudTable .badge,
body[bp-layout] #crudTable .label {
    border-radius: 999px !important;
    padding: .38rem .62rem !important;
    font-weight: 800 !important;
    letter-spacing: .01em;
}

body[bp-layout] #crudTable .btn,
body[bp-layout] #crudTable .btn-sm {
    border-radius: 10px !important;
    font-weight: 700 !important;
}

body[bp-layout] #crudTable td:last-child,
body[bp-layout] #crudTable th:last-child {
    text-align: right;
}

body[bp-layout] #crudTable td.dataTables_empty {
    text-align: center !important;
}

body[bp-layout] #crudTable td:last-child a,
body[bp-layout] #crudTable td:last-child button {
    margin-left: .35rem;
}

body[bp-layout] #crudTable img {
    border-radius: 12px;
    object-fit: cover;
}

/* --------------------------------------------------------------------------
   Solicitações: fila de atendimento mantendo tabela do Backpack
-------------------------------------------------------------------------- */

body[bp-layout] .kpf-solicitation-summary {
    min-width: 220px;
}

body[bp-layout] .kpf-solicitation-title {
    color: var(--tblr-body-color);
    font-size: .92rem;
    font-weight: 850;
    line-height: 1.25;
}

body[bp-layout] .kpf-solicitation-subtitle {
    display: flex;
    flex-wrap: wrap;
    gap: .3rem .55rem;
    margin-top: .22rem;
    color: var(--tblr-secondary-color);
    font-size: .76rem;
    font-weight: 650;
}

body[bp-layout] .kpf-solicitation-subtitle span + span::before {
    content: "";
    display: inline-block;
    width: 4px;
    height: 4px;
    margin-right: .55rem;
    border-radius: 999px;
    background: currentColor;
    opacity: .38;
    vertical-align: middle;
}

body[bp-layout] .kpf-solicitation-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    padding: .34rem .68rem;
    border-radius: 999px;
    border: 1px solid transparent;
    font-size: .74rem;
    font-weight: 850;
    line-height: 1;
    white-space: nowrap;
}

body[bp-layout] .kpf-solicitation-status.is-open {
    color: #b45309;
    background: rgba(245, 158, 11, .13);
    border-color: rgba(245, 158, 11, .26);
}

body[bp-layout] .kpf-solicitation-status.is-progress {
    color: #1d4ed8;
    background: rgba(59, 130, 246, .12);
    border-color: rgba(59, 130, 246, .22);
}

body[bp-layout] .kpf-solicitation-status.is-done {
    color: #047857;
    background: rgba(16, 185, 129, .12);
    border-color: rgba(16, 185, 129, .24);
}

body[bp-layout] .kpf-solicitation-status.is-cancelled,
body[bp-layout] .kpf-solicitation-status.is-neutral {
    color: #64748b;
    background: rgba(100, 116, 139, .10);
    border-color: rgba(100, 116, 139, .18);
}

body[bp-layout] .kpf-solicitation-flow.is-provider {
    color: #9a3412;
    background: rgba(249, 115, 22, .10);
    border-color: rgba(249, 115, 22, .20);
}

body[bp-layout] .kpf-solicitation-flow.is-platform {
    color: #6d28d9;
    background: rgba(124, 58, 237, .10);
    border-color: rgba(124, 58, 237, .20);
}

body[bp-layout] .kpf-solicitation-flow.is-neutral {
    color: #64748b;
    background: rgba(100, 116, 139, .10);
    border-color: rgba(100, 116, 139, .18);
}

body[bp-layout] #crudTable .kpf-solicitation-action-primary {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    min-height: 32px;
    padding: .38rem .72rem;
    border: 1px solid rgba(220, 38, 38, .18);
    border-radius: 999px !important;
    color: #fff;
    background: #dc2626;
    font-size: .78rem;
    font-weight: 850 !important;
    text-decoration: none;
    box-shadow: 0 8px 18px rgba(220, 38, 38, .18);
}

body[bp-layout] #crudTable .kpf-solicitation-action-primary:hover {
    color: #fff;
    background: #b91c1c;
    box-shadow: 0 10px 22px rgba(220, 38, 38, .22);
}

body[bp-layout] #crudTable .kpf-solicitation-action-muted {
    display: inline-flex;
    align-items: center;
    gap: .28rem;
    color: var(--tblr-secondary-color) !important;
    font-size: .78rem;
    font-weight: 750 !important;
    text-decoration: none;
}

body[bp-layout] #crudTable .kpf-solicitation-action-muted:hover {
    color: var(--tblr-body-color) !important;
    background: rgba(100, 116, 139, .08);
}

/* --------------------------------------------------------------------------
   Sorting indicators: keep Bootstrap/DataTables behavior, just soften
-------------------------------------------------------------------------- */

body[bp-layout] #crudTable thead .sorting,
body[bp-layout] #crudTable thead .sorting_asc,
body[bp-layout] #crudTable thead .sorting_desc {
    cursor: pointer;
}

body[bp-layout] #crudTable thead .sorting:before,
body[bp-layout] #crudTable thead .sorting:after,
body[bp-layout] #crudTable thead .sorting_asc:before,
body[bp-layout] #crudTable thead .sorting_asc:after,
body[bp-layout] #crudTable thead .sorting_desc:before,
body[bp-layout] #crudTable thead .sorting_desc:after {
    opacity: .28 !important;
}

body[bp-layout] #crudTable thead .sorting_asc:before,
body[bp-layout] #crudTable thead .sorting_desc:after {
    opacity: .78 !important;
    color: var(--kpf-list-primary) !important;
}

/* --------------------------------------------------------------------------
   Pagination
-------------------------------------------------------------------------- */

body[bp-layout] #crudTable_wrapper .dataTables_paginate,
body[bp-layout] #crudTable_paginate {
    margin-top: 1.15rem !important;
}

body[bp-layout] #crudTable_wrapper .dataTables_paginate .pagination {
    gap: .4rem;
}

body[bp-layout] #crudTable_wrapper .page-link {
    min-width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px !important;
    border: 1px solid var(--kpf-list-border) !important;
    background: var(--kpf-list-bg) !important;
    color: var(--kpf-list-muted) !important;
    font-weight: 800;
    box-shadow: 0 8px 18px rgba(15, 23, 42, .04);
}

body[bp-layout] #crudTable_wrapper .page-item.active .page-link {
    color: #fff !important;
    border-color: var(--kpf-list-primary) !important;
    background: var(--kpf-list-primary) !important;
    box-shadow: 0 12px 24px rgba(239, 29, 20, .22);
}

body[bp-layout] #crudTable_wrapper .page-item.disabled .page-link {
    opacity: .52;
    box-shadow: none;
}

/* --------------------------------------------------------------------------
   CRUD/content header polish
   --------------------------------------------------------------------------
   O CRUD padrão renderiza `section.header-operation[bp-section="page-header"]`.
   A ideia é aproximar do hero moderno KPF, mas em altura operacional.
-------------------------------------------------------------------------- */

body[bp-layout] [bp-section="page-header"] {
    position: relative;
    overflow: hidden;
    min-height: 106px;
    margin: 0 0 1rem !important;
    padding: 24px 28px !important;
    border-radius: 28px;
    color: #fff;
    background:
        radial-gradient(circle at 10% 20%, rgba(239, 68, 68, .35), transparent 30%),
        radial-gradient(circle at 90% 10%, rgba(249, 115, 22, .35), transparent 28%),
        linear-gradient(135deg, #211924 0%, #2c1f2c 45%, #3a1f1f 100%);
    box-shadow: 0 24px 60px rgba(15, 23, 42, .24);
    flex-direction: column !important;
    align-items: flex-start !important;
    justify-content: center;
    gap: .45rem;
}

body[bp-layout] [bp-section="page-header"]::after {
    content: "";
    position: absolute;
    right: -70px;
    bottom: -96px;
    width: 250px;
    height: 250px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .08);
    pointer-events: none;
}

body[bp-layout] [bp-section="page-header"] > * {
    position: relative;
    z-index: 1;
}

body[bp-layout] [bp-section="page-heading"] {
    margin: 0 !important;
    color: #fff !important;
    font-size: 1.86rem;
    font-weight: 850;
    line-height: 1.12;
    letter-spacing: -0.03em;
}

body[bp-layout] [bp-section="page-subheading"],
body[bp-layout] [bp-section="page-subheading-back-button"],
body[bp-layout] #datatable_info_stack {
    width: auto !important;
    max-width: 100%;
    margin: .35rem 0 0 !important;
    color: rgba(255, 255, 255, .72) !important;
    font-size: .94rem;
    line-height: 1.5;
}

body[bp-layout] #datatable_info_stack,
body[bp-layout] #datatable_info_stack .dataTables_info {
    color: rgba(255, 255, 255, .72) !important;
}

body[bp-layout] #datatable_info_stack {
    display: inline-flex !important;
    align-items: center;
    align-self: flex-start !important;
    justify-content: flex-start !important;
    gap: .25rem;
    flex-wrap: wrap;
    margin-left: 0 !important;
    margin-right: 0 !important;
    text-align: left !important;
}

body[bp-layout] #datatable_info_stack .dataTables_info {
    padding: 0 !important;
    margin: 0 !important;
}

body[bp-layout] [bp-section="page-subheading"] a,
body[bp-layout] [bp-section="page-subheading-back-button"] a {
    color: #fff !important;
    font-weight: 800;
    text-decoration: underline;
    text-underline-offset: 3px;
}

body[bp-layout]:has([bp-section="crud-operation-show"]) [bp-section="page-header"] {
    width: 100%;
    flex: 1 1 auto;
    min-height: 118px;
    padding-right: 92px !important;
}

body[bp-layout]:has([bp-section="crud-operation-show"]) .container-fluid:has([bp-section="page-header"]) {
    position: relative;
    align-items: flex-start !important;
    gap: 0;
    margin-top: 0 !important;
    margin-bottom: 1rem !important;
}

body[bp-layout]:has([bp-section="crud-operation-show"]) .container-fluid:has([bp-section="page-header"]) > .btn {
    position: absolute;
    top: 24px;
    right: 30px;
    z-index: 2;
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 12px;
    color: var(--tblr-body-color);
    background: var(--tblr-bg-surface);
    border: 1px solid var(--tblr-border-color);
    box-shadow: 0 10px 24px rgba(15, 23, 42, .10);
}

body[bp-layout]:has([bp-section="crud-operation-create"]) [bp-section="page-header"],
body[bp-layout]:has([bp-section="crud-operation-update"]) [bp-section="page-header"] {
    min-height: 112px;
}

body[bp-layout] [bp-section="crud-operation-list"] > [class*="col-"] > .row.mb-2:first-child {
    margin-top: -.35rem;
    margin-bottom: .9rem !important;
}

body[bp-layout] [bp-section="page-header"] .breadcrumb,
body[bp-layout] .content-header .breadcrumb {
    font-size: .875rem;
}

body[bp-layout] .crud-header-row,
body[bp-layout] .content-header + .container-fluid {
    position: relative;
}

/* --------------------------------------------------------------------------
   Top buttons / CRUD actions area polish, scoped to Backpack pages
-------------------------------------------------------------------------- */

body[bp-layout] .page-title + .btn,
body[bp-layout] .content-header .btn,
body[bp-layout] .card .btn-primary,
body[bp-layout] .btn-primary {
    border-radius: 12px;
    font-weight: 800;
}

/* --------------------------------------------------------------------------
   CRUD Show geral
-------------------------------------------------------------------------- */

body[bp-layout] [bp-section="crud-operation-show"] {
    margin-top: 0.5rem;
}

body[bp-layout] [bp-section="crud-operation-show"] > div {
    width: 100%;
}

body[bp-layout] .kpf-show-details {
    padding: 1rem;
}

body[bp-layout] .kpf-show-details-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.85rem;
}

body[bp-layout] .kpf-show-detail-item {
    min-height: 88px;
    padding: 1rem 1.1rem;
    border: 1px solid rgba(15, 23, 42, 0.06);
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.035);
}

body[bp-layout] .kpf-show-detail-item:nth-child(2n) {
    border-right: 1px solid rgba(15, 23, 42, 0.06);
}

body[bp-layout] .kpf-show-detail-label {
    margin-bottom: 0.45rem;
    font-size: 0.68rem;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: 0.055em;
    text-transform: uppercase;
    color: #64748b;
}

body[bp-layout] .kpf-show-detail-value {
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.5;
    color: #0f172a;
    word-break: break-word;
}

body[bp-layout] .kpf-show-detail-value p:last-child {
    margin-bottom: 0;
}

body[bp-layout] .kpf-show-detail-value a {
    font-weight: 600;
    color: #b91c1c;
    text-decoration: none;
}

body[bp-layout] .kpf-show-detail-value a:hover {
    text-decoration: underline;
}

body[bp-layout] .kpf-show-detail-value .badge,
body[bp-layout] .kpf-show-detail-value .label {
    border-radius: 999px;
    padding: 0.35rem 0.65rem;
    font-size: 0.72rem;
    font-weight: 700;
}

body[bp-layout] .kpf-show-detail-actions {
    grid-column: 1 / -1;
    min-height: auto;
    background: linear-gradient(90deg, rgba(185, 28, 28, 0.08), rgba(255, 255, 255, 0.92));
    border-color: rgba(185, 28, 28, 0.14);
}

body[bp-layout] .kpf-show-detail-actions .kpf-show-detail-value {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    align-items: center;
}

body[bp-layout] .kpf-show-detail-actions .btn {
    border-radius: 999px;
    font-weight: 600;
}

body[bp-layout] .kpf-show-detail-value img {
    max-width: 100%;
    height: auto;
    border-radius: 14px;
}

body[bp-layout] .kpf-show-detail-value ul,
body[bp-layout] .kpf-show-detail-value ol {
    margin-bottom: 0;
    padding-left: 1.2rem;
}

body[bp-layout] .kpf-show-detail-value pre,
body[bp-layout] .kpf-show-detail-value code {
    white-space: pre-wrap;
    word-break: break-word;
}

html[data-bs-theme="dark"] body[bp-layout] .kpf-show-detail-item {
    background: #111827;
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
}

html[data-bs-theme="dark"] body[bp-layout] .kpf-show-detail-label {
    color: #94a3b8;
}

html[data-bs-theme="dark"] body[bp-layout] .kpf-show-detail-value {
    color: #e5e7eb;
}

html[data-bs-theme="dark"] body[bp-layout] .kpf-show-detail-value a {
    color: #f87171;
}

html[data-bs-theme="dark"] body[bp-layout] .kpf-show-detail-actions {
    background: linear-gradient(90deg, rgba(248, 113, 113, 0.13), rgba(17, 24, 39, 0.95));
    border-color: rgba(248, 113, 113, 0.2);
}

/* --------------------------------------------------------------------------
   Responsive: keep table usable without forcing card conversion
-------------------------------------------------------------------------- */

@media (max-width: 991.98px) {
    body[bp-layout] #crudTable {
        min-width: 760px;
    }

    body[bp-layout] #crudTable thead th,
    body[bp-layout] #crudTable tbody td {
        padding: 14px 12px !important;
        font-size: .86rem !important;
    }

    body[bp-layout] #datatable_search_stack .input-icon {
        width: 100%;
    }
}

@media (max-width: 1399.98px) {
    body[bp-layout] .kpf-show-details-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 767.98px) {
    body[bp-layout] .kpf-show-details-grid {
        grid-template-columns: 1fr;
    }

    body[bp-layout] .kpf-show-details {
        padding: 0.75rem;
    }

    body[bp-layout] .kpf-show-detail-item {
        min-height: auto;
        padding: 0.95rem;
    }
}
