/* ==========================================================================
   SPS HISTORY & CASHFLOW - MOBILE RESPONSIVE STYLES (PORTRAIT & LANDSCAPE)
   File: sps-history-mobile.css
   Chuẩn hóa tỷ lệ và bố cục Lịch sử lệnh & Dòng tiền trên điện thoại di động
   ========================================================================== */

/* ── 1. PORTRAIT / MOBILE SCREENS (<= 768px) ───────────────────────────── */
@media (max-width: 768px) {
    /* Khung ngoài gọn gàng, chừa khoảng trống cho Floating Chatbot */
    #sps-history-tab {
        padding: 8px 6px 75px 6px !important;
        gap: 8px !important;
        min-height: calc(100dvh - 50px) !important;
        box-sizing: border-box !important;
    }

    /* Thanh Subtabs trượt ngang mượt mà trên cảm ứng */
    .sps-hist-nav {
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
        padding: 5px 6px !important;
        border-radius: 8px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        flex-wrap: nowrap !important;
        position: relative !important;
    }

    .sps-hist-nav::-webkit-scrollbar {
        display: none !important;
    }

    .sps-hist-tab-btn {
        display: inline-flex !important;
        align-items: center !important;
        gap: 5px !important;
        padding: 6px 11px !important;
        font-size: 12px !important;
        font-weight: 600 !important;
        border-radius: 6px !important;
        white-space: nowrap !important;
        flex-shrink: 0 !important;
    }

    /* Thẻ Card chứa nội dung */
    .sps-hist-card {
        padding: 10px 8px !important;
        border-radius: 8px !important;
        gap: 8px !important;
    }

    /* Tiêu đề mục */
    .sps-hist-header {
        padding-bottom: 6px !important;
        margin-bottom: 0 !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important;
    }

    .sps-hist-title {
        font-size: 14px !important;
        font-weight: 700 !important;
        gap: 6px !important;
    }

    .sps-hist-title::before {
        height: 14px !important;
        width: 3.5px !important;
    }

    /* Thanh bộ lọc (Toolbar) - Chuyển sang dạng Flex cột gọn gàng */
    .sps-hist-toolbar {
        display: flex !important;
        flex-direction: column !important;
        gap: 6px !important;
        padding: 8px !important;
        border-radius: 8px !important;
        background: rgba(15, 23, 42, 0.6) !important;
    }

    /* Lưới bộ lọc 2 cột (50% - 50%) */
    .sps-hist-filter-group {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 6px !important;
        width: 100% !important;
    }

    /* Nút hành động (Tìm kiếm & Xuất dữ liệu) chia đôi hàng 3 */
    .sps-hist-actions-group {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 6px !important;
        width: 100% !important;
    }

    /* Nếu chỉ có 1 select (như ở tab Khớp lệnh & Lãi/Lỗ), chiếm trọn 100% hàng đầu */
    .sps-hist-select-full {
        grid-column: 1 / -1 !important;
    }

    /* Sửa triệt để lỗi hiển thị Dropdown trên iOS Safari (không mất chữ, căn giữa chuẩn) */
    .sps-hist-select {
        -webkit-appearance: none !important;
        -moz-appearance: none !important;
        appearance: none !important;
        background-color: #111827 !important;
        color: #f1f5f9 !important;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2338bdf8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") !important;
        background-repeat: no-repeat !important;
        background-position: right 8px center !important;
        padding: 0 24px 0 8px !important;
        font-size: 12.5px !important;
        line-height: normal !important;
        border: 1px solid rgba(255, 255, 255, 0.15) !important;
        border-radius: 6px !important;
        height: 34px !important;
        min-width: 0 !important;
        width: 100% !important;
        box-sizing: border-box !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
        overflow: hidden !important;
    }

    .sps-hist-select option {
        background-color: #111827 !important;
        color: #f1f5f9 !important;
        font-size: 13px !important;
    }

    /* Ô ngày tháng chuẩn mobile (không bao giờ gãy đôi dòng text trên iOS) */
    .sps-hist-date-item {
        display: flex !important;
        align-items: center !important;
        gap: 4px !important;
        padding: 0 6px !important;
        height: 34px !important;
        box-sizing: border-box !important;
        min-width: 0 !important;
        width: 100% !important;
        background: #111827 !important;
        border: 1px solid rgba(255, 255, 255, 0.15) !important;
        border-radius: 6px !important;
    }

    .sps-hist-date-lbl {
        font-size: 11px !important;
        color: #94a3b8 !important;
        white-space: nowrap !important;
        flex-shrink: 0 !important;
        font-weight: 500 !important;
    }

    .sps-hist-date-input {
        flex: 1 !important;
        min-width: 0 !important;
        width: 100% !important;
        font-size: 11.5px !important;
        padding: 0 !important;
        color: #f1f5f9 !important;
        background: transparent !important;
        border: none !important;
        outline: none !important;
        cursor: pointer !important;
        text-align: right !important;
    }

    .sps-hist-date-input::-webkit-calendar-picker-indicator {
        filter: invert(0.8) !important;
        cursor: pointer !important;
        margin-left: 2px !important;
        padding: 0 !important;
    }

    /* Nút Tìm kiếm */
    .sps-hist-btn-search {
        width: 100% !important;
        height: 34px !important;
        font-size: 12.5px !important;
        font-weight: 600 !important;
        border-radius: 6px !important;
        justify-content: center !important;
        padding: 0 8px !important;
        box-sizing: border-box !important;
    }

    /* Nút Xuất dữ liệu */
    .sps-hist-btn-export {
        width: 100% !important;
        height: 34px !important;
        font-size: 12px !important;
        font-weight: 500 !important;
        border-radius: 6px !important;
        justify-content: center !important;
        padding: 0 8px !important;
        box-sizing: border-box !important;
    }

    /* Bảng dữ liệu: Chiều cao tối ưu & Thanh cuộn mượt */
    .sps-hist-table-wrap {
        max-height: calc(100dvh - 300px) !important;
        min-height: 220px !important;
        overflow-x: auto !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        border-radius: 6px !important;
        border: 1px solid rgba(255, 255, 255, 0.08) !important;
    }

    /* Cố định dòng Tiêu đề và dòng Tổng cộng */
    .sps-hist-table {
        border-collapse: separate !important;
        border-spacing: 0 !important;
    }

    .sps-hist-table thead th {
        position: sticky !important;
        top: 0 !important;
        z-index: 10 !important;
        background: #111827 !important;
        padding: 6px 8px !important;
        font-size: 11px !important;
        white-space: nowrap !important;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4) !important;
    }

    .sps-hist-table thead tr:nth-child(2) th {
        top: 28px !important;
        background: #162032 !important;
    }

    .sps-hist-table td {
        padding: 6px 8px !important;
        font-size: 11.5px !important;
        white-space: nowrap !important;
    }

    .sps-hist-table tfoot tr td {
        position: sticky !important;
        bottom: 0 !important;
        z-index: 10 !important;
        background: #0f172a !important;
        padding: 7px 8px !important;
        font-size: 11.5px !important;
        border-top: 2px solid #38bdf8 !important;
        box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.5) !important;
    }

    /* Pagination Bar (Phân trang Lãi/Lỗ) */
    .sps-hist-pagination-bar {
        padding: 6px 4px !important;
        font-size: 11.5px !important;
        gap: 6px !important;
    }

    /* Màn hình khóa khi chưa liên kết SPS */
    #sps-history-lock-gate {
        padding: 20px 8px !important;
        min-height: 360px !important;
    }

    .sps-lock-card {
        padding: 18px 14px !important;
        max-width: 95% !important;
        gap: 12px !important;
    }

    .sps-lock-title {
        font-size: 16px !important;
    }

    .sps-lock-desc {
        font-size: 12.5px !important;
        line-height: 1.5 !important;
    }

    .sps-lock-btn-link {
        width: 100% !important;
        min-height: 40px !important;
        font-size: 13.5px !important;
        justify-content: center !important;
    }
}

