/**
 * @skill hatdaukhaai-livechat-telegram
 * @see .agents/skills/hatdaukhaai-livechat-telegram/SKILL.md
 */
/* Livechat widget panel — Task 11, mobile-first max-width breakpoints only */

:root {
    --lc-primary: var(--hdk-primary, #2456d8);
    --lc-primary-dark: #1a44b0;
    --lc-bg: #efeae2;
    --lc-bg-dark: #0b141a;
    --lc-surface-dark: #111b21;
    --lc-bubble-in: #ffffff;
    --lc-bubble-in-dark: #202c33;
    --lc-bubble-out: var(--lc-primary);
    --lc-bubble-out-dark: #005c4b;
    --lc-composer-bg: #f0f2f5;
    --lc-composer-bg-dark: #202c33;
    --lc-input-bg: #ffffff;
    --lc-input-bg-dark: #2a3942;
    --lc-text: #111b21;
    --lc-text-dark: #e9edef;
    --lc-muted: #6b7280;
    --lc-muted-dark: #9ca3af;
    --lc-border: var(--hdk-border, #e1eaef);
    --lc-shadow-panel: 0 8px 30px rgba(0, 0, 0, 0.15);
    --lc-shadow-bubble: 0 1px 0.5px rgba(0, 0, 0, 0.13);
    --lc-radius-panel: 16px;
    --lc-radius-bubble: 14px;
    --lc-header-height: 56px;
    --lc-transition-panel: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.2s ease, visibility 0.2s;
}

/* Dropdown item accents (livechat entry in tools menu) */
.ai-chat-tools-icon--livechat {
    background: rgba(245, 158, 11, 0.14);
    color: #d97706;
}

html.dark .ai-chat-tools-icon--livechat {
    background: rgba(245, 158, 11, 0.22);
    color: #fbbf24;
}

.ai-chat-tools-badge--live {
    background: rgba(16, 185, 129, 0.18);
    color: #059669;
}

html.dark .ai-chat-tools-badge--live {
    background: rgba(16, 185, 129, 0.28);
    color: #6ee7b7;
}

/* FAB unread badge */
.livechat-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    z-index: 5;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 9999px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    border: 2px solid var(--lc-primary);
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.45);
    pointer-events: none;
}

.livechat-fab-badge[hidden] {
    display: none !important;
}

html.dark .livechat-fab-badge {
    border-color: #1f2937;
    box-shadow: none;
}

/* Panel shell — desktop default (card above FAB area) */
.livechat-panel {
    position: fixed;
    right: 20px;
    bottom: 88px;
    z-index: 1081;
    width: 380px;
    height: min(560px, 80vh);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    background: var(--lc-bg);
    border-radius: var(--lc-radius-panel);
    box-shadow: var(--lc-shadow-panel);
    overflow: hidden;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(16px);
    transition: var(--lc-transition-panel);
}

.livechat-panel[hidden] {
    display: none !important;
}

.livechat-panel.is-open {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

html.dark .livechat-panel {
    background: var(--lc-bg-dark);
    box-shadow: none;
    border: 1px solid var(--lc-border);
}

/* Header */
.livechat-header {
    flex: 0 0 auto;
    height: var(--lc-header-height);
    min-height: var(--lc-header-height);
    padding: 0 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: linear-gradient(135deg, var(--lc-primary) 0%, var(--lc-primary-dark) 100%);
    color: #fff;
}

.livechat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1 1 auto;
}

.livechat-avatar {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 9999px;
    background: #fff;
    border: 2px solid rgba(255, 255, 255, 0.25);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.livechat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.livechat-title-wrap {
    min-width: 0;
}

.livechat-title {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
    color: #fff;
}

.livechat-subtitle {
    margin: 2px 0 0;
    font-size: 11px;
    line-height: 1.35;
    color: rgba(255, 255, 255, 0.82);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.livechat-header .ai-chat-icon-btn {
    flex: 0 0 auto;
    min-width: 40px;
    min-height: 40px;
}

/* Messages area */
.livechat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--lc-bg);
}

html.dark .livechat-messages {
    background: var(--lc-surface-dark);
}

/* Message rows */
.livechat-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    max-width: 92%;
}

