/* Base styles */
:root {
    /* Tsinghua University Theme Colors */
    --primary-color: #660874;
    /* Tsinghua Purple */
    --primary-light: #8E2B9D;
    /* Lighter purple for hovers/gradients */
    --primary-tint: rgba(102, 8, 116, 0.08);
    /* Very light purple tint for chips/bg */

    --bg-color: #F8F8FA;
    /* Slightly cooler light grey */
    --btn-bg: #EAEAEF;
    --msg-bg-white: #FFFFFF;
    --text-dark: #1F1F2C;
    --text-muted: #8B8B9E;

    --border-radius-lg: 24px;
    --border-radius-md: 16px;
    --border-radius-sm: 8px;

    --shadow-subtle: 0 4px 12px rgba(102, 8, 116, 0.06);
    /* Tinted shadow */
    --shadow-strong: 0 12px 32px rgba(102, 8, 116, 0.12);
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

body {
    font-family: var(--font-family);
    background-color: #e0e0f0;
    /* Page background, adjust as needed */
    margin: 0;
    padding: 0;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Widget Container */
.livechat-widget {
    width: 380px;
    max-width: 100%;
    height: 640px;
    background-color: var(--bg-color);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-strong);
    display: flex;
    flex-direction: column;
    overflow: hidden;

    /* Animation Styles */
    position: fixed;
    bottom: 90px;
    right: 24px;
    opacity: 1;
    transform: scale(1);
    transform-origin: bottom right;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
}

/* Hidden state for widget */
.livechat-widget.hidden {
    opacity: 0;
    transform: scale(0.5) translate(20px, 20px);
    pointer-events: none;
}

/* Launcher Button */
.livechat-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    /* Gradient background for a more premium look */
    background: linear-gradient(135deg, var(--primary-light), var(--primary-color));
    border: none;
    box-shadow: var(--shadow-strong);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 1000;
    color: #FFFFFF;
    /* White icon on dark purple */
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.2s ease;
}

.livechat-launcher:hover {
    transform: scale(1.08);
    box-shadow: 0 16px 40px rgba(102, 8, 116, 0.25);
}

