/* ============================================
   CROP YIELD PREDICTION DASHBOARD - STYLES
   Modern, Clean, Professional Design
   ============================================ */

/* CSS Variables */
:root {
    --primary-color: #2e7d32;
    --primary-light: #4caf50;
    --primary-dark: #1b5e20;
    --secondary-color: #ff9800;
    --accent-color: #03a9f4;
    --background-color: #f5f7fa;
    --card-background: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #4a4a68;
    --text-muted: #6c757d;
    --border-color: #e0e0e0;
    --success-color: #4caf50;
    --warning-color: #ff9800;
    --error-color: #f44336;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: all 0.3s ease;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #e4e8eb 100%);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Top Navigation */
.top-nav {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    padding: 15px 20px;
    background: var(--card-background);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.top-nav a {
    text-decoration: none;
    color: var(--text-secondary);
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 500;
    transition: var(--transition);
}

.top-nav a:hover,
.top-nav a.active {
    background: var(--primary-color);
    color: white;
}

/* Backend Status Indicator */
.backend-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: var(--card-background);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
    font-size: 0.9rem;
    font-weight: 500;
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #9e9e9e;
    animation: pulse 1.5s infinite;
}

.status-indicator.online {
    background: #4caf50;
    box-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
}

.status-indicator.offline {
    background: #f44336;
    box-shadow: 0 0 10px rgba(244, 67, 54, 0.5);
    animation: none;
}

.status-indicator.checking {
    background: #ff9800;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.status-text {
    color: var(--text-secondary);
}

.status-text.online {
    color: #4caf50;
}

.status-text.offline {
    color: #f44336;
}

.backend-status .retry-btn {
    margin-left: auto;
    padding: 6px 12px;
    font-size: 0.8rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: none;
}

.backend-status .retry-btn:hover {
    background: var(--primary-dark);
}

/* Author Credit */
.author-credit {
    font-size: 0.95rem;
    opacity: 0.85;
    margin-top: 8px;
    font-style: italic;
}

/* Header */
.header {
    text-align: center;
    padding: 40px 20px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    border-radius: var(--radius-lg);
    margin-bottom: 30px;
    color: white;
    box-shadow: var(--shadow-lg);
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 10px;
}

.logo-icon {
    font-size: 48px;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
    margin-top: 5px;
}

/* Main Content */
.main-content {
    display: grid;
    gap: 30px;
}

/* Section Headers */
.section-header {
    margin-bottom: 20px;
}

.section-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 5px;
}

.section-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* Form Section */
.form-section {
    background: var(--card-background);
    border-radius: var(--radius-lg);
    padding: 30px;
    box-shadow: var(--shadow-md);
}

.form-group-container {
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.group-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary-light);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.label-icon {
    font-size: 1.1rem;
}

.form-group input,
.form-group select {
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    transition: var(--transition);
    background: white;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.1);
}

.form-group input::placeholder {
    color: #adb5bd;
}

.hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 5px;
}

