/* Mailbox - two-pane mail client on Bootstrap 5.
   Global (not scoped) because the markup spans several components. All classes are mb-* prefixed. */

/* Tokens: shared by the mailbox pages (.mb-shell) and the embedded compose card (.mb-card). */
.mb-shell,
.mb-card {
    --mb-accent: #1a73e8;
    --mb-accent-soft: #e8f0fe;
    --mb-text: #202124;
    --mb-muted: #5f6368;
    --mb-line: #e8eaed;
    --mb-hover: #f5f7fb;
    --mb-unread-bg: #fff;
    --mb-read-bg: #f8f9fb;
    --mb-radius: 12px;
}

.mb-shell {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 1rem;
    padding: 1rem;
    min-height: calc(100vh - 150px);
    color: var(--mb-text);
}

/* ---------------- Folder rail ---------------- */
.mb-rail {
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.mb-compose-btn {
    display: inline-flex;
    align-items: center;
    gap: .75rem;
    align-self: flex-start;
    padding: .9rem 1.4rem;
    border-radius: 16px;
    background: var(--mb-accent-soft);
    color: #174ea6;
    font-weight: 600;
    text-decoration: none;
    box-shadow: 0 1px 2px rgba(60, 64, 67, .2), 0 1px 3px 1px rgba(60, 64, 67, .1);
    transition: box-shadow .15s, background .15s;
}

    .mb-compose-btn:hover {
        color: #174ea6;
        background: #d2e3fc;
        box-shadow: 0 1px 3px rgba(60, 64, 67, .3), 0 4px 8px 3px rgba(60, 64, 67, .15);
    }

.mb-folders {
    display: flex;
    flex-direction: column;
}

.mb-folder {
    display: flex;
    align-items: center;
    gap: .9rem;
    height: 36px;
    padding: 0 1rem;
    border-radius: 0 18px 18px 0;
    color: var(--mb-text);
    text-decoration: none;
    font-size: .9rem;
}

    .mb-folder i {
        width: 18px;
        text-align: center;
        color: var(--mb-muted);
    }

    .mb-folder:hover {
        background: #eceff1;
        color: var(--mb-text);
    }

    .mb-folder.active {
        background: #d3e3fd;
        font-weight: 700;
        color: #041e49;
    }

        .mb-folder.active i {
            color: #041e49;
        }

.mb-folder-count {
    margin-left: auto;
    font-size: .8rem;
    font-weight: 700;
}

.mb-rail-note {
    margin-top: auto;
    padding: 0 1rem;
    font-size: .75rem;
    color: var(--mb-muted);
}

/* ---------------- Content pane ---------------- */
.mb-pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #fff;
    border-radius: var(--mb-radius);
    box-shadow: 0 1px 2px rgba(60, 64, 67, .12), 0 1px 3px 1px rgba(60, 64, 67, .06);
    overflow: hidden;
}

.mb-topbar {
    padding: .75rem 1rem .25rem;
}

.mb-search {
    display: flex;
    align-items: center;
    gap: .5rem;
    height: 46px;
    padding: 0 .5rem 0 1rem;
    border-radius: 24px;
    background: #eaf1fb;
    transition: background .15s, box-shadow .15s;
}

    .mb-search:focus-within {
        background: #fff;
        box-shadow: 0 1px 1px rgba(65, 69, 73, .3), 0 1px 3px 1px rgba(65, 69, 73, .15);
    }

    .mb-search > i {
        color: var(--mb-muted);
    }

    .mb-search input {
        flex: 1;
        min-width: 0;
        border: 0;
        outline: 0;
        background: transparent;
        font-size: .95rem;
    }

.mb-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: .75rem;
    margin: .5rem 1rem 0;
    padding: .75rem 1rem;
    border: 1px solid var(--mb-line);
    border-radius: 10px;
    background: #fbfcfe;
}

.mb-filter-field {
    display: flex;
    flex-direction: column;
    gap: .2rem;
    min-width: 140px;
}

    .mb-filter-field label {
        font-size: .72rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: .04em;
        color: var(--mb-muted);
    }

.mb-filter-app {
    flex: 1 1 260px;
}

.mb-filter-actions {
    display: flex;
    gap: .25rem;
    margin-left: auto;
}

/* Toolbar */
.mb-toolbar {
    display: flex;
    align-items: center;
    gap: .35rem;
    min-height: 48px;
    padding: .25rem 1rem;
    border-bottom: 1px solid var(--mb-line);
}

.mb-folder-title {
    margin: 0 0 0 .25rem;
    font-size: 1.05rem;
    font-weight: 600;
}

