/* ═══════════════════════════════════════════════════════════════════
   NEUROCUOLE — 4. Communications & Shared Mailbox
   (nc-mailbox, mb-*, nc-comms, nc-compose-card, nc-timeline)
   ═══════════════════════════════════════════════════════════════════ */

/* ── Shared Mailbox widget (nc-mailbox) ───────────────────────────── */
.nc-mailbox { display: grid; grid-template-columns: 340px 1fr; border: 1px solid var(--nc-grey-100); border-radius: 10px; overflow: hidden; min-height: 520px; background: var(--nc-white); }
.nc-mailbox-list { border-right: 1px solid var(--nc-grey-100); overflow-y: auto; }
.nc-mailbox-row { padding: 14px 16px; border-bottom: 1px solid var(--nc-grey-100); cursor: pointer; transition: background 0.15s; position: relative; }
.nc-mailbox-row:hover { background: var(--nc-grey-50); }
.nc-mailbox-row--active { background: #eff8f8; border-left: 3px solid var(--nc-teal-600); }
.nc-mailbox-row--unread .nc-mailbox-subject { font-weight: 700; }
.nc-mailbox-row-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; }
.nc-mailbox-sender { font-size: .78rem; font-weight: 600; color: var(--nc-grey-600); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nc-mailbox-subject { font-size: .88rem; color: var(--nc-grey-900); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 2px; }
.nc-mailbox-preview { font-size: .78rem; color: var(--nc-grey-400); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nc-mailbox-date { font-size: .72rem; color: var(--nc-grey-400); position: absolute; top: 14px; right: 14px; }
.nc-badge-unread { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--nc-teal-600); flex-shrink: 0; }
.nc-badge-broadcast { display: inline-block; font-size: .65rem; font-weight: 600; background: #e0f7f7; color: var(--nc-teal-700); border-radius: 4px; padding: 1px 5px; flex-shrink: 0; }
.nc-mailbox-detail { display: flex; flex-direction: column; padding: 28px 28px 20px; overflow-y: auto; }
.nc-mailbox-detail-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--nc-grey-400); font-size: .9rem; }
.nc-mailbox-detail-header { margin-bottom: 18px; border-bottom: 1px solid var(--nc-grey-100); padding-bottom: 14px; }
.nc-mailbox-detail-header h2 { font-size: 1.1rem; font-weight: 700; color: var(--nc-grey-900); margin: 0 0 6px; }
.nc-mailbox-detail-meta { display: flex; flex-wrap: wrap; gap: 12px; font-size: .8rem; color: var(--nc-grey-500); }
.nc-mailbox-detail-body { flex: 1; font-size: .92rem; line-height: 1.65; color: var(--nc-grey-800); white-space: pre-wrap; margin-bottom: 20px; }
.nc-mailbox-detail-actions { display: flex; gap: 10px; padding-top: 12px; border-top: 1px solid var(--nc-grey-100); }
.nc-recipient-list { display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow-y: auto; border: 1px solid var(--nc-grey-100); border-radius: 6px; padding: 8px 10px; background: var(--nc-white); }
.nc-recipient-item { display: flex; align-items: center; gap: 8px; font-size: .85rem; cursor: pointer; color: var(--nc-grey-800); }
.nc-recipient-item input[type="checkbox"] { cursor: pointer; }

