/* Smart Travel Concierge Chat Widget Styles */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.chat-toggle {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #0d6efd;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: transform 0.2s, background 0.2s, box-shadow 0.3s;
}

.chat-toggle:hover {
    transform: scale(1.05);
    background: #0b5ed7;
}

/* Subtle pulse animation when contextual help is available */
.chat-toggle.has-context {
    animation: contextPulse 2s ease-in-out infinite;
}

.chat-toggle.has-context::after {
    content: '';
    position: absolute;
    top: -3px;
    right: -3px;
    width: 14px;
    height: 14px;
    background: #10b981;
    border-radius: 50%;
    border: 2px solid white;
}

@keyframes contextPulse {
    0%, 100% {
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
    50% {
        box-shadow: 0 4px 20px rgba(13, 110, 253, 0.4);
    }
}

.chat-window {
    display: none;
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 380px;
    height: 550px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 5px 40px rgba(0,0,0,0.16);
    flex-direction: column;
    overflow: hidden;
}

.chat-window.open {
    display: flex;
}

.chat-header {
    background: linear-gradient(135deg, #0d6efd 0%, #0a58ca 100%);
    color: white;
    padding: 14px 16px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-itinerary-toggle {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: background 0.2s;
}

.chat-itinerary-toggle:hover {
    background: rgba(255,255,255,0.3);
}

.itinerary-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #f97316;
    color: white;
    font-size: 10px;
    font-weight: 700;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
}

.chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    opacity: 0.8;
    line-height: 1;
}

.chat-close:hover {
    opacity: 1;
}

/* Chat Body - holds both panels */
.chat-body {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.chat-panel.hidden {
    transform: translateX(-100%);
    opacity: 0;
    position: absolute;
    pointer-events: none;
}

.itinerary-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: white;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    pointer-events: none;
}

.itinerary-panel.visible {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.5;
    font-size: 14px;
}

.chat-message.user {
    align-self: flex-end;
    background: #0d6efd;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant {
    align-self: flex-start;
    background: #f1f3f5;
    color: #333;
    border-bottom-left-radius: 4px;
}

/* Item Cards in Chat */
.chat-item-card {
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    overflow: hidden;
    max-width: 95%;
    align-self: flex-start;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.item-card-image {
    height: 100px;
    background-size: cover;
    background-position: center;
    background-color: #e9ecef;
}

.item-card-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
}

.item-card-placeholder i {
    font-size: 32px;
    color: rgba(255, 255, 255, 0.9);
}

.item-card-content {
    padding: 12px;
}

.item-card-content h5 {
    margin: 0 0 4px 0;
    font-size: 14px;
    font-weight: 600;
    color: #222;
}

.item-card-meta {
    margin: 0;
    font-size: 12px;
    color: #717171;
    display: flex;
    gap: 8px;
    align-items: center;
}

.item-card-meta .rating {
    color: #f59e0b;
    font-weight: 500;
}

.item-card-price {
    margin: 8px 0 0 0;
    font-size: 14px;
    font-weight: 600;
    color: #0d6efd;
}

.item-card-price small {
    font-weight: 400;
    color: #717171;
}

.item-card-actions {
    padding: 10px 12px;
    border-top: 1px solid #f1f3f5;
    display: flex;
    gap: 8px;
    align-items: center;
}

.day-select {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 12px;
    background: white;
}

.btn-add-item {
    padding: 6px 12px;
    background: #0d6efd;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background 0.2s;
}

.btn-add-item:hover {
    background: #0b5ed7;
}

.btn-add-item.added {
    background: #10b981;
}

.btn-add-item:disabled {
    cursor: default;
}

/* Chat Input */
.chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
    background: white;
}

.chat-live-agent {
    padding: 8px 16px 12px;
    background: white;
    text-align: center;
}

.live-agent-btn {
    width: 100%;
    padding: 10px 16px;
    background: linear-gradient(135deg, #003580 0%, #00224f 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.live-agent-btn:hover {
    background: linear-gradient(135deg, #00224f 0%, #001a3d 100%);
    transform: translateY(-1px);
}

.live-agent-btn i {
    font-size: 16px;
}

/* Agent options panel */
.agent-options {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.agent-options-label {
    font-size: 12px;
    font-weight: 600;
    color: #6c757d;
    text-align: center;
    margin-bottom: 2px;
}
.agent-option-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #e9ecef;
    border-radius: 10px;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}
.agent-option-btn i {
    font-size: 18px;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}
.agent-option-btn div {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}
.agent-option-btn strong {
    font-size: 13px;
    color: #1a1a1a;
}
.agent-option-btn span {
    font-size: 11px;
    color: #6c757d;
}
.agent-option-live {
    border-color: #10b981;
}
.agent-option-live i {
    color: #10b981;
}
.agent-option-live:hover {
    background: #ecfdf5;
    border-color: #059669;
}
.agent-option-email {
    border-color: #3b82f6;
}
.agent-option-email i {
    color: #3b82f6;
}
.agent-option-email:hover {
    background: #eff6ff;
    border-color: #2563eb;
}
.agent-option-cancel {
    background: none;
    border: none;
    color: #6c757d;
    font-size: 12px;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}
.agent-option-cancel:hover {
    color: #1a1a1a;
}

/* Waiting for agent */
.agent-waiting {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px;
    font-size: 13px;
    color: #10b981;
    font-weight: 500;
}
.agent-waiting-pulse {
    width: 10px;
    height: 10px;
    background: #10b981;
    border-radius: 50%;
    animation: agentPulse 1.5s ease-in-out infinite;
}
@keyframes agentPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.8); }
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 24px;
    outline: none;
    font-size: 14px;
}

