/**
 * Touch (تاچ) - Smart Contact Hub Widget Styles
 * Main widget styles with 7 style variations and theming support
 * 
 * @package Touch
 * @version 1.0.0
 */

/* ============================================
   All Plugin Fonts — Local (Self-Hosted)
   Loaded once here; activated via --tch-font CSS var
   ============================================ */

@font-face {
    font-family: 'Vazir';
    src: url('../fonts/vazir.woff2') format('woff2');
    font-weight: 400 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Samim';
    src: url('../fonts/samim.woff2') format('woff2');
    font-weight: 400 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Shabnam';
    src: url('../fonts/shabnam.woff2') format('woff2');
    font-weight: 400 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Sahel';
    src: url('../fonts/sahel.woff2') format('woff2');
    font-weight: 400 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Nahid';
    src: url('../fonts/nahid.woff2') format('woff2');
    font-weight: 400 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Parastoo';
    src: url('../fonts/parastoo.woff2') format('woff2');
    font-weight: 400 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Gandom';
    src: url('../fonts/gandom.woff2') format('woff2');
    font-weight: 400 700;
    font-style: normal;
    font-display: swap;
}

/* ============================================
   CSS Custom Properties (Theming System)
   ============================================ */

:root {
    /* Color Theme */
    --tch-primary-color: #3b82f6;
    --tch-secondary-color: #ffffff;
    --tch-text-color: #1f2937;
    --tch-shadow-color: rgba(0, 0, 0, 0.1);
    
    /* Font — default set here as fallback; overridden per-widget via inline style */
    --tch-font: 'Vazir', Tahoma, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    /* Sizing */
    --tch-button-size: 60px;
    --tch-icon-size: 24px;
    --tch-corner-radius: 50%;
    
    /* Shadow */
    --tch-shadow-blur: 20px;
    --tch-shadow-spread: 0px;
    
    /* Spacing */
    --tch-spacing-sm: 8px;
    --tch-spacing-md: 16px;
    --tch-spacing-lg: 24px;
    
    /* Z-Index */
    --tch-z-index: 999999;
    
    /* Transitions */
    --tch-transition-speed: 300ms;
    --tch-transition-easing: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   Base Widget Container
   ============================================ */

.tch-widget {
    position: fixed;
    z-index: var(--tch-z-index);
    font-family: var(--tch-font);
    font-size: var(--tch-channel-title-size, 14px);
    line-height: 1.5;
    color: var(--tch-text-color);
    box-sizing: border-box;
    display: flex;
    flex-direction: column-reverse;
    /* Force LTR on the container so flex-start/flex-end
       map to physical left/right regardless of page direction */
    direction: ltr;
    gap: var(--tch-spacing-sm);
    transition: opacity var(--tch-transition-speed) var(--tch-transition-easing);
    /* Allow panel to overflow the button-sized container */
    overflow: visible;
}

/* Right-side positions: children stick to right */
.tch-widget.tch-position-bottom-right,
.tch-widget.tch-position-middle-right {
    align-items: flex-start;
}

/* Left-side positions: children stick to left */
.tch-widget.tch-position-bottom-left,
.tch-widget.tch-position-middle-left {
    align-items: flex-end;
}

/* Re-enable RTL inside the panel and button-wrap so text renders correctly */
.tch-widget-panel,
.tch-widget-button-wrap {
    direction: inherit; /* will inherit from html/body (rtl) */
}

.tch-widget *,
.tch-widget *::before,
.tch-widget *::after {
    box-sizing: border-box;
    font-family: var(--tch-font) !important;
}

/* Initial hidden state */
.tch-widget:not(.tch-visible) {
    opacity: 0;
    pointer-events: none;
}

.tch-widget.tch-visible {
    opacity: 1;
    /* pointer-events only on the button-wrap; panel gets its own rule below */
    pointer-events: none;
}

/* The toggle button is always clickable when widget is visible */
.tch-widget.tch-visible .tch-widget-button-wrap {
    pointer-events: auto;
}

/* Panel is only interactive when the widget is open */
.tch-widget.tch-visible .tch-widget-panel {
    pointer-events: none;
}

.tch-widget.tch-visible.tch-open .tch-widget-panel {
    pointer-events: auto;
}

/* ============================================
   Widget Positioning
   ============================================ */

/* Bottom Right */
.tch-widget.tch-position-bottom-right {
    bottom: var(--tch-offset-bottom, var(--tch-spacing-lg));
    right: var(--tch-offset-side, var(--tch-spacing-lg));
    left: auto;
}

/* Bottom Left */
.tch-widget.tch-position-bottom-left {
    bottom: var(--tch-offset-bottom, var(--tch-spacing-lg));
    left: var(--tch-offset-side, var(--tch-spacing-lg));
    right: auto;
}

/* Middle Right */
.tch-widget.tch-position-middle-right {
    top: 50%;
    right: var(--tch-spacing-lg);
    left: auto;
    transform: translateY(-50%);
}

.tch-widget.tch-position-middle-right.tch-visible {
    transform: translateY(-50%);
}

/* Middle Left */
.tch-widget.tch-position-middle-left {
    top: 50%;
    left: var(--tch-spacing-lg);
    right: auto;
    transform: translateY(-50%);
}

.tch-widget.tch-position-middle-left.tch-visible {
    transform: translateY(-50%);
}

/* ============================================
   Widget Button Wrapper (button + badge together)
   ============================================ */

.tch-widget-button-wrap {
    position: relative; /* badge is absolute inside this */
    display: inline-flex;
    flex-shrink: 0;
}

/* ============================================
   Widget Button (Closed State)
   ============================================ */

.tch-widget-button {
    width: var(--tch-button-size);
    height: var(--tch-button-size);
    background-color: var(--tch-primary-color);
    color: var(--tch-secondary-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
    transition: transform var(--tch-transition-speed) var(--tch-transition-easing),
                box-shadow var(--tch-transition-speed) var(--tch-transition-easing);
    outline: none;
}

.tch-widget-button:hover {
    transform: scale(1.05);
}

.tch-widget-button:focus-visible {
    outline: 2px solid var(--tch-primary-color);
    outline-offset: 2px;
}

.tch-widget-button:active {
    transform: scale(0.95);
}

/* Shadow */
.tch-widget.tch-shadow-enabled .tch-widget-button {
    box-shadow: 0 var(--tch-shadow-spread) var(--tch-shadow-blur) var(--tch-shadow-color);
}

/* Icon */
.tch-widget-button-icon {
    width: var(--tch-icon-size);
    height: var(--tch-icon-size);
    transition: transform var(--tch-transition-speed) var(--tch-transition-easing);
}

.tch-widget.tch-open .tch-widget-button-icon {
    transform: rotate(180deg);
}

/* Badge — hide when panel is open */
.tch-widget.tch-open .tch-widget-badge {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--tch-transition-speed) var(--tch-transition-easing),
                visibility var(--tch-transition-speed) var(--tch-transition-easing);
}

/* Badge */
.tch-widget-badge {
    position: absolute;
    background-color: var(--tch-secondary-color);
    color: var(--tch-primary-color);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: var(--tch-header-text-size, 12px);
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    pointer-events: none;
    opacity: 1;
    visibility: visible;
    transition: opacity var(--tch-transition-speed) var(--tch-transition-easing),
                visibility var(--tch-transition-speed) var(--tch-transition-easing);
}

.tch-widget-badge.tch-badge-top {
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: var(--tch-spacing-sm);
}

/* Prevent badge from overflowing screen edges on mobile */
@media (max-width: 768px) {
    /* Badge on right-side widgets — clamp to left */
    .tch-widget.tch-position-bottom-right .tch-widget-badge.tch-badge-top,
    .tch-widget.tch-position-middle-right .tch-widget-badge.tch-badge-top {
        left: auto;
        right: 0;
        transform: none;
    }

    /* Badge on left-side widgets — clamp to right */
    .tch-widget.tch-position-bottom-left .tch-widget-badge.tch-badge-top,
    .tch-widget.tch-position-middle-left .tch-widget-badge.tch-badge-top {
        left: 0;
        right: auto;
        transform: none;
    }
}

.tch-widget-badge.tch-badge-bottom {
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-top: var(--tch-spacing-sm);
}

.tch-widget-badge.tch-badge-left {
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-right: var(--tch-spacing-sm);
}

.tch-widget-badge.tch-badge-right {
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: var(--tch-spacing-sm);
}

/* ============================================
   Widget Panel (Open State)
   ============================================ */

.tch-widget-panel {
    position: absolute;
    /* Default: above the button, anchored to bottom of container */
    bottom: calc(var(--tch-button-size, 60px) + var(--tch-spacing-sm, 8px));
    background-color: var(--tch-secondary-color);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    padding: var(--tch-spacing-md);
    width: 300px;
    max-width: min(300px, calc(100vw - 32px));
    /* Prevent panel from exceeding viewport height */
    max-height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.85);
    transform-origin: bottom center;
    transition: opacity var(--tch-transition-speed) var(--tch-transition-easing),
                transform var(--tch-transition-speed) var(--tch-transition-easing),
                visibility var(--tch-transition-speed) var(--tch-transition-easing);
}

