:root {
    /* Fintech Palette */
    --primary: #092d76;
    --accent: #cc1818;
    --accent-glow: rgba(204, 24, 24, 0.15);
    --bg: #f8fafc;
    --surface: #ffffff;
    --text-main: #1e293b;
    --text-sub: #64748b;
    --line: #e2e8f0;
    --success: #10b981;
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 10px 10px -5px rgba(15, 23, 42, 0.04);
    --font: 'DM Sans', sans-serif;
}

/* --- Base Reset --- */
#ldc-widget * {
    box-sizing: border-box;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

/* Use specific ID to contain styles */
#ldc-widget {
    font-family: var(--font);
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
    line-height: normal;
    /* Reset line height */
}

/* --- Launcher Button --- */
#ldc-widget .launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 64px;
    height: 64px;
    background: var(--primary);
    /* Solid Color */
    border-radius: 50%;
    box-shadow: 0 8px 32px rgba(9, 45, 118, 0.35);
    border: none;
    cursor: pointer;
    /* High Z-index */
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: grid;
    place-items: center;
    padding: 0;
    margin: 0;
}

#ldc-widget .launcher:hover {
    transform: scale(1.1) rotate(-5deg);
}

#ldc-widget .launcher svg {
    width: 32px;
    height: 32px;
    fill: white;
    pointer-events: none;
}

#ldc-widget .notification-dot {
    position: absolute;
    top: 0;
    right: 0;
    width: 16px;
    height: 16px;
    background: #ef4444;
    border: 2px solid white;
    border-radius: 50%;
    animation: bounce 2s infinite;
}

/* --- Chat Main Container --- */
#ldc-widget .chat-widget {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    height: 680px;
    max-width: calc(100vw - 48px);
    max-height: calc(100vh - 160px);
    /* Increased top gap */
    background: var(--bg);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 999999;
    /* High Z-index */
    border: 1px solid var(--line);
    overscroll-behavior: contain;
    /* Prevent background scroll chaining */
    opacity: 0;
    transform: translateY(20px) scale(0.96);
    transition: opacity 0.3s, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#ldc-widget .chat-widget.active {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* --- Header --- */
#ldc-widget .header {
    background: var(--primary);
    color: white;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    /* Prevent shrinking */
}

#ldc-widget .header.secure-active {
    background: #064e3b;
    /* Darker Green shade */
    transition: background 0.3s ease;
}

#ldc-widget .brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

#ldc-widget .brand-logo {
    width: 36px;
    height: 36px;
    background: white;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: var(--primary);
    font-weight: 800;
    font-size: 18px;
}

#ldc-widget .brand-info h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: white;
    line-height: 1.2;
}

#ldc-widget .brand-info p {
    margin: 0;
    font-size: 11px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 4px;
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.2;
}

#ldc-widget .live-dot {
    width: 6px;
    height: 6px;
    background: #22c55e;
    border-radius: 50%;
}

#ldc-widget .actions {
    display: flex;
    gap: 8px;
}

#ldc-widget .icon-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background 0.2s;
    padding: 0;
}

#ldc-widget .icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* --- Message Area --- */
#ldc-widget .messages {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    overscroll-behavior: contain;
    /* Prevent chaining */
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 20px;
    /* Increased spacing */
}

#ldc-widget .msg-row {
    display: flex;
    gap: 12px;
    opacity: 0;
    transform: translateY(10px);
    animation: ldcSlideIn 0.3s forwards;
    margin: 0;
}

#ldc-widget .msg-row.user {
    justify-content: flex-end;
}

#ldc-widget .avatar {
    width: 36px;
    height: 36px;
    /* Slightly larger */
    background: #e2e8f0;
    border-radius: 50%;
    background-size: cover;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#ldc-widget .avatar.system {
    background-image: url('https://ui-avatars.com/api/?name=L+D&background=0f172a&color=fff');
}

#ldc-widget .bubble {
    max-width: 85%;
    padding: 14px 18px;
    /* More breathing room */
    border-radius: 18px;
    font-size: 14.5px;
    /* Better readability */
    line-height: 1.6;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

#ldc-widget .msg-row.system .bubble {
    background: var(--surface);
    border-top-left-radius: 4px;
    color: var(--text-main);
}

/* Default System Avatar */
#ldc-widget .msg-row .avatar.system {
    background: black;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
}