/* ── Shared mailbox shell (mb-*) ──────────────────────────────────── */
.mb-shell { display: flex; flex-direction: column; height: calc(100vh - 60px); background: var(--nc-white); overflow: hidden; }
.mb-topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 20px; border-bottom: 1px solid var(--nc-grey-100); background: var(--nc-white); flex-shrink: 0; gap: 12px; }
.mb-topbar-left { display: flex; align-items: center; gap: 10px; }
.mb-topbar-title { font-size: 1.1rem; font-weight: 600; color: var(--nc-grey-900); }
.mb-topbar-address { font-size: .82rem; color: var(--nc-grey-500); background: var(--nc-grey-50); border: 1px solid var(--nc-grey-100); border-radius: 20px; padding: 2px 10px; }
.mb-topbar-right { display: flex; align-items: center; gap: 8px; }
.mb-sync-msg { font-size: .8rem; color: var(--nc-success); font-weight: 500; }
.mb-tabbar { display: flex; gap: 0; border-bottom: 1px solid var(--nc-grey-100); flex-shrink: 0; padding: 0 20px; }
.mb-tab { background: none; border: none; border-bottom: 2px solid transparent; padding: 8px 16px; font-size: .88rem; color: var(--nc-grey-500); cursor: pointer; display: flex; align-items: center; gap: 6px; transition: color .15s, border-color .15s; }
.mb-tab:hover { color: var(--nc-grey-900); }
.mb-tab--active { color: #3b82f6; border-bottom-color: #3b82f6; font-weight: 600; }
.mb-unread-badge { background: #3b82f6; color: #fff; border-radius: 10px; padding: 1px 6px; font-size: .72rem; font-weight: 700; line-height: 1.4; }
.mb-body { display: flex; flex: 1; overflow: hidden; }
.mb-list { width: 320px; min-width: 260px; border-right: 1px solid var(--nc-grey-100); overflow-y: auto; flex-shrink: 0; }
.mb-item { padding: 12px 16px; border-bottom: 1px solid var(--nc-grey-50); cursor: pointer; transition: background .12s; }
.mb-item:hover { background: var(--nc-grey-50); }
.mb-item--active { background: #eff6ff !important; border-left: 3px solid #3b82f6; }
.mb-item--unread .mb-item-from,
.mb-item--unread .mb-item-subject { font-weight: 700; color: var(--nc-grey-900); }
.mb-item-row1 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.mb-item-from { font-size: .82rem; color: var(--nc-grey-700); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.mb-item-date { font-size: .75rem; color: var(--nc-grey-400); flex-shrink: 0; }
.mb-item-subject { font-size: .88rem; color: var(--nc-grey-800); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 2px; }
.mb-item-preview { font-size: .78rem; color: var(--nc-grey-400); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mb-detail { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.mb-detail-header { padding: 20px 24px 14px; border-bottom: 1px solid var(--nc-grey-100); flex-shrink: 0; }
.mb-detail-subject { font-size: 1.1rem; font-weight: 600; color: var(--nc-grey-900); margin: 0 0 10px; }
.mb-detail-meta { display: flex; flex-direction: column; gap: 3px; margin-bottom: 12px; }
.mb-detail-meta-row { display: flex; gap: 8px; font-size: .82rem; color: var(--nc-grey-600); }
.mb-detail-meta-label { min-width: 40px; font-weight: 600; color: var(--nc-grey-400); }
.mb-detail-actions { display: flex; gap: 8px; }
.mb-detail-body { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.mb-detail-iframe { flex: 1; width: 100%; border: none; min-height: 400px; }
.mb-detail-plaintext { padding: 20px 24px; font-size: .88rem; color: var(--nc-grey-700); white-space: pre-wrap; font-family: inherit; margin: 0; }
.mb-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 20px; gap: 12px; color: var(--nc-grey-400); font-size: .88rem; text-align: center; }
.mb-empty--detail { flex: 1; }

/* ── Patient communications (nc-comms) ───────────────────────────── */
.nc-comms-list { display: flex; flex-direction: column; border-bottom: 1px solid var(--nc-grey-100); max-height: 280px; overflow-y: auto; }
.nc-comms-item { display: flex; flex-direction: column; padding: 10px 16px; border-bottom: 1px solid var(--nc-grey-50); cursor: pointer; transition: background .12s; }
.nc-comms-item:hover { background: var(--nc-grey-50); }
.nc-comms-item--active { background: #eff6ff !important; }
.nc-comms-item--unread .nc-comms-subject { font-weight: 700; }
.nc-comms-item-row1 { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.nc-comms-direction { font-size: .72rem; font-weight: 700; border-radius: 4px; padding: 1px 5px; flex-shrink: 0; }
.nc-comms-direction--in  { background: #dbeafe; color: #1d4ed8; }
.nc-comms-direction--out { background: #dcfce7; color: #15803d; }
.nc-comms-from    { font-size: .82rem; color: var(--nc-grey-600); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.nc-comms-date    { font-size: .75rem; color: var(--nc-grey-400); flex-shrink: 0; }
.nc-comms-subject { font-size: .88rem; color: var(--nc-grey-800); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nc-comms-preview { font-size: .78rem; color: var(--nc-grey-400); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nc-comms-detail { border-top: 1px solid var(--nc-grey-100); }
.nc-comms-detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--nc-grey-100); background: var(--nc-grey-50); }
.nc-comms-detail-meta { display: flex; flex-direction: column; gap: 2px; font-size: .82rem; color: var(--nc-grey-600); }
.nc-comms-detail-meta strong { font-size: .92rem; color: var(--nc-grey-900); }
.nc-comms-detail-body { min-height: 200px; }
.nc-comms-iframe    { width: 100%; min-height: 250px; border: none; display: block; }
.nc-comms-plaintext { padding: 16px; font-size: .88rem; color: var(--nc-grey-700); white-space: pre-wrap; font-family: inherit; margin: 0; }

.nc-comms-page-header  { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.nc-comms-page-title   { font-size: 1.2rem; font-weight: 700; color: var(--nc-grey-900); margin: 0 0 2px; }
.nc-comms-page-mailbox { font-size: .8rem; color: var(--nc-grey-500); }

/* ── Compose card (nc-compose-card) ───────────────────────────────── */
.nc-compose-card { background: #fff; border: 1px solid var(--nc-grey-200); border-radius: 12px; box-shadow: 0 4px 24px rgba(0,0,0,.07), 0 1px 4px rgba(0,0,0,.04); margin-bottom: 22px; overflow: hidden; }
.nc-compose-card-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; background: var(--nc-grey-50); border-bottom: 1px solid var(--nc-grey-100); }
.nc-compose-card-title { font-size: .92rem; font-weight: 700; color: var(--nc-grey-800); letter-spacing: -.01em; }
.nc-compose-card-close { background: none; border: none; font-size: .95rem; cursor: pointer; color: var(--nc-grey-400); width: 28px; height: 28px; border-radius: 6px; display: flex; align-items: center; justify-content: center; transition: background .12s, color .12s; }
.nc-compose-card-close:hover { background: var(--nc-grey-100); color: var(--nc-grey-700); }
.nc-compose-channels { display: flex; padding: 10px 20px 0; border-bottom: 1px solid var(--nc-grey-100); overflow-x: auto; }
.nc-compose-channel-tab { display: flex; align-items: center; gap: 5px; padding: 7px 14px; font-size: .8rem; font-weight: 500; color: var(--nc-grey-500); background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; transition: color .12s, border-color .12s; margin-bottom: -1px; }
.nc-compose-channel-tab:hover { color: var(--nc-grey-800); }
.nc-compose-channel-tab--active { color: #3b82f6; border-bottom-color: #3b82f6; font-weight: 600; }
.nc-compose-channel-icon { font-size: 1rem; }
.nc-compose-card-body { padding: 0; }
.nc-compose-field-row { display: flex; align-items: stretch; border-bottom: 1px solid var(--nc-grey-100); min-height: 44px; }
.nc-compose-field { display: flex; align-items: center; flex: 1; }
.nc-compose-field-prefix { font-size: .78rem; font-weight: 600; color: var(--nc-grey-400); text-transform: uppercase; letter-spacing: .06em; padding: 0 14px; white-space: nowrap; min-width: 72px; border-right: 1px solid var(--nc-grey-100); align-self: stretch; display: flex; align-items: center; }
.nc-compose-inline-input { flex: 1; border: none; outline: none; padding: 10px 14px; font-size: .88rem; color: var(--nc-grey-800); background: transparent; appearance: none; -webkit-appearance: none; font-family: inherit; }
.nc-compose-inline-input::placeholder { color: var(--nc-grey-300); }
.nc-compose-inline-input:focus { background: #eff6ff; }
select.nc-compose-inline-input { background: transparent; cursor: pointer; }
.nc-compose-textarea { width: 100%; border: none; outline: none; padding: 14px 20px; font-size: .9rem; color: var(--nc-grey-800); resize: vertical; min-height: 148px; font-family: inherit; line-height: 1.6; background: transparent; box-sizing: border-box; border-bottom: 1px solid var(--nc-grey-100); }
.nc-compose-textarea::placeholder { color: var(--nc-grey-300); }
.nc-compose-textarea:focus { background: #eff6ff; }
.nc-compose-attachments { padding: 10px 20px 12px; border-bottom: 1px solid var(--nc-grey-100); background: var(--nc-grey-50); }
.nc-compose-attach-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.nc-compose-attach-btn { display: inline-flex; align-items: center; gap: 5px; padding: 5px 12px; border-radius: 6px; border: 1px solid var(--nc-grey-200); background: #fff; font-size: .8rem; color: var(--nc-grey-600); cursor: pointer; font-family: inherit; transition: border-color .12s, color .12s, background .12s; }
.nc-compose-attach-btn:hover:not(:disabled) { border-color: #93c5fd; color: #2563eb; background: #eff6ff; }
.nc-compose-attach-btn:disabled { opacity: .45; cursor: not-allowed; }
.nc-compose-alert { margin: 0 20px; padding: 9px 14px; border-radius: 6px; font-size: .83rem; font-weight: 500; }
.nc-compose-alert--error   { background: #fef2f2; color: #b91c1c; border-left: 3px solid #f87171; }
.nc-compose-alert--success { background: #f0fdf4; color: #166534; border-left: 3px solid #4ade80; }
.nc-compose-card-footer { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px 10px 20px; background: var(--nc-grey-50); border-top: 1px solid var(--nc-grey-100); gap: 10px; }
.nc-compose-footer-left  { flex: 1; overflow: hidden; }
.nc-compose-footer-right { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.nc-compose-from-badge { font-size: .77rem; color: var(--nc-grey-400); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nc-compose-action-btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 16px; border-radius: 7px; font-size: .83rem; font-weight: 600; cursor: pointer; font-family: inherit; border: 1px solid transparent; transition: all .14s; white-space: nowrap; }
.nc-compose-action-btn--ghost   { background: none; border-color: transparent; color: var(--nc-grey-500); }
.nc-compose-action-btn--ghost:hover { color: var(--nc-grey-800); background: var(--nc-grey-100); }
.nc-compose-action-btn--outline { background: #fff; border-color: var(--nc-grey-300); color: var(--nc-grey-700); }
.nc-compose-action-btn--outline:hover:not(:disabled) { border-color: #93c5fd; color: #1d4ed8; background: #eff6ff; }
.nc-compose-action-btn--primary { background: #3b82f6; border-color: #3b82f6; color: #fff; box-shadow: 0 1px 4px rgba(59,130,246,.25); }
.nc-compose-action-btn--primary:hover:not(:disabled) { background: #1d4ed8; border-color: #1d4ed8; }
.nc-compose-action-btn:disabled { opacity: .5; cursor: not-allowed; }
.nc-compose-spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: nc-spin .6s linear infinite; }
@keyframes nc-spin { to { transform: rotate(360deg); } }

/* ── Filter chips ─────────────────────────────────────────────────── */
.nc-comms-filterbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.nc-comms-filterbar-label { font-size: .82rem; font-weight: 600; color: var(--nc-grey-500); margin-right: 2px; }
.nc-comms-filterbar-count { margin-left: auto; font-size: .8rem; color: var(--nc-grey-400); }
.nc-comms-filter-chip { background: var(--nc-grey-100); border: 1px solid var(--nc-grey-200); border-radius: 20px; padding: 3px 12px; font-size: .8rem; color: var(--nc-grey-600); cursor: pointer; transition: all .12s; }
.nc-comms-filter-chip:hover { background: var(--nc-grey-200); }
.nc-comms-filter-chip--active { background: #3b82f6; border-color: #3b82f6; color: #fff; font-weight: 600; }
.nc-comms-empty { text-align: center; padding: 48px 20px; color: var(--nc-grey-400); }
.nc-comms-empty p { margin: 0 0 6px; }

/* ── Communications timeline ──────────────────────────────────────── */
.nc-timeline { display: flex; flex-direction: column; }
.nc-timeline-item { display: flex; cursor: pointer; position: relative; }
.nc-timeline-item:hover .nc-timeline-content { background: var(--nc-grey-50); }
.nc-timeline-item--selected .nc-timeline-content { background: #eff6ff; border-left: 2px solid #3b82f6; }
.nc-timeline-icon-col { display: flex; flex-direction: column; align-items: center; width: 48px; flex-shrink: 0; padding-top: 14px; }
.nc-timeline-icon { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: .95rem; flex-shrink: 0; z-index: 1; }
.nc-timeline-icon--email  { background: #dbeafe; }
.nc-timeline-icon--sms    { background: #dcfce7; }
.nc-timeline-icon--phone  { background: #fef9c3; }
.nc-timeline-icon--post   { background: #fce7f3; }
.nc-timeline-icon--app    { background: #ede9fe; }
.nc-timeline-icon--secure { background: #fee2e2; }
.nc-timeline-icon--other  { background: var(--nc-grey-100); }
.nc-timeline-line { flex: 1; width: 2px; background: var(--nc-grey-100); margin-top: 4px; min-height: 20px; }
.nc-timeline-item:last-child .nc-timeline-line { display: none; }

/* ── Attachment chips ─────────────────────────────────────────────── */
.nc-attachment-list { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; align-items: center; }
.nc-attachment-list-label { font-size: .78rem; color: var(--nc-text-muted); font-weight: 600; }
.nc-attachment-chip { display: inline-flex; align-items: center; gap: .3rem; padding: .25rem .6rem; border: 1px solid var(--nc-grey-200); border-radius: 20px; background: var(--nc-grey-50); font-size: .78rem; cursor: pointer; transition: background .15s, border-color .15s; color: var(--nc-text); }
.nc-attachment-chip:hover { background: #eff6ff; border-color: #3b82f6; color: #1d4ed8; }

/* ── Attachment viewer drawer ─────────────────────────────────────── */
.nc-viewer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 800; }
.nc-viewer-drawer { position: fixed; top: 0; right: 0; width: min(680px, 96vw); height: 100vh; background: var(--nc-white); box-shadow: -4px 0 24px rgba(0,0,0,.18); z-index: 801; display: flex; flex-direction: column; }
.nc-viewer-drawer-header { display: flex; align-items: center; justify-content: space-between; padding: .85rem 1.1rem; border-bottom: 1px solid var(--nc-grey-200); gap: .75rem; }
.nc-viewer-drawer-title { font-weight: 600; font-size: .93rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nc-viewer-drawer-body { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.nc-viewer-close { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--nc-text-muted); padding: .2rem .4rem; border-radius: 4px; line-height: 1; }
.nc-viewer-close:hover { background: var(--nc-grey-100); color: var(--nc-text); }
.nc-viewer-image { max-width: 100%; max-height: 100%; object-fit: contain; display: block; margin: auto; padding: 1rem; }
.nc-viewer-iframe { width: 100%; height: 100%; border: none; flex: 1; }
.nc-viewer-media { max-width: 100%; max-height: 100%; display: block; margin: 1rem auto; }
.nc-viewer-download { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; height: 100%; padding: 2rem; text-align: center; }
.nc-timeline-content { flex: 1; padding: 12px 14px 12px 10px; border-bottom: 1px solid var(--nc-grey-50); border-radius: 0 6px 6px 0; transition: background .1s; min-width: 0; }
.nc-timeline-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.nc-timeline-header-left  { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.nc-timeline-header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.nc-timeline-channel-badge { font-size: .72rem; font-weight: 700; border-radius: 4px; padding: 2px 6px; flex-shrink: 0; }
.nc-timeline-channel-badge--email { background: #dbeafe; color: #1d4ed8; }
.nc-timeline-channel-badge--sms   { background: #dcfce7; color: #15803d; }