.livechat-row--out {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.livechat-row--in {
    align-self: flex-start;
}

.livechat-avatar--msg {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    border-radius: 9999px;
    overflow: hidden;
    background: #fff;
}

.livechat-avatar--msg img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Bubbles */
.livechat-bubble {
    position: relative;
    padding: 10px 12px;
    border-radius: var(--lc-radius-bubble);
    font-size: 14px;
    line-height: 1.55;
    box-shadow: var(--lc-shadow-bubble);
    max-width: 100%;
    word-break: break-word;
}

.livechat-bubble p {
    margin: 0;
}

.livechat-bubble--in {
    background: var(--lc-bubble-in);
    color: var(--lc-text);
    border-top-left-radius: 4px;
}

.livechat-bubble--out {
    background: var(--lc-bubble-out);
    color: #fff;
    border-top-right-radius: 4px;
}

html.dark .livechat-bubble {
    box-shadow: none;
}

html.dark .livechat-bubble--in {
    background: var(--lc-bubble-in-dark);
    color: var(--lc-text-dark);
}

html.dark .livechat-bubble--out {
    background: var(--lc-bubble-out-dark);
    color: var(--lc-text-dark);
}

/* Bubble tails (reuse AI tail pattern) */
.livechat-bubble--in.bubble-tail-in::before {
    content: "";
    position: absolute;
    top: 0;
    left: -8px;
    width: 0;
    height: 0;
    border-top: 10px solid var(--lc-bubble-in);
    border-left: 10px solid transparent;
    z-index: 1;
}

.livechat-bubble--out.bubble-tail-out::before {
    content: "";
    position: absolute;
    top: 0;
    right: -8px;
    width: 0;
    height: 0;
    border-top: 10px solid var(--lc-bubble-out);
    border-right: 10px solid transparent;
    z-index: 1;
}

html.dark .livechat-bubble--in.bubble-tail-in::before {
    border-top-color: var(--lc-bubble-in-dark);
}

html.dark .livechat-bubble--out.bubble-tail-out::before {
    border-top-color: var(--lc-bubble-out-dark);
}

/* Image bubble */
.livechat-bubble--image,
.livechat-bubble-image {
    padding: 4px;
    background: transparent;
    box-shadow: none;
    max-width: 70%;
}

/* Bubble ảnh: bỏ mũi tên (nền trong suốt, mũi tên màu bubble trông lệch) */
.livechat-bubble--image.bubble-tail-in::before,
.livechat-bubble--image.bubble-tail-out::before {
    content: none;
}

/* Bubble ảnh sát mép cột theo chiều tin nhắn; nền trong suốt nên text dùng màu thường */
.livechat-bubble--out.livechat-bubble--image {
    margin-left: auto;
    color: var(--lc-text);
}

.livechat-bubble--in.livechat-bubble--image {
    margin-right: auto;
}

.livechat-bubble--image .livechat-time,
.livechat-bubble--out.livechat-bubble--image .livechat-time {
    color: var(--lc-muted);
}

html.dark .livechat-bubble--out.livechat-bubble--image {
    color: var(--lc-text-dark);
}

html.dark .livechat-bubble--image .livechat-time,
html.dark .livechat-bubble--out.livechat-bubble--image .livechat-time {
    color: var(--lc-muted-dark);
}

.livechat-bubble-image a.livechat-image-zoom,
.livechat-bubble--image a.livechat-image-zoom {
    display: block;
    cursor: zoom-in;
    border-radius: 12px;
    overflow: hidden;
}

.livechat-bubble-image img,
.livechat-bubble--image img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 280px;
    object-fit: cover;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.06);
}

.livechat-panel.is-dragover {
    outline: 2px dashed var(--lc-primary);
    outline-offset: -8px;
}

.livechat-panel.is-dragover .livechat-messages {
    opacity: 0.72;
}

.livechat-bubble--out.livechat-bubble--image,
.livechat-bubble--out .livechat-bubble-image {
    background: transparent;
}

/* System message badge */
.livechat-system {
    align-self: center;
    max-width: 90%;
    margin: 4px 0;
    padding: 6px 12px;
    font-size: 12px;
    line-height: 1.45;
    text-align: center;
    color: var(--lc-muted);
    background: rgba(0, 0, 0, 0.06);
    border-radius: 9999px;
}

html.dark .livechat-system {
    color: var(--lc-muted-dark);
    background: rgba(255, 255, 255, 0.08);
}

.livechat-system--warn {
    color: #8a6d1f;
    background: rgba(244, 185, 66, 0.18);
    border-radius: 12px;
}

html.dark .livechat-system--warn {
    color: #f4d78a;
    background: rgba(244, 185, 66, 0.12);
}

.livechat-system--error {
    color: #b42318;
    background: rgba(220, 53, 69, 0.12);
    border-radius: 12px;
}

html.dark .livechat-system--error {
    color: #ff8a8a;
    background: rgba(220, 53, 69, 0.18);
}

/* Meta / time / delivery status */
.livechat-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 4px;
}

.livechat-time {
    font-size: 10px;
    color: var(--lc-muted);
}

.livechat-bubble--out .livechat-time {
    color: rgba(255, 255, 255, 0.72);
}

html.dark .livechat-bubble--in .livechat-time {
    color: var(--lc-muted-dark);
}

.livechat-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.75);
}

.livechat-status iconify-icon {
    font-size: 12px;
    line-height: 1;
}

/* Pending / typing dots */
.livechat-dots {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 0;
}

.livechat-dots span {
    width: 7px;
    height: 7px;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.65);
    animation: livechat-dot 1.2s ease-in-out infinite;
}

