/* ========================================
   GPT-Style Chat Interface
   Clean, minimal conversation UI
   ======================================== */

/* Chat Wrapper */
.gpt-chat-wrapper {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 60px);
    width: 100%;
    position: relative;
}

/* Messages Container */
.gpt-messages {
    flex: 1;
    padding: 24px 40px;
    padding-bottom: 220px;
}

/* Welcome State */
.welcome-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    text-align: center;
    animation: fadeIn 0.5s ease;
}

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

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

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

.welcome-state > p {
    color: var(--sidebar-text-muted);
    margin-bottom: 40px;
}

/* Suggestion Cards */
.suggestion-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    max-width: 900px;
    width: 100%;
}

@media (max-width: 1200px) {
    .suggestion-cards {
        grid-template-columns: repeat(2, 1fr);
        max-width: 600px;
    }
}

.suggestion-card {
    background: var(--chat-surface);
    border: 1px solid var(--chat-border);
    border-radius: 16px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    text-align: left;
}

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

.suggestion-icon {
    font-size: 1.3rem;
    flex-shrink: 0;
}

.suggestion-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

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

.suggestion-desc {
    font-size: 0.8rem;
    color: var(--sidebar-text-muted);
}

/* Message Styles */
.gpt-message {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    animation: slideUp 0.3s ease;
    max-width: 100%;
}

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

.gpt-message.user {
    flex-direction: row-reverse;
}

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

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

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

.gpt-message .message-content {
    flex: 1;
    max-width: 85%;
}

.gpt-message.user .message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

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

.gpt-message.user .message-text {
    background: var(--chat-surface);
    padding: 12px 16px;
    border-radius: 18px 18px 4px 18px;
    border: 1px solid var(--chat-border);
}

.gpt-message .message-image {
    margin-top: 12px;
    max-width: 280px;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.gpt-message .message-image img {
    width: 100%;
    height: auto;
    display: block;
}

/* ========================================
   Crop Modal
   ======================================== */

.crop-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 5000;
    padding: 20px;
}

.crop-modal.show {
    display: flex;
}

.crop-modal-content {
    background: #ffffff;
    border-radius: 16px;
    max-width: 720px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

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

.crop-modal-header h5 {
    margin: 0;
    font-size: 1rem;
    color: #0f172a;
}

.crop-modal-close {
    border: none;
    background: transparent;
    color: #64748b;
    font-size: 1rem;
    cursor: pointer;
}

.crop-modal-body {
    padding: 12px 16px;
    max-height: 70vh;
    overflow: hidden;
}

.crop-modal-body img {
    max-width: 100%;
    display: block;
    margin: 0 auto;
}

.crop-canvas {
    display: none;
    max-width: 100%;
    width: 100%;
    border-radius: 12px;
    background: #0f172a;
}

.crop-modal-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding: 16px 20px;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 16px 20px;
    background: var(--chat-surface);
    border-radius: 18px;
    border: 1px solid var(--chat-border);
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--sidebar-text-muted);
    border-radius: 50%;
    animation: typingBounce 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 typingBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* AI Response Card Styles */
.ai-result-card {
    background: var(--chat-surface);
    border: 1px solid var(--chat-border);
    border-radius: 20px;
    overflow: hidden;
    margin-top: 12px;
}

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

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

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

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

