/*
 * RiseMail Composer - gebaut wie ein Mailprogramm: eine ruhige weisse Flaeche,
 * nur duenne Trennlinien, keine Karten, kein Grau pro Sektion.
 *
 *   Kopf (Titel + Kontextzeile, x)
 *   ─ An (Chips) ................ CC  BCC
 *   ─ Betreff
 *   ─ Nachricht (dominant, scrollt allein) + eingeklappte Signatur
 *   ─ B I U • Liste Link (leise, hell bei Fokus im Text)
 *   ─ Anhangzeilen (Fach-PDF + eigene Uploads)
 *   ─ Footer (Speicherstatus ...... Datei anhängen  Senden), steht immer
 *
 * Layout-Klassen setzt mail-composer.js (initComposer): .rmc-dialog an die
 * .modal-dialog, .rmc-content-wrap an den Wrapper, in den der RISE-Kern Body
 * und Footer laedt (#ajaxModalContent). Nur so erreicht das Flex-Layout den
 * Body. Bewusst nicht an data-modal-class (.rise-mail-composer-modal)
 * gehaengt - je nach Kernversion landet die Klasse an .modal statt
 * .modal-dialog und bleibt fuer das naechste Modal haengen.
 *
 * Feste Dialoghoehe: nichts springt, wenn Anhang oder Hinweise nachladen.
 */

.rmc-dialog,
.rmc,
.rmc-footer,
.rmc-preview {
    --rmc-line: #eceef1;
    --rmc-text: #1f2328;
    --rmc-muted: #6b7280;
    --rmc-faint: #9ca3af;
    --rmc-hover: #f5f6f8;
    --rmc-accent: #2563eb;
    --rmc-ok: #15803d;
    --rmc-warn: #b45309;
    --rmc-error: #c62828;
    --rmc-error-soft: #fdecec;
    --rmc-pad-x: 28px;
}

/* ------------------------------------------------------------------ Dialog */

.modal-dialog.rmc-dialog {
    max-width: none !important;
    width: min(1050px, calc(100vw - 48px));
    margin: 24px auto;
}

