/* ========================================
   AgriLens Chat-Style Layout

   ======================================== */

/* CSS Variables for Chat Interface */
:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 0px;
    --sidebar-bg: #171717;
    --sidebar-hover: #212121;
    --sidebar-text: #ececec;
    --sidebar-text-muted: #9ca3af;
    --chat-bg: #212121;
    --chat-surface: #2f2f2f;
    --chat-input-bg: #303030;
    --chat-border: #424242;
    --accent-green: #22c55e;
    --accent-green-dark: #16a34a;
}

/* Light mode overrides */
[data-theme="light"] {
    --sidebar-bg: #f9fafb;
    --sidebar-hover: #f3f4f6;
    --sidebar-text: #111827;
    --sidebar-text-muted: #6b7280;
    --chat-bg: #ffffff;
    --chat-surface: #f9fafb;
    --chat-input-bg: #f3f4f6;
    --chat-border: #e5e7eb;
}

/* ========================================
   Main Layout Structure
   ======================================== */
.chat-app-wrapper {
    display: flex;
    min-height: 100vh;
    background: var(--chat-bg);
}

/* ========================================
   Sidebar Styles
   ======================================== */
.chat-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 1000;
    transition: transform 0.3s ease, width 0.3s ease;
    border-right: 1px solid var(--chat-border);
}

.chat-sidebar.collapsed {
    transform: translateX(-100%);
}

/* Sidebar Header */
.sidebar-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--chat-border);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
}

.sidebar-logo i {
    color: var(--accent-green);
    font-size: 1.1rem;
}

.sidebar-toggle {
    background: transparent;
    border: none;
    color: var(--sidebar-text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.sidebar-toggle:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}

/* New Scan Button */
.new-scan-btn {
    margin: 16px;
    padding: 12px 16px;
    background: transparent;
    border: 1px solid var(--chat-border);
    border-radius: 12px;
    color: var(--sidebar-text);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
}

.new-scan-btn:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}

.new-scan-btn i {
    font-size: 1rem;
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

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

.sidebar-section-title {
    padding: 8px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--sidebar-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 10px;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    margin-bottom: 2px;
}

.sidebar-nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}

.sidebar-nav-item.active {
    background: var(--sidebar-hover);
    color: var(--accent-green);
}

.sidebar-nav-item i {
    width: 20px;
    text-align: center;
    font-size: 0.95rem;
}

/* Scan History Items */
.scan-history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 10px;
    transition: all 0.2s ease;
    font-size: 0.85rem;
}

.scan-history-item:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}

.scan-history-item .scan-emoji {
    font-size: 1.1rem;
}

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

.scan-history-item .scan-name {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.scan-history-item .scan-time {
    font-size: 0.75rem;
    color: var(--sidebar-text-muted);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--chat-border);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.sidebar-user:hover {
    background: var(--sidebar-hover);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-green), var(--accent-green-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.85rem;
}

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

.user-name {
    display: block;
    color: var(--sidebar-text);
    font-weight: 500;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 0.75rem;
    color: var(--sidebar-text-muted);
}

/* ========================================
   Main Content Area
   ======================================== */
.chat-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
    background: var(--chat-bg);
    overflow-x: hidden;
}

.chat-sidebar.collapsed ~ .chat-main,
.chat-main.expanded {
    margin-left: 0;
}

/* Top Header Bar */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--chat-bg);
    border-bottom: 1px solid var(--chat-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.mobile-menu-btn:hover {
    background: var(--sidebar-hover);
    color: var(--accent-green);
}

.header-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--sidebar-text);
}

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

.header-btn {
    background: transparent;
    border: none;
    color: var(--sidebar-text-muted);
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.header-btn:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}

/* ========================================
   Chat Container
   ======================================== */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: 0;
}

/* Welcome/Empty State */
.chat-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.welcome-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-green), var(--accent-green-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
}

.welcome-icon i {
    font-size: 2rem;
    color: white;
}

.welcome-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--sidebar-text);
    margin-bottom: 12px;
}

.welcome-subtitle {
    font-size: 0.95rem;
    color: var(--sidebar-text-muted);
    margin-bottom: 40px;
    max-width: 500px;
}

/* Quick Action Cards */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    width: 100%;
    max-width: 700px;
}

