:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #232636;
    --bg-user-msg: #3b5bdb;
    --bg-bot-msg: #232636;
    --text-primary: #e8eaed;
    --text-secondary: #9aa0a6;
    --text-muted: #6b7280;
    --accent: #5b8def;
    --accent-hover: #4a7ce0;
    --success: #34d399;
    --border: #2d3142;
    --shadow: rgba(0, 0, 0, 0.3);
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    padding-bottom: 29px;
    overflow: hidden;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 29px);
    max-width: 800px;
    margin: 0 auto;
}

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.header-logo {
    font-size: 28px;
    color: var(--accent);
    display: flex;
    align-items: center;
}

.header-logo svg {
    width: 28px;
    height: 28px;
}

.header-info h1 {
    font-size: 16px;
    font-weight: 600;
}

.header-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
}

.connection-status {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 0.3s;
}

.connection-status.connected .status-dot {
    background: var(--success);
}

.connection-status.connected .status-text {
    color: var(--success);
}

.connection-status.error .status-dot {
    background: #ef4444;
}

/* Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

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

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

.message.bot {
    align-self: flex-start;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.5;
    font-size: 14px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message.user .message-bubble {
    background: var(--bg-user-msg);
    border-bottom-right-radius: 4px;
}

.message.bot .message-bubble {
    background: var(--bg-bot-msg);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    padding: 0 4px;
}

.message.user .message-time {
    text-align: right;
}

/* Product cards */
.products-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
    white-space: normal;
}

.product-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    cursor: pointer;
    transition: border-color 0.3s, transform 0.2s, box-shadow 0.3s;
    animation: cardSlideIn 0.4s ease both;
    white-space: normal;
}

.product-card:nth-child(1) { animation-delay: 0s; }
.product-card:nth-child(2) { animation-delay: 0.1s; }
.product-card:nth-child(3) { animation-delay: 0.2s; }
.product-card:nth-child(4) { animation-delay: 0.3s; }
.product-card:nth-child(5) { animation-delay: 0.4s; }

.product-card:hover {
    border-color: var(--accent);
    transform: translateX(4px);
    box-shadow: -4px 0 0 var(--accent);
}

.product-card:active {
    transform: scale(0.98);
}

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

.product-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 4px;
}

.product-card-name {
    font-weight: 600;
    font-size: 14px;
}

.product-card-provider {
    font-size: 12px;
    color: var(--text-secondary);
}

.product-card-score {
    font-size: 11px;
    color: var(--accent);
    white-space: nowrap;
}

.product-card-summary {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.3;
    margin-bottom: 6px;
}

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

.btn {
    padding: 5px 12px;
    border-radius: 6px;
    border: none;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn svg {
    width: 14px;
    height: 14px;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

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

.btn-secondary {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
}

.btn-secondary:hover {
    background: rgba(91, 141, 239, 0.1);
}

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

/* Order form */
.order-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 12px;
    padding: 14px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    animation: cardSlideIn 0.4s ease;
}

.order-form input {
    padding: 10px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.order-form input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(91, 141, 239, 0.15);
}

.order-form input::placeholder {
    color: var(--text-muted);
}

/* Confirmation */
.confirmation-card {
    padding: 16px;
    background: rgba(52, 211, 153, 0.1);
    border: 1px solid var(--success);
    border-radius: var(--radius-sm);
    margin-top: 12px;
    animation: confirmPop 0.5s ease;
}

@keyframes confirmPop {
    0% { opacity: 0; transform: scale(0.9); }
    60% { transform: scale(1.02); }
    100% { opacity: 1; transform: scale(1); }
}

.confirmation-card h3 {
    color: var(--success);
    font-size: 15px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.confirmation-card h3 svg {
    width: 18px;
    height: 18px;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--bg-bot-msg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    align-self: flex-start;
    width: fit-content;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

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

/* Input area */
.chat-input-area {
    padding: 16px 20px 26px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
}

.input-wrapper textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.5;
}

.input-wrapper textarea::placeholder {
    color: var(--text-muted);
}

.send-btn {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--accent-hover);
}

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

/* Scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* Responsive */
@media (max-width: 600px) {
    .chat-container {
        max-width: 100%;
    }

    .message {
        max-width: 92%;
    }

    .chat-header {
        padding: 12px 16px;
    }

    .chat-messages {
        padding: 12px;
    }

    .chat-input-area {
        padding: 12px;
    }
}

/* Bold text in messages */
.message-bubble strong {
    font-weight: 600;
    color: var(--accent);
}

.message-bubble em {
    font-style: italic;
    color: var(--text-secondary);
}

/* Toast notifications */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.4;
    max-width: 360px;
    box-shadow: 0 4px 12px var(--shadow);
    pointer-events: auto;
    animation: toastIn 0.3s ease;
}

.toast.removing {
    animation: toastOut 0.3s ease forwards;
}

.toast svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.toast-success {
    border-color: var(--success);
}

.toast-success svg {
    color: var(--success);
}

.toast-error {
    border-color: #ef4444;
}

.toast-error svg {
    color: #ef4444;
}

.toast-info {
    border-color: var(--accent);
}

.toast-info svg {
    color: var(--accent);
}

.toast-warning {
    border-color: #f59e0b;
}

.toast-warning svg {
    color: #f59e0b;
}

.toast-close {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    display: flex;
}

.toast-close:hover {
    color: var(--text-primary);
}

.toast-close svg {
    width: 14px;
    height: 14px;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(20px); }
}

@media (max-width: 600px) {
    .toast-container {
        top: 8px;
        right: 8px;
        left: 8px;
    }

    .toast {
        max-width: 100%;
    }
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
