/* ==========================================================================
   ️ TORA22 OFFICIAL AI CHAT LITE - ENTERPRISE SHARP DESIGN
   Fully Aligned with Cocoon Child Theme Design System & Mobile Optimized
   ========================================================================== */

:root {
    --tora-chat-primary: #2a4a6b;
    --tora-chat-primary-hover: #1d354d;
    --tora-chat-primary-light: #f0f5fa;
    --tora-chat-accent: #0284c7;
    --tora-chat-accent-hover: #0369a1;
    --tora-chat-bg-canvas: #fbfbfd;
    --tora-chat-bg-surface: #ffffff;
    --tora-chat-bg-card: #f5f5f7;
    --tora-chat-text-main: #1d1d1f;
    --tora-chat-text-muted: #515154;
    --tora-chat-text-subtle: #86868b;
    --tora-chat-border: #e5e5ea;
    --tora-chat-border-strong: #d2d2d7;
    --tora-chat-radius-pill: 9999px;
    --tora-chat-radius-card: 16px;
    --tora-chat-shadow: 0 4px 20px rgba(42, 74, 107, 0.08), 0 1px 3px rgba(0, 0, 0, 0.02);
}

/* ==========================================
    CHAT BOX CONTAINER
   ========================================== */
.tora-chat-box {
    display: flex;
    flex-direction: column;
    background: var(--tora-chat-bg-surface);
    border: 1px solid var(--tora-chat-border);
    border-radius: var(--tora-chat-radius-card);
    box-shadow: var(--tora-chat-shadow);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
    letter-spacing: -0.018em;
    overflow: hidden;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

/* 1. Embedded Console Mode (Support Page) */
.tora-embedded-chat-wrap {
    max-width: 820px;
    margin: 24px auto 36px auto;
    width: 100%;
    box-sizing: border-box;
}
.tora-chat-box.tora-embedded {
    height: var(--chat-height, 530px);
    width: 100%;
}

/* 2. Floating Mode (Desktop & Tablet) */
#tora-floating-widget-root {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999990;
}

.tora-floating-backdrop {
    display: none;
}

.tora-fab-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 22px;
    background: rgba(42, 74, 107, 0.95);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--tora-chat-radius-pill);
    font-size: 13.5px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(42, 74, 107, 0.28);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    outline: none;
}
.tora-fab-btn:hover {
    background: #1d354d;
    transform: translateY(-2px);
    box-shadow: 0 12px 28px rgba(42, 74, 107, 0.38);
}
.tora-fab-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.tora-sheet-handle-bar {
    display: none;
}

.tora-chat-box.tora-floating {
    position: fixed;
    top: 20px;
    bottom: 84px;
    right: 24px;
    width: 400px;
    height: calc(100vh - 104px);
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 104px);
    z-index: 999999;
    box-shadow: 0 16px 40px rgba(42, 74, 107, 0.16), 0 2px 6px rgba(0, 0, 0, 0.04);
    animation: toraFloatingScale 0.22s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes toraFloatingScale {
    0% { opacity: 0; transform: scale(0.94) translateY(12px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* ==========================================
    HEADER SECTION (Apple Blur Nav Style)
   ========================================== */
.tora-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-bottom: 1px solid var(--tora-chat-border);
    flex-shrink: 0;
}
.tora-chat-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--tora-chat-text-main);
}
.tora-chat-header-title strong {
    font-weight: 700;
}
.tora-chat-status-dot {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
}
.tora-chat-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--tora-chat-primary-light);
    color: var(--tora-chat-primary);
    border-radius: var(--tora-chat-radius-pill);
    font-size: 10.5px;
    font-weight: 800;
    letter-spacing: 0.03em;
}
.tora-close-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    color: #334155;
    cursor: pointer;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
    outline: none;
}
.tora-close-btn:hover {
    background: #e2e8f0;
    border-color: #cbd5e1;
    color: #0f172a;
    transform: scale(1.08);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}
.tora-close-btn:active {
    transform: scale(0.94);
    background: #cbd5e1;
}
.tora-close-btn svg {
    display: block;
    pointer-events: none;
}

/* ==========================================
    QUICK PROMPT CHIPS
   ========================================== */