.tch-widget.tch-open .tch-widget-panel {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

/* ── Panel anchor: right-side positions → panel anchors to right edge of button ── */
.tch-widget.tch-position-bottom-right .tch-widget-panel,
.tch-widget.tch-position-middle-right .tch-widget-panel {
    right: 0;
    left: auto;
    transform-origin: bottom right;
}

/* ── Panel anchor: left-side positions → panel anchors to left edge of button ── */
.tch-widget.tch-position-bottom-left .tch-widget-panel,
.tch-widget.tch-position-middle-left .tch-widget-panel {
    left: 0;
    right: auto;
    transform-origin: bottom left;
}

/* ── Middle positions: panel sits beside button (centered vertically on button) ── */
.tch-widget.tch-position-middle-right .tch-widget-panel,
.tch-widget.tch-position-middle-left .tch-widget-panel {
    bottom: auto;
    top: 50%;
    transform: translateY(-50%) scale(0.85);
}

.tch-widget.tch-open.tch-position-middle-right .tch-widget-panel,
.tch-widget.tch-open.tch-position-middle-left .tch-widget-panel {
    transform: translateY(-50%) scale(1);
}

/* ── Bottom positions: open state transform-origin corrections ── */
.tch-widget.tch-open.tch-position-bottom-right .tch-widget-panel {
    transform-origin: bottom right;
}
.tch-widget.tch-open.tch-position-bottom-left .tch-widget-panel {
    transform-origin: bottom left;
}

/* Re-apply open state after transform-origin is set */
.tch-widget.tch-open .tch-widget-panel {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

/* Welcome text */
.tch-widget-welcome {
    margin-bottom: var(--tch-spacing-md);
    font-size: var(--tch-welcome-size, 16px);
    font-weight: 600;
    color: var(--tch-text-color);
}

/* Outside hours message */
.tch-widget-outside-hours-message {
    padding: var(--tch-spacing-md);
    background-color: #fef3c7;
    border-left: 4px solid #f59e0b;
    border-radius: 8px;
    color: #92400e;
    font-size: var(--tch-channel-desc-size, 14px);
    margin-bottom: var(--tch-spacing-md);
}

/* Channels list — supports both .tch-widget-channels (legacy) and .tch-channels-list (renderer) */
.tch-widget-channels,
.tch-channels-list {
    display: flex;
    flex-direction: column;
    gap: var(--tch-spacing-sm);
    /* Scrollable when content exceeds panel height */
    overflow-y: auto;
    overflow-x: hidden;
    /* Smooth momentum scrolling on iOS */
    -webkit-overflow-scrolling: touch;
    /* Reserve scrollbar space to avoid layout shift */
    scrollbar-gutter: stable;
}

/* Custom scrollbar — webkit */
.tch-widget-channels::-webkit-scrollbar,
.tch-channels-list::-webkit-scrollbar {
    width: 4px;
}

.tch-widget-channels::-webkit-scrollbar-track,
.tch-channels-list::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 4px;
}

.tch-widget-channels::-webkit-scrollbar-thumb,
.tch-channels-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    transition: background 0.2s ease;
}