#ldc-widget .msg-row .avatar.system::after {
    content: "LD";
    font-size: 15px;
    /* Increased to 15px */
    font-weight: 600;
    letter-spacing: 0.5px;
    font-family: var(--font);
}

#ldc-widget .msg-row.user .bubble {
    background: var(--accent);
    color: white;
    border-top-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

/* --- Rich Elements --- */
#ldc-widget .card {
    background: white;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 8px;
    margin-top: 8px;
    box-shadow: var(--shadow-sm);
}

#ldc-widget .card-header {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 12px;
    color: var(--primary);
}

#ldc-widget .chips-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

#ldc-widget .chip {
    background: white;
    border: 1px solid var(--line);
    padding: 14px 16px;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    margin: 0;
}

/* Hover Arrow Effect */
#ldc-widget .chip::after {
    content: '→';
    font-weight: 700;
    opacity: 0;
    transform: translateX(-10px);
    transition: all 0.2s;
    color: var(--accent);
}

#ldc-widget .chip:hover {
    border-color: var(--accent);
    background: var(--accent-glow);
    color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
}

#ldc-widget .chip:hover::after {
    opacity: 1;
    transform: translateX(0);
}

/* --- Input Area --- */
#ldc-widget .input-bar {
    background: white;
    border-top: 1px solid var(--line);
    padding: 16px 20px;
    display: flex;
    gap: 12px;
    align-items: center;
    flex-shrink: 0;
    /* Prevent shrinking */
}

#ldc-widget .input-box {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 24px;
    padding: 14px 18px;
    font-size: 15px;
    transition: border 0.2s, box-shadow 0.2s;
    color: var(--text-main);
    margin: 0;
}

#ldc-widget .input-box:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#ldc-widget .send-btn {
    background: var(--primary);
    color: white;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: transform 0.2s;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.2);
    padding: 0;
    margin: 0;
}

#ldc-widget .send-btn:hover {
    transform: scale(1.05);
}

#ldc-widget .send-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* --- Special Interactions --- */
#ldc-widget .ticket-view {
    text-align: center;
    border: 2px dashed var(--line);
    padding: 24px;
    margin: 12px 0;
    border-radius: 16px;
    background: #fff;
}

#ldc-widget .ticket-id {
    font-family: monospace;
    font-size: 18px;
    color: var(--accent);
    font-weight: 700;
    letter-spacing: 1px;
    margin: 8px 0;
}

/* --- Big Actions --- */
#ldc-widget .big-actions {
    display: flex;
    flex-direction: column;
    /* Stacked for mobile focus */
    gap: 12px;
    margin-top: 20px;
}

#ldc-widget .big-btn {
    width: 100%;
    padding: 12px 16px;
    /* Reduced padding */
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: hidden;
    text-align: left;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    margin: 0;
}

#ldc-widget .big-btn:hover {
    transform: scale(1.02);
    box-shadow: 0 12px 24px -8px rgba(0, 0, 0, 0.3);
}

/* Glassy Icon container */
#ldc-widget .btn-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(4px);
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

#ldc-widget .btn-content {
    display: flex;
    flex-direction: column;
    gap: 0px;
    /* Reduced gap */
}

#ldc-widget .btn-title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.1;
    /* Tighter line height */
    letter-spacing: -0.01em;
}

#ldc-widget .btn-sub {
    font-size: 12px;
    opacity: 0.9;
    font-weight: 400;
}

/* Specific Colors */
#ldc-widget .btn-wa {
    background: #25D366;
}

#ldc-widget .btn-call {
    background: var(--primary);
}

/* Arrow Hint */
#ldc-widget .big-btn::after {
    content: '→';
    position: absolute;
    right: 20px;
    font-weight: bold;
    transform: translateX(-10px);
    transition: all 0.2s;
}

/* --- Minimal Case Card --- */
#ldc-widget .case-card.minimal {
    background: white;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    text-align: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    margin-top: 10px;
}

#ldc-widget .case-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #64748b;
    margin-bottom: 8px;
    font-weight: 600;
}

#ldc-widget .case-number {
    font-family: var(--font);
    /* Tech feel */
    font-size: 28px;
    font-weight: 700;
    color: #092d76;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

#ldc-widget .case-meta {
    font-size: 11px;
    color: #10b981;
    /* Green for valid */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

#ldc-widget .case-meta::before {
    content: '●';
    font-size: 8px;
}