.livechat-bubble--in .livechat-dots span {
    background: rgba(17, 27, 33, 0.35);
}

html.dark .livechat-bubble--in .livechat-dots span {
    background: rgba(233, 237, 239, 0.55);
}

.livechat-dots span:nth-child(2) {
    animation-delay: 0.15s;
}

.livechat-dots span:nth-child(3) {
    animation-delay: 0.3s;
}

.livechat-pending-text {
    font-size: 12px;
    color: inherit;
    opacity: 0.85;
}

@keyframes livechat-dot {
    0%,
    80%,
    100% {
        transform: translateY(0);
        opacity: 0.55;
    }

    40% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* Closed session banner */
.livechat-closed-banner {
    flex: 0 0 auto;
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.45;
    text-align: center;
    color: #92400e;
    background: #fef3c7;
    border-top: 1px solid #fde68a;
}

.livechat-closed-banner[hidden] {
    display: none !important;
}

.livechat-closed-banner button {
    margin-left: 4px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--lc-primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    min-height: 40px;
}

html.dark .livechat-closed-banner {
    color: #fcd34d;
    background: #1c1917;
    border-top-color: #44403c;
    box-shadow: none;
}

html.dark .livechat-closed-banner button {
    color: #93c5fd;
}

/* Guest name form */
.livechat-name-form {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--lc-composer-bg);
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.livechat-name-form[hidden] {
    display: none !important;
}

.livechat-name-form input {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid var(--lc-border);
    border-radius: 9999px;
    font-size: 14px;
    color: var(--lc-text);
    background: var(--lc-input-bg);
    outline: none;
}

.livechat-name-form input:focus {
    border-color: rgba(36, 86, 216, 0.45);
}

.livechat-name-form button {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 8px 14px;
    border: 0;
    border-radius: 9999px;
    background: var(--lc-primary);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.livechat-name-form button:hover {
    background: var(--lc-primary-dark);
}

html.dark .livechat-name-form {
    background: var(--lc-composer-bg-dark);
    border-top-color: rgba(255, 255, 255, 0.08);
    box-shadow: none;
}

html.dark .livechat-name-form input {
    background: var(--lc-input-bg-dark);
    border-color: var(--lc-border);
    color: var(--lc-text-dark);
}

/* Footer composer */
.livechat-footer {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    background: var(--lc-composer-bg);
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.livechat-footer .ai-chat-tool-btn,
.livechat-footer .ai-chat-send-btn {
    flex: 0 0 auto;
    min-width: 40px;
    min-height: 40px;
    width: 40px;
    height: 40px;
}

.livechat-input {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 40px;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: 9999px;
    font-size: 14px;
    line-height: 1.4;
    color: var(--lc-text);
    background: var(--lc-input-bg);
    outline: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.livechat-input::placeholder {
    color: var(--lc-muted);
}

.livechat-input:focus {
    border-color: rgba(36, 86, 216, 0.35);
}

.livechat-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

html.dark .livechat-footer {
    background: var(--lc-composer-bg-dark);
    border-top-color: rgba(255, 255, 255, 0.08);
    box-shadow: none;
}

html.dark .livechat-input {
    background: var(--lc-input-bg-dark);
    color: var(--lc-text-dark);
    box-shadow: none;
}

html.dark .livechat-input::placeholder {
    color: var(--lc-muted-dark);
}

/* Tablet */
@media (max-width: 991.98px) {
    .livechat-panel {
        right: 16px;
        bottom: 80px;
        width: min(380px, calc(100vw - 32px));
    }
}

/* Mobile bottom sheet */
@media (max-width: 768px) {
    .livechat-panel {
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        height: 85dvh;
        max-height: 85dvh;
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
    }

    .livechat-panel.is-open {
        transform: translateY(0);
    }

    .livechat-footer {
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }
}

/* Small mobile */
@media (max-width: 576px) {
    .livechat-header {
        padding: 0 10px;
    }

    .livechat-title {
        font-size: 14px;
    }

    .livechat-messages {
        padding: 10px;
        gap: 8px;
    }

    .livechat-footer {
        padding: 8px 10px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        gap: 6px;
    }

    .livechat-name-form {
        padding: 8px 10px;
    }
}

/* Very small screens */
@media (max-width: 350px) {
    .livechat-subtitle {
        font-size: 10px;
    }

    .livechat-name-form button {
        padding: 8px 10px;
        font-size: 12px;
    }

    .livechat-input {
        font-size: 13px;
        padding: 8px 12px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .livechat-panel {
        transition: opacity 0.15s ease, visibility 0.15s ease;
        transform: none !important;
    }

    .livechat-panel.is-open {
        transform: none !important;
    }

    .livechat-dots span {
        animation: none;
        opacity: 0.7;
    }

    .livechat-pending-text {
        display: inline;
    }
}