.tch-widget-channels::-webkit-scrollbar-thumb:hover,
.tch-channels-list::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Firefox */
.tch-widget-channels,
.tch-channels-list {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

/* Single channel — supports both .tch-widget-channel (legacy) and .tch-channel (renderer) */
.tch-widget-channel,
.tch-channel {
    display: flex;
    align-items: center;
    padding: 12px;
    background-color: #f9fafb;
    border-radius: 8px;
    text-decoration: none;
    color: var(--tch-text-color);
    transition: background-color var(--tch-transition-speed) var(--tch-transition-easing),
                transform var(--tch-transition-speed) var(--tch-transition-easing);
    cursor: pointer;
}

/* Channel link inside .tch-channel */
.tch-channel-link {
    display: flex;
    align-items: center;
    width: 100%;
    text-decoration: none;
    color: inherit;
    font-family: inherit;
}

.tch-widget-channel:hover,
.tch-channel:hover {
    background-color: #f3f4f6;
    transform: translateX(4px);
}

.tch-widget-channel:active,
.tch-channel:active {
    transform: translateX(2px);
}

.tch-widget-channel:focus-visible,
.tch-channel-link:focus-visible {
    outline: 2px solid var(--tch-primary-color);
    outline-offset: 2px;
}

/* Disabled channel */
.tch-widget-channel.tch-disabled,
.tch-channel.tch-channel-disabled,
.tch-channel-link.tch-disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Channel icon — supports both .tch-widget-channel-icon and .tch-channel-icon */
.tch-widget-channel-icon,
.tch-channel-icon {
    margin-right: 12px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background-color: var(--tch-primary-color);
    color: var(--tch-secondary-color);
    overflow: hidden;
}

/* Icon background shape modes */
.tch-widget[style*="--tch-channel-icon-bg: none"] .tch-channel-icon,
.tch-widget[style*="--tch-channel-icon-bg:none"] .tch-channel-icon,
.tch-widget[style*="--tch-channel-icon-bg: none"] .tch-widget-channel-icon,
.tch-widget[style*="--tch-channel-icon-bg:none"] .tch-widget-channel-icon {
    background: transparent !important;
    box-shadow: none !important;
    border-radius: 0;
}

/* circle */
.tch-widget[style*="--tch-channel-icon-bg: circle"] .tch-channel-icon,
.tch-widget[style*="--tch-channel-icon-bg:circle"] .tch-channel-icon,
.tch-widget[style*="--tch-channel-icon-bg: circle"] .tch-widget-channel-icon,
.tch-widget[style*="--tch-channel-icon-bg:circle"] .tch-widget-channel-icon {
    border-radius: 50%;
}

/* rounded */
.tch-widget[style*="--tch-channel-icon-bg: rounded"] .tch-channel-icon,
.tch-widget[style*="--tch-channel-icon-bg:rounded"] .tch-channel-icon,
.tch-widget[style*="--tch-channel-icon-bg: rounded"] .tch-widget-channel-icon,
.tch-widget[style*="--tch-channel-icon-bg:rounded"] .tch-widget-channel-icon {
    border-radius: 30%;
}

.tch-widget-channel-icon img,
.tch-widget-channel-icon svg,
.tch-channel-icon img,
.tch-channel-icon svg {
    width: var(--tch-channel-icon-img-size, 40px) !important;
    height: var(--tch-channel-icon-img-size, 40px) !important;
    max-width: none !important;
    max-height: none !important;
    object-fit: contain;
    flex-shrink: 0;
    display: block;
}

/* Custom channel color */
.tch-widget-channel[data-custom-color] .tch-widget-channel-icon,
.tch-channel-link[style*="--channel-color"] .tch-channel-icon {
    background-color: var(--channel-color);
}

/* Channel content */
.tch-widget-channel-content,
.tch-channel-content {
    flex: 1;
    min-width: 0;
}

.tch-widget-channel-title,
.tch-channel-title {
    font-weight: 600;
    font-size: var(--tch-channel-title-size, 14px);
    margin-bottom: 2px;
}

.tch-widget-channel-description,
.tch-channel-description {
    font-size: var(--tch-channel-desc-size, 12px);
    color: #6b7280;
}

/* Channel arrow */
.tch-channel-arrow {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    color: #9ca3af;
    margin-left: 8px;
}

.tch-channel-arrow svg {
    width: 16px;
    height: 16px;
}

/* Welcome text */
.tch-welcome-text {
    margin-bottom: var(--tch-spacing-md);
    padding-bottom: var(--tch-spacing-md);
    border-bottom: 1px solid #f3f4f6;
}

.tch-welcome-text p {
    margin: 0;
    font-size: var(--tch-welcome-size, 15px);
    font-weight: 600;
    color: var(--tch-text-color);
}

/* Outside hours message */
.tch-outside-hours-message {
    padding: var(--tch-spacing-md);
    background-color: #fef3c7;
    border-left: 4px solid #f59e0b;
    border-radius: 8px;
    color: #92400e;
    font-size: var(--tch-channel-desc-size, 14px);
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.tch-outside-hours-message .tch-message-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    color: #f59e0b;
}

.tch-outside-hours-message .tch-message-icon svg {
    width: 20px;
    height: 20px;
}

.tch-outside-hours-message p {
    margin: 0;
}

/* ============================================
   STYLE 1: Floating Circle
   ============================================ */

.tch-widget.tch-style-floating-circle .tch-widget-button {
    border-radius: 50%;
}

/* ============================================
   STYLE 2: Floating Square
   ============================================ */

.tch-widget.tch-style-floating-square .tch-widget-button {
    border-radius: 0;
}

/* ============================================
   STYLE 3: Rounded Square
   ============================================ */

.tch-widget.tch-style-rounded-square .tch-widget-button {
    border-radius: 12px;
}

/* ============================================
   STYLE 4: Pill  (stretched capsule — less circular)
   ============================================ */

.tch-widget.tch-style-pill .tch-widget-button {
    width: auto;
    min-width: calc(var(--tch-button-size) * 1.8);
    height: calc(var(--tch-button-size) * 0.62);
    padding: 0 calc(var(--tch-spacing-md) * 1.5);
    border-radius: 12px;
}

.tch-widget.tch-style-pill .tch-widget-button-text {
    margin-left: var(--tch-spacing-sm);
    font-weight: 600;
    font-size: var(--tch-header-text-size, 14px);
}

/* ============================================
   STYLE 5: Chat Bubble
   ============================================ */

.tch-widget.tch-style-chat-bubble .tch-widget-button {
    border-radius: 50% 50% 0 50%;
}

.tch-widget.tch-style-chat-bubble.tch-position-bottom-left .tch-widget-button,
.tch-widget.tch-style-chat-bubble.tch-position-middle-left .tch-widget-button {
    border-radius: 50% 50% 50% 0;
}

/* ============================================
   STYLE 6: Side Panel  (slide-in drawer via toggle tab)
   ============================================ */

/* ── Trigger tab ── */
.tch-widget.tch-style-side-panel .tch-widget-button-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
}

