/* ═══════════════════════════════════════════════════════════════════════════
   Nexus Control — Messages Section
   Fully theme-adaptive: uses CSS variables, no hard-coded colors.
   Light mode: dark text & icons on light surfaces.
   Dark mode: light text & icons on dark surfaces.
   Accent gradient used for sent bubbles, headers, and CTAs.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Layout ─────────────────────────────────────────────────────────────── */
/*
 * Identical pattern to Licenses, Customers and every other section:
 * plain display:block inside .nc-main (padding:24px, overflow-y:auto).
 * Width is 100% automatically. Height is calculated to fill .nc-main's
 * padded content box exactly so nc-main never needs to scroll.
 *   calc(100vh - topbar(56px) - top_pad(24px) - bottom_pad(24px))
 * No position:fixed, no position:absolute, no JS, no negative margins.
 */
#nxctl-portal .nc-section--messages {
    padding: 0;
}

#nxctl-portal .nc-msg-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    width: 100%;
    height: calc(100vh - var(--nc-topbar-h) - 2 * var(--nc-space-6));
    overflow: hidden;
    position: relative;
    background: var(--nc-surface);
    border-radius: var(--nc-radius-lg);
    border: 1px solid var(--nc-border);
    box-shadow: var(--nc-shadow-md);
}

/* ══════════════════════════════════════════════════════════════════════════
   LEFT PANEL — Thread list
   ══════════════════════════════════════════════════════════════════════════ */
#nxctl-portal .nc-msg-list-panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--nc-border);
    overflow: hidden;
    background: var(--nc-surface);
}

/* ── List panel header ────────────────────────────────────────────────── */
#nxctl-portal .nc-msg-list-header {
    padding: var(--nc-space-4) var(--nc-space-4) 0;
    flex-shrink: 0;
}

#nxctl-portal .nc-msg-list-header__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--nc-space-3);
}

#nxctl-portal .nc-msg-list-header__title {
    font-size: var(--nc-fs-lg);
    font-weight: 800;
    color: var(--nc-text);
    margin: 0;
}

/* Compose button */
#nxctl-portal .nc-msg-compose-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--nc-radius-full);
    background: var(--nc-accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    transition: transform var(--nc-dur), box-shadow var(--nc-dur);
    box-shadow: 0 2px 8px rgba(var(--nc-accent-rgb),.4);
}
#nxctl-portal .nc-msg-compose-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 14px rgba(var(--nc-accent-rgb),.5);
}

/* Search */
#nxctl-portal .nc-msg-search-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--nc-surface2);
    border: 1px solid var(--nc-border);
    border-radius: var(--nc-radius-full);
    padding: 7px 13px;
    margin-bottom: var(--nc-space-3);
    transition: border-color var(--nc-dur);
}
#nxctl-portal .nc-msg-search-wrap:focus-within { border-color: var(--nc-accent); }
#nxctl-portal .nc-msg-search-wrap svg { color: var(--nc-muted); flex-shrink: 0; }

#nxctl-portal .nc-msg-search-input {
    border: none;
    background: transparent;
    outline: none;
    font-size: var(--nc-fs-base);
    color: var(--nc-text);
    width: 100%;
}
#nxctl-portal .nc-msg-search-input::placeholder { color: var(--nc-muted); }

/* Selection toolbar */
#nxctl-portal .nc-msg-sel-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    margin-bottom: var(--nc-space-2);
}

#nxctl-portal .nc-msg-sel-all {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}
#nxctl-portal .nc-msg-sel-all input { accent-color: var(--nc-accent); width: 15px; height: 15px; }

#nxctl-portal .nc-msg-sel-count {
    font-size: 12px;
    font-weight: 700;
    color: var(--nc-accent);
    white-space: nowrap;
}

#nxctl-portal .nc-msg-sel-actions {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

