/* ======================================================== */
/* MEDIA DATABASE STYLESHEET (ADAPTED FOR MAIN THEME)       */
/* ======================================================== */

/* -------------------------------------------------------- */
/* 2. PAGE LAYOUT & CONTROLS (ปรับให้เหมือนหน้า Network)       */
/* -------------------------------------------------------- */

/* --- Wrapper สำหรับส่วนควบคุมทั้งหมด (Search, Filter, Export) */
.controls-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.search-container {
    flex-grow: 1;
}

/* Fix for search input in media_database.html (which uses search-box div) */
/* This ensures the input inside .search-box is borderless */
.search-box > #search-input {
    flex: 1;
    border: none;
    border-radius: 0;
    padding: 0;
    font-size: 14px;
    line-height: normal;
    outline: none;
    background: transparent;
}
#search-input:focus {
    box-shadow: none; 
    outline: none;
}
#search-input::placeholder {
    color: #999;
    font-size: 0.9rem;
}


/* Filter dropdown */
#age-range-select {
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 0 12px;
    background: #fff;
    height: 100%;
    line-height: normal;
}

/* --- ปรับปุ่มและ Filter dropdown ให้เข้าชุดกัน (ใช้ class .control-element) --- */
.filter-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* -------------------------------------------------------- */
/* 3. COLLAPSIBLE FILTER OPTIONS (ปรับให้เข้ากับ Theme)       */
/* -------------------------------------------------------- */

.collapsible-filters {
    background: #fdfdfd; 
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    transition: all 0.25s ease-in-out;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}

.collapsible-filters[open] {
    background: #fff;
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}

.collapsible-filters summary {
    font-size: 1rem;
    font-weight: 600;
    color: #2c3e50;
    cursor: pointer;
    list-style: none;
    padding: 12px 20px;
    transition: color 0.2s;
    outline: none;
}
.collapsible-filters summary:hover {
    color: #2980b9;
}
.collapsible-filters summary::before {
    content: '▶ ';
    font-size: 0.9em;
    margin-right: 8px;
    display: inline-block;
    transition: transform 0.25s;
}
.collapsible-filters[open] summary::before {
    transform: rotate(90deg);
}

/* ปรับ Content ข้างใน */
.filters-content-area {
    padding: 0 20px 20px 20px;
}
.checkbox-filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 8px;
    padding-top: 1px;
    border-top: 1px solid #e9ecef;
}

.checkbox-filters-grid fieldset {
    border: 1px solid #dcdcdc;
    border-radius: 8px;
    padding: 20px 16px 16px 16px;
    background: #fafafa;
    min-width: 240px;
    box-sizing: border-box;
    margin: 5px;
}
.checkbox-filters-grid legend {
    font-weight: 600;
    color: #2980b9;
    padding: 0 8px;
    margin-left: 10px;
    font-size: 0.95rem;
}

.checkbox-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px 20px;
}

.checkbox-container label {
    display: flex;
    align-items: center;
    font-size: 0.9rem;
    gap: 6px;
    padding: 2px 4px;
    border-radius: 4px;
    transition: background 0.2s;
    cursor: pointer;
    white-space: nowrap;
}
.checkbox-container label:hover {
    background-color: #f1f5f9;
}
.checkbox-container input[type="checkbox"] {
    accent-color: #2980b9;
}

/* --- 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;
}

.edit-btn { background-color: #f1c40f; color: #333; }
.delete-btn { background-color: #e74c3c; }

/* ถ้ามี form แก้ไขก็จะซ่อนไว้ก่อน */
.form-container.hidden {
    display: none;
}

/* Layout หลัก */
#site-form {
    max-width: 800px;
    margin: 20px auto;
    padding: 20px 25px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    font-family: "Poppins", "Tahoma", sans-serif;
}

#site-form h2 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
    color: #2c3e50;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 8px;
}

/* จัดฟอร์มเป็น grid */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.full-width {
    grid-column: span 2;
}

