/* ----------------------------------------------------------------------
 * Messages V2 — inbox shell styles (Phase 2)
 * Self-contained; no Bootstrap utility overrides outside .msgv2-* scope.
 * -------------------------------------------------------------------- */

.msgv2-shell {
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid #e6e8ec;
    border-radius: 6px;
    margin-top: 12px;
    min-height: 70vh;
}

/* ---- Toolbar ---- */
.msgv2-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid #eef0f3;
    flex-wrap: wrap;
    gap: 10px;
}

.msgv2-folders {
    display: flex;
    gap: 4px;
}

.msgv2-folder-tab {
    background: transparent;
    border: 1px solid transparent;
    padding: 6px 14px;
    border-radius: 4px 4px 0 0;
    font-size: 14px;
    color: #4a5568;
    cursor: pointer;
    position: relative;
}

.msgv2-folder-tab:hover {
    background: #f5f7fa;
}

.msgv2-folder-tab.is-active {
    background: #fff;
    border-color: #d0d4da;
    border-bottom-color: transparent;
    color: #1f2937;
    font-weight: 600;
}

.msgv2-unread-badge {
    display: inline-block;
    background: #e53e3e;
    color: #fff;
    font-size: 11px;
    line-height: 1;
    padding: 3px 6px;
    border-radius: 10px;
    margin-left: 6px;
    min-width: 18px;
    text-align: center;
    vertical-align: middle;
}

.msgv2-toolbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.msgv2-search-wrapper {
    position: relative;
}

.msgv2-search {
    padding-left: 30px;
    padding-right: 30px;
    width: 220px;
    height: 32px;
    font-size: 13px;
}

.msgv2-search-wrapper .fa-search,
.msgv2-search-icon {
    position: absolute;
    top: 50%;
    left: 10px;
    transform: translateY(-50%);
    color: #9aa1a9;
    pointer-events: none;
}

.msgv2-search-clear {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    background: transparent;
    border: 0;
    color: #9aa1a9;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    line-height: 1;
}
.msgv2-search-clear:hover {
    color: #1e293b;
    background: #e2e8f0;
}

.msgv2-bulk-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
    border-left: 1px solid #e6e8ec;
}

.msgv2-bulk-count {
    font-size: 12px;
    color: #4a5568;
    background: #edf2f7;
    padding: 2px 8px;
    border-radius: 10px;
}

/* ---- Body ---- */
.msgv2-body {
    margin: 0;
}

.msgv2-list-container {
    border-right: 1px solid #eef0f3;
    min-height: 60vh;
    display: flex;
    flex-direction: column;
}

.msgv2-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    border-bottom: 1px solid #eef0f3;
    font-size: 12px;
    color: #6b7280;
}

.msgv2-select-all-label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    cursor: pointer;
    font-size: 12px;
}

.msgv2-list {
    flex: 1;
    overflow-y: auto;
    max-height: 65vh;
}

.msgv2-list-loading {
    padding: 24px;
    text-align: center;
    color: #6b7280;
    font-size: 13px;
}

/* ---- List rows ---- */
.msgv2-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid #f1f3f5;
    cursor: pointer;
    transition: background 120ms ease;
}

.msgv2-row:hover {
    background: #f9fafb;
}

.msgv2-row .msgv2-row-from {
    font-weight: 500;
}

.msgv2-row .msgv2-row-subject {
    font-weight: 500;
}

.msgv2-row .msgv2-row-preview,
.msgv2-row .msgv2-row-date {
    color: #9ca3af;
}

.msgv2-row.is-active {
    background: #eef5ff;
    border-left: 3px solid #3b82f6;
    padding-left: 11px;
}

.msgv2-row.is-unread .msgv2-row-from,
.msgv2-row.is-unread .msgv2-row-subject {
    font-weight: 700;
    color: #111827;
}

.msgv2-row.is-unread {
    background: #f8fbff;
}

.msgv2-row.is-unread:hover {
    background: #f1f7ff;
}

.msgv2-row.is-unread .msgv2-row-preview,
.msgv2-row.is-unread .msgv2-row-date {
    color: #4b5563;
}

.msgv2-row.is-unread::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #3b82f6;
    margin-top: 8px;
    flex-shrink: 0;
}

