/* CSS Variables for consistent theming */
:root {
    --primary: #4CAF50;
    --primary-dark: #388E3C;
    --secondary: #FFF8E1;
    --bg: #ffffff;
    --muted: #f4f4f4;
    --text: #333333;
    --text-light: #666666;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.15);
    --border-radius: 12px;
    --transition: all 0.3s ease;
    --font-size-base: 16px;
    --font-size-large: 18px;
    --font-size-xlarge: 22px;
    --spacing: 20px;
}

/* Global Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', Arial, sans-serif;
    font-size: var(--font-size-base);
    line-height: 1.5;
    color: var(--text);
    background-color: var(--bg);
    min-height: 100vh;
    overflow-x: hidden;
    margin: 0;
    padding: 0;
    background-image: url('field.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
}

/* Main page background styling */
#main {
    min-height: 100vh;
    width: 100%;
    position: relative;
}

/* Semi-transparent overlay for better readability */
#main::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 1;
}

/* Page Container System */
.page {
    display: none;
    min-height: 100vh;
    animation: fadeIn 0.3s ease-in;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Hidden Utility Class */
.hidden {
    display: none !important;
}

/* === ONBOARDING STYLES === */
.onboarding-container {
    min-height: 100vh;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing);
    background: linear-gradient(135deg, #E8F5E9 0%, #C5E1A5 100%);
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.onboarding-card {
    background: var(--bg);
    border-radius: var(--border-radius);
    padding: 40px 30px;
    max-width: 450px;
    width: 100%;
    box-shadow: var(--shadow);
    text-align: center;
    max-height: 90vh;
    overflow-y: auto;
}

.welcome-title {
    font-size: var(--font-size-xlarge);
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 30px;
}

.farmer-image-container {
    margin: 30px 0;
}

.image-placeholder {
    width: 120px;
    height: 120px;
    margin: 0 auto;
    background: var(--primary);
    color: #ffffff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 60px;
}

.form-group {
    margin-bottom: 25px;
    text-align: left;
}

.form-group label {
    display: block;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 10px;
    font-size: var(--font-size-base);
}

/* Custom Dropdown Styles - Opens Upward */
.custom-dropdown {
    position: relative;
    width: 100%;
}

.dropdown-selected {
    width: 100%;
    padding: 15px;
    font-size: var(--font-size-base);
    border: 2px solid #E0E0E0;
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
}

.dropdown-selected::after {
    content: '▲';
    font-size: 10px;
    color: #666;
}

.dropdown-selected:hover,
.custom-dropdown.open .dropdown-selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
}

.dropdown-options {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--bg);
    border: 2px solid var(--primary);
    border-radius: 8px;
    margin-bottom: 4px;
    max-height: 180px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
}

.custom-dropdown.open .dropdown-options {
    display: block;
}

.dropdown-option {
    padding: 12px 15px;
    cursor: pointer;
    transition: background 0.2s;
}

.dropdown-option:hover {
    background: #E8F5E9;
}

.dropdown-option.selected {
    background: var(--primary);
    color: white;
}

.dropdown {
    width: 100%;
    padding: 15px;
    font-size: var(--font-size-base);
    border: 2px solid #E0E0E0;
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.dropdown:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
}

.btn-primary {
    width: 100%;
    padding: 16px 32px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: var(--font-size-large);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.btn-primary:active {
    transform: translateY(0);
}

/* Header styling */
.app-header {
    position: relative;
    z-index: 2;
    background: rgba(255, 255, 255, 0.9);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-name {
    font-size: var(--font-size-xlarge);
    font-weight: 700;
    color: var(--primary);
}

.back-btn {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text);
    cursor: pointer;
    padding: 5px 10px;
    transition: var(--transition);
    z-index: 100;
    position: relative;
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.back-btn:hover {
    color: var(--primary);
    background: rgba(76, 175, 80, 0.1);
    border-radius: 4px;
}

/* === MAIN PAGE STYLES === */
.main-content {
    position: relative;
    z-index: 2;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 80px); /* Adjust based on header height */
}

.background-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

.bg-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.1);
}

/* Voice Agent Button */
.voice-button-container {
    text-align: center;
    z-index: 10;
}

.voice-agent-button {
    position: relative;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #66BB6A);
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    transition: var(--transition);
    box-shadow: 0 8px 30px rgba(76, 175, 80, 0.3);
}

.voice-agent-button:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 40px rgba(76, 175, 80, 0.4);
}

.voice-agent-button:active {
    transform: scale(0.98);
}

.button-glow {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: inherit;
    opacity: 0.5;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.5; }
    50% { transform: scale(1.15); opacity: 0.2; }
    100% { transform: scale(1); opacity: 0.5; }
}

.farmer-logo {
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
}

.logo-placeholder {
    font-size: 50px;
    color: #ffffff;
}

.button-label {
    color: #333;
    font-size: 1.2rem;
    font-weight: 600;
    margin-top: 0.5rem;
}

