/* === Base Styles === */
body {
    font-family: 'Poppins', Arial, sans-serif;
    margin: 0;
    background: #f7f9fc;
    color: #333;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    line-height: 1.4;
}

/* === Container === */
.container {
    width: 95%;
    margin: 2rem auto;
    padding: 1rem;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    flex-grow: 1;
    animation: fadeIn 0.5s ease-in-out;
}

h2 {
    font-size: 1.2rem;       /* ขนาดรองลงมา */
    font-weight: 500;
    margin: 0.5em 0;
    line-height: 1.3;
}

/* === Header === */
.main-header {
    background: #2c3e50;
    color: #fff;
    padding: 0.1rem 5%; /* เปลี่ยนจาก 1.2rem เป็น 0.4rem (บางลงอีก) */
    text-align: center;
    font-size: 1.1rem; /* อาจจะลดขนาดตัวอักษรลงเป็น 1.4rem ด้วยก็ได้ถ้าต้องการ */
    font-weight: 600;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
/* === Home Page Specific Styles === */
.home-container {
    text-align: center;
    padding: 2rem 1rem;
}

/* =========================================
   1. ส่วน NAVIGATION (เมนูบาร์แบบใหม่)
   (เอาไปแทนที่ .main-nav เดิม)
   ========================================= */
.main-nav {
    background: #34495e;
    padding: 0;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    position: sticky; top: 0; z-index: 1000;
}
.main-nav ul {
    list-style: none;
    margin: 0;
    padding: 10px 2%; /* ลด padding ด้านข้างลงนิดนึงกันล้น */
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap; /* รองรับมือถือ */
}
.main-nav li { margin: 0; }
.main-nav a {
    display: flex;
    align-items: center;
    gap: 8px; /* ระยะห่างไอคอนกับตัวหนังสือ */
    padding: 10px 15px;
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    color: #ecf0f1;
    border-radius: 6px;
    transition: all 0.2s;
    white-space: nowrap; /* ห้ามตัดคำ */
}
.main-nav a:hover,
.main-nav a.active {
    background: #2980b9;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
.main-nav a i {
    font-size: 1.1em;
}

/* === Cards === */
.card-menu {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1.5rem;
    margin-top: 2rem;
}
.card {
    background: #fff;
    border-radius: 12px;
    padding: 1.5rem;
    width: 260px;
    text-align: center;
    color: inherit;
    text-decoration: none;
    box-shadow: 0 3px 8px rgba(0,0,0,0.08);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.card:hover {
    transform: translateY(-6px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}
.card.disabled {
    background: #f1f1f1;
    color: #aaa;
    pointer-events: none;
}
.card h3 {
    margin: 0 0 0.5rem;
    color: #2980b9;
}

/* === Footer === */
.main-footer {
    background: #2c3e50;
    color: #ecf0f1;
    text-align: center;
    padding: 1rem;
    margin-top: auto;
    font-size: 0.9rem;
}

/*เมนูค้นหาใน Network*/
/* 3. ทำให้ตัว search-box ขยาย 100% ตามขนาดของ parent */
.search-box {
    display: flex;
    align-items: center;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 0 10px;
    height: 40px;          /* สูงเท่ากับ select และปุ่ม */
    background: #fff;
    flex: 1;               /* ให้กินพื้นที่ที่เหลือ */
    box-sizing: border-box;
}
.search-box:focus-within {
    border: 1px solid #2980b9;
    box-shadow: 0 0 6px rgba(41, 128, 185, 0.3);
}
.search-box i {
    color: #888;
    margin-right: 8px;
    font-size: 14px;
}
.search-box input {
    border: none;
    outline: none;
    font-size: 14px;
    flex: 1;
    height: 100%;          /* <<< ทำให้ input สูงเท่ากับ parent */
    line-height: 1;        /* <<< ปรับ baseline */
    background: transparent;
}

.search-box input::placeholder {
    color: #999;
    font-size: 0.9rem;
}


#summary-container {
    margin-bottom: 0.1rem; /* ปรับ margin ล่าง */
    font-size: 0.95rem;
    font-weight: 500;
    padding: 8px 15px;
    display: inline-block;
    background: #e9ecef;
    border-radius: 6px;
    border: 1px solid #dee2e6;
}
#summary-container #total-records {
    color: #2980b9;
    font-weight: 600;
}
#summary-container span {
    color: #2980b9;
    font-weight: 600;
}


/* === Table === */
.table-container {
    width: 100%;
    overflow-x: auto;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    background: #fff;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
thead tr {
    background: #f4f6f8;
    color: #555;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid #e0e0e0;
}
th, td {
    padding: 12px 15px;
    vertical-align: middle;
}
tbody tr {
    border-bottom: 1px solid #f1f1f1;
    transition: background 0.2s;
}
tbody tr:nth-of-type(even) {
    background: #fafafa;
}
tbody tr:hover {
    background: #f1f5f9;
}
tbody tr:last-of-type {
    border-bottom: none;
}

/* === Status Cells === */
.status-cell {
    padding: 4px 10px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #fff;
}
.status-active, .status-online, .status-on { background: #27ae60; }
.status-inactive, .status-offline, .status-off, .status-down { background: #e74c3c; }
.status-standby, .status-pending { background: #f1c40f; color: #333; }

/* === Animations === */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Row Highlighting Classes --- */

/* สีเขียวอ่อนสำหรับ Network Address */
tr.highlight-green {
    background-color: #f0fff4 !important; /* <== เพิ่ม !important */
}
tr.highlight-green:hover {
    background-color: #d4edda !important; /* <== เพิ่มที่ hover ด้วยก็ดี */
}

/* สีเหลืองอ่อนสำหรับ Broadcast Address */
tr.highlight-yellow {
    background-color: #fffbe6 !important; /* <== เพิ่ม !important */
}
tr.highlight-yellow:hover {
    background-color: #fff3cd !important;
}

/* สีฟ้าอ่อนสำหรับ Router */
tr.highlight-blue {
    background-color: #e6f7ff !important; /* <== เพิ่ม !important */
}
tr.highlight-blue:hover {
    background-color: #d1ecf9 !important;
}


/* 1. ปรับคอนเทนเนอร์หลัก */
.search-export-container {
    display: flex;
    align-items: center;   /* ให้อยู่กลางแนวตั้ง */
    gap: 10px;
    width: 100%;
}

/* Select & Button */
.control-element {
    padding: 0 12px;          /* เอา padding แนวตั้งออก */
    height: 40px;
    display: flex;
    align-items: center;      /* ให้ข้อความอยู่กลาง */
}

/* 2. ทำให้คอนเทนเนอร์ของช่องค้นหาขยายเต็มพื้นที่ */
.search-container {
    flex-grow: 1; /* <<< หัวใจของการแก้ไข: ให้ element นี้ขยายเพื่อเติมพื้นที่ว่าง */
}
/* Filter Dropdown */

#router-filter {
    display: flex;
    align-items: center;
    height: 40px;          /* เท่ากันเป๊ะ */
    font-size: 14px;
    padding: 0 12px;
    box-sizing: border-box;
}


.filter-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- Normalize search/filter/export ให้เท่ากัน --- */
.search-export-container > * {
    height: 40px;              /* ให้เท่ากันหมด */
    font-size: 14px;
    box-sizing: border-box;
    display: flex;
    align-items: center;       /* ข้อความอยู่กลางแนวตั้ง */
}

.search-export-container > * {
    height: 40px;              /* ให้เท่ากันหมด */
    font-size: 14px;
    box-sizing: border-box;
    display: flex;
    align-items: center;       /* ข้อความอยู่กลางแนวตั้ง */
}

#export-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid #28a745;
    border-radius: 4px;
    background: #28a745;
    color: #fff;
    padding: 0 12px;
    height: 100%;
    cursor: pointer;
    font-size: 14px;
}
#export-btn:hover {
    background: #218838;
}

/* --- Action Buttons in Table --- */
.utility-btn, .edit-btn, .delete-btn {
    padding: 5px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: white;
    text-transform: uppercase;
    transition: all 0.2s;
}
.utility-btn:hover, .edit-btn:hover, .delete-btn:hover {
    transform: translateY(-2px);
    opacity: 0.85;
}

/* --- Password Visibility Styles (ฉบับแก้ไข) --- */

/* 1. ทำให้ <td> เป็น Flex Container */
td.password-cell {
    display: flex;
    justify-content: space-between; /* จัดให้ item ชิดซ้ายและขวา */
    align-items: center;          /* จัดให้อยู่กลางแนวตั้ง */
    gap: 8px;                     /* สร้างช่องว่างเล็กน้อยระหว่างข้อความกับปุ่ม */
}

/* 2. สไตล์สำหรับตัวหนังสือรหัสผ่าน */
.password-text-container {
    /* ทำให้ข้อความที่ยาวมากๆ ตัดคำขึ้นบรรทัดใหม่ได้ */
    word-break: break-all;
}

/* เหมือนเดิม: ป้องกันการ select ข้อความจุดไข่ปลา */
.password-hidden-text {
    user-select: none;
    font-family: monospace;
}

/* 3. สไตล์สำหรับปุ่ม (เอา position:absolute ออก) */
.toggle-password-btn {
    padding: 2px 8px;
    font-size: 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    background-color: #f0f0f0;
    /* ทำให้ปุ่มไม่หดตัวเมื่อข้อความยาว */
    flex-shrink: 0;
}

.toggle-password-btn:hover {
    background-color: #e0e0e0;
}

/* เหมือนเดิม: สไตล์ปุ่ม "ซ่อน" สีแดง */
.toggle-password-btn.active {
    background-color: #dc3545;
    color: white;
    border-color: #c82333;
}

/* สไตล์สำหรับแถวที่ข้อมูลจากชีตหลัก (Site Data) ยังไม่มี */
tr.missing-data-highlight {
    background-color: #fffbe6 !important; /* สีเหลืองอ่อนๆ */
}

/* ทำให้เซลล์ที่ข้อมูลขาดหายไปดูเด่นขึ้นเล็กน้อย */
tr.missing-data-highlight td {
    color: #856404; /* สีตัวหนังสือโทนเหลืองเข้ม */
}

/* เวลาเอาเมาส์ไปชี้ ให้สีเข้มขึ้นเล็กน้อย */
tr.missing-data-highlight:hover {
    background-color: #fff3cd !important;
}

/* --- Add this to your main.css file --- */

/* Style for the Save button (green) */
.utility-btn.save-btn.enabled {
    background-color: #28a745; /* สีเขียว */
    color: white;
}

.utility-btn.save-btn.enabled:hover {
    background-color: #218838; /* สีเขียวเข้มขึ้นเมื่อเมาส์ชี้ */
}

/* This is the gray style for disabled buttons */
.utility-btn:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

/* --- Add this to the BOTTOM of public/main.css --- */

/* Fix for User Management <select> box size */
.form-group select {
    width: 100%;
    height: 38px; /* (อาจจะต้องปรับค่านี้) ให้สูงเท่ากล่อง input */
    padding: 6px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box; /* สำคัญมาก! */
    background-color: white;
    font-size: 0.9rem; /* (อาจจะต้องปรับค่านี้) ให้ขนาดตัวอักษรเท่ากล่อง input */
}

/* Notification Badge ในเมนู */
.nav-badge {
    background-color: #e74c3c; /* สีแดง */
    color: white;
    border-radius: 12px;       /* มนๆ เหมือนแคปซูล */
    padding: 2px 8px;
    font-size: 0.75rem;
    font-weight: bold;
    margin-left: 8px;          /* เว้นระยะจากตัวหนังสือ */
    vertical-align: middle;
    display: inline-block;
    box-shadow: 0 2px 4px rgba(231, 76, 60, 0.3);
    animation: popIn 0.3s ease-out; /* เอฟเฟกต์เด้งดึ๋งตอนโผล่มา */
}

@keyframes popIn {
    0% { transform: scale(0); }
    80% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* =========================================
   2. ส่วน MODERN DASHBOARD (Upload Portal)
   (เพิ่มใหม่ต่อท้ายไฟล์ main.css ได้เลย)
   ========================================= */

/* โครงสร้างหน้าเว็บแบบ Grid ซ้าย-ขวา */
.page-container {
    max-width: 1400px;
    margin: 30px auto;
    padding: 0 20px;
    display: grid;
    grid-template-columns: 380px 1fr; /* ซ้าย 380px, ขวา auto */
    gap: 25px;
    align-items: start;
}
@media (max-width: 900px) {
    .page-container { grid-template-columns: 1fr; } /* มือถือเรียงแนวตั้ง */
}

/* การ์ดพื้นหลังสีขาว */
.modern-card {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    padding: 25px;
    border: 1px solid #edf2f7;
}

/* ทำให้กล่องซ้ายไหลตามลงมา (Sticky) */
.sticky-panel {
    position: sticky;
    top: 80px; /* เว้นระยะจากเมนูด้านบน */
}

/* กล่องอัปโหลด */
.upload-zone {
    border: 2px dashed #cbd5e0;
    border-radius: 12px;
    padding: 30px 20px;
    text-align: center;
    background: #f8fafc;
    cursor: pointer;
    transition: 0.3s;
    position: relative;
}
.upload-zone:hover { border-color: #4a90e2; background: #ebf8ff; }
.upload-zone input[type="file"] {
    position: absolute; width: 100%; height: 100%; top: 0; left: 0; opacity: 0; cursor: pointer;
}
.upload-icon { font-size: 3rem; color: #4a90e2; margin-bottom: 10px; }

/* ปุ่มกด Broadcast/Upload */
.btn-broadcast {
    background: linear-gradient(135deg, #4a90e2, #357abd);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    width: 100%;
}
.btn-broadcast:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.3);
}

/* หัวข้อ Section */
.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 15px;
    border-left: 4px solid #4a90e2;
    padding-left: 10px;
}

/* =========================================
   SCROLL TO TOP BUTTON (Go Up)
   ========================================= */
#scrollToTopBtn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 9999; /* อยู่บนสุดเสมอ */
    
    /* Design */
    width: 50px;
    height: 50px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #2c3e50, #3498db); /* สีธีมเดียวกับ Header */
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    
    /* Animation */
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s ease;
    
    /* Center Icon */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

/* ตอนเอาเมาส์ชี้ */
#scrollToTopBtn:hover {
    background: linear-gradient(135deg, #3498db, #2980b9);
    transform: translateY(-3px); /* ลอยขึ้นนิดนึง */
    box-shadow: 0 6px 20px rgba(52, 152, 219, 0.4);
}

/* Class สำหรับโชว์ปุ่ม (JS จะเป็นคนใส่ Class นี้) */
#scrollToTopBtn.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.online-badge {
    display:inline-flex; align-items:center; gap:6px;
    background:#0f1e3d; color:#fff; padding:6px 14px;
    border-radius:20px; font-size:13px; font-weight:600;
    cursor:default;
}
.online-dot {
    width:8px; height:8px; border-radius:50%;
    background:#22c55e; box-shadow:0 0 6px #22c55e;
    animation:pulse 2s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }