.gli-chat {
    --gli-chat-border: #d9e1e8;
    --gli-chat-muted: #5d6a75;
    --gli-chat-primary: #0b5f73;
    --gli-chat-primary-dark: #084959;
    box-sizing: border-box;
    margin: 2rem 0;
    border: 1px solid var(--gli-chat-border);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 4px 18px rgba(25, 45, 60, 0.08);
    color: #1f2933;
    overflow: hidden;
}

.gli-portal > .gli-chat--portal-top {
    clear: both;
    grid-column: 1 / -1;
    width: 100%;
    margin: 0.75rem 0 1.5rem;
}

/* Compact portal dashboard: title, account buttons and chat share the top
   row; the four summary cards fill the space below the title/buttons. */
.gli-portal .gli-portal-head.gli-chat-dashboard-layout {
    display: grid !important;
    grid-template-columns: minmax(270px, 0.9fr) minmax(320px, 1fr) minmax(350px, 1.1fr);
    grid-template-areas:
        "intro actions chat"
        "cards cards chat";
    align-items: start !important;
    gap: 16px 20px !important;
}

.gli-portal .gli-chat-dashboard-intro {
    grid-area: intro;
    align-self: start;
}

.gli-portal .gli-chat-dashboard-intro h2 {
    white-space: nowrap;
}

.gli-portal .glow-portal-account-actions.gli-chat-dashboard-actions {
    grid-area: actions;
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: stretch !important;
    gap: 8px !important;
    width: 100%;
    margin: 0 !important;
}

.gli-portal .gli-chat-dashboard-actions .glow-portal-account-button {
    flex: 1 1 0;
    min-width: 0 !important;
    width: auto !important;
    padding-left: 10px;
    padding-right: 10px;
    text-align: center;
}

.gli-portal .gli-portal-head.gli-chat-dashboard-layout > .gli-chat--portal-top {
    grid-area: chat;
    align-self: start;
    width: 100%;
    margin: 0 !important;
}

.gli-portal .gli-chat-dashboard-cards {
    grid-area: cards;
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 14px !important;
    width: 100%;
    margin: 0 !important;
}

@media (max-width: 1200px) {
    .gli-portal .gli-portal-head.gli-chat-dashboard-layout {
        grid-template-columns: minmax(0, 1fr) minmax(340px, 0.9fr);
        grid-template-areas:
            "intro chat"
            "actions chat"
            "cards chat";
    }
}

@media (max-width: 760px) {
    .gli-portal .gli-portal-head.gli-chat-dashboard-layout {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "intro"
            "actions"
            "chat"
            "cards";
    }

    .gli-portal .glow-portal-account-actions.gli-chat-dashboard-actions {
        flex-wrap: wrap !important;
    }

    .gli-portal .gli-chat-dashboard-actions .glow-portal-account-button {
        flex-basis: 160px;
    }

    .gli-portal .gli-chat-dashboard-intro h2 {
        white-space: normal;
    }
}

/* Compact, consistent purchase-request controls. */
.gli-portal .gli-compact-actions-cell {
    vertical-align: middle;
}

.gli-portal .gli-compact-order-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: center;
    gap: 4px;
    max-width: 210px;
    min-width: 170px;
    margin: 0 auto;
}

.gli-portal .gli-compact-order-actions > details,
.gli-portal .gli-compact-order-actions > form {
    margin: 0 !important;
}

.gli-portal .gli-compact-order-actions > details:not([open]) {
    display: block;
}

.gli-portal .gli-compact-order-actions > details[open] {
    flex: 1 0 100%;
    width: 100%;
    padding: 8px;
    border: 1px solid #d8dee7;
    border-radius: 6px;
    background: #f8fafc;
    text-align: left;
}

.gli-portal .gli-order-action {
    appearance: none;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    margin: 0 !important;
    padding: 5px 8px !important;
    border: 1px solid transparent !important;
    border-radius: 5px !important;
    box-shadow: none !important;
    color: #fff !important;
    cursor: pointer;
    font-family: inherit;
    font-size: 11px !important;
    font-weight: 600 !important;
    line-height: 1.2 !important;
    text-align: center;
    text-decoration: none !important;
    white-space: nowrap;
}

.gli-portal summary.gli-order-action {
    list-style: none;
}

.gli-portal summary.gli-order-action::-webkit-details-marker {
    display: none;
}

.gli-portal .gli-order-action--edit {
    background: #6554a4 !important;
    border-color: #6554a4 !important;
}

