/* ==================== AGD.Chat — WhatsApp-Like Styling ==================== */

:root {
    --chat-bg: #E5DDD5;
    --chat-header-bg: #075E54;
    --chat-header-text: #FFFFFF;
    --chat-sent-bg: #DCF8C6;
    --chat-received-bg: #FFFFFF;
    --chat-accent: #075E54;
    --chat-input-bg: #F0F0F0;
    --chat-border: #E0E0E0;
    --chat-text: #303030;
    --chat-text-secondary: #667781;
    --chat-time-color: #667781;
    --chat-send-btn: #075E54;
}

/* ==================== RESET & BASE ==================== */

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    background: var(--chat-bg);
}

/* ==================== LAYOUT ==================== */

.chat-page {
    height: 100dvh;
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #d6cfc5;
}

.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    background: var(--chat-bg);
    position: relative;
    overflow: hidden;
    min-height: 0;
    border-radius: 0 0 16px 16px;
}

/* ==================== HEADER (full-width) ==================== */

.chat-header {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    background: var(--chat-header-bg);
    color: var(--chat-header-text);
    gap: 12px;
    flex-shrink: 0;
    z-index: 10;
    min-height: 60px;
    width: 100%;
}

.chat-header-avatar {
    flex-shrink: 0;
}

.chat-header-logo {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-header-logo-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    color: #FFFFFF;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-name {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-status {
    font-size: 12px;
    opacity: 0.8;
}

.chat-header-online span::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #25D366;
    margin-right: 4px;
    vertical-align: middle;
}

/* ==================== CHAT BODY ==================== */

.chat-body {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: var(--chat-bg);
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23c8c4be' fill-opacity='0.15'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

/* ==================== TELERIK CHAT OVERRIDES ==================== */

/* --- Container --- */
.chat-body .k-chat {
    border: none;
    background: transparent;
    font-family: inherit;
}

/* --- Message list (scrollable area) --- */
.chat-body .k-chat .k-message-list {
    background: transparent;
    padding: 12px 12px 8px;
}

.chat-body .k-chat .k-message-list::-webkit-scrollbar {
    width: 6px;
}

.chat-body .k-chat .k-message-list::-webkit-scrollbar-track {
    background: transparent;
}

.chat-body .k-chat .k-message-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

/* --- Message groups --- */
.chat-body .k-chat .k-message-group {
    gap: 2px;
    max-width: 85%;
}

/* --- Individual messages --- */
.chat-body .k-chat .k-message {
    max-width: 100%;
}

/* --- Bubble base --- */
.chat-body .k-chat .k-bubble {
    max-width: 100%;
    padding: 7px 11px 7px 11px;
    font-size: 14.2px;
    line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: break-word;
    border: none;
    position: relative;
}

/* --- SENT bubbles (current user = sender) --- */
.chat-body .k-chat .k-message-group-sender .k-chat-bubble {
    background: var(--chat-sent-bg);
    color: var(--chat-text);
    border-radius: 7.5px 7.5px 2px 7.5px;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

/* First sent bubble in a group gets top-right tail */
.chat-body .k-chat .k-message-group-sender .k-message:first-child .k-chat-bubble {
    border-radius: 7.5px 2px 2px 7.5px;
}

/* Last sent bubble in a group */
.chat-body .k-chat .k-message-group-sender .k-message:last-child .k-chat-bubble {
    border-radius: 7.5px 7.5px 2px 7.5px;
}

/* Only bubble in group */
.chat-body .k-chat .k-message-group-sender .k-message:only-child .k-chat-bubble {
    border-radius: 7.5px 2px 2px 7.5px;
}

/* --- RECEIVED bubbles (other = receiver) --- */
.chat-body .k-chat .k-message-group-receiver .k-chat-bubble {
    background: var(--chat-received-bg);
    color: var(--chat-text);
    border-radius: 7.5px 7.5px 7.5px 2px;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

/* First received bubble in a group gets top-left tail */
.chat-body .k-chat .k-message-group-receiver .k-message:first-child .k-chat-bubble {
    border-radius: 2px 7.5px 7.5px 2px;
}

/* Last received bubble */
.chat-body .k-chat .k-message-group-receiver .k-message:last-child .k-chat-bubble {
    border-radius: 7.5px 7.5px 7.5px 2px;
}

/* Only bubble in group */
.chat-body .k-chat .k-message-group-receiver .k-message:only-child .k-chat-bubble {
    border-radius: 2px 7.5px 7.5px 7.5px;
}

/* --- Timestamps --- */
.chat-body .k-chat .k-message-time {
    font-size: 11px;
    color: var(--chat-time-color);
    padding: 0 4px;
    opacity: 0.85;
}

/* --- Hide author name & avatar (business name shown in header) --- */
.chat-body .k-chat .k-author,
.chat-body .k-chat .k-message-author {
    display: none;
}

.chat-body .k-chat .k-avatar {
    display: none;
}

/* --- Hide Telerik's built-in input (we use custom textarea) --- */
.k-chat .k-message-box-wrapper {
    display: none !important;
}

/* ==================== CUSTOM INPUT AREA ==================== */

.chat-input-area {
    flex-shrink: 0;
    padding: 8px 10px;
    background: var(--chat-input-bg);
    border-top: 1px solid var(--chat-border);
    border-radius: 0 0 16px 16px;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #FFFFFF;
    border: 1px solid var(--chat-border);
    border-radius: 21px;
    padding-right: 4px;
    transition: border-color 0.2s;
}

.chat-input-wrapper:focus-within {
    border-color: var(--chat-accent);
}

.chat-input {
    flex: 1;
    min-width: 0;
    resize: none;
    border: none;
    border-radius: 0;
    background: transparent;
    padding: 9px 16px;
    font-size: 15px;
    font-family: inherit;
    line-height: 1.35;
    color: var(--chat-text);
    outline: none;
    overflow-y: hidden;
    max-height: 120px;
}

.chat-input:focus {
    border-color: var(--chat-accent);
}

.chat-input::placeholder {
    color: var(--chat-text-secondary);
}

.chat-input:disabled {
    opacity: 0.6;
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--chat-send-btn);
    color: #FFFFFF;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s, transform 0.1s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.chat-send-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.chat-send-btn:not(:disabled):hover {
    opacity: 0.88;
}

.chat-send-btn:not(:disabled):active {
    transform: scale(0.93);
}

/* --- Message appear animation --- */
.chat-body .k-chat .k-bubble {
    animation: chatBubbleIn 0.2s ease-out;
}

@keyframes chatBubbleIn {
    from {
        opacity: 0;
        transform: translateY(6px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* --- Remove any default Telerik borders/outlines --- */
.chat-body .k-chat,
.chat-body .k-chat *:focus {
    outline: none;
    box-shadow: none;
}

/* --- Scroll to bottom button --- */
.chat-body .k-chat .k-scroll-to-bottom,
.chat-body .k-chat .k-chat-scroll-to-bottom {
    background: #FFFFFF;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    border: none;
    right: 16px;
    bottom: 70px;
}

/* --- Date separators --- */
.chat-body .k-chat .k-timestamp {
    font-size: 12px;
    color: var(--chat-time-color);
    background: rgba(225, 218, 208, 0.75);
    padding: 4px 12px;
    border-radius: 7.5px;
    margin: 8px auto;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
}

/* ==================== CUSTOM MESSAGE HELPERS ==================== */

.chat-text {
    white-space: pre-wrap;
}

/* ==================== TYPING INDICATOR ==================== */

.chat-typing-indicator {
    padding: 4px 16px 8px;
    display: flex;
    align-items: center;
}

.chat-typing-dots {
    display: flex;
    gap: 4px;
    background: var(--chat-received-bg);
    padding: 10px 16px;
    border-radius: 18px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}

.chat-typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chat-text-secondary);
    animation: chatTypingBounce 1.4s infinite ease-in-out;
}

.chat-typing-dots span:nth-child(1) { animation-delay: 0s; }
.chat-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatTypingBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ==================== LOADING ==================== */

.chat-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100dvh;
    gap: 16px;
    color: var(--chat-text-secondary);
}

.chat-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--chat-border);
    border-top-color: var(--chat-accent);
    border-radius: 50%;
    animation: chatSpin 0.8s linear infinite;
}