.msgv2-row-select {
    margin: 0;
    padding-top: 4px;
}

.msgv2-row-avatar {
    flex-shrink: 0;
    margin-top: 2px;
}

.msgv2-row-body {
    flex: 1;
    min-width: 0;
}

/* Avatar tiles (sender identity) */
.msgv2-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    overflow: hidden;
    color: #ffffff;
    font-weight: 600;
    line-height: 1;
    text-transform: uppercase;
    user-select: none;
    vertical-align: middle;
    flex-shrink: 0;
}

.msgv2-avatar-sm {
    width: 28px;
    height: 28px;
    font-size: 11px;
}

.msgv2-avatar-md {
    width: 40px;
    height: 40px;
    font-size: 15px;
}

.msgv2-avatar-img {
    object-fit: cover;
    display: block;
    border-radius: 50%;
}

.msgv2-avatar-tile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.msgv2-detail-from {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.msgv2-detail-from-name {
    font-weight: 600;
    color: #1f2937;
}

.msgv2-msg-avatar {
    flex-shrink: 0;
}

.msgv2-row-top {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.msgv2-row-from {
    font-size: 13px;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msgv2-row-date {
    font-size: 11px;
    color: #9ca3af;
    flex-shrink: 0;
}

.msgv2-row-subject {
    font-size: 13px;
    color: #1f2937;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msgv2-row-preview {
    font-size: 12px;
    color: #6b7280;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msgv2-broadcast-badge {
    display: inline-block;
    background: #fef3c7;
    color: #92400e;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: 4px;
}

/* ---- Empty state ---- */
.msgv2-empty {
    padding: 40px 20px;
    text-align: center;
    color: #6b7280;
}

.msgv2-empty-icon {
    font-size: 36px;
    color: #cbd5e1;
    margin-bottom: 8px;
}

.msgv2-empty-text {
    margin: 0;
    font-size: 14px;
}

/* ---- Pagination ---- */
.msgv2-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid #eef0f3;
    font-size: 12px;
}

.msgv2-page-indicator {
    color: #4a5568;
    min-width: 50px;
    text-align: center;
}

/* ---- Detail panel ---- */
.msgv2-detail-container {
    min-height: 60vh;
    padding: 20px;
}

.msgv2-detail-empty {
    text-align: center;
    color: #9ca3af;
    padding: 60px 20px;
}

.msgv2-detail-empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    color: #cbd5e1;
}

.msgv2-detail-header {
    border-bottom: 1px solid #eef0f3;
    padding-bottom: 12px;
    margin-bottom: 16px;
}

.msgv2-detail-subject {
    font-size: 18px;
    font-weight: 600;
    color: var(--info, #71cde0);
    margin: 0 0 6px 0;
}

.msgv2-detail-meta {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #6b7280;
}

.msgv2-detail-actions {
    margin-top: 8px;
}

.msgv2-detail-messages {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.msgv2-msg {
    border: 1px solid #eef0f3;
    border-radius: 6px;
    padding: 12px 14px;
    background: #fafbfc;
}

.msgv2-msg-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 12px;
    color: #6b7280;
}

.msgv2-msg-date {
    margin-left: auto;
}

.msgv2-msg-from {
    font-weight: 600;
    color: #374151;
}

.msgv2-msg-body {
    font-size: 14px;
    color: #1f2937;
    line-height: 1.5;
    word-wrap: break-word;
}

.msgv2-msg-body p {
    margin: 0 0 8px 0;
}
.msgv2-msg-body p:last-child {
    margin-bottom: 0;
}

.msgv2-detail-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: 12px;
    border-radius: 6px;
    font-size: 13px;
    display: flex;
    gap: 8px;
    align-items: center;
}

/* ---- Utility ---- */
.msgv2-shell .hide {
    display: none !important;
}

/* ======================================================================
 * Phase 3 — Compose modal + Reply box
 * ==================================================================== */

/* ---- Modal ---- */
.msgv2-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1050;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 4vh 16px;
    overflow-y: auto;
}
.msgv2-modal.hide {
    display: none !important;
}

.msgv2-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.55);
    z-index: -1;
}

.msgv2-modal-dialog {
    background: #fff;
    width: 100%;
    max-width: 720px;
    border-radius: 8px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.msgv2-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid #eef0f3;
    background: #f8fafc;
}

