.contact-chip {
    display: flex;
    align-items: center;
    position: relative;
    cursor: default;
    font-size: var(--c--globals--font--sizes--sm);
    white-space: nowrap;
    min-width: 0;
    max-width: 100%;

    &:not(:last-of-type):after {
        content: ", ";
        margin-right: 1ex;
    }
}

.contact-chip__content {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    color: inherit;
    cursor: pointer;
    display: flex;
    align-items: baseline;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: var(--c--globals--spacings--2xs);
    position: relative;
    z-index: 1;
    transition: color 0.2s;
    min-width: 0;
    max-width: 100%;

    &:hover:before {
        content: "";
        display: block;
        position: absolute;
        inset: -4px -8px;
        border-radius: 4px;
        background-color: var(--c--contextuals--background--semantic--neutral--tertiary);
        z-index: -1;
    }
}

.contact-chip__identity-name {
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    color: var(--c--contextuals--content--semantic--neutral--primary);

    &::first-letter {
        text-transform: uppercase;
    }
}

.contact-chip__identity-email {
    min-width: 0;
    max-width: 100%;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    flex: 0 1 auto;
}

.contact-chip__identity-name + .contact-chip__identity-email {
    color: var(--c--contextuals--content--semantic--neutral--secondary);
    font-size: var(--c--globals--font--sizes--xs);
}

.contact-chip__icon {
    transform: translateY(2px);
}
.contact-chip__icon--warning {
    color: var(--c--contextuals--content--semantic--warning--tertiary);
}

.contact-chip__icon--error {
    color: var(--c--contextuals--content--semantic--error--tertiary);
}

.contact-chip__icon--success {
    color: var(--c--contextuals--content--semantic--success--tertiary);
}

.contact-chip__icon--muted {
    color: var(--c--contextuals--content--semantic--neutral--tertiary);
}

// == ContactPopover
.contact-popover {
    padding: var(--c--globals--spacings--base);
    display: flex;
    flex-direction: column;
    gap: var(--c--globals--spacings--xs);
    background-color: var(--c--contextuals--background--surface--secondary);
    border: 1px solid var(--c--contextuals--border--surface--primary);
    border-radius: 4px;
    box-shadow: 0 2px 5px 0 var(--c--contextuals--background--semantic--contextual--primary-hover);
    width: 350px;
}

.contact-popover__identity {
    display: flex;
    gap: var(--c--globals--spacings--md);
    align-items: center;

    & > div {
        flex-shrink: 0;
        overflow: hidden;
    }
}
.contact-popover__identity-info {
    flex: 1;
}

.contact-popover__identity-name {
    display: inline-block;
    font-size: var(--c--globals--font--sizes--h6);
    font-weight: bold;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    margin: 0;
    line-height: 1;

    &::first-letter {
        text-transform: uppercase;
    }
}

.contact-popover__identity-email {
    appearance: none;
    background: none;
    border: none;
    color: inherit;
    align-items: center;
    padding: 0;
    margin: 0;
    font-size: var(--c--globals--font--sizes--sm);
    line-height: 1.37;
    cursor: pointer;
    display: flex;
    position: relative;
    max-width: 100%;

    & > span:first-child {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 100%;
        text-decoration: underline;
    }

    & > .contact-popover__copy-icon {
        height: 100%;
        font-size: var(--c--globals--font--sizes--md);
        padding: 2px;
        display: none;
        text-decoration: none;
    }

    &:hover {
        color: var(--c--contextuals--content--semantic--brand--primary);
        text-decoration-color: currentColor;
        & > .contact-popover__copy-icon {
            display: block;
        }
    }
}

// Delivery status section (only shown for failed/delivering)
.contact-popover__delivery {
    border-top: 1px solid var(--c--contextuals--border--surface--primary);
    padding-top: var(--c--globals--spacings--xs);
    display: flex;
    flex-direction: column;
    gap: var(--c--globals--spacings--2xs);
}

.contact-popover__delivery-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--c--globals--spacings--xs);
}

.contact-popover__delivery-info {
    display: flex;
    align-items: center;
    gap: var(--c--globals--spacings--2xs);
    font-size: var(--c--globals--font--sizes--xs);
    color: var(--c--contextuals--content--semantic--neutral--secondary);
}

.contact-popover__delivery-icon {
    flex-shrink: 0;

    &--error {
        color: var(--c--contextuals--content--semantic--error--tertiary);
    }

    &--warning {
        color: var(--c--contextuals--content--semantic--warning--tertiary);
    }
}

.contact-popover__delivery-label {
    font-size: var(--c--globals--font--sizes--xs);
}

.contact-popover__delivery-timestamp {
    font-size: var(--c--globals--font--sizes--2xs);
    color: var(--c--contextuals--content--semantic--neutral--tertiary);
}

.contact-popover__delivery-actions {
    display: flex;
    gap: var(--c--globals--spacings--2xs);
    flex-shrink: 0;
}

.contact-chip__delivery-logs {
    font-size: var(--c--globals--font--sizes--xs);
    color: var(--c--contextuals--content--semantic--neutral--tertiary);

    summary {
        cursor: pointer;
        user-select: none;

        &:hover {
            text-decoration: underline;
        }
    }

    pre {
        margin: var(--c--globals--spacings--2xs) 0 0;
        white-space: pre-wrap;
        word-break: break-word;
        font-size: var(--c--globals--font--sizes--2xs);
        background-color: var(--c--contextuals--background--surface--tertiary);
        padding: var(--c--globals--spacings--xs);
        border-radius: 4px;
        max-height: 80px;
        overflow-y: auto;
    }
}
