/* Dashboard Styles - Được tích hợp với style.css hiện có */

/* Reset style cho phần dashboard để không bị ảnh hưởng bởi style chung */
.dashboard-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 80px); /* Trừ đi chiều cao của navbar */

    width: 100%; /* Luôn giữ nguyên chiều rộng 100% */
    margin-left: 0; /* Luôn giữ nguyên margin 0 */
    font-family: Arial, sans-serif;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    margin-bottom: 0;
    overflow: hidden;
    position: relative;
    transition: none; /* Không có transition để tránh thu hẹp */
}

/* Header styles */
.dashboard-header {
    padding: 20px;
    border-bottom: 1px solid #eaeaea;
}

.dashboard-header h1 {
    font-size: 24px;
    color: #333;
    margin: 0;
    font-weight: 600;
}

.welcome-message {
    color: #666;
    margin: 5px 0 0 0;
    font-size: 14px;
}

/* Flash messages */
.flash-messages {
    padding: 0 20px;
}

.flash-success {
    background-color: #d4edda;
    color: #155724;
    padding: 10px 15px;
    border-radius: 4px;
    margin: 10px 0;
}

.flash-error, .flash-danger {
    background-color: #f8d7da;
    color: #721c24;
    padding: 10px 15px;
    border-radius: 4px;
    margin: 10px 0;
}

.flash-warning {
    background-color: #fff3cd;
    color: #856404;
    padding: 10px 15px;
    border-radius: 4px;
    margin: 10px 0;
}

.flash-info {
    background-color: #d1ecf1;
    color: #0c5460;
    padding: 10px 15px;
    border-radius: 4px;
    margin: 10px 0;
}

/* Chat container */
.chat-container {
  /*  flex: 1;*/

    width: 897px;  /* Hoặc 600px tùy vào lựa chọn của bạn */
    height: 393px;
    overflow-y: auto;
    padding: 15px;
    margin-bottom: 70px; /* Space for input section */
}

/* Message styling - Simplified */
.user-message-container, .bot-message-container {
    margin-bottom: 20px;
}

.user-message {
    background-color: #f0f0f0;
    padding: 12px 16px;
    border-radius: 12px;
    color: #333;
    max-width: 80%;
    margin-left: auto;
    line-height: 1.5;
}

.bot-message {
    background-color: #f9f9f9;
    padding: 15px 20px;
    border-radius: 12px;
    border: 1px solid #eaeaea;
    color: #333;
    max-width: 90%;
    line-height: 1.5;
}

/* Fixed input section at bottom */
.input-section {
   /* position: absolute;*/
    position: static;  /* ✅ Cho phép input-section nằm đúng theo flow nội dung */
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    padding: 15px 20px;
    border-top: 1px solid #eaeaea;
    z-index: 10;
}

.input-container form {
    display: flex;
    width: 100%;
    gap: 10px;
    align-items: center;
}

.input-container input[type="text"] {
    flex: 1;
    padding: 12px 15px;
    font-size: 16px;
    border: 1px solid #ddd;
    border-radius: 24px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    background-color: #fff;
}

.input-container input[type="text"]:focus {
    outline: none;
    border-color: #007BFF;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.input-container button {
    background-color: #007BFF;
    color: white;
    border: none;
    border-radius: 24px;
    padding: 12px 20px;
    font-size: 16px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.input-container button:hover {
    background-color: #0056b3;
}

/* Result styling - Giữ nguyên format như cũ */
.bot-message h3 {
    font-size: 18px;
    color: #333;
    margin-top: 15px;
    margin-bottom: 10px;
    font-weight: 600;
}

.bot-message h4 {
    font-size: 16px;
    color: #333;
    margin-top: 15px;
    margin-bottom: 8px;
    font-weight: 600;
}

.bot-message ul {
    list-style-type: disc;
    margin: 10px 0;
    padding-left: 20px;
}

.bot-message li {
    margin-bottom: 8px;
    color: #333;
}

.bot-message table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
}

.bot-message th,
.bot-message td {
    padding: 10px;
    border: 1px solid #ddd;
    text-align: left;
}