.tch-widget.tch-style-side-panel .tch-widget-button {
    width: 36px;
    min-width: 36px;
    height: 80px;
    padding: 0;
    border-radius: 12px 0 0 12px;
    box-shadow: -4px 0 16px rgba(0,0,0,.18);
    flex-direction: column;
    gap: 6px;
}

/* flip tail for left-side placement */
.tch-widget.tch-style-side-panel.tch-position-bottom-left .tch-widget-button,
.tch-widget.tch-style-side-panel.tch-position-middle-left .tch-widget-button {
    border-radius: 0 12px 12px 0;
    box-shadow: 4px 0 16px rgba(0,0,0,.18);
}

/* tiny chevron arrows inside the tab */
.tch-widget.tch-style-side-panel .tch-widget-button .tch-button-icon,
.tch-widget.tch-style-side-panel .tch-widget-button .tch-button-close {
    transition: opacity var(--tch-transition-speed) var(--tch-transition-easing),
                transform var(--tch-transition-speed) var(--tch-transition-easing);
}

/* force widget to right/left edge at middle height */
.tch-widget.tch-style-side-panel.tch-position-bottom-right,
.tch-widget.tch-style-side-panel.tch-position-middle-right {
    right: 0 !important;
    bottom: auto !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    left: auto !important;
}

