/* ==========================================================
   QUANLI5_NV_HSKHACH – Giao diện chung (sidebar + topbar + thẻ)
   Dùng kèm Bootstrap 4.6 và Font Awesome 6.
   ========================================================== */
:root {
    --primary: #3b82f6;
    --primary-light: #60a5fa;
    --primary-glow: rgba(59, 130, 246, 0.10);
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #06b6d4;

    --bg-main: #f1f5f9;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;

    --sidebar-bg: #0f172a;
    --sidebar-text: #cbd5e1;
    --sidebar-width: 250px;
    --sidebar-collapsed-width: 72px;
    --topbar-height: 64px;

    --border-radius: 14px;
    --border-radius-sm: 8px;
    --box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 16px rgba(15, 23, 42, 0.05);
    --transition: all 0.25s ease;
}

html[data-theme="dark"] {
    --primary-glow: rgba(59, 130, 246, 0.16);
    --bg-main: #0b1220;
    --bg-card: #111a2e;
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
    --border-color: #1f2a44;
    --sidebar-bg: #070d1a;
    --box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Inter", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 0.9rem;
    background: var(--bg-main);
    color: var(--text-main);
    transition: background 0.2s, color 0.2s;
}

/* ---------- Layout ---------- */
.app-container { display: flex; min-height: 100vh; }

.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex; flex-direction: column;
    z-index: 1040;
    transition: var(--transition);
    overflow-x: hidden; overflow-y: auto;
}
.main-content {
    flex: 1; min-width: 0;
    margin-left: var(--sidebar-width);
    transition: var(--transition);
}
.page-container { padding: 24px; }

