/**
 * Bond Portfolio CSS
 * ปรับปรุง: แยกส่วน Modal AI ให้เด็ดขาด ป้องกันการตีกับระบบ Login
 */

/* --- พื้นฐานและฟอนต์ --- */
body { 
    font-family: 'Sarabun', sans-serif; 
    margin: 20px; 
    background-color: #f4f6f9; 
    font-size: 14px; 
    color: #333;
}

.container { 
    max-width: 1400px; 
    margin: 0 auto; 
    background: #fff; 
    padding: 25px; 
    box-shadow: 0 0 15px rgba(0,0,0,0.1); 
    border-radius: 10px; 
    /* ย้าย Modal ออกไปนอก container ในทางปฏิบัติจะดีกว่า แต่ถ้ายังอยู่ในนี้ 
       ต้องระวังเรื่อง transform/filter ที่อาจสร้าง Stacking Context ใหม่ */
}        .user-nav {
            display: flex;
            justify-content: flex-end;
            align-items: center;
            margin-bottom: 20px;
            padding: 10px;
            background: #f8f9fa;
            border-radius: 5px;
            font-size: 14px;
        }
        .user-nav a {
            margin-left: 15px;
            color: #dc3545;
            text-decoration: none;
            font-weight: bold;
        }

h2 { text-align: center; color: #2c3e50; margin-bottom: 25px; }

/* --- ส่วนอัปโหลดไฟล์ --- */
.upload-box { 
    border: 2px dashed #007bff; 
    padding: 30px; 
    text-align: center; 
    margin-bottom: 25px; 
    border-radius: 8px; 
    background-color: #f8f9fa; 
}

/* --- ตารางแสดงผล (PC) --- */
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 12px; }
th, td { border: 1px solid #dee2e6; padding: 8px; text-align: right; }
th { background-color: #007bff; color: white; text-align: center; vertical-align: middle; }
td.text-left { text-align: left; }
td.text-center { text-align: center; }
tr:nth-child(even) { background-color: #f8f9fa; }
tr:hover { background-color: #f1f4f7; }

.customer-header { 
    background-color: #343a40; 
    color: white; 
    padding: 12px 18px; 
    margin-top: 35px; 
    border-radius: 6px 6px 0 0; 
    font-size: 1.2em; 
    font-weight: bold;
}

/* --- สีบ่งบอกสถานะ --- */
.profit { color: #28a745; font-weight: bold; }
.loss { color: #dc3545; font-weight: bold; }

/* --- ส่วนสรุปพอร์ตโฟลิโอ --- */
.summary-box { 
    background-color: #f1f3f5; 
    border: 1px solid #ced4da; 
    padding: 15px; 
    font-weight: bold; 
    display: flex; 
    justify-content: space-between; 
    gap: 20px; 
    align-items: flex-start;
    border-top: none;
    border-radius: 0 0 6px 6px;
}

/* --- สไตล์คำแนะนำ AI ในหน้าหลัก --- */
.ai-response-box { 
    background: #e3f2fd; 
    padding: 18px; 
    border-radius: 8px; 
    border-left: 6px solid #2196f3; 
    font-size: 15px; 
    line-height: 1.7; 
    color: #0d47a1; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    white-space: pre-wrap !important;
}

.portfolio-ai-section { margin-top: 15px; margin-bottom: 35px; }

.ai-btn { 
    background-color: #007bff; 
    color: white; 
    border: none; 
    padding: 6px 12px; 
    border-radius: 4px; 
    cursor: pointer; 
    transition: background 0.2s;
    font-size: 14px;
}
.ai-btn:hover { background-color: #0056b3; }

/* --- 🟢 Popup (Modal) System - ปรับปรุงใหม่ให้ทับทุกอย่าง 🟢 --- */
.modal-overlay { 
    display: none; /* คุมด้วย JS */
    position: fixed !important; 
    top: 0 !important; 
    left: 0 !important; 
    width: 100% !important; 
    height: 100% !important; 
    background: rgba(0,0,0,0.8) !important; 
    z-index: 200000 !important; /* สูงกว่า Login (9999) แน่นอน */
    justify-content: center; 
    align-items: center; 
    backdrop-filter: blur(4px);
    pointer-events: auto;
}

.modal-content { 
    background: #ffffff !important; 
    padding: 35px !important; 
    border-radius: 16px !important; 
    width: 90%; 
    max-width: 900px; 
    max-height: 85vh; 
    overflow-y: auto; 
    position: relative; 
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    animation: modalFadeIn 0.3s ease-out;
}

@keyframes modalFadeIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-close { 
    position: absolute; top: 15px; right: 20px; 
    font-size: 35px; cursor: pointer; color: #bbb; 
    line-height: 1;
    transition: color 0.2s;
}
.modal-close:hover { color: #ff4d4d; }

#aiContent {
    white-space: pre-wrap !important;
    font-size: 16px;
    color: #1a4b8c;
    line-height: 1.8;
    font-weight: 400;
}

/* --- Spinner & Loading --- */
.spinner { 
    border: 4px solid #f3f3f3; 
    border-top: 4px solid #007bff; 
    border-radius: 50%; 
    width: 45px; height: 45px; 
    animation: spin 1s linear infinite; 
    margin: 25px auto; 
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* --- Mobile View --- */
@media screen and (max-width: 768px) {
    .pc-view { display: none !important; }
    .mobile-view-container { display: block !important; }
    .mobile-cust-card { margin-bottom: 25px; border: 1px solid #dee2e6; border-radius: 10px; overflow: hidden; background: #fff; }
    .mobile-cust-header { background: #2c3e50; color: white; padding: 15px; cursor: pointer; display: flex; justify-content: space-between; }
    .mobile-cust-body { padding: 10px; display: none; }
    .mobile-cust-body.open { display: block; }
    .m-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed #eee; }
}

@media screen and (min-width: 769px) {
    .pc-view { display: block !important; }
    .mobile-view-container { display: none !important; }
}

/* --- Print Settings --- */
@media print {
    .no-print, .upload-box, .export-section, .ai-btn, .toggle-btn, .portfolio-ai-section, .portfolio-ai-trigger, .spinner, .modal-overlay { 
        display: none !important; 
    }
    .pc-view { display: block !important; }
    body { background-color: white; padding: 0; margin: 0; }
    .container { box-shadow: none; border: none; width: 100%; max-width: 100%; padding: 0; }
    .remark-note { display: block !important; }
}