/* ============================================================================
   MODALS & CONTEXT WINDOWS - UNIFIED STYLING
   Einheitliches Styling für alle Modals, Dialoge und Context-Fenster
   Version: 1.0.0
   ============================================================================ */

/* ========== Modal Overlay & Base ========== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    opacity: 0;
    transition: opacity 0.15s ease;
}

/* Custom Users modals use the standard overlay (semi-transparent).
   The dialog itself is already solid via `.modal-dialog { background: var(--bg-primary); }`. */

.modal.active {
    opacity: 1;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1;
}

/* ========== Modal Dialog ========== */
.modal-dialog {
    position: relative;
    background: var(--bg-primary);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    z-index: 2;
    border: 1px solid var(--border-color);
    animation: modalSlideIn 0.15s cubic-bezier(0.16, 1, 0.3, 1);
    will-change: transform, opacity;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-12px) scale(0.98);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

/* ========== Modal Header ========== */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 16px 16px 0 0;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: transparent;
    border: none;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-close svg {
    width: 20px;
    height: 20px;
}

/* ========== Modal Body ========== */
.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

/* Custom scrollbar for modal body */
.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* ========== Modal Footer ========== */
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 0 0 16px 16px;
}

/* ========== Assignment/Selection Modals ========== */
.assignment-modal-header {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 0;
}

.assignment-modal-title {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-width: 0;
}

.assignment-modal-title > [data-icon] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35rem;
    height: 1.35rem;
    font-size: 1.35rem;
    line-height: 1;
    flex-shrink: 0;
    color: var(--text-primary);
}

.assignment-modal-title > [data-icon] .mdi {
    font-size: 1.35rem;
    line-height: 1;
}

.assignment-modal-title h2 {
    margin: 0;
}

.icm-compact {
    padding-top: 0.25rem;
}

.icm-compact .icm-form textarea {
    min-height: 120px;
    resize: vertical;
}

/* Modal Error Banners (BaseModal & ItemCreateModal) */
.bm-error-banner,
.icm-error-banner {
    display: none;
    padding: 0.75rem 1rem;
    margin: 0 0 0.75rem 0;
    background: var(--danger-bg);
    color: var(--danger-text);
    border: 1px solid var(--danger-border);
    border-radius: 6px;
    font-size: 0.875rem;
    line-height: 1.4;
    word-break: break-word;
}

.assignment-modal-subtitle {
    display: inline-block;
    margin-top: 0.15rem;
    padding: 0.25rem 0.55rem;
    font-size: 0.8rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 5px;
}

/* ========== Checklist Container ========== */
.checklist-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.checklist-search {
    position: relative;
}

.checklist-search input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.938rem;
    transition: all 0.2s;
}

.checklist-search input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(222, 12, 21, 0.1);
}

.checklist-search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
}

.checklist-search-icon svg {
    width: 18px;
    height: 18px;
}

/* ========== Checklist Items ========== */
.checklist {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: min(400px, 50vh);
    overflow-y: auto;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.checklist-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.checklist-item:hover {
    background: var(--bg-primary);
    border-color: #64748b;
}

.checklist-item.ipm-selected,
.checklist-item.ipm-selected:hover {
    background: var(--bg-primary);
    border-color: #64748b;
    box-shadow: inset 3px 0 0 #64748b;
    transform: none;
}

.ipm-item {
    min-height: 56px;
    padding: 0.85rem 1rem;
}

.checklist-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    flex-shrink: 0;
    accent-color: var(--primary-color);
}

.checklist-item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.checklist-item-name {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.938rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.checklist-item-desc {
    font-size: 0.813rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.checklist-item-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(222, 12, 21, 0.1);
    color: var(--primary-color);
}

/* Empty state */
.checklist-empty {
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-muted);
}

.checklist-empty-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 1rem;
    opacity: 0.5;
}

.checklist-empty-text {
    font-size: 0.938rem;
    margin-bottom: 0.5rem;
}

.checklist-empty-hint {
    font-size: 0.813rem;
    color: var(--text-secondary);
}

/* Loading state */
.checklist-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    gap: 1rem;
}

.checklist-loading .loading-spinner {
    width: 32px;
    height: 32px;
}

/* ========== Modal Sizes ========== */
.modal-dialog.modal-sm {
    max-width: 400px;
}

.modal-dialog.modal-md {
    max-width: 600px;
}

.modal-dialog.modal-lg {
    max-width: 800px;
}

.modal-dialog.modal-xl {
    max-width: 1100px;
}

