/*
 * DWMultiSelect v1.0
 * DW UI visual alignment: DWGrid / DWActionBar
 * v2.5 keeps the v2.4 visual baseline and adds functional controls.
 */

/* The native select remains the form value source. */
select.dw-ms-native {
    display: none !important;
}

.dw-ms {
    display: inline-block;
    position: relative;
    vertical-align: middle;
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    font-style: inherit;
    line-height: inherit;
    letter-spacing: inherit;
    box-sizing: border-box;
}

.dw-ms *,
.dw-ms-panel,
.dw-ms-panel * {
    box-sizing: border-box;
}

/* =========================================================
   TRIGGER / CLOSED CONTROL
   Same visual language as DWActionBar form controls.
   ========================================================= */

.dw-ms-trigger {
    position: relative;
    display: block;
    width: 100%;
    height: 30px;
    padding: 4px 29px 4px 8px;
    overflow: hidden;
    background: #fff;
    border: 1px solid #bdbfc2;
    border-radius: 4px;
    color: #3f4852;
    cursor: pointer;
    outline: none;
    white-space: nowrap;
    text-overflow: ellipsis;
    font: inherit;
    letter-spacing: inherit;
    transition: border-color .12s ease, box-shadow .12s ease, background-color .12s ease;
}

.dw-ms-trigger:hover {
    background: #fafbfc;
    border-color: #aeb3b8;
}

.dw-ms-trigger:focus,
.dw-ms-trigger.is-open {
    background: #fff;
    border-color: #7fa8ac;
    box-shadow: 0 0 0 2px rgba(39, 127, 137, .10);
}

.dw-ms-trigger.is-disabled {
    background: #f3f4f6;
    border-color: #dfe3e6;
    color: #8c959e;
    cursor: default;
    box-shadow: none;
}

.dw-ms-caption {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 20px;
}

.dw-ms-caption.is-placeholder {
    color: #7a858f;
}

.dw-ms-arrow {
    position: absolute;
    right: 10px;
    top: 50%;
    width: 0;
    height: 0;
    margin-top: -2px;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid #5f6973;
    transition: transform .12s ease;
}

.dw-ms-trigger.is-open .dw-ms-arrow {
    transform: rotate(180deg);
}

/* =========================================================
   BODY-LEVEL POPUP
   Uses the same border/radius/shadow family as DWActionBar.
   ========================================================= */

.dw-ms-panel {
    position: absolute;
    z-index: 10050;
    overflow: hidden;
    background: #fff;
    border: 1px solid #bdbfc2;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
    color: #3f4852;
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    font-style: inherit;
    line-height: inherit;
    letter-spacing: inherit;
}

/* =========================================================
   SEARCH
   ========================================================= */

.dw-ms-search-wrap {
    position: relative;
    padding: 7px;
    background: #fafbfc;
    border-bottom: 1px solid #d6d9dc;
}

/* CSS magnifier: no emoji / icon-font dependency. */
.dw-ms-search-icon {
    position: absolute;
    left: 17px;
    top: 50%;
    width: 11px;
    height: 11px;
    margin-top: -7px;
    border: 1.5px solid #6f7a84;
    border-radius: 50%;
    pointer-events: none;
    opacity: .95;
}

.dw-ms-search-icon:after {
    content: '';
    position: absolute;
    width: 6px;
    height: 1.5px;
    right: -5px;
    bottom: -3px;
    background: #6f7a84;
    transform: rotate(45deg);
    transform-origin: left center;
}

.dw-ms-search {
    display: block;
    width: 100%;
    height: 30px;
    margin: 0;
    padding: 4px 8px 4px 30px;
    background: #fff;
    border: 1px solid #bdbfc2;
    border-radius: 4px;
    color: #34414a;
    font: inherit;
    letter-spacing: inherit;
    outline: none;
    box-shadow: none;
    transition: border-color .12s ease, box-shadow .12s ease;
}

