/* ----- General Styling ----- */
:root {
    --primary-color: #2a9d8f;
    --secondary-color: #e9c46a;
    --background-color: #f8f9fa;
    --text-color: #333;
    --card-bg-color: #ffffff;
    --shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Sarabun', sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
}

h1, h2, h3 {
    color: var(--primary-color);
}

section {
    padding: 80px 20px; /* Increased top and bottom padding from 60px to 80px */
    text-align: center;
}

.subtitle {
    max-width: 600px;
    margin: 0 auto 30px auto;
    color: #666;
}

.hidden {
    display: none !important;
}

/* ----- Header & Navigation ----- */
header {
    background-color: var(--card-bg-color);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 1000;
}

nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    height: 70px;
}

.logo {
    font-size: 1.5em;
    font-weight: 700;
    color: var(--primary-color);
}

nav ul {
    list-style: none;
    display: flex;
    gap: 20px;
    margin: 0;
    padding: 0;
}

nav a {
    text-decoration: none;
    color: var(--text-color);
    font-weight: 700;
    transition: color 0.3s;
    padding: 5px 10px;
}

nav a:hover {
    color: var(--primary-color);
}

.hamburger {
    display: none;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
}

.hamburger-bar {
    display: block;
    width: 25px;
    height: 3px;
    margin: 5px auto;
    transition: all 0.3s ease-in-out;
    background-color: var(--text-color);
}

/* ----- Hero Section ----- */
#hero {
    background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('../assets/images/smart-farm-technology.jpg');
    background-size: cover;
    background-position: center;
    color: white;
    min-height: 80vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.hero-content h1 {
    font-size: 3em;
    color: white;
    margin-bottom: 20px;
}

.hero-content p {
    font-size: 1.3em;
    margin-bottom: 30px;
}

/* ----- Updated Explore Section for Larger Map ----- */
#explore {
    padding: 100px 30px; /* Increased padding all around */
}

#explore h2 {
    font-size: 2.8em; /* Larger section title */
    margin-bottom: 25px;
}

#explore .subtitle {
    font-size: 1.2em; /* Larger subtitle */
    margin-bottom: 50px;
}

.explore-container {
    display: flex;
    flex-wrap: wrap;
    gap: 40px; /* Increased gap */
    max-width: 1400px; /* Increased max-width */
    margin: 0 auto;
    align-items: flex-start;
    text-align: left;
}

.farm-map-container {
    flex: 2.5; /* Increased from 3 to give more space */
    min-width: 500px; /* Increased minimum width */
    position: relative;
}

.zoom-container {
    position: relative;
    overflow: hidden;
    border-radius: 12px; /* Slightly more rounded corners */
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15); /* Enhanced shadow */
    cursor: grab;
    background: #eaf6f5;
    min-height: 600px; /* Set minimum height to match legend */
    height: 600px; /* Fixed height */
}

.zoom-container img {
    width: 100%;
    height: 100%; /* Changed from auto to 100% to fill container */
    object-fit: contain; /* Maintain aspect ratio while filling */
    display: block;
    transition: transform 0.3s ease;
}

.zoom-controls {
    position: absolute;
    top: 15px; /* Increased spacing */
    right: 15px;
    display: flex;
    flex-direction: column;
    gap: 8px; /* Increased gap */
    z-index: 100;
}

.zoom-btn {
    width: 45px; /* Increased size */
    height: 45px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #ccc;
    border-radius: 50%;
    font-size: 22px; /* Increased font size */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    box-shadow: 0 3px 8px rgba(0,0,0,0.25);
}