/* Unified MQTT modal size — all mqtt-modal bodies share this */
.modal-dialog.modal-xl:has(.mqtt-modal) {
    width: min(1400px, 96vw);
    max-width: min(1400px, 96vw);
    height: min(90vh, 900px);
    max-height: min(90vh, 900px);
}

.modal-dialog.modal-xl:has(.mqtt-modal) .modal-body.mqtt-modal {
    flex: 1 1 auto;
    max-height: none;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-dialog.modal-xl:has(.mqtt-modal) .mqtt-modal > .bm-body-content {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    gap: 1rem;
    height: 100%;
    overflow: auto;
}

/* Assign: allow dropdown to overflow add-form; only list scrolls */
.modal-dialog.modal-xl:has(.mqtt-assign-layout) .modal-body.mqtt-assign-layout {
    overflow: visible;
}

.modal-dialog.modal-xl:has(.mqtt-assign-layout) .mqtt-assign-layout > .bm-body-content {
    overflow: visible;
}

/* Single action button footer — right aligned, no cancel gap */
.modal-dialog:has(.mqtt-modal) .modal-footer {
    justify-content: flex-end;
}

.modal-dialog:has(.mqtt-modal) .modal-footer .btn:only-child {
    min-width: 120px;
}

.modal-dialog.modal-fullscreen {
    max-width: 95vw;
    max-height: 95vh;
}

/* ========== Confirmation Modals ========== */
.modal-dialog.modal-confirm {
    max-width: 450px;
}

.modal-confirm .modal-body {
    text-align: center;
    padding: 2rem;
}

.modal-confirm-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 1.5rem;
    padding: 1rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-confirm-icon.warning {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
}

.modal-confirm-icon.danger {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.modal-confirm-icon.success {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.modal-confirm-icon.info {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.modal-confirm-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.modal-confirm-message {
    font-size: 0.938rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ========== Responsive Design ========== */
@media (max-width: 768px) {
    .modal {
        padding: 0.5rem;
    }
    
    .modal-dialog {
        max-width: 100%;
        max-height: 95vh;
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 1rem;
    }
    
    .modal-footer {
        flex-direction: column;
    }
    
    .modal-footer button {
        width: 100%;
    }
    
    .checklist {
        max-height: min(300px, 40vh);
    }
}

/* ========== Dark Mode Specific ========== */
[data-theme="dark"] .modal-overlay {
    background: rgba(0, 0, 0, 0.55);
}

[data-theme="dark"] .modal-dialog {
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .checklist-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* ========== Accessibility ========== */
.modal[aria-hidden="true"] {
    display: none;
}

.modal[aria-hidden="false"] {
    display: flex;
}

.modal-dialog:focus {
    outline: none;
}

.modal-dialog:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* ========== MQTT Assign Layout ==========
   Unified layout for all manage/assign modals:
   - Add form on top
   - Scrollable table below
*/
.mqtt-assign-layout {
    min-height: 0;
}

.mqtt-assign-layout .mqtt-assign-subtitle {
    margin: 0;
    padding: 0.45rem 0;
    font-size: 0.85rem;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 0;
}

.mqtt-assign-layout .mqtt-assign-subtitle code {
    display: inline-block;
    padding: 0.3rem 0.65rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 999px;
}

.mqtt-assign-list {
    flex: 1 1 0;
    overflow: auto;
    min-height: 280px;
    max-height: none;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    padding: 0.35rem;
}

.mqtt-assign-list .dynamic-table-wrapper {
    min-width: 0;
}

.mqtt-assign-list .dt-table-section {
    overflow-x: visible;
}

.mqtt-assign-list table {
    width: 100%;
}

.mqtt-assign-list th {
    white-space: nowrap;
}

.mqtt-assign-list td {
    vertical-align: middle;
}

.mqtt-allow-deny {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: capitalize;
    color: var(--text-secondary);
}

.mqtt-allow-deny-allow { color: #94a3b8; }
.mqtt-allow-deny-deny { color: #f87171; }

.mqtt-assign-add {
    position: relative;
    z-index: 5;
    flex-shrink: 0;
    overflow: visible;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.9rem 1rem;
}

.mqtt-assign-add h4 {
    margin: 0 0 0.75rem 0;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-secondary);
}

.mqtt-add-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.mqtt-add-form-inline {
    flex-direction: row;
    align-items: flex-end;
    flex-wrap: nowrap;
    gap: 0.75rem;
}

.mqtt-add-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-width: 0;
}

.mqtt-add-field-grow {
    flex: 1 1 auto;
    min-width: 220px;
}

.mqtt-add-field-sm {
    flex: 0 0 96px;
}

@media (max-width: 900px) {
    .mqtt-add-form-inline {
        flex-wrap: wrap;
    }
    .mqtt-add-field-grow {
        flex: 1 1 100%;
    }
}

/* Inline DetailSelection inside MQTT add forms */
.mqtt-entity-search {
    position: relative;
    width: 100%;
    min-width: 0;
    z-index: 6;
}

.mqtt-entity-search .detail-autocomplete-control {
    margin-bottom: 0;
    max-width: none;
}

.mqtt-entity-search .autocomplete-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

/* data-icon sits ON the icon span — center + size the MDI child */
.mqtt-entity-search .autocomplete-icon,
.mqtt-entity-search .autocomplete-icon.autocomplete-icon-search {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    margin: 0;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
    pointer-events: none;
    z-index: 2;
}

.mqtt-entity-search .autocomplete-icon .mdi,
.mqtt-entity-search .autocomplete-icon[data-icon] .mdi {
    font-size: 18px;
    width: 18px;
    height: 18px;
    line-height: 18px;
}

/* Beat .mqtt-add-field input[type="text"] { padding: 0 0.65rem } */
.mqtt-add-field .mqtt-entity-search .autocomplete-input[type="text"],
.mqtt-entity-search .autocomplete-input[type="text"],
.mqtt-entity-search .autocomplete-input {
    background: var(--bg-tertiary);
    height: 38px;
    min-height: 38px;
    padding: 0 2.5rem 0 2.5rem;
    text-overflow: ellipsis;
}

.mqtt-entity-search .autocomplete-input::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

.mqtt-entity-search .autocomplete-dropdown {
    z-index: 1200;
}

/* Clickable count badges in overview tables */
button.mqtt-count-btn {
    cursor: pointer;
    font: inherit;
}

.mqtt-create-entity-field {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

.mqtt-create-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    min-height: 0;
}

.email-chip-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.45rem;
}

.email-chip-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
}

.email-chip-toggle input {
    cursor: pointer;
}

.email-chip-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.email-chip-input {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    min-height: 42px;
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-secondary);
}

.email-chip-input:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(222, 12, 21, 0.12);
}

.email-chip-input-el {
    flex: 1 1 8rem;
    min-width: 8rem;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.9rem;
    padding: 0.15rem 0;
}

.email-chip-input-el[hidden] {
    display: none !important;
}

.email-chip-field .mqtt-entity-search {
    margin-bottom: 0.45rem;
}

.email-chip-field .mqtt-entity-search[hidden] {
    display: none !important;
    margin-bottom: 0;
}

.email-chip {
    min-width: unset;
    max-width: 100%;
    gap: 0.25rem;
    padding-right: 0.3rem;
}

.email-chip.badge-muted {
    background: rgba(148, 163, 184, 0.14);
    color: #94a3b8;
    border: 1px dashed #64748b;
    opacity: 1;
    text-decoration: line-through;
}

[data-theme="dark"] .email-chip.badge-muted {
    background: rgba(148, 163, 184, 0.1);
    color: #94a3b8;
    border-color: #64748b;
}

.email-chip-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.18);
    color: inherit;
    font-size: 0.75rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.85;
}