/* Buttons */
.form-actions {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    margin-top: 20px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 28px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.btn-icon {
    font-size: 1.2rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(46, 125, 50, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(46, 125, 50, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
}

.btn-outline:hover {
    background: var(--primary-color);
    color: white;
}

/* Results Section */
.results-section {
    background: var(--card-background);
    border-radius: var(--radius-lg);
    padding: 30px;
    box-shadow: var(--shadow-md);
}

.results-container {
    min-height: 200px;
}

.result-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted);
}

.placeholder-icon {
    font-size: 64px;
    margin-bottom: 15px;
    opacity: 0.5;
}

/* Result Card */
.result-card {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
    border-radius: var(--radius-lg);
    padding: 40px;
    color: white;
    text-align: center;
    animation: fadeInUp 0.5s ease;
}

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

.result-title {
    font-size: 1.2rem;
    opacity: 0.9;
    margin-bottom: 10px;
}

.result-value {
    font-size: 4rem;
    font-weight: 700;
    margin-bottom: 5px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.result-unit {
    font-size: 1.1rem;
    opacity: 0.9;
}

.result-secondary {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    justify-content: center;
    gap: 40px;
}

.result-item {
    text-align: center;
}

.result-item-label {
    font-size: 0.9rem;
    opacity: 0.8;
}

.result-item-value {
    font-size: 1.5rem;
    font-weight: 600;
}

/* Info Section */
.info-section {
    background: var(--card-background);
    border-radius: var(--radius-lg);
    padding: 30px;
    box-shadow: var(--shadow-md);
}

.info-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.info-card {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.info-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.info-icon {
    font-size: 2.5rem;
}

.info-content h4 {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 3px;
}

.info-content p {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--primary-color);
}

/* Footer */
.footer {
    text-align: center;
    padding: 30px 20px;
    margin-top: 30px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.footer-sub {
    margin-top: 5px;
    font-size: 0.85rem;
    opacity: 0.8;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    text-align: center;
    color: white;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--primary-light);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

/* Error State */
.error-card {
    background: linear-gradient(135deg, var(--error-color) 0%, #c62828 100%);
    border-radius: var(--radius-lg);
    padding: 30px;
    color: white;
    text-align: center;
}

.error-icon {
    font-size: 48px;
    margin-bottom: 15px;
}

/* ============================================
   NEW: Crop & Location Section Styles
   ============================================ */

.highlight-section {
    border-left: 4px solid var(--primary-color);
    background: linear-gradient(135deg, rgba(46, 125, 50, 0.03) 0%, rgba(76, 175, 80, 0.05) 100%);
}

/* Input with unit selector */
.input-with-unit {
    display: flex;
    gap: 8px;
}

.input-with-unit input {
    flex: 1;
}

.input-with-unit select {
    width: 120px;
    flex-shrink: 0;
}

/* Comparison Toggle */
.comparison-section {
    background: linear-gradient(135deg, rgba(3, 169, 244, 0.05) 0%, rgba(33, 150, 243, 0.08) 100%);
    border-left: 4px solid var(--accent-color);
}

.comparison-toggle {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    user-select: none;
}

.toggle-label input[type="checkbox"] {
    display: none;
}

.toggle-slider {
    width: 50px;
    height: 26px;
    background: var(--border-color);
    border-radius: 13px;
    position: relative;
    transition: var(--transition);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.toggle-label input:checked + .toggle-slider {
    background: var(--primary-color);
}

.toggle-label input:checked + .toggle-slider::before {
    transform: translateX(24px);
}

.toggle-text {
    font-weight: 500;
    color: var(--text-primary);
}

/* ============================================
   NEW: Crop & Location Result Header
   ============================================ */

.crop-location-header {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.crop-badge,
.location-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
}

.result-badge.excellent { background: rgba(76, 175, 80, 0.3); }
.result-badge.good { background: rgba(76, 175, 80, 0.2); }
.result-badge.moderate { background: rgba(255, 152, 0, 0.3); }
.result-badge.low { background: rgba(244, 67, 54, 0.3); }

/* ============================================
   NEW: Total Production Card
   ============================================ */

.total-production-card {
    margin-top: 25px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-md);
    border: 1px dashed rgba(255, 255, 255, 0.3);
}

.total-production-card h4 {
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.farm-size-info {
    font-size: 0.9rem;
    opacity: 0.9;
    margin-bottom: 15px;
}

.total-production-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
}

.total-item {
    text-align: center;
    padding: 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
}

.total-value {
    font-size: 1.4rem;
    font-weight: 700;
}

.total-label {
    font-size: 0.8rem;
    opacity: 0.8;
    margin-top: 4px;
}

/* ============================================
   NEW: Multi-Crop Comparison Section
   ============================================ */

.comparison-results-section {
    background: var(--card-background);
    border-radius: var(--radius-lg);
    padding: 30px;
    box-shadow: var(--shadow-md);
    margin-top: 30px;
}

.comparison-note {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.comparison-note.supported {
    background: rgba(76, 175, 80, 0.1);
    color: var(--success-color);
    border: 1px solid rgba(76, 175, 80, 0.3);
}

.comparison-note.demo {
    background: rgba(3, 169, 244, 0.1);
    color: var(--accent-color);
    border: 1px solid rgba(3, 169, 244, 0.3);
}

.comparison-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

.comparison-table th,
.comparison-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.comparison-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: var(--text-primary);
}

.comparison-table tr:hover {
    background: rgba(46, 125, 50, 0.05);
}

.comparison-table tr.top-crop {
    background: rgba(76, 175, 80, 0.1);
}

.comparison-table tr.top-crop td:first-child::after {
    content: '🏆';
    margin-left: 8px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    .header {
        padding: 30px 15px;
    }
    
    .header h1 {
        font-size: 1.8rem;
    }
    
    .form-section,
    .results-section,
    .info-section,
    .comparison-results-section {
        padding: 20px;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
    
    .result-value {
        font-size: 3rem;
    }
    
    .result-secondary {
        flex-direction: column;
        gap: 15px;
    }
    
    .total-production-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .crop-location-header {
        flex-direction: column;
        align-items: center;
    }
    
    .input-with-unit {
        flex-direction: column;
    }
    
    .input-with-unit select {
        width: 100%;
    }
    
    .comparison-table {
        font-size: 0.85rem;
    }
    
    .comparison-table th,
    .comparison-table td {
        padding: 8px 10px;
    }
}

/* Print Styles */
@media print {
    .form-actions,
    .loading-overlay {
        display: none;
    }
    
    .header {
        background: var(--primary-color) !important;
        -webkit-print-color-adjust: exact;
    }
}

/* ============================================
   FIELD STATUS INDICATORS
   Distinguish ML Active vs Contextual Fields
   ============================================ */

/* Toggle Button */
.btn-info {
    background: linear-gradient(135deg, #17a2b8, #138496);
    color: white;
    margin-top: 15px;
    font-size: 0.9rem;
    padding: 10px 20px;
}

.btn-info:hover {
    background: linear-gradient(135deg, #138496, #117a8b);
    transform: translateY(-2px);
}

/* Field Status Legend */
.field-status-legend {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 25px;
    border-left: 4px solid var(--accent-color);
    animation: slideDown 0.3s ease;
}

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

.legend-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 15px;
    margin: 8px 0;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
}

.legend-item.active-field {
    background: rgba(76, 175, 80, 0.1);
    border: 1px solid rgba(76, 175, 80, 0.3);
}

.legend-item.contextual-field {
    background: rgba(255, 152, 0, 0.1);
    border: 1px solid rgba(255, 152, 0, 0.3);
}

.status-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.active {
    background: linear-gradient(135deg, #4caf50, #2e7d32);
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.5);
}

.status-dot.contextual {
    background: linear-gradient(135deg, #ff9800, #f57c00);
    box-shadow: 0 0 8px rgba(255, 152, 0, 0.5);
}

/* Field Badges in Section Headers */
.field-badge {
    font-size: 0.7rem;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 500;
    margin-left: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: none; /* Hidden by default */
}

.field-badge.active {
    background: linear-gradient(135deg, #4caf50, #2e7d32);
    color: white;
}

.field-badge.partial {
    background: linear-gradient(135deg, #ffc107, #f9a825);
    color: #333;
}

.field-badge.contextual {
    background: linear-gradient(135deg, #78909c, #546e7a);
    color: white;
}

/* Show badges when field status is visible */
.show-field-status .field-badge {
    display: inline-block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

/* Section Highlighting when status visible */
.show-field-status .ml-active-section {
    border-left: 4px solid #4caf50;
    background: linear-gradient(135deg, rgba(76, 175, 80, 0.03), rgba(76, 175, 80, 0.08));
}

.show-field-status .partial-section {
    border-left: 4px solid #ffc107;
    background: linear-gradient(135deg, rgba(255, 193, 7, 0.03), rgba(255, 193, 7, 0.08));
}

.show-field-status .contextual-section {
    border-left: 4px solid #78909c;
    background: linear-gradient(135deg, rgba(120, 144, 156, 0.03), rgba(120, 144, 156, 0.08));
}

/* Transition for smooth toggle */
.form-group-container {
    transition: all 0.3s ease;
}

/* Active toggle button state */
.btn-info.active {
    background: linear-gradient(135deg, #0d6efd, #0b5ed7);
    box-shadow: 0 0 12px rgba(13, 110, 253, 0.4);
}

/* Data Quality Indicators */
.data-indicator {
    font-size: 0.7rem;
    margin-left: 5px;
    cursor: help;
    display: none; /* Hidden by default */
}

.data-indicator.good {
    color: #4caf50;
}

.data-indicator.partial {
    color: #ffc107;
    text-shadow: 0 0 2px rgba(0,0,0,0.3);
}

.data-indicator.contextual {
    color: #78909c;
}

/* Show indicators when field status is visible */
.show-field-status .data-indicator {
    display: inline;
}

/* Legend Item Styling - Distinct colors */
.legend-item.active-field {
    background: rgba(76, 175, 80, 0.1);
    border: 1px solid rgba(76, 175, 80, 0.3);
}

.legend-item.partial-field {
    background: rgba(255, 193, 7, 0.15);
    border: 1px solid rgba(255, 193, 7, 0.4);
}

.legend-item.contextual-field {
    background: rgba(120, 144, 156, 0.1);
    border: 1px solid rgba(120, 144, 156, 0.3);
}

/* Status dots - Clear differentiation */
.status-dot.active {
    background: linear-gradient(135deg, #4caf50, #2e7d32);
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.5);
}

.status-dot.partial {
    background: linear-gradient(135deg, #ffc107, #f9a825);
    box-shadow: 0 0 8px rgba(255, 193, 7, 0.5);
}

.status-dot.contextual {
    background: linear-gradient(135deg, #78909c, #546e7a);
    box-shadow: 0 0 8px rgba(120, 144, 156, 0.5);
}

/* Field type styling when status visible */
.show-field-status .good-data-field {
    border-left: 3px solid #4caf50;
    padding-left: 12px;
    margin-left: -12px;
}

.show-field-status .partial-data-field {
    border-left: 3px solid #ffc107;
    padding-left: 12px;
    margin-left: -12px;
    background: rgba(255, 193, 7, 0.05);
}

.show-field-status .contextual-data-field {
    border-left: 3px solid #78909c;
    padding-left: 12px;
    margin-left: -12px;
    background: rgba(120, 144, 156, 0.05);
}

/* Improved Legend Styling */
.field-status-legend h4 {
    font-size: 1rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 10px;
}

.legend-item small {
    color: var(--text-muted);
    font-size: 0.8rem;
    display: block;
    margin-top: 3px;
}