.quick-action-card {
    background: var(--chat-surface);
    border: 1px solid var(--chat-border);
    border-radius: 16px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.quick-action-card:hover {
    background: var(--sidebar-hover);
    border-color: var(--accent-green);
    transform: translateY(-2px);
}

.quick-action-icon {
    font-size: 1.5rem;
    margin-bottom: 12px;
}

.quick-action-title {
    font-weight: 600;
    color: var(--sidebar-text);
    margin-bottom: 4px;
    font-size: 0.95rem;
}

.quick-action-desc {
    font-size: 0.82rem;
    color: var(--sidebar-text-muted);
}

/* ========================================
   Chat Messages Area
   ======================================== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
}

.message {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    animation: fadeInUp 0.3s ease;
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
}

.message.assistant .message-avatar {
    background: linear-gradient(135deg, var(--accent-green), var(--accent-green-dark));
    color: white;
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.message-author {
    font-weight: 600;
    color: var(--sidebar-text);
    font-size: 0.9rem;
}

.message-time {
    font-size: 0.75rem;
    color: var(--sidebar-text-muted);
}

.message-body {
    color: var(--sidebar-text);
    line-height: 1.6;
    font-size: 0.95rem;
}

.message-body p {
    margin-bottom: 12px;
}

.message-body p:last-child {
    margin-bottom: 0;
}

/* ========================================
   Input Area at Bottom
   ======================================== */
.chat-input-area {
    padding: 16px 0 24px;
    background: var(--chat-bg);
    position: sticky;
    bottom: 0;
}

.input-container {
    background: var(--chat-input-bg);
    border: 1px solid var(--chat-border);
    border-radius: 24px;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: all 0.2s ease;
}

.input-container:focus-within {
    border-color: var(--accent-green);
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.1);
}

/* Scanner Card in Input Area */
.scanner-input-card {
    background: var(--chat-surface);
    border-radius: 16px;
    overflow: hidden;
}

.scanner-input-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--accent-green), var(--accent-green-dark));
    color: white;
}

.scanner-input-header .header-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.scanner-input-body {
    padding: 16px;
}

/* Input Row */
.input-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.input-actions {
    display: flex;
    gap: 4px;
}

.input-action-btn {
    background: transparent;
    border: none;
    color: var(--sidebar-text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-size: 1.1rem;
}

.input-action-btn:hover {
    background: var(--sidebar-hover);
    color: var(--accent-green);
}

.input-field {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--sidebar-text);
    font-size: 0.95rem;
    outline: none;
    resize: none;
    font-family: inherit;
}

.input-field::placeholder {
    color: var(--sidebar-text-muted);
}

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

.send-btn:hover {
    background: var(--accent-green-dark);
    transform: scale(1.05);
}

.send-btn:disabled {
    background: var(--chat-border);
    cursor: not-allowed;
    transform: none;
}

/* Input Tips */
.input-tips {
    display: flex;
    justify-content: center;
    gap: 16px;
    padding-top: 8px;
    font-size: 0.75rem;
    color: var(--sidebar-text-muted);
}

/* ========================================
   Scanner Compact in Chat
   ======================================== */
.chat-scanner {
    background: var(--chat-surface);
    border-radius: 20px;
    overflow: hidden;
    margin: 16px 0;
    border: 1px solid var(--chat-border);
}

.chat-scanner-header {
    background: linear-gradient(135deg, var(--accent-green), var(--accent-green-dark));
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
}

.chat-scanner-header .title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.chat-scanner-body {
    padding: 20px;
}

/* Step Pills Style */
.scan-step-chat {
    margin-bottom: 20px;
}

.scan-step-chat:last-child {
    margin-bottom: 0;
}

.step-label-chat {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    font-weight: 600;
    color: var(--sidebar-text);
    font-size: 0.9rem;
}

.step-badge {
    width: 24px;
    height: 24px;
    background: var(--accent-green);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
}

/* Selection Buttons in Chat */
.selection-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.selection-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--chat-input-bg);
    border: 2px solid var(--chat-border);
    border-radius: 12px;
    color: var(--sidebar-text);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    font-weight: 500;
}

.selection-btn:hover {
    border-color: var(--accent-green);
    background: var(--sidebar-hover);
}

.selection-btn.selected {
    border-color: var(--accent-green);
    background: rgba(34, 197, 94, 0.15);
    color: var(--accent-green);
}

.selection-btn .emoji {
    font-size: 1.2rem;
}