.email-chip-remove:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.35);
}

.email-chip-overflow {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.75rem;
    color: var(--warning-color, #d97706);
}

.mqtt-inline-search-hint {
    margin: 0 0 0.75rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.modal-dialog:has(.mqtt-inline-search-modal) {
    width: min(480px, 94vw);
    max-width: min(480px, 94vw);
}

.modal-dialog:has(.mqtt-inline-search-modal) .modal-body {
    overflow: visible;
    min-height: 120px;
}

.mqtt-add-field > label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    line-height: 1.2;
}

.mqtt-add-form-actions {
    display: flex;
    align-items: flex-end;
    flex: 0 0 auto;
    padding-bottom: 0;
}

.mqtt-add-form-actions .btn {
    min-height: 38px;
    height: 38px;
    padding: 0 1.25rem;
    white-space: nowrap;
    border-radius: 6px;
}

.mqtt-add-field select,
.mqtt-add-field input[type="text"],
.mqtt-add-field input[type="number"] {
    width: 100%;
    min-height: 38px;
    height: 38px;
    padding: 0 0.65rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.875rem;
    box-sizing: border-box;
}

.mqtt-add-field select:focus,
.mqtt-add-field input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-color) 25%, transparent);
}

/* Permission toggles = same visual language as table badges */
.mqtt-perm-toggles {
    display: flex;
    gap: 0.3rem;
    align-items: center;
    min-height: 38px;
    height: 38px;
}