/* ── 2. LANDSCAPE MODE (Xoay ngang màn hình thoại, height <= 550px) ───── */
@media (orientation: landscape) and (max-height: 550px) {
    #sps-history-tab {
        padding: 4px 8px 30px 8px !important;
        gap: 5px !important;
        min-height: calc(100dvh - 35px) !important;
    }

    .sps-hist-nav {
        padding: 3px 6px !important;
        gap: 5px !important;
        border-radius: 6px !important;
    }

    .sps-hist-tab-btn {
        padding: 4px 10px !important;
        font-size: 11px !important;
    }

    .sps-hist-card {
        padding: 6px 8px !important;
        gap: 5px !important;
        border-radius: 6px !important;
    }

    /* Ẩn bớt tiêu đề trùng lặp để tiết kiệm tối đa chiều cao màn hình ngang */
    .sps-hist-header {
        display: none !important;
    }

    /* Toolbar biến thành 1 hàng ngang duy nhất siêu gọn */
    .sps-hist-toolbar {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 3px 6px !important;
        gap: 6px !important;
        background: rgba(15, 23, 42, 0.5) !important;
    }

    .sps-hist-filter-group {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 5px !important;
        flex-wrap: nowrap !important;
        flex: 1 !important;
        min-width: 0 !important;
    }

    .sps-hist-actions-group {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 5px !important;
        flex-wrap: nowrap !important;
        flex-shrink: 0 !important;
    }

    .sps-hist-select {
        height: 28px !important;
        font-size: 11px !important;
        min-width: 0 !important;
        width: auto !important;
        max-width: 180px !important;
        padding: 0 18px 0 6px !important;
        flex: 1 !important;
    }

    .sps-hist-date-item {
        height: 28px !important;
        padding: 0 4px !important;
        width: auto !important;
        min-width: 110px !important;
        flex-shrink: 0 !important;
    }

    .sps-hist-date-lbl {
        font-size: 10px !important;
    }

    .sps-hist-date-input {
        font-size: 11px !important;
        width: 78px !important;
    }

    .sps-hist-btn-search,
    .sps-hist-btn-export {
        height: 28px !important;
        font-size: 11px !important;
        padding: 0 8px !important;
        width: auto !important;
        white-space: nowrap !important;
        flex-shrink: 0 !important;
    }

    /* Bảng dữ liệu tự động mở rộng theo chiều cao màn hình ngang */
    .sps-hist-table-wrap {
        max-height: calc(100dvh - 90px) !important;
        min-height: 160px !important;
    }

    .sps-hist-table thead th {
        padding: 4px 6px !important;
        font-size: 10.5px !important;
    }

    .sps-hist-table thead tr:nth-child(2) th {
        top: 24px !important;
    }

    .sps-hist-table td {
        padding: 4px 6px !important;
        font-size: 10.5px !important;
    }

    .sps-hist-table tfoot tr td {
        padding: 5px 6px !important;
        font-size: 11px !important;
    }
}
