/* KBI Chat Widget Styles - Matching Frontend Design */

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

html {
    height: 100%;
    height: 100dvh;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: #f8f9fa;
    overflow: hidden;
    min-height: 100vh;
    min-height: 100dvh;
    height: 100%;
    max-height: 100dvh;
}

#kbi-widget-root {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Chat Container */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    background: #f8f9fa;
    font-family: system-ui, -apple-system, sans-serif;
}

/* Login Container */
.login-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    background: #f8f9fa;
    font-family: system-ui, -apple-system, sans-serif;
    overflow: hidden;
}

.login-header {
    flex-shrink: 0;
    padding: 16px 14px 14px 14px;
    background: white;
    border-bottom: 1px solid #e1e5e9;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.login-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding: 24px 20px 32px 20px;
    text-align: center;
    overflow-y: auto;
    min-height: 0;
}

.login-message {
    margin-bottom: 20px;
}

.login-message h3 {
    font-size: 20px;
    color: #1a1a1a;
    margin-bottom: 8px;
    font-weight: 600;
}

.login-message p {
    font-size: 14px;
    color: #666;
    margin-bottom: 24px;
    line-height: 1.5;
}

/* Login Form Styles */
.login-form {
    width: 100%;
    max-width: 280px;
    text-align: left;
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border: 1px solid #e5e7eb;
}

.field-group {
    margin-bottom: 16px;
}

.field-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 600;
    color: #374151;
}

.field-group input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    background: #f9fafb;
    transition: all 0.2s ease;
    font-family: inherit;
}