.tora-quick-prompts {
    display: flex;
    gap: 7px;
    padding: 10px 16px;
    background: #fbfbfd;
    border-bottom: 1px solid var(--tora-chat-border);
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0;
}
.tora-quick-prompts::-webkit-scrollbar {
    display: none;
}
.tora-prompt-chip {
    padding: 6px 13px;
    background: #ffffff;
    border: 1px solid var(--tora-chat-border);
    border-radius: var(--tora-chat-radius-pill);
    font-size: 12px;
    font-weight: 600;
    color: var(--tora-chat-text-muted);
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
    flex-shrink: 0;
    outline: none;
}
.tora-prompt-chip:hover {
    border-color: var(--tora-chat-accent);
    color: var(--tora-chat-accent);
    background: #f0f9ff;
    transform: translateY(-1px);
}

/* ==========================================
    MESSAGES SCROLL AREA
   ========================================== */
.tora-chat-messages {
    flex: 1;
    padding: 18px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--tora-chat-bg-canvas);
    -webkit-overflow-scrolling: touch;
}
.tora-msg-row {
    display: flex;
    width: 100%;
}
.tora-msg-row.user {
    justify-content: flex-end;
}
.tora-msg-row.bot {
    justify-content: flex-start;
}
.tora-bubble {
    max-width: 84%;
    padding: 12px 16px;
    font-size: 13.5px;
    line-height: 1.68;
    word-break: break-word;
}
.tora-msg-row.user .tora-bubble {
    background: linear-gradient(135deg, var(--tora-chat-primary) 0%, var(--tora-chat-primary-hover) 100%);
    color: #ffffff;
    border-radius: 18px 18px 4px 18px;
    box-shadow: 0 2px 8px rgba(42, 74, 107, 0.18);
}
.tora-msg-row.bot .tora-bubble {
    background: var(--tora-chat-bg-surface);
    color: var(--tora-chat-text-main);
    border: 1px solid var(--tora-chat-border);
    border-radius: 18px 18px 18px 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.02);
}
.tora-msg-row.bot .tora-bubble p {
    margin: 0 0 8px 0;
}
.tora-msg-row.bot .tora-bubble p:last-child {
    margin-bottom: 0;
}
.tora-msg-row.bot .tora-bubble ul,
.tora-msg-row.bot .tora-bubble ol {
    margin: 6px 0 8px 18px;
    padding: 0;
}
.tora-msg-row.bot .tora-bubble li {
    margin-bottom: 4px;
}
.tora-msg-row.bot .tora-bubble strong {
    font-weight: 700;
    color: #0f172a;
}
.tora-msg-row.bot .tora-bubble code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace !important;
    background: #f1f5f9;
    color: #0f172a;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12.5px;
    font-weight: 700;
}

/* ==========================================
    ESCALATION CARD (MATCHING SUPPORT CONSOLE)
   ========================================== */
.tora-escalate-card {
    margin-top: 12px;
    padding: 14px 16px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    border: 1.5px solid #cbd5e1;
    border-radius: 14px;
    box-shadow: 0 4px 16px rgba(42, 74, 107, 0.06);
    box-sizing: border-box;
}
.tora-escalate-notice {
    font-size: 12px;
    font-weight: 700;
    color: var(--tora-chat-primary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 5px;
}
.tora-escalate-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    background: linear-gradient(135deg, var(--tora-chat-primary) 0%, var(--tora-chat-primary-hover) 100%);
    color: #ffffff !important;
    text-decoration: none !important;
    border-radius: var(--tora-chat-radius-pill);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.02em;
    box-shadow: 0 2px 8px rgba(42, 74, 107, 0.25);
    transition: all 0.2s ease;
    box-sizing: border-box;
}
.tora-escalate-btn:hover {
    background: #142536;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(42, 74, 107, 0.35);
}

/* Typing Indicator */
.tora-typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 14px;
}
.tora-typing-dot {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: toraDotPulse 1.2s infinite ease-in-out;
}
.tora-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.tora-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes toraDotPulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1.1); opacity: 1; }
}

/* ==========================================
   ✍️ INPUT FORM (IOS SAFARI SAFE)
   ========================================== */