#nxctl-portal .nc-msg-sel-action {
    width: 28px;
    height: 28px;
    border: 1px solid var(--nc-border);
    border-radius: var(--nc-radius);
    background: var(--nc-surface2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--nc-text);
    transition: all var(--nc-dur);
}
#nxctl-portal .nc-msg-sel-action:hover { background: var(--nc-accent); border-color: var(--nc-accent); color: #fff; }
#nxctl-portal .nc-msg-sel-action--danger:hover { background: #ef4444; border-color: #ef4444; }
#nxctl-portal .nc-msg-sel-action--close:hover { background: var(--nc-hover); color: var(--nc-text); border-color: var(--nc-border); }

/* Filter tabs */
#nxctl-portal .nc-msg-filters {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--nc-border);
    overflow-x: auto;
    scrollbar-width: none;
}
#nxctl-portal #nxctl-portal .nc-msg-filters::-webkit-scrollbar { display: none; }

#nxctl-portal .nc-msg-filter {
    padding: 7px 13px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--nc-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
    transition: color var(--nc-dur), border-color var(--nc-dur);
}
#nxctl-portal .nc-msg-filter--active, #nxctl-portal .nc-msg-filter:hover { color: var(--nc-accent); }
#nxctl-portal .nc-msg-filter--active { border-bottom-color: var(--nc-accent); }

/* ── Thread list ─────────────────────────────────────────────────────── */
#nxctl-portal .nc-msg-thread-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--nc-space-2) 0;
    scrollbar-width: thin;
    scrollbar-color: var(--nc-border) transparent;
}

/* Thread card */
#nxctl-portal .nc-msg-thread-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 14px;
    cursor: pointer;
    transition: background var(--nc-dur);
    position: relative;
    border-left: 3px solid transparent;
}
#nxctl-portal .nc-msg-thread-card:hover { background: var(--nc-hover); }
#nxctl-portal .nc-msg-thread-card--active { background: rgba(var(--nc-accent-rgb),.08); border-left-color: var(--nc-accent); }
#nxctl-portal .nc-msg-thread-card--unread { border-left-color: var(--nc-accent); }
#nxctl-portal .nc-msg-thread-card--unread #nxctl-portal .nc-msg-thread-card__subject { font-weight: 700; }

/* Checkbox — visible on hover or when any selected */
#nxctl-portal .nc-msg-thread-card__checkbox {
    flex-shrink: 0;
    align-self: center;
    accent-color: var(--nc-accent);
    width: 15px;
    height: 15px;
    cursor: pointer;
    opacity: 1;
    appearance: auto;
    -webkit-appearance: checkbox;
    display: inline-block;
}

/* Avatar */
#nxctl-portal .nc-msg-avatar {
    width: 38px;
    height: 38px;
    border-radius: var(--nc-radius-full);
    background: linear-gradient(135deg, var(--nc-accent) 0%, #000 100%);
    color: #ffffff;
    font-size: 13px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    text-transform: uppercase;
}
#nxctl-portal .nc-msg-avatar--sm { width: 28px; height: 28px; font-size: 10px; }

/* Thread card content */
#nxctl-portal .nc-msg-thread-card__body { flex: 1; min-width: 0; }

#nxctl-portal .nc-msg-thread-card__top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 3px;
}

#nxctl-portal .nc-msg-thread-card__subject {
    font-size: 13px;
    font-weight: 600;
    color: var(--nc-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

#nxctl-portal .nc-msg-thread-card__time {
    font-size: 11px;
    color: var(--nc-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

#nxctl-portal .nc-msg-thread-card__preview {
    font-size: 12px;
    color: var(--nc-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#nxctl-portal .nc-msg-thread-card__badges {
    display: flex;
    gap: 5px;
    align-items: center;
    margin-top: 4px;
}

#nxctl-portal .nc-msg-unread-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--nc-radius-full);
    background: var(--nc-accent);
    flex-shrink: 0;
}

#nxctl-portal .nc-msg-star-icon {
    color: #f59e0b;
    font-size: 12px;
}

/* Loading / empty state */
#nxctl-portal .nc-msg-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 48px 24px;
    gap: 12px;
    color: var(--nc-muted);
    font-size: 13px;
}