.field-group input:focus {
    outline: none;
    border-color: #4f46e5;
    background: white;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.field-group input::placeholder {
    color: #9ca3af;
    font-style: italic;
}

.field-group input:valid {
    border-color: #10b981;
}

/* Button Loading State */
.start-chat-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.btn-loading {
    display: none;
}

.start-chat-btn {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 140px;
    width: 100%;
}

.start-chat-btn:hover {
    background: #0056b3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

.start-chat-btn:active {
    transform: translateY(0);
}

/* Header */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 16px 16px 16px;
    background: white;
    border-bottom: 1px solid #e1e5e9;
    min-height: 60px;
    flex-shrink: 0;
}

.profile-section {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.profile-image {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: #e1e5e9;
    flex-shrink: 0;
}

.profile-info {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.business-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.business-name {
    font-weight: bold;
    font-size: 14px;
    color: #1a1a1a;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #007bff;
    flex-shrink: 0;
}

.status-dot.offline {
    background-color: #9ca3af;
}

.header-agent-line {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
    font-size: 12px;
    line-height: 1.2;
}

.header-agent-name {
    color: #374151;
    font-weight: 600;
}

.header-agent-status {
    font-size: 11px;
    font-weight: 500;
}

.header-agent-status.online {
    color: #059669;
}

.header-agent-status.offline {
    color: #9ca3af;
}

.header-buttons {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.exit-chat-btn {
    font-size: 12px;
    font-weight: 600;
    color: #dc2626;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: 8px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    transition: all 0.2s ease;
    user-select: none;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.exit-chat-btn:hover {
    background: #fee2e2;
    color: #b91c1c;
    border-color: #fca5a5;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(220, 38, 38, 0.1);
}

.exit-chat-btn:active {
    transform: translateY(0);
    background: #fecaca;
    box-shadow: 0 1px 2px rgba(220, 38, 38, 0.2);
}

.close-btn {
    font-size: 20px;
    color: #6b7280;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s ease;
    user-select: none;
}

.close-btn:hover {
    background: #f3f4f6;
    color: #374151;
    transform: scale(1.1);
}

.close-btn:active {
    transform: scale(0.95);
}

/* Messages Area */
.messages-container {
    flex: 1;
    padding: 20px 16px 16px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

.timestamp {
    text-align: center;
    font-size: 12px;
    color: #666;
    margin-bottom: 8px;
}

.messages-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message.user {
    align-items: flex-end;
}

.message.agent,
.message.ai {
    align-items: flex-start;
}

.message-content {
    max-width: 75%;
    padding: 14px 18px;
    border-radius: 20px;
    font-size: 15px;
    line-height: 1.4;
}

.message.user .message-content {
    background-color: #007bff;
    color: white;
}

.message.agent .message-content,
.message.ai .message-content {
    background-color: #2D2D2F;
    color: white;
}

.message-time {
    font-size: 11px;
    color: #666;
    margin: 0 8px;
}

.handoff-connecting-label {
    font-size: 12px;
    color: #6b7280;
    margin-bottom: 6px;
}

.message.agent.handoff-connecting .message-content {
    background: var(--widget-secondary, #f3f4f6);
    padding: 10px 14px;
    border-radius: 18px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--widget-secondary, #f3f4f6);
    border-radius: 18px;
    max-width: 85%;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

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

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

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

/* Feedback Card */
.feedback-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    margin: 16px 0;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.feedback-question {
    font-weight: bold;
    margin-bottom: 12px;
    color: #1a1a1a;
}

.feedback-buttons {
    display: flex;
    justify-content: center;
    gap: 16px;
}

.feedback-button {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: #f1f3f4;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.thumb-icon {
    width: 30px;
    height: 30px;
}

/* Feedback buttons below messages (left side) */
.message-feedback {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    margin-left: 0;
    padding: 4px 0;
}

.feedback-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: #f1f3f4;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
}

.feedback-btn:hover:not(:disabled) {
    background: #e8eaed;
    transform: scale(1.1);
}

.feedback-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.feedback-btn .thumb-icon {
    width: 20px;
    height: 20px;
}

/* Feedback Modal */
.feedback-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
}

.feedback-modal {
    background: white;
    border-radius: 8px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
}

.feedback-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 24px 16px 24px;
    border-bottom: 1px solid #e5e7eb;
}

.feedback-modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: #1a1a1a;
    font-family: serif;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #6b7280;
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.modal-close:hover {
    background: #f3f4f6;
}

.feedback-modal-body {
    padding: 24px;
    flex: 1;
    overflow-y: auto;
}

.feedback-section {
    margin-bottom: 24px;
}

.feedback-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 12px;
}

.feedback-label .required {
    color: #dc2626;
}

.feedback-categories {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.feedback-checkbox {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 8px 0;
    user-select: none;
}

.feedback-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-right: 12px;
    cursor: pointer;
    accent-color: #007bff;
}

.feedback-checkbox span {
    font-size: 14px;
    color: #374151;
}

.feedback-modal-body textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    margin-top: 8px;
    min-height: 80px;
    box-sizing: border-box;
}

.feedback-modal-body textarea:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.feedback-modal-body textarea::placeholder {
    color: #9ca3af;
}

.feedback-privacy {
    font-size: 12px;
    color: #6b7280;
    line-height: 1.5;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;
}

.privacy-link {
    color: #007bff;
    text-decoration: none;
}

.privacy-link:hover {
    text-decoration: underline;
}

.feedback-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
}

.btn-cancel, .btn-submit {
    padding: 10px 24px;
    border-radius: 4px;
    border: 1px solid #d1d5db;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    transition: all 0.2s;
}

.btn-cancel {
    background: white;
    color: #374151;
}

.btn-cancel:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.btn-submit {
    background: #007bff;
    color: white;
    border-color: #007bff;
}

.btn-submit:hover:not(:disabled) {
    background: #0056b3;
    border-color: #0056b3;
}

.btn-submit:disabled {
    background: #e5e7eb;
    color: #9ca3af;
    border-color: #d1d5db;
    cursor: not-allowed;
}

/* Toast notification */
.feedback-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #10b981;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10001;
    font-size: 14px;
    animation: slideIn 0.3s ease;
}

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

/* Input Area */
.input-container {
    display: flex;
    align-items: center;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
    background: white;
    border-top: 1px solid #e1e5e9;
    gap: 6px;
    flex-shrink: 0;
    min-height: 0;
    border-radius: 0 0 12px 12px;
    max-width: 100%;
}

.attachment-buttons {
    display: flex;
    gap: 8px;
}

.attachment-button-circle {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.attachment-button-circle:hover {
    background: rgba(0, 0, 0, 0.04);
}

.attachment-button-square {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.attachment-button-square:hover {
    background: rgba(0, 0, 0, 0.04);
}

.attachment-icon {
    width: 30px;
    height: 30px;
}

.input-form {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 6px;
    min-width: 0;
}

.message-input {
    flex: 1;
    min-width: 0;
    width: 100%;
    padding: 10px 14px !important;
    border: none !important;
    border-radius: 25px !important;
    background: #f1f3f4 !important;
    font-size: 14px !important;
    outline: none !important;
    transition: all 0.2s ease;
    font-family: inherit;
    color: #1a1a1a;
    min-height: 20px;
    resize: none;
    line-height: 1.4;
    box-sizing: border-box;
    height: 40px;
}

.message-input:focus {
    outline: none !important;
    background: #e8eaed !important;
    box-shadow: none !important;
}

.message-input::placeholder {
    color: #9ca3af;
    font-style: normal;
    font-weight: 500;
}

.send-button {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.send-button:hover {
    background: rgba(0, 0, 0, 0.04);
}

.send-button:active {
    opacity: 0.85;
}

.send-icon {
    width: 30px;
    height: 30px;
}   

.send-icon svg {
    width: 30px;
    height: 30px;
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 20px;
    color: var(--widget-text, #111827);
}

.welcome-message h4 {
    font-size: 16px;
    margin-bottom: 8px;
    color: var(--widget-primary, #4f46e5);
}

.welcome-message p {
    font-size: 14px;
    color: #6b7280;
    line-height: 1.5;
}

/* Connection Status */
.connection-status {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
}

.connection-status.disconnected {
    background: #ef4444;
}

.connection-status.connecting {
    background: #f59e0b;
    animation: pulse 2s infinite;
}

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

/* Loading States */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: #6b7280;
    font-size: 14px;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e5e7eb;
    border-top: 2px solid var(--widget-primary, #4f46e5);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 8px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error States */
.error-message {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 12px 16px;
    border-radius: 8px;
    margin: 12px 20px;
    font-size: 14px;
}

/* Responsive Design */
@media (max-width: 480px) {
    .chat-header {
        padding: 12px 16px;
    }
    
    .messages-container {
        padding: 12px 10px;
    }
    
    .input-container {
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
        gap: 4px;
    }

    .attachment-button-circle,
    .attachment-button-square {
        width: 38px;
        height: 38px;
    }

    .send-button {
        width: 38px;
        height: 38px;
    }

    .attachment-icon {
        width: 26px;
        height: 26px;
    }

    .send-icon {
        width: 26px;
        height: 26px;
    }
    
    .message {
        max-width: 90%;
    }
}

/* Scrollbar Styling */
.messages-container::-webkit-scrollbar {
    width: 4px;
}

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

.messages-container::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 2px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}