/* === VOICE PAGE STYLES === */
/* Chat Interface */
.chat-interface {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 80px);
    max-width: 800px;
    margin: 0 auto;
    padding: 0 var(--spacing) 0 var(--spacing); /* Left padding only, right edge for scrollbar */
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 0; /* Remove margin to maximize available space */
    padding-right: 0; /* Remove right padding to keep scrollbar at edge */
    min-height: 0; /* Important: allows flex child to shrink */
    /* Optimized height calculation for better message visibility */
    height: calc(100vh - 260px); /* Reduced to give more space for messages */
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 25px 20px 20px 20px; /* Reduced top padding for more message space */
    display: flex;
    flex-direction: column;
    gap: 12px; /* Reduced gap between messages for more compact layout */
    scroll-behavior: smooth;
    margin-right: 0; /* Ensure scrollbar is at the right edge */
    min-height: 0; /* Important: allows flex child to shrink */
    /* Ensure messages start from the top */
    justify-content: flex-start;
    align-items: stretch;
    /* Add initial position to ensure first message is visible */
    position: relative;
}

/* Ensure first message is always visible */
.chat-messages.first-message-loaded {
    padding-top: 30px; /* Reduced padding when first message is loaded */
}

/* Make sure the first message has proper spacing */
.chat-messages .message:first-child {
    margin-top: 0;
    padding-top: 5px; /* Reduced padding for first message */
}

/* Message Styles */
.message {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    animation: fadeInMessage 0.3s ease-in;
    align-items: flex-start;
}

@keyframes fadeInMessage {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Assistant messages - Left side */
.message.assistant {
    justify-content: flex-start;
}

/* User messages - Right side */
.message.user {
    justify-content: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    flex-shrink: 0;
}

/* Assistant avatar - कृ symbol with white font and green background */
.message.assistant .message-avatar {
    background: var(--primary);
    color: white;
}

.message-content {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: var(--font-size-base);
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
}

/* User message content - Right side styling */
.message.user .message-content {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 6px;
    margin-left: auto;
}

/* Assistant message content - Left side styling */
.message.assistant .message-content {
    background: var(--muted);
    color: var(--text);
    border-bottom-left-radius: 6px;
    margin-right: auto;
}

.message-timestamp {
    font-size: 12px;
    margin-top: 4px;
}

/* Timestamp styling for user messages */
.message.user .message-timestamp {
    color: rgba(255, 255, 255, 0.8);
    text-align: right;
}

/* Timestamp styling for assistant messages */
.message.assistant .message-timestamp {
    color: var(--text-light);
    text-align: left;
}

/* Input Controls Section */
.input-controls {
    background: var(--bg);
    padding: 20px;
    border-top: 1px solid #E0E0E0;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.voice-control {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 15px;
}

.voice-btn {
    position: relative;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: #4CAF50;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.4);
}

.voice-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.5);
}

.voice-btn:active {
    transform: scale(0.95);
}

.voice-btn.listening {
    animation: glow 1.5s infinite;
}

@keyframes glow {
    0%, 100% { box-shadow: 0 0 15px rgba(76, 175, 80, 0.6); }
    50% { box-shadow: 0 0 30px rgba(76, 175, 80, 1); }
}

.mic-icon {
    width: 32px;
    height: 32px;
}

.voice-status {
    color: var(--text-light);
    font-size: 14px;
    font-weight: 500;
}

.text-input-section {
    margin-bottom: 15px;
}

.input-container {
    display: flex;
    gap: 10px;
    align-items: center;
    background: var(--muted);
    border-radius: 25px;
    padding: 8px;
    border: 2px solid transparent;
    transition: var(--transition);
}

.input-container:focus-within {
    border-color: var(--primary);
    background: var(--bg);
}

.message-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px 16px;
    font-size: var(--font-size-base);
    color: var(--text);
    outline: none;
    font-family: inherit;
}

.message-input::placeholder {
    color: var(--text-light);
}

.camera-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #4CAF50;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    color: white;
    margin-right: 8px;
}

.camera-btn:hover {
    background: #43A047;
    transform: scale(1.05);
}

.camera-btn:active {
    transform: scale(0.95);
}

.camera-icon {
    width: 22px;
    height: 22px;
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    color: white;
}

.send-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.send-icon {
    font-size: 18px;
    font-weight: bold;
}

/* Image message styling */
.message-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: 12px;
    margin-top: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.message-image:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Image preview modal */
.image-preview-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.image-preview-modal.active {
    display: flex;
}

.image-preview-content {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
}

.close-preview {
    position: absolute;
    top: 20px;
    right: 20px;
    background: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.close-preview:hover {
    background: #f0f0f0;
    transform: scale(1.1);
}

.mode-toggle {
    text-align: center;
}

.mode-text {
    color: var(--text-light);
    font-size: 12px;
    font-weight: 500;
}

/* Scrollbar Styling for Chat */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--muted);
    border-radius: 4px;
    margin: 10px 0;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
    border: 1px solid var(--bg);
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* Typing indicator animation */
.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 8px 0;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-light);
    animation: typingAnimation 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingAnimation {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* === RESPONSIVE DESIGN === */
@media (min-width: 768px) {
    .voice-agent-button {
        width: 250px;
        height: 250px;
    }
    
    .farmer-logo {
        width: 100px;
        height: 100px;
    }
    
    .logo-placeholder {
        font-size: 60px;
    }
    
    .voice-circle {
        width: 220px;
        height: 220px;
    }
}

@media (min-width: 1024px) {
    :root {
        --font-size-base: 18px;
        --font-size-large: 20px;
        --font-size-xlarge: 26px;
    }
    
    .voice-agent-button {
        width: 280px;
        height: 280px;
    }
}

/* Accessibility Focus Styles */
button:focus-visible,
select:focus-visible,
a:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    .settings-wrapper,
    .back-btn,
    .voice-circle {
        display: none;
    }
}
