/* Styles for the single-message view modal and the super-admin compose modal.
   (Shared message-list row styles live in css/control/notification_bell.css.) */

/* ---- View a single message ---- */
/* A comfortable, consistent reading width so short messages don't render as a tiny box
   (the modal is fit-content, so the content width drives the modal width). */
.msg-view {
    padding: 4px 6px 10px;
    width: min(520px, 86vw);
    max-width: 100%;
}

.msg-view-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    color: #7a7a7a;
    font-size: 12.5px;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.msg-view-meta strong {
    color: #444;
}

.msg-view-body {
    font-size: 14.5px;
    line-height: 1.6;
    color: #2b2b2b;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.msg-view-body p {
    margin: 0 0 10px;
}

.msg-view-body ul,
.msg-view-body ol {
    margin: 0 0 10px;
    padding-left: 22px;
}

.msg-view-body a {
    color: #007e82;
    text-decoration: underline;
}

.msg-view-body blockquote {
    margin: 0 0 10px;
    padding: 6px 14px;
    border-left: 3px solid #009fa4;
    background: rgba(0, 159, 164, 0.06);
    color: #444;
}

/* ---- Action buttons rendered from {action:…} tokens (see scripts/control/message_actions.js) ----
   Inline so an action can sit mid-sentence ("…then {action:helpTopic?…} to finish"), but clearly a
   control rather than a link, since clicking it opens something rather than navigating away. */
.msg-action-link {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin: 2px 1px;
    padding: 4px 12px;
    border: 1px solid rgba(0, 159, 164, 0.45);
    border-radius: 999px;
    background: rgba(0, 159, 164, 0.08);
    color: #007e82;
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.35;
    text-align: left;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}

.msg-action-link:hover {
    background: rgba(0, 159, 164, 0.18);
    border-color: #007e82;
}

.msg-action-link:active {
    background: rgba(0, 159, 164, 0.26);
}

.msg-action-link i {
    font-size: 12px;
    opacity: 0.85;
}

/* An action this build doesn't know about — shown inert so the message still reads sensibly. */
.msg-action-link--unknown {
    border-color: rgba(0, 0, 0, 0.18);
    background: rgba(0, 0, 0, 0.04);
    color: #8a8a8a;
    cursor: not-allowed;
}

/* ---- Data slots rendered from {query:…} tokens (see scripts/control/message_queries.js) ----
   These sit mid-sentence and become ordinary words, so the resolved state carries no styling of
   its own — only the waiting state is visible. */
.msg-query {
    display: inline;
}

/* Sized in em so it matches the line it's sitting on, and inline-block so it can't wrap oddly.
   The width is a guess at "a couple of words" — the text that replaces it decides the real width. */
.msg-query-skeleton {
    display: inline-block;
    width: 3.4em;
    height: 0.75em;
    vertical-align: baseline;
    border-radius: 3px;
    background: linear-gradient(90deg,
        rgba(0, 0, 0, 0.07) 25%,
        rgba(0, 0, 0, 0.14) 37%,
        rgba(0, 0, 0, 0.07) 63%);
    background-size: 400% 100%;
    animation: msgQueryShimmer 1.3s ease infinite;
}

@keyframes msgQueryShimmer {
    0% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0 50%;
    }
}

/* The value arriving shouldn't read as a jump-cut, but it mustn't hold up reading either. */
.msg-query--resolved {
    animation: msgQueryFadeIn 0.25s ease;
}

@keyframes msgQueryFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Compose preview: the author's own numbers aren't what the recipient will see, so show what the
   token IS rather than resolving it against the wrong person's data. */
.msg-query--inert {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 1px 8px;
    border: 1px dashed rgba(0, 159, 164, 0.5);
    border-radius: 20px;
    background: rgba(0, 159, 164, 0.07);
    color: #007e82;
    font-size: 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    cursor: help;
}

.msg-view-loading {
    padding: 30px;
    text-align: center;
    color: #8a8a8a;
}

.msg-view-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 18px;
    padding-top: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.msg-view-delete {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid rgba(229, 51, 47, 0.4);
    background: #ffffff;
    color: #e5332f;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.msg-view-delete:hover {
    background: #e5332f;
    color: #ffffff;
}

.msg-view-delete:disabled {
    opacity: 0.6;
    cursor: default;
}

/* ---- Compose (super-admin) ---- */
/* Composer + live preview, side by side. The modal is fit-content, so the shell's width is what
   sizes the window: it grows when the preview is shown and shrinks back when it's hidden. */
