/**
 * Billy & Daisy Classic Chat - Frontend Styles
 * ENHANCED VERSION - With user recognition styles and feedback UI
 * FIXED: Better responsiveness, accessibility, and consistent styling
 * ADDED: Bot statistics bar styles with color coding for memory usage
 */

:root {
    --billy-color: #4CAF50;
    --daisy-color: #FF69B4;
    --chat-bg: #ffffff;
    --chat-text: #333333;
    --chat-border: #e0e0e0;
    --user-message-bg: #f0f0f0;
    --bot-message-bg: #e8f5e9;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.12);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.15);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: 0.3s ease;
    --feedback-bg: #f5f5f5;
    --feedback-hover: #e8e8e8;
}

/* Chat Container */
.bdc-chat-container {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    max-width: 350px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    background: var(--chat-bg);
    transition: all var(--transition);
}

.bdc-chat-container:hover {
    box-shadow: var(--shadow-lg);
}

/* Position variants */
.bdc-chat-container.position-right {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    max-width: 380px;
}

.bdc-chat-container.position-left {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 999999;
    max-width: 380px;
}

.bdc-chat-container.position-inline {
    position: relative;
    width: 100%;
    max-width: 100%;
    margin: 20px 0;
}

/* Chat Header */
.bdc-chat-header {
    background: linear-gradient(135deg, var(--billy-color), var(--daisy-color));
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: background var(--transition);
    user-select: none;
}

.bdc-chat-header:hover {
    filter: brightness(1.05);
}

.bdc-chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: white;
    display: flex;
    align-items: center;
    gap: 8px;
}

.bdc-chat-header .bot-avatar {
    display: inline-block;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    line-height: 28px;
    text-align: center;
    font-size: 16px;
}

.bdc-status {
    font-size: 11px;
    padding: 3px 10px;
    background: rgba(255,255,255,0.2);
    border-radius: 12px;
    font-weight: 500;
    letter-spacing: 0.3px;
}

.bdc-status.online {
    background: rgba(76, 175, 80, 0.3);
}

.bdc-status.thinking {
    background: rgba(255, 193, 7, 0.3);
    animation: pulse 1.5s infinite;
}

/* ============================================================
   BOT STATS BAR
   ============================================================ */
.bdc-stats-bar {
    display: flex;
    gap: 16px;
    padding: 8px 15px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    font-size: 12px;
    color: #666;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    flex-wrap: wrap;
    align-items: center;
}

.bdc-stats-bar .bdc-stat-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.bdc-stats-bar .bdc-stat-value {
    font-weight: 600;
    color: #333;
    min-width: 20px;
    transition: color 0.3s ease;
}

.bdc-stats-bar .bdc-stat-patterns .bdc-stat-value {
    color: #2e7d32;
}

.bdc-stats-bar .bdc-stat-keywords .bdc-stat-value {
    color: #0d47a1;
}

.bdc-stats-bar .bdc-stat-memory .bdc-stat-value {
    color: #e65100;
}

.bdc-stats-bar .bdc-stat-patterns-billy .bdc-stat-value {
    color: #2e7d32;
}

.bdc-stats-bar .bdc-stat-patterns-daisy .bdc-stat-value {
    color: #c2185b;
}

.bdc-stats-bar .bdc-stat-memory-combined .bdc-stat-value {
    color: #e65100;
}

/* Memory usage color coding */
.bdc-stats-bar .bdc-stat-memory.low .bdc-stat-value {
    color: #2e7d32;
}

.bdc-stats-bar .bdc-stat-memory.medium .bdc-stat-value {
    color: #e65100;
}

.bdc-stats-bar .bdc-stat-memory.high .bdc-stat-value {
    color: #c62828;
    animation: memoryWarning 2s infinite;
}

.bdc-stats-bar .bdc-stat-memory-combined.low .bdc-stat-value {
    color: #2e7d32;
}

.bdc-stats-bar .bdc-stat-memory-combined.medium .bdc-stat-value {
    color: #e65100;
}

.bdc-stats-bar .bdc-stat-memory-combined.high .bdc-stat-value {
    color: #c62828;
    animation: memoryWarning 2s infinite;
}