.mb-selected-count {
    margin: 0 .5rem;
    font-size: .85rem;
    color: var(--mb-muted);
}

.mb-pager {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .15rem;
    font-size: .8rem;
    color: var(--mb-muted);
}

    .mb-pager > span {
        margin-right: .5rem;
    }

.mb-icon-btn {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--mb-muted);
    text-decoration: none;
    cursor: pointer;
    transition: background .15s;
}

    .mb-icon-btn:hover:not(:disabled) {
        background: rgba(60, 64, 67, .08);
        color: var(--mb-text);
    }

    .mb-icon-btn:disabled {
        opacity: .35;
        cursor: default;
    }

    .mb-icon-btn.active {
        color: var(--mb-accent);
        background: var(--mb-accent-soft);
    }

    .mb-icon-btn.sm {
        width: 28px;
        height: 28px;
        font-size: .8rem;
    }

.mb-tool-btn {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    height: 34px;
    padding: 0 .85rem;
    border: 1px solid var(--mb-line);
    border-radius: 17px;
    background: #fff;
    color: var(--mb-text);
    font-size: .85rem;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s;
}

    .mb-tool-btn:hover {
        background: var(--mb-hover);
        color: var(--mb-text);
    }

    .mb-tool-btn.danger {
        color: #c5221f;
        border-color: #f6c7c3;
    }

        .mb-tool-btn.danger:hover {
            background: #fce8e6;
        }

.mb-check {
    flex-shrink: 0;
    margin: 0 .35rem 0 0;
    cursor: pointer;
}

/* ---------------- List ---------------- */
.mb-list {
    flex: 1;
}

.mb-row {
    display: grid;
    grid-template-columns: auto auto minmax(120px, 200px) minmax(0, 1fr) auto;
    align-items: center;
    gap: .85rem;
    height: 52px;
    padding: 0 1rem;
    border-bottom: 1px solid var(--mb-line);
    background: var(--mb-read-bg);
    font-size: .875rem;
    cursor: pointer;
    position: relative;
}

    .mb-row:hover {
        z-index: 1;
        box-shadow: inset 1px 0 0 #dadce0, inset -1px 0 0 #dadce0, 0 1px 2px 0 rgba(60, 64, 67, .3), 0 1px 3px 1px rgba(60, 64, 67, .15);
    }

    .mb-row.unread {
        background: var(--mb-unread-bg);
    }

        .mb-row.unread .mb-row-from,
        .mb-row.unread .mb-row-subject,
        .mb-row.unread time {
            font-weight: 700;
            color: var(--mb-text);
        }

        .mb-row.unread::before {
            content: "";
            position: absolute;
            left: 0;
            top: 10px;
            bottom: 10px;
            width: 3px;
            border-radius: 0 3px 3px 0;
            background: var(--mb-accent);
        }

    .mb-row.selected {
        background: #c2dbff;
    }

.mb-row-from {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #3c4043;
}

.mb-row-main {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #3c4043;
}

.mb-row-subject {
    color: #3c4043;
}

.mb-row-snippet {
    color: var(--mb-muted);
}

.mb-row-meta {
    display: flex;
    align-items: center;
    gap: .75rem;
    font-size: .8rem;
    color: var(--mb-muted);
    white-space: nowrap;
}

/* Tags */
.mb-tag {
    display: inline-block;
    margin-right: .35rem;
    padding: 0 .45rem;
    border-radius: 4px;
    background: #e8eaed;
    color: #3c4043;
    font-size: .72rem;
    font-weight: 500;
    line-height: 1.6;
    vertical-align: 1px;
}

.mb-tag-system {
    background: #fef7e0;
    color: #b06000;
}

/* Avatar */
.mb-avatar {
    display: inline-grid;
    place-items: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #dadce0;
    color: #fff;
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .02em;
}

    .mb-avatar.lg {
        width: 40px;
        height: 40px;
        font-size: .9rem;
    }

    .mb-avatar.xs {
        width: 22px;
        height: 22px;
        font-size: .6rem;
    }

/* Loading skeleton + empty state */
.mb-skeleton {
    grid-template-columns: auto 1fr 2fr;
    cursor: default;
    background: #fff;
}

    .mb-skeleton:hover {
        box-shadow: none;
    }

