/* ==========================================================================
   Kobe AI Phone Chat — Immersive Phone-App UI with Bubble Animations
   ========================================================================== */

/* ─── Phone Container ─────────────────────────────────────────────────── */

.phone-chat-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s ease, visibility 0.35s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.phone-chat-overlay.active {
    opacity: 1;
    visibility: visible;
}

.phone-chat-container {
    position: fixed;
    bottom: -120%;
    right: 24px;
    width: 380px;
    height: 640px;
    max-height: calc(100vh - 48px);
    z-index: 9999;
    transition: bottom 0.5s cubic-bezier(0.32, 0.72, 0, 1);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

.phone-chat-container.active {
    bottom: 24px;
}

/* Phone Frame */
.phone-frame {
    position: relative;
    width: 100%;
    height: 100%;
    background: #f2f2f7;
    border-radius: 32px;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.08),
        0 20px 60px rgba(0, 0, 0, 0.25),
        0 8px 24px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ─── Status Bar ──────────────────────────────────────────────────────── */

.phone-status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 24px 6px;
    background: #1a1a2e;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

.phone-status-bar .time {
    font-weight: 700;
}

.phone-status-bar .icons {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
}

.phone-notch {
    width: 120px;
    height: 24px;
    background: #000;
    border-radius: 0 0 16px 16px;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
}

/* ─── Chat Header ─────────────────────────────────────────────────────── */

.phone-chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: linear-gradient(135deg, #a70000 0%, #c90000 100%);
    color: #fff;
    flex-shrink: 0;
}

.phone-chat-header .back-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    padding: 2px 4px;
    opacity: 0.9;
    transition: opacity 0.2s;
}

.phone-chat-header .back-btn:hover {
    opacity: 1;
}

.phone-chat-header .avatar {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.phone-chat-header .header-info {
    flex: 1;
    min-width: 0;
}

.phone-chat-header .header-info .name {
    font-weight: 700;
    font-size: 15px;
    line-height: 1.2;
}

.phone-chat-header .header-info .status {
    font-size: 11px;
    opacity: 0.85;
}

.phone-chat-header .header-actions {
    display: flex;
    gap: 6px;
}

.phone-chat-header .header-actions button {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    opacity: 0.85;
    padding: 4px;
    transition: opacity 0.2s;
}

.phone-chat-header .header-actions button:hover {
    opacity: 1;
}

/* ─── Messages Area ───────────────────────────────────────────────────── */

.phone-messages-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 14px;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(167, 0, 0, 0.03) 0%, transparent 60%),
        #f5f5f0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
}

.phone-messages-area::-webkit-scrollbar {
    width: 4px;
}

.phone-messages-area::-webkit-scrollbar-track {
    background: transparent;
}

.phone-messages-area::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}

/* ─── Message Bubbles ─────────────────────────────────────────────────── */

.phone-bubble {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 18px;
    line-height: 1.45;
    font-size: 14px;
    word-wrap: break-word;
    position: relative;
    animation: bubbleIn 0.35s cubic-bezier(0.32, 0.72, 0, 1) forwards;
    transform-origin: bottom;
    opacity: 0;
}

