.d365-grid {
    position: relative;
    display: grid;
    gap: 10px;
    color: #1f2933;
    font-size: 0.86rem;
}

.d365-grid__commandbar {
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    border: 1px solid rgba(31, 41, 51, 0.12);
    border-radius: 6px;
    background: #ffffff;
}

.d365-grid__summary {
    min-width: 0;
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.d365-grid__summary strong {
    font-size: 0.92rem;
}

.d365-grid__summary span {
    color: #64748b;
    font-size: 0.78rem;
}

.d365-grid__actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.d365-grid__command,
.d365-grid__header-menu,
.d365-grid__chooser header button,
.d365-grid__context-menu button {
    border: 0;
    background: transparent;
    color: #334155;
    cursor: pointer;
}

.d365-grid__command {
    min-height: 30px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 0 9px;
    font-size: 0.8rem;
}

.d365-grid__command:hover {
    background: rgba(0, 92, 184, 0.08);
    color: #005cb8;
}

.d365-grid__chooser-host {
    position: relative;
}

.d365-grid__chooser {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 120;
    width: min(280px, 86vw);
    max-height: 340px;
    overflow: auto;
    padding: 8px;
    border: 1px solid rgba(31, 41, 51, 0.14);
    border-radius: 6px;
    background: #ffffff;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.16);
}

.d365-grid__chooser header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 4px 4px 8px;
    border-bottom: 1px solid rgba(31, 41, 51, 0.1);
}

.d365-grid__chooser-item {
    min-height: 32px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px;
    border-radius: 4px;
    cursor: pointer;
}

.d365-grid__chooser-item:hover {
    background: rgba(31, 41, 51, 0.05);
}

.d365-grid__wrap {
    min-width: 0;
    overflow: auto;
    border: 1px solid rgba(31, 41, 51, 0.12);
    border-radius: 6px;
    background: #ffffff;
}

.d365-grid__table {
    width: 100%;
    min-width: 920px;
    border-collapse: collapse;
    background: #ffffff;
}

.d365-grid__table th,
.d365-grid__table td {
    padding: 8px 10px;
    border-right: 1px solid rgba(31, 41, 51, 0.08);
    border-bottom: 1px solid rgba(31, 41, 51, 0.08);
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

.d365-grid__table th:last-child,
.d365-grid__table td:last-child {
    border-right: 0;
}

.d365-grid__table thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: #f3f6f9;
    color: #334155;
    font-weight: 700;
}

.d365-grid__filters th {
    top: 37px;
    z-index: 2;
    padding: 6px;
    background: #f8fafc;
}

.d365-grid__th {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 28px;
    align-items: center;
    gap: 4px;
}

.d365-grid__sort {
    min-width: 0;
    border: 0;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

.d365-grid__sort span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.d365-grid__sort i {
    color: #64748b;
    font-size: 0.7rem;
}

.d365-grid__header-menu {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    display: grid;
    place-items: center;
}

.d365-grid__header-menu:hover {
    background: rgba(31, 41, 51, 0.08);
}

.d365-grid__header-menu--filtered {
    color: #005cb8;
    background: rgba(0, 92, 184, 0.1);
}

.d365-grid__table tbody tr:hover {
    background: rgba(0, 92, 184, 0.045);
}

.d365-grid__context-menu {
    position: fixed;
    z-index: 130;
    width: min(280px, 86vw);
    padding: 6px;
    border: 1px solid rgba(31, 41, 51, 0.16);
    border-radius: 6px;
    background: #ffffff;
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.22);
}

.d365-grid__context-menu button {
    width: 100%;
    min-height: 34px;
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    padding: 0 8px;
    border-radius: 4px;
    text-align: left;
}

.d365-grid__context-menu button:hover {
    background: rgba(0, 92, 184, 0.08);
    color: #005cb8;
}

.d365-grid__context-divider {
    height: 1px;
    margin: 6px 4px;
    background: rgba(31, 41, 51, 0.12);
}

.d365-grid__filter-panel {
    position: absolute;
    top: 6px;
    left: calc(100% + 8px);
    width: min(320px, 86vw);
    display: grid;
    gap: 10px;
    padding: 10px;
    border: 1px solid rgba(31, 41, 51, 0.16);
    border-radius: 6px;
    background: #ffffff;
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.22);
}

.d365-grid__filter-panel header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(31, 41, 51, 0.1);
}

.d365-grid__filter-panel header strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.d365-grid__filter-panel label {
    display: grid;
    gap: 5px;
    color: #64748b;
    font-size: 0.76rem;
    font-weight: 700;
}

.d365-grid__filter-panel select,
.d365-grid__filter-panel input {
    min-height: 34px;
    min-width: 0;
    border: 1px solid rgba(31, 41, 51, 0.14);
    border-radius: 4px;
    padding: 0 8px;
    background: #ffffff;
    color: #1f2933;
    font-size: 0.84rem;
}

.d365-grid__filter-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.d365-grid__filter-actions button {
    justify-content: start;
}

.d365-grid__empty,
.d365-grid__empty-row {
    color: #64748b;
}

.d365-grid__empty {
    display: grid;
    gap: 6px;
    padding: 18px;
    border: 1px solid rgba(31, 41, 51, 0.12);
    border-radius: 6px;
    background: #ffffff;
}

.d365-grid__empty p {
    margin: 0;
}

.d365-grid__empty-row {
    padding: 22px 10px;
    text-align: center;
}

@media (max-width: 720px) {
    .d365-grid__commandbar {
        align-items: stretch;
        flex-direction: column;
    }

    .d365-grid__summary,
    .d365-grid__actions {
        justify-content: space-between;
    }

    .d365-grid__command span {
        display: none;
    }

    .d365-grid__table {
        min-width: 760px;
    }

    .d365-grid__filter-panel {
        position: static;
        width: 100%;
        margin-top: 6px;
        box-shadow: none;
    }
}