.tch-widget.tch-style-side-panel.tch-position-bottom-left,
.tch-widget.tch-style-side-panel.tch-position-middle-left {
    left: 0 !important;
    bottom: auto !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    right: auto !important;
}

/* ── Drawer panel ── */
.tch-widget.tch-style-side-panel .tch-widget-panel {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateX(110%) translateY(-50%);
    opacity: 1;
    visibility: hidden;
    width: 260px;
    max-width: 80vw;
    max-height: calc(100vh - 48px);
    border-radius: 16px 0 0 16px;
    box-shadow: -6px 0 32px rgba(0,0,0,.16);
    transition: transform 380ms cubic-bezier(0.4, 0, 0.2, 1),
                visibility 380ms cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
}

/* left-side variant */
.tch-widget.tch-style-side-panel.tch-position-bottom-left .tch-widget-panel,
.tch-widget.tch-style-side-panel.tch-position-middle-left .tch-widget-panel {
    right: auto;
    left: 0;
    transform: translateX(-110%) translateY(-50%);
    border-radius: 0 16px 16px 0;
    box-shadow: 6px 0 32px rgba(0,0,0,.16);
}

/* open state */
.tch-widget.tch-style-side-panel.tch-open .tch-widget-panel {
    transform: translateX(0) translateY(-50%);
    visibility: visible;
}