/* Upload Area in Chat */
.upload-area-chat {
    border: 2px dashed var(--chat-border);
    border-radius: 16px;
    padding: 30px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.upload-area-chat:hover {
    border-color: var(--accent-green);
    background: rgba(34, 197, 94, 0.05);
}

.upload-area-chat i {
    font-size: 2.5rem;
    color: var(--accent-green);
    margin-bottom: 12px;
}

.upload-area-chat .upload-text {
    font-weight: 600;
    color: var(--sidebar-text);
    margin-bottom: 4px;
}

.upload-area-chat .upload-hint {
    font-size: 0.85rem;
    color: var(--sidebar-text-muted);
}

/* Image Preview in Chat */
.image-preview-chat {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    max-width: 300px;
}

.image-preview-chat img {
    width: 100%;
    height: auto;
    display: block;
}

.image-preview-chat .remove-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.image-preview-chat .remove-btn:hover {
    background: #ef4444;
}

/* Diagnose Button */
.diagnose-btn-chat {
    width: 100%;
    padding: 14px 24px;
    background: linear-gradient(135deg, var(--accent-green), var(--accent-green-dark));
    border: none;
    border-radius: 12px;
    color: white;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s ease;
    margin-top: 16px;
}

.diagnose-btn-chat:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(34, 197, 94, 0.3);
}

.diagnose-btn-chat:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ========================================
   Result Card in Chat
   ======================================== */
.result-card-chat {
    background: var(--chat-surface);
    border-radius: 20px;
    overflow: hidden;
    border: 1px solid var(--chat-border);
    margin: 16px 0;
}

.result-header-chat {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.result-header-chat.healthy {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
}

.result-header-chat.disease {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
}

.result-header-chat.pest {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
}

.result-body-chat {
    padding: 20px;
}

.result-diagnosis {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
}

.result-image {
    width: 100px;
    height: 100px;
    border-radius: 12px;
    object-fit: cover;
}

.result-info {
    flex: 1;
}

.result-label {
    font-size: 0.8rem;
    color: var(--sidebar-text-muted);
    margin-bottom: 4px;
}

.result-disease-name {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--sidebar-text);
    margin-bottom: 8px;
}

.result-confidence {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--chat-input-bg);
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.result-confidence.high {
    color: #22c55e;
}

.result-confidence.medium {
    color: #f59e0b;
}

.result-confidence.low {
    color: #ef4444;
}

/* Treatment Section in Chat */
.treatment-section-chat {
    background: var(--chat-input-bg);
    border-radius: 16px;
    padding: 16px;
}

.treatment-header-chat {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    font-weight: 600;
    color: var(--sidebar-text);
}

.treatment-header-chat i {
    color: var(--accent-green);
}

.treatment-name-chat {
    font-weight: 700;
    color: var(--accent-green);
    margin-bottom: 12px;
    font-size: 1.1rem;
}

.treatment-steps-chat {
    list-style: none;
    padding: 0;
    margin: 0;
}

.treatment-steps-chat li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 10px;
    color: var(--sidebar-text);
    font-size: 0.9rem;
}

.treatment-steps-chat li:last-child {
    margin-bottom: 0;
}

.treatment-steps-chat .step-num {
    width: 22px;
    height: 22px;
    background: var(--accent-green);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}

/* ========================================
   Responsive Design
   ======================================== */
@media (max-width: 768px) {
    .chat-sidebar {
        transform: translateX(-100%);
    }
    
    .chat-sidebar.open {
        transform: translateX(0);
    }
    
    .chat-main {
        margin-left: 0;
    }
    
    .mobile-menu-btn {
        display: block;
    }
    
    .chat-container {
        padding: 0 16px;
    }
    
    .quick-actions {
        grid-template-columns: 1fr;
    }
    
    .selection-grid {
        flex-direction: column;
    }
    
    .selection-btn {
        width: 100%;
        justify-content: center;
    }
    
    /* Mobile overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }
    
    .sidebar-overlay.active {
        display: block;
    }
}

/* ========================================
   Animations
   ======================================== */
.animate-fadeIn {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.animate-slideIn {
    animation: slideIn 0.3s ease;
}

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

/* Loading Spinner */
.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--chat-border);
    border-top-color: var(--accent-green);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--chat-surface);
    border-radius: 16px;
    width: fit-content;
}

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

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
.typing-indicator span:nth-child(3) { animation-delay: 0s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Theme Toggle */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--chat-input-bg);
    border-radius: 20px;
    cursor: pointer;
}

.theme-toggle i {
    font-size: 0.9rem;
    color: var(--sidebar-text-muted);
}

.theme-toggle i.active {
    color: var(--accent-green);
}