.tora-chat-form {
    padding: 12px 16px;
    background: var(--tora-chat-bg-surface);
    border-top: 1px solid var(--tora-chat-border);
    flex-shrink: 0;
}
.tora-chat-input-wrapper {
    display: flex;
    align-items: center;
    background: #f1f5f9;
    border: 1px solid var(--tora-chat-border);
    border-radius: var(--tora-chat-radius-pill);
    padding: 3px 4px 3px 16px;
    transition: all 0.15s ease;
}
.tora-chat-input-wrapper:focus-within {
    border-color: var(--tora-chat-primary);
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(42, 74, 107, 0.12);
}
.tora-chat-input {
    flex: 1;
    border: none !important;
    background: transparent !important;
    font-size: 14px;
    color: var(--tora-chat-text-main);
    outline: none !important;
    padding: 8px 0;
    box-shadow: none !important;
    font-family: inherit;
}
.tora-chat-send-btn {
    background: var(--tora-chat-primary);
    border: none;
    color: #ffffff;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
    outline: none;
}
.tora-chat-send-btn:hover {
    background: var(--tora-chat-primary-hover);
    transform: scale(1.05);
}
.tora-chat-send-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    transform: none;
}

/* ==========================================================================
    3. MOBILE & SMARTPHONE FULL RESPONSIVENESS (< 768px)
   ========================================================================== */
@media screen and (max-width: 768px) {
    /* 1. iOS Safari Auto-Zoom Fix (Must be >= 16px) */
    .tora-chat-input {
        font-size: 16px !important;
    }

    /* 2. Floating Action Button on Mobile */
    #tora-floating-widget-root {
        bottom: calc(18px + env(safe-area-inset-bottom, 0px));
        right: 14px;
    }
    .tora-fab-btn {
        padding: 10px 18px;
        font-size: 13px;
        box-shadow: 0 6px 20px rgba(42, 74, 107, 0.25);
    }

    /* 3. Mobile Backdrop Overlay */
    .tora-floating-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
        z-index: 999998;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }
    .tora-floating-backdrop.is-active {
        opacity: 1;
        pointer-events: auto;
    }

    /* 4. Fullscreen Mode on Mobile (No empty gap at the top) */
    .tora-chat-box.tora-floating {
        position: fixed !important;
        inset: 0 !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        height: 100% !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        border: none !important;
        box-shadow: none !important;
        z-index: 999999 !important;
        transform: translateY(100%);
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1) !important;
        animation: none !important;
    }
    .tora-chat-box.tora-floating.is-open {
        transform: translateY(0) !important;
    }

    /* Top Sheet Handle Bar hidden in full screen */
    .tora-sheet-handle-bar {
        display: none !important;
    }

    /* Top Header with Safe Area */
    .tora-chat-header {
        padding-top: calc(12px + env(safe-area-inset-top, 0px)) !important;
        padding-bottom: 12px !important;
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    .tora-close-btn {
        width: 34px !important;
        height: 34px !important;
        min-width: 34px !important;
        min-height: 34px !important;
        background: #e2e8f0 !important;
        border: 1px solid #cbd5e1 !important;
        color: #0f172a !important;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08) !important;
    }

    /* Bottom Input Bar with Safe Area */
    .tora-chat-form {
        padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 12px)) 14px !important;
    }
    .tora-chat-input-wrapper {
        padding: 2px 3px 2px 14px !important;
    }
    .tora-chat-send-btn {
        width: 42px !important;
        height: 42px !important;
    }

    /* Messages spacing on mobile */
    .tora-chat-messages {
        padding: 14px 12px;
        gap: 12px;
    }
    .tora-bubble {
        max-width: 88%;
        font-size: 13px;
        padding: 10px 14px;
    }

    /* Embedded Mode on Mobile */
    .tora-embedded-chat-wrap {
        margin: 16px 0 24px 0;
        border-radius: 14px;
    }
    .tora-chat-box.tora-embedded {
        height: 480px;
        border-radius: 14px;
    }
}

/* ==========================================
   ️ CLOUDFLARE TURNSTILE INTEGRATION
   ========================================== */
.tora-chat-shield-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    font-size: 10.5px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: var(--tora-chat-radius-pill);
    letter-spacing: 0.02em;
}

.tora-chat-turnstile-wrap {
    padding: 6px 14px 4px 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--tora-chat-bg-surface);
    border-top: 1px solid var(--tora-chat-border);
    gap: 4px;
    transition: all 0.2s ease;
}

.tora-chat-turnstile {
    display: flex;
    justify-content: center;
    align-items: center;
    max-width: 100%;
    transform: scale(0.92);
    transform-origin: center center;
}

.tora-turnstile-verified-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11.5px;
    color: #16a34a;
    font-weight: 700;
    margin-top: 2px;
}

.tora-chat-turnstile-wrap.is-verified .tora-chat-turnstile {
    display: none;
}

@media (max-width: 768px) {
    .tora-chat-turnstile {
        transform: scale(0.85);
        margin: -4px 0;
    }
}
