﻿/* Theme-aware styles. Add this stylesheet once after your existing theme styles. */
.crm-workspace {
    --crm-radius: 16px;
}

    .crm-workspace .mud-paper {
        border-radius: var(--crm-radius);
    }

.crm-hero {
    border: 1px solid var(--mud-palette-divider);
    border-inline-start: 4px solid var(--mud-palette-primary);
    background: var(--mud-palette-surface);
}

.crm-heading-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

    .crm-heading-row > * {
        min-width: 0;
    }

.crm-filters {
    display: grid;
    grid-template-columns: minmax(240px,2fr) minmax(180px,1fr) minmax(150px,1fr);
    gap: 16px;
    align-items: start;
}

.crm-grid {
    width: 100%;
    border: 1px solid var(--mud-palette-divider);
    border-radius: 16px;
    overflow: hidden;
}

    .crm-grid .mud-table-cell {
        overflow-wrap: anywhere;
    }

.crm-actions {
    text-align: end;
    white-space: nowrap;
}

.crm-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    flex-direction: column;
    gap: 12px;
    padding: 48px 24px;
}

.crm-tag-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--mud-palette-divider);
}

.crm-note {
    position: relative;
    padding: 20px 0 20px 20px;
    border-inline-start: 2px solid var(--mud-palette-divider);
}

    .crm-note::before {
        content: "";
        position: absolute;
        inset-inline-start: -5px;
        top: 24px;
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: var(--mud-palette-primary);
    }

.crm-note-text {
    margin: 10px 0 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    color: var(--mud-palette-text-primary);
    font: inherit;
    line-height: 1.65;
}

.crm-wrap {
    overflow-wrap: anywhere;
}

.crm-pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 16px;
}

.crm-dialog-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.crm-workspace a:focus-visible, .crm-workspace button:focus-visible, .crm-dialog button:focus-visible {
    outline: 3px solid var(--mud-palette-primary);
    outline-offset: 3px;
}

.crm-grid-fill {
    width: 100%;
    min-width: 0;
}

    .crm-grid-fill .mud-table-container {
        width: 100%;
        max-width: 100%;
    }

    .crm-grid-fill .mud-table-root {
        width: 100%;
        table-layout: fixed;
    }

    .crm-grid-fill .mud-table-cell {
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .crm-grid-fill .crm-cell-center {
        text-align: center;
    }

    .crm-grid-fill .crm-cell-end {
        text-align: right;
    }

    /* Align CRM grid headings with their column contents. */
    .crm-grid-fill .mud-table-head th.crm-cell-center {
        text-align: center;
    }

        .crm-grid-fill .mud-table-head th.crm-cell-center .column-header {
            width: 100%;
            justify-content: center;
        }

    .crm-grid-fill .mud-table-head th.crm-cell-end {
        text-align: right;
    }

        .crm-grid-fill .mud-table-head th.crm-cell-end .column-header {
            width: 100%;
            justify-content: flex-end;
        }


.crm-chat {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    overflow: hidden;
    border: 1px solid #dce4e7;
    border-radius: 16px;
    background: #f0f3f5;
}

.crm-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px 20px;
    background: #fff;
    border-bottom: 1px solid #e2e8ec;
}

.crm-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.crm-chat-header-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #e6f6ec;
    color: #16834a;
}

.crm-chat-header-title {
    font-weight: 600;
    color: #203039;
}

.crm-chat-header-subtitle {
    color: #74838c;
}

.crm-chat-messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 350px;
    max-height: 620px;
    overflow-y: auto;
    padding: 24px 20px;
    background-color: #eef2f3;
    background-image: radial-gradient(#d7e2e3 0.6px, transparent 0.6px);
    background-size: 18px 18px;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #c6d1d2 transparent;
}

.crm-chat-history {
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
}

.crm-chat-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    width: 100%;
}

.crm-chat-row-incoming {
    justify-content: flex-start;
}

.crm-chat-row-outgoing {
    justify-content: flex-end;
}

.crm-chat-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border-radius: 50%;
    background: #d9eee3;
    color: #16834a;
}

