/* BuildFlow តុការងារ — រចនាសម្រាប់កុំព្យូទ័រ (តារាងក្រាស់ អានលេខងាយ) */
:root {
  --brand: #1f8a84;
  --brand-dark: #166a65;
  --brand-soft: #e3f3f1;
  --ink: #1d2733;
  --ink-soft: #4a5866;
  --muted: #74828f;
  --line: #dde3e8;
  --line-soft: #edf1f4;
  --bg: #f3f5f7;
  --card: #ffffff;
  --warn: #b26a00;
  --warn-soft: #fff4e0;
  --bad: #c0392b;
  --bad-soft: #fdecea;
  --good: #1e7d4f;
  --good-soft: #e5f5ec;
  --dirty: #fff8d6;
  --owner: #6b4fbb;
  --owner-soft: #efeafb;
  --radius: 8px;
  --mono: "Inter", "Segoe UI", Roboto, system-ui, sans-serif;
  font-family: "Noto Sans Khmer", "Khmer OS Battambang", "Segoe UI", Roboto, system-ui, sans-serif;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); min-height: 100vh; }
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--line-soft); padding: 1px 6px; border-radius: 4px; font-size: 0.95em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- របារខាងលើ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  height: 56px; padding: 0 24px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); font-size: 16px; }
.brand:hover { text-decoration: none; }
.brand small { font-weight: 500; color: var(--muted); font-size: 13px; margin-left: 4px; }
.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--brand); color: #fff; font-family: var(--mono); font-weight: 800;
}
.brand.big { font-size: 20px; justify-content: center; margin-bottom: 8px; }
.tabs { display: flex; gap: 4px; height: 100%; }
.tabs a {
  display: flex; align-items: center; gap: 6px; padding: 0 14px; color: var(--ink-soft);
  border-bottom: 3px solid transparent; font-weight: 500;
}
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs a.active { color: var(--brand-dark); border-bottom-color: var(--brand); }
.count:not(:empty) {
  background: var(--bad); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px;
  font-family: var(--mono);
}
.who { margin-left: auto; display: flex; align-items: center; gap: 14px; color: var(--ink-soft); }
.live { color: var(--muted); font-size: 12px; }
.live.on { color: var(--good); }
.live.off { color: var(--bad); }
button.link { background: none; border: 0; color: var(--brand-dark); cursor: pointer; font: inherit; padding: 0; }

.view { max-width: 1480px; margin: 0 auto; padding: 20px 24px 120px; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 6px; }

/* ---------------------------------------------------------------- ប៊ូតុង និងប្រអប់ */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
  color: var(--ink); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #b9c4cd; background: #fafbfc; text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.owner { background: var(--owner); border-color: var(--owner); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); background: var(--bad-soft); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.big { height: 44px; padding: 0 20px; font-size: 15px; }
input, select, textarea {
  font: inherit; color: var(--ink); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 10px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }

/* ---------------------------------------------------------------- កាត និងស្លាក */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 500; background: var(--line-soft); color: var(--ink-soft); white-space: nowrap;
}
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.owner { background: var(--owner-soft); color: var(--owner); }
.chip.brand { background: var(--brand-soft); color: var(--brand-dark); }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 16px 0; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; cursor: pointer; }
.tile:hover { border-color: var(--brand); }
.tile.active { border-color: var(--brand); box-shadow: inset 0 -3px 0 var(--brand); }
.tile .label { color: var(--muted); font-size: 13px; }
.tile .value { font-family: var(--mono); font-size: 26px; font-weight: 700; }
.tile.bad .value { color: var(--bad); }
.tile.owner .value { color: var(--owner); }

