/* style.css - ระบบแดชบอร์ดสถิติยางพารา */
/* ธีมรักธรรมชาติ กระดาษ Green Read ถนอมสายตา */

:root {
    /* แสงสว่าง (โหมดกระดาษ Green Read) */
    --bg-primary: #f2f7f1; /* สีครีมอุ่นอมเขียวอ่อน */
    --bg-card: #fdfefe; /* สีเนื้อกระดาษขาวนวล */
    --bg-sidebar: #19271a; /* เขียวป่าไม้เข้มจัด */
    
    --text-primary: #172418; /* ดำปนเขียวเข้มมาก */
    --text-secondary: #485c49; /* เขียวหม่นถนอมสายตา */
    --text-on-sidebar: #e8efe9; /* ครีมอ่อน */
    
    --border-color: #dee6df; /* ขอบครีมเทาบางๆ */
    --accent-green: #2a6839; /* เขียวใบไม้ธรรมชาต */
    --accent-green-light: #e5f2e8; /* เขียวอ่อนพาสเทล */
    --accent-yellow: #bd872b; /* เหลืองมัสตาร์ดอบอุ่น */
    --accent-yellow-light: #fdf5e6;
    
    --shadow-sm: 0 2px 8px rgba(25, 39, 26, 0.04);
    --shadow-md: 0 6px 16px rgba(25, 39, 26, 0.06);
    --shadow-lg: 0 12px 28px rgba(25, 39, 26, 0.09);
    
    --font-thai: 'Sarabun', sans-serif;
    --font-eng: 'Outfit', sans-serif;
    --transition: all 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

/* โหมดถนอมสายตาในเวลากลางคืน (โหมดมืด) */
body.dark-mode {
    --bg-primary: #0f1510; /* เขียวดำมืดสนิท */
    --bg-card: #162017; /* เขียวโอลีฟเข้ม */
    --bg-sidebar: #090c09; /* ดำสนิท */
    
    --text-primary: #e5ede6; /* ขาวนวล */
    --text-secondary: #90a592; /* เขียวเทาอ่อน */
    --text-on-sidebar: #e5ede6;
    
    --border-color: #243326; /* ขอบเขียวเข้ม */
    --accent-green: #5eb573; /* เขียวใบไม้สว่าง */
    --accent-green-light: #1c2b1e;
    --accent-yellow: #dfa845; /* เหลืองทองอ่อน */
    --accent-yellow-light: #2b2315;
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.4);
}

/* ล้างค่าเริ่มต้น */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-thai);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    transition: var(--transition);
    overflow-x: hidden;
}

/* โครงสร้างคอนเทนเนอร์แอป */
.app-container {
    display: flex;
    width: 100vw;
    min-height: 100vh;
}

/* ==================== 1. SIDEBAR (เมนูด้านซ้าย) ==================== */
.sidebar {
    width: 280px;
    background-color: var(--bg-sidebar);
    color: var(--text-on-sidebar);
    display: flex;
    flex-direction: column;
    padding: 24px;
    flex-shrink: 0;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    z-index: 10;
    transition: var(--transition);
}

.sidebar-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 14px;
    padding-bottom: 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 24px;
}

.sidebar-header .logo {
    width: 130px;
    height: 130px;
    object-fit: contain;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.25));
    transition: var(--transition);
}

.sidebar-header .logo:hover {
    transform: scale(1.05);
    filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.35));
}

.brand-title h2 {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    line-height: 1.4;
}

.brand-title p {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 2px;
}

.sidebar-nav {
    flex-grow: 1;
}

.sidebar-nav ul {
    list-style: none;
}

.nav-section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.5;
    margin: 24px 0 8px 12px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    margin-bottom: 6px;
    transition: var(--transition);
    color: rgba(255, 255, 255, 0.75);
}

.nav-item i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: #fff;
    transform: translateX(4px);
}

.nav-item.active {
    background-color: var(--accent-green);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(42, 104, 57, 0.3);
}