.bot-message th {
    background-color: #f2f2f2;
    color: #333;
    font-weight: bold;
}

.bot-message p {
    margin: 10px 0;
    color: #333;
    line-height: 1.6;
}

.bot-message pre {
    background-color: #f5f5f5;
    padding: 15px;
    border-radius: 5px;
    overflow-x: auto;
    margin: 15px 0;
}

.bot-message code {
    font-family: monospace;
    font-size: 14px;
}

.bot-message a {
    color: #007BFF;
    text-decoration: none;
}

.bot-message a:hover {
    text-decoration: underline;
}

/* Responsive design - phù hợp với style.css */
@media (max-width: 768px) {
    .dashboard-container {
        height: calc(100vh - 70px); /* Điều chỉnh theo navbar nhỏ hơn */
    }

    .chat-container {
        padding: 15px;
    }

    .user-message {
        max-width: 85%;
    }

    .bot-message {
        max-width: 95%;
    }

    .input-section {
        padding: 12px 15px;
    }

    .input-container input[type="text"] {
        padding: 10px 15px;
        font-size: 15px;
    }

    .input-container button {
        padding: 10px 15px;
        font-size: 15px;
    }
}

/* --- Bổ sung hiển thị user input trong phần kết quả --- */
/* Tăng tính nhận diện cho tin nhắn của người dùng */
.user-message {
    position: relative; /* Cho phép tạo mũi tên */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* Hiệu ứng nổi nhẹ */
}

/* Tạo mũi tên nhỏ bên phải của tin nhắn người dùng */
.user-message::after {
    content: "";
    position: absolute;
    top: 10px;
    right: -10px;
    border-width: 10px 0 10px 10px;
    border-style: solid;
    border-color: transparent transparent transparent #f0f0f0;
}

/* ================ LAYOUT CHÍNH ================ */
.app-container {
    display: flex;
    height: calc(100vh - 60px); /* Giả sử navbar có height là 60px, điều chỉnh tùy theo thực tế */
  /*  margin-top: 60px; */ /* ❌ XÓA DÒNG NÀY *//* Điều chỉnh phù hợp với chiều cao của navbar */
    position: relative;
    width: 100%;
    overflow: hidden;
}

/* ================ FIXED CHAT HISTORY SIDEBAR ================ */
.chat-history-sidebar {
    width: 260px;
    background: #f7f7f8;
    border-right: 1px solid #e5e5e6;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    left: -260px;
    top: 60px;
    bottom: 0;
    transition: all 0.3s ease;
    z-index: 1000;
    overflow: hidden; /* Parent container should not scroll */
}

.chat-history-sidebar.active {
    left: 0;
}

.sidebar-header {
    padding: 12px 16px;
    border-bottom: 1px solid #e5e5e6;
    margin-top: 30px;
    flex-shrink: 0; /* Header should not shrink */
}

.history-content {
    padding: 8px 0;
    flex: 1; /* Take remaining space */
    overflow-y: auto; /* Allow scrolling for content */
    min-height: 0; /* Important for flex children */
    max-height: calc(100vh - 200px); /* Ensure space for footer */
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid #e5e5e6;
    background: #f7f7f8;
    flex-shrink: 0; /* Footer should never shrink */
    margin-top: 0; /* Remove auto margin */
}



/* Vị trí nút toggle mới - ở góc trên bên trái của container thay vì sidebar */
.sidebar-toggle-btn {
    position: fixed; /* Đổi thành fixed để luôn hiển thị */
    left: 10px; /* Vị trí bên trái */
    top: 70px; /* Vị trí ngay dưới navbar */
    width: 40px;
    height: 40px;
    background: #f7f7f8;
    border: 1px solid #e5e5e6;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1001;
    transition: all 0.3s ease;
}

.sidebar-toggle-btn:hover {
    background: #e5e5e6;
}


.new-chat-btn {
    width: 100%;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid #d9d9e0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;

}

.new-chat-btn:hover {
    background: #f0f0f5;
}