.sidebar-logo { padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.logo-text { font-size: 1.3rem; font-weight: 800; color: #fff; white-space: nowrap; }
.logo-text span { color: var(--info); }
.sidebar-toggle-btn {
    background: rgba(255,255,255,0.06); border: 0; color: var(--sidebar-text);
    width: 30px; height: 30px; border-radius: 8px; cursor: pointer; flex-shrink: 0;
}
.sidebar-toggle-btn:hover { background: rgba(255,255,255,0.12); color: #fff; }

.sidebar-menu { list-style: none; margin: 0; padding: 12px 10px; flex: 1; }
.menu-item { margin-bottom: 2px; }
.menu-item.g-off { display: none; }
.menu-group button { display: flex; align-items: center; justify-content: space-between; width: 100%; border: 0; background: none; padding: 10px 14px 4px; color: #8193ad; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; cursor: pointer; }
.menu-group button:hover { color: #cbd5e1; } .menu-group button i { font-size: .6rem; transition: transform .15s; } .menu-group.shut button i { transform: rotate(-90deg); }
html.sidebar-collapsed .menu-group button { height: 1px; padding: 0; margin: 8px 0; background: rgba(255,255,255,.1); pointer-events: none; } html.sidebar-collapsed .menu-group button * { display: none; }
html.sidebar-collapsed .menu-item.g-off { display: block; }
.menu-link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px; border-radius: 10px;
    color: var(--sidebar-text); white-space: nowrap;
    transition: var(--transition);
}
.menu-link i { width: 20px; text-align: center; font-size: 1rem; }
.menu-link:hover { background: rgba(255,255,255,0.06); color: #fff; text-decoration: none; }
.menu-item.active .menu-link { background: var(--primary); color: #fff; box-shadow: 0 4px 14px rgba(59,130,246,0.35); }

.sidebar-user {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 16px; border-top: 1px solid rgba(255,255,255,0.06);
}
.user-avatar { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; }
.user-name { color: #fff; font-weight: 600; font-size: 0.85rem; white-space: nowrap; }
.user-role { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }

/* Thu gọn sidebar (desktop) */
html.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed-width); }
html.sidebar-collapsed .main-content { margin-left: var(--sidebar-collapsed-width); }
html.sidebar-collapsed .logo-text,
html.sidebar-collapsed .menu-link span,
html.sidebar-collapsed .user-info,
html.sidebar-collapsed .sidebar-logo .fa-folder-open { display: none; }
.brand-ic { border-radius: 9px; margin-right: 10px; flex-shrink: 0; background: #fff; }
.sidebar-logo .logo-text { line-height: 1.05; white-space: nowrap; } .sidebar-logo .logo-text small { display: block; font-size: .58rem; font-weight: 600; letter-spacing: .02em; color: #8193ad; margin-top: 3px; }
html.sidebar-collapsed .brand-ic { margin: 0; width: 34px; height: 34px; } html.sidebar-collapsed .sidebar-logo { flex-direction: column; gap: 8px; }
html.sidebar-collapsed .sidebar-logo { justify-content: center !important; padding: 20px 8px; }
html.sidebar-collapsed .menu-link { justify-content: center; padding: 10px; }
html.sidebar-collapsed .sidebar-user { justify-content: center; padding: 14px 8px; }

/* ---------- Topbar ---------- */
.topbar {
    position: sticky; top: 0; z-index: 1030;
    height: var(--topbar-height);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.page-title { font-size: 1.15rem; font-weight: 700; margin: 0; color: var(--text-main); }
.toggle-sidebar { display: none; }
.toggle-sidebar, .theme-toggle, .notification-bell {
    position: relative;
    width: 38px; height: 38px; border-radius: 10px;
    border: 1px solid var(--border-color); background: var(--bg-card);
    color: var(--text-muted); cursor: pointer; transition: var(--transition);
}
.toggle-sidebar:hover, .theme-toggle:hover, .notification-bell:hover { color: var(--primary); border-color: var(--primary); }
.notification-badge {
    position: absolute; top: 7px; right: 8px;
    width: 8px; height: 8px; border-radius: 50%; background: var(--danger);
}

/* ---------- Thẻ / bảng ---------- */
.filter-panel, .report-table-card, .summary-card, .dm-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}
.filter-panel { padding: 20px 24px 10px; margin-bottom: 24px; }
.filter-title { font-weight: 700; margin-bottom: 14px; color: var(--text-main); }
.filter-title i { color: var(--primary); margin-right: 6px; }
.report-table-card { overflow: hidden; margin-bottom: 24px; }
.table-header {
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
    padding: 16px 24px; border-bottom: 1px solid var(--border-color);
}
.table-title { font-weight: 700; font-size: 1rem; }
.record-count {
    font-size: 0.78rem; font-weight: 600; padding: 4px 12px; border-radius: 50px;
    background: var(--primary-glow); color: var(--primary);
}

.custom-table { color: var(--text-main); }
.custom-table thead th {
    background: var(--bg-main); color: var(--text-muted);
    font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
    border-top: 0; border-bottom: 1px solid var(--border-color); white-space: nowrap;
    padding: 12px 14px;
}
/* Bảng danh sách chính: dòng tiêu đề cột luôn cố định khi cuộn (bảng tự cuộn trong khung cao gần bằng màn hình) */
.tbl-sticky { max-height: calc(100vh - 120px); overflow: auto; }
.tbl-sticky > table > thead { position: sticky; top: 0; z-index: 6; }
.tbl-sticky > table > thead th { background: var(--bg-main); box-shadow: inset 0 -1px 0 var(--border-color); }
/* bản sao dòng tiêu đề khi cuộn cả trang (vitri1_app.js) */
.float-head { position: fixed; z-index: 1025; overflow: hidden; background: var(--bg-main); box-shadow: 0 3px 8px rgba(0,0,0,.10); }
.float-head table { background: var(--bg-main); }
.float-head thead th { background: var(--bg-main); box-shadow: inset 0 -1px 0 var(--border-color); }
@media print { .tbl-sticky { max-height: none; overflow: visible; } .float-head { display: none !important; } }
.custom-table td { border-top: 1px solid var(--border-color); vertical-align: middle; padding: 12px 14px; }
.custom-table tbody tr:hover { background: var(--primary-glow); }
.action-btns { display: flex; gap: 6px; white-space: nowrap; }
.mono { font-family: Consolas, "Courier New", monospace; }

/* Thẻ tổng quan */
.summary-card { display: flex; align-items: center; gap: 14px; padding: 20px; height: 100%; }
.summary-icon {
    width: 52px; height: 52px; border-radius: 12px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-size: 1.3rem;
}
.summary-icon.blue  { background: rgba(59,130,246,.12); color: #3b82f6; }
.summary-icon.red   { background: rgba(239,68,68,.12);  color: #ef4444; }
.summary-icon.green { background: rgba(16,185,129,.12); color: #10b981; }
.summary-icon.cyan  { background: rgba(6,182,212,.12);  color: #06b6d4; }
.summary-icon.teal  { background: rgba(20,184,166,.12); color: #14b8a6; }
.summary-icon.amber { background: rgba(245,158,11,.12); color: #f59e0b; }
.summary-icon.purple{ background: rgba(139,92,246,.12); color: #8b5cf6; }
.summary-label { font-size: 0.78rem; color: var(--text-muted); }
.summary-value { font-size: 1.5rem; font-weight: 800; color: var(--text-main); white-space: nowrap; }
.summary-meta { min-width: 0; }

.report-banner {
    padding: 22px 26px; border-radius: var(--border-radius); color: #fff;
    background: linear-gradient(135deg, #2563eb 0%, #06b6d4 100%);
    box-shadow: 0 8px 24px rgba(37,99,235,.25);
}
.report-banner-title { font-size: 1.25rem; font-weight: 800; }
.report-banner-sub { margin: 6px 0 0; opacity: .9; }
.report-progress { height: 8px; border-radius: 4px; background: var(--border-color); overflow: hidden; }
.report-progress-bar { height: 100%; border-radius: 4px; background: var(--primary); }

/* Chọn cột */
.col-selector-container { position: relative; }
.col-selector-dropdown {
    display: none; position: absolute; right: 0; top: calc(100% + 6px); z-index: 1050;
    width: 260px; max-height: 360px; overflow-y: auto; padding: 8px;
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm); box-shadow: 0 10px 30px rgba(15,23,42,.15);
}
.col-selector-dropdown.show { display: block; }
.col-selector-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; }
.col-selector-item:hover { background: var(--primary-glow); }
.col-selector-item label { margin: 0; cursor: pointer; flex: 1; }

/* ---------- Form, nút, modal theo theme ---------- */
.form-control, .custom-select {
    background-color: var(--bg-card); color: var(--text-main);
    border: 1px solid var(--border-color); border-radius: var(--border-radius-sm);
    min-height: 40px;
}
.form-control-sm, .custom-select-sm { min-height: 31px; }
.form-control:focus, .custom-select:focus {
    background-color: var(--bg-card); color: var(--text-main);
    border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow);
}
.form-label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 6px; }
.btn { border-radius: var(--border-radius-sm); font-weight: 600; }
.btn i { margin-right: 4px; }
.btn-secondary { background: var(--bg-main); color: var(--text-main); border-color: var(--border-color); }
.btn-secondary:hover { background: var(--border-color); color: var(--text-main); border-color: var(--border-color); }
.text-main { color: var(--text-main) !important; }
.text-muted { color: var(--text-muted) !important; }
.modal-content { background: var(--bg-card); color: var(--text-main); }
.close { color: var(--text-main); }
.nav-tabs, .nav-tabs .nav-link { border-color: var(--border-color); }
.nav-link { color: var(--text-muted); }
.nav-link.active { font-weight: 700; }
html[data-theme="dark"] .nav-tabs .nav-link.active { background: var(--bg-card); color: var(--text-main); }
html[data-theme="dark"] .table { color: var(--text-main); }
html[data-theme="dark"] .border-top { border-color: var(--border-color) !important; }

/* ---------- Toast ---------- */
.toast-container {
    position: fixed; top: 20px; right: 20px; z-index: 2000;
    display: flex; flex-direction: column; gap: 10px;
}
.toast-container .toast {
    display: flex; align-items: center; gap: 10px;
    flex-basis: auto; height: auto;
    min-width: 260px; max-width: 380px; padding: 12px 16px; opacity: 1;
    background: var(--bg-card); color: var(--text-main);
    border: 1px solid var(--border-color); border-left: 4px solid var(--success);
    border-radius: var(--border-radius-sm); box-shadow: 0 10px 30px rgba(15,23,42,.15);
    transition: all .3s ease;
}
.toast-container .toast.success { border-left-color: var(--success); }
.toast-container .toast.success .toast-icon { color: var(--success); }
.toast-container .toast.danger  { border-left-color: var(--danger); }
.toast-container .toast.danger .toast-icon  { color: var(--danger); }
.toast-container .toast.warning { border-left-color: var(--warning); }
.toast-container .toast.warning .toast-icon { color: var(--warning); }
.toast-container .toast.info    { border-left-color: var(--info); }
.toast-container .toast.info .toast-icon    { color: var(--info); }
.toast-icon { font-size: 1.15rem; }
.toast-message { flex: 1; font-size: 0.85rem; }

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); width: var(--sidebar-width) !important; }
    .sidebar.show { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.4); }
    .main-content, html.sidebar-collapsed .main-content { margin-left: 0; }
    .toggle-sidebar { display: inline-flex; align-items: center; justify-content: center; }
    .sidebar-toggle-btn { display: none; }
    .page-container { padding: 16px; }
    .topbar { padding: 0 16px; }
    .page-title { font-size: 1rem; }
}

/* ---------- Badge tình trạng ---------- */
.badge-custom {
    display: inline-block; padding: 5px 10px; border-radius: 50px;
    font-size: 0.72rem; font-weight: 700; letter-spacing: .02em; white-space: nowrap;
}
.badge-status-theo-doi { background: rgba(59,130,246,.12); color: #2563eb; }
.badge-status-dau      { background: rgba(16,185,129,.14); color: #059669; }
.badge-status-rot      { background: rgba(239,68,68,.12);  color: #dc2626; }
.badge-status-do-gia   { background: rgba(245,158,11,.14); color: #d97706; }
.badge-status-khac     { background: rgba(100,116,139,.14); color: #64748b; }
.report-banner .badge-custom { background: rgba(255,255,255,.95); }

/* ---------- Form Tạo / Sửa ---------- */
.form-section .form-group { margin-bottom: 14px; }
.form-actions {
    position: sticky; bottom: 0; z-index: 10;
    display: flex; justify-content: flex-end; gap: 10px;
    padding: 14px 0; background: var(--bg-main);
}
.custom-control-label { cursor: pointer; }

/* ---------- Trang chi tiết ---------- */
.info-item { margin-bottom: 14px; }
.info-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); font-weight: 600; }
.info-value { margin-top: 2px; word-break: break-word; }
.doc-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 10px; border-radius: 50px; font-size: 0.72rem; font-weight: 600;
    background: var(--bg-main); color: var(--text-muted); border: 1px solid var(--border-color);
}
.doc-chip i { font-size: 0.65rem; opacity: .5; }
.doc-chip.on { background: rgba(16,185,129,.12); color: #059669; border-color: rgba(16,185,129,.3); }
.doc-chip.on i { opacity: 1; font-size: 0.8rem; }

.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--border-color); }
.timeline li { position: relative; padding: 0 0 16px 10px; }
.timeline li::before {
    content: ""; position: absolute; left: -25px; top: 4px;
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--info); border: 2px solid var(--bg-card);
}
.timeline li.tl-success::before { background: var(--success); }
.timeline li.tl-warning::before { background: var(--warning); }
.timeline li.tl-danger::before  { background: var(--danger); }
.tl-body { font-size: 0.85rem; margin-top: 2px; }

@media print {
    .sidebar, .topbar, .btn, .form-actions { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .page-container { padding: 0; }
}

/* ---------- OCR giấy tờ ---------- */
.ocr-panel { border-style: dashed; border-color: var(--primary-light); }
.ocr-drop {
    display: flex; align-items: center; gap: 10px; cursor: pointer; margin: 0;
    min-height: 40px; padding: 8px 14px; border: 1px dashed var(--border-color);
    border-radius: var(--border-radius-sm); background: var(--bg-main); color: var(--text-muted);
    transition: var(--transition);
}
.ocr-drop:hover, .ocr-drop.drag { border-color: var(--primary); background: var(--primary-glow); color: var(--primary); }
.ocr-drop i { font-size: 1.1rem; }
.ocr-filled { box-shadow: 0 0 0 3px rgba(16,185,129,.35) !important; border-color: var(--success) !important; }

/* ---------- điện thoại: tab cuộn ngang, vùng bấm đủ lớn, hộp thoại tràn màn hình ---------- */
@media (max-width: 768px) {
    .nav-tabs { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
    .nav-tabs::-webkit-scrollbar { display: none; }
    .nav-tabs .nav-link { white-space: nowrap; }
    .topbar-right { gap: 8px; }
    .topbar-right > span:first-child:not([id]) { display: none; }
    .page-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 46vw; }
    .modal-dialog { margin: 8px; max-width: none; }
    input.form-control, select.custom-select, textarea.form-control { font-size: 16px; }
    .table-header .d-flex > input.form-control, .table-header .d-flex > .custom-select { max-width: 100%; }
}
a:focus-visible, button:focus-visible, .nav-link:focus-visible { outline: 2px solid var(--primary, #3b82f6); outline-offset: 2px; }