/* override global .tch-visible transform for side-panel */
.tch-widget.tch-style-side-panel.tch-position-middle-right.tch-visible,
.tch-widget.tch-style-side-panel.tch-position-bottom-right.tch-visible {
    transform: translateY(-50%) !important;
}

.tch-widget.tch-style-side-panel.tch-position-middle-left.tch-visible,
.tch-widget.tch-style-side-panel.tch-position-bottom-left.tch-visible {
    transform: translateY(-50%) !important;
}

.tch-widget.tch-style-side-panel .tch-widget-channels,
.tch-widget.tch-style-side-panel .tch-channels-list {
    gap: 6px;
    overflow-y: auto;
}

.tch-widget.tch-style-side-panel .tch-channel-arrow {
    display: none;
}

/* ============================================
   STYLE 7: Bottom Bar  (slide-up drawer via toggle button)
   ============================================ */

/* keep the widget glued to the bottom edge */
.tch-widget.tch-style-bottom-bar {
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100%;
    transform: none !important;
    flex-direction: column;      /* button above, drawer below (out of view) */
    align-items: center;
    gap: 0;
}

/* ── Trigger button ── */
.tch-widget.tch-style-bottom-bar .tch-widget-button-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    /* pill-shaped tab sitting on the bottom edge */
    background: var(--tch-primary-color);
    border-radius: 12px 12px 0 0;
    padding: 0 28px;
    box-shadow: 0 -4px 16px rgba(0,0,0,.18);
    position: relative;
    z-index: 1;
}

