/* Sourcing Hub — clean light theme */
:root {
  --bg: #f5f7fa; --card: #fff; --ink: #1a202c; --dim: #718096; --line: #e2e8f0;
  --brand: #1d6f5c; --brand-dk: #155446; --blue: #2b6cb0; --red: #c53030;
  --green: #2f855a; --purple: #6b46c1; --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; }
.dim { color: var(--dim); } .small { font-size: 12px; } .ml { margin-left: 8px; }

/* topbar */
.topbar { display: flex; align-items: center; gap: 24px; background: #fff;
  border-bottom: 1px solid var(--line); padding: 0 24px; height: 54px;
  position: sticky; top: 0; z-index: 50; }
.logo { font-weight: 800; font-size: 17px; color: var(--brand); }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { padding: 6px 14px; border-radius: 8px; color: var(--ink); font-weight: 600; }
.topbar nav a.on, .topbar nav a:hover { background: #e6f0ed; color: var(--brand-dk); }
.user-box { display: flex; align-items: center; }

main { max-width: 1180px; margin: 0 auto; padding: 24px; }

/* headers */
.page-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { font-size: 21px; flex: none; }
.page-head > div:first-child { flex: 1; }
.crumb { display: block; font-size: 12px; margin-bottom: 2px; }
.section-head { display: flex; align-items: center; gap: 12px; margin: 26px 0 10px; }
.section-head h3 { font-size: 16px; }
.search { flex: 1; max-width: 320px; padding: 8px 12px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px; }

/* buttons */
.btn { background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 14px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--ink); }
.btn:hover { border-color: #cbd5e0; background: #f7fafc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dk); }
.btn.danger { color: var(--red); border-color: #fbb6b6; }
.btn.danger:hover { background: #fff5f5; }
.btn.small { padding: 3px 10px; font-size: 12px; }
.btn.ghost { border-style: dashed; color: var(--dim); }
.btn.wide { width: 100%; }
.icon { background: none; border: none; cursor: pointer; color: var(--dim);
  font-size: 13px; padding: 3px 5px; border-radius: 6px; display: inline-flex; align-items: center; }
.icon:hover { background: #edf2f7; color: var(--ink); }
.icon.danger:hover { background: #fff0f0; color: var(--red); }

/* lucide icons */
svg.lucide { display: inline-block; vertical-align: middle; flex: 0 0 auto; }
.crumb { display: inline-flex; align-items: center; gap: 3px; }
.open-link { display: inline-flex; align-items: center; gap: 2px; }
.user-tag { display: inline-flex; align-items: center; gap: 3px; }
.btn svg.lucide, .crumb svg.lucide { vertical-align: -2px; }
.role-icon { vertical-align: -2px; }
.role-icon.role-admin { color: var(--purple); }
.role-icon.role-sales { color: var(--blue); }
.role-icon.role-sourcing { color: #b7791f; }
.team-list { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.team-member { display: inline-flex; align-items: center; gap: 4px; }
.btn-row { margin: 8px 0; }

/* tables */
table.list { width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.list th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--dim); padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; }
table.list td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tbody tr:last-child td { border-bottom: none; }
table.list tbody tr[onclick], table.list tbody tr { cursor: default; }
tbody tr:hover { background: #fafbfc; }
table.list.compact th, table.list.compact td { padding: 6px 10px; font-size: 13px; }
td.num, th.num { text-align: right; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
th .sort-ind { display: inline-flex; vertical-align: middle; color: var(--brand); }
table.list.fx-rates { max-width: 420px; }
.selected-row { background: #f0faf5 !important; }
.row-actions { white-space: nowrap; text-align: right; }
.low-margin { color: var(--red); }

/* chips */
.chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11.5px;
  font-weight: 600; background: #edf2f7; color: #4a5568; }
.chip.blue { background: #ebf4ff; color: var(--blue); }
.chip.green { background: #e6f6ee; color: var(--green); }
.chip.red { background: #fff0f0; color: var(--red); }
.chip.purple { background: #f3ebff; color: var(--purple); }
.chip.qty { background: #e6f0ed; color: var(--brand-dk); margin-right: 4px; }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; }
.prod-name { font-size: 15.5px; }
.desc { margin: 6px 0 0; }
.kv { display: flex; gap: 8px; margin: 3px 0; }
.kv .k { color: var(--dim); min-width: 130px; font-size: 12.5px; text-transform: capitalize; }
.kv .v { flex: 1; }
.meta-row { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 18px; margin-bottom: 8px; }
.detail-grid { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 18px; margin-bottom: 8px; }
.qty-row { display: flex; align-items: center; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.qty-row .k, .subsection .k, .att-row .k { color: var(--dim); font-size: 12.5px; font-weight: 600; }
.subsection { display: flex; align-items: center; margin-top: 14px; padding-top: 10px;
  border-top: 1px dashed var(--line); }
.part-row { display: flex; justify-content: space-between; padding: 3px 0 3px 12px; }
.vq-host { margin-top: 6px; }
.att-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.att { background: #f7fafc; border: 1px solid var(--line); border-radius: 6px;
  padding: 2px 4px 2px 10px; font-size: 12.5px; }

/* specs — compact, inline-editable */
.specs { margin-top: 8px; }
.spec-sec { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 10px; margin: 7px 0; }
.spec-sec-head { display: flex; align-items: center; gap: 4px; margin-bottom: 5px; }
.spec-title { font-weight: 700; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--brand-dk); flex: 1; }
.spec-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(185px, 1fr)); gap: 7px 14px; }
.spec-field { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.spec-field.wide { grid-column: 1 / -1; }
.spec-field .fk { font-size: 11px; font-weight: 600; color: var(--dim); }
.spec-field .fv { font-size: 13.5px; min-height: 18px; }
.spec-input { width: 100%; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 13px; font-family: inherit; background: #fff; color: var(--ink); }
.spec-input::placeholder { color: #cbd5e0; }
.spec-input:focus { outline: 2px solid #bfe3d8; border-color: var(--brand); }
textarea.spec-input { resize: vertical; min-height: 36px; line-height: 1.4; }
.team-field { display: flex; align-items: center; gap: 4px; font-size: 13.5px; min-height: 30px; }
select.spec-input { height: 30px; }
.add-section { display: flex; gap: 6px; align-items: center; margin-top: 8px; flex-wrap: wrap; }

/* totals */
.totals-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px; margin-top: 16px; max-width: 420px; margin-left: auto; }
.totals-card .kv.big .v { font-size: 17px; font-weight: 800; color: var(--brand-dk); }
.cell-input { width: 90px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 13px; text-align: right; }
.cell-input.narrow { width: 70px; }
.status-sel { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 13px; font-weight: 600; background: #fff; }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(26,32,44,0.45); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; overflow: auto; }
.modal { background: #fff; border-radius: 14px; padding: 22px 24px; width: 460px; max-width: 100%;
  box-shadow: 0 16px 48px rgba(0,0,0,0.18); }
.modal h3 { margin-bottom: 14px; }
.modal-form .field, .login-card .field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 12px; font-weight: 600; color: var(--dim); margin-bottom: 4px; }
.field input, .field select, .field textarea { width: 100%; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 14px; font-family: inherit; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid #bfe3d8; border-color: var(--brand); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.checklist { max-height: 260px; overflow: auto; margin: 10px 0; }
.checkrow { display: block; padding: 6px 4px; cursor: pointer; }
.confirm p { margin: 0 0 8px; }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 16px;
  padding: 36px; width: 360px; box-shadow: 0 8px 32px rgba(0,0,0,0.06); }
.login-card h1 { color: var(--brand); font-size: 22px; margin-bottom: 20px; text-align: center; }

/* toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(16px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 13.5px;
  opacity: 0; transition: all 0.25s; z-index: 200; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); }

.empty { color: var(--dim); background: var(--card); border: 1px dashed var(--line);
  border-radius: var(--radius); padding: 18px; text-align: center; }

/* tabs */
.tabs { display: flex; gap: 4px; }
.tab { background: none; border: 1px solid transparent; border-radius: 8px; padding: 6px 12px;
  font-size: 13px; font-weight: 600; color: var(--dim); cursor: pointer; }
.tab.on { background: #e6f0ed; color: var(--brand-dk); }

.reorder-products { max-height: 200px; overflow: auto; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; margin-top: 4px; }

/* project tabs */
.proj-tabs { gap: 2px; border-bottom: 1px solid var(--line); margin: 12px 0 16px; }
.proj-tabs .tab { border-radius: 8px 8px 0 0; margin-bottom: -1px; padding: 8px 16px; }
.proj-tabs .tab.on { background: var(--card); border: 1px solid var(--line); border-bottom-color: var(--card); }
.tab-panel { animation: fade 0.15s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.supplier-block { margin: 0 0 18px calc(var(--depth, 0) * 18px); }
.supplier-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }

/* clickable text (product/part names that open the spec popup) */
.clickable { cursor: pointer; }
.clickable:hover { color: var(--brand); text-decoration: underline; }

/* projects list — expandable tree */
table.list.tree-table th:first-child, table.list.tree-table td.chev-cell { width: 30px; padding-right: 0; }
.proj-row { cursor: pointer; }
.proj-row:hover { background: #f7fafc; }
.proj-row td.num { text-align: center; }
.chev { background: none; border: none; cursor: pointer; color: var(--dim);
  width: 22px; height: 22px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; }
.chev:hover { background: #edf2f7; color: var(--ink); }
.chev.disabled { color: var(--line); cursor: default; }
.open-link { color: var(--brand); font-weight: 600; font-size: 12px; float: right; opacity: 0; transition: opacity 0.12s; }
.proj-row:hover .open-link { opacity: 1; }
.tree-row > td.tree-cell { padding: 0; background: #fafcfb; }
.tree-host { padding: 6px 10px 10px 40px; }

/* product/parts tree */
.tree { display: flex; flex-direction: column; gap: 1px; }
.tree-node { display: flex; flex-direction: column; }
.tree-item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  background: none; border: none; cursor: pointer; padding: 5px 8px; border-radius: 6px;
  font: inherit; color: var(--ink); margin-left: calc(var(--depth, 0) * 22px); }
.tree-item:hover { background: #eef4f2; }
.tree-item .ti-twig { color: var(--brand); display: inline-flex; align-items: center; }
.tree-item .ti-twig.leaf { color: var(--dim); }
.tree-item .ti-name { font-weight: 600; }
.tree-item .qty-hint { margin-left: auto; }

/* expanded products sub-table */
.sub-table { width: 100%; box-shadow: none; border: 1px solid var(--line); margin: 0; }
.sub-table thead th { background: #f0f4f3; }
.sub-table .name-cell { padding-left: calc(12px + var(--depth, 0) * 22px); white-space: nowrap; }
.sub-table .name-cell .ti-twig { color: var(--brand); margin-right: 6px; vertical-align: -2px; }
.sub-table .name-cell .ti-twig.leaf { color: var(--dim); }
.prod-row:hover { background: #f7fafc; }
.mini-sel { padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px;
  background: #fff; font-family: inherit; max-width: 160px; color: var(--ink); }
.popup-meta { display: flex; align-items: center; gap: 6px; margin: 10px 0 4px; flex-wrap: wrap; }
.popup-meta .k { color: var(--dim); font-size: 12.5px; font-weight: 600; }

/* spec popup */
.modal.wide { width: 640px; }
.modal.wide.popup { width: 780px; max-width: 100%; }
.modal.popup { padding: 18px 20px; }
.popup-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px; }
.popup-head .prod-name { font-size: 16px; }
.popup-head .x { font-size: 16px; }
.popup-parts { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); }
.popup-parts .k { display: block; color: var(--dim); font-size: 12.5px; font-weight: 600; margin-bottom: 4px; }

/* file sections (per-section attachments with notes + thumbnails) */
.fs-block { margin-top: 10px; }
.fs-label { display: block; font-size: 11px; font-weight: 600; color: var(--dim); margin-bottom: 4px; }
.fs-toolbar { margin-bottom: 6px; }
.fs-list { display: flex; flex-direction: column; gap: 6px; }
.fs-file { display: flex; align-items: center; gap: 6px; }
.fs-file > a { flex: 0 0 auto; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fs-note { flex: 1; max-width: 300px; }
.fs-images { flex-direction: row; flex-wrap: wrap; gap: 12px; }
.fs-image { position: relative; width: 120px; }
.fs-image .thumb { width: 120px; height: 90px; object-fit: cover; border: 1px solid var(--line); border-radius: 8px; display: block; background: #f7fafc; }
.fs-image .icon { position: absolute; top: 3px; right: 3px; background: rgba(255,255,255,0.88); }
.fs-image .fs-note { width: 120px; max-width: 120px; margin-top: 4px; font-size: 11px; padding: 3px 6px; }
.popup-cost { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); }
.cost-summary .k { color: var(--dim); font-size: 12.5px; font-weight: 600; }
.cost-lines { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 6px; }
.cost-line { font-size: 13px; }

/* recursive part rows on the project page indent by depth */
.part-row { padding-left: calc(12px + var(--depth, 0) * 20px); }

@media (max-width: 720px) {
  main { padding: 12px; }
  .spec-grid { grid-template-columns: 1fr; }
  .topbar { padding: 0 12px; gap: 10px; }
  .user-box span.dim { display: none; }
  .modal.wide { width: 100%; }
}