#nxctl-portal .nc-msg-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--nc-border);
    border-top-color: var(--nc-accent);
    border-radius: var(--nc-radius-full);
    animation: nc-spin .7s linear infinite;
}

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

#nxctl-portal .nc-msg-thread-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--nc-muted);
    font-size: 13px;
}

/* ══════════════════════════════════════════════════════════════════════════
   RIGHT PANEL — Thread view
   ══════════════════════════════════════════════════════════════════════════ */
#nxctl-portal .nc-msg-thread-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--nc-surface2);
}

/* Empty state */
#nxctl-portal .nc-msg-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--nc-muted);
    padding: 40px;
    text-align: center;
}
#nxctl-portal .nc-msg-empty-state svg { opacity: .25; color: var(--nc-muted); }
#nxctl-portal .nc-msg-empty-state p { font-size: 15px; font-weight: 600; color: var(--nc-text); margin: 0; }
#nxctl-portal .nc-msg-empty-state span { font-size: 13px; color: var(--nc-muted); }

/* Chat container */
#nxctl-portal .nc-msg-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Chat header */
#nxctl-portal .nc-msg-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--nc-border);
    background: var(--nc-surface);
    flex-shrink: 0;
}

#nxctl-portal .nc-msg-back-btn {
    display: none; /* shown on mobile */
    background: none;
    border: none;
    cursor: pointer;
    color: var(--nc-text);
    padding: 4px;
    border-radius: var(--nc-radius);
}
#nxctl-portal .nc-msg-back-btn:hover { background: var(--nc-hover); }

#nxctl-portal .nc-msg-chat-header__info { flex: 1; min-width: 0; }

#nxctl-portal .nc-msg-chat-header__subject {
    font-size: 15px;
    font-weight: 700;
    color: var(--nc-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#nxctl-portal .nc-msg-chat-header__participants {
    font-size: 11px;
    color: var(--nc-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#nxctl-portal .nc-msg-chat-header__actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

#nxctl-portal .nc-msg-assigned-badge {
    font-size: 11px;
    padding: 3px 9px;
    border-radius: var(--nc-radius-full);
    background: rgba(var(--nc-accent-rgb),.12);
    color: var(--nc-accent);
    font-weight: 600;
}

#nxctl-portal .nc-msg-hdr-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: var(--nc-radius-full);
    border: 1px solid var(--nc-border);
    background: var(--nc-surface);
    color: var(--nc-text);
    cursor: pointer;
    transition: all var(--nc-dur);
}
#nxctl-portal .nc-msg-hdr-btn:hover {
    background: var(--nc-accent);
    border-color: var(--nc-accent);
    color: #fff;
}

/* ── Message bubbles ─────────────────────────────────────────────────── */
#nxctl-portal .nc-msg-bubbles {
    flex: 1;
    overflow-y: auto;
    padding: var(--nc-space-5) var(--nc-space-5);
    display: flex;
    flex-direction: column;
    gap: 18px;
    scrollbar-width: thin;
    scrollbar-color: var(--nc-border) transparent;
}

/* Date separator */
#nxctl-portal .nc-msg-date-sep {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 11px;
    color: var(--nc-muted);
    font-weight: 600;
}
#nxctl-portal .nc-msg-date-sep::before, #nxctl-portal .nc-msg-date-sep::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--nc-border);
}

/* Message row */
#nxctl-portal .nc-msg-bubble-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
#nxctl-portal .nc-msg-bubble-row--mine {
    flex-direction: row-reverse;
}

#nxctl-portal .nc-msg-bubble-avatar { flex-shrink: 0; }

#nxctl-portal .nc-msg-bubble-body { max-width: 70%; min-width: 80px; }

#nxctl-portal .nc-msg-bubble-meta {
    font-size: 11px;
    color: var(--nc-muted);
    margin-bottom: 4px;
    display: flex;
    gap: 6px;
    align-items: baseline;
}
#nxctl-portal .nc-msg-bubble-row--mine .nc-msg-bubble-meta { flex-direction: row-reverse; }

#nxctl-portal .nc-msg-bubble-meta__name { font-weight: 700; color: var(--nc-text); }


