:root {
    --primary-blue: #4da4ff;
    --active-blue: #1d72db;
    --card-bg: #ffffff;
    --main-bg: #edf6f9;
    --btn-blue: #3b82f6;
    --btn-hover: #1d4ed8;

    --sky-gradient-vertical: linear-gradient(180deg, #57a6ff 0%, #b3dcff 50%, #e8f4ff 100%);
    --sky-gradient-horizontal: linear-gradient(135deg, #57a6ff 0%, #90caf9 50%, #e8f4ff 100%);
}

body {
    font-family: 'Prompt', 'Kanit', sans-serif;
    margin: 0;
    background-color: var(--main-bg);
    color: #333333;
    overflow: hidden;
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 250px;
    height: 100vh;
    background: var(--sky-gradient-vertical);
    color: #1e3a8a;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    left: 0;
    overflow-y: auto;
    box-sizing: border-box;
}

.brand {
    padding: 20px;
    font-size: 1.4rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #0f172a;
}

.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-menu li a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    color: #1e3a8a;
    font-weight: 500;
    text-decoration: none;
    transition: 0.3s;
}

.sidebar-menu li.active a, .sidebar-menu li a:hover {
    background-color: rgba(255, 255, 255, 0.6);
    color: #0284c7;
    font-weight: bold;
    border-radius: 0 25px 25px 0;
    backdrop-filter: blur(4px);
}

.user-profile-bottom {
    padding: 15px 20px;
    background-color: rgba(255, 255, 255, 0.4);
    display: flex;
    align-items: center;
    gap: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.5);
}

.user-avatar {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background-color: #0284c7;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* Main Content */
.main-content {
    flex: 1;
    height: 100vh;
    overflow-y: auto;
    padding: 30px;
    box-sizing: border-box;
}

/* ==========================================
   หัวข้อนอกกล่อง (ปรับให้เปลี่ยนสีอัตโนมัติ อ่านง่ายทุกธีม)
   ========================================== */
.page-title {
    font-size: 1.5rem;
    font-weight: bold;
    margin-bottom: 25px;
    color: var(--primary-blue, #1d72db) !important;
    text-shadow: none !important;
}

/* หัวข้อทั่วไปนอกกล่อง เช่น "ควบคุมอุปกรณ์" */
.main-content > h1, .main-content > h2, .main-content > h3, 
.main-content > h4, .main-content > h5, .main-content > h6 {
    color: var(--primary-blue, #1d72db) !important;
    margin-top: 25px;
    margin-bottom: 15px;
    text-shadow: none !important;
}

/* Top Banner (ปรับให้เป็นกล่องสีขาวเหมือน Card วงแดง) */
.top-banner {
    background: #ffffff !important;
    color: #1e293b !important;
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 25px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.04) !important;
}

/* บังคับตัวอักษรและไอคอนข้างใน Top Banner ให้เป็นสีเข้มคมชัด */
.top-banner h1, .top-banner h2, .top-banner h3, .top-banner h4, 
.top-banner p, .top-banner span, .top-banner i {
    color: #1e293b !important;
    text-shadow: none !important;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

/* ==========================================
   Card Component Styles (บังคับสีเข้มและลบเงา)
   ========================================== */
.card {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.04);
    color: #1e293b !important;
}

/* บังคับหัวข้อ และองค์ประกอบภายใน Card ทั้งหมดให้เป็นสีเข้มคมชัด */
.card h1, .card h2, .card h3, .card h4, .card h5, .card h6,
.card p, .card span, .card label, .card div, .card i {
    color: #1e293b !important;
    text-shadow: none !important;
    -webkit-text-stroke: 0px !important;
}

.card .val {
    font-size: 1.8rem;
    font-weight: bold;
    margin-top: 10px;
    color: #0284c7 !important;
}

/* Forms & Buttons */
.btn-primary, button[type="submit"] {
    background-color: var(--btn-blue);
    color: #ffffff !important;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    width: 100%;
    text-shadow: none !important;
    -webkit-text-stroke: 0px !important;
}

.btn-primary:hover, button[type="submit"]:hover {
    background-color: var(--btn-hover);
}

.btn-primary *, button[type="submit"] * {
    color: #ffffff !important;
    text-shadow: none !important;
}

/* ลิงก์ภายในปุ่ม เช่น ปุ่ม Google Maps */
.card a.btn-primary, .card a[href*="maps"] {
    color: #ffffff !important;
    text-shadow: none !important;
}

.btn-outline {
    border: 1px solid var(--btn-blue);
    color: var(--btn-blue) !important;
    background: transparent;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    width: 100%;
    text-shadow: none !important;
}

.form-control {
    width: 100%;
    padding: 10px;
    margin: 8px 0 16px 0;
    border: 1px solid #ccc;
    border-radius: 8px;
    box-sizing: border-box;
    color: #1e293b !important;
    background-color: #ffffff;
}

/* Tables */
.table-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #eee;
    color: #1e293b !important;
}

/* ==========================================
   Chart Wrapper & Responsive Styles
   ========================================== */
.chart-container {
    position: relative;
    width: 100%;
    height: 260px;
    margin-top: 10px;
}

.chart-container.large {
    height: 420px;
}

.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Responsive (<= 768px) */
@media (max-width: 768px) {
    body, html {
        overflow-x: hidden !important;
        width: 100% !important;
    }

    .main-content {
        width: 100% !important;
        padding: 12px !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }

    .top-charts-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 15px !important;
    }

    .dashboard-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 10px;
    }

    .dashboard-header select {
        width: 100% !important;
    }

    .chart-container.large {
        height: 480px !important;
    }
}

/* ==========================================
   Profile Page Layout Adjustments
   ========================================== */
.profile-layout-wrapper {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    align-items: flex-start;
    width: 100%;
}

.profile-user-card {
    flex: 1 1 100%;
    width: 100%;
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    box-sizing: border-box;
}

.profile-admin-side {
    flex: 55;
    min-width: 340px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

@media screen and (min-width: 769px) {
    .profile-layout-wrapper:has(.profile-admin-side) .profile-user-card {
        flex: 45;
        min-width: 320px;
    }
}

@media screen and (max-width: 768px) {
    .profile-layout-wrapper {
        flex-direction: column !important;
        gap: 15px !important;
    }

    .profile-user-card,
    .profile-admin-side {
        width: 100% !important;
        flex: 1 1 100% !important;
        min-width: 100% !important;
        padding: 18px !important;
    }
}

