/* Trang Đơn hàng Affiliate (/tiktok-shop-orders + link chia sẻ công khai /tiktok-shop/live/{token}).
 * Tách từ <style> inline của tiktok-shop-orders.php. Nạp SAU tiktok-shop-mobile.css nên rule
 * cùng specificity ở đây thắng; chỗ cần thắng rule mobile chung thì dùng selector dài hơn.
 * Tông cam theo trang chính /tiktok-shop: #ea580c / nền #fff7ed / viền #fed7aa / chữ #9a3412. */

.ord-page {
    --o-primary: #ea580c; --o-bg: #fff7ed; --o-line: #fed7aa; --o-ink2: #9a3412;
    --ink: #111827; --muted: #6b7280; --line: #eef0f3;
}

/* Hero: trang owner được tiktok-shop-subpage-hero.css (body .tts-hero) phủ tông cam; link chia sẻ công khai
 * KHÔNG có thanh chuyển nhanh nên file đó không nạp ⇒ tự đặt cùng tông ở đây. Trong app, app-view.css
 * (.rh-app .tts-hero) cụ thể hơn nên vẫn thắng. */
.tts-hero { background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%); border: 1px solid #fed7aa; border-radius: 16px; padding: 16px 20px; margin-bottom: 12px; color: #111827; position: relative; overflow: hidden; }
.tts-hero h1 { font-size: 1.45rem; font-weight: 800; margin: 0 0 4px; color: #111827; }
.tts-hero h1 > .bi:first-child { color: #ea580c; }
.tts-hero p { color: #6b7280; font-size: .875rem; margin: 0; }
.tts-hero .btn-light { background: #fff; border: 1px solid #fed7aa; color: #9a3412; font-weight: 700; }
.tts-hero-live { display: inline-flex; align-items: center; gap: 4px; vertical-align: middle; font-size: .62rem; font-weight: 800; letter-spacing: .04em; color: #fff; background: #dc2626; border-radius: 999px; padding: 3px 8px; }
.tts-hero-live::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: #fff; animation: ordPulse 1.4s infinite; }
@keyframes ordPulse { 0%, 100% { opacity: 1 } 50% { opacity: .3 } }

/* Thẻ chung + cũ (giữ tên .tts-card, .not-connected-notice vì gate/JS khác dùng) */
.tts-card { background: #fff; border: 1px solid #eef0f3; border-radius: 14px; padding: 12px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(17,24,39,.04); }
.not-connected-notice { background: #fff7ed; border: 1.5px dashed #fdba74; border-radius: 14px; padding: 32px; text-align: center; }
.skeleton { background: linear-gradient(90deg,#f3f4f6 25%,#e5e7eb 50%,#f3f4f6 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 6px; }
@keyframes shimmer { 0% { background-position: 200% 0 } 100% { background-position: -200% 0 } }

/* Nút cam dùng trong trạng thái rỗng/lỗi */
.ord-btn-primary { background: #ea580c; border: 1px solid #ea580c; color: #fff; font-weight: 700; border-radius: 9px; }
.ord-btn-primary:hover { background: #c2410c; border-color: #c2410c; color: #fff; }
.ord-btn-outline { background: #fff; border: 1px solid #fed7aa; color: #9a3412; font-weight: 700; border-radius: 9px; }
.ord-btn-outline:hover { background: #fff7ed; color: #9a3412; border-color: #fdba74; }

/* ---- Thanh trên: trạng thái đồng bộ (trái) + thao tác CSV/Live/Chia sẻ (phải) ---- */
.ord-topbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
#ordersSyncBar { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 14px; font-size: .76rem; color: #6b7280; font-variant-numeric: tabular-nums; }
#ordersSyncBar > span { white-space: nowrap; }
#ordersSyncBar .bi { color: #ea580c; }
#ordersSyncBar .tts-sync-v { display: inline-block; min-width: 6.4em; }   /* cụm "37 giây trước": cố định bề rộng để dòng không giật */
#ordersSyncBar .tts-sync-n { display: inline-block; min-width: 2ch; text-align: right; }
.ord-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ord-actions .btn { height: 32px; padding: 0 11px; font-size: .8rem; font-weight: 700; border-width: 1px; border-radius: 9px; display: inline-flex; align-items: center; }
.ord-actions .btn.btn-rh-outline { background: #fff; border-color: #e5e7eb; color: #374151; }
.ord-actions .btn.btn-rh-outline:hover { border-color: #fdba74; color: #9a3412; background: #fff7ed; }
.ord-actions .form-select { width: auto; height: 32px; font-size: .8rem; padding: 0 1.6rem 0 .6rem; border-radius: 9px; border-color: #e5e7eb; background-color: #fff; }

/* ---- Khung lọc ---- */
.ord-filters { background: #fff; border: 1px solid #eef0f3; border-radius: 14px; padding: 8px 10px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(17,24,39,.04); }
.ord-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ord-row + .ord-row { margin-top: 6px; padding-top: 6px; border-top: 1px dashed #eef0f3; }
.ord-filters .form-select, .ord-filters .form-control { width: auto; height: 32px; font-size: .8rem; border-radius: 9px; border-color: #e5e7eb; background-color: #fff; }
.ord-filters .form-select { padding: 0 1.8rem 0 .65rem; background-position: right .5rem center; }
.ord-filters .form-select:focus, .ord-filters .form-control:focus { border-color: #fdba74; box-shadow: 0 0 0 3px rgba(234,88,12,.12); }
.ord-search { position: relative; display: flex; align-items: center; flex: 0 1 270px; }
.ord-search-ic { position: absolute; left: 10px; font-size: .78rem; color: #9ca3af; pointer-events: none; }
.ord-filters .ord-search .form-control { width: 100%; padding: 0 50px 0 28px; }
.ord-search-btn { position: absolute; right: 3px; height: 26px; padding: 0 11px; font-size: .75rem; font-weight: 700; line-height: 1; color: #fff; background: #ea580c; border: 0; border-radius: 7px; }
.ord-search-btn:hover { background: #c2410c; color: #fff; }
.ord-sep { width: 1px; height: 18px; background: #e5e7eb; }
.ord-chip { height: 32px; padding: 0 12px; font-size: .8rem; font-weight: 700; border: 1px solid #e5e7eb; border-radius: 9px; background: #fff; color: #374151; }
.ord-chip:hover { border-color: #fdba74; color: #9a3412; }
/* JS bật/tắt btn-rh-primary / btn-rh-outline trên nút "Hôm nay" — trung hoà kiểu nút theme */
.ord-chip.btn-rh-outline, .ord-chip.btn-rh-primary { border-width: 1px; border-radius: 9px; padding: 0 12px; font-size: .8rem; transform: none; box-shadow: none; }
.ord-chip.btn-rh-outline { background: #fff; border-color: #e5e7eb; color: #374151; }
.ord-chip.btn-rh-primary { background: #fff7ed; border-color: #ea580c; color: #9a3412; }
.ord-range { display: inline-flex; align-items: center; gap: 4px; }
.ord-filters .ord-range .form-control { padding: 0 6px; }
.ord-range-to { color: #9ca3af; font-size: .8rem; }
.ord-push { flex: 1 1 0; }
.ord-reset { height: 32px; padding: 0 6px; font-size: .78rem; font-weight: 600; color: #9a3412; text-decoration: none; }
.ord-reset:hover { color: #dc2626; }
.ord-more-btn { display: none; }
.ord-more-count { display: inline-flex; align-items: center; justify-content: center; min-width: 17px; height: 17px; padding: 0 4px; margin-left: 4px; border-radius: 9px; background: #ea580c; color: #fff; font-size: .66rem; font-weight: 800; }

/* ---- Banner Live / cảnh báo huỷ cao / giữ quyết toán ---- */
.ord-note { display: flex; align-items: flex-start; gap: 8px; border-radius: 12px; padding: 9px 12px; margin-bottom: 10px; font-size: .8rem; line-height: 1.45; border: 1px solid; }
.ord-note > .bi { font-size: .95rem; line-height: 1.35; flex: none; }
.ord-note--live { background: #fff7ed; border-color: #fed7aa; color: #9a3412; }
.ord-note--live > .bi { color: #dc2626; }
.ord-note--danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.settle-hold { background: #fffbeb; border: 1px solid #fde68a; color: #78350f; border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; font-size: .8rem; line-height: 1.5; }
.settle-hold-ic { width: 26px; height: 26px; border-radius: 8px; background: #fef3c7; color: #b45309; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.settle-hold .btn { height: 28px; padding: 0 10px; font-size: .76rem; font-weight: 700; border-radius: 8px; display: inline-flex; align-items: center; }
.settle-hold .settle-hold-primary { background: #fff; border: 1px solid #fcd34d; color: #92400e; }
.settle-hold .settle-hold-primary:hover { background: #fef3c7; color: #78350f; }
.settle-hold .settle-hold-ghost { background: transparent; border: 0; color: #92400e; opacity: .8; padding: 0 4px; }
.settle-hold .settle-hold-ghost:hover { opacity: 1; text-decoration: underline; }
.settle-hold-detail { background: #fff; border: 1px solid #fde68a; border-radius: 10px; padding: 10px 12px; color: #374151; }

/* ---- KPI ---- */
#ordersSummary { margin-bottom: 12px; }
.ord-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.ord-kpi { background: #fff; border: 1px solid #eef0f3; border-radius: 14px; padding: 12px 14px; box-shadow: 0 1px 2px rgba(17,24,39,.04); min-width: 0; }
.ord-kpi-head { display: flex; align-items: center; gap: 7px; }
.ord-kpi-ic { width: 26px; height: 26px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; font-size: .85rem; flex: none; background: #f3f4f6; color: #6b7280; }
.ord-kpi-lbl { font-size: .74rem; font-weight: 700; color: #6b7280; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ord-kpi-val { font-size: 1.35rem; font-weight: 800; color: #111827; letter-spacing: -.02em; line-height: 1.2; margin-top: 6px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ord-kpi-sub { font-size: .72rem; color: #6b7280; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ord-kpi-sub b { color: #374151; }
.ord-kpi--gmv .ord-kpi-ic { background: #fff7ed; color: #ea580c; }
.ord-kpi--est .ord-kpi-ic { background: #fef3c7; color: #b45309; }
/* HH thực nhận là con số "tiền thật" — nhấn bằng nền cam nhạt */
.ord-kpi--act { background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%); border-color: #fed7aa; }
.ord-kpi--act .ord-kpi-ic { background: #ea580c; color: #fff; }
.ord-kpi--act .ord-kpi-val { color: #9a3412; }
.ord-chipstats { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ord-chipstats:empty { display: none; }
.ord-chipstat { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 10px; border-radius: 999px; background: #fff; border: 1px solid #eef0f3; font-size: .75rem; color: #6b7280; white-space: nowrap; }
.ord-chipstat b { color: #111827; }
.ord-chipstat-pct { font-weight: 700; }
.ord-chipstat.is-danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.ord-chipstat.is-danger b { color: #991b1b; }
.ord-chipstat.is-bonus .bi { color: #c2410c; }

/* ---- Biểu đồ ---- */
#ordersChart { padding: 14px 16px !important; }

/* ---- Nhãn trạng thái / nguồn (1 bảng màu cho bảng, thẻ, modal) ---- */
.ord-st { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: .7rem; font-weight: 700; white-space: nowrap; border: 1px solid transparent; }
.ord-st .bi { font-size: .68rem; }
.ord-st--pending { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.ord-st--settled { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.ord-st--cancel  { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.ord-src { display: inline-flex; align-items: center; gap: 3px; height: 20px; padding: 0 7px; border-radius: 6px; font-size: .68rem; font-weight: 700; white-space: nowrap; }
.ord-src .bi { font-size: .72rem; }
.ord-src--link  { background: #fff7ed; color: #9a3412; }
.ord-src--video { background: #eff6ff; color: #1d4ed8; }
.ord-src--live  { background: #fdf2f8; color: #be185d; }
.ord-src--shop  { background: #f3f4f6; color: #374151; }
.ord-sub { font-size: .7rem; color: #6b7280; white-space: nowrap; }
.ord-sub code { color: #9a3412; font-size: .7rem; }

/* ---- Danh sách đơn ---- */
.ord-tip { font-size: .74rem; color: #9ca3af; margin: 0 2px 6px; }
.ord-list-card { background: #fff; border: 1px solid #eef0f3; border-radius: 14px; box-shadow: 0 1px 2px rgba(17,24,39,.04); overflow: hidden; }
.ord-table-wrap { overflow-x: auto; }
.ord-page .ord-table { font-size: .82rem; }
.ord-page .ord-table thead th { background: #f9fafb; color: #6b7280; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid #eef0f3; padding: 10px 12px; white-space: nowrap; }
.ord-page .ord-table td { padding: 10px 12px; border-color: #f3f4f6; }
.ord-page .ord-table tbody tr { cursor: pointer; transition: background .12s; }
.ord-page .ord-table tbody tr:hover td { background: #fffaf5; }
.ord-page .ord-table tbody tr:last-child td { border-bottom: 0; }
.ord-nowrap { white-space: nowrap; }
.ord-num { font-variant-numeric: tabular-nums; font-weight: 600; color: #111827; }
.ord-page .ord-table td.ord-when { font-size: .74rem; color: #6b7280; min-width: 92px; }
.ord-qt { font-size: .68rem; color: #047857; }
.ord-prod { display: flex; gap: 10px; align-items: center; min-width: 240px; }
.ord-prod img, .ord-card-top img { width: 44px; height: 44px; object-fit: cover; border-radius: 10px; background: #f3f4f6; flex: none; border: 1px solid #f3f4f6; }
.ord-prod-txt { min-width: 0; }
.ord-prod-name { font-weight: 600; font-size: .82rem; color: #111827; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ord-prod-meta { font-size: .7rem; color: #9ca3af; font-variant-numeric: tabular-nums; }
.ord-oid { color: #6b7280; }
.ord-same { display: inline-block; font-size: .64rem; font-weight: 600; color: #6b7280; background: #f3f4f6; border-radius: 5px; padding: 1px 6px; }
.ord-variant { display: inline-block; font-size: .64rem; font-weight: 600; color: #c2410c; background: #fff7ed; border: 1px solid #fed7aa; border-radius: 5px; padding: 0 6px; margin-left: 4px; white-space: nowrap; }
.ord-copy { border: 0; background: transparent; color: #9ca3af; padding: 0 2px; font-size: .74rem; line-height: 1; }
.ord-copy:hover { color: #ea580c; }
.ord-comm { font-weight: 700; color: #111827; font-variant-numeric: tabular-nums; }
.ord-comm.is-settled { color: #047857; }
.ord-comm.is-cancel { color: #9ca3af; text-decoration: line-through; }
.ord-comm-note { font-size: .68rem; color: #9ca3af; }
.ord-bonus { font-size: .68rem; color: #c2410c; font-weight: 600; }
.ord-cards { display: none; }

/* Phân trang */
.ord-pager { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.ord-pager-info { font-size: .78rem; color: #6b7280; }
.ord-pager-info b { color: #111827; }
.ord-pager-btns { display: flex; gap: 4px; }
.ord-pg { height: 32px; min-width: 34px; padding: 0 10px; border: 1px solid #e5e7eb; background: #fff; color: #374151; border-radius: 9px; font-size: .78rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.ord-pg:hover:not(:disabled) { border-color: #fdba74; color: #9a3412; background: #fff7ed; }
.ord-pg:disabled { opacity: .45; cursor: not-allowed; }

/* Skeleton dạng hàng */
.ord-skel-row { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-bottom: 1px solid #f3f4f6; }
.ord-skel-row:last-child { border-bottom: 0; }
.ord-skel-img { width: 44px; height: 44px; border-radius: 10px; flex: none; }
.ord-skel-l1 { height: 12px; width: 70%; margin-bottom: 8px; }
.ord-skel-l2 { height: 10px; width: 40%; }

/* Trạng thái rỗng / lỗi */
.ord-state { background: #fff; border: 1px solid #eef0f3; border-radius: 14px; padding: 32px 18px; text-align: center; }
.ord-state-ic { width: 52px; height: 52px; border-radius: 16px; margin: 0 auto 10px; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; background: #fff7ed; color: #ea580c; }
.ord-state--error .ord-state-ic { background: #fef2f2; color: #dc2626; }
.ord-state-title { font-weight: 800; color: #111827; font-size: .95rem; }
.ord-state-title code { color: #9a3412; background: #fff7ed; padding: 1px 6px; border-radius: 5px; }
.ord-state-desc { font-size: .8rem; color: #6b7280; max-width: 420px; margin: 4px auto 0; line-height: 1.5; }

/* Modal chi tiết: nhãn trạng thái mới cạnh settlement_status */
#orderDetailModal .modal-content, #shareModal .modal-content { border-radius: 16px; border: 0; }

/* Footer quay về */
.ord-back { margin-top: 14px; }
.ord-back .btn { border-radius: 9px; font-weight: 700; }

/* ============ Desktop vừa ============ */
@media (max-width: 991.98px) {
    .ord-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ============ Điện thoại / tablet dọc: thẻ thay bảng, lọc thu gọn ============ */
@media (max-width: 767.98px) {
    .ord-topbar { flex-direction: column; align-items: stretch; }
    #ordersSyncBar { gap: 2px 12px; font-size: .72rem; }
    #ordersSyncBar .tts-sync-v { min-width: 0; }

    /* Theme mobile ép select 44px/16px — ghi đè cho gọn (16px giữ để iOS không zoom khi gõ). */
    .ord-page .ord-filters .form-select, .ord-page .ord-filters .form-control, .ord-page .ord-chip, .ord-page .ord-more-btn { height: 38px !important; min-height: 38px !important; }
    .ord-filters { padding: 8px; }
    .ord-search { flex: 1 1 100%; }
    .ord-search-btn { height: 30px; min-height: 0 !important; padding: 0 12px !important; }
    .ord-chip { padding: 0 10px !important; font-size: .88rem; }
    .ord-sep, .ord-push { display: none; }
    .ord-row-main > .form-select { flex: 1 1 0; min-width: 0; }
    .ord-row-main > .ord-chip, .ord-row-main > .ord-more-btn { flex: 0 0 auto; }
    .ord-more-btn { display: inline-flex; align-items: center; justify-content: center; padding: 0 10px; font-size: .88rem; font-weight: 700; border: 1px solid #e5e7eb; border-radius: 9px; background: #fff; color: #374151; white-space: nowrap; }
    .ord-filters.is-open .ord-more-btn { border-color: #ea580c; color: #9a3412; background: #fff7ed; }
    /* Thu gọn: khoảng ngày + hàng lọc phụ chỉ hiện khi bấm "Bộ lọc" */
    .ord-range, .ord-more { display: none; }
    .ord-filters.is-open .ord-range { display: flex; flex: 1 1 100%; order: 5; } /* xuống dưới nút Bộ lọc */
    .ord-filters.is-open .ord-more { display: flex; }
    .ord-filters .ord-range .form-control { flex: 1; min-width: 0; }
    .ord-more > .form-select, .ord-more > .ord-reset { flex: 1 1 calc(50% - 6px); min-width: 0; }

    /* 4 thao tác trên 1 hàng thay vì 4 hàng nút to của theme mobile */
    .ord-actions { width: 100%; flex-wrap: nowrap; }
    .ord-page .ord-actions > * { flex: 1 1 auto; min-width: 0; height: 36px !important; min-height: 36px !important; padding: 0 8px !important; justify-content: center; white-space: nowrap; }
    .ord-page .ord-actions > .form-select { flex: 0 0 66px; padding-right: 1.4rem !important; }

    .ord-kpis { gap: 8px; }
    .ord-kpi { padding: 10px 11px; border-radius: 12px; }
    .ord-kpi-val { font-size: 1.12rem; margin-top: 4px; }
    .ord-kpi-sub { font-size: .68rem; }

    /* Bảng → thẻ */
    .ord-table-wrap { display: none; }
    .ord-list-card { background: transparent; border: 0; box-shadow: none; overflow: visible; }
    .ord-cards { display: flex; flex-direction: column; gap: 8px; }
    .ord-card { background: #fff; border: 1px solid #eef0f3; border-radius: 14px; padding: 11px 12px; box-shadow: 0 1px 2px rgba(17,24,39,.04); cursor: pointer; }
    .ord-card:active { background: #fffaf5; }
    .ord-card-top { display: flex; gap: 10px; align-items: flex-start; }
    .ord-card-main { flex: 1 1 auto; min-width: 0; }
    .ord-card-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 4px; }
    .ord-card-tags .ord-sub { overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
    .ord-card-top > .ord-st { flex: none; }
    .ord-card-nums { display: flex; justify-content: space-between; gap: 10px; margin-top: 10px; padding: 8px 10px; background: #f9fafb; border-radius: 10px; }
    .ord-card-k { font-size: .66rem; color: #9ca3af; font-weight: 600; }
    .ord-card-v { font-size: .9rem; font-weight: 700; color: #111827; font-variant-numeric: tabular-nums; }
    .ord-card-v .ord-comm { font-size: .95rem; }
    .ord-card-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; font-size: .7rem; color: #9ca3af; }
    .ord-card-foot > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .ord-card-foot > span:last-child { flex: none; }
    .ord-tip { display: none; }

    .ord-pager { justify-content: center; }
    .ord-pager-info { width: 100%; text-align: center; }
    .ord-page .ord-pg { height: 38px !important; min-height: 38px !important; }
}

@media (max-width: 575.98px) {
    .ord-kpi-lbl { font-size: .7rem; }
    .ord-state { padding: 26px 14px; }
}
