/* style.css - การออกแบบหน้าจอพรีเมียม สไตล์ Modern Dark Mode สวนทุเรียน */

:root {
    --bg-primary: #090d16;
    --bg-secondary: #111827;
    --card-bg: rgba(22, 28, 45, 0.7);
    --card-border: rgba(255, 255, 255, 0.06);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --primary: #10b981; /* Emerald Green */
    --primary-hover: #059669;
    --primary-glow: rgba(16, 185, 129, 0.15);
    --accent: #f59e0b; /* Durian Gold */
    --accent-hover: #d97706;
    --accent-glow: rgba(245, 158, 11, 0.15);
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #10b981;
    --info: #3b82f6;
    --sidebar-width: 260px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --font-sans: 'Outfit', 'Sarabun', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body {
    background-color: var(--bg-primary);
    background-image: 
        radial-gradient(at 0% 0%, rgba(16, 185, 129, 0.05) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(245, 158, 11, 0.05) 0px, transparent 50%);
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
}

/* Scrollbar Design */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* Sidebar Styling */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--card-border);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: var(--transition);
}

.sidebar-brand {
    padding: 24px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--card-border);
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.brand-name {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: linear-gradient(to right, #ffffff, #dcdcdc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-sub {
    font-size: 0.75rem;
    color: var(--primary);
    display: block;
    font-weight: 500;
}

.sidebar-menu {
    list-style: none;
    padding: 20px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-grow: 1;
    overflow-y: auto;
}

.sidebar-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 500;
    transition: var(--transition);
}

.sidebar-item a:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.03);
}

.sidebar-item.active a {
    color: var(--text-primary);
    background: linear-gradient(to right, rgba(16, 185, 129, 0.15), rgba(16, 185, 129, 0.02));
    border-left: 3px solid var(--primary);
    box-shadow: inset 0 0 10px rgba(16, 185, 129, 0.05);
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--card-border);
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}

/* Main Content Area */
.main-content {
    margin-left: var(--sidebar-width);
    flex-grow: 1;
    padding: 30px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    width: calc(100% - var(--sidebar-width));
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--card-border);
}

.header-title h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.header-title p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Garden Filter Selector */
.garden-selector-container {
    display: flex;
    background: var(--bg-secondary);
    border: 1px solid var(--card-border);
    padding: 4px;
    border-radius: 12px;
}

.garden-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 18px;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.garden-btn:hover {
    color: var(--text-primary);
}

.garden-btn.active {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 4px 10px rgba(16, 185, 129, 0.2);
}

/* Tab Content Visibility */
.tab-content {
    display: none;
    animation: fadeIn 0.4s ease;
}

.tab-content.active {
    display: block;
}

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

/* Layout Grids */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.dashboard-lg-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

/* Cards Design */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 24px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.card:hover {
    border-color: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: transparent;
    transition: var(--transition);
}

.card.primary-accent::before { background: var(--primary); }
.card.gold-accent::before { background: var(--accent); }
.card.danger-accent::before { background: var(--danger); }

/* Card Metrics */
.metric-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

.metric-value {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 6px;
    letter-spacing: -0.5px;
}

.metric-trend {
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

.metric-trend.up { color: var(--success); }
.metric-trend.down { color: var(--danger); }
.metric-trend.neutral { color: var(--text-muted); }

.icon-wrapper {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.card.primary-accent .icon-wrapper { background: rgba(16, 185, 129, 0.1); color: var(--primary); }
.card.gold-accent .icon-wrapper { background: rgba(245, 158, 11, 0.1); color: var(--accent); }
.card.danger-accent .icon-wrapper { background: rgba(239, 68, 68, 0.1); color: var(--danger); }
.icon-wrapper.blue { background: rgba(59, 130, 246, 0.1); color: var(--info); }

/* Section Header inside Cards */
.card-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
}

.card-title-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Forms & Input Elements */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

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

.form-group.full-width {
    grid-column: 1 / -1;
}

label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
    background-color: rgba(17, 24, 39, 0.6);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    transition: var(--transition);
    width: 100%;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
    background-color: rgba(17, 24, 39, 0.9);
}

/* Multi-select Pesticide Field */
.multi-select-pesticides {
    border: 1px solid var(--card-border);
    border-radius: 8px;
    max-height: 150px;
    overflow-y: auto;
    background-color: rgba(17, 24, 39, 0.6);
    padding: 8px;
}

.pesticide-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: var(--transition);
}

.pesticide-option:hover {
    background-color: rgba(255, 255, 255, 0.04);
}

.pesticide-option input[type="checkbox"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 8px;
    padding: 10px 18px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: none;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}
.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.3);
}

.btn-accent {
    background-color: var(--accent);
    color: white;
}
.btn-accent:hover {
    background-color: var(--accent-hover);
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.3);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    border: 1px solid var(--card-border);
}
.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

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

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
    border-radius: 6px;
}

/* Tables Styling */
.table-container {
    overflow-x: auto;
    margin-top: 10px;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.9rem;
}

th {
    border-bottom: 2px solid var(--card-border);
    padding: 12px 16px;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--card-border);
    color: var(--text-primary);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: rgba(255, 255, 255, 0.01);
}