.livechat-launcher svg {
    position: absolute;
    width: 28px;
    height: 28px;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.livechat-launcher .msg-icon {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.livechat-launcher .x-icon {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Launcher states */
.livechat-launcher.closed .msg-icon {
    opacity: 1;
    transform: rotate(0) scale(1);
    animation: breathe 2s ease-in-out infinite;
}

.livechat-launcher.closed .x-icon {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

@keyframes breathe {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.15);
    }

    100% {
        transform: scale(1);
    }
}

/* Header (Floating controls) */
.livechat-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;

    /* Make it semi-transparent fading down */
    background: linear-gradient(to bottom, var(--bg-color) 40%, transparent);

    /* Add subtle blur for items passing beneath the top solid part */
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.header-left,
.header-right {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* Center Agent Pill in Header */
.header-agent-pill {
    display: flex;
    align-items: center;
    background-color: var(--msg-bg-white);
    padding: 6px 16px 6px 6px;
    border-radius: 30px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
    /* Slightly stronger shadow to lift off background */
    gap: 10px;
    margin: 0 10px;
    /* buffer from side buttons */
}

.agent-avatar-sm-pill {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: #4C4B63;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    flex-shrink: 0;
}

.agent-avatar-sm-pill svg {
    width: 14px;
    height: 14px;
    fill: var(--primary-color);
}

.online-indicator-sm {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 10px;
    height: 10px;
    background-color: #0CAF60;
    border: 2px solid var(--msg-bg-white);
    border-radius: 50%;
}

.agent-name-pill {
    font-weight: 700;
    color: var(--text-dark);
    font-size: 14px;
    white-space: nowrap;
}

.icon-btn-round {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--btn-bg);
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: var(--text-dark);
    transition: background-color 0.2s;
}

.icon-btn-round:hover {
    background-color: #dcdce2;
}

.icon-btn-round svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Messages Area */
.livechat-messages {
    flex-grow: 1;
    padding: 60px 16px 16px 16px;
    /* Space for top header */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Push messages down when there are few of them (anchors to bottom view) */
.livechat-messages> :first-child {
    margin-top: auto;
}

/* Agent Profile Card in Chat */
.agent-profile-card {
    background-color: var(--msg-bg-white);
    border-radius: var(--border-radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-subtle);
    width: fit-content;
    align-self: center;
    margin-bottom: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
}

.agent-header-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.agent-avatar-lg {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #4C4B63;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.agent-avatar-lg svg {
    width: 20px;
    height: 20px;
    fill: var(--primary-color);
}

.online-indicator {
    position: absolute;
    top: 0;
    right: -2px;
    width: 12px;
    height: 12px;
    background-color: #0CAF60;
    border: 2px solid var(--msg-bg-white);
    border-radius: 50%;
}

.agent-info {
    text-align: left;
}

.agent-name {
    font-weight: 600;
    color: var(--text-dark);
    font-size: 14px;
    margin: 0;
    line-height: 1.2;
}

.agent-role {
    color: var(--text-muted);
    font-size: 12px;
    margin: 2px 0 0 0;
}

.feedback-actions {
    display: flex;
    gap: 16px;
}

.feedback-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    color: var(--text-dark);
}

.feedback-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Message Bubbles */
.message {
    display: flex;
    max-width: 90%;
    gap: 8px;
}

.message.incoming {
    align-self: flex-start;
}

.message.outgoing {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar-sm {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: #4C4B63;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    margin-top: 4px;
    /* Align with top text line */
}

.message-avatar-sm svg {
    width: 12px;
    height: 12px;
    fill: var(--primary-color);
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-bubble {
    padding: 14px 16px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-dark);
    word-break: break-word;
    box-shadow: var(--shadow-subtle);
}

.message.incoming .message-bubble {
    background-color: var(--msg-bg-white);
    /* Top-left, Top-right, Bottom-right, Bottom-left */
    border-radius: var(--border-radius-sm) var(--border-radius-lg) var(--border-radius-lg) var(--border-radius-lg);
}

.message.outgoing .message-bubble {
    background: linear-gradient(135deg, var(--primary-light), var(--primary-color));
    color: #FFFFFF;
    border-radius: var(--border-radius-lg) var(--border-radius-sm) var(--border-radius-lg) var(--border-radius-lg);
}

.human-support-link {
    font-size: 11px;
    color: var(--text-muted);
    text-decoration: none;
    margin-top: 4px;
    opacity: 0.7;
    transition: opacity 0.2s, color 0.2s;
    width: 100%;
    text-align: center;
    display: block;
}

.human-support-link:hover {
    opacity: 1;
    color: var(--primary-color);
    text-decoration: underline;
}

.message-status {
    font-size: 11px;
    color: var(--text-muted);
    align-self: flex-end;
    /* right align for outgoing */
    margin-top: -2px;
}

/* Typewriter Cursor */
.typewriter-cursor {
    display: inline-block;
    width: 2px;
    height: 14px;
    background-color: var(--text-dark);
    vertical-align: middle;
    margin-left: 2px;
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

/* Suggested Questions */
.suggestions-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
    padding-left: 40px;
    /* Align with message bubble (24px avatar + 8px gap + 8px padding) */
    max-width: 85%;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.suggestions-container.visible {
    opacity: 1;
    transform: translateY(0);
}

.suggestion-chip {
    background-color: transparent;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-family);
    cursor: pointer;
    text-align: left;
    transition: background-color 0.2s, transform 0.1s, color 0.2s;
    width: fit-content;
}

.suggestion-chip:hover {
    background-color: var(--primary-color);
    color: #FFFFFF;
}

.suggestion-chip:active {
    transform: scale(0.98);
}

/* Typing indicator */
.typing-indicator-container {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 14px 16px;
    background-color: var(--msg-bg-white);
    /* Match the incoming message bubble shape: Top-left, Top-right, Bottom-right, Bottom-left */
    border-radius: var(--border-radius-sm) var(--border-radius-lg) var(--border-radius-lg) var(--border-radius-lg);
    box-shadow: var(--shadow-subtle);
    width: fit-content;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background-color: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Area */
.livechat-input-area {
    padding: 0 16px 8px 16px;
    background-color: var(--bg-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-container {
    display: flex;
    align-items: center;
    background-color: var(--msg-bg-white);
    border-radius: 30px;
    padding: 8px 8px 8px 16px;
    box-shadow: var(--shadow-subtle);
    gap: 8px;
}

.icon-btn-flat {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-dark);
}

.icon-btn-flat svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.livechat-input {
    flex-grow: 1;
    border: none;
    outline: none;
    font-size: 14px;
    font-family: var(--font-family);
    padding: 6px 0;
    background: transparent;
    color: var(--text-dark);
    height: 24px;
    line-height: 24px;
}

.livechat-input::placeholder {
    color: var(--text-muted);
}

.send-btn-round {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--btn-bg);
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: default;
    /* Inactive by default */
    color: #A0A0B0;
}

.send-btn-round.active {
    background-color: var(--primary-color);
    color: #FFFFFF;
    cursor: pointer;
    box-shadow: 0 4px 10px var(--primary-tint);
}

.send-btn-round svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Footer */
.livechat-footer {
    text-align: center;
    padding-bottom: 12px;
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.livechat-footer img {
    height: 12px;
    vertical-align: middle;
}

.livechat-footer span {
    font-weight: 500;
    color: var(--text-dark);
}

/* Custom scrollbar */
.livechat-messages::-webkit-scrollbar {
    width: 4px;
}

.livechat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.livechat-messages::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}