.tch-widget.tch-style-bottom-bar .tch-widget-button {
    width: auto;
    height: 40px;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
    padding: 0 12px;
    flex-direction: row;
    gap: 8px;
}

/* ── Drawer panel ── */
.tch-widget.tch-style-bottom-bar .tch-widget-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    transform: translateY(110%);
    opacity: 1;
    visibility: hidden;
    border-radius: 0;
    box-shadow: 0 -4px 32px rgba(0,0,0,.14);
    padding: var(--tch-spacing-md) var(--tch-spacing-lg);
    transition: transform 380ms cubic-bezier(0.4, 0, 0.2, 1),
                visibility 380ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* open state */
.tch-widget.tch-style-bottom-bar.tch-open .tch-widget-panel {
    transform: translateY(0);
    visibility: visible;
}

.tch-widget.tch-style-bottom-bar .tch-widget-channels,
.tch-widget.tch-style-bottom-bar .tch-channels-list {
    flex-direction: row;
    overflow-x: auto;
    gap: var(--tch-spacing-sm);
}

.tch-widget.tch-style-bottom-bar .tch-widget-channel,
.tch-widget.tch-style-bottom-bar .tch-channel {
    flex: 0 0 auto;
    min-width: 120px;
}

.tch-widget.tch-style-bottom-bar .tch-widget-welcome,
.tch-widget.tch-style-bottom-bar .tch-welcome-text {
    text-align: center;
}

/* ============================================
   Mobile Responsiveness
   ============================================ */

@media (max-width: 768px) {
    .tch-widget {
        --tch-button-size: 56px;
        --tch-icon-size: 22px;
        --tch-spacing-lg: 16px;
    }
    
    .tch-widget-panel {
        width: min(300px, calc(100vw - 32px));
        max-width: min(300px, calc(100vw - 32px));
        max-height: calc(100vh - 100px);
    }

    .tch-widget.tch-position-bottom-right .tch-widget-panel,
    .tch-widget.tch-position-middle-right .tch-widget-panel {
        right: 0;
        left: auto;
    }

    .tch-widget.tch-position-bottom-left .tch-widget-panel,
    .tch-widget.tch-position-middle-left .tch-widget-panel {
        left: 0;
        right: auto;
    }
    
    .tch-widget-badge {
        font-size: var(--tch-header-text-size, 11px);
        padding: 3px 10px;
    }
    
    /* Touch targets - minimum 44x44px */
    .tch-widget-button {
        min-width: 44px;
        min-height: 44px;
    }
    
    .tch-widget-channel,
    .tch-channel {
        min-height: 44px;
        padding: 10px;
    }
    
    /* Side Panel on mobile - keep the trigger tab a bit smaller */
    .tch-widget.tch-style-side-panel .tch-widget-button {
        width: 30px;
        min-width: 30px;
        height: 64px;
    }

    .tch-widget.tch-style-side-panel .tch-widget-panel {
        width: 220px;
        max-width: 75vw;
    }
    
    /* Bottom Bar on mobile - single column if too many channels */
    .tch-widget.tch-style-bottom-bar .tch-widget-channels,
    .tch-widget.tch-style-bottom-bar .tch-channels-list {
        flex-wrap: wrap;
    }
}

@media (max-width: 480px) {
    .tch-widget {
        --tch-button-size: 52px;
        --tch-spacing-lg: 12px;
    }
    
    .tch-widget-panel {
        width: min(280px, calc(100vw - 24px));
        max-width: min(280px, calc(100vw - 24px));
    }
}

