/* ========= Quan ly kho hang - giao dien ========= */
:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --line: #e4e8f0;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}
.hidden { display: none !important; }

/* ---------- Dang nhap ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px;
}
.login-card {
  background: var(--card); padding: 28px 24px; border-radius: 14px; box-shadow: var(--shadow);
  width: 100%; max-width: 360px;
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p.sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }

/* ---------- Khung chinh ---------- */
header.topbar {
  background: var(--primary); color: #fff; padding: 10px 16px;
  display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 20;
}
header.topbar .title { font-weight: 700; font-size: 17px; }
header.topbar .spacer { flex: 1; }
header.topbar .user { font-size: 13px; opacity: .95; }
header.topbar button {
  background: rgba(255,255,255,.15); color: #fff; border: none; padding: 6px 12px;
  border-radius: 8px; cursor: pointer; font-size: 13px;
}
header.topbar button:hover { background: rgba(255,255,255,.28); }

.pw-warn { background: #fde8e8; color: #9b1c1c; padding: 9px 16px; font-size: 14px; text-align: center; border-bottom: 1px solid #f5c2c2; }
.pw-warn a { color: #9b1c1c; font-weight: 700; }

nav.tabs {
  display: flex; gap: 4px; background: var(--card); padding: 8px 12px;
  border-bottom: 1px solid var(--line); overflow-x: auto; position: sticky; top: 44px; z-index: 15;
}
nav.tabs button {
  border: none; background: transparent; padding: 8px 14px; border-radius: 8px;
  cursor: pointer; font-size: 14px; color: var(--muted); white-space: nowrap;
}
nav.tabs button.active { background: #eaf0ff; color: var(--primary-d); font-weight: 600; }

main { padding: 16px; max-width: 980px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* ---------- Thanh phan chung ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
input, select, textarea {
  font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px;
  background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d7ff; border-color: var(--primary); }
label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }

button.btn {
  border: none; border-radius: 9px; padding: 9px 14px; cursor: pointer; font: inherit;
  background: var(--primary); color: #fff; font-weight: 600;
}
button.btn:hover { background: var(--primary-d); }
button.btn.gray { background: #eef1f6; color: var(--text); }
button.btn.gray:hover { background: #e2e7ef; }
button.btn.green { background: var(--green); }
button.btn.red { background: var(--red); }
button.btn.sm { padding: 5px 10px; font-size: 13px; font-weight: 600; }
button:disabled { opacity: .55; cursor: not-allowed; }

.search { max-width: 320px; }

/* ---------- Ton kho ---------- */
.product-group { margin-bottom: 14px; overflow: hidden; }
.product-head {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px;
  background: #f8fafc; border-bottom: 1px solid var(--line); font-weight: 700;
}
.product-head .code {
  background: var(--primary); color: #fff; border-radius: 6px; font-size: 12px;
  padding: 2px 8px; font-weight: 700;
}
.product-head .total { margin-left: auto; font-size: 13px; color: var(--muted); font-weight: 500; }
.variant-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid #f1f3f8;
  flex-wrap: wrap;
}
.variant-row:last-child { border-bottom: none; }
.variant-row .meta { flex: 1; min-width: 130px; }
.variant-row .meta .vname { font-weight: 600; }
.variant-row .meta .vsub { color: var(--muted); font-size: 13px; }
.stock-badge {
  font-weight: 700; font-size: 16px; min-width: 52px; text-align: center;
  padding: 4px 8px; border-radius: 8px; background: #eef6ff; color: var(--primary-d);
}
.stock-badge.low { background: #fff3e6; color: var(--amber); }
.stock-badge.zero { background: #fde8e8; color: var(--red); }
.stock-badge small { display: block; font-size: 10px; font-weight: 600; opacity: .7; line-height: 1; margin-top: 1px; }
.pack-tag { background: #eef6ff; color: var(--primary-d); border-radius: 6px; padding: 1px 7px; font-size: 12px; font-weight: 600; }

/* ---------- Tooltip chi tiet ton kho ---------- */
.has-tip { cursor: help; }
.has-tip:hover { outline: 2px solid #c7d7ff; outline-offset: 1px; }
.vtip {
  position: absolute; z-index: 200; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 12px 32px rgba(15,23,42,.22); padding: 10px 12px;
  max-width: 340px; font-size: 13px; color: var(--text);
}
.vtip-head { font-weight: 700; margin-bottom: 6px; }
.vtip-tbl { width: 100%; border-collapse: collapse; }
.vtip-tbl td { padding: 4px 0; border-bottom: 1px solid #f1f3f8; }
.vtip-tbl tr:last-child td { border-bottom: none; }
.vtip-tbl td.r { text-align: right; white-space: nowrap; padding-left: 16px; }
.vtip-tbl .tred { color: var(--red); }
.vtip-tbl .tamber { color: var(--amber); }
.vtip-tbl .tok { color: var(--primary-d); }
.row-actions { display: flex; gap: 6px; }

table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th, table.tbl td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
table.tbl th { background: #f8fafc; color: var(--muted); font-weight: 600; position: sticky; top: 0; }
table.tbl tr:hover td { background: #fafbfe; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 20px; font-weight: 600; }
.pill.in { background: #e7f6ee; color: var(--green); }
.pill.out { background: #fde8e8; color: var(--red); }
.pill.adjust { background: #eef1f6; color: var(--muted); }
.pill.admin { background: #eaf0ff; color: var(--primary-d); }
.pill.staff { background: #eef1f6; color: var(--muted); }

.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.help { background: #f0f7ff; border: 1px solid #cfe2ff; border-radius: 10px; padding: 12px 14px; font-size: 13px; color: #334155; margin-bottom: 14px; }
.help code { background: #fff; padding: 1px 5px; border-radius: 4px; border: 1px solid var(--line); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
@media (max-width: 560px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.qty-cell { display: flex; gap: 5px; align-items: center; }
.qty-cell input { min-width: 56px; }
.qty-cell select { width: auto; padding: 7px 6px; }

/* ---------- Modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex;
  align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.modal {
  background: #fff; border-radius: 14px; padding: 20px; width: 100%; max-width: 420px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25); max-height: 90vh; overflow: auto;
}
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ---------- Thong bao ---------- */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 11px 18px; border-radius: 10px;
  font-size: 14px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.3); max-width: 90%;
}
#toast.err { background: var(--red); }
#toast.ok { background: var(--green); }

.section-title { font-size: 15px; font-weight: 700; margin: 0 0 10px; }
.add-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.add-bar .field { margin-bottom: 0; }
.add-bar > div { flex: 1; min-width: 120px; }

/* ---------- Gia tien ---------- */
.price { color: var(--green); font-weight: 600; }
.price.zero { color: var(--muted); font-weight: 400; }
.value-tag { font-size: 13px; color: var(--muted); }

/* ---------- Modal rong (form them san pham) ---------- */
.modal.modal-wide { max-width: 680px; }
.vwrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table.vtable { width: 100%; border-collapse: collapse; min-width: 540px; }
table.vtable th { background: #f8fafc; color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); }
table.vtable td { padding: 5px 6px; border-bottom: 1px solid #f1f3f8; }
table.vtable tr:last-child td { border-bottom: none; }
table.vtable input { padding: 7px 8px; border-radius: 7px; }
table.vtable .col-num { width: 92px; }
table.vtable .col-x { width: 38px; text-align: center; }
table.vtable button.x { background: #fde8e8; color: var(--red); border: none; border-radius: 7px; padding: 6px 9px; cursor: pointer; font-weight: 700; }
table.vtable button.x:hover { background: #fbd5d5; }

/* ---------- Bang bien the trong the san pham ---------- */
table.vlist { width: 100%; border-collapse: collapse; }
table.vlist th { background: #fbfcfe; color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; padding: 8px 14px; border-bottom: 1px solid var(--line); }
table.vlist td { padding: 9px 14px; border-bottom: 1px solid #f1f3f8; font-size: 14px; vertical-align: middle; }
table.vlist tr:last-child td { border-bottom: none; }
table.vlist .num { text-align: right; white-space: nowrap; }
.prod-foot { padding: 10px 14px; border-top: 1px solid var(--line); background: #fbfcfe; }
.stock-mini { font-weight: 700; padding: 2px 9px; border-radius: 7px; background: #eef6ff; color: var(--primary-d); }
.stock-mini.low { background: #fff3e6; color: var(--amber); }
.stock-mini.zero { background: #fde8e8; color: var(--red); }

/* ---------- Tong ton kho cua san pham (noi bat) ---------- */
.product-head .pname { font-weight: 700; }
.ptotal {
  margin-left: auto; display: inline-flex; align-items: baseline; gap: 5px;
  font-weight: 800; font-size: 16px; padding: 4px 12px; border-radius: 9px;
  background: #eef6ff; color: var(--primary-d); white-space: nowrap;
}
.ptotal .lbl { font-size: 11px; font-weight: 600; opacity: .8; }
.ptotal.low { background: #fff3e6; color: var(--amber); }
.ptotal.zero { background: #fde8e8; color: var(--red); }
.pvalue { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ---------- Anh san pham ---------- */
.thumb { width: 42px; height: 42px; border-radius: 8px; object-fit: cover; border: 1px solid var(--line); flex: none; background: #f3f4f6; }
.thumb-ph { width: 42px; height: 42px; border-radius: 8px; border: 1px dashed var(--line); display: flex; align-items: center; justify-content: center; color: #c0c6d0; font-size: 18px; flex: none; }
.img-edit { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.img-preview { width: 96px; height: 96px; border-radius: 10px; object-fit: cover; border: 1px solid var(--line); background: #f3f4f6; flex: none; }
.img-preview.ph { display: flex; align-items: center; justify-content: center; color: #c0c6d0; font-size: 30px; }

/* ---------- Bang tong ket ton kho (tab San pham) ---------- */
.summary-card { margin-bottom: 16px; overflow: hidden; }
table.summary { width: 100%; border-collapse: collapse; }
table.summary th { background: #f8fafc; color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--line); }
table.summary td { padding: 9px 14px; border-bottom: 1px solid #f1f3f8; font-size: 14px; }
table.summary tr:last-child td { border-bottom: none; }
table.summary .num { text-align: right; white-space: nowrap; }
table.summary tfoot td { font-weight: 700; background: #fbfcfe; border-top: 2px solid var(--line); }

/* ---------- Select trong phieu nhap ---------- */
table.rctable { min-width: 640px; }
table.rctable select { padding: 7px 8px; border-radius: 7px; width: 100%; background: #fff; }
table.rctable td { vertical-align: top; }
table.rctable input { margin-top: 0; }
table.rctable input + input { margin-top: 5px; }
table.rctable .r-prod + input { margin-top: 5px; }
.r-newvar > * + * { margin-top: 5px; }

table.sltable { min-width: 640px; }
table.sltable select { padding: 7px 8px; border-radius: 7px; width: 100%; background: #fff; }
table.sltable td { vertical-align: top; }
.r-wh-new, .sl-ch-new { margin-top: 5px; }

/* ---------- Tinh gia / phi san ---------- */
.calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
@media (max-width: 760px) { .calc-grid { grid-template-columns: 1fr; } }
.calc-line { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.calc-line.big { font-size: 16px; font-weight: 700; border-bottom: none; padding-top: 12px; }
.calc-line .neg { color: var(--red); }
.verdict { margin-top: 14px; padding: 12px 14px; border-radius: 10px; font-weight: 700; text-align: center; font-size: 15px; }
.verdict.win { background: #e7f6ee; color: var(--green); }
.verdict.lose { background: #fde8e8; color: var(--red); }
.verdict.even { background: #fff3e6; color: var(--amber); }
.verdict small { display: block; font-weight: 500; font-size: 12px; margin-top: 4px; color: var(--muted); }
table.report { width: 100%; border-collapse: collapse; }
table.report th { background: #f8fafc; color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); }
table.report td { padding: 8px 12px; border-bottom: 1px solid #f1f3f8; font-size: 14px; }
table.report .num { text-align: right; white-space: nowrap; }
table.report tfoot td { font-weight: 700; background: #fbfcfe; border-top: 2px solid var(--line); }
.report-block { margin-bottom: 16px; }
.report-block h4 { margin: 0 0 8px; font-size: 14px; color: var(--muted); }

/* O chon anh cho san pham moi trong phieu nhap */
.r-img-wrap { margin-top: 6px; display: flex; align-items: center; gap: 8px; }
.r-img-lbl {
  display: inline-block; cursor: pointer; font-size: 12px; color: var(--primary-d);
  background: #eaf0ff; padding: 6px 10px; border-radius: 7px; white-space: nowrap;
}
.r-img-lbl:hover { background: #dde7ff; }
.r-img-prev { width: 40px; height: 40px; }
