/* --- RESET & VARIABLES --- */
:root {
    --primary-green: #166534;
    --primary-green-light: #15803d;
    --primary-green-bg: #f0fdf4;
    --accent-yellow: #ca8a04;
    --accent-yellow-light: #eab308;
    --text-main: #111827;
    --text-muted: #4b5563;
    --bg-main: #f9fafb;
    --bg-white: #ffffff;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --border-radius: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--text-main);
    background-color: var(--bg-main);
    line-height: 1.5;
}

a {
    text-decoration: none;
    color: inherit;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
}

/* --- BUTTONS --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    font-weight: 500;
    border-radius: var(--border-radius);
    transition: all 0.2s ease;
    font-size: 0.95rem;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

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

.btn-outline {
    background-color: transparent;
    color: var(--primary-green);
    border: 1px solid var(--primary-green);
}
.btn-outline:hover {
    background-color: var(--primary-green-bg);
}

.btn-accent {
    background-color: var(--accent-yellow);
    color: white;
}
.btn-accent:hover {
    background-color: var(--accent-yellow-light);
}
.btn-accent:disabled {
    background-color: #cbd5e1;
    cursor: not-allowed;
}

/* --- NAVBAR --- */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: var(--primary-green);
    border-bottom: none;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    height: 65px;
}

.navbar-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100%;
}

.navbar-brand {
    display: flex;
    flex-direction: column;
}

.logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.5px;
}

.tagline {
    font-size: 0.75rem;
    color: #bbf7d0;
}

.nav-links {
    list-style: none;
    display: flex;
    gap: 2rem;
}

.nav-link {
    font-weight: 500;
    color: #bbf7d0;
    padding: 1.5rem 0;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.nav-link:hover {
    color: #ffffff;
}

.nav-link.active {
    color: #ffffff;
    border-bottom-color: var(--accent-yellow);
}

.hamburger-menu {
    display: none;
    color: #ffffff;
    background: transparent;
    border: none;
    cursor: pointer;
}

/* --- PAGES --- */
.page-container {
    display: none;
    padding-top: 65px; /* Sesuaikan persis dengan tinggi navbar */
    min-height: 100dvh;
    max-width: 1200px;
    margin: 0 auto;
}

.page-active {
    display: block !important;
}

/* --- DASHBOARD PAGE --- */
.hero-section {
    display: flex;
    align-items: center;
    padding: 4rem 1.5rem;
    gap: 2rem;
}

.hero-content {
    flex: 1;
}

.hero-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.2;
    margin-bottom: 1rem;
}