/* สีเฉพาะสำหรับสัญลักษณ์จังหวัด */
.text-ut { color: #88d49e; }
.text-ns { color: #f0a202; }
.text-sp { color: #f18f01; }
.text-cn { color: #00b4d8; }

.sidebar-footer {
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background-color: transparent;
    color: var(--text-on-sidebar);
    cursor: pointer;
    font-family: var(--font-thai);
    font-size: 0.85rem;
    transition: var(--transition);
}

.btn-theme-toggle:hover {
    background-color: rgba(255, 255, 255, 0.08);
    border-color: #fff;
}

.sys-version {
    text-align: center;
    font-size: 0.7rem;
    opacity: 0.4;
    margin-top: 14px;
}

/* ==================== 2. MAIN CONTENT (พื้นที่แสดงเนื้อหาหลัก) ==================== */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    padding: 30px;
}

/* Top Header Bar */
.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 1.5px solid var(--border-color);
    margin-bottom: 30px;
    transition: var(--transition);
}

.header-title h1 {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--accent-green);
}

.header-title .subtitle {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.header-controls {
    display: flex;
    gap: 16px;
}

.selector-container {
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: var(--bg-card);
    padding: 8px 16px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.selector-container label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.selector-container select {
    border: none;
    outline: none;
    font-family: var(--font-thai);
    font-weight: 600;
    font-size: 0.95rem;
    background-color: transparent;
    color: var(--text-primary);
    cursor: pointer;
    padding-right: 8px;
}

.content-body {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

/* แจ้งเตือน Warning */
.alert-warning {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 16px;
    background-color: var(--accent-yellow-light);
    border-left: 4px solid var(--accent-yellow);
    border-radius: 8px;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.alert-warning i {
    font-size: 1.3rem;
    color: var(--accent-yellow);
    margin-top: 2px;
}

.alert-warning strong {
    display: block;
    font-size: 0.95rem;
    margin-bottom: 2px;
}

.alert-warning p {
    font-size: 0.85rem;
    opacity: 0.85;
}

.hidden {
    display: none !important;
}

/* ==================== 3. KPI CARDS (บัตรข้อมูลหลัก) ==================== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
}

.kpi-card {
    background-color: var(--bg-card);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 18px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    cursor: default;
}

.kpi-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent-green);
}

.kpi-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.icon-farmers { background-color: #e3f2fd; color: #1e88e5; }
.icon-area { background-color: #e8f5e9; color: #2e7d32; }
.icon-tapped { background-color: #e0f2f1; color: #00695c; }
.icon-tappers { background-color: #efebe9; color: #4e342e; }
.icon-institutes { background-color: #f3e5f5; color: #6a1b9a; }
.icon-operators { background-color: #fff8e1; color: #ff8f00; }

body.dark-mode .icon-farmers { background-color: #1a2a3a; color: #64b5f6; }
body.dark-mode .icon-area { background-color: #1b2e1c; color: #81c784; }
body.dark-mode .icon-tapped { background-color: #152d2a; color: #4db6ac; }
body.dark-mode .icon-tappers { background-color: #2b2220; color: #d7ccc8; }
body.dark-mode .icon-institutes { background-color: #2a1f30; color: #ba68c8; }
body.dark-mode .icon-operators { background-color: #2f2718; color: #ffd54f; }

.kpi-details h3 {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.kpi-value {
    font-family: var(--font-eng);
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1;
}

.kpi-value .unit {
    font-family: var(--font-thai);
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--text-secondary);
    margin-left: 4px;
}

.kpi-trend {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 6px;
    opacity: 0.8;
}

/* ==================== 4. CHARTS SECTION (พื้นที่จัดเรียงกราฟ) ==================== */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

.card-shadow {
    background-color: var(--bg-card);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.chart-container {
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.chart-container.full-width {
    grid-column: span 2;
}

.chart-header {
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.chart-header h4 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chart-body {
    position: relative;
    height: 280px;
    width: 100%;
}

.chart-body-large {
    position: relative;
    height: 320px;
    width: 100%;
}

/* ==================== 5. TABLES SECTION (ตารางรายละเอียด) ==================== */
.table-section {
    display: flex;
    flex-direction: column;
    padding: 24px;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.table-header-title h4 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.table-header-title p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.table-controls {
    display: flex;
    gap: 12px;
    align-items: center;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-box i {
    position: absolute;
    left: 12px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.search-box input {
    font-family: var(--font-thai);
    padding: 8px 12px 8px 34px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    outline: none;
    font-size: 0.9rem;
    width: 220px;
    transition: var(--transition);
}

.search-box input:focus {
    border-color: var(--accent-green);
    box-shadow: 0 0 0 3px rgba(42, 104, 57, 0.1);
}

.btn-secondary {
    font-family: var(--font-thai);
    background-color: var(--accent-green-light);
    color: var(--accent-green);
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
}

.btn-secondary:hover {
    filter: brightness(0.96);
}

.table-container {
    overflow-x: auto;
    width: 100%;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.data-table th {
    background-color: var(--bg-primary);
    color: var(--text-secondary);
    font-weight: 600;
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1.5px solid var(--border-color);
    font-size: 0.85rem;
    letter-spacing: 0.2px;
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition);
}

.data-table tr.district-row {
    cursor: pointer;
    font-weight: 500;
}

.data-table tr.district-row:hover {
    background-color: var(--bg-primary);
}

.data-table tr.subdistrict-row {
    background-color: rgba(250, 252, 250, 0.6);
    font-size: 0.9rem;
}

body.dark-mode .data-table tr.subdistrict-row {
    background-color: rgba(20, 28, 21, 0.3);
}

.data-table tr.subdistrict-row td:first-child {
    padding-left: 38px;
    position: relative;
}

.data-table tr.subdistrict-row td:first-child::before {
    content: "└ ";
    color: var(--text-secondary);
    position: absolute;
    left: 20px;
    opacity: 0.6;
}

.data-table tr.subdistrict-row.collapsed {
    display: none;
}

/* คอลัมน์ตัวเลขให้ใช้ฟอนต์ Outfit และจัดขวา */
.col-num {
    font-family: var(--font-eng);
    text-align: right !important;
}

.bold {
    font-weight: 700;
}

/* ตัวนำสายตาแสดงขยายได้ */
.expand-icon {
    display: inline-block;
    width: 16px;
    margin-right: 6px;
    transition: var(--transition);
    color: var(--text-secondary);
}

.expanded .expand-icon {
    transform: rotate(90deg);
    color: var(--accent-green);
}

/* ==================== 6. FOOTER ==================== */
.app-footer {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
    opacity: 0.8;
}

/* ==================== 7. RESPONSIVE DESIGN ==================== */
@media (max-width: 1024px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
    .chart-container.full-width {
        grid-column: span 1;
    }
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        height: auto;
        padding: 16px;
    }
    .sidebar-header {
        margin-bottom: 16px;
        padding-bottom: 16px;
    }
    .main-content {
        padding: 16px;
    }
    .top-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }
    .table-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .search-box input {
        width: 100%;
    }
}