.msg-compose-shell {
    display: flex;
    align-items: stretch;
    gap: 20px;
}

.msg-compose {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: min(620px, 90vw);
    padding: 4px 4px 6px;
}

.msg-compose-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.msg-compose-field > label {
    font-size: 12.5px;
    font-weight: 600;
    color: #555;
}

/* "Show sender" toggle — a plain checkbox + label, so it reads as an inline option. */
.msg-toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    color: #444;
    cursor: pointer;
    user-select: none;
}

.msg-toggle-label input {
    width: 16px;
    height: 16px;
    accent-color: #009fa4;
    cursor: pointer;
}

.msg-compose-title-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid rgba(0, 0, 0, 0.18);
    border-radius: 8px;
    font-size: 14px;
}

/* Rich-text editor */
.msg-editor-toolbar {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    padding: 6px;
    border: 1px solid rgba(0, 0, 0, 0.18);
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    background: #f7f7f7;
}

.msg-editor-btn {
    min-width: 30px;
    height: 28px;
    padding: 0 8px;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: #444;
}

.msg-editor-btn:hover {
    background: rgba(0, 0, 0, 0.08);
}

.msg-editor-btn.is-active {
    background: rgba(0, 159, 164, 0.15);
    border-color: rgba(0, 159, 164, 0.4);
    color: #007e82;
}

.msg-editor {
    min-height: 150px;
    max-height: 40vh;
    overflow-y: auto;
    padding: 10px 12px;
    border: 1px solid rgba(0, 0, 0, 0.18);
    border-radius: 0 0 8px 8px;
    font-size: 14px;
    line-height: 1.55;
    outline: none;
    background: #fff;
}

.msg-editor:empty::before {
    content: attr(data-placeholder);
    color: #a5a5a5;
}

/* WYSIWYG parity: the editor renders blocks the same way the view modal does below. */
.msg-editor p {
    margin: 0 0 10px;
}

.msg-editor ul,
.msg-editor ol {
    margin: 0 0 10px;
    padding-left: 22px;
}

.msg-editor a {
    color: #007e82;
    text-decoration: underline;
}

/* Scope radios */
.msg-scope-options {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.msg-scope-option {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border: 1px solid rgba(0, 0, 0, 0.18);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    user-select: none;
}

.msg-scope-option.is-active {
    border-color: #009fa4;
    background: rgba(0, 159, 164, 0.08);
    color: #007e82;
    font-weight: 600;
}

.msg-scope-option input {
    accent-color: #009fa4;
}

/* Recipient picker (user search / org select) */
.msg-recipient-picker {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.msg-recipient-picker.is-hidden {
    display: none;
}

.msg-recipient-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid rgba(0, 0, 0, 0.18);
    border-radius: 8px;
    font-size: 14px;
}

/* In-flow (not absolute) so it can't be clipped by the fit-content modal — the modal grows and
   the content area scrolls, and _ensureResultsVisible() scrolls it into view. */
.msg-recipient-results {
    margin-top: 6px;
    max-height: 220px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
    display: none;
}

.msg-recipient-results.is-open {
    display: block;
}

.msg-recipient-result {
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
}

.msg-recipient-result:hover,
.msg-recipient-result.is-highlighted {
    background: rgba(0, 159, 164, 0.1);
}

.msg-recipient-result-sub {
    font-size: 11.5px;
    color: #888;
}

.msg-recipient-selected {
    font-size: 12.5px;
    color: #007e82;
    font-weight: 600;
}

.msg-recipient-selected:empty {
    display: none;
}

/* Multi-select users: search input + chips for the chosen users. */
.msg-user-search-wrap {
    position: relative;
}

.msg-user-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.msg-user-chips:not(:empty) {
    margin-bottom: 8px;
}

.msg-user-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(0, 159, 164, 0.12);
    color: #007e82;
    border: 1px solid rgba(0, 159, 164, 0.3);
    border-radius: 16px;
    padding: 3px 6px 3px 12px;
    font-size: 12.5px;
    font-weight: 600;
}

/* Organisation chips read as a different kind of recipient (a whole group, not a person). */
.msg-user-chip-org {
    background: rgba(120, 90, 200, 0.10);
    border-color: rgba(120, 90, 200, 0.32);
    color: #5b46a3;
}

.msg-user-chip-org .msg-user-chip-x {
    color: #5b46a3;
}