.rmc-dialog .modal-content {
    height: min(820px, calc(100vh - 48px));
    height: min(820px, calc(100dvh - 48px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    border: 0;
    border-radius: 12px;
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.22);
}

.rmc-dialog .modal-header {
    flex: 0 0 auto;
    flex-wrap: wrap;
    align-items: flex-start;
    padding: 18px var(--rmc-pad-x) 14px;
    border-bottom: 1px solid var(--rmc-line);
    background: #fff;
}

.rmc-dialog .modal-header .modal-title {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 17px;
    font-weight: 600;
    color: var(--rmc-text);
}

.rmc-header-sub {
    order: 3;
    flex: 1 0 100%;
    margin-top: 2px;
    font-size: 13px;
    color: var(--rmc-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rmc-header-sub a {
    color: inherit;
    text-decoration: none;
}

.rmc-header-sub a:hover {
    color: var(--rmc-accent);
    text-decoration: underline;
}

.rmc-dialog .rmc-content-wrap {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Body: Kopfzeilen, Nachricht und Anhang - nur die Nachricht scrollt. */
.rmc-dialog .rise-mail-composer-body {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
    background: #fff;
}

.rmc-compose {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.rmc-compose[hidden] {
    display: none;
}

/* ------------------------------------------------------------------ Kopfzeilen (An / CC / BCC / Betreff) */

.rmc-head {
    flex: 0 0 auto;
}

.rmc-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 46px;
    padding: 5px var(--rmc-pad-x);
    border-bottom: 1px solid var(--rmc-line);
    color: var(--rmc-text);
}

.rmc-row[hidden] {
    display: none;
}

.rmc-row-label {
    flex: 0 0 64px;
    margin: 0;
    font-size: 14px;
    font-weight: 400;
    color: var(--rmc-muted);
}

.rmc-row.is-invalid .rmc-row-label {
    color: var(--rmc-error);
}

.rmc-row-side {
    flex: 0 0 auto;
    display: flex;
    gap: 4px;
}

.rmc-row-toggle {
    background: none;
    border: 0;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 13px;
    color: var(--rmc-muted);
    cursor: pointer;
}

.rmc-row-toggle:hover,
.rmc-row-toggle:focus-visible {
    background: var(--rmc-hover);
    color: var(--rmc-text);
    outline: none;
}

.rmc-row-error {
    padding: 6px var(--rmc-pad-x) 6px calc(var(--rmc-pad-x) + 76px);
    border-bottom: 1px solid var(--rmc-line);
    font-size: 13px;
    color: var(--rmc-error);
}

.rmc-row-error[data-tone="warning"] {
    color: var(--rmc-warn);
}

.rmc-row-error[hidden] {
    display: none;
}

.rmc-row-hint {
    padding: 6px var(--rmc-pad-x) 6px calc(var(--rmc-pad-x) + 76px);
    border-bottom: 1px solid var(--rmc-line);
    font-size: 13px;
    color: var(--rmc-muted);
}

/* Fachliche Auswahl (z.B. Mahnstufe) - eine schmale Zeile, kein Formularblock */
.rmc-row--options {
    flex-wrap: wrap;
    gap: 6px 24px;
}

.rmc-option {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-weight: 400;
}

.rmc-option-label {
    font-size: 14px;
    color: var(--rmc-muted);
}

.rmc-option-select {
    border: 0;
    border-radius: 6px;
    background: var(--rmc-hover);
    padding: 4px 8px;
    font-size: 14px;
    color: var(--rmc-text);
    cursor: pointer;
}

.rmc-option-select:focus-visible {
    outline: 2px solid var(--rmc-accent);
    outline-offset: 1px;
}

/* Weitere Kontakte */
.rmc-contacts {
    position: relative;
}

.rmc-contacts-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 20;
    min-width: 280px;
    max-width: 380px;
    max-height: 300px;
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--rmc-line);
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.14);
}

.rmc-contacts-menu[hidden] {
    display: none;
}

.rmc-contact {
    display: block;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: 6px;
    background: none;
    text-align: left;
    cursor: pointer;
}

.rmc-contact:hover,
.rmc-contact:focus-visible {
    background: var(--rmc-hover);
    outline: none;
}

.rmc-contact-name {
    display: block;
    font-size: 14px;
    color: var(--rmc-text);
}

.rmc-contact-label,
.rmc-contact-email {
    font-size: 12px;
    color: var(--rmc-muted);
}

/* Chips */

.rmc-chips {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    cursor: text;
}

.rmc-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    padding: 3px 4px 3px 10px;
    border-radius: 999px;
    background: var(--rmc-hover);
    font-size: 14px;
    line-height: 20px;
    cursor: pointer;
}

.rmc-chip:hover {
    background: #eceef2;
}

.rmc-chip-name,
.rmc-chip-addr {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rmc-chip-addr {
    color: var(--rmc-muted);
}

.rmc-chip-addr::before {
    content: "<";
}

.rmc-chip-addr::after {
    content: ">";
}

.rmc-chip.is-invalid {
    background: var(--rmc-error-soft);
    color: var(--rmc-error);
}

.rmc-chip-warn {
    font-size: 12px;
}

.rmc-chip-remove {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    border: 0;
    border-radius: 50%;
    background: none;
    padding: 0;
    font-size: 15px;
    line-height: 20px;
    color: var(--rmc-faint);
    cursor: pointer;
}

.rmc-chip-remove:hover,
.rmc-chip-remove:focus-visible {
    background: rgba(15, 23, 42, 0.08);
    color: var(--rmc-text);
    outline: none;
}

.rmc-chip-input,
.rmc-subject {
    border: 0;
    outline: none;
    background: transparent;
    padding: 4px 0;
    font-size: 14px;
    color: var(--rmc-text);
    box-shadow: none;
}

.rmc-chip-input {
    flex: 1 1 140px;
    min-width: 140px;
}

.rmc-chip-input::placeholder {
    color: var(--rmc-faint);
}

.rmc-subject {
    flex: 1 1 auto;
    min-width: 0;
    font-weight: 500;
}

/* ------------------------------------------------------------------ Nachricht (dominant) */

.rmc-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 22px var(--rmc-pad-x) 20px;
    cursor: text;
}

.rmc-editor {
    min-height: 6.4em;
    outline: none;
    font-size: 15px;
    line-height: 1.6;
    color: var(--rmc-text);
    overflow-wrap: anywhere;
}

.rmc-editor p {
    margin: 0 0 1em;
}

.rmc-editor ul,
.rmc-editor ol {
    margin: 0 0 1em;
    padding-left: 1.4em;
}

.rmc-editor a {
    color: var(--rmc-accent);
}

