/* Chat Button */
#chat-toggle-btn {
    position: fixed;
    bottom: 80px;
    right: 18px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #006400 0%, #228b22 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0,100,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    transition: all 0.3s ease;
    z-index: 1001;
}

#chat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(0,100,0,0.4);
}

#chat-toggle-btn.active {
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
    bottom: 30px;
}

/* Notification badge */
.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4444;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    display: none;
    align-items: center;
    justify-content: center;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Chat Container - Desktop */
#agri-chatbot-container {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 400px;
    height: 600px;
    max-height: calc(100vh - 140px);
    border: none;
    border-radius: 20px;
    background-color: #ffffff;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    overflow: hidden;
    display: none;
    flex-direction: column;
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

#agri-chatbot-container.show {
    display: flex;
    transform: translateY(0);
    opacity: 1;
}

#chatbot-header {
    background: linear-gradient(135deg, #006400 0%, #228b22 100%);
    color: white;
    padding: 20px;
    font-weight: 600;
    text-align: center;
    border-bottom: none;
    box-shadow: 0 2px 10px rgba(0,100,0,0.2);
    position: relative;
    flex-shrink: 0;
}

#chatbot-header h3 {
    margin: 0;
    font-size: 18px;
    line-height: 1.2;
}

#chatbot-header p {
    margin: 5px 0 0 0;
    font-size: 12px;
    opacity: 0.9;
    line-height: 1.2;
}

.minimize-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.minimize-btn:hover {
    background-color: rgba(255,255,255,0.2);
}

.chat-restored-indicator {
    text-align: center;
    padding: 8px;
    background: #e8f5e8;
    color: #006400;
    font-size: 12px;
    border-bottom: 1px solid #d4edda;
    flex-shrink: 0;
}

#chatbot-messages {
    padding: 20px;
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background-color: #fafafa;
    min-height: 0;
}

.message {
    padding: 12px 16px;
    border-radius: 18px;
    max-width: 85%;
    line-height: 1.6;
    word-wrap: break-word;
    position: relative;
    animation: messageSlideIn 0.3s ease-out;
    font-size: 14px;
}

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

.user-message {
    background: linear-gradient(135deg, #dcf8c6 0%, #c8f7c5 100%);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    border: 1px solid #b8f5b1;
}

.bot-message {
    background-color: #ffffff;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid #e0e0e0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Enhanced formatting for bot messages */
.bot-message h4 {
    color: #006400;
    margin: 0 0 10px 0;
    font-size: 16px;
    line-height: 1.3;
}

.bot-message ul {
    margin: 10px 0;
    padding-left: 20px;
}

.bot-message li {
    margin: 8px 0;
    line-height: 1.5;
}

.bot-message strong {
    color: #006400;
}

.bot-message a {
    color: #006400;
    text-decoration: none;
    font-weight: 500;
}

.bot-message a:hover {
    text-decoration: underline;
}

.contact-info {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 12px;
    margin: 10px 0;
    border-left: 4px solid #006400;
}

.contact-info h5 {
    margin: 0 0 8px 0;
    color: #006400;
    font-size: 14px;
}

.contact-info p {
    margin: 4px 0;
    font-size: 13px;
}

/* Typing indicator */
.typing-indicator {
    display: none;
    align-self: flex-start;
    background-color: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    padding: 12px 16px;
    max-width: 85%;
    margin: 0 20px 15px 20px;
}

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

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #006400;
    animation: typingAnimation 1.4s infinite;
}

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

@keyframes typingAnimation {
    0%, 60%, 100% { opacity: 0.3; }
    30% { opacity: 1; }
}

#chatbot-input-container {
    display: flex;
    border-top: 1px solid #e0e0e0;
    background-color: #ffffff;
    padding: 15px;
    gap: 10px;
    flex-shrink: 0;
}

#chatbot-input {
    flex-grow: 1;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    padding: 12px 18px;
    font-size: 16px;
    outline: none;
    background-color: #f8f9fa;
    min-width: 0;
}

#chatbot-input:focus {
    border-color: #006400;
    background-color: #ffffff;
}

#chatbot-input::placeholder {
    color: #999;
}

#chatbot-send {
    background: linear-gradient(135deg, #006400 0%, #228b22 100%);
    color: white;
    border: none;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#chatbot-send:hover {
    background: linear-gradient(135deg, #005000 0%, #1e7d1e 100%);
    transform: translateY(-1px);
}

#chatbot-send:active {
    transform: translateY(0);
}

#chatbot-send:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* Scrollbar styling */
#chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

#chatbot-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

#chatbot-messages::-webkit-scrollbar-thumb {
    background: #c0c0c0;
    border-radius: 3px;
}

#chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #a0a0a0;
}

/* Tablet Styles (768px - 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
    #agri-chatbot-container {
        width: 380px;
        height: 550px;
        right: 20px;
        bottom: 90px;
    }

    #chat-toggle-btn {
        right: 25px;
        bottom: 70px;
    }
}

/* Mobile Styles (max-width: 768px) */
@media (max-width: 768px) {
    #agri-chatbot-container {
        width: calc(100vw - 20px);
        height: calc(100vh - 120px);
        max-height: calc(100vh - 120px);
        right: 10px;
        bottom: 80px;
        border-radius: 15px;
    }

    #chat-toggle-btn {
        right: 20px;
        bottom: 20px;
        width: 55px;
        height: 55px;
        font-size: 22px;
    }

    #chat-toggle-btn.active {
        bottom: 20px;
    }

    #chatbot-header {
        padding: 15px;
    }

    #chatbot-header h3 {
        font-size: 16px;
        margin-right: 35px;
    }

    #chatbot-header p {
        font-size: 11px;
    }

    .minimize-btn {
        top: 12px;
        right: 12px;
        width: 28px;
        height: 28px;
        font-size: 16px;
    }

    #chatbot-messages {
        padding: 15px;
        gap: 12px;
    }

    .message {
        padding: 10px 14px;
        font-size: 14px;
        max-width: 90%;
    }

    .bot-message h4 {
        font-size: 15px;
    }

    #chatbot-input-container {
        padding: 12px;
        gap: 8px;
    }

    #chatbot-input {
        padding: 10px 16px;
        font-size: 16px;
        border-radius: 18px;
    }

    #chatbot-send {
        width: 40px;
        height: 40px;
        font-size: 14px;
    }

    .typing-indicator {
        margin: 0 15px 12px 15px;
        padding: 10px 14px;
    }
}