/* Bubble itself */
#nxctl-portal .nc-msg-bubble {
    padding: 11px 15px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
}
/* Received bubble */
#nxctl-portal .nc-msg-bubble--received {
    background: var(--nc-surface);
    color: var(--nc-text);
    border: 1px solid var(--nc-border);
    border-bottom-left-radius: 4px;
}
/* Sent bubble */
#nxctl-portal .nc-msg-bubble--sent {
    background: linear-gradient(135deg, var(--nc-accent) 0%, rgba(var(--nc-accent-rgb),.7) 100%);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}
/* Text inside sent bubble must always be white */
#nxctl-portal .nc-msg-bubble--sent, #nxctl-portal .nc-msg-bubble--sent * { color: #ffffff !important; }
#nxctl-portal .nc-msg-bubble--sent a { color: rgba(255,255,255,.9) !important; text-decoration: underline; }

/* ── Reply bar ────────────────────────────────────────────────────────── */
#nxctl-portal .nc-msg-reply-bar {
    flex-shrink: 0;
    border-top: 1px solid var(--nc-border);
    background: var(--nc-surface);
    padding: var(--nc-space-3) var(--nc-space-4);
}

#nxctl-portal .nc-msg-last-reply-hint {
    font-size: 11px;
    color: var(--nc-muted);
    margin-bottom: 8px;
    padding: 5px 10px;
    background: rgba(var(--nc-accent-rgb),.06);
    border-radius: var(--nc-radius);
    border-left: 2px solid var(--nc-accent);
}

#nxctl-portal .nc-msg-reply-input-wrap {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#nxctl-portal .nc-msg-reply-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--nc-input-border);
    border-radius: var(--nc-radius-lg);
    background: var(--nc-input-bg);
    color: var(--nc-text);
    font-size: 14px;
    padding: 10px 14px;
    line-height: 1.5;
    outline: none;
    transition: border-color var(--nc-dur);
    max-height: 120px;
    scrollbar-width: thin;
}
#nxctl-portal .nc-msg-reply-input:focus { border-color: var(--nc-accent); }
#nxctl-portal .nc-msg-reply-input::placeholder { color: var(--nc-muted); }

#nxctl-portal .nc-msg-reply-send {
    width: 40px;
    height: 40px;
    border-radius: var(--nc-radius-full);
    background: linear-gradient(135deg, var(--nc-accent) 0%, #000 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    flex-shrink: 0;
    transition: transform var(--nc-dur), box-shadow var(--nc-dur);
}
#nxctl-portal .nc-msg-reply-send:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(var(--nc-accent-rgb),.4);
}

/* ══════════════════════════════════════════════════════════════════════════
   COMPOSE MODAL
   ══════════════════════════════════════════════════════════════════════════ */
#nxctl-portal .nc-msg-compose-modal {
    position: fixed;
    inset: 0;
    z-index: 999998;
    display: none;  /* JS controls this */
    align-items: flex-end;
    justify-content: flex-end;
    padding: 24px;
    pointer-events: none;
}
#nxctl-portal .nc-msg-compose-modal.is-open {
    display: flex;
    pointer-events: all;
}

#nxctl-portal .nc-msg-compose-card {
    background: var(--nc-surface);
    border: 1px solid var(--nc-border);
    border-radius: var(--nc-radius-xl);
    box-shadow: var(--nc-shadow-xl);
    width: 440px;
    max-width: calc(100vw - 48px);
    display: flex;
    flex-direction: column;
    max-height: 80vh;
    overflow: hidden;
    animation: nc-compose-in var(--nc-dur-md) var(--nc-ease);
}

@keyframes nc-compose-in {
    from { opacity: 0; transform: translateY(20px) scale(.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

#nxctl-portal .nc-msg-compose-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: linear-gradient(135deg, var(--nc-accent) 0%, #000 100%);
    color: #ffffff;
    font-size: 14px;
    font-weight: 700;
    flex-shrink: 0;
}
#nxctl-portal .nc-msg-compose-card__header button {
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255,255,255,.8);
    display: flex;
    padding: 3px;
    border-radius: var(--nc-radius);
}
#nxctl-portal .nc-msg-compose-card__header button:hover { color: #fff; background: rgba(255,255,255,.15); }