.zoom-btn:hover {
    background: white;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.fullscreen-btn {
    position: absolute;
    top: 15px; /* Increased spacing */
    left: 15px;
    width: 45px; /* Increased size */
    height: 45px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #ccc;
    border-radius: 50%;
    font-size: 18px; /* Increased font size */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    box-shadow: 0 3px 8px rgba(0,0,0,0.25);
}

.fullscreen-btn:hover {
    background: white;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.legend-container {
    flex: 1;
    min-width: 320px; /* Increased minimum width */
    box-sizing: border-box;
    background-color: var(--card-bg-color);
    padding: 25px; /* Increased padding */
    border-radius: 12px; /* Match map border radius */
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15); /* Enhanced shadow */
    height: 600px; /* Fixed height to match map */
    overflow-y: auto;
}

.legend-container h3 {
    margin-top: 0;
    text-align: center;
    border-bottom: 3px solid var(--primary-color); /* Thicker border */
    padding-bottom: 15px; /* Increased padding */
    position: sticky;
    top: -25px; /* Adjust for increased padding */
    background: white;
    z-index: 10;
    font-size: 1.3em; /* Larger title */
}

.legend-button {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 15px 18px; /* Increased padding */
    margin-bottom: 12px; /* Increased margin */
    border: 1px solid #ddd;
    background-color: #fff;
    border-radius: 8px; /* Slightly more rounded */
    cursor: pointer;
    text-align: left;
    font-family: 'Sarabun', sans-serif;
    font-size: 1.05rem; /* Slightly larger font */
    transition: all 0.3s;
}

.legend-button:hover {
    background-color: #f8f9fa;
    transform: translateX(8px); /* Increased hover movement */
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-color: var(--primary-color);
}

.legend-color-dot {
    width: 22px; /* Increased size */
    height: 22px;
    border-radius: 50%;
    margin-right: 18px; /* Increased margin */
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.15);
}

/* ----- Fullscreen Modal ----- */
.fullscreen-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.95);
    z-index: 9999;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.fullscreen-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
}

.fullscreen-content {
    position: relative;
    width: 95%;
    height: 95%;
    display: flex;
    gap: 20px;
}

.fullscreen-map {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.fullscreen-map img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    cursor: grab;
    transition: transform 0.3s ease;
}

.fullscreen-legend {
    width: 300px;
    background: white;
    padding: 20px;
    border-radius: 8px;
    overflow-y: auto;
    flex-shrink: 0;
}

.close-fullscreen {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 44px;
    height: 44px;
    background: rgba(255,255,255,0.9);
    border: none;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* =================================== */
/* ----- REFACTORED DASHBOARD MENU ----- */
/* =================================== */
#dashboard {
    background: linear-gradient(135deg, #eaf6f5, #f0f8f7);
}

.dashboard-header {
    margin-bottom: 50px;
}

.dashboard-header h2 {
    font-size: 2.5em;
    margin-bottom: 15px;
}

.dashboard-menu-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 25px;
    max-width: 1200px;
    margin: 0 auto;
}

.dashboard-menu-card {
    background-color: var(--card-bg-color);
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    border-top: 4px solid var(--primary-color);
}

.dashboard-menu-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.12);
    border-top-color: var(--secondary-color);
}

.dashboard-menu-card .card-icon {
    font-size: 3em;
    margin-bottom: 15px;
}

.dashboard-menu-card .card-title {
    font-size: 1.4em;
    margin-bottom: 10px;
}

.dashboard-menu-card .card-description {
    font-size: 0.9em;
    color: #666;
    line-height: 1.5;
}

/* =================================== */
/* ----- Dashboard Grid (Original) ----- */
/* =================================== */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 25px;
    max-width: 1200px;
    margin: 0 auto;
}

.dashboard-card {
    background: linear-gradient(135deg, var(--card-bg-color), #fafafa);
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
    text-align: left;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
}

.dashboard-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.12);
}

.dashboard-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
}

.card-header {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #f0f0f0;
}

.card-icon {
    font-size: 2.5em;
    margin-right: 15px;
}

.card-title {
    margin: 0;
    font-size: 1.4em;
    color: var(--primary-color);
}

.card-content { 
    display: grid; 
    gap: 15px; 
}