@keyframes chatSpin {
    to { transform: rotate(360deg); }
}

/* ==================== EXPIRED PAGE ==================== */

.chat-expired {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100dvh;
    padding: 24px;
    background: #FAFAFA;
}

.chat-expired-content {
    text-align: center;
    max-width: 400px;
}

.chat-expired-icon {
    margin-bottom: 16px;
}

.chat-expired-content h2 {
    font-size: 22px;
    color: var(--chat-text);
    margin: 0 0 8px 0;
}

.chat-expired-content p {
    font-size: 15px;
    color: var(--chat-text-secondary);
    margin: 0 0 8px 0;
    line-height: 1.5;
}

.chat-expired-hint {
    font-size: 13px !important;
    margin-top: 16px !important;
}

/* ==================== NOT FOUND ==================== */

.chat-not-found {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100dvh;
    text-align: center;
    padding: 24px;
    color: var(--chat-text-secondary);
}

.chat-not-found h2 {
    color: var(--chat-text);
    margin-bottom: 8px;
}

/* ==================== RESPONSIVE ==================== */

@media (min-width: 601px) {
    .chat-container {
        border-left: 1px solid var(--chat-border);
        border-right: 1px solid var(--chat-border);
    }
}

@media (max-width: 600px) {
    .chat-container {
        max-width: 100%;
    }

    .chat-body .k-chat .k-message-group {
        max-width: 90%;
    }
}

/* Safe area for iOS notch */
@supports (padding-top: env(safe-area-inset-top)) {
    .chat-header {
        padding-top: calc(10px + env(safe-area-inset-top));
    }

    .chat-input-area {
        padding-bottom: calc(6px + env(safe-area-inset-bottom));
    }
}

/* ==================== Blazor Reconnect UI ==================== */
/* Hide default Blazor reconnect overlay completely during initial connection */
#components-reconnect-modal.components-reconnect-hide {
    display: none;
}

#components-reconnect-modal.components-reconnect-show #components-reconnect-show {
    display: block !important;
}

#components-reconnect-modal.components-reconnect-failed #components-reconnect-failed {
    display: block !important;
}

#components-reconnect-modal.components-reconnect-rejected #components-reconnect-rejected {
    display: block !important;
}