@keyframes memoryWarning {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Combined stats bar spacing */
.bdc-stats-bar.combined {
    gap: 20px;
}

.bdc-stats-bar.combined .bdc-stat-item {
    font-weight: 500;
}

/* ============================================================
   END BOT STATS BAR
   ============================================================ */

/* Chat Messages Area */
.bdc-chat-messages {
    height: 300px;
    overflow-y: auto;
    padding: 15px;
    background: var(--chat-bg);
    border-bottom: 1px solid var(--chat-border);
    scroll-behavior: smooth;
}

/* Message Bubbles */
.chat-message {
    margin-bottom: 12px;
    display: flex;
    animation: fadeIn 0.3s ease;
}

.bot-message {
    justify-content: flex-start;
}

.user-message {
    justify-content: flex-end;
}

.message-content {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.bot-message .message-content {
    background: var(--bot-message-bg);
    border-bottom-left-radius: 5px;
    color: var(--chat-text);
    margin-left: 8px;
}

.user-message .message-content {
    background: var(--user-message-bg);
    border-bottom-right-radius: 5px;
    color: var(--chat-text);
    margin-right: 8px;
}

/* Avatars */
.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    font-size: 20px;
    line-height: 32px;
    text-align: center;
    flex-shrink: 0;
    background: #f0f0f0;
}

/* Message Metadata */
.message-sender {
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 12px;
    color: #666;
}

.message-time {
    font-size: 10px;
    color: #999;
    margin-top: 4px;
    text-align: right;
    opacity: 0.8;
}

.message-text {
    word-break: break-word;
}

/* Feedback Buttons */
.message-feedback {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    gap: 6px;
}

.message-feedback .feedback-btn {
    background: var(--feedback-bg);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

.message-feedback .feedback-btn:hover:not(:disabled) {
    background: var(--feedback-hover);
    transform: scale(1.15);
}

.message-feedback .feedback-btn:active:not(:disabled) {
    transform: scale(0.9);
}

.message-feedback .feedback-btn.thumbs-up:hover:not(:disabled) {
    background: #4CAF50;
    color: white;
}

.message-feedback .feedback-btn.thumbs-down:hover:not(:disabled) {
    background: #f44336;
    color: white;
}

.message-feedback .feedback-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.message-feedback.feedback-submitted .feedback-btn {
    display: none;
}

.message-feedback .feedback-message {
    font-size: 11px;
    color: #666;
    animation: fadeIn 0.3s ease;
}

/* Name suggestion styling */
.name-suggestion {
    background: #f0f8ff;
    border-left: 3px solid #2196F3;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    margin: 10px 0;
    font-style: italic;
}

.name-suggestion-examples {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.name-example {
    background: #e0e0e0;
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 12px;
    color: #555;
}

/* Welcome back styling */
.welcome-back {
    background: linear-gradient(135deg, rgba(76,175,80,0.1), rgba(255,105,180,0.1));
    border-radius: var(--radius-sm);
    padding: 12px 15px;
    margin: 10px 0;
    text-align: center;
    font-weight: 500;
}

/* Input Area */
.bdc-chat-input {
    padding: 12px 15px;
    display: flex;
    gap: 10px;
    background: white;
    border-top: 1px solid var(--chat-border);
}

.bdc-chat-input input {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid var(--chat-border);
    border-radius: 25px;
    outline: none;
    font-size: 14px;
    transition: border-color var(--transition), box-shadow var(--transition);
    background: #fafafa;
}

.bdc-chat-input input:focus {
    border-color: var(--billy-color);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
    background: white;
}

.bdc-chat-input input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.bdc-chat-input button {
    padding: 10px 20px;
    background: var(--billy-color);
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background var(--transition), transform 0.15s;
    white-space: nowrap;
}

.bdc-chat-input button:hover:not(:disabled) {
    filter: brightness(1.1);
    transform: scale(1.02);
}

.bdc-chat-input button:active:not(:disabled) {
    transform: scale(0.95);
}

.bdc-chat-input button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Bot Conversation Styles */
.bdc-bot-conversation {
    background: white;
    border-radius: var(--radius-md);
    padding: 20px;
    margin: 20px 0;
    box-shadow: var(--shadow-md);
    max-width: 800px;
}

.bdc-bot-conversation .conversation-header {
    background: linear-gradient(135deg, #4CAF50, #FF69B4);
    color: white;
    padding: 12px 18px;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: -20px -20px 15px -20px;
}

.conversation-messages {
    max-height: 400px;
    overflow-y: auto;
    padding: 15px;
    background: #f9f9f9;
    border-radius: var(--radius-sm);
    margin-bottom: 15px;
    scroll-behavior: smooth;
}

.conversation-message {
    margin: 10px 0;
    padding: 10px 15px;
    border-radius: 15px;
    animation: slideIn 0.3s ease;
}

.conversation-message.billy {
    background: #e8f5e9;
    margin-right: 20%;
}

.conversation-message.daisy {
    background: #fff0f5;
    margin-left: 20%;
}

.message-header {
    font-weight: bold;
    margin-bottom: 5px;
    font-size: 12px;
    color: #666;
}

.message-header .billy {
    color: var(--billy-color);
}

.message-header .daisy {
    color: var(--daisy-color);
}

/* Conversation Controls */
.conversation-controls {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    flex-wrap: wrap;
    padding: 15px;
    background: #f9f9f9;
    border-radius: var(--radius-sm);
}

.conversation-controls button {
    padding: 10px 20px;
    background: var(--billy-color);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background var(--transition), transform 0.15s;
}

.conversation-controls button:hover:not(:disabled) {
    filter: brightness(1.1);
}

.conversation-controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.conversation-controls select,
.conversation-controls input {
    padding: 8px 12px;
    border: 1px solid var(--chat-border);
    border-radius: 5px;
    font-size: 14px;
    background: white;
    min-width: 120px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 4px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

.typing-indicator-container .typing-indicator {
    display: inline-flex;
}

/* History Page */
.bdc-history-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

.history-filters {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    padding: 20px;
    background: white;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
    align-items: center;
}

.history-filters select,
.history-filters input {
    padding: 8px 12px;
    border: 1px solid var(--chat-border);
    border-radius: 5px;
    font-size: 14px;
    background: white;
}

.history-entry {
    background: white;
    border-radius: var(--radius-sm);
    padding: 15px;
    margin-bottom: 15px;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition), box-shadow var(--transition);
}

.history-entry:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.history-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--chat-border);
}

.history-bot {
    font-weight: bold;
    color: var(--billy-color);
}

.history-date {
    color: #999;
    font-size: 12px;
}

.history-user-name {
    font-weight: 600;
    color: #333;
    margin-left: 10px;
}

.history-messages {
    margin-top: 10px;
}

.history-message {
    margin: 8px 0;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
}

.history-message.user {
    background: var(--user-message-bg);
    text-align: right;
}

.history-message.bot {
    background: var(--bot-message-bg);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .bdc-chat-container.position-right,
    .bdc-chat-container.position-left {
        width: 92%;
        max-width: 380px;
        bottom: 10px;
        right: 4%;
        left: 4%;
    }
    
    .bdc-chat-messages {
        height: 250px;
    }
    
    .conversation-controls {
        flex-direction: column;
    }
    
    .conversation-controls button,
    .conversation-controls select,
    .conversation-controls input {
        width: 100%;
    }
    
    .history-filters {
        flex-direction: column;
    }
    
    .history-filters select,
    .history-filters input,
    .history-filters button {
        width: 100%;
    }
    
    .message-content {
        max-width: 90%;
        font-size: 13px;
    }
    
    .bdc-chat-header h3 {
        font-size: 14px;
    }
    
    .conversation-message.billy {
        margin-right: 10%;
    }
    
    .conversation-message.daisy {
        margin-left: 10%;
    }
    
    .bdc-stats-bar {
        font-size: 10px;
        gap: 10px;
        padding: 6px 12px;
    }
    
    .bdc-stats-bar.combined {
        gap: 12px;
    }
}

@media (max-width: 480px) {
    .bdc-chat-container.position-right,
    .bdc-chat-container.position-left {
        width: 96%;
        max-width: 100%;
        bottom: 5px;
        right: 2%;
        left: 2%;
        border-radius: var(--radius-sm);
    }
    
    .bdc-chat-messages {
        height: 200px;
        padding: 10px;
    }
    
    .bdc-chat-input {
        padding: 8px 10px;
    }
    
    .bdc-chat-input input {
        padding: 8px 12px;
        font-size: 13px;
    }
    
    .bdc-chat-input button {
        padding: 8px 14px;
        font-size: 13px;
    }
    
    .conversation-messages {
        max-height: 300px;
        padding: 10px;
    }
    
    .bdc-bot-conversation {
        padding: 10px;
        margin: 10px 0;
    }
    
    .message-content {
        max-width: 95%;
        font-size: 12px;
        padding: 8px 12px;
    }
    
    .message-feedback .feedback-btn {
        width: 24px;
        height: 24px;
        font-size: 12px;
    }
    
    .bdc-stats-bar {
        font-size: 9px;
        gap: 8px;
        padding: 4px 10px;
    }
    
    .bdc-stats-bar.combined {
        gap: 8px;
        flex-wrap: wrap;
    }
}

/* Loading States */
.bdc-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100px;
}

.bdc-loading::after {
    content: '';
    width: 30px;
    height: 30px;
    border: 3px solid var(--chat-border);
    border-top-color: var(--billy-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Error States */
.bdc-error {
    padding: 20px;
    text-align: center;
    color: #f44336;
    background: #ffebee;
    border-radius: var(--radius-sm);
    margin: 10px;
}

/* Scrollbar Styling */
.bdc-chat-messages::-webkit-scrollbar,
.conversation-messages::-webkit-scrollbar {
    width: 6px;
}

.bdc-chat-messages::-webkit-scrollbar-track,
.conversation-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.bdc-chat-messages::-webkit-scrollbar-thumb,
.conversation-messages::-webkit-scrollbar-thumb {
    background: var(--billy-color);
    border-radius: 3px;
}

.bdc-chat-messages::-webkit-scrollbar-thumb:hover,
.conversation-messages::-webkit-scrollbar-thumb:hover {
    background: #45a049;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

.bdc-chat-container:focus-visible,
.bdc-chat-input input:focus-visible,
.bdc-chat-input button:focus-visible {
    outline: 2px solid #2271b1;
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    .bdc-chat-container.position-right,
    .bdc-chat-container.position-left {
        display: none !important;
    }
    
    .bdc-bot-conversation {
        box-shadow: none;
        border: 1px solid #ddd;
        break-inside: avoid;
    }
}

/* Dark Mode Support - Optional */
@media (prefers-color-scheme: dark) {
    .bdc-chat-container,
    .bdc-bot-conversation,
    .bdc-history-container,
    .bdc-chat-messages {
        background: #1a1a1a;
        color: #e0e0e0;
    }
    
    .bdc-chat-header {
        background: linear-gradient(135deg, #2e7d32, #c2185b);
    }
    
    .bdc-chat-input {
        background: #1a1a1a;
        border-top-color: #333;
    }
    
    .bdc-chat-input input {
        background: #2a2a2a;
        border-color: #444;
        color: #e0e0e0;
    }
    
    .bdc-chat-input input:focus {
        border-color: var(--billy-color);
        background: #333;
    }
    
    .bot-message .message-content {
        background: #2d3d2d;
        color: #e0e0e0;
    }
    
    .user-message .message-content {
        background: #3d3d3d;
        color: #e0e0e0;
    }
    
    .conversation-messages {
        background: #1a1a1a;
    }
    
    .conversation-message.billy {
        background: #2d3d2d;
    }
    
    .conversation-message.daisy {
        background: #3d2d3d;
    }
    
    .history-entry {
        background: #2a2a2a;
    }
    
    .history-message.user {
        background: #3d3d3d;
    }
    
    .history-message.bot {
        background: #2d3d2d;
    }
    
    .history-filters {
        background: #2a2a2a;
    }
    
    .conversation-controls {
        background: #2a2a2a;
    }
    
    .bdc-status.online {
        background: rgba(76, 175, 80, 0.3);
    }
    
    .message-sender {
        color: #aaa;
    }
    
    .message-time {
        color: #777;
    }
    
    .history-date {
        color: #777;
    }
    
    .message-feedback .feedback-btn {
        background: #3d3d3d;
        color: #ccc;
    }
    
    .message-feedback .feedback-btn:hover:not(:disabled) {
        background: #4d4d4d;
    }
    
    .message-feedback .feedback-message {
        color: #999;
    }
    
    /* Dark mode stats bar */
    .bdc-stats-bar {
        background: #2a2a2a;
        border-bottom-color: #3d3d3d;
        color: #adb5bd;
    }
    
    .bdc-stats-bar .bdc-stat-value {
        color: #e0e0e0;
    }
    
    .bdc-stats-bar .bdc-stat-patterns .bdc-stat-value {
        color: #81c784;
    }
    
    .bdc-stats-bar .bdc-stat-keywords .bdc-stat-value {
        color: #64b5f6;
    }
    
    .bdc-stats-bar .bdc-stat-memory .bdc-stat-value {
        color: #ffb74d;
    }
    
    .bdc-stats-bar .bdc-stat-patterns-billy .bdc-stat-value {
        color: #81c784;
    }
    
    .bdc-stats-bar .bdc-stat-patterns-daisy .bdc-stat-value {
        color: #f06292;
    }
    
    .bdc-stats-bar .bdc-stat-memory-combined .bdc-stat-value {
        color: #ffb74d;
    }
    
    .bdc-stats-bar .bdc-stat-memory.high .bdc-stat-value {
        color: #ef9a9a;
    }
    
    .bdc-stats-bar .bdc-stat-memory-combined.high .bdc-stat-value {
        color: #ef9a9a;
    }
}