/* ============================================
   Accessibility
   ============================================ */

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .tch-widget,
    .tch-widget *,
    .tch-widget-button,
    .tch-widget-panel,
    .tch-widget-channel {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .tch-widget-button {
        border: 2px solid currentColor;
    }
    
    .tch-widget-channel {
        border: 1px solid currentColor;
    }
}

/* Focus visible for keyboard navigation */
.tch-widget-button:focus-visible,
.tch-widget-channel:focus-visible {
    outline: 3px solid var(--tch-primary-color);
    outline-offset: 2px;
}

/* Screen reader only content */
.tch-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ============================================
   Disabled State
   ============================================ */

.tch-widget.tch-disabled .tch-widget-button {
    opacity: 0.6;
    cursor: not-allowed;
}

.tch-widget.tch-disabled .tch-widget-channels {
    opacity: 0.6;
}

/* ============================================
   Loading State
   ============================================ */

.tch-widget.tch-loading .tch-widget-button::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid var(--tch-secondary-color);
    border-top-color: transparent;
    border-radius: 50%;
    animation: tch-spin 0.6s linear infinite;
}

@keyframes tch-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   Channel Type Icons (SVG via background-image)
   These show when no custom icon_url is set
   ============================================ */

/* Default icon container for SVG icons rendered by PHP */
.tch-channel-icon svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    display: block;
    flex-shrink: 0;
}

/* Phone */
.tch-channel-phone .tch-channel-icon {
    background-color: #16a34a;
}

/* WhatsApp */
.tch-channel-whatsapp .tch-channel-icon {
    background-color: #25d366;
}

/* Telegram */
.tch-channel-telegram .tch-channel-icon {
    background-color: #229ed9;
}

/* Instagram */
.tch-channel-instagram .tch-channel-icon {
    background: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
}

/* Email */
.tch-channel-email .tch-channel-icon {
    background-color: #6366f1;
}

/* SMS */
.tch-channel-sms .tch-channel-icon {
    background-color: #0ea5e9;
}

/* Custom */
.tch-channel-custom .tch-channel-icon {
    background-color: var(--tch-primary-color);
}

/* Button icons (open/close toggle) */
.tch-widget-button .tch-button-icon,
.tch-widget-button .tch-button-close {
    width: var(--tch-icon-size);
    height: var(--tch-icon-size);
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: opacity var(--tch-transition-speed) var(--tch-transition-easing),
                transform var(--tch-transition-speed) var(--tch-transition-easing);
    display: block;
}

/* hidden icon sits on top of the visible one without taking space */
.tch-widget-button .tch-button-close {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-90deg);
    opacity: 0;
}

.tch-widget-button .tch-button-icon {
    opacity: 1;
    transform: rotate(0deg);
}

.tch-widget.tch-open .tch-widget-button .tch-button-icon {
    opacity: 0;
    transform: rotate(90deg);
}

.tch-widget.tch-open .tch-widget-button .tch-button-close {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0deg);
}

.tch-widget-button .tch-button-icon-img{width:var(--tch-icon-size);height:var(--tch-icon-size);object-fit:contain;display:block;stroke:unset;fill:unset;opacity:1;transform:rotate(0deg);transition:opacity var(--tch-transition-speed) var(--tch-transition-easing),transform var(--tch-transition-speed) var(--tch-transition-easing)}.tch-widget-button .tch-button-icon-svg{width:var(--tch-icon-size);height:var(--tch-icon-size);display:flex;align-items:center;justify-content:center;opacity:1;transform:rotate(0deg);transition:opacity var(--tch-transition-speed) var(--tch-transition-easing),transform var(--tch-transition-speed) var(--tch-transition-easing)}.tch-widget-button .tch-button-icon-svg svg{width:100%;height:100%;display:block}.tch-widget.tch-open .tch-widget-button .tch-button-icon-img,.tch-widget.tch-open .tch-widget-button .tch-button-icon-svg{opacity:0;transform:rotate(90deg)}