#nxctl-portal .nc-msg-compose-card__body {
    flex: 1;
    overflow-y: auto;
    padding: var(--nc-space-4);
    display: flex;
    flex-direction: column;
    gap: var(--nc-space-3);
}

#nxctl-portal .nc-msg-compose-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
#nxctl-portal .nc-msg-compose-field--grow { flex: 1; }
#nxctl-portal .nc-msg-compose-field label { font-size: 11px; font-weight: 700; color: var(--nc-muted); text-transform: uppercase; letter-spacing: .05em; }

#nxctl-portal .nc-msg-compose-input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--nc-input-border);
    border-radius: var(--nc-radius);
    background: var(--nc-input-bg);
    color: var(--nc-text);
    font-size: 13px;
    outline: none;
    transition: border-color var(--nc-dur);
    box-sizing: border-box;
}
#nxctl-portal .nc-msg-compose-input:focus { border-color: var(--nc-accent); }
#nxctl-portal .nc-msg-compose-input::placeholder { color: var(--nc-muted); }

#nxctl-portal .nc-msg-compose-textarea {
    resize: vertical;
    min-height: 120px;
    line-height: 1.6;
}

#nxctl-portal .nc-msg-compose-to-support {
    font-size: 13px;
    font-weight: 600;
    color: var(--nc-accent);
    padding: 7px 0;
}

#nxctl-portal .nc-msg-compose-card__footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 12px 18px;
    border-top: 1px solid var(--nc-border);
    background: var(--nc-surface2);
    flex-shrink: 0;
}

/* ═══
/* ══════════════════════════════════════════════════════════════════════════
   LIGHT MODE SPECIFICS
   ══════════════════════════════════════════════════════════════════════════ */
body.nc-light #nxctl-portal #nxctl-portal .nc-msg-thread-card--active {
    background: rgba(var(--nc-accent-rgb),.07);
}
body.nc-light #nxctl-portal #nxctl-portal .nc-msg-bubble--received {
    background: #ffffff;
    box-shadow: var(--nc-shadow-sm);
}

/* ══════════════════════════════════════════════════════════════════════════
   DARK MODE SPECIFICS
   ══════════════════════════════════════════════════════════════════════════ */
body.nc-dark #nxctl-portal .nc-msg-list-panel,
body.nc-dark #nxctl-portal .nc-msg-thread-panel,
body.nc-dark #nxctl-portal .nc-msg-chat-header,
body.nc-dark #nxctl-portal .nc-msg-reply-bar,
body.nc-dark #nxctl-portal #nxctl-portal .nc-msg-compose-card {
    background: rgba(255,255,255,.05);
    border-color: rgba(255,255,255,.08);
}
body.nc-dark #nxctl-portal #nxctl-portal .nc-msg-bubble--received {
    background: rgba(255,255,255,.08);
    border-color: rgba(255,255,255,.1);
}
body.nc-dark #nxctl-portal #nxctl-portal .nc-msg-thread-card:hover { background: rgba(255,255,255,.06); }
body.nc-dark #nxctl-portal #nxctl-portal .nc-msg-thread-card--active { background: rgba(var(--nc-accent-rgb),.15); }
body.nc-dark #nxctl-portal #nxctl-portal .nc-msg-search-wrap { background: rgba(255,255,255,.07); }

/* ── Inbox drawer items ─────────────────────────────────────────────── */
.nc-inbox-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 16px;
    border-bottom: 1px solid var(--nc-border);
    cursor: pointer;
    transition: background var(--nc-dur);
}
.nc-inbox-item:hover { background: var(--nc-hover); }
.nc-inbox-item--unread { background: rgba(var(--nc-accent-rgb),.05); }

