/* ============================================================
   Birfair Dental — Chat Widget (Mobile-First Responsive)
   ============================================================ */
.chat-widget *,
.chat-widget *::before,
.chat-widget *::after {
    box-sizing:border-box;
    margin:0;
    padding:0
}
.chat-widget{
    font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
    font-size:14px;
    line-height:1.5;
    color:#1a1a2e;
    z-index:9999;
    /* Improve text rendering on mobile */
    -webkit-font-smoothing:antialiased;
    -moz-osx-font-smoothing:grayscale
}

/* ══════════════════════════════
   TOGGLE BUTTON (Mobile-first)
   ══════════════════════════════ */
.chat-toggle{
    position:fixed;
    bottom:20px /* Slightly higher on small screens */;
    right:20px;
    width:56px;
    height:56px;
    min-width:48px /* Touch-friendly */;
    min-height:48px;
    border-radius:50%;
    background:linear-gradient(135deg,#2563EB,#1D4ED8);
    border:none;
    cursor:pointer;
    display:flex;
    align-items:center;
    justify-content:center;
    box-shadow:0 4px 16px rgba(37,99,235,0.35);
    transition:all .25s cubic-bezier(0.4,0,0.2,1);
    z-index:10000;
    color:#fff;
    /* Prevent tap highlight on mobile */
    -webkit-tap-highlight-color:transparent;
    /* Touch-action for better UX */
    touch-action:manipulation
}
.chat-toggle:hover,
.chat-toggle:active{
    transform:scale(1.08);
    box-shadow:0 6px 24px rgba(37,99,235,0.45)
}
/* Active/pressed state for tactile feedback */
.chat-toggle:active{
    transform:scale(0.95);
    transition-duration:.1s
}
.chat-toggle .badge{
    position:absolute;
    top:-4px;
    right:-4px;
    min-width:20px;
    height:20px;
    border-radius:50%;
    background:#EF4444;
    color:#fff;
    font-size:11px;
    font-weight:700;
    display:flex;
    align-items:center;
    justify-content:center;
    padding:0 5px;
    box-shadow:0 2px 6px rgba(239,68,68,0.4)
}
.chat-toggle .badge.hidden{display:none}

/* ══════════════════════════════
   CHAT PANEL (Mobile-first layout)
   ══════════════════════════════ */
.chat-panel{
    position:fixed;
    bottom:90px /* Adjusted for mobile */;
    right:16px;
    width:calc(100vw - 32px) /* Full width with margins on mobile */;
    max-width:380px;
    max-height:65vh /* Use viewport height on mobile */;
    background:#fff;
    border-radius:16px;
    box-shadow:
        0 12px 48px rgba(0,0,0,0.15),
        0 2px 8px rgba(0,0,0,0.08),
        0 0 0 1px rgba(0,0,0,0.04) /* Subtle border for definition */;
    display:none;
    flex-direction:column;
    overflow:hidden;
    z-index:9999;
    animation:cpIn .25s cubic-bezier(0.4,0,0.2,1);
    /* Hardware acceleration for smooth animation */
    will-change:transform, opacity;
    /* Prevent overscroll bounce on iOS */
    -webkit-overflow-scrolling:touch;
    /* Safe area support for notched devices */
    padding-bottom:env(safe-area-inset-bottom,0px)
}
.chat-panel.open{display:flex}
@keyframes cpIn{
    from{
        opacity:0;
        transform:translateY(16px) scale(0.96)
    }
    to{
        opacity:1;
        transform:translateY(0) scale(1)
    }
}

/* ══════════════════════════════
   PANEL HEADER (Touch-optimized)
   ══════════════════════════════ */
.cp-header{
    padding:14px 16px /* Slightly reduced for mobile */;
    background:linear-gradient(135deg,#2563EB,#1D4ED8);
    color:#fff;
    display:flex;
    align-items:center;
    justify-content:space-between;
    cursor:pointer;
    flex-shrink:0;
    /* Larger touch target */
    min-height:48px
}
.cp-title{
    font-weight:700;
    font-size:15px;
    display:flex;
    align-items:center;
    gap:8px
}
.cp-title .status-dot{
    width:8px;
    height:8px;
    border-radius:50%;
    background:#22C55E;
    animation:pulse 2s infinite
}
@keyframes pulse{
    0%,100%{opacity:1}
    50%{opacity:0.4}
}
.cp-close{
    background:none;
    border:none;
    color:rgba(255,255,255,0.7);
    cursor:pointer;
    font-size:20px /* Slightly larger for touch */;
    padding:8px /* Larger touch target */;
    border-radius:6px;
    transition:.15s;
    min-width:36px;
    min-height:36px;
    display:flex;
    align-items:center;
    justify-content:center;
    /* Prevent tap highlight */
    -webkit-tap-highlight-color:transparent
}
.cp-close:hover,
.cp-close:active{
    color:#fff;
    background:rgba(255,255,255,0.1)
}

/* ══════════════════════════════
   WELCOME MESSAGE
   ══════════════════════════════ */
.cp-welcome{
    text-align:center;
    color:#9ca3af;
    font-size:13px;
    line-height:1.6;
    padding:24px 16px
}

/* ══════════════════════════════
   MESSAGES AREA (Mobile-optimized scrolling)
   ══════════════════════════════ */
.cp-messages{
    flex:1;
    overflow-y:auto;
    padding:14px 12px /* Reduced side padding for mobile */;
    display:flex;
    flex-direction:column;
    gap:8px;
    background:#f3f4f6;
    min-height:180px;
    max-height:calc(65vh - 140px) /* Dynamic based on panel size */;
    /* Smooth momentum scrolling on iOS */
    -webkit-overflow-scrolling:touch;
    /* Hide scrollbar on mobile but keep functionality */
    scrollbar-width:thin;
    scrollbar-color:rgba(0,0,0,0.1) transparent
}
/* Custom scrollbar for desktop */
.cp-messages::-webkit-scrollbar{width:4px}
.cp-messages::-webkit-scrollbar-thumb{
    background:rgba(0,0,0,0.1);
    border-radius:2px
}
.cp-msg{
    max-width:88% /* Wider messages on mobile */;
    padding:10px 14px /* Slightly more padding for readability */;
    border-radius:14px;
    font-size:14px /* Slightly larger on mobile for readability */;
    line-height:1.55;
    word-break:break-word;
    animation:msgIn .2s ease;
    /* Ensure long words break properly */
    overflow-wrap:break-word;
    hyphens:auto
}
@keyframes msgIn{
    from{
        opacity:0;
        transform:translateY(8px)
    }
    to{
        opacity:1;
        transform:translateY(0)
    }
}
.cp-msg.visitor{
    align-self:flex-end;
    background:#2563EB;
    color:#fff;
    border-bottom-right-radius:4px
}
.cp-msg.admin{
    align-self:flex-start;
    background:#fff;
    color:#1a1a2e;
    border-bottom-left-radius:4px;
    box-shadow:0 1px 3px rgba(0,0,0,0.06)
}
.cp-msg-time{
    font-size:10.5px;
    opacity:0.5;
    margin-top:4px;
    text-align:right
}
.cp-msg.admin .cp-msg-time{text-align:left}
.cp-msg-name{
    font-size:10.5px;
    opacity:0.6;
    margin-bottom:2px
}
.cp-sys{
    text-align:center;
    color:#9ca3af;
    font-size:12px;
    padding:6px 0
}

/* ══════════════════════════════
   TOOLBAR + INPUT AREA (Touch-optimized)
   ══════════════════════════════ */
.cp-toolbar{
    display:flex;
    padding:6px 12px 0 /* Adjusted for mobile */;
    gap:6px;
    flex-shrink:0
}
.cp-toolbar button{
    background:none;
    border:1px solid #e5e7eb;
    border-radius:6px;
    padding:6px 10px /* Larger touch targets */;
    cursor:pointer;
    font-size:17px /* Larger icons for touch */;
    transition:.15s;
    min-width:36px;
    min-height:36px;
    display:flex;
    align-items:center;
    justify-content:center;
    /* Prevent tap highlight */
    -webkit-tap-highlight-color:transparent
}
.cp-toolbar button:hover,
.cp-toolbar button:active{background:#f3f4f6}

.cp-input-area{
    display:flex;
    align-items:flex-end;
    gap:8px;
    padding:8px 12px 12px /* Adjusted for mobile */;
    flex-shrink:0;
    position:relative
}
.cp-input-area textarea{
    flex:1;
    padding:11px 13px /* Larger for touch */;
    border:1.5px solid #d1d5db;
    border-radius:12px /* More rounded for modern look */;
    font-size:16px!important /* iOS zoom prevention */;
    outline:none;
    resize:none;
    font-family:inherit;
    line-height:1.45;
    max-height:100px;
    min-height:42px /* Taller minimum for touch */;
    transition:.15s;
    /* Better mobile experience */
    touch-action:manipulation
}
.cp-input-area textarea:focus{
    border-color:#2563EB;
    box-shadow:0 0 0 3px rgba(37,99,235,0.08)
}
.cp-input-area textarea::placeholder{color:#b0b7c3}

.cp-input-area .btn-send{
    background:#2563EB;
    color:#fff;
    border:none;
    padding:11px 18px /* Larger touch target */;
    border-radius:12px;
    font-size:15px;
    font-weight:600;
    cursor:pointer;
    white-space:nowrap;
    transition:.15s;
    min-height:42px;
    min-width:64px /* Ensure adequate touch area */;
    /* Tactile feedback */
    touch-action:manipulation;
    -webkit-tap-highlight-color:transparent
}
.cp-input-area .btn-send:hover,
.cp-input-area .btn-send:active{background:#1D4ED8}
.cp-input-area .btn-send:active{
    transform:scale(0.95);
    transition-duration:.1s
}
.cp-input-area .btn-send:disabled{
    opacity:0.4;
    cursor:not-allowed
}

/* ══════════════════════════════
   EMOJI PANEL (Mobile-enhanced)
   ══════════════════════════════ */
.cp-emoji-panel{
    position:absolute;
    bottom:100%;
    left:12px;
    right:12px;
    background:#fff;
    border:1px solid #e5e7eb;
    border-radius:14px;
    box-shadow:
        0 8px 30px rgba(0,0,0,0.12),
        0 2px 8px rgba(0,0,0,0.06);
    display:none;
    z-index:100;
    margin-bottom:8px;
    /* Hardware acceleration */
    will-change:transform, opacity;
    /* Prevent body scroll when open on mobile */
    -webkit-overflow-scrolling:touch
}
.cp-emoji-panel.show{display:block}
.cp-emoji-tabs{
    display:flex;
    border-bottom:1px solid #f3f4f6;
    overflow-x:auto;
    padding:0 8px;
    /* Hide scrollbar but keep scrollable */
    scrollbar-width:none;
    -ms-overflow-style:none
}
.cp-emoji-tabs::-webkit-scrollbar{display:none}
.cp-emoji-tab{
    padding:10px 12px /* Larger touch targets */;
    cursor:pointer;
    font-size:12px;
    color:#9ca3af;
    border:none;
    background:none;
    font-family:inherit;
    white-space:nowrap;
    transition:.15s;
    border-bottom:2px solid transparent;
    min-height:44px /* Touch-friendly tabs */
}
.cp-emoji-tab:hover,
.cp-emoji-tab:active,
.cp-emoji-tab.active{
    color:#2563EB;
    border-bottom-color:#2563EB
}
.cp-emoji-grid{
    display:grid;
    grid-template-columns:repeat(8,1fr);
    gap:2px;
    padding:10px;
    max-height:180px /* Slightly taller on mobile */;
    overflow-y:auto;
    /* Smooth scrolling */
    -webkit-overflow-scrolling:touch
}
.cp-emoji-item{
    font-size:24px /* Larger emojis for easier selection on mobile */;
    cursor:pointer;
    padding:6px 4px /* More padding for larger touch areas */;
    text-align:center;
    border-radius:6px;
    transition:.1s;
    /* Touch optimization */
    min-width:36px;
    min-height:36px;
    display:flex;
    align-items:center;
    justify-content:center;
    -webkit-tap-highlight-color:transparent
}
.cp-emoji-item:hover,
.cp-emoji-item:active{
    background:#f3f4f6;
    transform:scale(1.15)
}

/* ════════════════════════════════════
   TABLET & DESKTOP ENHANCEMENTS
   ════════════════════════════════════ */

/* Small tablets and large phones (≥480px) */
@media(min-width:480px){
    .chat-panel{
        right:24px;
        bottom:90px;
        max-height:60vh
    }
    .chat-toggle{
        right:24px;
        bottom:24px
    }

    .cp-header{padding:14px 18px}
    .cp-messages{
        padding:16px;
        max-height:400px
    }
    .cp-msg{max-width:82%;font-size:13.5px}
    .cp-toolbar{padding:6px 14px 0}
    .cp-toolbar button{padding:4px 8px;font-size:15px}
    .cp-input-area{padding:8px 14px 14px}
    .cp-emoji-panel{left:14px;right:14px}
    .cp-emoji-grid{max-height:160px}
}

/* Desktop (≥768px) */
@media(min-width:768px){
    .chat-panel{
        width:380px;
        max-width:380px;
        right:24px;
        bottom:96px;
        max-height:600px /* Original desktop size */
    }
    .chat-toggle{
        bottom:24px;
        right:24px
    }

    /* Revert some mobile-specific adjustments to original values */
    .cp-input-area textarea{
        font-size:14px /* Allow smaller font on desktop where no zoom issue */
    }
}