/* Small Mobile Styles (max-width: 480px) */
@media (max-width: 480px) {
    #agri-chatbot-container {
        width: calc(100vw - 10px);
        height: calc(100vh - 100px);
        right: 5px;
        bottom: 70px;
        border-radius: 12px;
    }

    #chat-toggle-btn {
        right: 15px;
        bottom: 15px;
        width: 50px;
        height: 50px;
        font-size: 20px;
    }

    #chatbot-header {
        padding: 12px;
    }

    #chatbot-header h3 {
        font-size: 15px;
        margin-right: 30px;
    }

    #chatbot-header p {
        font-size: 10px;
    }

    .minimize-btn {
        top: 10px;
        right: 10px;
        width: 26px;
        height: 26px;
        font-size: 14px;
    }

    #chatbot-messages {
        padding: 12px;
        gap: 10px;
    }

    .message {
        padding: 8px 12px;
        font-size: 13px;
        border-radius: 16px;
        max-width: 92%;
    }

    .bot-message h4 {
        font-size: 14px;
        margin-bottom: 8px;
    }

    .bot-message ul {
        padding-left: 16px;
    }

    .bot-message li {
        margin: 6px 0;
    }

    .contact-info {
        padding: 10px;
        margin: 8px 0;
    }

    .contact-info h5 {
        font-size: 13px;
    }

    .contact-info p {
        font-size: 12px;
    }

    #chatbot-input-container {
        padding: 10px;
        gap: 6px;
    }

    #chatbot-input {
        padding: 8px 14px;
        font-size: 15px;
        border-radius: 16px;
    }

    #chatbot-send {
        width: 36px;
        height: 36px;
        font-size: 13px;
    }

    .typing-indicator {
        margin: 0 12px 10px 12px;
        padding: 8px 12px;
    }

    .typing-dot {
        width: 5px;
        height: 5px;
    }
}

/* Extra Small Mobile (max-width: 320px) */
@media (max-width: 320px) {
    #agri-chatbot-container {
        width: calc(100vw - 8px);
        height: calc(100vh - 90px);
        right: 4px;
        bottom: 65px;
        border-radius: 10px;
    }

    #chat-toggle-btn {
        right: 12px;
        bottom: 12px;
        width: 45px;
        height: 45px;
        font-size: 18px;
    }

    #chatbot-header {
        padding: 10px;
    }

    #chatbot-header h3 {
        font-size: 14px;
        margin-right: 28px;
    }

    #chatbot-header p {
        font-size: 9px;
    }

    .minimize-btn {
        top: 8px;
        right: 8px;
        width: 24px;
        height: 24px;
        font-size: 12px;
    }

    #chatbot-messages {
        padding: 10px;
        gap: 8px;
    }

    .message {
        padding: 6px 10px;
        font-size: 12px;
        border-radius: 14px;
    }

    .bot-message h4 {
        font-size: 13px;
        margin-bottom: 6px;
    }

    #chatbot-input-container {
        padding: 8px;
        gap: 5px;
    }

    #chatbot-input {
        padding: 6px 12px;
        font-size: 14px;
        border-radius: 14px;
    }

    #chatbot-send {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }
}

/* Landscape orientation for mobile */
@media (max-width: 768px) and (orientation: landscape) {
    #agri-chatbot-container {
        height: calc(100vh - 80px);
        bottom: 60px;
    }

    #chat-toggle-btn {
        bottom: 15px;
    }

    #chat-toggle-btn.active {
        bottom: 15px;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    #chat-toggle-btn {
        box-shadow: 0 2px 10px rgba(0,100,0,0.3);
    }

    #agri-chatbot-container {
        box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    #agri-chatbot-container {
        background-color: #2d2d2d;
        color: #ffffff;
    }

    #chatbot-messages {
        background-color: #1e1e1e;
    }

    .bot-message {
        background-color: #3d3d3d;
        border-color: #555;
        color: #ffffff;
    }

    .user-message {
        background: linear-gradient(135deg, #4a6741 0%, #5a7850 100%);
        border-color: #6a8860;
    }

    #chatbot-input {
        background-color: #3d3d3d;
        border-color: #555;
        color: #ffffff;
    }

    #chatbot-input:focus {
        background-color: #4d4d4d;
    }

    #chatbot-input::placeholder {
        color: #aaa;
    }

    .contact-info {
        background-color: #3d3d3d;
        border-left-color: #228b22;
    }

    .chat-restored-indicator {
        background-color: #2d4a2d;
        color: #90c690;
        border-bottom-color: #456745;
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .notification-badge {
        animation: none;
    }

    .typing-dot {
        animation: none;
        opacity: 0.6;
    }
}

/* Focus states for accessibility */
#chat-toggle-btn:focus-visible,
.minimize-btn:focus-visible,
#chatbot-send:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

#chatbot-input:focus-visible {
    outline: 2px solid #006400;
    outline-offset: 1px;
}