.mb-sk-line {
    height: 10px;
    border-radius: 5px;
    background: linear-gradient(90deg, #eceff1 25%, #f5f7f8 50%, #eceff1 75%);
    background-size: 200% 100%;
    animation: mb-shimmer 1.2s infinite;
}

@keyframes mb-shimmer {
    to {
        background-position: -200% 0;
    }
}

.mb-empty {
    padding: 4rem 1rem;
    text-align: center;
    color: var(--mb-muted);
}

    .mb-empty > i {
        font-size: 3rem;
        color: #c4c7c5;
        margin-bottom: 1rem;
    }

    .mb-empty h2 {
        font-size: 1.1rem;
        font-weight: 600;
        color: var(--mb-text);
        margin-bottom: .35rem;
    }

.mb-loading {
    padding: 3rem;
    text-align: center;
}

/* ---------------- Read ---------------- */
.mb-read {
    padding: 1.25rem 1.5rem 2rem;
}

.mb-read-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem;
    margin-bottom: 1.25rem;
    padding-left: 56px;
}

    .mb-read-head h1 {
        flex-basis: 100%;
        margin: 0;
        font-size: 1.4rem;
        font-weight: 400;
    }

.mb-read-app {
    font-size: .85rem;
    color: var(--mb-muted);
}

.mb-read-count {
    margin-left: auto;
    font-size: .8rem;
    color: var(--mb-muted);
}

.mb-msg {
    padding: 1rem 0 1.25rem;
    border-top: 1px solid var(--mb-line);
}

    .mb-msg:not(.latest) .mb-msg-body {
        color: #3c4043;
    }