.chat-input:focus {
    border-color: #0d6efd;
}

.chat-send {
    width: 40px;
    height: 40px;
    background: #0d6efd;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chat-send:hover {
    background: #0b5ed7;
}

/* Itinerary Panel */
.itinerary-header {
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.itinerary-header h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #222;
}

.itinerary-back {
    background: none;
    border: none;
    color: #0d6efd;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

.itinerary-back:hover {
    text-decoration: underline;
}

.itinerary-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.itinerary-empty {
    text-align: center;
    padding: 40px 20px;
    color: #717171;
}

.itinerary-empty i {
    font-size: 48px;
    opacity: 0.3;
}

.itinerary-empty p {
    margin: 16px 0 4px 0;
    font-size: 14px;
}

.itinerary-empty small {
    font-size: 12px;
    opacity: 0.7;
}

.itinerary-day {
    margin-bottom: 16px;
}

.itinerary-day-header {
    margin-bottom: 8px;
}

.itinerary-day-header h5 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: #0d6efd;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.itinerary-day-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.itinerary-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.itinerary-item-image {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    background-size: cover;
    background-position: center;
    background-color: #ddd;
    flex-shrink: 0;
}

.itinerary-item-info {
    flex: 1;
    min-width: 0;
}

.itinerary-item-name {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #222;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.itinerary-item-price {
    display: block;
    font-size: 12px;
    color: #717171;
}

.itinerary-item-remove {
    width: 24px;
    height: 24px;
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    opacity: 0.6;
    transition: opacity 0.2s, background 0.2s;
}

.itinerary-item-remove:hover {
    opacity: 1;
    background: rgba(220, 53, 69, 0.1);
}

/* Itinerary Footer */
.itinerary-footer {
    padding: 12px 16px;
    border-top: 1px solid #eee;
    background: #f8f9fa;
}

.itinerary-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.itinerary-total span {
    font-size: 13px;
    color: #717171;
}

.itinerary-total strong {
    font-size: 18px;
    color: #222;
}

.itinerary-actions {
    display: flex;
    gap: 8px;
}

.btn-save-trip,
.btn-get-quote {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.2s, opacity 0.2s;
}

.btn-save-trip {
    background: #e7f1ff;
    color: #0d6efd;
}

.btn-save-trip:hover:not(:disabled) {
    background: #d0e3ff;
}

.btn-get-quote {
    background: #0d6efd;
    color: white;
}

.btn-get-quote:hover:not(:disabled) {
    background: #0b5ed7;
}

.btn-save-trip:disabled,
.btn-get-quote:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: #f1f3f5;
    border-radius: 18px;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typing 1s infinite;
}

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

@keyframes typing {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

/* Agent message styling */
.chat-message.agent {
    align-self: flex-start;
    background: #e8f4fd;
    color: #333;
    border: 1px solid #bee5eb;
    border-bottom-left-radius: 4px;
}

.agent-name {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #0d6efd;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Live indicator */
.live-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    margin-right: 6px;
    animation: livePulse 2s infinite;
}

@keyframes livePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Connection status dot */
.connection-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-left: 6px;
    background: #fbbf24;
}

.connection-dot.connected {
    background: #10b981;
}

/* Typing indicator label */
.typing-label {
    font-size: 11px;
    color: #666;
    margin-right: 8px;
    font-style: italic;
}

/* Load more messages button */
.load-more-messages {
    text-align: center;
    padding: 8px;
    margin-bottom: 8px;
}

.load-more-messages button {
    background: none;
    border: 1px solid #ddd;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
}

.load-more-messages button:hover {
    background: #f5f5f5;
    border-color: #ccc;
    color: #333;
}

.loading-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid #ddd;
    border-top-color: #666;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 6px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Toast notification */
