/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #2d5016 0%, #4a7c30 50%, #6b9a4d 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Main chat container */
.chat-container {
    width: 100%;
    max-width: 1200px;
    height: 90vh;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: 20px;
}

/* Mobile viewport optimizations */
@supports (-webkit-touch-callout: none) {
    .chat-container {
        height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    }
}

/* Header */
.chat-header {
    background: linear-gradient(135deg, #2d5016, #4a7c30);
    color: white;
    padding: 20px;
    text-align: center;
    position: relative;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo {
    font-size: 2rem;
}

.subtitle {
    font-size: 0.9rem;
    font-weight: 400;
    opacity: 0.8;
}

.language-toggle {
    display: flex;
    align-items: center;
}

.language-toggle button {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 12px;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.3s ease;
}

.language-toggle button:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Chat messages area */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    display: flex;
    animation: slideIn 0.3s ease;
}

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

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 80%;
    padding: 12px 18px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.4;
}

.message.user .message-bubble {
    background: linear-gradient(135deg, #4a7c30, #6b9a4d);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
    background: #f8f9fa;
    color: #2c3e50;
    border: 1px solid #e9ecef;
    border-bottom-left-radius: 4px;
}

.welcome-message {
    background: linear-gradient(135deg, #6b9a4d, #8bc34a) !important;
    color: white !important;
    border: none !important;
}

.welcome-message h3 {
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.welcome-message p {
    margin-bottom: 8px;
}

/* Suggestion buttons */
.suggestions-container {
    margin-top: 15px;
}

.suggestions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 10px;
}

.suggestion-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 12px 16px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    text-align: center;
    backdrop-filter: blur(10px);
}

.suggestion-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.suggestion-btn:active {
    transform: translateY(0);
}

/* Chat input */
.chat-input-container {
    padding: 20px;
    border-top: 1px solid #e9ecef;
    background: #fafbfc;
}

.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.input-buttons {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#clearButton {
    width: 44px;
    height: 44px;
    border: 2px solid #e1e5e9;
    border-radius: 50%;
    background: white;
    color: #6c757d;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

#clearButton:hover:not(:disabled) {
    border-color: #dc3545;
    color: #dc3545;
    transform: scale(1.05);
}

#clearButton:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

#messageInput {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e1e5e9;
    border-radius: 20px;
    resize: none;
    font-size: 16px;
    font-family: inherit;
    outline: none;
    transition: all 0.3s ease;
    max-height: 120px;
    min-height: 44px;
}

#messageInput:focus {
    border-color: #4a7c30;
    box-shadow: 0 0 0 3px rgba(74, 124, 48, 0.1);
}

#sendButton {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #4a7c30, #6b9a4d);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

#sendButton:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(74, 124, 48, 0.4);
}

#sendButton:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: white;
    border-radius: 15px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
}

.modal-header {
    background: linear-gradient(135deg, #2d5016, #4a7c30);
    color: white;
    padding: 20px;
    text-align: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.4rem;
}

.modal-body {
    padding: 25px;
    max-height: 400px;
    overflow-y: auto;
}

.modal-body p {
    margin-bottom: 15px;
    line-height: 1.5;
    color: #4a5568;
}

.modal-body ul {
    margin: 15px 0 15px 20px;
}

.modal-body li {
    margin-bottom: 8px;
    color: #4a5568;
}

.checkbox-container {
    margin-top: 20px;
    padding: 16px;
    border-top: 1px solid #e2e8f0;
    transition: all 0.3s ease;
    border-radius: 8px;
}

.checkbox-container.validation-warning {
    background: #fff3cd;
    border: 2px solid #ffc107;
    animation: pulse 0.5s ease-in-out;
}

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

.checkbox-container label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-weight: 500;
}

.checkbox-container input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: #4a7c30;
    cursor: pointer;
}

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

.modal-footer button {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
}

#privacyDecline {
    background: #e2e8f0;
    color: #4a5568;
}

#privacyDecline:hover {
    background: #cbd5e0;
}

.primary-button,
#privacyAcceptBtn,
#readAcceptBtn {
    background: linear-gradient(135deg, #4a7c30, #6b9a4d);
    color: white;
}

.primary-button:hover,
#privacyAcceptBtn:hover:not(:disabled),
#readAcceptBtn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74, 124, 48, 0.4);
}

#privacyAcceptBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Loading indicator */
.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    z-index: 1001;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e1e5e9;
    border-top: 3px solid #4a7c30;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#loadingText {
    color: #4a5568;
    font-weight: 500;
}

/* Thinking process styles */
.message.thinking {
    opacity: 0.9;
}

.thinking-bubble {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef) !important;
    border: 1px solid #dee2e6;
    border-radius: 18px;
    padding: 15px 20px;
    position: relative;
    overflow: hidden;
}