.mb-msg-head {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.mb-msg-who {
    flex: 1;
    min-width: 0;
    font-size: .9rem;
}

.mb-you {
    font-size: .8rem;
    color: var(--mb-muted);
    margin-left: .25rem;
}

.mb-msg-to {
    font-size: .8rem;
    color: var(--mb-muted);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.mb-msg-date {
    font-size: .8rem;
    color: var(--mb-muted);
    white-space: nowrap;
}

.mb-msg-subject {
    margin: .75rem 0 0 56px;
    font-weight: 600;
    font-size: .9rem;
}

.mb-msg-body {
    margin: .75rem 0 0 56px;
    white-space: pre-wrap; /* keep the sender's line breaks */
    line-height: 1.65;
    font-size: .925rem;
    overflow-wrap: anywhere;
}

.mb-files-label {
    margin: 1.25rem 0 .5rem 56px;
    font-size: .8rem;
    font-weight: 600;
    color: var(--mb-muted);
}

.mb-files {
    display: flex;
    flex-wrap: wrap;
    gap: .6rem;
    margin-left: 56px;
}

.mb-file {
    display: flex;
    align-items: center;
    gap: .6rem;
    width: 230px;
    padding: .55rem .65rem;
    border: 1px solid var(--mb-line);
    border-radius: 8px;
    background: #fff;
    color: var(--mb-text);
    text-decoration: none;
    transition: border-color .15s, box-shadow .15s;
}

a.mb-file:hover {
    color: var(--mb-text);
    border-color: #c6dafc;
    box-shadow: 0 1px 3px rgba(60, 64, 67, .15);
}

.mb-file-icon {
    font-size: 1.5rem;
}

.mb-file-text {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    line-height: 1.25;
}

.mb-file-name {
    font-size: .82rem;
    font-weight: 500;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.mb-file-size {
    font-size: .72rem;
    color: var(--mb-muted);
}

.mb-file-dl {
    color: var(--mb-muted);
    opacity: 0;
    transition: opacity .15s;
}

a.mb-file:hover .mb-file-dl {
    opacity: 1;
}

.mb-ic-pdf { color: #d93025; }
.mb-ic-word { color: #1a73e8; }
.mb-ic-excel { color: #188038; }
.mb-ic-image { color: #9334e6; }
.mb-ic-other { color: var(--mb-muted); }

/* Reply */
.mb-reply {
    margin: 1rem 0 0 56px;
    border: 1px solid var(--mb-line);
    border-radius: var(--mb-radius);
    box-shadow: 0 1px 3px rgba(60, 64, 67, .12);
    scroll-margin-top: 1rem;
}

.mb-reply-head {
    padding: .7rem 1rem;
    border-bottom: 1px solid var(--mb-line);
    font-size: .875rem;
    font-weight: 600;
    color: var(--mb-muted);
}

/* ---------------- Compose ---------------- */
.mb-compose {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.mb-compose-hint {
    margin: 1.5rem;
    padding: 1rem 1.25rem;
    border: 1px dashed #c4c7c5;
    border-radius: 10px;
    color: var(--mb-muted);
    font-size: .9rem;
}

.mb-form {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.mb-field {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-height: 48px;
    padding: .35rem 1.25rem;
    border-bottom: 1px solid var(--mb-line);
}

    .mb-field > label {
        width: 88px;
        flex-shrink: 0;
        margin: 0;
        font-size: .85rem;
        color: var(--mb-muted);
    }

.mb-field-to {
    align-items: flex-start;
    padding-top: .6rem;
    padding-bottom: .6rem;
}

    .mb-field-to > label {
        padding-top: .3rem;
    }

.mb-field-input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    font-size: .95rem;
    padding: .35rem 0;
}

select.mb-field-input {
    cursor: pointer;
}

.mb-chips {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
}

.mb-chip {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    max-width: 100%;
    height: 32px;
    padding: 0 .65rem 0 .3rem;
    border: 1px solid #dadce0;
    border-radius: 16px;
    background: #fff;
    color: var(--mb-text);
    font-size: .82rem;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}

    .mb-chip:hover {
        background: var(--mb-hover);
    }

    .mb-chip.on {
        background: var(--mb-accent-soft);
        border-color: #aecbfa;
    }

.mb-chip-name {
    font-weight: 500;
    white-space: nowrap;
}

.mb-chip-role {
    color: var(--mb-muted);
    font-size: .72rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.mb-chip-mark {
    font-size: .7rem;
    color: var(--mb-muted);
}

.mb-chip.on .mb-chip-mark {
    color: var(--mb-accent);
}

.mb-body-input {
    flex: 1;
    width: 100%;
    min-height: 180px;
    padding: 1rem 1.25rem;
    border: 0;
    outline: 0;
    resize: vertical;
    font-size: .95rem;
    line-height: 1.6;
}

.mb-files-pending {
    margin: 0;
    padding: 0 1.25rem .75rem;
}

.mb-form-footer {
    position: sticky;
    bottom: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem;
    padding: .75rem 1.25rem;
    border-top: 1px solid var(--mb-line);
    background: #fff;
}

.mb-send {
    border-radius: 18px;
    padding: .45rem 1.4rem;
    font-weight: 600;
}

.mb-attach {
    position: relative;
    overflow: hidden;
    margin: 0;
}

    .mb-attach input[type=file] {
        position: absolute;
        inset: 0;
        opacity: 0;
        cursor: pointer;
    }

.mb-form-hint,
.mb-counter {
    font-size: .75rem;
    color: var(--mb-muted);
}

.mb-alert {
    margin: .75rem 1.25rem 0;
    padding: .6rem .9rem;
    border-radius: 8px;
    background: #fce8e6;
    color: #c5221f;
    font-size: .875rem;
}

.mb-form.compact .mb-field > label {
    width: 64px;
}

.mb-form.compact .mb-body-input {
    min-height: 120px;
}

/* ---------------- Responsive ---------------- */
@media (max-width: 992px) {
    .mb-shell {
        grid-template-columns: 1fr;
        padding: .5rem;
    }

    .mb-rail {
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
    }

    .mb-folders {
        flex-direction: row;
    }

    .mb-folder {
        border-radius: 18px;
    }

    .mb-rail-note {
        display: none;
    }
}

@media (max-width: 640px) {
    .mb-row {
        grid-template-columns: auto auto minmax(0, 1fr) auto;
        grid-template-areas: "check avatar from meta" "check avatar main main";
        height: auto;
        padding: .6rem .75rem;
        row-gap: .15rem;
    }

        .mb-row .mb-check { grid-area: check; }
        .mb-row .mb-avatar { grid-area: avatar; }
        .mb-row-from { grid-area: from; }
        .mb-row-main { grid-area: main; }
        .mb-row-meta { grid-area: meta; }

    .mb-tool-btn span,
    .mb-form-hint {
        display: none;
    }

    .mb-read {
        padding: 1rem;
    }

    .mb-read-head,
    .mb-msg-subject,
    .mb-msg-body,
    .mb-files-label,
    .mb-files,
    .mb-reply {
        margin-left: 0;
        padding-left: 0;
    }

    .mb-msg-date {
        display: none;
    }

    .mb-field > label {
        width: 60px;
    }
}

/* ---------------- Header envelope (MailBell) ---------------- */
.mail-bell {
    position: relative;
    font-size: 1.4rem;
    color: inherit;
    text-decoration: none;
}

.mail-bell-badge {
    position: absolute;
    top: -6px;
    right: -10px;
    min-width: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #dc3545;
    color: #fff;
    font-size: .65rem;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}

/* Fixed recipient (embedded compose): looks selected, not clickable */
.mb-chip.locked {
    cursor: default;
    opacity: 1;
}

    .mb-chip.locked:hover {
        background: var(--mb-accent-soft);
    }