.msgv2-modal-title {
    font-size: 16px;
    margin: 0;
    color: var(--info, #71cde0);
}

.msgv2-modal-close {
    background: transparent;
    border: 0;
    color: #64748b;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}
.msgv2-modal-close:hover {
    background: #e2e8f0;
    color: #1e293b;
}

.msgv2-modal-body {
    padding: 18px;
    overflow-y: auto;
    max-height: calc(90vh - 150px);
}

.msgv2-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 18px;
    border-top: 1px solid #eef0f3;
    background: #f8fafc;
}

body.msgv2-modal-open {
    overflow: hidden;
}

/* ---- Recipients fieldset ---- */
.msgv2-recipients {
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 12px 14px 6px;
    margin-bottom: 16px;
    background: #f8fafc;
}
.msgv2-field-legend {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: #64748b;
    padding: 0 6px;
    width: auto;
    border: 0;
    margin-bottom: 4px;
}
.msgv2-recipients-loading {
    color: #64748b;
    font-size: 13px;
    padding: 6px 0;
}
.msgv2-recipient-row {
    margin-bottom: 10px;
}
.msgv2-recipient-row:last-child {
    margin-bottom: 6px;
}

/* Top-level recipient toggles shown side-by-side. */
.msgv2-top-toggles {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.msgv2-top-toggles .msgv2-toggle-btn {
    margin: 0;
    border-color: #71cde0;
    background: #71cde0;
    color: #fff;
    font-weight: 500;
    max-width: 160px;
}
.msgv2-top-toggles .msgv2-toggle-btn:hover,
.msgv2-top-toggles .msgv2-toggle-btn:focus {
    border-color: #5fc4da;
    background: #5fc4da;
    color: #fff;
}
.msgv2-top-toggles .msgv2-toggle-btn.active,
.msgv2-top-toggles .msgv2-toggle-btn.active:hover,
.msgv2-top-toggles .msgv2-toggle-btn.active:focus {
    border-color: #343a40;
    background: #343a40;
    color: #fff;
}
.msgv2-top-toggles .msgv2-toggle-btn input[type='checkbox'] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

/* Boolean "everyone" toggles — keep them on the same row to save vertical space. */
.msgv2-recipient-row[data-cap='allow_whole_school'],
.msgv2-recipient-row[data-cap='allow_all_teachers'],
.msgv2-recipient-row[data-cap='allow_all_parents'] {
    display: inline-block;
    margin-right: 18px;
    margin-bottom: 8px;
    margin-top: 8px;
    vertical-align: middle;
}
.msgv2-recipient-row[data-cap='allow_whole_school'].hide,
.msgv2-recipient-row[data-cap='allow_all_teachers'].hide,
.msgv2-recipient-row[data-cap='allow_all_parents'].hide {
    display: none;
}

/* "Send by group" toggle + collapsible group block. */
.msgv2-group-toggle-label {
    font-weight: 500;
    color: #334155;
}
.msgv2-group-block {
    padding: 8px 12px;
    margin-bottom: 10px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}

/* "Send by grade and class" toggle + collapsible block. */
.msgv2-grade-class-toggle-label {
    font-weight: 500;
    color: #334155;
}
.msgv2-grade-class-block {
    padding: 8px 12px;
    margin-bottom: 10px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}

/* "Send by teachers" toggle + collapsible block. */
.msgv2-teachers-toggle-label {
    font-weight: 500;
    color: #334155;
}
.msgv2-teachers-block {
    padding: 8px 12px;
    margin-bottom: 10px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}

.msgv2-grade-picker {
    display: flex;
    align-items: stretch;
    flex-direction: row-reverse;
    gap: 8px;
}

.msgv2-grade-picker #msgv2RecipGrades {
    flex: 1;
}

#msgv2AddGradeBtn {
    min-width: 72px;
    align-self: center;
}

.msgv2-sent-grade-class {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 2px;
}

.msgv2-class-picker {
    display: flex;
    align-items: stretch;
    flex-direction: row-reverse;
    gap: 8px;
}

.msgv2-class-picker #msgv2RecipClasses {
    flex: 1;
}

#msgv2AddClassBtn {
    min-width: 72px;
    align-self: center;
}