.dw-ms-search:focus {
    border-color: #7fa8ac;
    box-shadow: 0 0 0 2px rgba(39, 127, 137, .10);
}

/* =========================================================
   SELECT ALL
   ========================================================= */

.dw-ms-select-all {
    position: relative;
    min-height: 30px;
    padding: 5px 48px 5px 32px;
    background: #f7f8fa;
    border-bottom: 1px solid #d1d5d9;
    cursor: pointer;
    outline: none;
    font-family: inherit;
    font-size: inherit;
    line-height: 20px;
    font-weight: 600;
    color: #39434c;
    transition: background-color .12s ease;
}

.dw-ms-select-all:hover,
.dw-ms-select-all:focus {
    background: #eef1f3;
}

.dw-ms-select-all-count {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    color: #7a858f;
    font-size: .90em;
    font-weight: 500;
    line-height: 18px;
    text-align: right;
}

/* =========================================================
   ITEMS
   ========================================================= */

.dw-ms-items {
    overflow-x: hidden;
    overflow-y: auto;
    max-height: 360px;
    background: #fff;
    overscroll-behavior: contain;
}

.dw-ms-item {
    position: relative;
    min-height: 28px;
    padding: 4px 8px 4px 32px;
    border-bottom: 1px solid #edf0f2;
    background: #fff;
    color: #3f4852;
    cursor: pointer;
    outline: none;
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    font-style: inherit;
    letter-spacing: inherit;
    line-height: 20px;
    transition: background-color .10s ease, color .10s ease;
}

.dw-ms-item:last-child {
    border-bottom: 0;
}

.dw-ms-item:hover,
.dw-ms-item:focus {
    background: #f6f8fa;
}

.dw-ms-item.is-selected {
    background: #f2f8f8;
    color: #34484a;
}

.dw-ms-item.is-selected:hover,
.dw-ms-item.is-selected:focus {
    background: #eaf4f4;
}

.dw-ms-item.is-disabled {
    background: #fafbfc;
    color: #a3abb3;
    cursor: default;
}

/* Long labels remain one-line for dense ERP lists.
   The complete label is available through the native title tooltip. */
.dw-ms-item-text {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* =========================================================
   CHECKBOXES
   Exact DWGrid pattern: .dw-grid-check + native input +
   Font Awesome .dw-grid-check-icon (square/check/minus).
   ========================================================= */

.dw-ms-panel .dw-ms-check.dw-grid-check {
    position: absolute;
    left: 9px;
    top: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 0;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: inherit;
    line-height: 16px;
    pointer-events: none;
}

/* Keep the same DOM structure as DWGrid, but let the FA icon render the box. */
.dw-ms-panel .dw-ms-check.dw-grid-check input[type="checkbox"] {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    border: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
}

.dw-ms-panel .dw-ms-check .dw-grid-check-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    margin: 0;
    padding: 0;
    color: #59636c;
    font-size: 16px;
    font-weight: normal;
    line-height: 16px;
    text-align: center;
    vertical-align: middle;
    transition: color .10s ease;
}

.dw-ms-item:hover .dw-grid-check-icon,
.dw-ms-item:focus .dw-grid-check-icon,
.dw-ms-select-all:hover .dw-grid-check-icon,
.dw-ms-select-all:focus .dw-grid-check-icon {
    color: #3e777b;
}

.dw-ms-item.is-selected .dw-grid-check-icon,
.dw-ms-select-all.is-selected .dw-grid-check-icon,
.dw-ms-select-all.is-partial .dw-grid-check-icon,
.dw-ms-check.is-checked .dw-grid-check-icon,
.dw-ms-check.is-partial .dw-grid-check-icon {
    color: #278189;
}

.dw-ms-item.is-disabled .dw-grid-check-icon,
.dw-ms-check.is-disabled .dw-grid-check-icon {
    color: #b9c0c5;
}

/* =========================================================
   OPTGROUP HEADER
   Mirrors DWGrid group-row visual hierarchy.
   ========================================================= */

