/* ============================================================
   SimPRO Agent — Theme CRM cao cấp (overlay, nạp sau cùng).
   Hệ thiết kế: typography & spacing chuẩn, control đồng bộ 40px,
   viền hairline + đổ bóng tinh tế, chi tiết nét & tỉ mỉ.
   ============================================================ */
:root {
    --brand: #4f46e5;
    --brand-d: #4338ca;
    --brand-dd: #3730a3;
    --brand-soft: #eef2ff;
    --brand-ring: rgba(79,70,229,.14);

    --side1: #0b1220;
    --side2: #141d33;

    --bg: #f2f3f7;
    --surface: #ffffff;
    --ink: #0b1220;          /* tiêu đề — đậm, rõ nét */
    --text: #111827;         /* nội dung */
    --muted: #5b6675;
    --muted2: #8a93a3;
    --line: #dde0e8;         /* viền rõ hơn */
    --line2: #e8eaf0;        /* viền nhạt (row) */

    --radius: 8px;
    --radius-sm: 6px;
    --radius-xs: 4px;
    --ctl-h: 36px;
    --ctl-h-sm: 30px;
    --sidew: 252px;
    --toph: 60px;

    --ok: #16a34a; --warn: #d97706; --danger: #e11d48; --info: #0ea5e9;

    --shadow-xs: 0 1px 2px rgba(16,24,40,.05);
    --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.04);
    --shadow-md: 0 4px 16px -4px rgba(16,24,40,.12);
    --shadow-lg: 0 24px 56px -12px rgba(16,24,40,.32);
}

* { box-sizing: border-box; }

/* Font dùng chung: Be Vietnam Pro (hợp tiếng Việt) */
body, body.loading,
.btn, .form-control, .custom-select, select, textarea, input, .badge, .dropdown-item,
.table, h1, h2, h3, h4, h5, h6, .modal, .swal2-popup, .toast-title, .toast-text {
    font-family: 'Be Vietnam Pro','Inter',system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif !important;
}
body, body.loading {
    background: var(--bg) !important;
    color: var(--text) !important;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.55;
    margin: 0;
    letter-spacing: .1px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    visibility: visible !important; opacity: 1 !important;
}
h1, h2, h3, h4, h5, h6 { color: var(--ink); letter-spacing: -.01em; }
p, td, th, span, div, label, a, li { font-weight: inherit; }
.text-muted, small, .small { font-weight: 500; }
::selection { background: rgba(79,70,229,.16); }
:focus-visible { outline: 2px solid var(--brand-ring); outline-offset: 2px; }