.gli-portal .gli-order-action--delete {
    background: #b42318 !important;
    border-color: #b42318 !important;
}

.gli-portal .gli-order-action--ordered {
    background: #b96b00 !important;
    border-color: #b96b00 !important;
}

.gli-portal .gli-order-action--delivered {
    background: #2e7d32 !important;
    border-color: #2e7d32 !important;
}

.gli-portal .gli-order-action--word {
    background: #1d4b7a !important;
    border-color: #1d4b7a !important;
}

.gli-portal .gli-order-action:hover,
.gli-portal .gli-order-action:focus {
    filter: brightness(0.88);
    color: #fff !important;
    outline: 2px solid rgba(29, 75, 122, 0.2);
    outline-offset: 1px;
}

.gli-portal .gli-compact-order-actions > details[open] > summary {
    margin-bottom: 8px !important;
}

.gli-chat *,
.gli-chat *::before,
.gli-chat *::after {
    box-sizing: border-box;
}

.gli-chat__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--gli-chat-border);
    background: #f7fafb;
}

.gli-chat__header h2 {
    margin: 0 0 0.2rem;
    font-size: 1.35rem;
}

.gli-chat__header p {
    margin: 0;
    color: var(--gli-chat-muted);
}

.gli-chat__count {
    flex: 0 0 auto;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    background: #e7f2f4;
    color: var(--gli-chat-primary-dark);
    font-size: 0.8rem;
}

.gli-chat__messages {
    max-height: 32rem;
    overflow-y: auto;
    padding: 1rem 1.5rem;
    background: #fbfcfd;
    scroll-behavior: smooth;
}

.gli-chat__message {
    position: relative;
    margin: 0 0 0.9rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--gli-chat-border);
    border-radius: 10px;
    background: #fff;
}

.gli-chat__message--mine {
    border-left: 4px solid var(--gli-chat-primary);
    background: #f4fafb;
}

.gli-chat__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.35rem 0.75rem;
    margin-bottom: 0.35rem;
}

.gli-chat__meta time {
    color: var(--gli-chat-muted);
    font-size: 0.82rem;
}

.gli-chat__body {
    overflow-wrap: anywhere;
    line-height: 1.55;
    white-space: normal;
}

.gli-chat__delete-form {
    margin: 0.45rem 0 0;
}

.gli-chat__delete {
    padding: 0;
    border: 0;
    background: transparent;
    color: #9c2f2f;
    cursor: pointer;
    font-size: 0.78rem;
    text-decoration: underline;
}

.gli-chat__empty {
    margin: 2rem 0;
    color: var(--gli-chat-muted);
    text-align: center;
}

.gli-chat__composer {
    padding: 1.25rem 1.5rem 1.5rem;
    border-top: 1px solid var(--gli-chat-border);
}

.gli-chat__composer label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 600;
}

.gli-chat__composer textarea {
    display: block;
    width: 100%;
    min-height: 5.5rem;
    margin: 0;
    padding: 0.7rem 0.8rem;
    resize: vertical;
    border: 1px solid #aebbc5;
    border-radius: 7px;
    background: #fff;
    color: #1f2933;
    font: inherit;
}

.gli-chat__composer textarea:focus {
    border-color: var(--gli-chat-primary);
    outline: 3px solid rgba(11, 95, 115, 0.16);
}

.gli-chat__composer-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 0.75rem;
}

.gli-chat__composer-actions small {
    color: var(--gli-chat-muted);
}

.gli-chat__send {
    padding: 0.62rem 1rem;
    border: 0;
    border-radius: 6px;
    background: var(--gli-chat-primary);
    color: #fff;
    cursor: pointer;
    font-weight: 600;
}

.gli-chat__send:hover,
.gli-chat__send:focus {
    background: var(--gli-chat-primary-dark);
}

.gli-chat__notice,
.gli-chat-access-notice {
    margin: 1rem 1.5rem 0;
    padding: 0.7rem 0.85rem;
    border-radius: 6px;
}

.gli-chat__notice--success {
    border: 1px solid #91c7a1;
    background: #eef9f1;
    color: #245f34;
}

.gli-chat__notice--error,
.gli-chat-access-notice {
    border: 1px solid #dfaaaa;
    background: #fff3f3;
    color: #7c2828;
}

@media (max-width: 600px) {
    .gli-chat__header,
    .gli-chat__composer-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .gli-chat__count {
        align-self: flex-start;
    }

    .gli-chat__send {
        width: 100%;
    }
}