.ai-result-header .status {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.ai-result-header .badge {
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
}

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

.diagnosis-row {
    margin-bottom: 20px;
}

.diagnosis-label {
    font-size: 0.75rem;
    color: var(--sidebar-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.diagnosis-name {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--sidebar-text);
    margin-bottom: 12px;
}

.confidence-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.confidence-bar {
    flex: 1;
    height: 8px;
    background: var(--chat-input-bg);
    border-radius: 4px;
    overflow: hidden;
    max-width: 200px;
}

.confidence-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.8s ease;
}

.confidence-fill.high { background: #22c55e; }
.confidence-fill.medium { background: #f59e0b; }
.confidence-fill.low { background: #ef4444; }

.confidence-text {
    font-weight: 600;
    font-size: 0.9rem;
}

.confidence-text.high { color: #22c55e; }
.confidence-text.medium { color: #f59e0b; }
.confidence-text.low { color: #ef4444; }

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

/* Fix visibility issues in treatment tabs */
.treatment-section .text-dark {
    color: var(--sidebar-text) !important; /* Force light text in dark mode */
}

.treatment-section .text-muted {
    color: var(--sidebar-text-muted) !important;
    opacity: 0.9 !important; /* Make sure it's visible */
    font-size: 0.9rem !important; /* Increase size slightly */
}

.treatment-section small {
    font-size: 0.9rem !important; /* Enforce readable size */
}

.treatment-section .badge.bg-success-subtle {
    background-color: #dcfce7 !important;
    color: #166534 !important;
    border: 1px solid #22c55e !important;
    font-weight: 700;
}

/* Tab styling adjustments */
.treatment-section .nav-tabs .nav-link {
    color: var(--sidebar-text-muted);
    border-color: transparent;
}

.treatment-section .nav-tabs .nav-link.active {
    background-color: var(--chat-surface);
    color: var(--accent-green);
    border-color: var(--chat-border) var(--chat-border) var(--chat-surface);
    font-weight: 700;
}

.treatment-section .tab-content {
    color: var(--sidebar-text);
}

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

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

.treatment-title .verified {
    margin-left: auto;
    background: rgba(34, 197, 94, 0.15);
    color: var(--accent-green);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.medicine-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-green);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.treatment-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.detail-pill {
    background: var(--chat-surface);
    padding: 10px 14px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.detail-pill .label {
    font-size: 0.7rem;
    color: var(--sidebar-text-muted);
    text-transform: uppercase;
}

.detail-pill .value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--sidebar-text);
}

.treatment-steps {
    margin-top: 16px;
}

.treatment-steps h4 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--sidebar-text);
    margin-bottom: 12px;
}

.treatment-steps ol {
    margin: 0;
    padding-left: 20px;
}

.treatment-steps li {
    color: var(--sidebar-text-muted);
    margin-bottom: 8px;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* Action Buttons in Result */
.result-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.result-action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    border: none;
}

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

.result-action-btn.primary:hover {
    background: var(--accent-green-dark);
}

.result-action-btn.secondary {
    background: var(--chat-input-bg);
    color: var(--sidebar-text);
    border: 1px solid var(--chat-border);
}

.result-action-btn.secondary:hover {
    border-color: var(--accent-green);
    color: var(--accent-green);
}

/* Feedback in Result */
.feedback-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--chat-border);
}

.feedback-label {
    font-size: 0.85rem;
    color: var(--sidebar-text-muted);
}

.feedback-btns {
    display: flex;
    gap: 8px;
}

.feedback-btn {
    padding: 6px 14px;
    border-radius: 8px;
    border: 1px solid var(--chat-border);
    background: var(--chat-input-bg);
    color: var(--sidebar-text);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.feedback-btn:hover {
    border-color: var(--accent-green);
}

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

/* ========================================
   Input Area (Fixed Bottom)
   ======================================== */
.gpt-input-area {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width);
    right: 0;
    background: linear-gradient(to top, var(--chat-bg) 80%, transparent);
    padding: 20px 24px 24px;
    transition: left 0.3s ease;
}

.chat-sidebar.collapsed ~ .chat-main .gpt-input-area,
.chat-main.expanded .gpt-input-area {
    left: 0;
}

@media (max-width: 768px) {
    .gpt-input-area {
        left: 0;
    }
}

.gpt-input-area form {
    max-width: 100%;
    padding: 0 24px;
    margin: 0 auto;
}

/* Options Panel */
.input-options {
    background: var(--chat-surface);
    border: 1px solid var(--chat-border);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 12px;
    display: none;
    animation: fadeIn 0.2s ease;
}

.input-options.show {
    display: block;
}

.option-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.option-row:last-child {
    margin-bottom: 0;
}

.option-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--sidebar-text-muted);
    min-width: 70px;
}

