/* Hoa Vinh ERP — giao diện gọn kiểu bảng Excel. Không cần build. */
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 "Segoe UI", Roboto, Arial, sans-serif; color: #1f2937; background: #f3f4f6; }
a { color: #1d4ed8; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Thanh điều hướng: dính trên cùng khi cuộn, chữ không xuống dòng. */
html { scroll-padding-top: 56px; }
.topbar { position: sticky; top: 0; z-index: 100; display: flex; align-items: center; gap: 18px; padding: 0 20px; height: 48px;
    background: #1e3a5f; color: #fff; white-space: nowrap; box-shadow: 0 1px 4px rgba(0, 0, 0, .15); }
.topbar a { color: #e5edf7; }
.topbar a.active, .topbar summary.active { color: #fff; font-weight: 600; border-bottom: 2px solid #fbbf24; padding-bottom: 2px; }
.topbar details.menu { position: relative; }
.topbar details.menu summary { cursor: pointer; list-style: none; color: #e5edf7; user-select: none; }
.topbar details.menu summary::-webkit-details-marker { display: none; }
.topbar details.menu summary::after { content: " ▾"; font-size: 11px; }
.topbar details.menu[open] summary { color: #fff; }
.topbar .menu-list { position: absolute; top: calc(100% + 12px); left: -12px; min-width: 210px; padding: 6px 0;
    background: #fff; border: 1px solid #e5e7eb; border-radius: 6px; box-shadow: 0 6px 20px rgba(0, 0, 0, .15); }
.topbar details.menu.right .menu-list { left: auto; right: -12px; min-width: 170px; }
.topbar .menu-list a, .topbar .menu-list .link-btn { display: block; width: 100%; text-align: left; padding: 7px 16px; color: #1f2937; box-sizing: border-box; }
.topbar .menu-list a:hover, .topbar .menu-list .link-btn:hover { background: #f1f5f9; text-decoration: none; }
.topbar .menu-list a.active { color: #1e3a5f; font-weight: 600; border-bottom: 0; padding-bottom: 7px; background: #eff6ff; }
.topbar .menu-list hr { margin: 6px 0; border: 0; border-top: 1px solid #e5e7eb; }
.topbar .brand { font-weight: 700; color: #fff; margin-right: 12px; }
.topbar .spacer { flex: 1; }
.topbar form { margin: 0; }
.topbar .who { font-size: 13px; color: #cbd5e1; }

.banner { padding: 6px 20px; font-size: 13px; }
.banner.sandbox { background: #fef3c7; color: #92400e; }

main { max-width: 1280px; margin: 20px auto; padding: 0 20px; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 24px 0 10px; }

.card { background: #fff; border: 1px solid #e5e7eb; border-radius: 6px; padding: 16px 18px; margin-bottom: 16px; }

.flash { padding: 10px 14px; border-radius: 4px; margin-bottom: 14px; }
.flash.ok { background: #dcfce7; color: #166534; }
.flash.err { background: #fee2e2; color: #991b1b; }
.flash ul { margin: 0; padding-left: 18px; }

table.grid { width: 100%; border-collapse: collapse; background: #fff; font-size: 13px; }
table.grid th, table.grid td { border: 1px solid #d1d5db; padding: 5px 8px; vertical-align: top; text-align: left; }
table.grid th { background: #e8eef6; font-weight: 600; white-space: nowrap; }
table.grid tr:nth-child(even) td { background: #fafafa; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
/* Danh sách PR, PO: nội dung canh giữa dòng theo chiều dọc. */
table.grid.list-middle td { vertical-align: middle; }

.form-row { display: grid; grid-template-columns: 200px 1fr; gap: 8px 14px; align-items: center; margin-bottom: 8px; }
.form-row label { font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
    width: 100%; max-width: 520px; padding: 6px 8px; border: 1px solid #cbd5e1; border-radius: 4px; font: inherit;
}
textarea { min-height: 70px; }
input[type=month],
.form-row input[type=date], .form-row input[type=datetime-local] { width: 100%; max-width: 240px; padding: 6px 8px; border: 1px solid #cbd5e1; border-radius: 4px; font: inherit; }
.inline-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.inline-form input, .inline-form select { width: auto; min-width: 110px; }

.btn { display: inline-block; white-space: nowrap; padding: 6px 14px; border: 1px solid #1e3a5f; background: #1e3a5f; color: #fff; border-radius: 4px; cursor: pointer; font: inherit; }
.btn:hover { background: #274b77; text-decoration: none; }
.btn.secondary { background: #fff; color: #1e3a5f; }
.btn.danger { background: #b91c1c; border-color: #b91c1c; }
.btn.small { padding: 2px 8px; font-size: 12px; }
.link-btn { background: none; border: 0; color: #cbd5e1; cursor: pointer; font: inherit; padding: 0; }

.muted { color: #6b7280; font-size: 12px; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 12px; background: #e5e7eb; }
.badge.on { background: #dcfce7; color: #166534; }
.badge.off { background: #fee2e2; color: #991b1b; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar h1 { white-space: nowrap; }
.toolbar > .muted { min-width: 0; }
.toolbar .spacer { flex: 1; }
details.edit summary { cursor: pointer; color: #1d4ed8; font-size: 12px; }

.login-box { max-width: 380px; margin: 80px auto; }
.login-box .form-row { grid-template-columns: 1fr; }
.login-box input { max-width: none; }
pre.values { margin: 0; white-space: pre-wrap; font-size: 12px; }

/* Trạng thái PR */
.st { display: inline-block; padding: 1px 7px; border-radius: 3px; font-size: 12px; white-space: nowrap; }
.st-net { background: #fef3c7; color: #92400e; }
.st-approval { background: #e0e7ff; color: #3730a3; }
.st-customer { background: #dbeafe; color: #1e40af; }
.st-done { background: #dcfce7; color: #166534; }
.st-cancel { background: #f3f4f6; color: #6b7280; text-decoration: line-through; }
.urgent { color: #b91c1c; font-weight: 700; }
table.grid th a { color: inherit; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.filters input, .filters select { width: auto; min-width: 120px; padding: 4px 6px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* Báo giá */
main.wide { max-width: none; }
.q-grid { border: 1px solid #cbd5e1; font-size: 13px; }
.q-grid .tabulator-row.q-group { background: #eef2ff; font-weight: 600; }
.q-grid .tabulator-cell.q-err { background: #fee2e2 !important; outline: 1px solid #dc2626; }
.q-grid .tabulator-cell.q-calc { color: #334155; background: #f8fafc; }
.q-total { display: flex; justify-content: flex-end; gap: 24px; padding: 10px 4px; font-size: 15px; }
.q-total strong { font-size: 17px; }
table.q-table td.num, table.q-table th.num { text-align: right; white-space: nowrap; }
table.q-table tr.q-group td { background: #eef2ff; font-weight: 600; }
.q-status { margin-left: 8px; }
.q-errors { color: #b91c1c; margin: 6px 0; }
textarea.q-paste { width: 100%; max-width: none; height: 160px; font-family: monospace; font-size: 12px; }

/* Trang Tổng quan */
.dash-head { display: flex; align-items: baseline; gap: 14px; }
.dash-head h1 { margin-bottom: 4px; }
.dash-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.dash-tile { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; background: #fff; border: 1px solid #e5e7eb;
    border-left: 4px solid #1e3a5f; border-radius: 6px; color: #1f2937; }
.dash-tile:hover { text-decoration: none; border-color: #1e3a5f; box-shadow: 0 2px 8px rgba(0, 0, 0, .08); }
.dash-tile .n { font-size: 26px; font-weight: 700; color: #1e3a5f; line-height: 1.1; }
.dash-tile .l { font-weight: 600; }
.dash-tile .h { font-size: 12px; color: #6b7280; }

/* Ô chọn: không kéo dãn như ô nhập; chữ đi sát ô chọn. */
input[type=checkbox], input[type=radio],
.filters input[type=checkbox], .filters input[type=radio],
.inline-form input[type=checkbox], .inline-form input[type=radio] {
    width: auto; min-width: 0; max-width: none; margin: 0 5px 0 0; padding: 0; vertical-align: middle; flex: none;
}
.filters label, .inline-form label:has(> input[type=checkbox]) { display: inline-flex; align-items: center; white-space: nowrap; margin: 0 6px; }
.form-hint { margin: -2px 0 10px 214px; }

/* Bảng: cuộn ngang/dọc trong khung riêng (public/js/ui.js bọc mọi table.grid), hàng tiêu đề đứng yên khi cuộn dọc. */
.table-scroll { overflow: auto; max-height: calc(100vh - 150px); max-width: 100%; margin-bottom: 12px; }
.table-scroll > table.grid > tbody > tr:first-child > th,
.table-scroll > table.grid > thead th { position: sticky; top: 0; z-index: 2; }

/* Điện thoại: chỉ cần thao tác được. */
@media (max-width: 760px) {
    html { scroll-padding-top: 0; }
    .topbar { position: static; flex-wrap: wrap; height: auto; gap: 6px 14px; padding: 8px 12px; white-space: normal; }
    .topbar .brand { margin-right: 4px; }
    .topbar .spacer { display: none; }
    .topbar .menu-list { left: 0; }
    .topbar details.menu.right .menu-list { right: auto; left: 0; }
    .banner { padding: 6px 12px; }
    main { margin: 12px auto; padding: 0 10px; }
    .card { padding: 12px; }
    .form-row { grid-template-columns: 1fr; gap: 4px; }
    .form-hint { margin-left: 0; }
    .toolbar { flex-wrap: wrap; }
    .toolbar h1 { width: 100%; }
    .filters input[type=text], .filters select { flex: 1 1 100%; min-width: 0 !important; }
    /* iOS phóng to trang khi ô nhập chữ nhỏ hơn 16px. */
    input, select, textarea { font-size: 16px; }
    .table-scroll { max-height: none; }
    .btn { padding: 8px 14px; }
    .btn.small { padding: 5px 10px; font-size: 13px; }
    .q-total { flex-wrap: wrap; justify-content: flex-start; gap: 10px; }
}
/* Cột tên việc: không bị ép còn vài chữ khi bảng nhiều cột. */
table.grid td.col-title { min-width: 240px; }
@media (max-width: 760px) { table.grid td.col-title { min-width: 200px; } }

/* Dòng tổng danh sách PO (như dòng SUBTOTAL của file Excel cũ). */
table.grid tr.total-row td { font-weight: 600; background: #fff7e6; }
table.grid tr.total-row td.num { color: #c0392b; font-weight: 700; }