.rmc-editor img {
    max-width: 100%;
    height: auto;
}

.rmc-body-error {
    margin: 4px 0 8px;
    font-size: 13px;
    color: var(--rmc-error);
}

.rmc-body-error[data-tone="warning"] {
    color: var(--rmc-warn);
}

.rmc-body-error[hidden] {
    display: none;
}

/* Signatur: nicht editierbar, standardmaessig eingeklappt. */
.rmc-signature {
    margin-top: 4px;
    font-size: 15px;
    line-height: 1.6;
    color: var(--rmc-text);
    cursor: default;
}

.rmc-signature-summary div:first-child {
    font-weight: 500;
}

.rmc-signature-summary div + div {
    color: var(--rmc-muted);
}

.rmc-signature-summary[hidden],
.rmc-signature-full[hidden] {
    display: none;
}

.rmc-signature-full {
    font-size: 13px;
    line-height: 1.45;
    overflow-x: auto;
}

.rmc-signature-full img {
    max-width: 100%;
    height: auto;
}

.rmc-signature-toggle {
    display: block;
    width: 100%;
    margin-top: 14px;
    padding: 10px 0 0;
    border: 0;
    border-top: 1px solid var(--rmc-line);
    background: none;
    text-align: left;
    font-size: 13px;
    color: var(--rmc-muted);
    cursor: pointer;
}

.rmc-signature-toggle:hover,
.rmc-signature-toggle:focus-visible {
    color: var(--rmc-text);
    outline: none;
}

/* ------------------------------------------------------------------ Formatierung (schmal, leise) */

.rmc-toolbar {
    flex: 0 0 auto;
    display: flex;
    gap: 2px;
    padding: 4px calc(var(--rmc-pad-x) - 8px);
    opacity: 0.45;
    transition: opacity 0.15s ease;
}

.rmc-compose:focus-within .rmc-toolbar,
.rmc-toolbar:hover {
    opacity: 1;
}

.rmc-tool {
    min-width: 30px;
    height: 28px;
    padding: 0 8px;
    border: 0;
    border-radius: 6px;
    background: none;
    font-size: 13px;
    color: var(--rmc-muted);
    cursor: pointer;
}

.rmc-tool:hover,
.rmc-tool:focus-visible {
    background: var(--rmc-hover);
    color: var(--rmc-text);
    outline: none;
}

.rmc-u {
    text-decoration: underline;
}

/* ------------------------------------------------------------------ Anhang (eine Zeile) */

.rmc-attachments {
    flex: 0 0 auto;
    max-height: 196px;
    overflow-y: auto;
    border-top: 1px solid var(--rmc-line);
}

.rmc-attachments[hidden] {
    display: none;
}

.rmc-attachment {
    padding: 0 var(--rmc-pad-x);
}

.rmc-attachment + .rmc-attachment {
    border-top: 1px solid var(--rmc-line);
}

.rmc-attachment-line {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 46px;
    font-size: 14px;
    color: var(--rmc-text);
}

.rmc-attachment-icon {
    flex: 0 0 auto;
    color: var(--rmc-muted);
}

.rmc-attachment-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rmc-attachment-size {
    flex: 0 0 auto;
    color: var(--rmc-muted);
    font-size: 13px;
}

.rmc-attachment-status {
    flex: 0 0 auto;
    font-size: 13px;
    color: var(--rmc-muted);
    white-space: nowrap;
}

.rmc-attachment--ok .rmc-attachment-status {
    color: var(--rmc-ok);
}

.rmc-attachment--problem .rmc-attachment-status {
    color: var(--rmc-warn);
}

.rmc-attachment-actions {
    flex: 0 0 auto;
    display: flex;
    gap: 12px;
}

.rmc-attachment-problem {
    padding: 0 0 12px 30px;
    margin-top: -6px;
    font-size: 13px;
    color: var(--rmc-warn);
}

/* ------------------------------------------------------------------ Kleine Textaktionen */

.rmc-inline-action,
.rmc-link {
    background: none;
    border: 0;
    padding: 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--rmc-accent);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

.rmc-inline-action:hover,
.rmc-link:hover {
    text-decoration: underline;
}

.rmc-inline-action--muted {
    color: var(--rmc-muted);
}

.rmc-inline-action + .rmc-inline-action {
    margin-left: 14px;
}

.rmc-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(15, 23, 42, 0.15);
    border-top-color: var(--rmc-accent);
    border-radius: 50%;
    vertical-align: -1px;
    animation: rmc-spin 0.8s linear infinite;
}

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