.nc-inbox-avatar {
    width: 34px;
    height: 34px;
    border-radius: var(--nc-radius-full);
    background: linear-gradient(135deg, var(--nc-accent) 0%, #000 100%);
    color: #ffffff;
    font-size: 12px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    text-transform: uppercase;
}

.nc-inbox-body { flex: 1; min-width: 0; }
.nc-inbox-subject {
    font-size: 13px;
    font-weight: 600;
    color: var(--nc-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nc-inbox-item--unread .nc-inbox-subject { font-weight: 700; }
.nc-inbox-preview {
    font-size: 12px;
    color: var(--nc-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.nc-inbox-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}
.nc-inbox-time { font-size: 11px; color: var(--nc-muted); }
.nc-inbox-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--nc-accent);
}

.nc-inbox-loading {
    display: flex;
    justify-content: center;
    padding: 30px;
}
.nc-inbox-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--nc-muted);
    font-size: 13px;
}

/* ── Compose recipient type tabs ────────────────────────────────────────── */
#nxctl-portal .nc-msg-to-type-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: var(--nc-space-2);
}
#nxctl-portal .nc-msg-to-tab {
    flex: 1;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--nc-border);
    border-radius: var(--nc-radius);
    background: var(--nc-surface2);
    color: var(--nc-muted);
    cursor: pointer;
    transition: all var(--nc-dur);
    text-align: center;
}
#nxctl-portal .nc-msg-to-tab--active {
    background: var(--nc-accent);
    border-color: var(--nc-accent);
    color: #ffffff;
}
#nxctl-portal .nc-msg-to-tab:hover:not(.nc-msg-to-tab--active) {
    border-color: var(--nc-accent);
    color: var(--nc-accent);
}
#nxctl-portal .nc-msg-to-all-notice {
    font-size: 12px;
    color: var(--nc-muted);
    padding: 8px 12px;
    background: rgba(var(--nc-accent-rgb),.08);
    border-radius: var(--nc-radius);
    border-left: 3px solid var(--nc-accent);
}

/* ── Reply send button — spinner loading state ──────────────────────────── */
#nxctl-portal .nc-msg-reply-send {
    position: relative;  /* needed for ::after spinner */
}
#nxctl-portal .nc-msg-reply-send.is-loading {
    color: transparent !important;
    pointer-events: none;
}
#nxctl-portal .nc-msg-reply-send.is-loading svg {
    opacity: 0;
}
#nxctl-portal .nc-msg-reply-send.is-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    margin: auto;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: nc-spin .7s linear infinite;
}


/* ── Per-card hover action pill ─────────────────────────────────────────── */
#nxctl-portal .nc-msg-thread-card { position: relative; overflow: visible; }

#nxctl-portal .nc-msg-card-actions {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 2px;
    background: var(--nc-surface);
    border: 1px solid var(--nc-border);
    border-radius: 999px;
    padding: 4px 6px;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--nc-dur);
    z-index: 5;
    box-shadow: 0 2px 12px rgba(0,0,0,.12);
}
#nxctl-portal .nc-msg-thread-card:hover .nc-msg-card-actions {
    opacity: 1;
    pointer-events: all;
}
#nxctl-portal .nc-msg-card-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--nc-muted);
    cursor: pointer;
    transition: background var(--nc-dur), color var(--nc-dur);
    flex-shrink: 0;
}
#nxctl-portal .nc-msg-card-btn:hover {
    background: var(--nc-surface2);
    color: var(--nc-text);
}
#nxctl-portal .nc-msg-card-btn.active {
    color: #f59e0b;
}
#nxctl-portal .nc-msg-card-btn.active:hover { color: #d97706; }
#nxctl-portal .nc-msg-card-btn--danger:hover {
    background: rgba(239,68,68,.12);
    color: #ef4444;
}

/* Hide card time when pill is hovering to avoid overlap */
#nxctl-portal .nc-msg-thread-card:hover .nc-msg-thread-card__time {
    opacity: 0;
}