.history-date {
    color: #8e8ea0;
    font-size: 12px;
    padding: 8px 16px;
    margin-top: 12px;
}
/*
.history-item {
    padding: 8px 16px;
    margin: 4px 0;
    cursor: pointer;
    font-size: 14px;

}*/

.history-item {
    display: block;
    width: 100%;
    text-align: left;
    /*padding: 5px;*/
    padding: 5px 10px;
    margin: 2px 0;
    background: none;
    border: none;
    cursor: pointer;
    border-left: 1px solid transparent;
}

.history-item:hover, .history-item.active {
    background: #f0f0f5;
    border-left-color: #10a37f;
}



.footer-item {
    padding: 8px 0;
    cursor: pointer;
    font-size: 14px;
    color: #333; /* Make sure text is visible 16 09*/

}

.footer-item:hover {
    color: #10a37f;
}

/* ================ RESPONSIVE ================ */
@media (max-width: 768px) {
    .chat-history-sidebar {
        width: 80%;
        left: -80%;
    }

    /* Dashboard container không bị ảnh hưởng bởi sidebar */
    .chat-history-sidebar.active ~ .dashboard-container {
        margin-left: 0;
        width: 100%;
    }
}

/* Loại bỏ hoặc sửa đổi các styles xung đột */
.container-wrapper {
    position: relative;
    overflow-x: hidden;
}

/* QUAN TRỌNG: Xóa hoặc vô hiệu hóa các rules gây ảnh hưởng đến dashboard container */
.chat-history-sidebar.active ~ .dashboard-container {
    margin-left: 0 !important; /* Ghi đè để đảm bảo không có margin */
    width: 100% !important; /* Ghi đè để đảm bảo full width */
}