.mqtt-perm-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    min-width: 2.25rem;
    height: 38px;
    padding: 0 0.65rem;
    border-radius: 6px;
    border: 1px solid #64748b;
    background: transparent;
    color: #94a3b8;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.mqtt-perm-toggle input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.mqtt-perm-toggle:has(input:checked),
.mqtt-perm-toggle.is-active {
    color: #fff;
    background: #64748b;
    border-color: #64748b;
}

.mqtt-perm-toggle:hover {
    border-color: #94a3b8;
    color: #e2e8f0;
}

.mqtt-perm-toggle:has(input:checked):hover,
.mqtt-perm-toggle.is-active:hover {
    background: #475569;
    border-color: #475569;
    color: #fff;
}

/* Compact checklist override for modal context */
.modal-body .checklist {
    max-height: none;
}

.modal-body .checklist-item {
    padding: 0.625rem 0.75rem;
}

/* ========== Print Styles ========== */
@media print {
    .modal,
    .modal-overlay {
        display: none !important;
    }
}

/* ========== Animations ========== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        transform: translateY(10px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal.active .modal-dialog {
    animation: slideUp 0.15s ease;
}

/* ========== Loading Spinner for Modals ========== */
.modal .loading-spinner {
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========== MQTT Permission Badges (grouped, removable) ========== */
.mqtt-perm-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    min-width: 2.4rem;
    height: 28px;
    justify-content: center;
    padding: 0 0.65rem;
    margin: 0.1rem 0.25rem 0.1rem 0;
    border-radius: 5px;
    border: 1px solid #64748b;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #fff;
    white-space: nowrap;
    background: #64748b;
    transition: opacity 0.15s, background 0.15s;
}

.mqtt-perm-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin-left: 0.2rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.2);
    color: white;
    font-size: 0.75rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.15s, background 0.15s;
}

.mqtt-perm-remove:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.45);
}

/* ========== ItemPicker Modal Layout ========== */
.ipm-layout {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    gap: 0.85rem;
}

.modal-dialog.modal-xl:has(.ipm-layout) {
    max-width: min(720px, 92vw);
}

.modal-dialog.modal-xl:has(.ipm-layout) .modal-body {
    max-height: min(78vh, 680px);
    min-height: 480px;
    display: flex;
    flex-direction: column;
}

/* MQTT entity pickers: compact search dialog (not assign-modal size) */
.modal-dialog.modal-xl:has(.mqtt-picker-modal) {
    width: min(560px, 94vw);
    max-width: min(560px, 94vw);
    height: min(70vh, 640px);
    max-height: min(70vh, 640px);
}

.modal-dialog.modal-xl:has(.mqtt-picker-modal) .modal-body {
    max-height: none;
    min-height: 0;
}

.modal-dialog.modal-xl:has(.mqtt-picker-modal) .ipm-list {
    min-height: 220px !important;
}

.checklist-empty.ipm-min-search {
    gap: 0.5rem;
    padding: 2.5rem 1.5rem;
}

.checklist-empty.ipm-min-search .checklist-empty-icon {
    width: 40px;
    height: 40px;
    opacity: 0.55;
}

.checklist-empty.ipm-min-search .checklist-empty-text {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.checklist-empty.ipm-min-search .checklist-empty-hint {
    margin-top: 0.15rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    max-width: 260px;
    text-align: center;
    line-height: 1.4;
}

.ipm-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 0;
    flex: 1;
    height: 100%;
}

.ipm-container .checklist-search input {
    min-height: 42px;
    background: var(--bg-tertiary);
}

.ipm-info {
    padding: 0.15rem 0.25rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: right;
}

.ipm-list {
    flex: 1 1 auto !important;
    min-height: 280px !important;
    max-height: none !important;
    height: 100%;
}

.ipm-check {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 0.15rem;
    color: white;
    transition: background 0.15s, border-color 0.15s;
}

.ipm-check-square {
    border-radius: 4px;
}

.ipm-check-round {
    border-radius: 50%;
}

.ipm-selected .ipm-check {
    background: #64748b;
    border-color: #64748b;
}

.ipm-item-badge {
    margin-left: auto;
    flex-shrink: 0;
}

.ipm-loading-more {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    gap: 0.5rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Role assign empty / action bar */
.mqtt-assign-add-action {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.mqtt-assign-add-action .bm-add-picker-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 38px;
    padding: 0.5rem 1.1rem;
    width: auto;
}

.mqtt-assign-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2.5rem 1.25rem;
    color: var(--text-muted);
    min-height: 180px;
}

.mqtt-assign-empty-text {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.mqtt-assign-empty-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.mqtt-assign-empty-error {
    color: var(--error-color, #ef4444);
}