/* Inline clarification on the Organisations label — a whole-org send isn't obvious otherwise. */
.msg-recipient-hint {
    margin-left: 6px;
    font-size: 11.5px;
    font-weight: 400;
    color: #9a9a9a;
}

.msg-user-chip-x {
    border: 0;
    background: transparent;
    color: #007e82;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 4px;
    border-radius: 50%;
}

.msg-user-chip-x:hover {
    color: #e5332f;
}

/* Actions */
.msg-compose-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 2px;
}

.msg-compose-btn {
    padding: 8px 18px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
}

.msg-compose-btn-cancel {
    background: transparent;
    border-color: rgba(0, 0, 0, 0.2);
    color: #555;
}

.msg-compose-btn-send {
    background: linear-gradient(180deg, #009fa4 0%, #007e82 100%);
    color: #fff;
}

.msg-compose-btn-send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ---- Live preview panel ---- */
/* Toggle sits in the teal header, to the left of the close button (30px wide at right:12px, and
   the header pads 20px), so it needs that much clearance. Same 30px box as the close button. */
.msg-compose-preview-toggle {
    flex: 0 0 auto;
    margin-right: 30px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 30px;
    padding: 0 12px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.85);
    font-size: 13px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}

.msg-compose-preview-toggle:hover {
    background: rgba(255, 255, 255, 0.26);
    border-color: rgba(255, 255, 255, 0.6);
    color: #fff;
}

/* On = filled, so the current state is readable at a glance rather than from the icon alone. */
.msg-compose-preview-toggle.is-active {
    background: #fff;
    border-color: #fff;
    color: #007e82;
}

/* The close button is absolutely positioned at top:12px, ~6px above the centre of the header's
   title row. Drop it onto the row so it lines up with the toggle beside it. */
.modal-window-container.msg-compose-modal-container > .modal-window-close {
    top: 18px;
}

.msg-compose-preview {
    flex: 0 0 330px;
    width: 330px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-left: 20px;
    border-left: 1px solid rgba(0, 0, 0, 0.09);
}

.msg-compose-shell--no-preview .msg-compose-preview {
    display: none;
}

.msg-compose-preview-label {
    font-size: 12.5px;
    font-weight: 600;
    color: #555;
}

/* Echoes the view modal's card so what's shown here reads as the finished message. */
.msg-compose-preview-card {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 14px 16px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 10px;
    background: #fcfdfd;
}

.msg-compose-preview-title {
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    font-size: 15px;
    font-weight: 600;
    color: #2b2b2b;
    word-break: break-word;
}

.msg-compose-preview-title.is-placeholder,
.msg-compose-preview-empty {
    color: #a5a5a5;
    font-weight: 400;
}

/* Preview actions look identical to the real ones but do nothing — see MessageActions render(inert). */
.msg-action-link--inert {
    cursor: default;
}

/* Not enough width for two columns: stack the preview under the composer instead of squeezing it. */
@media (max-width: 1100px) {
    .msg-compose-shell {
        flex-direction: column;
    }

    .msg-compose-preview {
        flex: 0 0 auto;
        width: auto;
        padding-left: 0;
        padding-top: 16px;
        border-left: 0;
        border-top: 1px solid rgba(0, 0, 0, 0.09);
    }

    .msg-compose-preview-card {
        max-height: 260px;
    }
}

/* ---- Insert-an-action picker (MessageActionModal) ---- */
/* Sits apart from the formatting commands: it inserts content rather than styling a selection. */
.msg-editor-btn-action {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #007e82;
    font-weight: 600;
}

/* Sits beside the Action button, which carries the margin-left:auto that floats the pair right —
   a second auto margin here would split the free space and drive them apart. */
.msg-editor-btn-query {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #007e82;
    font-weight: 600;
}

/* The literal token the picker will type into the message. */
.msg-query-token-preview {
    display: block;
    padding: 8px 10px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.03);
    color: #007e82;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    word-break: break-all;
}

.msg-action-form {
    width: min(430px, 86vw);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.msg-action-select {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid rgba(0, 0, 0, 0.18);
    border-radius: 8px;
    background: #fff;
    font-size: 14px;
    color: #2b2b2b;
}

.msg-action-select:disabled {
    color: #9a9a9a;
    background: #f6f6f6;
}

.msg-action-description {
    margin-top: 6px;
    color: #7a7a7a;
    font-size: 12.5px;
    line-height: 1.45;
}

.msg-action-optional {
    color: #9a9a9a;
    font-weight: 400;
}

.msg-action-empty {
    padding: 24px;
    color: #8a8a8a;
    text-align: center;
}
