/* Giao diện gần giống KiotViet. Lớp dùng chung — xem chú thích từng nhóm. */
:root {
  --primary: #0b6ef6; --primary-d: #0857c7; --primary-l: #e8f1fe;
  --success: #16a34a; --success-d: #11823b; --danger: #dc2626; --warning: #d97706; --info: #0891b2;
  --text: #1f2937; --muted: #6b7280; --line: #e5e7eb; --bg: #eef1f5; --card: #fff; --head: #f3f6fb;
  --radius: 6px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font: 13px/1.45 -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  border: 1px solid #cfd6df; border-radius: 4px; padding: 6px 8px; background: #fff; min-width: 0; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-l); }
input[type=checkbox], input[type=radio] { padding: 0; width: auto; vertical-align: middle; }
input:disabled, select:disabled, textarea:disabled { background: #f3f4f6; }
textarea { resize: vertical; width: 100%; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
h2 { font-size: 20px; } h3 { font-size: 16px; } h4 { font-size: 13px; }

/* ---------- Tiện ích ---------- */
.r { text-align: right; } .c { text-align: center; } .muted { color: var(--muted); } .bold, .b { font-weight: 600; }
.nowrap { white-space: nowrap; } .grow { flex: 1; } .hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 8px; } .row.wrap { flex-wrap: wrap; } .col { display: flex; flex-direction: column; gap: 8px; }
.mt { margin-top: 12px; } .mb { margin-bottom: 12px; } .gap { gap: 8px; }
.text-success { color: var(--success); } .text-danger { color: var(--danger); } .text-primary { color: var(--primary); } .text-warning { color: var(--warning); }
.link { color: var(--primary); cursor: pointer; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(0,0,0,.06); padding: 12px 14px; }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px;
  border: 1px solid #cfd6df; border-radius: 4px; background: #fff; cursor: pointer; white-space: nowrap; text-decoration: none !important; color: var(--text);
}
.btn:hover { background: #f5f7fa; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: var(--success-d); }
.btn-danger { background: #fff; border-color: #f3b4b4; color: var(--danger); }
.btn-danger:hover { background: #fdecec; }
.btn-sm { height: 26px; padding: 0 8px; font-size: 12px; }
.btn-lg { height: 42px; padding: 0 20px; font-size: 15px; font-weight: 600; }
.btn-block { width: 100%; }
.btn-icon { width: 28px; height: 28px; padding: 0; border: 0; background: transparent; cursor: pointer; border-radius: 4px; color: var(--muted); }
.btn-icon:hover { background: #eef1f5; color: var(--danger); }

/* ---------- Nhãn trạng thái ---------- */
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; white-space: nowrap; }
.s-success { background: #dcfce7; color: #166534; } .s-danger { background: #fee2e2; color: #991b1b; }
.s-warning { background: #fef3c7; color: #92400e; } .s-info { background: #cffafe; color: #155e75; } .s-muted { background: #f3f4f6; color: #4b5563; }

/* ---------- Khung trang ---------- */
.topbar { height: 44px; background: #fff; display: flex; align-items: center; gap: 14px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 16px; color: var(--primary); }
.branch-pick select { border: 1px solid var(--line); height: 30px; }
.mainnav { height: 42px; background: var(--primary); display: flex; align-items: stretch; padding: 0 8px; position: sticky; top: 0; z-index: 50; }
.nav-item { position: relative; display: flex; align-items: center; }
.mainnav .nav-item > a { color: #fff; padding: 0 14px; height: 100%; display: flex; align-items: center; font-weight: 500; text-decoration: none; }
.mainnav .nav-item:hover > a, .mainnav .nav-item.active > a { background: var(--primary-d); }
.nav-drop {
  position: absolute; top: 100%; left: 0; min-width: 210px; background: #fff; border-radius: 0 0 6px 6px;
  box-shadow: 0 6px 18px rgba(0,0,0,.15); padding: 6px 0; z-index: 60;
}
.nav-drop.right { left: auto; right: 0; }
.nav-drop a { display: block; padding: 8px 16px; color: var(--text); text-decoration: none; }
.nav-drop a:hover { background: var(--primary-l); color: var(--primary); }
.user-menu { cursor: pointer; height: 100%; }
.btn-sale { align-self: center; background: #fff; color: var(--primary); font-weight: 600; padding: 6px 14px; border-radius: 4px; text-decoration: none !important; }
.content { padding: 14px 16px 40px; }
.loading-screen { padding: 60px; text-align: center; color: var(--muted); }
.empty-page { max-width: 560px; margin: 40px auto; text-align: center; }

/* ---------- Trang danh sách (kiểu KiotViet: bộ lọc trái + bảng phải) ----------
   <div class="list-page">
     <aside class="filters"><div class="filter-box"><h4>Thời gian</h4> ... </div></aside>
     <section class="list-main">
       <div class="list-head"><h2>Tiêu đề</h2><input class="search" ...><div class="grow"></div><button class="btn btn-primary">+ Thêm mới</button></div>
       <div class="table-wrap"><table class="grid">...</table></div>
       <pager .../>
     </section>
   </div> */
.list-page { display: grid; grid-template-columns: 230px 1fr; gap: 14px; align-items: start; }
.filters { display: flex; flex-direction: column; gap: 10px; }
.filter-box { background: #fff; border-radius: var(--radius); padding: 10px 12px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.filter-box h4 { margin-bottom: 8px; }
.filter-box label { display: flex; align-items: center; gap: 6px; padding: 3px 0; cursor: pointer; }
.filter-box select, .filter-box input:not([type=checkbox]):not([type=radio]) { width: 100%; }
.list-main { min-width: 0; }
.list-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.list-head .search { width: 320px; max-width: 100%; height: 34px; }
.table-wrap { background: #fff; border-radius: var(--radius); box-shadow: 0 1px 2px rgba(0,0,0,.06); overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th { background: var(--head); text-align: left; font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; }
table.grid td { padding: 8px 10px; border-bottom: 1px solid #f0f2f5; vertical-align: middle; }
table.grid tr.sum td { background: #fffbea; font-weight: 600; }
table.grid tr.clickable { cursor: pointer; }
table.grid tr.clickable:hover td { background: #f5f9ff; }
table.grid tr.open td { background: var(--primary-l); }
table.grid tr.detail > td { background: #fff; border: 2px solid var(--primary-l); border-top: 0; padding: 0; }
table.grid td.r, table.grid th.r { text-align: right; }
table.grid tr.empty td { text-align: center; color: var(--muted); padding: 30px; }
table.grid input:not([type=checkbox]) { width: 100%; }
/* Khung chi tiết mở rộng dưới dòng */
.detail-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 12px; background: #fafbfd; }
.detail-tabs a, .tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; text-decoration: none; }
.detail-tabs a.active, .tabs a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.detail-body { padding: 12px 14px; }
.detail-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 14px; border-top: 1px solid var(--line); background: #fafbfd; flex-wrap: wrap; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px 24px; margin-bottom: 12px; }
.info-grid > div { display: flex; gap: 8px; border-bottom: 1px dotted var(--line); padding: 4px 0; }
.info-grid > div > span:first-child { color: var(--muted); min-width: 110px; }
.totals { margin-left: auto; width: 320px; max-width: 100%; }
.totals > div { display: flex; justify-content: space-between; padding: 3px 0; }
.totals > div.big { font-weight: 700; font-size: 14px; }

/* ---------- Trang tạo/sửa chứng từ (bảng hàng trái + bảng thông tin phải) ----------
   <div class="doc-page">
     <section class="doc-left"><div class="doc-search"><product-search @select="add"/></div><div class="table-wrap">...</div></section>
     <aside class="doc-right card"> .form-row ... <div class="doc-buttons"><button class="btn btn-primary">Lưu tạm</button><button class="btn btn-success">Hoàn thành</button></div></aside>
   </div> */
.doc-page { display: grid; grid-template-columns: 1fr 340px; gap: 14px; align-items: start; }
.doc-left { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.doc-search { display: flex; gap: 8px; align-items: center; background: #fff; padding: 8px; border-radius: var(--radius); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.doc-search .psearch { flex: 1; }
.doc-right { position: sticky; top: 56px; display: flex; flex-direction: column; gap: 8px; }
.doc-right h3 { margin-bottom: 4px; }
.doc-buttons { display: flex; gap: 8px; margin-top: 8px; }
.doc-buttons .btn { flex: 1; height: 40px; font-weight: 600; }
.doc-items td input { height: 30px; }
.doc-items .qty-input { width: 90px !important; text-align: right; }
.doc-items .money-input { width: 110px !important; text-align: right; }

/* ---------- Biểu mẫu ---------- */
.form-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.form-row > label:first-child { width: 130px; flex-shrink: 0; color: #374151; }
.form-row > input, .form-row > select, .form-row > textarea, .form-row > .grow, .form-row > .money-input { flex: 1; }
.form-row.top { align-items: flex-start; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.req::after { content: ' *'; color: var(--danger); }
.money-input { text-align: right; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* ---------- Hộp thoại ---------- */
.modal-mask { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; z-index: 100; padding: 40px 12px; overflow-y: auto; }
.modal { background: #fff; border-radius: 8px; max-width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,.25); display: flex; flex-direction: column; max-height: calc(100vh - 80px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 15px; }
.modal-x { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-body { padding: 14px 16px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 16px; border-top: 1px solid var(--line); }

/* ---------- Ô tìm kiếm thả xuống ---------- */
.psearch { position: relative; }
.psearch-input { width: 100%; height: 34px; }
.psearch-list { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 0 0 6px 6px; box-shadow: 0 8px 20px rgba(0,0,0,.15); max-height: 380px; overflow-y: auto; z-index: 80; }
.psearch-item { padding: 7px 10px; cursor: pointer; border-bottom: 1px solid #f3f4f6; }
.psearch-item.active, .psearch-item:hover { background: var(--primary-l); }
.psearch-name { font-weight: 500; }
.psearch-meta { color: var(--muted); font-size: 12px; }
.psearch-empty { padding: 12px; color: var(--muted); text-align: center; }

/* ---------- Khác ---------- */
.pager { display: flex; align-items: center; gap: 6px; padding: 10px 2px; flex-wrap: wrap; }
.date-range { display: flex; flex-direction: column; gap: 6px; }
.date-range-custom { display: flex; gap: 4px; }
.date-range-custom input { width: 50%; }
.toasts { position: fixed; top: 14px; right: 14px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 10px 16px; border-radius: 6px; color: #fff; box-shadow: 0 6px 16px rgba(0,0,0,.2); max-width: 420px; }
.t-success { background: var(--success); } .t-error { background: var(--danger); } .t-info { background: var(--primary); }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0b6ef6, #4f9cff); padding: 16px; }
.login-box { background: #fff; padding: 28px; border-radius: 10px; width: 360px; max-width: 100%; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.login-box label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
.login-box input { height: 38px; }
.login-err { color: var(--danger); }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.stat { background: #fff; border-radius: var(--radius); padding: 12px 14px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.stat .label { color: var(--muted); } .stat .value { font-size: 20px; font-weight: 700; margin-top: 4px; }

@media (max-width: 900px) {
  .list-page, .doc-page { grid-template-columns: 1fr; }
  .doc-right { position: static; }
  .form-grid { grid-template-columns: 1fr; }
}
/* Điện thoại: menu xuống dòng thay vì cuộn ngang (cuộn ngang cắt mất menu con), menu con trải hết bề ngang */
@media (max-width: 700px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .brand { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .branch-pick select { max-width: 120px; }
  .mainnav { height: auto; flex-wrap: wrap; position: relative; padding: 0 4px; }
  .mainnav .nav-item { position: static; }
  .mainnav .nav-item > a { padding: 0 10px; height: 40px; }
  .mainnav .nav-drop:not(.right) { left: 4px; right: 4px; }
  .btn-sale { margin: 4px; }
  .content { padding: 10px 8px 40px; }
  .list-page > .filters { order: 2; } /* bảng kết quả lên trước, bộ lọc xuống dưới */
}
@media print { .topbar, .mainnav, .filters, .no-print { display: none !important; } .content { padding: 0; } }