/* ------------------------------------------------------------------ Hinweis direkt ueber dem Footer */

.rmc-notice {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px 16px;
    padding: 10px var(--rmc-pad-x);
    border-top: 1px solid var(--rmc-line);
    font-size: 13px;
    color: var(--rmc-text);
}

.rmc-notice[hidden] {
    display: none;
}

.rmc-notice--warning strong {
    color: var(--rmc-warn);
}

.rmc-notice-text {
    flex: 1 1 320px;
    min-width: 0;
}

.rmc-notice-actions {
    flex: 0 0 auto;
}

/* ------------------------------------------------------------------ Ergebnis */

.rmc-result {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px var(--rmc-pad-x);
    text-align: center;
}

.rmc-result[hidden] {
    display: none;
}

.rmc-result-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: #e8f5ec;
    color: var(--rmc-ok);
    font-size: 26px;
    line-height: 52px;
}

.rmc-result-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--rmc-text);
}

.rmc-result-recipient {
    font-size: 14px;
    color: var(--rmc-muted);
}

.rmc-result-name {
    color: var(--rmc-text);
    font-weight: 500;
}

.rmc-result-status {
    margin-top: 4px;
    font-size: 14px;
    color: var(--rmc-muted);
}

.rmc-status {
    font-weight: 600;
}

.rmc-status--ok {
    color: var(--rmc-ok);
}

.rmc-status--problem {
    color: var(--rmc-error);
}

.rmc-status--muted {
    color: var(--rmc-muted);
}

/* ------------------------------------------------------------------ Footer (steht immer) */

.modal-footer.rmc-footer {
    position: relative;
    flex: 0 0 auto;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px var(--rmc-pad-x);
    border-top: 1px solid var(--rmc-line);
    background: #fff;
}

.rmc-footer-left {
    flex: 1 1 auto;
    min-width: 0;
}

/* Speicherstatus: Optik kommt von RiseUXCore (.rise-save-status, save-status.css). */
.rmc-save-state {
    white-space: nowrap;
}

.rmc-actions {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.rmc-actions[hidden] {
    display: none;
}

.rmc-text-button {
    background: none;
    border: 0;
    border-radius: 6px;
    padding: 7px 12px;
    font-size: 14px;
    color: var(--rmc-muted);
    cursor: pointer;
}

.rmc-text-button:hover,
.rmc-text-button:focus-visible,
.rmc-text-button[aria-expanded="true"] {
    background: var(--rmc-hover);
    color: var(--rmc-text);
    outline: none;
}

.rmc-text-button:disabled {
    opacity: 0.5;
    cursor: default;
}

.btn.rmc-send {
    min-width: 112px;
    border-radius: 8px;
    font-weight: 500;
}

/* ------------------------------------------------------------------ PDF-Vorschau (ueber dem Dialog) */

.rmc-preview {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: inherit;
}

.rmc-preview[hidden] {
    display: none;
}

.rmc-preview-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--rmc-line);
}

.rmc-preview-title {
    flex: 1 1 auto;
    min-width: 0;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rmc-preview-frame {
    flex: 1 1 auto;
    width: 100%;
    border: 0;
    background: #525659;
}

/* ------------------------------------------------------------------ Kleine Bildschirme */

@media (max-width: 767px) {
    .rmc-dialog,
    .rmc,
    .rmc-footer,
    .rmc-preview {
        --rmc-pad-x: 16px;
    }

    .modal-dialog.rmc-dialog {
        width: calc(100vw - 20px);
        margin: 10px auto;
    }

    .rmc-dialog .modal-content {
        height: calc(100vh - 20px);
        height: calc(100dvh - 20px);
    }

    .rmc-row-label {
        flex-basis: 52px;
    }

    .rmc-row-error,
    .rmc-row-hint {
        padding-left: calc(var(--rmc-pad-x) + 64px);
    }

    .rmc-chip-addr {
        display: none;
    }

    .rmc-chip-input {
        flex-basis: 60px;
        min-width: 60px;
    }

    .rmc-attachment-line {
        flex-wrap: wrap;
        gap: 4px 12px;
        padding: 10px 0;
    }

    .rmc-attachment-name {
        flex-basis: calc(100% - 30px);
    }

    .rmc-attachment-problem {
        padding-left: 0;
        margin-top: 0;
    }
}