.dw-ms-group {
    padding: 5px 8px;
    background: #eef0f2;
    border-top: 1px solid #d6dbe0;
    border-bottom: 1px solid #d6dbe0;
    box-shadow: inset 3px 0 0 #358388;
    color: #39434c;
    font-size: .90em;
    font-weight: 600;
    text-transform: none;
    letter-spacing: normal;
    line-height: 18px;
}

.dw-ms-empty {
    padding: 14px 10px;
    color: #7a858f;
    text-align: center;
}

/* =========================================================
   FOOTER
   ========================================================= */

.dw-ms-footer {
    min-height: 30px;
    padding: 5px 8px;
    overflow: hidden;
    background: #fafbfc;
    border-top: 1px solid #d6d9dc;
    color: #7a858f;
    font-size: .92em;
    line-height: 20px;
}

.dw-ms-footer-count {
    float: left;
}

.dw-ms-clear,
.dw-ms-selected-only {
    float: right;
    color: #2f7478;
    font-weight: 500;
    text-decoration: underline;
    text-decoration-color: #a9c7c9;
    text-underline-offset: 2px;
    cursor: pointer;
}

.dw-ms-selected-only,
.dw-ms-clear {
    margin-right: 12px;
}

/* Explicit completion action: visually presented as a compact Office button. */
.dw-ms-done {
    float: right;
    display: inline-block;
    height: 24px;
    min-width: 44px;
    margin: -2px 0 -2px 0;
    padding: 0 9px;
    background: #fff;
    border: 1px solid #9bbfc2;
    border-radius: 4px;
    color: #2f7478;
    font: inherit;
    font-weight: 600;
    line-height: 22px;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    outline: none;
    box-shadow: none;
    vertical-align: middle;
    -webkit-appearance: none;
    appearance: none;
}

.dw-ms-clear:hover,
.dw-ms-clear:focus,
.dw-ms-selected-only:hover,
.dw-ms-selected-only:focus {
    color: #245f63;
    text-decoration-color: #245f63;
    outline: none;
}

.dw-ms-done:hover {
    background: #f7fbfb;
    border-color: #79a8ac;
    color: #245f63;
}

.dw-ms-done:focus {
    background: #fff;
    border-color: #6f9fa3;
    color: #245f63;
    box-shadow: 0 0 0 2px rgba(39, 127, 137, .10);
}

.dw-ms-done:active {
    background: #eef5f5;
    border-color: #6f9fa3;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, .05);
}

.dw-ms-selected-only.is-active {
    font-weight: 600;
}

.dw-ms-clear.is-disabled {
    color: #b4bbc1;
    text-decoration: none;
    pointer-events: none;
}

/* Compact scrollbar where supported. */
.dw-ms-items {
    scrollbar-width: thin;
    scrollbar-color: #bfc6cc #f4f5f6;
}

.dw-ms-items::-webkit-scrollbar {
    width: 7px;
}

.dw-ms-items::-webkit-scrollbar-track {
    background: #f4f5f6;
}

.dw-ms-items::-webkit-scrollbar-thumb {
    background: #bfc6cc;
    border: 0;
    border-radius: 5px;
}

.dw-ms-items::-webkit-scrollbar-thumb:hover {
    background: #a6afb6;
}

/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 520px) {
    .dw-ms-trigger {
        height: 32px;
        padding-top: 5px;
        padding-bottom: 5px;
    }

    .dw-ms-panel {
        border-radius: 5px;
    }

    .dw-ms-search {
        height: 32px;
    }

    .dw-ms-select-all {
        min-height: 34px;
        padding-top: 7px;
        padding-bottom: 7px;
    }

    /* Keep touch targets usable while desktop remains dense. */
    .dw-ms-item {
        min-height: 34px;
        padding-top: 7px;
        padding-bottom: 7px;
    }

    .dw-ms-footer {
        min-height: 34px;
        padding-top: 7px;
        padding-bottom: 7px;
    }
}