.msgv2-teacher-picker {
    display: flex;
    align-items: stretch;
    flex-direction: row-reverse;
    gap: 8px;
}

.msgv2-teacher-picker #msgv2RecipTeachers {
    flex: 1;
}

#msgv2AddTeacherBtn {
    min-width: 72px;
    align-self: center;
}

.msgv2-sent-teachers {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 2px;
}

.msgv2-user-search-wrap {
    position: relative;
}

.msgv2-user-search-results {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 6px);
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
    max-height: 260px;
    overflow-y: auto;
    z-index: 30;
}

.msgv2-user-result-item {
    width: 100%;
    border: 0;
    border-bottom: 1px solid #e2e8f0;
    background: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    text-align: left;
    cursor: pointer;
}

.msgv2-user-result-item:last-child {
    border-bottom: 0;
}

.msgv2-user-result-item:hover {
    background: #f8fafc;
}

.msgv2-user-result-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid #d1d5db;
    flex-shrink: 0;
}

.msgv2-user-result-avatar--fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    background: #f1f5f9;
}

.msgv2-user-result-text {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.msgv2-user-result-name {
    font-size: 13px;
    color: #0f172a;
    font-weight: 600;
    line-height: 1.2;
}

.msgv2-user-result-email {
    font-size: 12px;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msgv2-user-result-empty {
    padding: 10px;
    font-size: 12px;
    color: #64748b;
}

.sent-to-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    background: #eef6fb;
    color: #1e293b;
    font-size: 12px;
    line-height: 1.2;
}

.sent-to-badge--class {
    background: #f0faf0;
    border-color: #a7c8a7;
    color: #1a3a1a;
}

.sent-to-badge .close-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    cursor: pointer;
    font-weight: 700;
    color: #475569;
}

.sent-to-badge .close-icon:after {
    content: 'x';
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin-bottom: 2px;
    width: 16px;
    height: 16px;
}

.sent-to-badge .close-icon:hover {
    background: #cbd5e1;
    color: #0f172a;
}

.msgv2-checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #1e293b;
    cursor: pointer;
    margin: 0;
}
.msgv2-checkbox-label input[type='checkbox'] {
    margin: 0;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.msgv2-checkbox-label.is-disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.msgv2-checkbox-label.is-disabled span {
    text-decoration: line-through;
}

.msgv2-field-label {
    display: block;
    font-size: 14px;
    color: #71cde0;
    margin-bottom: 8px;
    font-weight: 700;
}

.msgv2-multiselect {
    width: 100%;
    min-height: 70px;
}

.msgv2-field-hint {
    font-size: 12px;
    color: #64748b;
    margin: 4px 0 0;
    font-style: italic;
}

.msgv2-recipients-error,
.msgv2-form-error {
    color: #b91c1c;
    background: #fef2f2;
    border: 1px solid #fecaca;
    padding: 8px 10px;
    border-radius: 4px;
    font-size: 13px;
    margin: 8px 0 0;
}

/* ---- Compose form ---- */
.msgv2-form-row {
    margin-bottom: 14px;
}

.msgv2-editor {
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #fff;
    min-height: 220px;
    overflow: hidden;
}
.msgv2-editor .pell-content {
    min-height: 180px;
    padding: 10px;
    outline: none;
}
.msgv2-editor-compact {
    min-height: 140px;
}
.msgv2-editor-compact .pell-content {
    min-height: 100px;
}

/* ---- Inline reply box ---- */
.msgv2-reply-box {
    border-top: 1px solid #eef0f3;
    padding: 12px 16px 16px;
    background: #f8fafc;
}
.msgv2-reply-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 600;
    color: #475569;
    margin-bottom: 8px;
}
.msgv2-reply-footer {
    margin-top: 10px;
    text-align: right;
}

/* ---- Forward quote ---- */
.msgv2-fwd-quote {
    border-left: 3px solid #cbd5e1;
    margin: 8px 0;
    padding: 4px 12px;
    color: #475569;
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
    .msgv2-modal {
        padding: 0;
        align-items: stretch;
    }
    .msgv2-modal-dialog {
        max-width: 100%;
        border-radius: 0;
        min-height: 100vh;
    }
    .msgv2-modal-body {
        max-height: none;
    }
}