/* Scrollbar mảnh, tinh tế */
* { scrollbar-width: thin; scrollbar-color: #c9cfdc transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cbd2e0; border-radius: 10px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #aeb7ca; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* Ẩn phần thừa của theme Hyper cũ */
#topnav, .navbar-custom, .topnav, .right-bar, .rightbar-overlay, .footer.footer { display: none !important; }
#wrapper { display: block; }
.content-page { margin: 0 !important; padding: 0 !important; min-height: 100vh; }
.content { padding: 0 !important; }

/* ---------- Shell ---------- */
.crm-sidebar {
    position: fixed; top: 0; left: 0; width: var(--sidew); height: 100vh; z-index: 1040;
    background: linear-gradient(190deg, var(--side1), var(--side2));
    display: flex; flex-direction: column; overflow-y: auto;
    border-right: 1px solid rgba(255,255,255,.05);
}
.crm-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); background-clip: content-box; }
.crm-brand { height: var(--toph); display: flex; align-items: center; padding: 0 22px; border-bottom: 1px solid rgba(255,255,255,.06); position: sticky; top: 0; background: var(--side1); z-index: 2; }
.crm-brand img { max-height: 30px; }
.crm-brand .crm-brand-text { color: #fff; font-weight: 700; font-size: 1.15rem; letter-spacing: .2px; }
.crm-brand .crm-brand-text span { color: #8b9bff; }
.crm-nav { padding: 14px 12px 30px; }
.crm-nav-section { color: rgba(255,255,255,.38); font-size: .64rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; margin: 18px 12px 7px; }
.crm-nav a {
    display: flex; align-items: center; gap: 12px; padding: 9px 12px; margin: 2px 0; border-radius: var(--radius-sm);
    color: rgba(255,255,255,.72); text-decoration: none; font-weight: 500; font-size: .875rem; transition: background .15s, color .15s;
    position: relative;
}
.crm-nav a i { font-size: 1.1rem; opacity: .85; width: 20px; text-align: center; }
.crm-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.crm-nav a:hover i { opacity: 1; }
.crm-nav a.active {
    background: linear-gradient(90deg, var(--brand), var(--brand-d));
    color: #fff; font-weight: 600; box-shadow: 0 8px 18px -8px rgba(79,70,229,.8);
}
.crm-nav a.active i { opacity: 1; }

.crm-main { margin-left: var(--sidew); min-height: 100vh; }
.crm-topbar {
    height: var(--toph); position: sticky; top: 0; z-index: 1030;
    background: rgba(255,255,255,.8); backdrop-filter: saturate(180%) blur(12px); -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 14px; padding: 0 24px;
}
.crm-topbar .crm-page-title { font-weight: 700; font-size: 1.02rem; color: var(--ink); letter-spacing: -.01em; }
.crm-burger { display: none; background: none; border: 0; font-size: 1.5rem; color: var(--text); cursor: pointer; }
.crm-topbar .crm-spacer { flex: 1; }
.crm-content { padding: 18px 20px; max-width: 1520px; }

/* user menu trong topbar */
.crm-topbar .nav-user, .crm-topbar .dropdown-toggle { display: inline-flex; align-items: center; gap: 8px; color: var(--text) !important; text-decoration: none; font-weight: 600; }
.crm-topbar .nav-user img, .crm-topbar img.rounded-circle { width: 34px; height: 34px; object-fit: cover; border-radius: 50%; box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--line); }

/* ---------- Bootstrap component overrides ---------- */
a { color: var(--brand); }
a:hover { color: var(--brand-d); }
.card { background: var(--surface); border: 1px solid var(--line) !important; border-radius: var(--radius) !important; box-shadow: var(--shadow) !important; margin-bottom: 16px; }
.card-body { padding: 16px 18px; }
.card-header { background: transparent; border-bottom: 1px solid var(--line); padding: 12px 18px; font-weight: 700; color: var(--ink); }
.card-title, .header-title { font-weight: 700 !important; color: var(--ink); letter-spacing: -.01em; }

.page-title-box, .page-title-box-alt { padding: 0 0 16px !important; border: 0 !important; }
.page-title { font-size: 1.18rem !important; font-weight: 700 !important; color: var(--ink); letter-spacing: -.02em; }
.breadcrumb { background: transparent; padding: 0; }

/* Buttons — chiều cao đồng bộ control (40px) */
.btn {
    border-radius: var(--radius-sm) !important; font-weight: 600; font-size: .82rem; padding: 0 .85rem;
    border: 1px solid transparent; transition: background .15s, border-color .15s, box-shadow .15s, transform .04s; box-shadow: none;
    min-height: var(--ctl-h); display: inline-flex; align-items: center; justify-content: center; gap: 6px; line-height: 1; letter-spacing: .1px; vertical-align: middle;
}
.btn:active { transform: translateY(1px); }
.btn-block { display: flex !important; width: 100%; }
.btn > i { line-height: 1; font-size: 1.05em; }
.btn-sm { padding: 0 .7rem; font-size: .8rem; min-height: var(--ctl-h-sm); gap: 5px; border-radius: var(--radius-xs) !important; }
.btn-xs { padding: 0 .55rem; font-size: .76rem; min-height: 27px; gap: 4px; border-radius: var(--radius-xs) !important; }
.input-group .btn, .input-group-append .btn, .input-group-prepend .btn { min-height: var(--ctl-h); }
.input-group-sm .btn, .input-group .btn-sm { min-height: var(--ctl-h-sm); }
.btn-primary, .btn-custom { background: var(--brand) !important; border-color: var(--brand) !important; color: #fff !important; box-shadow: 0 1px 2px rgba(67,56,202,.35); }
.btn-primary:hover, .btn-custom:hover { background: var(--brand-d) !important; border-color: var(--brand-d) !important; box-shadow: 0 4px 12px -2px rgba(67,56,202,.45); }
.btn-success { background: var(--ok) !important; border-color: var(--ok) !important; color:#fff !important; box-shadow: 0 1px 2px rgba(22,163,74,.3); }
.btn-success:hover { background: #15803d !important; border-color: #15803d !important; }
.btn-danger { background: var(--danger) !important; border-color: var(--danger) !important; color:#fff !important; box-shadow: 0 1px 2px rgba(225,29,72,.3); }
.btn-danger:hover { background: #be123c !important; border-color: #be123c !important; }
.btn-warning { background: var(--warn) !important; border-color: var(--warn) !important; color:#fff !important; }
.btn-info { background: var(--info) !important; border-color: var(--info) !important; color:#fff !important; }
.btn-light, .btn-white, .btn-secondary { background: #fff !important; border-color: var(--line) !important; color: #374151 !important; }
.btn-light:hover, .btn-white:hover, .btn-secondary:hover { background: #f4f5f9 !important; border-color: #d8dce6 !important; }
.btn-outline-primary { color: var(--brand) !important; border-color: var(--brand) !important; background: transparent !important; }
.btn-outline-primary:hover { background: var(--brand) !important; color: #fff !important; }
.btn-rounded { border-radius: 999px !important; }

/* Forms */
.form-control, .custom-select, select.form-control, select, textarea.form-control, .select2-container--default .select2-selection--single {
    border: 1px solid var(--line) !important; border-radius: var(--radius-sm) !important; padding: .4rem .7rem; font-size: .85rem;
    line-height: 1.4; color: var(--text); background-color: #fff; min-height: var(--ctl-h); box-shadow: none !important;
    transition: border-color .15s, box-shadow .15s;
}
textarea.form-control { min-height: 84px; line-height: 1.55; }
.form-control::placeholder { color: var(--muted2); }
select option { padding: 8px 10px; line-height: 1.6; }
.form-control:focus, .custom-select:focus, select:focus, textarea.form-control:focus {
    border-color: var(--brand) !important; box-shadow: 0 0 0 3.5px var(--brand-ring) !important; outline: 0;
}
.form-control:hover:not(:focus), select:hover:not(:focus) { border-color: #d4d8e3 !important; }
.form-control-sm, .custom-select-sm, .form-select-sm { min-height: var(--ctl-h-sm) !important; font-size: .82rem; padding: .3rem .6rem; border-radius: var(--radius-xs) !important; }
label, .col-form-label { font-weight: 600; font-size: .8rem; color: #3a4759; margin-bottom: .35rem; letter-spacing: .1px; }
select.form-control, select.custom-select, select {
    -webkit-appearance: none; -moz-appearance: none; appearance: none; padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7280' 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");
    background-repeat: no-repeat; background-position: right 13px center;
}
.input-group-text { border-radius: var(--radius-sm); border-color: var(--line); background: #f7f8fb; color: var(--muted); font-size: .85rem; }
/* Ảnh/giấy tờ trong bảng (vd icon PDF trang Người đứng tên) — giới hạn kích thước */
.avt-table { width: 46px !important; height: 46px !important; object-fit: cover; border-radius: var(--radius-xs); border: 1px solid var(--line); background: #fff; }
.contact-img, .avatar-md { object-fit: cover; }
.table img.rounded-circle { width: 34px; height: 34px; object-fit: cover; }
/* Select2 hợp theme */
.select2-container--default .select2-selection--single { height: var(--ctl-h) !important; display: flex; align-items: center; }
.select2-container--default .select2-selection--single .select2-selection__arrow { height: 38px; }
.select2-container--default.select2-container--focus .select2-selection--single { border-color: var(--brand) !important; box-shadow: 0 0 0 3.5px var(--brand-ring); }
.select2-dropdown { border-color: var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); }
.select2-container--default .select2-results__option--highlighted[aria-selected] { background: var(--brand); }

/* Tables */
.table { color: var(--text); margin-bottom: 0; }
.table thead th {
    background: #f7f8fb; color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700;
    border-bottom: 1px solid var(--line) !important; border-top: 0 !important; padding: 9px 12px; white-space: nowrap;
}
.table td { padding: 9px 12px; vertical-align: middle; border-top: 1px solid var(--line2) !important; font-variant-numeric: tabular-nums; font-size: .85rem; }
.table tbody tr:first-child td { border-top: 0 !important; }
.table-hover tbody tr, .table tbody tr { transition: background .12s; }
.table-hover tbody tr:hover, .table tbody tr:hover { background: #f7f8fc; }
.table-striped tbody tr:nth-of-type(odd) { background: #fafbfd; }
.table-centered td, .table-centered th { vertical-align: middle; }
.table-responsive { border-radius: var(--radius-sm); }

/* Badges */
.badge { font-weight: 700; padding: .32em .56em; border-radius: var(--radius-xs); font-size: .72rem; letter-spacing: .2px; border: 1px solid transparent; }
.badge-success, .bg-success { background: #d6f5e0 !important; color: #047857 !important; border-color: #a7e8c0 !important; }
.badge-danger, .bg-danger { background: #ffdfe2 !important; color: #be123c !important; border-color: #ffc1c7 !important; }
.badge-warning, .bg-warning { background: #fdedc8 !important; color: #b45309 !important; border-color: #f8d98c !important; }
.badge-info, .bg-info { background: #d6ebfe !important; color: #1d4ed8 !important; border-color: #aed6fc !important; }
.badge-primary, .bg-primary { background: var(--brand-soft) !important; color: var(--brand-d) !important; border-color: #c7d0fb !important; }
.badge-secondary, .bg-secondary { background: #eaedf3 !important; color: #334155 !important; border-color: #d7dce6 !important; }

/* Modal */
.modal-content { border: 0; border-radius: var(--radius); box-shadow: var(--shadow-lg); overflow: hidden; }
.modal-header { border-bottom: 1px solid var(--line); padding: 17px 22px; }
.modal-title { font-weight: 700; color: var(--ink); }
.modal-body { padding: 20px 22px; }
.modal-footer { border-top: 1px solid var(--line); padding: 14px 22px; }
.modal-backdrop.show { opacity: .4; }

/* Pagination */
.pagination { gap: 5px; }
.page-link { border-radius: var(--radius-xs) !important; border-color: var(--line); color: var(--text); min-width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; font-size: .85rem; font-weight: 600; }
.page-link:hover { background: var(--brand-soft); border-color: var(--brand-soft); color: var(--brand-d); }
.page-item.active .page-link { background: var(--brand); border-color: var(--brand); box-shadow: 0 4px 10px -3px rgba(79,70,229,.6); }

/* Dropdown menu (BS4) */
.dropdown-menu { border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 7px; font-size: .875rem; }
.dropdown-item { border-radius: var(--radius-xs); padding: 8px 12px; font-size: .875rem; font-weight: 500; }
.dropdown-item:hover { background: var(--brand-soft); color: var(--brand-d); }
.dropdown-divider { border-color: var(--line2); }

/* Tabs */
.nav-tabs { border-bottom: 1px solid var(--line); }
.nav-tabs .nav-link { border: 0; color: var(--muted); font-weight: 600; padding: 11px 16px; font-size: .9rem; border-bottom: 2px solid transparent; transition: color .15s, border-color .15s; }
.nav-tabs .nav-link:hover { color: var(--ink); border-bottom-color: var(--line); }
.nav-tabs .nav-link.active { color: var(--brand); border-bottom: 2px solid var(--brand); background: transparent; }
.nav-pills .nav-link { border-radius: var(--radius-xs); font-weight: 600; color: var(--muted); }
.nav-pills .nav-link.active { background: var(--brand); color: #fff; }

/* Alerts */
.alert { border-radius: var(--radius-sm); border: 1px solid transparent; padding: 13px 16px; font-size: .9rem; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

/* Misc text helpers giữ tương thích */
.text-primary { color: var(--brand) !important; }
.text-muted { color: var(--muted) !important; }
hr { border-color: var(--line2); }

/* ---------- Sidebar menu cấp 2 ---------- */
.crm-group .crm-parent { display: flex; align-items: center; gap: 12px; padding: 9px 12px; margin: 2px 0; border-radius: var(--radius-sm);
    color: rgba(255,255,255,.72); cursor: pointer; font-weight: 600; font-size: .875rem; transition: background .15s, color .15s; }
.crm-group .crm-parent:hover { background: rgba(255,255,255,.06); color: #fff; }
.crm-group .crm-parent i:first-child { font-size: 1.1rem; width: 20px; text-align: center; opacity: .85; }
.crm-group .crm-caret { margin-left: auto; transition: transform .2s; font-size: 1rem; opacity: .6; }
.crm-group.open .crm-caret { transform: rotate(180deg); }
.crm-sub { display: none; margin: 2px 0 6px 19px; padding-left: 9px; border-left: 1.5px solid rgba(255,255,255,.1); }
.crm-group.open .crm-sub { display: block; }
.crm-sub a { display: block; padding: 7px 12px; margin: 1px 0; border-radius: var(--radius-xs); color: rgba(255,255,255,.6);
    font-size: .835rem; font-weight: 500; text-decoration: none; transition: background .15s, color .15s; }
.crm-sub a:hover { background: rgba(255,255,255,.06); color: #fff; }
.crm-sub a.active { background: var(--brand); color: #fff; font-weight: 600; }

/* ---------- Modal chi tiết đơn hàng (#viewmodal) ---------- */
#viewmodal .modal-content { background: var(--bg) !important; border: 0 !important; border-radius: 16px; overflow: hidden; }
#viewmodal .modal-header { background: #fff !important; border-bottom: 1px solid var(--line) !important; padding: 14px 20px; }
#viewmodal .modal-header #titleOrder { font-weight: 700; font-size: 1.1rem; color: var(--ink); }
#viewmodal .modal-body { max-height: 86vh; overflow-y: auto; padding: 16px; }
#viewmodal .card { box-shadow: var(--shadow) !important; }
#viewmodal img { max-width: 100%; height: auto; }
#viewmodal .rounded-circle, #viewmodal .chat-admin img, #viewmodal .avatar-md, #viewmodal .contact-img {
    width: 36px !important; height: 36px !important; object-fit: cover !important; border-radius: 50% !important; flex: 0 0 auto; }
#viewmodal #customer-info img, #viewmodal #ownerSim img { width: 40px !important; height: 40px !important; object-fit: cover; border-radius: 8px !important; }
#viewmodal .nav-pills .nav-link { border-radius: 8px; font-weight: 600; padding: 7px 12px; }
#viewmodal .nav-pills .nav-link.active { background: var(--brand); color: #fff; }
#viewmodal h5.bg-warning, #viewmodal .text-white.bg-warning { background: var(--brand) !important; color: #fff !important; border-radius: 10px 10px 0 0; }
#viewmodal .chat-detail { max-height: 360px; overflow-y: auto; }
#viewmodal .chat-footer { padding: 10px 12px; }
#viewmodal .chat-footer .row { align-items: center; }
#viewmodal .chat-footer .col-10 { display: flex; align-items: center; gap: 10px; }
#viewmodal .chat-footer .chat-admin { flex: 0 0 auto; margin: 0; line-height: 0; }
#viewmodal .chat-footer .chat-admin img { width: 36px !important; height: 36px !important; }
#viewmodal .chat-footer .form-control { flex: 1 1 auto; margin: 0; }
#viewmodal select, #viewmodal .order-select { padding: .5rem 2rem .5rem .8rem !important; min-height: var(--ctl-h); }
#viewmodal .table-responsive { overflow-x: auto; }
#viewmodal * { word-break: break-word; }
#feemodal .modal-content, #ownermodal .modal-content, #addmodal .modal-content { border: 0 !important; }

/* ---------- Mobile ---------- */
@media (max-width: 992px) {
    .crm-sidebar { transform: translateX(-100%); transition: transform .25s; box-shadow: var(--shadow-lg); }
    body.crm-sb-open .crm-sidebar { transform: none; }
    .crm-main { margin-left: 0; }
    .crm-burger { display: inline-block; }
    .crm-content { padding: 18px 16px; }
    .crm-sb-backdrop { display: none; position: fixed; inset: 0; background: rgba(2,6,23,.45); z-index: 1035; }
    body.crm-sb-open .crm-sb-backdrop { display: block; }
}