/* label */
.form-group label {
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    color: #34495e;
}

/* input พื้นฐาน */
.form-group input, .form-group textarea {
    padding: 8px 10px;
    border: 1px solid #dce3eb;
    border-radius: 6px;
    font-size: 0.95rem;
    transition: border 0.2s, box-shadow 0.2s;
    font-family: inherit;
}


/* input ที่แก้ไขไม่ได้ */
.form-group input[readonly] {
    background: #f5f6f8;
    color: #555;
    border: 1px solid #ddd;
    cursor: not-allowed;
    font-style: italic;
}

/* input ที่แก้ไขได้ */
.form-group.editable input, .form-group.editable textarea {
    background: #fff;
}

/* focus effect */
.form-group.editable input:focus, .form-group.editable textarea:focus {
    border: 1px solid #2980b9;
    box-shadow: 0 0 5px rgba(41,128,185,0.25);
    outline: none;
}

/* ปุ่ม */
.form-actions {
    margin-top: 20px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.form-actions button {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.2s;
}

.form-actions button[type="submit"] {
    background: #27ae60;
    color: white;
}
.form-actions button[type="submit"]:hover {
    background: #219150;
}

.form-actions button#cancel-edit-btn {
    background: #e0e0e0;
    color: #333;
}
.form-actions button#cancel-edit-btn:hover {
    background: #d0d0d0;
}

/* ========================================= */
/* Classic Style for Cost Details Pop-up   */
/* ========================================= */

/* Trigger (ข้อความที่กดได้) */
.codedgt-trigger {
    cursor: pointer;
    font-weight: 600;
    color: #2c3e50;
    text-decoration: underline;
    transition: color 0.2s ease;
}
.codedgt-trigger:hover {
    color: #8e44ad;
}

/* กล่อง Pop-up */
.cost-popup {
    position: absolute;
    background: #fcfcfc;
    border: 1px solid #dcdcdc;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    padding: 18px 20px;
    width: auto; /* Let width adjust to content */
    min-width: 300px; /* Set a minimum width */
    max-width: 450px; /* Set a maximum width */
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s 0.25s;
    font-family: "Poppins", "Tahoma", sans-serif;
}

.cost-popup.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s 0s;
}

/* Header */
.cost-popup-header {
    font-size: 1.05rem;
    font-weight: 700;
    padding-bottom: 8px;
    margin-bottom: 12px;
    border-bottom: 1px solid #e0e0e0;
    color: #2c3e50;
    letter-spacing: 0.5px;
}
.cost-popup-header strong {
    color: #2980b9;
}

/* Body */
.cost-popup-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.cost-popup-body p {
    margin: 5px 0;
    color: #6c757d;
}

/* VVVV MODIFICATION: New layout for 4 items VVVV */
/* รายการ */
.cost-item {
    display: grid;
    /* 2 columns: Label (auto-width) and Value (fills remaining space) */
    grid-template-columns: auto 1fr; 
    gap: 5px 10px; /* 5px row gap, 10px column gap */
    padding: 10px 12px;
    background: #f4f4f4;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 0.9rem; /* Increased font size slightly */
    align-items: center; /* Vertically align items in grid cells */
}
.cost-item:hover {
    background: #eaeaea;
}

/* Class for Labels (CID:, Network:, etc.) */
.cost-label {
    font-weight: 600;
    color: #34495e;
    text-align: right; /* Align labels to the right */
    white-space: nowrap;
}

/* Class for the Cost value specifically */
.cost-value {
    font-weight: 700; /* Bolder */
    color: #27ae60;   /* Green color */
    font-size: 1rem;  /* Slightly larger */
}

/* Default span (for CID, Network, CCTV values) */
.cost-item > span {
     white-space: normal; /* Allow values to wrap if needed */
     word-break: break-word; /* Break long words */
     color: #2c3e50;
}
/* ^^^^ END MODIFICATION ^^^^ */