/* Badge Badges */
.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-primary { background: rgba(16, 185, 129, 0.15); color: var(--primary); }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: var(--accent); }
.badge-danger { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.badge-info { background: rgba(59, 130, 246, 0.15); color: var(--info); }
.badge-neutral { background: rgba(255, 255, 255, 0.06); color: var(--text-secondary); }

/* Quick Action Widgets */
.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.gap-10 { gap: 10px; }
.gap-15 { gap: 15px; }

/* Timeline tracking for Batch stages */
.batch-timeline-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.batch-card {
    background: rgba(17, 24, 39, 0.4);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
}

.batch-meta {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    padding-bottom: 10px;
}

.batch-title {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--accent);
}

.timeline-steps {
    display: flex;
    justify-content: space-between;
    position: relative;
    margin: 25px 0 15px 0;
}

.timeline-steps::before {
    content: '';
    position: absolute;
    top: 14px;
    left: 4%;
    right: 4%;
    height: 3px;
    background: rgba(255, 255, 255, 0.08);
    z-index: 1;
}

.timeline-progress {
    position: absolute;
    top: 14px;
    left: 4%;
    height: 3px;
    background: linear-gradient(to right, var(--primary), var(--accent));
    z-index: 2;
    transition: var(--transition);
}

.step-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 3;
    position: relative;
    width: 30%;
}

.node-dot {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-color: var(--bg-secondary);
    border: 3px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    transition: var(--transition);
}

.step-node.completed .node-dot {
    background-color: var(--primary);
    border-color: rgba(16, 185, 129, 0.3);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
    color: white;
}

.step-node.active .node-dot {
    background-color: var(--accent);
    border-color: rgba(245, 158, 11, 0.3);
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.5);
    color: white;
}

.node-label {
    margin-top: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-align: center;
}

.step-node.completed .node-label,
.step-node.active .node-label {
    color: var(--text-primary);
}

.node-date {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.batch-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-top: 15px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
    padding: 12px;
}

.batch-stat-box {
    text-align: center;
    border-right: 1px solid rgba(255, 255, 255, 0.04);
}

.batch-stat-box:last-child {
    border-right: none;
}

.batch-stat-lbl {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.batch-stat-val {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.batch-stat-val span {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: normal;
    margin-left: 2px;
}

/* Articles and Knowledge Base layout */
.article-search-bar {
    margin-bottom: 20px;
    display: flex;
    gap: 10px;
}

.articles-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.article-card {
    cursor: pointer;
}

.article-tags {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.article-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
    line-height: 1.4;
}

.article-preview {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.article-footer {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Gemini Assistant Chat Panel Layout */
.gemini-assistant {
    display: grid;
    grid-template-columns: 3fr 2fr;
    gap: 24px;
    min-height: 500px;
}

.chat-container {
    background: rgba(17, 24, 39, 0.4);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    height: 550px;
}

.chat-header {
    padding: 16px;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--info), var(--primary));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.chat-bubble.user {
    background-color: var(--primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.chat-bubble.ai {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    align-self: flex-start;
    border-bottom-left-radius: 2px;
    border: 1px solid var(--card-border);
}

.chat-bubble p {
    margin-bottom: 10px;
}
.chat-bubble p:last-child {
    margin-bottom: 0;
}
.chat-bubble code {
    background-color: rgba(255, 255, 255, 0.1);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.85rem;
}
.chat-bubble ul, .chat-bubble ol {
    margin-left: 20px;
    margin-bottom: 8px;
}
.chat-bubble li {
    margin-bottom: 4px;
}

.chat-bubble.typing {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 12px 20px;
}

.chat-bubble.typing span {
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    display: inline-block;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.chat-bubble.typing span:nth-child(1) { animation-delay: -0.32s; }
.chat-bubble.typing span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

.chat-input-area {
    padding: 16px;
    border-top: 1px solid var(--card-border);
    display: flex;
    gap: 10px;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 200;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 24px;
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    transform: translateY(-20px);
    transition: transform 0.3s ease;
}

.modal.active .modal-content {
    transform: translateY(0);
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--card-border);
}

/* Interactive Calculator Quick Widget */
.calc-quick-widget {
    background: rgba(245, 158, 11, 0.05);
    border: 1px solid rgba(245, 158, 11, 0.15);
    border-radius: 12px;
    padding: 16px;
    margin-top: 15px;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .dashboard-lg-grid {
        grid-template-columns: 1fr;
    }
    .gemini-assistant {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    body {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        border-right: none;
        border-bottom: 1px solid var(--card-border);
    }
    .sidebar-menu {
        flex-direction: row;
        overflow-x: auto;
        padding: 10px;
        white-space: nowrap;
    }
    .sidebar-footer {
        display: none;
    }
    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 15px;
    }
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .articles-grid {
        grid-template-columns: 1fr;
    }
    .timeline-steps {
        flex-direction: column;
        gap: 20px;
        align-items: flex-start;
        padding-left: 20px;
    }
    .timeline-steps::before {
        left: 24px;
        top: 0;
        bottom: 0;
        width: 3px;
        height: auto;
    }
    .timeline-progress {
        left: 24px;
        top: 0;
        width: 3px;
        height: 60%;
    }
    .step-node {
        flex-direction: row;
        width: 100%;
        gap: 15px;
        align-items: center;
    }
    .node-label {
        margin-top: 0;
        text-align: left;
    }
    .batch-stats-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .batch-stat-box {
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.04);
        padding-bottom: 8px;
        text-align: left;
        display: flex;
        justify-content: space-between;
    }
    .batch-stat-box:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }
}