.chat-toast {
    position: fixed;
    bottom: 100px;
    right: 30px;
    background: #222;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s, transform 0.3s;
    z-index: 10000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.chat-toast.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Mobile Responsive - Tablet */
@media (max-width: 768px) {
    .chat-window {
        width: 340px;
        height: 500px;
    }

    .chat-item-card {
        max-width: 100%;
    }
}

/* Mobile Responsive - Phone */
@media (max-width: 480px) {
    .chat-widget {
        bottom: 0;
        right: 0;
        left: 0;
    }

    .chat-toggle {
        position: fixed;
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
        font-size: 22px;
    }

    .chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        box-shadow: none;
    }

    .chat-window.open {
        animation: slideUp 0.25s ease-out;
    }

    @keyframes slideUp {
        from {
            transform: translateY(100%);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    .chat-header {
        padding: 16px;
        padding-top: max(16px, env(safe-area-inset-top));
    }

    .chat-close {
        font-size: 28px;
        padding: 4px 8px;
    }

    .chat-itinerary-toggle {
        width: 40px;
        height: 40px;
    }

    .chat-messages {
        padding: 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .chat-message {
        max-width: 90%;
        font-size: 15px;
        padding: 10px 14px;
    }

    .chat-input-area {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        gap: 10px;
    }

    .chat-input {
        padding: 12px 16px;
        font-size: 16px; /* Prevents iOS zoom on focus */
        border-radius: 20px;
    }

    .chat-send {
        width: 44px;
        height: 44px;
        flex-shrink: 0;
    }

    /* Item cards on mobile */
    .chat-item-card {
        max-width: 100%;
        margin-right: 0;
    }

    .item-card-image {
        height: 120px;
    }

    .item-card-content {
        padding: 14px;
    }

    .item-card-content h5 {
        font-size: 15px;
    }

    .item-card-actions {
        padding: 12px 14px;
        flex-wrap: wrap;
    }

    .day-select {
        padding: 10px 12px;
        font-size: 14px;
        flex: 1;
        min-width: 100px;
    }

    .btn-add-item {
        padding: 10px 16px;
        font-size: 14px;
        flex: 1;
        justify-content: center;
    }

    /* Itinerary panel on mobile */
    .itinerary-header {
        padding: 14px 16px;
        padding-top: max(14px, env(safe-area-inset-top));
    }

    .itinerary-header h4 {
        font-size: 17px;
    }

    .itinerary-back {
        font-size: 14px;
        padding: 8px;
    }

    .itinerary-content {
        padding: 12px;
    }

    .itinerary-item {
        padding: 10px;
    }

    .itinerary-item-image {
        width: 48px;
        height: 48px;
    }

    .itinerary-item-name {
        font-size: 14px;
    }

    .itinerary-item-remove {
        width: 32px;
        height: 32px;
    }

    .itinerary-footer {
        padding: 14px 16px;
        padding-bottom: max(14px, env(safe-area-inset-bottom));
    }

    .itinerary-total strong {
        font-size: 20px;
    }

    .btn-save-trip,
    .btn-get-quote {
        padding: 12px;
        font-size: 14px;
    }

    /* Toast on mobile */
    .chat-toast {
        left: 16px;
        right: 16px;
        bottom: auto;
        top: max(80px, calc(env(safe-area-inset-top) + 60px));
        text-align: center;
    }
}

/* Landscape phone adjustments */
@media (max-width: 480px) and (orientation: landscape) {
    .chat-window {
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height */
    }

    .chat-messages {
        max-height: calc(100dvh - 140px);
    }
}

/* Touch-friendly enhancements */
@media (hover: none) and (pointer: coarse) {
    .chat-toggle:active {
        transform: scale(0.95);
    }

    .btn-add-item:active,
    .btn-save-trip:active,
    .btn-get-quote:active {
        opacity: 0.8;
    }

    .itinerary-item-remove:active {
        background: rgba(220, 53, 69, 0.2);
    }

    /* Larger touch targets */
    .itinerary-item-remove {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .chat-window {
        background: #1a1a1a;
    }

    .chat-message.assistant {
        background: #2d2d2d;
        color: #e5e5e5;
    }

    .chat-item-card {
        background: #2d2d2d;
        border-color: #404040;
    }

    .item-card-content h5 {
        color: #e5e5e5;
    }

    .item-card-meta {
        color: #a0a0a0;
    }

    .chat-input-area {
        background: #1a1a1a;
        border-color: #404040;
    }

    .chat-input {
        background: #2d2d2d;
        border-color: #404040;
        color: #e5e5e5;
    }

    .itinerary-panel {
        background: #1a1a1a;
    }

    .itinerary-header {
        border-color: #404040;
    }

    .itinerary-header h4 {
        color: #e5e5e5;
    }

    .itinerary-item {
        background: #2d2d2d;
        border-color: #404040;
    }

    .itinerary-item-name {
        color: #e5e5e5;
    }

    .itinerary-footer {
        background: #2d2d2d;
        border-color: #404040;
    }

    .itinerary-total strong {
        color: #e5e5e5;
    }

    .day-select {
        background: #2d2d2d;
        border-color: #404040;
        color: #e5e5e5;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .chat-toggle,
    .chat-window,
    .chat-panel,
    .itinerary-panel,
    .typing-indicator span,
    .chat-toast {
        animation: none;
        transition: none;
    }
}