.hero-subtitle {
    font-size: 1.125rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.hero-actions {
    display: flex;
    gap: 1rem;
}

.hero-illustration {
    flex: 1;
    display: flex;
    justify-content: center;
}

.illustration-graphic {
    width: 100%;
    max-width: 400px;
    height: 300px;
    background: linear-gradient(135deg, var(--primary-green-bg), #dcfce7);
    border-radius: 24px;
    border: 1px solid #bbf7d0;
    overflow: hidden; /* Pastikan gambar tidak keluar dari sudut membulat */
}

.illustration-graphic img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.stats-section {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    padding: 0 1.5rem 4rem;
}

.stat-card {
    background-color: var(--bg-white);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    border-left: 4px solid var(--primary-green);
    box-shadow: var(--shadow-sm);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-green);
    margin-bottom: 0.25rem;
}

.stat-label {
    color: var(--text-muted);
    font-weight: 500;
}

.features-section {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    padding: 0 1.5rem 4rem;
}

.feature-card {
    background-color: var(--bg-white);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.feature-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.bg-green { background-color: var(--primary-green); }
.bg-yellow { background-color: var(--accent-yellow); }

.feature-card h3 {
    margin-bottom: 0.75rem;
    font-size: 1.25rem;
}

.feature-card p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

.feature-link {
    color: var(--primary-green);
    font-weight: 600;
    font-size: 0.95rem;
}

/* --- DETECT PAGE --- */
.detect-layout {
    display: flex;
    padding: 2rem 1.5rem;
    gap: 2rem;
}

.detect-left {
    flex: 0 0 60%;
}

.detect-right {
    flex: 0 0 calc(40% - 2rem);
}

.detect-tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.detect-tab {
    padding: 0.5rem 1.25rem;
    border-radius: 999px;
    font-weight: 500;
    background-color: var(--border-color);
    color: var(--text-muted);
}
.detect-tab.active {
    background-color: var(--primary-green);
    color: white;
}

.camera-container {
    background-color: var(--bg-white);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

.camera-zone {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    background-color: #000;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
}

.camera-zone video, .camera-zone img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-zone canvas {
    display: none;
}

.viewfinder-corners {
    position: absolute;
    top: 10%; left: 10%; right: 10%; bottom: 10%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    z-index: 10;
}
.viewfinder-corners::before, .viewfinder-corners::after {
    content: ''; position: absolute; width: 30px; height: 30px; border-color: var(--accent-yellow); border-style: solid;
}
.viewfinder-corners::before { top: -2px; left: -2px; border-width: 4px 0 0 4px; }
.viewfinder-corners::after { bottom: -2px; right: -2px; border-width: 0 4px 4px 0; }

.camera-label {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0,0,0,0.6);
    color: white;
    padding: 0.25rem 1rem;
    border-radius: 999px;
    font-size: 0.85rem;
    z-index: 10;
}

.camera-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(255,255,255,0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 20;
}

.spinner {
    width: 40px; height: 40px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-green);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

.camera-controls, .action-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 0.75rem;
}

.detect-error-box {
    margin-top: 0.75rem;
    padding: 0.75rem 1rem;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    color: #b91c1c;
    font-size: 0.875rem;
}

.upload-section {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}
.upload-label { font-size: 0.875rem; color: var(--text-muted); }
.btn-file-upload {
    padding: 0.5rem 1rem;
    background-color: var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    cursor: pointer;
    font-weight: 500;
}

.result-empty-state {
    height: 100%;
    min-height: 400px;
    background-color: var(--bg-white);
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: var(--text-muted);
}
.result-empty-state p { margin-top: 1rem; }

.result-panel {
    background-color: var(--bg-white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.result-annotated-img {
    width: 100%;
    height: 250px;
    object-fit: cover;
    background-color: #000;
}

.result-section {
    padding: 1.5rem 1.5rem 0;
}
.result-section h4 {
    font-size: 1rem;
    color: var(--text-main);
    margin-bottom: 0.75rem;
}

.detection-classes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.class-tag {
    background-color: var(--primary-green-bg);
    color: var(--primary-green);
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid #bbf7d0;
}

.recommendation-box {
    background-color: var(--bg-main);
    padding: 1rem;
    border-radius: var(--border-radius);
    font-size: 0.95rem;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

.recommended-products-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.mini-product {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.mini-product-img {
    height: 100px;
    background-color: var(--bg-main);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    padding: 0.5rem;
}
.mini-product-info {
    padding: 0.75rem;
}
.mini-product-name {
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mini-product-price {
    color: var(--primary-green);
    font-weight: 700;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}
.mini-product-link {
    font-size: 0.75rem;
    color: var(--primary-green);
    font-weight: 500;
}

.result-actions {
    padding: 1.5rem;
    display: flex;
    gap: 1rem;
}

/* --- CHAT PAGE --- */
.chat-layout {
    display: flex;
    height: calc(100dvh - 70px);
    overflow: hidden;
}

.chat-sidebar {
    width: 25%;
    border-right: 1px solid var(--border-color);
    background-color: var(--bg-white);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
}

.sidebar-header h2 { font-size: 1.5rem; color: var(--primary-green); }
.sidebar-header p { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 1.5rem; }

.sidebar-info-box {
    background-color: var(--primary-green-bg);
    border: 1px solid #bbf7d0;
    padding: 1rem;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    color: var(--primary-green);
    margin-bottom: 2rem;
}

.quick-questions {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    gap: 0.75rem;
    padding-bottom: 0.75rem;
}
.quick-questions::-webkit-scrollbar { display: none; }

.btn-quick-question {
    display: inline-block;
    width: max-content;
    white-space: nowrap;
    text-align: center;
    padding: 0.5rem 1rem;
    border: 1px solid var(--primary-green);
    border-radius: 999px;
    color: var(--primary-green);
    background: transparent;
    font-size: 0.85rem;
    transition: all 0.2s;
}
.btn-quick-question:hover {
    background-color: var(--primary-green-bg);
}

.sidebar-footer {
    margin-top: auto;
    font-size: 0.75rem;
    color: #9ca3af;
    text-align: center;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-main);
    min-height: 0;
    overflow: hidden;
}

.chat-header {
    height: 60px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-white);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    flex-shrink: 0;
}
.chat-header h3 { font-size: 1.1rem; }
.btn-clear-chat { color: var(--text-muted); font-size: 0.875rem; }
.btn-clear-chat:hover { color: #dc2626; }

.chat-messages {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.chat-message {
    display: flex;
    width: 100%;
}
.message-content {
    max-width: 75%;
    padding: 1rem 1.25rem;
    border-radius: var(--border-radius);
    font-size: 0.95rem;
    box-shadow: var(--shadow-sm);
}

.bot-message { justify-content: flex-start; }
.bot-message .message-content {
    background-color: var(--bg-white);
    border-left: 4px solid var(--primary-green);
    border-top: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.user-message { justify-content: flex-end; }
.user-message .message-content {
    background-color: #fef3c7;
    border-right: 4px solid var(--accent-yellow);
    border-top: 1px solid #fde68a;
    border-left: 1px solid #fde68a;
    border-bottom: 1px solid #fde68a;
}

.chat-input-area {
    padding: 1.5rem 2rem;
    background-color: var(--bg-white);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}
.typing-indicator {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    font-style: italic;
}
.input-wrapper {
    display: flex;
    gap: 1rem;
}
.input-wrapper textarea {
    flex: 1;
    resize: none;
    height: 50px;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-family: inherit;
    font-size: 0.95rem;
}
.input-wrapper textarea:focus {
    outline: none;
    border-color: var(--primary-green);
}

/* --- MARKET PAGE --- */
.market-header {
    padding: 3rem 1.5rem 1.5rem;
    text-align: center;
}
.market-header h2 { font-size: 2rem; color: var(--text-main); margin-bottom: 0.5rem; }
.market-header p { color: var(--text-muted); }

.market-filters {
    padding: 0 1.5rem 2rem;
}
.filter-scroll {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
}
.filter-scroll::-webkit-scrollbar { height: 4px; }
.filter-scroll::-webkit-scrollbar-thumb { background-color: var(--border-color); border-radius: 4px; }

.filter-pill {
    white-space: nowrap;
    padding: 0.5rem 1.25rem;
    background-color: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    font-size: 0.9rem;
    color: var(--text-muted);
}
.filter-pill.active {
    background-color: var(--accent-yellow);
    color: #ffffff;
    border-color: var(--accent-yellow);
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    padding: 0 1.5rem 4rem;
}

.product-card {
    background-color: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}
.product-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.product-card img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    background-color: var(--bg-main);
    border-bottom: 1px solid var(--border-color);
}
.product-img-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.875rem;
    text-align: center;
    padding: 1rem;
    background-color: #f3f4f6;
}

.product-info {
    padding: 1.25rem;
}
.product-category {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    background-color: #e5e7eb;
    color: #4b5563;
}
/* Category specific colors */
.tag-pupuk-organik-padat { background-color: #dcfce7; color: #166534; }
.tag-pupuk-organik-cair { background-color: #dbeafe; color: #1e40af; }
.tag-agen-hayati { background-color: #fef3c7; color: #92400e; }
.tag-biopestisida { background-color: #fee2e2; color: #991b1b; }
.tag-pembenah-tanah { background-color: #f3e8ff; color: #6b21a8; }
.tag-alat---kebutuhan { background-color: #f1f5f9; color: #334155; }

.product-name {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    line-height: 1.3;
    height: 2.6em; /* max 2 lines */
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.product-price {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--primary-green);
    margin-bottom: 1rem;
}

.product-card .btn {
    width: 100%;
}

/* --- RESPONSIVE BREAKPOINTS --- */
@media (max-width: 1024px) {
    .product-grid { grid-template-columns: repeat(3, 1fr); }
    .chat-sidebar { width: 30%; }
    .hero-section { padding: 3rem 1.5rem; }
    .hero-title { font-size: 2.25rem; }
}

@media (max-width: 768px) {
    /* Navbar */
    .nav-links {
        display: flex;
        flex-direction: column;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--primary-green);
        border-bottom: 1px solid #166534;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        padding: 0;
        z-index: 999;
        
        /* Animasi Slide */
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease-in-out, padding 0.3s ease-in-out;
    }
    .nav-links.nav-open {
        max-height: 500px;
        padding: 0.75rem 0;
    }
    .nav-links li {
        width: 100%;
    }
    .nav-links .nav-link {
        display: block;
        padding: 1rem 1.5rem;
        border-bottom: none;
        font-size: 1rem;
        color: #bbf7d0;
        transition: background 0.2s;
    }
    .nav-links .nav-link:hover,
    .nav-links .nav-link.active {
        background: #14532d;
        color: #ffffff;
        border-left: 4px solid var(--accent-yellow);
    }
    .hamburger-menu { display: flex; }
    /* Dashboard */
    .hero-section { flex-direction: column; text-align: center; padding-top: 1.5rem; }
    .hero-actions { justify-content: center; }
    .stats-section { grid-template-columns: 1fr; }
    .features-section { grid-template-columns: 1fr; }

    /* Detect */
    .detect-layout { flex-direction: column; gap: 1rem; padding: 1rem; }
    .detect-right { margin-top: 0; }
    .camera-zone { max-height: 60vh; }
    .camera-controls, .action-controls {
        flex-direction: column;
        align-items: stretch;
    }
    .upload-section { margin-left: 0; justify-content: center; margin-top: 1rem; }
    .btn { width: 100%; text-align: center; }

    /* Chat */
    .chat-layout { 
        flex-direction: column; 
        position: fixed;
        top: 65px; /* Sesuaikan dengan tinggi navbar */
        bottom: 0;
        left: 0;
        right: 0;
        height: auto;
        z-index: 10;
        background-color: var(--bg-main);
    }
    .chat-sidebar { display: none; }
    .chat-header { justify-content: space-between; padding: 0.75rem 1rem; border-bottom: none; }
    .chat-header h3 { display: block; font-size: 1.1rem; color: var(--primary-green); margin: 0; }
    .chat-messages { padding: 1rem; }
    .chat-input-area { padding: 1rem; }
    .input-wrapper { flex-direction: row; align-items: flex-end; }
    .input-wrapper textarea { min-height: 48px; max-height: 80px; }
    .input-wrapper button { width: max-content; padding: 0.75rem 1.25rem; }
    
    /* Market */
    .market-header { display: block; padding: 1rem 1rem 0.5rem; }
    .market-header h2 { font-size: 1.5rem; }
    .market-header p { font-size: 0.85rem; }
    .product-grid { grid-template-columns: repeat(2, 1fr); gap: 1rem; padding: 1rem; }
    .filter-scroll { padding: 0 1rem 1rem; }
}

@media (max-width: 480px) {
    .product-grid { grid-template-columns: 1fr; }
    .hero-title { font-size: 1.75rem; }
    .hero-actions { flex-direction: column; }
    .result-actions { flex-direction: column; }
}

