/* =========================================================
   Chat UI (modern bubble-style) + invoice summary card styles
   ========================================================= */

/* Briefly flashes a chat message when the user arrives via a deep link
   (e.g. "View message in app" button from an email). */
.chat-msg-highlight .chat-bubble,
.chat-msg-highlight > .border {
    background-color: #fff3cd !important;
    transition: background-color 1.5s ease-out;
    box-shadow: 0 0 0 2px #ffe08a;
}

/* ---------- Chat panel shell ---------- */
.chat-panel {
    background: #ffffff;
    border: 1px solid #e6ebf1;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.chat-panel__header {
    padding: 14px 18px;
    border-bottom: 1px solid #eef2f6;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-panel__title {
    font-weight: 600;
    color: #1f2937;
    font-size: 15px;
    line-height: 1.2;
}

.chat-panel__subtitle {
    color: #6b7280;
    font-size: 12px;
    margin-top: 2px;
}

.chat-panel__body {
    background: #f7f9fb;
    padding: 18px 18px 8px 18px;
    min-height: 480px;
    max-height: 70vh;
    overflow-y: auto;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Thin modern scrollbar */
.chat-panel__body::-webkit-scrollbar { width: 8px; }
.chat-panel__body::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}
.chat-panel__body::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    text-align: center;
    padding: 40px 20px;
}

.chat-empty__icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #eef2f6;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    font-size: 24px;
    margin-bottom: 12px;
}

.chat-empty__title {
    font-weight: 600;
    color: #4b5563;
    font-size: 14px;
    margin-bottom: 2px;
}

.chat-empty__subtitle {
    font-size: 12px;
    color: #9ca3af;
}

/* ---------- Day separator ---------- */
.chat-day-sep {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 14px 0 10px 0;
    color: #6b7280;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-day-sep::before,
.chat-day-sep::after {
    content: "";
    flex: 1;
    height: 1px;
    background: #e6ebf1;
}

/* ---------- Message group ---------- */
.chat-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-top: 2px;
    animation: chat-fade-in 180ms ease-out;
}

@keyframes chat-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-msg--first-of-group { margin-top: 10px; }

.chat-msg--mine { flex-direction: row-reverse; }

/* Avatar (initials circle) */
.chat-avatar {
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    user-select: none;
}

/* Hide the avatar on continuation messages in the same group but keep
   the space so bubbles align. */
.chat-avatar--spacer {
    background: transparent !important;
    color: transparent !important;
}

/* Sender name label shown only on the first bubble of a group */
.chat-sender {
    font-size: 12px;
    font-weight: 600;
    color: #4b5563;
    margin: 0 6px 3px 6px;
}

.chat-msg--mine .chat-sender { text-align: right; }

.chat-bubble-col {
    display: flex;
    flex-direction: column;
    max-width: 72%;
}

.chat-msg--mine .chat-bubble-col { align-items: flex-end; }
.chat-msg--theirs .chat-bubble-col { align-items: flex-start; }

/* Bubble */
.chat-bubble {
    padding: 9px 13px;
    font-size: 14px;
    line-height: 1.45;
    color: #1f2937;
    background: #ffffff;
    border: 1px solid #e6ebf1;
    border-radius: 14px;
    word-wrap: break-word;
    white-space: pre-wrap;
    box-shadow: 0 1px 1px rgba(15, 23, 42, 0.03);
    position: relative;
}

.chat-msg--mine .chat-bubble {
    background: #2f3a4a;
    border-color: #2f3a4a;
    color: #ffffff;
}

/* Visual connection between stacked bubbles from same sender */
.chat-msg--middle-of-group.chat-msg--theirs .chat-bubble {
    border-top-left-radius: 6px;
    border-bottom-left-radius: 6px;
}
.chat-msg--last-of-group.chat-msg--theirs .chat-bubble {
    border-top-left-radius: 6px;
}
.chat-msg--first-of-group.chat-msg--theirs:not(.chat-msg--last-of-group) .chat-bubble {
    border-bottom-left-radius: 6px;
}