.thinking-bubble::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: shimmer 2s infinite;
}

.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #6c757d;
    font-style: italic;
}

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

.thinking-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4a7c30;
    animation: thinking-pulse 1.4s ease-in-out infinite both;
}

.thinking-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.thinking-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

.thinking-text {
    font-size: 0.9rem;
    font-weight: 500;
    transition: opacity 0.3s ease;
}

@keyframes thinking-pulse {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes shimmer {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

/* Markdown formatting styles */
.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
    margin: 16px 0 12px 0;
    font-weight: 600;
    line-height: 1.3;
    color: #2c3e50;
}

.message-bubble h1 {
    font-size: 1.4rem;
    border-bottom: 2px solid #e9ecef;
    padding-bottom: 8px;
}

.message-bubble h2 {
    font-size: 1.2rem;
    color: #34495e;
}

.message-bubble h3 {
    font-size: 1.1rem;
    color: #34495e;
}

.message-bubble p {
    margin: 8px 0;
    line-height: 1.5;
}

.message-bubble ul,
.message-bubble ol {
    margin: 12px 0;
    padding-left: 24px;
}

.message-bubble li {
    margin: 4px 0;
    line-height: 1.4;
}

.message-bubble code {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 2px 6px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    color: #e83e8c;
}

.message-bubble hr {
    border: none;
    border-top: 1px solid #e9ecef;
    margin: 16px 0;
}

.message-bubble a {
    color: #4a7c30;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all 0.2s ease;
}

.message-bubble a:hover {
    border-bottom-color: #4a7c30;
    color: #2d5016;
}

.message-bubble strong {
    font-weight: 600;
    color: #2c3e50;
}

.message-bubble em {
    font-style: italic;
    color: #495057;
}

/* Footer styles */
.footer {
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    padding: 20px;
    margin-top: auto;
}

.footer-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    text-align: center;
    font-size: 0.85rem;
    color: #6c757d;
}

.footer-content a {
    color: #4a7c30;
    text-decoration: none;
    transition: color 0.3s ease;
}

.footer-content a:hover {
    color: #2d5016;
    text-decoration: underline;
}

.footer-separator {
    color: #6c757d;
    margin: 0 4px;
}

/* Table wrapper for responsive behavior */
.message-bubble .table-wrapper {
    overflow-x: auto;
    margin: 16px 0;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.message-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    background: #fff;
    border-radius: 8px;
    font-size: 0.9rem;
    min-width: 300px;
}

.message-bubble thead {
    background: linear-gradient(135deg, #4a7c30, #6b9a4d);
    color: white;
}

.message-bubble th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: none;
}

.message-bubble td {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: top;
}

.message-bubble tbody tr:nth-child(even) {
    background: #f8f9fa;
}

.message-bubble tbody tr:hover {
    background: #e8f5e9;
    transition: background-color 0.2s ease;
}

.message-bubble tbody tr:last-child td {
    border-bottom: none;
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Mobile Responsive Design */
@media (max-width: 480px) {
    body {
        align-items: stretch;
        min-height: 100vh;
        padding: 0;
    }

    .chat-container {
        height: 100vh;
        margin: 0;
        border-radius: 0;
        max-width: none;
    }

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

    .header-content {
        flex-direction: row;
        gap: 8px;
        align-items: center;
    }

    .chat-header h1 {
        font-size: 1.1rem;
        gap: 6px;
    }

    .subtitle {
        font-size: 0.7rem;
        display: block;
    }

    .language-toggle button {
        padding: 4px 8px;
        font-size: 0.8rem;
    }

    .footer {
        display: none;
    }

    .chat-messages {
        padding: 12px;
        gap: 10px;
    }

    .message-bubble {
        max-width: 85%;
        padding: 10px 14px;
        font-size: 0.9rem;
    }

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

    .input-wrapper {
        gap: 8px;
    }

    #messageInput {
        font-size: 16px;
        padding: 10px 14px;
        min-height: 40px;
    }

    #sendButton, #clearButton {
        width: 40px;
        height: 40px;
    }

    .modal-content {
        margin: 10px;
        width: calc(100% - 20px);
        max-height: 90vh;
    }

    .suggestions-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .suggestion-btn {
        padding: 10px 14px;
        font-size: 0.85rem;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    body {
        align-items: stretch;
    }

    .chat-container {
        height: 100vh;
        margin: 0;
        border-radius: 0;
    }

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

    .chat-header h1 {
        font-size: 1.3rem;
    }

    .subtitle {
        font-size: 0.75rem;
    }

    .footer {
        opacity: 0.6;
        padding: 12px;
    }

    .footer-content {
        font-size: 0.8rem;
    }
}