/* Example question buttons */
.example-question-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.example-btn {
/*    background: #f0f0f5; */
    background: #ffffff;

    border: 1px solid #e5e5e6;
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.example-btn:hover {
/*    background: #e5e5e6; */
      background: #f5f5f5;

}

/* Chat input styling */
.chat-input-wrapper {
    display: flex;
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 24px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.chat-input {
    flex: 1;
    padding: 12px 15px;
    font-size: 16px;
    border: none;
    resize: none;
}

.chat-input:focus {
    outline: none;
}

.input-actions {
    display: flex;
    align-items: center;
}

.attach-btn {
    display: flex;
    padding: 8px;
    cursor: pointer;
}

.send-btn {
    background-color: #007BFF;
    color: white;
    border: none;
    border-radius: 0 24px 24px 0;
    padding: 12px 20px;
    font-size: 16px;
    cursor: pointer;
}

/* Image preview styling */
.file-preview {
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 10px;
    position: relative;
}

.preview-header {
    display: flex;
    justify-content: flex-end;
}

.remove-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #666;
}

.preview-image {
    max-width: 100%;
    max-height: 200px;
    display: block;
    margin: 0 auto;
}


/*  css cho markdown */

 .bot-message-container {
        margin-top: 20px;
        display: flex;
        justify-content: flex-start;
    }

    .bot-message {
        background-color: #f5f5f5;
        padding: 20px;
        border-radius: 12px;
        max-width: 800px;
        font-family: Arial, sans-serif;
        line-height: 1.6;
        white-space: pre-line; /* Cho phép xuống dòng tự nhiên */
    }

    .bot-message h3 {
        margin-top: 0;
        font-size: 20px;
        color: #333;
    }

    .bot-content strong {
        font-weight: bold;
        color: #c0392b;
    }

    .bot-content ul {
        padding-left: 20px;
        margin: 10px 0;
    }

    .bot-content li {
        margin-bottom: 5px;
    }

    /* Expert Analysis Toggle Button (không conflict class khác) */
button.expert-toggle {
  position: absolute;
  bottom: 20px;
  left: 25px;
  padding: 4px 12px;
  font-size: 13px;
  border-radius: 16px;
  border: 1px solid #ccc;
  background-color: #f5f5f5;
  color: #333;
  transition: all 0.2s ease-in-out;
  z-index: 2;
}

button.expert-toggle.active {
  background-color: #ffd54f;
  color: #000;
  border-color: #ffca28;
  box-shadow: 0 0 4px rgba(0,0,0,0.2);
}


 /* ✅CSS của ads google 28 10 */

/* ======== ADS SIDEBAR (fixed overlay, doesn't change layout flow) ======== */
.ads-sidebar-right {
    position: fixed;
    right: 0;
    top: 60px;       /* sync with navbar height */
    bottom: 0;
    width: 180px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background-color: transparent;
    z-index: 999;
    overflow-y: auto;
    pointer-events: auto; /* allow clicks inside ads */
}

/* Ad card */
.ad-card {
    border: 1px solid rgba(0,0,0,0.06);
    padding: 8px;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
    width: 160px;
    flex-shrink: 0;
    position: relative;
}

/* Ad label & close */
.ad-card .ad-label { font-size: 11px; color: #6b7280; margin-bottom: 4px; text-align: right; }
.ad-card .ad-close-btn {
    position: absolute; top: 4px; left: 4px;
    background: rgba(255,255,255,0.7); border: none; border-radius: 50%;
    width: 18px; height: 18px; cursor: pointer; color:#999; opacity:0.6;
}
.ad-card .ad-close-btn:hover { opacity:1; color:#333; }

/* Hidden after dismiss */
.ad-card.hidden { display:none; }

/* ===== NO LAYOUT SHIFT: don't change .dashboard-container width globally ===== */
/* Instead: if we *must* reserve space (optional), add body.has-ads padding-right so flow unaffected */
body.has-ads .app-wrapper {
    padding-right: 180px; /* reserve space for fixed ads if you want visual gap */
}

/* Responsive: hide ads on smaller screens */
@media (max-width: 1024px) {
    .ads-sidebar-right { display: none; }
    body.has-ads .app-wrapper { padding-right: 0; }
}

/* Horizontal scroll for example buttons on small screens, update 10 12 */
@media (max-width: 900px) {
    .example-question-buttons {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 8px;
        padding-bottom: 6px;      /* thêm khoảng để không chạm scrollbar */
        margin-bottom: 12px;
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
    }

    .example-question-buttons::-webkit-scrollbar {
        height: 6px;
    }
    .example-question-buttons::-webkit-scrollbar-thumb {
        background: #d0d0d0;
        border-radius: 999px;
    }
    .example-question-buttons::-webkit-scrollbar-track {
        background: transparent;
    }

    .example-btn {
        flex: 0 0 auto;           /* không co lại */
        white-space: nowrap;      /* không xuống dòng */
    }
}


/* ⚠️===== Top Buttons: Scrollable on mobile (Risk page) ===== 10 12 night */
/* Mobile overrides to remove horizontal scroll on risk pages */
@media (max-width: 900px) {
  .chat-container {
    width: 100% !important;
    max-width: 100% !important;
    padding: 12px !important;
    box-sizing: border-box;
  }
  .dashboard-container {
    padding: 12px;
  }
  .input-group {
    width: 100%;
    max-width: 100%;
  }
  .input-group .analyze-btn,
  .input-group .summary-btn {
    flex: 0 0 auto;
  }
}
/* Force top buttons to scroll horizontally on mobile */
@media (max-width: 900px) {
  .dashboard-header h1 + div {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: hidden;
    gap: 10px;
    padding-bottom: 6px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
  }
  .dashboard-header h1 + div .top-btn {
    flex: 0 0 auto;
    min-width: 140px;
    white-space: nowrap;
  }
  .dashboard-header h1 + div::-webkit-scrollbar {
    height: 6px;
  }
  .dashboard-header h1 + div::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 999px;
  }
}

/* Mobile: risk type pills scroll horizontally */
/* Mobile: risk type pills scroll horizontally */
@media (max-width: 900px) {
  .risk-options ul {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 8px;
    padding-bottom: 6px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
  }
  .risk-options li {
    flex: 0 0 auto;
    white-space: nowrap;
    min-width: 170px; /* tùy chỉnh lại nếu muốn nhỏ hơn */
  }
  .risk-options ul::-webkit-scrollbar {
    height: 6px;
  }
  .risk-options ul::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 999px;
  }
}


/* Tooltips for Risk Type options (hover/focus) */
.risk-options li {
  position: relative;
}

.risk-options li::after {
  position: absolute;
  left: 0;
  top: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #47628f;
  color: #fff;
  font-size: 13px;
  line-height: 1.45;
  box-shadow: 0 8px 24px rgba(0,0,0,0.16);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  transform: translateY(-4px);
  max-width: 280px;
  width: max-content;
  min-width: 200px;
  z-index: 50;
  /* Giới hạn chiều rộng trên mobile */
  max-width: calc(80vw - 60px);
  white-space: normal;
}

.risk-options li:hover::after,
.risk-options li:focus-within::after {
  opacity: 1;
  transform: translateY(-2px);
}

/* Nội dung cho từng loại risk */
.risk-options li:has(input[value="market"])::after {
  content: "Market Risk: biến động chung của toàn thị trường ảnh hưởng đến danh mục.";
}
.risk-options li:has(input[value="systemic"])::after {
  content: "Systemic Risk: rủi ro hệ thống xuất phát từ yếu tố vĩ mô, khó đa dạng hóa để loại bỏ.";
}
.risk-options li:has(input[value="sector"])::after {
  content: "Sector Risk: rủi ro theo ngành do chu kỳ, chính sách, hoặc xu hướng riêng của ngành.";
}
.risk-options li:has(input[value="company"])::after {
  content: "Company Risk: rủi ro đặc thù doanh nghiệp (quản trị, tài chính, sản phẩm, cạnh tranh).";
}
.risk-options li:has(input[value="liquidity"])::after {
  content: "Liquidity Risk: khó mua/bán với khối lượng lớn mà không làm giá biến động mạnh.";
}
.risk-options li:has(input[value="valuation"])::after {
  content: "Valuation Risk: định giá quá cao so với nội tại, dễ bị điều chỉnh khi kỳ vọng đổi chiều.";
}
.risk-options li:has(input[value="technical"])::after {
  content: "Technical Risk: tín hiệu kỹ thuật kém (xu hướng yếu, kháng cự gần, thanh khoản suy giảm).";
}

/* Scoped styling for AI output (html_output) 17 12 add on*/
.bot-message .ai-output {
    font-size: 16px;
    line-height: 1.6;
    color: #222;
}

.bot-message .ai-output p {
    margin: 6px 0 10px;
}

.bot-message .ai-output h1,
.bot-message .ai-output h2,
.bot-message .ai-output h3,
.bot-message .ai-output h4,
.bot-message .ai-output h5,
.bot-message .ai-output h6 {
    margin: 14px 0 8px;
    line-height: 1.3;
    font-weight: 700;
}

.bot-message .ai-output ul,
.bot-message .ai-output ol {
    margin: 8px 0 10px 18px;
    padding: 0 0 0 4px;
}

.bot-message .ai-output li {
    margin: 4px 0 6px;
}

.bot-message .ai-output hr {
    margin: 12px 0;
    border: 0;
    border-top: 1px solid #ccc;
}

.bot-message .ai-output pre {
    background: #f5f5f5;
    padding: 10px 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 10px 0;
}

.bot-message .ai-output code {
    font-family: Consolas, Menlo, Monaco, monospace;
    font-size: 14px;
}

/* ✅ Loading Overlay CSS 24 12 */

/* Tiny inline loading badge */
#inline-loading {
  padding: 6px 0;
}

.loading-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(59,130,246,0.08);
  color: #2563eb;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}

/* Dots animation */
.loading-indicator .dot {
  width: 6px;
  height: 6px;
  background: #2563eb;
  border-radius: 50%;
  animation: typing 1.2s infinite ease-in-out;
  opacity: 0.4;
}

.loading-indicator .dot:nth-child(1) { animation-delay: 0s; }
.loading-indicator .dot:nth-child(2) { animation-delay: 0.2s; }
.loading-indicator .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}