.chat-msg--middle-of-group.chat-msg--mine .chat-bubble {
    border-top-right-radius: 6px;
    border-bottom-right-radius: 6px;
}
.chat-msg--last-of-group.chat-msg--mine .chat-bubble {
    border-top-right-radius: 6px;
}
.chat-msg--first-of-group.chat-msg--mine:not(.chat-msg--last-of-group) .chat-bubble {
    border-bottom-right-radius: 6px;
}

/* Timestamp shown under the last bubble of a group */
.chat-time {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 3px;
    padding: 0 6px;
}

/* ---------- Composer ---------- */
.chat-composer {
    background: #ffffff;
    border-top: 1px solid #eef2f6;
    padding: 10px 12px 12px 12px;
}

.chat-composer__wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f7f9fb;
    border: 1px solid #e6ebf1;
    border-radius: 20px;
    padding: 6px 6px 6px 14px;
    transition: border-color 120ms ease-out, box-shadow 120ms ease-out;
}

.chat-composer__wrap:focus-within {
    border-color: #2f3a4a;
    box-shadow: 0 0 0 3px rgba(47, 58, 74, 0.08);
    background: #ffffff;
}

.chat-composer__input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    resize: none;
    font-size: 14px;
    line-height: 1.45;
    color: #1f2937;
    max-height: 140px;
    min-height: 22px;
    padding: 6px 0;
    font-family: inherit;
}

.chat-composer__input::placeholder { color: #9ca3af; }

.chat-composer__send {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: #2f3a4a;
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 120ms ease-out, transform 120ms ease-out;
}

.chat-composer__send:hover:not(:disabled) {
    background: #1f2937;
    transform: scale(1.05);
}

.chat-composer__send:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
}

.chat-composer__hint {
    font-size: 11px;
    color: #9ca3af;
    margin: 6px 4px 0 4px;
}

.chat-composer__readonly {
    text-align: center;
    color: #6b7280;
    font-size: 13px;
    padding: 10px;
}

/* "New message ↓" pill shown when user is scrolled up and a message arrives */
.chat-new-pill {
    position: sticky;
    bottom: 8px;
    align-self: center;
    background: #2f3a4a;
    color: #ffffff;
    border: none;
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.18);
    cursor: pointer;
    margin-top: auto;
}

.chat-new-pill:hover { background: #1f2937; }

/* =========================================================
   Invoice summary card (right column on Chat tab)
   ========================================================= */
.summary-card {
    background: #ffffff;
    border: 1px solid #e6ebf1;
    border-radius: 12px;
    padding: 16px 18px;
    position: sticky;
    top: 16px;
}

.summary-card__eyebrow {
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.summary-card__number {
    font-size: 20px;
    font-weight: 700;
    color: #1f2937;
    letter-spacing: 0.3px;
    font-variant-numeric: tabular-nums;
}

.summary-card__divider {
    border: none;
    border-top: 1px solid #eef2f6;
    margin: 14px 0;
}

.summary-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 12px;
}

.summary-row:first-of-type { margin-top: 0; }

.summary-row__label {
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.summary-row__value {
    font-size: 14px;
    font-weight: 500;
    color: #2f3a4a;
    text-align: right;
}

.summary-row__value--amount {
    font-size: 16px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.summary-stack {
    margin-top: 14px;
}

.summary-stack__label {
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 3px;
}

.summary-stack__value {
    font-size: 14px;
    font-weight: 500;
    color: #2f3a4a;
    line-height: 1.4;
}

/* =========================================================
   Status pills (shared: summary card, header, history grid)
   ========================================================= */
.status-pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
    line-height: 1.5;
    white-space: nowrap;
    border: 1px solid transparent;
}

.status-pill--draft     { background: #e5e7eb; color: #374151; }
.status-pill--submitted { background: #dbeafe; color: #1e40af; }
.status-pill--pending   { background: #fef3c7; color: #92400e; }
.status-pill--completed { background: #d1fae5; color: #065f46; }
.status-pill--paid      { background: #dcfce7; color: #14532d; }