.data-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.data-label { 
    font-weight: 600; 
    color: #555; 
}

.data-value { 
    font-size: 1.2em; 
    font-weight: 700; 
    color: var(--primary-color); 
    text-align: right; 
}

.status-indicator { 
    display: inline-flex; 
    align-items: center; 
    padding: 5px 12px; 
    border-radius: 15px; 
    font-size: 0.9em; 
    font-weight: 600; 
}

.status-excellent { 
    background: #d4edda; 
    color: #155724; 
}

.status-good { 
    background: #d1ecf1; 
    color: #0c5460; 
}

.status-warning { 
    background: #fff3cd; 
    color: #856404; 
}

.external-factors { 
    background: linear-gradient(135deg, #e3f2fd, #f3e5f5); 
}

.external-factors::before{ 
    background: linear-gradient(90deg, #4a90e2, #774fb8); 
}

.factor-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); 
    gap: 15px; 
}

.factor-item { 
    text-align: center; 
    padding: 15px; 
    background: rgba(255,255,255,0.8); 
    border-radius: 10px; 
}

.factor-icon { 
    font-size: 2em; 
    margin-bottom: 8px; 
}

.factor-label { 
    font-size: 0.9em; 
    color: #666; 
    margin-bottom: 5px; 
}

.factor-value { 
    font-size: 1.1em; 
    font-weight: 700; 
    color: var(--primary-color); 
}

/* =================================== */
/* ----- DETAIL PAGES STYLES ----- */
/* =================================== */

#detail-pages-container {
    padding: 40px 20px;
    animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.detail-page-header {
    max-width: 1200px;
    margin: 0 auto 30px auto;
    text-align: left;
}

#back-to-dashboard-btn {
    background: none;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    padding: 10px 20px;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 700;
    font-family: 'Sarabun', sans-serif;
    font-size: 1em;
    transition: all 0.3s ease;
}

#back-to-dashboard-btn:hover {
    background: var(--primary-color);
    color: white;
}

.detail-page {
    display: none; /* Hidden by default */
    max-width: 1200px;
    margin: 0 auto;
}

.detail-page.active {
    display: block; /* Shown when active */
}

.detail-page-title {
    text-align: center;
    font-size: 2.2em;
    margin-bottom: 40px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 25px;
}

/* ----- Modal Styles ----- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background-color: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 600px;
    position: relative;
    transform: scale(1);
    transition: transform 0.3s ease;
}

.modal-overlay.hidden .modal-content { 
    transform: scale(0.9); 
}

.close-button {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 2em;
    line-height: 1;
    font-weight: bold;
    color: #aaa;
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.3s;
    padding: 5px;
}

.close-button:hover { 
    color: #333; 
}

#modal-crops { 
    list-style-type: none; 
    padding-left: 0; 
}

#modal-crops li {
    background-color: #eaf6f5;
    padding: 10px 15px;
    border-radius: 8px;
    margin-bottom: 8px;
    color: var(--primary-color);
    font-weight: 600;
}

.status-badge {
    background-color: var(--secondary-color);
    color: #333;
    padding: 5px 12px;
    border-radius: 15px;
    font-size: 0.9em;
    font-weight: bold;
}

/* ----- Chart Section ----- */
.chart-container {
    max-width: 1000px;
    height: 500px;
    margin: 40px auto;
    padding: 30px;
    background-color: var(--card-bg-color);
    border-radius: 15px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

footer {
    background-color: var(--text-color);
    color: white;
    text-align: center;
    padding: 30px;
}

/* =================================== */
/* ----- Responsive Design ----- */
/* =================================== */

@media (max-width: 1200px) {
    .explore-container {
        max-width: 1200px;
        gap: 30px;
    }
    
    .farm-map-container {
        min-width: 450px;
    }
    
    .zoom-container,
    .legend-container {
        height: 550px; /* Slightly reduced for medium screens */
    }
    
    .dashboard-menu-grid { 
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); 
    }
    
    .detail-grid { 
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); 
    }
}