/* ---------------------------------------------------------------- តារាង */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  position: sticky; top: 0; z-index: 2; background: #f8fafb; color: var(--ink-soft);
  font-weight: 600; font-size: 12.5px; text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 8px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover td { background: #f7fbfa; }
th.num, td.num { text-align: right; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.progress { width: 80px; height: 6px; background: var(--line-soft); border-radius: 3px; overflow: hidden; display: inline-block; vertical-align: middle; }
.progress > i { display: block; height: 100%; background: var(--brand); }
.progress.done > i { background: var(--good); }

/* ---------------------------------------------------------------- កន្លែងធ្វើការលើសំណើ */
.req-head { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: start; }
.req-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.req-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--ink-soft); margin-top: 6px; }
.req-meta b { color: var(--ink); font-weight: 600; }
.banner { margin-top: 12px; padding: 10px 14px; border-radius: 8px; background: var(--warn-soft); color: #6b4300; }
.banner.owner { background: var(--owner-soft); color: #3f2c7a; }
.banner.ai { background: #eef6ff; color: #1d4f86; }
.banner ul { margin: 4px 0 0; padding-left: 20px; }
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 16px 0 10px;
}
.toolbar .spacer { flex: 1; }
.rate { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); }
.rate input { width: 90px; text-align: right; font-family: var(--mono); }

.grid td { padding: 6px 8px; }
.grid td.item { min-width: 220px; }
.grid .code { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.grid input.cell { width: 100%; min-width: 90px; height: 32px; }
.grid input.cell.price { text-align: right; font-family: var(--mono); width: 120px; }
.grid input.cell.qty { text-align: right; font-family: var(--mono); width: 90px; }
.grid input.cell.supplier { min-width: 150px; }
.grid tr.dirty td { background: var(--dirty); }
.grid tr.error td { background: var(--bad-soft); }
.grid tr.saved td { animation: saved 1.6s ease-out; }
@keyframes saved { from { background: var(--good-soft); } to { background: transparent; } }
.grid tr.removed td { color: var(--muted); text-decoration: line-through; }
.grid tr.msg td { padding-top: 0; border-bottom: 1px solid var(--line-soft); }
.grid .rowmsg { font-size: 12.5px; }
.grid .rowmsg.bad { color: var(--bad); }
.grid .rowmsg.note { color: var(--ink-soft); }
.ref { font-family: var(--mono); }
.ref-sub { display: block; font-size: 11.5px; color: var(--muted); font-family: inherit; max-width: 220px; white-space: normal; }
.quote-cell { font-family: var(--mono); text-align: right; white-space: nowrap; }
.quote-cell button {
  border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 2px 8px; cursor: pointer;
  font: inherit; color: var(--ink);
}
.quote-cell button:hover { border-color: var(--brand); color: var(--brand-dark); }
.quote-cell button.best { background: var(--good-soft); border-color: #9bd3b5; color: var(--good); font-weight: 700; }
.quote-cell .warn { display: block; color: var(--warn); font-size: 11px; font-family: inherit; white-space: normal; max-width: 160px; text-align: right; }
th.quote-col { color: var(--ink); background: #f2f8f7; }
th.quote-col small { display: block; font-weight: 400; color: var(--muted); }
.var-up { color: var(--bad); font-weight: 600; }
.var-down { color: var(--good); font-weight: 600; }

.summary {
  position: sticky; bottom: 0; z-index: 10; margin-top: 16px;
  display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px;
  box-shadow: 0 -6px 20px rgba(29, 39, 51, 0.06);
}
.figures { display: flex; gap: 28px; flex-wrap: wrap; }
.figure .label { color: var(--muted); font-size: 12.5px; }
.figure .value { font-family: var(--mono); font-size: 20px; font-weight: 700; }
.figure .value.total { color: var(--brand-dark); font-size: 24px; }
.reasons { margin-top: 6px; color: var(--owner); font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.drop {
  border: 2px dashed #c3ced6; border-radius: 10px; padding: 14px; text-align: center; color: var(--ink-soft);
  background: #fafcfd; cursor: pointer;
}
.drop.over { border-color: var(--brand); background: var(--brand-soft); }
.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; margin-top: 12px; }
.doc { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: var(--card); }
.doc.used { opacity: 0.75; }
.doc .doc-top { display: flex; justify-content: space-between; gap: 8px; }
.doc .doc-total { font-family: var(--mono); font-weight: 700; }
.doc .doc-note { white-space: pre-line; font-size: 12.5px; color: var(--ink-soft); margin: 6px 0; }
.doc .doc-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.busy { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--brand-soft); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- បញ្ជីទិញ */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin: 14px 0; }
.filters label { display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; color: var(--muted); }
.groups { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.groups table td { padding: 5px 10px; }

/* ---------------------------------------------------------------- ផ្សេងៗ */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; max-width: 640px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.toast.bad { background: var(--bad); }
.toast.good { background: var(--good); }
.dialog { border: 0; border-radius: 12px; padding: 20px 22px; width: min(480px, 92vw); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(29, 39, 51, 0.35); }
.dialog textarea { width: 100%; margin-top: 6px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.back { display: inline-block; margin-bottom: 10px; }
.kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; color: var(--muted); }

.login-page { display: grid; place-items: center; padding: 24px; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 32px 36px; max-width: 520px; }
.login-card h1 { text-align: center; margin: 8px 0 16px; }
.steps { padding-left: 22px; line-height: 2; }

@media (max-width: 1100px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .groups { grid-template-columns: 1fr; }
  .summary { grid-template-columns: 1fr; }
  .actions { justify-content: flex-start; }
}
@media (max-width: 700px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .who #who-name, .brand small { display: none; }
  .view { padding: 14px 12px 120px; }
}
