* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    width: 100%;
    max-width: 800px;
    height: 90vh;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-title {
    text-align: left;
}

.chat-header h1 {
    font-size: 24px;
    margin-bottom: 5px;
}

.chat-header p {
    font-size: 14px;
    opacity: 0.9;
}

.auth-section {
    display: flex;
    align-items: center;
}

.auth-loading {
    color: white;
    font-size: 14px;
}

.auth-button {
    padding: 8px 16px;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.login-button {
    background: white;
    color: #667eea;
}

.login-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.3);
}

.logout-button {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid white;
}

.logout-button:hover {
    background: rgba(255, 255, 255, 0.3);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid white;
}

.user-email {
    color: white;
    font-size: 14px;
    font-weight: 500;
}

.login-prompt {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    padding: 40px;
    text-align: center;
}

.login-prompt-content h2 {
    color: #333;
    margin-bottom: 16px;
}

.login-prompt-content p {
    color: #666;
    margin-bottom: 24px;
    font-size: 16px;
}

.merchant-auth-prompt {
    background: #fff3cd;
    border: 2px solid #ffc107;
    border-radius: 8px;
    padding: 16px;
    margin: 16px 20px;
    text-align: center;
}

.merchant-auth-content p {
    color: #856404;
    margin-bottom: 12px;
    font-size: 14px;
}

.merchant-auth-content .auth-button {
    background: #ffc107;
    color: #333;
}

.merchant-auth-content .auth-button:hover {
    background: #ffb300;
}

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

.message {
    white-space: pre-line;  /* keep the line breaks in server-written replies */
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    align-self: flex-end;
    background: #667eea;
    color: white;
}

.assistant-message {
    align-self: flex-start;
    background: #f1f3f4;
    color: #333;
}

.product-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 16px;
    margin: 8px 0;
    align-self: flex-start;
    max-width: 80%;
}

.product-card h4 {
    margin-bottom: 8px;
    color: #333;
}

.product-card p {
    color: #666;
    font-size: 14px;
    margin-bottom: 8px;
}

.product-card .price {
    font-size: 18px;
    font-weight: bold;
    color: #667eea;
}

.cart-summary {
    background: #f9f9f9;
    border-top: 2px solid #e0e0e0;
    padding: 16px 20px;
    max-height: 150px;
    overflow-y: auto;
}

.cart-summary h3 {
    font-size: 16px;
    margin-bottom: 12px;
    color: #333;
}

.cart-item {
    font-size: 14px;
    color: #666;
    padding: 4px 0;
}

.cart-total {
    font-size: 16px;
    font-weight: bold;
    color: #333;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #e0e0e0;
}

.order-confirmation {
    background: #e8f5e9;
    border: 2px solid #4caf50;
    border-radius: 8px;
    padding: 16px;
    margin: 8px 0;
    align-self: flex-start;
    max-width: 80%;
}

.order-confirmation h4 {
    color: #2e7d32;
    margin-bottom: 8px;
}

.order-confirmation p {
    color: #333;
    font-size: 14px;
    margin: 4px 0;
}

.order-confirmation a {
    color: #667eea;
    text-decoration: none;
}

.order-confirmation a:hover {
    text-decoration: underline;
}

.input-container {
    display: flex;
    gap: 12px;
    padding: 20px;
    background: #f9f9f9;
    border-top: 1px solid #e0e0e0;
}

#messageInput {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 24px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

#messageInput:focus {
    border-color: #667eea;
}

#sendButton {
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

#sendButton:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

#sendButton:active {
    transform: translateY(0);
}

#sendButton:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.loading {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #667eea;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 0.4;
    }
    50% {
        opacity: 1;
    }
}

/* Merchant Authorization Link */
.merchant-auth-link {
    display: inline-block;
    margin-left: 8px;
    padding: 8px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 600;
    transition: transform 0.2s, box-shadow 0.2s;
}

.merchant-auth-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.merchant-auth-link:active {
    transform: translateY(0);
}

/* Connect-to-merchant invitation shown under the first product list */
.merchant-connect-invite p {
    margin: 0 0 10px 0;
}

.merchant-connect-button {
    margin-left: 0;
}

/* Approval for the merchant's order lookup; the assistant's explanation sits above it */
.pact-approval {
    padding: 4px 0;
}

.pact-approval-button {
    margin-left: 0;
    cursor: pointer;
}

.pact-approval-button:not([href]) {
    cursor: default;
    opacity: 0.7;
}

/* After connecting, the invitation stays in the chat history but loses its button */
.merchant-connect-done {
    opacity: 0.7;
}