@media (max-width: 1024px) {
    .explore-container {
        flex-direction: column;
        align-items: center;
        gap: 40px;
    }
    
    .farm-map-container, 
    .legend-container {
        flex: none;
        width: 100%;
        max-width: 800px; /* Increased max width */
        height: auto; /* Allow natural height on mobile */
        min-height: 500px; /* Maintain minimum height */
    }
    
    .zoom-container {
        height: 500px; /* Fixed height for tablets */
    }
    
    .legend-container {
        height: 400px; /* Shorter legend on tablets */
    }
}

@media (max-width: 768px) {
    #nav-links {
        position: absolute;
        top: 70px;
        left: 0;
        right: 0;
        flex-direction: column;
        background-color: white;
        text-align: center;
        box-shadow: var(--shadow);
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.4s ease-out;
    }
    
    #nav-links.active { 
        max-height: 300px; 
        padding-bottom: 10px; 
    }
    
    #nav-links li { 
        padding: 10px 0; 
    }
    
    .hamburger { 
        display: block; 
    }
    
    .hamburger.active .hamburger-bar:nth-child(2) { 
        opacity: 0; 
    }
    
    .hamburger.active .hamburger-bar:nth-child(1) { 
        transform: translateY(8px) rotate(45deg); 
    }
    
    .hamburger.active .hamburger-bar:nth-child(3) { 
        transform: translateY(-8px) rotate(-45deg); 
    }
    
    section { 
        padding: 40px 15px; 
    }
    
    .hero-content h1 { 
        font-size: 2.2em; 
    }
    
    .hero-content p { 
        font-size: 1.1em; 
    }
    
    h2 { 
        font-size: 1.8em; 
    }
    
    #explore {
        padding: 60px 20px; /* Reduced padding on mobile */
    }
    
    .explore-container {
        gap: 25px;
    }
    
    .farm-map-container {
        min-width: 300px; /* Reduced for mobile */
    }
    
    .zoom-container {
        height: 400px; /* Smaller height for mobile */
        border-radius: 8px;
    }
    
    .legend-container {
        height: 350px; /* Shorter legend on mobile */
        padding: 20px;
        border-radius: 8px;
        max-height: 400px;
    }
    
    .zoom-btn,
    .fullscreen-btn {
        width: 40px; /* Back to original size on mobile */
        height: 40px;
        font-size: 18px;
    }
    
    .zoom-controls {
        top: 10px;
        right: 10px;
        gap: 5px;
    }
    
    .fullscreen-btn {
        top: 10px;
        left: 10px;
    }
    
    .dashboard-menu-grid, 
    .detail-grid { 
        grid-template-columns: 1fr; 
        gap: 20px; 
    }
    
    .dashboard-card, 
    .dashboard-menu-card { 
        padding: 20px; 
    }
    
    .data-item { 
        flex-direction: column; 
        align-items: flex-start; 
        gap: 5px; 
    }
    
    .data-value { 
        font-size: 1.1em; 
        text-align: left; 
    }
    
    .chart-container { 
        height: 60vh; 
        max-height: 400px; 
        padding: 15px; 
    }
    
    .fullscreen-content { 
        flex-direction: column; 
        width: 100%; 
        height: 100%; 
        padding: 15px; 
        box-sizing: border-box; 
    }
    
    .fullscreen-map { 
        margin-bottom: 15px; 
        flex: 1; 
        min-height: 0; 
    }
    
    .fullscreen-legend { 
        width: 100%; 
        max-height: 35vh; 
        flex-shrink: 0; 
    }
    
    .close-fullscreen { 
        top: 10px; 
        right: 10px; 
        width: 40px; 
        height: 40px; 
    }
    
    .modal-content { 
        width: 95%; 
        padding: 25px 20px; 
    }
    
    .detail-page-title { 
        font-size: 1.8em; 
    }
}