.option-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.option-pill {
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid var(--chat-border);
    background: var(--chat-input-bg);
    color: var(--sidebar-text);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.option-pill:hover {
    border-color: var(--accent-green);
}

.option-pill.active {
    background: rgba(34, 197, 94, 0.15);
    border-color: var(--accent-green);
    color: var(--accent-green);
}

/* Main Input Container */
.input-main {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-container {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    background: var(--chat-surface);
    border: 1px solid var(--chat-border);
    border-radius: 26px;
    padding: 8px 12px;
    transition: all 0.2s ease;
}

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

.input-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--sidebar-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

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

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

.input-display {
    flex: 1;
    padding: 8px 4px;
    min-height: 24px;
    display: flex;
    align-items: center;
}

.input-display .placeholder-text {
    color: var(--sidebar-text-muted);
    font-size: 0.95rem;
}

.input-display .selected-text {
    color: var(--sidebar-text);
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

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

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

.send-btn:disabled {
    background: var(--chat-border);
    color: var(--sidebar-text-muted);
    cursor: not-allowed;
}

/* Mini Image Preview */
.image-preview-mini {
    margin-bottom: 12px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    max-width: 150px;
    animation: fadeIn 0.2s ease;
    position: relative;
    display: inline-block;
}

.image-preview-mini img {
    width: 100%;
    height: auto;
    max-height: 120px;
    object-fit: cover;
    display: block;
}

.remove-preview {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 1rem;
}

.remove-preview:hover {
    background: #ef4444;
    transform: scale(1.1);
}

/* Input Hint */
.input-hint {
    text-align: center;
    font-size: 0.75rem;
    color: var(--sidebar-text-muted);
    margin-top: 10px;
}

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

/* Responsive */
@media (max-width: 768px) {
    .chat-container {
        padding: 0;
    }

    .suggestion-cards {
        grid-template-columns: 1fr;
    }
    
    .welcome-state h1 {
        font-size: 1.3rem;
    }
    
    .option-row {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .gpt-messages {
        padding-bottom: 220px;
    }
    
    .gpt-message .message-content {
        max-width: 100%;
        width: 100%;
        min-width: 0;
    }
    
    .treatment-details {
        grid-template-columns: 1fr;
    }

    .ai-result-card {
        width: 100%;
    }

    .treatment-section {
        width: 100%;
        padding: 16px;
    }

    .treatment-section .nav-tabs {
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 6px;
        border-bottom: 1px solid var(--chat-border);
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .treatment-section .nav-tabs .nav-item {
        width: auto;
        flex: 1 1 0;
    }

    .treatment-section .nav-tabs .nav-link {
        width: 100%;
        border: 1px solid var(--chat-border);
        border-radius: 12px;
        white-space: nowrap;
        font-size: 0.85rem;
        padding: 10px 8px;
    }

    .treatment-section .nav-tabs .nav-link.active {
        border-color: var(--accent-green);
    }
    
    .result-actions {
        flex-direction: column;
    }
    
    .result-action-btn {
        justify-content: center;
        width: 100%;
    }

    .feedback-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .feedback-btns {
        width: 100%;
    }

    .feedback-btn {
        flex: 1;
        justify-content: center;
    }

    .result-actions,
    .feedback-btns {
        gap: 8px;
    }
}

@media (max-width: 480px) {
    .chat-container {
        padding: 0;
    }

    .gpt-messages {
        padding: 10px 0 180px;
    }

    .gpt-message {
        gap: 10px;
        margin-bottom: 18px;
    }

    .gpt-message .message-avatar {
        width: 32px;
        height: 32px;
        flex-shrink: 0;
    }

    .gpt-message .message-image {
        max-width: 100%;
    }

    .gpt-message .message-image img {
        width: 100%;
    }

    .gpt-message .message-content {
        max-width: 100%;
        width: 100%;
        min-width: 0;
    }

    .ai-result-card,
    .treatment-section,
    .feedback-card,
    .map-card-chat,
    .result-card-chat,
    .treatment-card-chat,
    .feedback-card-chat {
        width: 100%;
        box-sizing: border-box;
    }

    .result-actions,
    .feedback-btns,
    .continue-prompt .action-btns,
    .conversation-actions {
        width: 100%;
    }

    .ai-result-card {
        margin-left: 0;
        margin-right: 0;
        border-radius: 14px;
        width: 100%;
    }

    .ai-result-body {
        padding: 16px 14px;
    }

    .treatment-section {
        padding: 14px;
        margin-top: 12px;
    }

    .treatment-section .nav-tabs {
        gap: 4px;
    }

    .treatment-section .nav-tabs .nav-link {
        padding: 9px 6px;
        font-size: 0.78rem;
    }

    .treatment-title {
        font-size: 0.95rem;
    }

    .medicine-name {
        font-size: 0.95rem;
    }

    .treatment-steps h4 {
        font-size: 0.85rem;
    }

    .result-action-btn,
    .feedback-btn,
    .continue-prompt .action-btn,
    .conv-action-btn {
        width: 100%;
        justify-content: center;
    }

    .continue-prompt {
        margin: 0.75rem 0;
        padding: 0.9rem;
    }

    .conversation-header {
        padding: 0.85rem 0.9rem;
        gap: 0.75rem;
        flex-direction: column;
        align-items: stretch;
    }

    .conversation-info {
        gap: 0.75rem;
        align-items: flex-start;
    }

    .conversation-actions {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    .conversation-actions .conversation-badge,
    .conversation-actions .conv-action-btn {
        width: 100%;
    }

    .session-divider {
        padding: 0.75rem 0;
        gap: 0.5rem;
    }
}