@keyframes bubbleIn {
    0% {
        opacity: 0;
        transform: scale(0.7) translateY(12px);
    }
    60% {
        transform: scale(1.03) translateY(-2px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* User bubble (right-aligned, red) */
.phone-bubble.user {
    background: linear-gradient(135deg, #a70000 0%, #c90000 100%);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(167, 0, 0, 0.2);
}

.phone-bubble.user::after {
    content: '';
    position: absolute;
    right: -6px;
    bottom: 0;
    border: 8px solid transparent;
    border-left-color: #c90000;
    border-bottom-color: #c90000;
}

/* Bot bubble (left-aligned, white) */
.phone-bubble.bot {
    background: #fff;
    color: #1a1a1a;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.phone-bubble.bot::after {
    content: '';
    position: absolute;
    left: -6px;
    bottom: 0;
    border: 8px solid transparent;
    border-right-color: #fff;
    border-bottom-color: #fff;
}

/* Bot bubble links */
.phone-bubble.bot a {
    color: #a70000;
    text-decoration: none;
    font-weight: 500;
}

.phone-bubble.bot a:hover {
    text-decoration: underline;
}

/* ─── Typing Indicator (WhatsApp-style) ───────────────────────────────── */

.phone-bubble.typing {
    align-self: flex-start;
    background: #fff;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    padding: 14px 18px;
    animation: none;
    opacity: 1;
}

.typing-dots {
    display: flex;
    align-items: center;
    gap: 5px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: #a70000;
    border-radius: 50%;
    display: inline-block;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) {
    animation-delay: 0s;
}

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

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

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* ─── Quick Reply Chips ───────────────────────────────────────────────── */

.quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 14px 2px;
    animation: bubbleIn 0.3s ease-out forwards;
    opacity: 0;
}

.quick-reply-chip {
    background: #fff;
    border: 1px solid rgba(167, 0, 0, 0.25);
    border-radius: 18px;
    padding: 6px 14px;
    font-size: 13px;
    color: #a70000;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-weight: 500;
}

.quick-reply-chip:hover {
    background: #a70000;
    color: #fff;
    border-color: #a70000;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(167, 0, 0, 0.2);
}

.quick-reply-chip:active {
    transform: scale(0.95);
}

/* ─── Input Area (iMessage-style) ─────────────────────────────────────── */

.phone-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 12px 10px;
    background: #fff;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
}

.phone-input-wrapper {
    flex: 1;
    display: flex;
    align-items: flex-end;
    background: #f2f2f7;
    border-radius: 20px;
    padding: 4px 4px 4px 16px;
    border: 1px solid transparent;
    transition: border-color 0.2s;
}

.phone-input-wrapper:focus-within {
    border-color: #a70000;
    background: #fff;
}

.phone-input-wrapper input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px 0;
    font-size: 15px;
    outline: none;
    color: #1a1a1a;
    min-height: 20px;
    max-height: 80px;
    font-family: inherit;
}

.phone-input-wrapper input::placeholder {
    color: #8e8e93;
}

.phone-send-btn {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #a70000 0%, #c90000 100%);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    opacity: 0.4;
    pointer-events: none;
}

.phone-send-btn.active {
    opacity: 1;
    pointer-events: auto;
}

.phone-send-btn.active:hover {
    transform: scale(1.08);
    box-shadow: 0 2px 8px rgba(167, 0, 0, 0.3);
}

.phone-send-btn.active:active {
    transform: scale(0.92);
}

/* ─── Home Indicator ──────────────────────────────────────────────────── */

.phone-home-indicator {
    width: 134px;
    height: 5px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
    margin: 6px auto 8px;
    flex-shrink: 0;
}

/* ─── Floating Trigger Button ─────────────────────────────────────────── */

.phone-chat-trigger {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #a70000 0%, #c90000 100%);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    z-index: 9997;
    box-shadow: 0 4px 20px rgba(167, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    transition: all 0.3s ease;
    animation: triggerPulse 2s infinite;
}

.phone-chat-trigger:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px rgba(167, 0, 0, 0.45);
}

.phone-chat-trigger:active {
    transform: scale(0.95);
}

.phone-chat-trigger.minimized {
    width: 48px;
    height: 48px;
    font-size: 20px;
    animation: none;
}

.phone-chat-trigger .badge-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    background: #ff3b30;
    border-radius: 50%;
    border: 2px solid #fff;
    display: none;
}

.phone-chat-trigger .badge-dot.active {
    display: block;
    animation: badgePulse 1s infinite;
}

@keyframes triggerPulse {
    0%, 100% {
        box-shadow: 0 4px 20px rgba(167, 0, 0, 0.35);
    }
    50% {
        box-shadow: 0 4px 30px rgba(167, 0, 0, 0.55);
    }
}

@keyframes badgePulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
}

/* ─── Welcome / Bot Avatar ────────────────────────────────────────────── */

.phone-bubble.bot .bot-avatar-inline {
    display: inline-block;
    margin-right: 6px;
    font-size: 16px;
}

/* ─── Date Separator ──────────────────────────────────────────────────── */

.date-separator {
    text-align: center;
    font-size: 12px;
    color: #8e8e93;
    padding: 8px 0 4px;
    font-weight: 500;
}

/* ─── Responsive ───────────────────────────────────────────────────────── */

@media (max-width: 420px) {
    .phone-chat-container {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        right: 0;
        bottom: -100%;
    }

    .phone-chat-container.active {
        bottom: 0;
    }

    .phone-frame {
        border-radius: 0;
        box-shadow: none;
    }

    .phone-status-bar {
        padding: 6px 20px 4px;
    }

    .phone-chat-trigger {
        bottom: 16px;
        right: 16px;
        width: 54px;
        height: 54px;
    }
}

@media (min-width: 421px) and (max-width: 768px) {
    .phone-chat-container {
        width: 360px;
        height: 580px;
        right: 16px;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .phone-chat-container {
        right: 16px;
    }
}

/* ─── Scroll Animation Helper ─────────────────────────────────────────── */

.phone-messages-area .scroll-anchor {
    height: 1px;
    flex-shrink: 0;
}