﻿:root {
    --primary: #1e40af;
    --bg: #f8fafc;
    --card: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
}

* {
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, sans-serif;
}

body {
    margin: 0;
    padding: 20px;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

.container {
    max-width: 1440px;
    margin: 0 auto;
}

.header, .filter-panel {
    background: var(--card);
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 16px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

    .header h1 {
        margin: 0;
        font-size: 20px;
        color: var(--primary);
    }

.header-actions {
    display: flex;
    gap: 10px;
}

.filter-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    align-items: end;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

    .form-group label {
        font-weight: 600;
        font-size: 12px;
        color: #475569;
    }

    .form-group input, .form-group select {
        padding: 8px;
        border: 1px solid var(--border);
        border-radius: 6px;
    }

button {
    padding: 9px 16px;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    color: #fff;
}

.btn-primary {
    background: var(--primary);
}

.btn-success {
    background: #047857;
}

.btn-warning {
    background: #d97706;
}

.btn-outline {
    background: #fff;
    border: 1px solid var(--border);
    color: var(--text);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-weight: 600;
}

.table-wrapper {
    background: var(--card);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: auto;
    max-height: 70vh;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: right;
    white-space: nowrap;
}

th {
    background: #f1f5f9;
    padding: 12px 10px;
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
}

td {
    padding: 10px;
    border-bottom: 1px solid var(--border);
}

tr:hover {
    background: #f8fafc;
}

.text-left {
    text-align: left;
}

.text-center {
    text-align: center;
}

.symbol-cell {
    font-weight: 700;
    color: var(--primary);
    font-size: 15px;
}

.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 12px;
}

.badge-up, .badge-buy {
    background: #dcfce7;
    color: #15803d;
}

.badge-down, .badge-sell {
    background: #fee2e2;
    color: #b91c1c;
}

.badge-watch {
    background: #f1f5f9;
    color: #475569;
}
/* Cố định cột Checkbox (cột 1) và Mã CK (cột 2) bên trái khi cuộn ngang */
#stockTable th:nth-child(1), #stockTable td:nth-child(1) {
    position: sticky;
    left: 0;
    z-index: 6;
    background: #ffffff;
}

#stockTable th:nth-child(1) {
    background: #f1f5f9;
    z-index: 16;
}

#stockTable th:nth-child(2), #stockTable td:nth-child(2) {
    position: sticky;
    left: 60px; /* Bằng đúng chiều rộng cột 1 */
    z-index: 5;
    background: #ffffff;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.05);
}

#stockTable th:nth-child(2) {
    background: #f1f5f9;
    z-index: 15;
}
/* Hiệu ứng bấm vào dòng cổ phiếu */
tbody tr {
    cursor: pointer;
}

/* Cửa sổ Popup hiển thị biểu đồ nến */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    z-index: 100;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal-box {
    background: #fff;
    width: 100%;
    max-width: 960px;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
}

    .modal-header h2 {
        margin: 0;
        font-size: 18px;
        color: var(--primary);
    }

.close-btn {
    background: #ef4444;
    color: #fff;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
}

#chartContainer {
    width: 100%;
    height: 420px;
}
/* Tối ưu giao diện cho Smartphone (màn hình nhỏ hơn 768px) */
@media (max-width: 768px) {
    body {
        padding: 10px;
        font-size: 13px;
    }

    /* Xếp dọc phần tiêu đề và chia các nút thành lưới 2 cột dễ bấm */
    .header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 14px;
    }

        .header h1 {
            font-size: 17px;
            line-height: 1.3;
        }

    .header-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

        .header-actions a {
            display: flex;
        }

        .header-actions button {
            width: 100%;
            padding: 8px 6px;
            font-size: 12px;
        }

    /* Bộ lọc chia 2 cột gọn gàng trên điện thoại */
    .filter-panel {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        padding: 12px;
    }
        /* Ô Tìm nhanh Mã CK và nút Lọc Cổ Phiếu chiếm trọn chiều ngang */
        .filter-panel .form-group:first-child,
        .filter-panel .form-group:last-child {
            grid-column: span 2;
        }

    /* Tối ưu bảng dữ liệu khi vuốt ngang bằng ngón tay */
    .table-wrapper {
        max-height: 62vh;
        -webkit-overflow-scrolling: touch;
    }

    th, td {
        padding: 8px 6px;
        font-size: 12px;
    }

    .symbol-cell {
        font-size: 14px;
    }

    /* Cửa sổ Popup biểu đồ vừa khít màn hình điện thoại */
    .modal-overlay {
        padding: 8px;
    }

    .modal-header {
        padding: 10px 12px;
    }

        .modal-header h2 {
            font-size: 14px;
        }

    #chartContainer {
        height: 320px;
    }
}
/* Mặc định ẩn nút thu gọn trên màn hình máy tính */
.mobile-filter-toggle {
    display: none;
}

@media (max-width: 768px) {
    /* Hiện nút thu gọn bộ lọc trên điện thoại */
    .mobile-filter-toggle {
        display: block;
        width: 100%;
        background: #e2e8f0;
        color: #1e293b;
        margin-bottom: 10px;
        padding: 8px;
        font-size: 13px;
        border: 1px solid #cbd5e1;
    }

    /* Khi bấm thu gọn, ẩn khung bộ lọc và tăng chiều cao bảng dữ liệu lên 76% màn hình */
    .filter-panel.collapsed {
        display: none;
    }

    .table-wrapper.expanded {
        /*max-height: 76vh;*/
    }
}

/* 1. Khóa thanh cuộn thừa của cửa sổ trình duyệt, dùng 100dvh để chuẩn trên cả Smartphone */
html, body {
    height: 100dvh;
    margin: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

body {
    padding: 12px 16px;
}

/* 2. Chia bố cục dọc linh hoạt để bảng tự lấp đầy phần màn hình còn lại */
.container {
    max-width: 1440px;
    height: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

.header, .filter-panel, .status-bar, .mobile-filter-toggle {
    flex-shrink: 0; /* Không bị co lại khi danh sách dài */
}

/* 3. Khung bảng sở hữu thanh cuộn dọc & ngang duy nhất của toàn trang */
.table-wrapper {
    flex: 1;
    min-height: 0; /* Bắt buộc để flex child kích hoạt cuộn bên trong */
    background: var(--card);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

/* 4. Làm thanh cuộn mảnh mai, hiện đại hơn (6px) */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

    ::-webkit-scrollbar-thumb:hover {
        background: #94a3b8;
    }

/* Hỗ trợ thanh cuộn mảnh trên Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f5f9;
}

