:root {
  --teal-900: #35267a;
  --teal-700: #5e42d3;
  --teal-600: #6a4fda;
  --teal-500: #7c62e6;
  --teal-050: #ece8fb;
  --ink: #1f2937;
  --ink-2: #4b5563;
  --muted: #6b7280;
  --line: #e2e6ea;
  --bg: #f4f6f8;
  --white: #ffffff;
  --amber: #b45309;
  --red: #dc2626;
  --green: #16a34a;
  --blue: #2563eb;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px; color: var(--ink); background: var(--bg);
}
a { color: var(--teal-700); text-decoration: none; }
button { font-family: inherit; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 238px 1fr; min-height: 100vh; }

/* ---- Thanh bên (sidebar) ---- */
.side { background: #241a48; color: #e4dff5; display: flex; flex-direction: column;
  border-right: 1px solid #362a63; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { display: flex; align-items: center; gap: 11px; padding: 16px 16px 14px; }
.side .brand .logo { width: 38px; height: 38px; border-radius: 9px; color: #fff;
  background: linear-gradient(150deg, #7c62e6, #4a34b0); display: grid; place-items: center;
  font-weight: 800; font-size: 17px; box-shadow: 0 2px 8px rgba(0,0,0,.3); flex: none; }
.side .brand .nm { font-weight: 700; font-size: 16px; line-height: 1.1; letter-spacing: .3px; }
.side .brand .sub { font-size: 11px; color: #9a8fc0; letter-spacing: .3px; margin-top: 2px; }
.navgrp { padding: 2px 12px; }
.navgrp .lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: .11em;
  color: #9a8fc0; padding: 12px 10px 6px; font-weight: 700; }
.navitem { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: transparent; border: 0; color: #e4dff5; padding: 9px 11px; border-radius: 8px;
  cursor: pointer; font-size: 13.5px; font-weight: 500; }
.navitem .ico { font-size: 15px; width: 18px; text-align: center; opacity: .92; flex: none; }
.navitem:hover { background: #1c1440; }
.navitem.active { background: #6a4fda; color: #fff; font-weight: 600; }
.side-foot { margin-top: auto; display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-top: 1px solid #362a63; }
.side-foot .avatar { width: 34px; height: 34px; border-radius: 50%; color: #fff;
  background: linear-gradient(150deg, #7c62e6, #4a34b0); display: grid; place-items: center;
  font-weight: 700; font-size: 14px; flex: none; }
.side-foot .nm2 { font-weight: 600; font-size: 12.5px; line-height: 1.2; }
.side-foot .role { font-size: 11px; color: #9a8fc0; }
.side-foot .logout { margin-left: auto; background: rgba(255,255,255,.1); border: 0; color: #e4dff5;
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 15px; flex: none; }
.side-foot .logout:hover { background: rgba(255,255,255,.22); }

.main { min-width: 0; display: flex; flex-direction: column; }
.main .view { padding: 20px 24px 40px; max-width: 1500px; width: 100%; margin: 0 auto; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: column; }
  .side .brand { display: none; }
}

/* ---------- Panels / cards ---------- */
.panel { background: var(--white); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 14px; }
.panel-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-head h2 { margin: 0; font-size: 15.5px; }
.panel-head .sub { color: var(--muted); font-size: 12.5px; }
.panel-body { padding: 16px; }
.page-title { display: flex; align-items: center; justify-content: space-between; margin: 2px 0 14px; }
.page-title h1 { font-size: 20px; margin: 0; }
.page-title .desc { color: var(--muted); font-size: 13px; margin-top: 2px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.split { display: grid; grid-template-columns: 340px 1fr; gap: 14px; align-items: start; }
@media (max-width: 1100px){ .split { grid-template-columns: 1fr; } .grid-4 { grid-template-columns: 1fr 1fr; } }

/* ---------- Form ---------- */
.field { margin-bottom: 11px; }
.field label { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 4px; font-weight: 600; }
.field label .req { color: var(--red); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; font-size: 13.5px;
  background: #fff; color: var(--ink); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--teal-500); box-shadow: 0 0 0 3px var(--teal-050); }
input[readonly] { background: #f7f8fa; color: var(--muted); }
textarea { resize: vertical; min-height: 60px; }

.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 7px; cursor: pointer; font-size: 13.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: #f7f8fa; }
.btn-primary { background: var(--teal-600); border-color: var(--teal-600); color: #fff; }
.btn-primary:hover { background: var(--teal-700); }
.btn-amber { background: var(--amber); border-color: var(--amber); color: #fff; }
.btn-amber:hover { filter: brightness(.95); }
.btn-danger { background: #fff; border-color: #f3c2c2; color: var(--red); }
.btn-danger:hover { background: #fdeeee; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--teal-700); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Table ---------- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th { text-align: left; background: #f3f7f6; color: var(--ink-2); font-weight: 700; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tbl td { padding: 9px 10px; border-bottom: 1px solid #eef1f3; vertical-align: middle; }
table.tbl tbody tr:hover { background: #fafcfc; }
table.tbl tr.selected { background: var(--teal-050); }
table.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-wrap { overflow-x: auto; }
.clickable { cursor: pointer; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.badge.gray { background: #eef1f3; color: #55606b; }
.badge.blue { background: #e5edff; color: #2549b8; }
.badge.amber { background: #fef3c7; color: #92600a; }
.badge.green { background: #dcfce7; color: #15803d; }
.badge.teal { background: var(--teal-050); color: var(--teal-700); }
.badge.red { background: #fee2e2; color: #b91c1c; }
.badge.purple { background: #ede9fe; color: #6d28d9; }

/* ---------- Stat tiles ---------- */
.stat { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; box-shadow: var(--shadow); }
.stat .k { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat .v { font-size: 24px; font-weight: 800; margin-top: 6px; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat .v.teal { color: var(--teal-700); }
.stat .v.green { color: var(--green); }
.stat .v.red { color: var(--red); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { background: transparent; border: 0; border-bottom: 2px solid transparent; padding: 9px 14px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 13.5px; }
.tabs button.active { color: var(--teal-700); border-bottom-color: var(--teal-600); }

/* ---------- Money summary bar ---------- */
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; background: #f3f7f6; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-top: 12px; }
.summary .item .lbl { color: var(--muted); font-size: 12px; }
.summary .item .val { font-size: 16px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--teal-700), var(--teal-900)); padding: 20px; }
.login-card { background: #fff; border-radius: 14px; padding: 30px 28px; width: 360px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card .logo-lg { width: 56px; height: 56px; border-radius: 13px; background: var(--teal-600); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 24px; margin: 0 auto 12px; }
.login-card h1 { text-align: center; font-size: 20px; margin: 0 0 2px; }
.login-card .tag { text-align: center; color: var(--muted); font-size: 12.5px; margin-bottom: 20px; }
.login-hint { margin-top: 14px; font-size: 12px; color: var(--muted); text-align: center; line-height: 1.6; }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; top: 64px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #111827; color: #fff; padding: 10px 15px; border-radius: 8px; font-size: 13px; box-shadow: 0 8px 20px rgba(0,0,0,.2); animation: slidein .2s ease; max-width: 340px; }
.toast.ok { background: #5e42d3; }
.toast.err { background: #b91c1c; }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: grid; place-items: center; z-index: 90; padding: 20px; }
.modal { background: #fff; border-radius: 12px; width: 620px; max-width: 100%; max-height: 90vh; overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.x { cursor: pointer; border: 0; background: transparent; font-size: 20px; color: var(--muted); line-height: 1; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* Cờ bất thường H/L */
.flag-h { color: #b91c1c; font-weight: 800; }
.flag-l { color: #1d4ed8; font-weight: 800; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.dot.red { background: #dc2626; } .dot.green { background: #16a34a; } .dot.amber { background: #f59e0b; }

/* Phân trang */
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 10px 14px; font-size: 13px; color: var(--muted); }
.pager button { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 4px 10px; cursor: pointer; }
.pager button:disabled { opacity: .4; cursor: not-allowed; }

/* Levey-Jennings mini chart */
.lj { width: 100%; height: 180px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 7px; background: #f3f7f6; font-size: 12.5px; margin: 2px; }
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 1100px){ .kpi-row { grid-template-columns: 1fr 1fr; } }
.card-link { cursor: pointer; transition: transform .08s; }
.card-link:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(16,24,40,.1); }
.pill-list { display: flex; gap: 6px; flex-wrap: wrap; }
.mini { font-size: 12px; color: var(--muted); }
.hr { height: 1px; background: var(--line); margin: 14px 0; border: 0; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }
.search-box { position: relative; }
.autocomplete { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 280px; overflow: auto; z-index: 20; margin-top: 2px; }
.autocomplete .opt { padding: 8px 11px; cursor: pointer; border-bottom: 1px solid #f0f2f4; }
.autocomplete .opt:hover, .autocomplete .opt.hi { background: var(--teal-050); }
.autocomplete .opt .m { font-size: 12px; color: var(--muted); }

/* ---------- Print ---------- */
@media print {
  .topbar, .toast-wrap, .no-print, .btn, .toolbar { display: none !important; }
  body, .main { background: #fff; padding: 0; }
  .print-area { box-shadow: none; border: 0; }
}

/* ---- Đề xuất mua hàng & Tài sản (module bổ sung) ---- */
.filter-chips { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.filter-chips .chip { cursor: pointer; border: 1px solid #dbe3ec; background: #fff; user-select: none; }
.filter-chips .chip.active { background: #5e42d3; color: #fff; border-color: #5e42d3; }
.progress { height: 7px; border-radius: 4px; background: #eef2f6; overflow: hidden; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg,#7c62e6,#5e42d3); border-radius: 4px; }