/* ══════════════════════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   Heights match the padding responsive.css applies to .nc-main at each bp:
     Desktop  > 900px : padding = 24px (--nc-space-6)  → subtract 48px
     Tablet  ≤ 900px  : padding = 16px (--nc-space-4)  → subtract 32px
     Mobile  ≤ 600px  : padding = 12px (--nc-space-3)  → subtract 24px
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Tablet (≤ 900px) — KEEP 2-column grid, adjust widths & height ──── */
@media (max-width: 900px) {
    #nxctl-portal .nc-msg-layout {
        /* Narrower left column on tablet but STAY 2-column */
        grid-template-columns: 260px 1fr;
        height: calc(100vh - var(--nc-topbar-h) - 2 * var(--nc-space-4));
        border-radius: var(--nc-radius);
    }
    /* Hide Assign button text on tablet to save space */
    #nxctl-portal .nc-msg-hdr-btn span { display: none; }
}

/* ── Mobile (≤ 600px) — single column + slide-in conversation ───────── */
@media (max-width: 600px) {
    #nxctl-portal .nc-msg-layout {
        grid-template-columns: 1fr;   /* single column */
        height: calc(100vh - var(--nc-topbar-h) - 2 * var(--nc-space-3));
        border-radius: 0;
        position: relative;           /* anchor for absolute thread panel */
    }

    #nxctl-portal .nc-msg-list-panel { border-right: none; }

    /* Conversation slides in from the right as a full-screen overlay */
    #nxctl-portal .nc-msg-thread-panel {
        position: absolute;
        inset: 0;
        z-index: 10;
        /* OPAQUE backgrounds — --nc-surface is semi-transparent in dark mode */
        background: #ffffff;
        transform: translateX(100%);
        transition: transform var(--nc-dur-md) var(--nc-ease);
    }
    body.nc-dark #nxctl-portal .nc-msg-thread-panel {
        background: #111111;
    }

    #nxctl-portal .nc-msg-layout.thread-open .nc-msg-thread-panel {
        transform: translateX(0);
    }

    /* Back button — visible on mobile only */
    #nxctl-portal .nc-msg-back-btn { display: flex; }

    /* Compose modal — full-width bottom sheet on mobile */
    #nxctl-portal .nc-msg-compose-modal {
        padding: 0;
        align-items: flex-end;
        justify-content: center;
    }
    #nxctl-portal .nc-msg-compose-card {
        width: 100%;
        max-width: 100%;
        border-radius: var(--nc-radius-xl) var(--nc-radius-xl) 0 0;
    }

    #nxctl-portal .nc-msg-bubble-body { max-width: 88%; }
    #nxctl-portal .nc-msg-sel-toolbar { flex-wrap: wrap; gap: 4px; }
    #nxctl-portal .nc-msg-hdr-btn { font-size: 0; width: 32px; padding: 0; justify-content: center; }
    #nxctl-portal .nc-msg-hdr-btn svg { font-size: initial; }
}

/* ══════════════════════════════════════════════════════════════════════════
   iOS SAFARI FIXES
   ══════════════════════════════════════════════════════════════════════════ */

/*
 * iOS Safari zooms the viewport when any focused input has font-size < 16px.
 * The portal uses --nc-fs-base: 13px globally.
 * Override to 16px on mobile to prevent zoom entirely.
 * The !important is required — the base form rule uses var(--nc-fs-base).
 */
@media (max-width: 900px) {
    #nxctl-portal input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
    #nxctl-portal textarea,
    #nxctl-portal select {
        font-size: 16px !important;
        -webkit-text-size-adjust: 100%;
    }
}

/*
 * Compose bottom sheet on iOS: use svh (small viewport height) so the card
 * shrinks to fit the visible area when the keyboard is open.
 * svh = viewport height measured with browser UI visible (keyboard up).
 * dvh = dynamic — updates as UI toggles.  Both used for max browser support.
 */
@media (max-width: 600px) {
    #nxctl-portal .nc-msg-compose-card {
        max-height: 85vh;
        max-height: 85svh;
        max-height: 85dvh;
        overflow-y: auto;
        /* Account for iOS home indicator */
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }
    /* Keep the footer (Cancel / Send) always visible at the bottom of card */
    #nxctl-portal .nc-msg-compose-card__footer {
        position: sticky;
        bottom: 0;
        z-index: 2;
    }
}