#ldc-widget .big-btn:hover::after {
    opacity: 1;
    transform: translateX(0);
}


/* --- Animations --- */
@keyframes ldcSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Archive View --- */
#ldc-widget .archive-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg);
    z-index: 20;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#ldc-widget .archive-overlay.open {
    transform: translateX(0);
}

#ldc-widget .archive-header {
    padding: 16px 20px;
    background: white;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    color: var(--primary);
}

#ldc-widget .archive-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#ldc-widget .archive-item {
    background: white;
    padding: 16px;
    border-radius: 16px;
    border: 1px solid var(--line);
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    margin: 0;
}

#ldc-widget .archive-item:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

#ldc-widget .archive-delete {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #ffe5e5;
    color: #cc1818;
    border: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    transition: all 0.2s;
    z-index: 2;
    padding: 0;
}

#ldc-widget .archive-delete:hover {
    background: #cc1818;
    color: white;
    transform: scale(1.1);
}

#ldc-widget .archive-meta {
    font-size: 11px;
    color: var(--text-sub);
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

#ldc-widget .archive-case {
    font-size: 16px;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 2px;
}

#ldc-widget .archive-name {
    font-size: 13px;
    color: var(--text-main);
}

#ldc-widget .empty-state {
    text-align: center;
    opacity: 0.5;
    margin-top: 40px;
    font-size: 14px;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-3px);
    }
}

#ldc-widget .typing-dots span {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    display: inline-block;
    animation: ldcTyping 1.4s infinite ease-in-out both;
    margin: 0 1px;
}

#ldc-widget .typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

#ldc-widget .typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes ldcTyping {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* --- Mobile Responsiveness --- */
@media (max-width: 600px) {
    #ldc-widget .input-bar {
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
        /* Reduced from 20px */
        background: white;
        /* Ensure opaque background behind safe area */
    }

    /* Prevent iOS Zoom on focus */
    #ldc-widget .input-box {
        font-size: 16px !important;
    }

    #ldc-widget .chat-widget {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 60px !important;
        /* Added top margin */
        width: 100% !important;
        height: auto !important;
        /* Let top/bottom define height */
        /* Full dynamic height */
        max-height: none !important;
        /* Fallback for older iOS */
        border-radius: 20px 20px 0 0 !important;
        transform: translateY(100%);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15) !important;
        max-width: none !important;
        -webkit-overflow-scrolling: touch;
        /* Smooth scroll iOS */
        overscroll-behavior: contain;
        /* Prevent chaining */
    }

    #ldc-widget .chat-widget.active {
        transform: translateY(0);
    }

    #ldc-widget .launcher {
        bottom: 20px;
        right: 20px;
        width: 52px;
        /* Reduced from 64px */
        height: 52px;
        /* Reduced from 64px */
    }

    #ldc-widget .launcher svg {
        width: 26px;
        /* Reduced from 32px */
        height: 26px;
        /* Reduced from 32px */
    }
}

/* --- Case ID Card (Clean Professional) --- */
#ldc-widget .case-card {
    background: #ffffff;
    padding: 24px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    border: 1px solid #e2e8f0;
    margin: 16px 0;
    position: relative;
}

#ldc-widget .case-card-header {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #64748b;
    font-weight: 600;
    margin-bottom: 6px;
}

#ldc-widget .case-card-body {
    font-family: var(--font);
    font-size: 26px;
    font-weight: 800;
    letter-spacing: 1px;
    color: var(--primary);
    margin-bottom: 6px;
}

#ldc-widget .case-card-footer {
    font-size: 11px;
    color: #94a3b8;
    font-weight: 500;
}

/* --- Enhanced Big Actions --- */
#ldc-widget .big-btn {
    width: 100%;
    padding: 18px 24px;
    border-radius: 16px;
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    text-align: left;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    margin: 0;
    background-size: 200% auto;
}

#ldc-widget .big-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

#ldc-widget .btn-wa {
    background: #25D366;
    /* WhatsApp Green */
}

#ldc-widget .btn-call {
    background: var(--primary);
    /* Brand Color */
}

/* --- Rating Options --- */
#ldc-widget .rating-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
}

#ldc-widget .rating-opt {
    background: white;
    border: 1px solid var(--line);
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    margin: 0;
}

#ldc-widget .rating-opt:hover {
    background: #fffbef;
    border-color: #fbbf24;
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}