.crm-chat-bubble {
    display: flex;
    flex-direction: column;
    gap: 7px;
    width: fit-content;
    max-width: min(78%, 600px);
    min-width: 110px;
    padding: 12px 15px 9px;
    border-radius: 15px;
    overflow-wrap: anywhere;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.crm-chat-row-incoming .crm-chat-bubble {
    background: #fff;
    color: #24343c;
    border-bottom-left-radius: 4px;
}

.crm-chat-row-outgoing .crm-chat-bubble {
    background: #dcf8e6;
    color: #213c2d;
    border-bottom-right-radius: 4px;
}

.crm-chat-sender {
    font-size: 12px;
    font-weight: 700;
    line-height: 1.4;
}

.crm-chat-row-incoming .crm-chat-sender {
    color: #16834a;
}

.crm-chat-row-outgoing .crm-chat-sender {
    color: #276b43;
}

.crm-chat-text {
    font-size: 14px;
    line-height: 1.65;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.crm-chat-time {
    margin-top: 3px;
    font-size: 10px;
    line-height: 1.4;
    color: #77858c;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.crm-chat-row-outgoing .crm-chat-time {
    color: #658573;
}

.crm-chat-empty {
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 50px 20px;
    text-align: center;
    color: #667781;
}

.crm-chat-footer {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 15px 20px;
    border-top: 1px solid #e1e8eb;
    background: #fff;
}

.crm-chat-compose {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 56px;
    padding: 7px 8px 7px 16px;
    border: 1px solid #dce4e7;
    border-radius: 28px;
    background: #f8fafb;
}

.crm-chat-compose-text {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    color: #84929b;
    font-size: 14px;
}

    .crm-chat-compose-text span {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }

.crm-chat-send {
    flex-shrink: 0;
}

.crm-chat-footer-note {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 11px;
    color: #819099;
    text-align: center;
}

/* Customer Service sidebar badge */
.crm-customer-service-link {
    position: relative;
}

    .crm-customer-service-link .crm-unassigned-case-badge {
        position: absolute;
        top: 50%;
        right: 48px;
        transform: translateY(-50%);
        margin: 0 !important;
        min-width: 20px;
        height: 20px;
        padding: 0 5px !important;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
        font-size: 11px;
        font-weight: 600;
        line-height: 1 !important;
        text-align: center;
        pointer-events: none;
    }

    /* Preserve the existing dropdown arrow positioning */
    .crm-customer-service-link .menu-arrow {
        position: absolute;
        right: 17px;
        top: 50%;
        margin: 0;
        transform: translateY(-50%);
    }

@media (max-width: 600px) {
    .crm-chat {
        border-radius: 12px;
    }

    .crm-chat-header {
        padding: 12px;
    }

    .crm-chat-header-icon {
        width: 38px;
        height: 38px;
    }

    .crm-chat-messages {
        min-height: 300px;
        max-height: 65vh;
        padding: 16px 10px;
        gap: 12px;
    }

    .crm-chat-bubble {
        max-width: 85%;
        padding: 10px 12px 8px;
    }

    .crm-chat-avatar {
        width: 28px;
        height: 28px;
        flex-basis: 28px;
    }

    .crm-chat-footer {
        padding: 12px;
    }

    .crm-chat-text {
        font-size: 13px;
    }

    .crm-chat-footer-note {
        font-size: 10px;
    }
}


.crm-work-alert-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

@media (prefers-reduced-motion: no-preference) {
    .crm-work-alert-icon.crm-reminder-shake {
        transform-origin: top center;
        animation: crm-reminder-shake 4s ease-in-out infinite;
    }

    .crm-work-alert-icon.crm-overdue-pulse {
        transform-origin: center;
        animation: crm-overdue-pulse 4s ease-in-out infinite;
    }
}

@keyframes crm-reminder-shake {
    0%, 24%, 100% {
        transform: rotate(0deg);
    }

    4%, 12%, 20% {
        transform: rotate(-12deg);
    }

    8%, 16% {
        transform: rotate(12deg);
    }
}

@keyframes crm-overdue-pulse {
    0%, 24%, 100% {
        transform: scale(1);
    }

    8%, 16% {
        transform: scale(1.15);
    }

    12%, 20% {
        transform: scale(1);
    }
}

/* Preserve the label/value layout used by MudBlazor on small screens. */
@media (max-width: 599.98px) {
    .crm-grid-fill.mud-sm-table .mud-table-root {
        table-layout: auto;
    }
}


@media (prefers-reduced-motion:no-preference) {
    .crm-workspace .crm-hero {
        animation: crm-enter 160ms ease-out;
    }

    .crm-workspace .mud-button-root {
        transition: background-color 120ms ease,box-shadow 120ms ease;
    }

    @keyframes crm-enter {
        from {
            opacity: .7;
            transform: translateY(3px);
        }

        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
}

@media (max-width:700px) {
    .crm-filters {
        grid-template-columns: minmax(0,1fr);
        gap: 8px;
    }

    .crm-heading-row {
        align-items: flex-start;
    }

        .crm-heading-row > .mud-button-root {
            width: 100%;
        }

    .crm-dialog-actions {
        flex-direction: column;
    }

        .crm-dialog-actions > * {
            width: 100%;
            min-height: 44px;
        }

    .crm-workspace .mud-icon-button {
        min-width: 44px;
        min-height: 44px;
    }
}
