/* BOQ Builder - "marked-up rate book" theme */
:root {
  --ink: #1B2638;
  --ink-2: #33415a;
  --muted: #5D6B80;
  --paper: #F3F5F8;
  --surface: #FFFFFF;
  --rule: #DCE1E8;
  --rule-strong: #C3CAD5;
  --hi: #FFE14D;          /* highlighter */
  --hi-tint: #FFF5BF;
  --hi-tint-2: #FFFBE3;
  --action: #2350B8;
  --action-dark: #1A3E92;
  --danger: #B42318;
  --ok: #1F7A4D;
  --radius: 6px;
  --bs-body-font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --bs-body-color: var(--ink);
  --bs-body-bg: var(--paper);
  --bs-primary: var(--action);
  --bs-primary-rgb: 35, 80, 184;
  --bs-link-color: var(--action);
  --bs-link-color-rgb: 35, 80, 184;
  --bs-link-hover-color: var(--action-dark);
  --bs-border-color: var(--rule);
  --bs-border-radius: var(--radius);
}

body { font-size: 14.5px; line-height: 1.5; background: var(--paper); color: var(--ink); }
.num, .tabular { font-variant-numeric: tabular-nums; }
h1, h2, h3, h4 { font-weight: 600; letter-spacing: -0.01em; color: var(--ink); }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
a { text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--action); outline-offset: 2px; }

/* ------------------------------------------------ buttons & forms */
.btn { font-weight: 500; border-radius: var(--radius); }
.btn-primary { --bs-btn-bg: var(--action); --bs-btn-border-color: var(--action); --bs-btn-hover-bg: var(--action-dark); --bs-btn-hover-border-color: var(--action-dark); --bs-btn-active-bg: var(--action-dark); }
.btn-outline-primary { --bs-btn-color: var(--action); --bs-btn-border-color: var(--action); --bs-btn-hover-bg: var(--action); --bs-btn-hover-border-color: var(--action); }
.btn-ink { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-ink:hover { background: var(--ink-2); color: #fff; }
.form-control, .form-select { border-color: var(--rule-strong); border-radius: var(--radius); }
.form-control:focus, .form-select:focus { border-color: var(--action); box-shadow: 0 0 0 3px rgba(35, 80, 184, .15); }
.form-label { font-weight: 500; margin-bottom: .3rem; }
.form-text { color: var(--muted); }

/* ------------------------------------------------ nav */
.app-nav { background: var(--ink); padding: .35rem 0; }
.app-nav .navbar-brand { color: #fff; font-weight: 600; display: flex; align-items: center; gap: .55rem; font-size: 1.05rem; }
.brand-mark { width: 28px; height: 28px; border-radius: 5px; background: var(--hi); color: var(--ink); display: inline-grid; place-items: center; font-size: .95rem; }
.app-nav .nav-link { color: rgba(255,255,255,.72); font-weight: 500; border-radius: 5px; padding: .4rem .7rem !important; }
.app-nav .nav-link:hover { color: #fff; }
.app-nav .nav-link.active { color: #fff; background: rgba(255,255,255,.1); }
.app-nav .navbar-toggler { color: #fff; border: 0; font-size: 1.5rem; }
.nav-user { color: #fff; text-decoration: none; display: flex; align-items: center; gap: .5rem; }
.nav-user:hover { color: #fff; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: rgba(255,255,255,.14); display: inline-grid; place-items: center; font-weight: 600; font-size: .85rem; }

.flash-wrap { position: fixed; top: 62px; left: 50%; transform: translateX(-50%); z-index: 1080; width: min(520px, calc(100vw - 32px)); }
.flash-wrap .alert { box-shadow: 0 6px 20px rgba(27,38,56,.14); }

/* ------------------------------------------------ generic page */
.page { max-width: 1240px; margin: 0 auto; padding: 28px 20px 60px; }
.page-narrow { max-width: 760px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-head p { color: var(--muted); margin: .2rem 0 0; }
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); }
.panel-body { padding: 20px; }
.panel h2 { font-size: 1.05rem; margin-bottom: 14px; }
.table-clean { margin: 0; }
.table-clean th { font-weight: 600; color: var(--muted); font-size: .8rem; border-bottom: 1px solid var(--rule-strong); background: #fafbfc; white-space: nowrap; }
.table-clean td, .table-clean th { padding: .65rem .8rem; vertical-align: middle; }
.table-clean tbody tr:hover { background: #f8f9fb; }
.badge-soft { background: #eef1f6; color: var(--ink-2); font-weight: 500; }
.badge-draft { background: #eef1f6; color: var(--ink-2); }
.badge-final { background: #e3f3ea; color: var(--ok); }
.badge-archived { background: #f3f3f3; color: #777; }

/* ------------------------------------------------ auth */
.auth-body { min-height: 100vh; display: grid; place-items: center; background: var(--ink); padding: 20px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 10px; padding: 32px 30px; box-shadow: 0 24px 60px rgba(0,0,0,.3); }
.auth-card .brand-mark { width: 40px; height: 40px; font-size: 1.3rem; margin-bottom: 14px; }
.auth-card h1 { font-size: 1.35rem; margin-bottom: .25rem; }
.auth-card p.lead-sm { color: var(--muted); margin-bottom: 22px; }

/* ------------------------------------------------ dashboard */
.project-row td:first-child a { font-weight: 600; color: var(--ink); text-decoration: none; }
.project-row td:first-child a:hover { color: var(--action); }
.project-meta { color: var(--muted); font-size: .85rem; }
.empty-state { text-align: center; padding: 56px 20px; }
.empty-state .bi { font-size: 2.4rem; color: var(--rule-strong); }

/* ------------------------------------------------ BOQ editor shell */
body.editor { overflow: hidden; }
.editor-shell { display: grid; grid-template-rows: auto auto 1fr auto; height: calc(100vh - 54px); }
.proj-bar { background: var(--surface); border-bottom: 1px solid var(--rule); padding: 10px 18px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.proj-bar h1 { font-size: 1.15rem; margin: 0; }
.proj-bar .proj-sub { color: var(--muted); font-size: .85rem; }
.proj-bar .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.unit-pill { font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 20px; border: 1px solid var(--rule-strong); color: var(--ink-2); }

.bill-tabs { background: var(--surface); border-bottom: 1px solid var(--rule); padding: 0 18px; display: flex; align-items: flex-end; gap: 2px; overflow-x: auto; }
.bill-tab { border: 1px solid transparent; border-bottom: 0; background: none; padding: 8px 14px 7px; font-weight: 500; color: var(--muted); border-radius: 6px 6px 0 0; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.bill-tab:hover { color: var(--ink); background: #f6f7f9; }
.bill-tab.active { color: var(--ink); background: var(--paper); border-color: var(--rule); position: relative; top: 1px; }
.bill-tab .bill-no { font-size: .72rem; font-weight: 600; background: #e6e9ef; border-radius: 4px; padding: 0 5px; color: var(--ink-2); }
.bill-tab.active .bill-no { background: var(--hi); color: var(--ink); }
.bill-tab .bill-amt { font-size: .8rem; color: var(--muted); }
.bill-add { color: var(--action); }

.editor-main { display: grid; grid-template-columns: 250px 1fr; min-height: 0; }
.rail { background: var(--surface); border-right: 1px solid var(--rule); overflow-y: auto; min-height: 0; }
.rail-search { padding: 12px; border-bottom: 1px solid var(--rule); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.rail-views { padding: 8px; border-bottom: 1px solid var(--rule); display: grid; gap: 2px; }
.rail-link { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; text-align: left; padding: 7px 8px; border-radius: 6px; color: var(--ink); font-weight: 500; }
.rail-link:hover { background: #f3f5f8; }
.rail-link.active { background: #e9eef9; color: var(--action-dark); }
.rail-link .count { margin-left: auto; font-size: .78rem; color: var(--muted); font-weight: 500; }
.rail-sections { padding: 8px; display: grid; gap: 1px; }
.sec-link { display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 8px; width: 100%; border: 0; background: none; text-align: left; padding: 5px 8px 5px 5px; border-radius: 6px; color: var(--ink); }
.sec-link:hover { background: #f3f5f8; }
.sec-link .sec-code { font-weight: 700; font-size: .95rem; height: 30px; border-radius: 5px; display: grid; place-items: center; background: #eef1f6; color: var(--ink-2); }
.sec-link .sec-name { font-size: .84rem; line-height: 1.25; }
.sec-link .sec-sel { font-size: .72rem; font-weight: 600; min-width: 20px; text-align: center; border-radius: 10px; padding: 1px 6px; background: var(--hi); color: var(--ink); }
.sec-link.has-sel .sec-code { background: var(--hi-tint); color: var(--ink); box-shadow: inset 3px 0 0 var(--hi); }
.sec-link.active { background: var(--ink); color: #fff; }
.sec-link.active .sec-code { background: var(--hi); color: var(--ink); box-shadow: none; }

.work { overflow-y: auto; min-height: 0; padding: 0 0 30px; }
.work-head { position: sticky; top: 0; z-index: 3; background: var(--paper); padding: 16px 22px 10px; border-bottom: 1px solid var(--rule); display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.work-head .big-code { font-size: 1.9rem; font-weight: 700; line-height: 1; background: var(--hi); padding: 4px 10px; border-radius: 6px; }
.work-head h2 { margin: 0; font-size: 1.15rem; }
.work-head .sub { color: var(--muted); font-size: .85rem; }
.work-head .tools { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.grp { margin: 18px 22px 0; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); }
.grp-head { padding: 10px 14px; border-bottom: 1px solid var(--rule); display: flex; align-items: baseline; gap: 10px; }
.grp-head h3 { font-size: .95rem; margin: 0; }
.grp-notes-btn { margin-left: auto; font-size: .8rem; border: 0; background: none; color: var(--action); white-space: nowrap; }
.grp-notes { padding: 10px 16px; background: #f8f9fb; border-bottom: 1px solid var(--rule); font-size: .84rem; color: var(--ink-2); max-height: 320px; overflow-y: auto; }
.grp-notes p { margin: 0 0 .4rem; }

table.items { width: 100%; border-collapse: collapse; }
table.items th { font-size: .75rem; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--rule); background: #fafbfc; text-align: left; }
table.items td { padding: 8px; border-bottom: 1px solid #edf0f4; vertical-align: top; }
table.items tr:last-child td { border-bottom: 0; }
table.items .c-chk { width: 34px; padding-left: 12px; }
table.items .c-code { width: 74px; font-weight: 600; white-space: nowrap; }
table.items .c-unit { width: 70px; color: var(--ink-2); white-space: nowrap; }
table.items .c-rate { width: 104px; text-align: right; white-space: nowrap; }
table.items .c-qty { width: 150px; }
table.items .c-amt { width: 120px; text-align: right; font-weight: 600; white-space: nowrap; }
table.items .c-more { width: 40px; }
table.items th.c-rate, table.items th.c-amt { text-align: right; }
.form-check-input.item-chk { width: 1.15rem; height: 1.15rem; margin-top: .1rem; cursor: pointer; border-color: var(--rule-strong); }
.form-check-input.item-chk:checked { background-color: var(--ink); border-color: var(--ink); }
.desc { color: var(--ink); font-size: .88rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.desc.open { -webkit-line-clamp: unset; display: block; }
.desc mark { background: var(--hi); padding: 0 1px; }
.sec-tag { font-size: .7rem; color: var(--muted); font-weight: 500; }

tr.item-row.sel td { background: var(--hi-tint-2); }
tr.item-row.sel td.c-chk { box-shadow: inset 4px 0 0 var(--hi); }
tr.item-row.sel .desc { color: var(--ink); }
tr.group-row td { background: #f7f8fa; font-size: .86rem; color: var(--ink-2); }
tr.child-row td.c-code { padding-left: 18px; }
.qty-wrap { display: flex; gap: 4px; align-items: center; }
.qty-input { width: 92px; text-align: right; font-variant-numeric: tabular-nums; padding: .25rem .45rem; font-size: .88rem; }
.qty-input:disabled { background: transparent; border-color: transparent; }
.icon-btn { border: 1px solid transparent; background: none; color: var(--muted); border-radius: 5px; padding: 2px 6px; line-height: 1.2; }
.icon-btn:hover { color: var(--ink); border-color: var(--rule); background: #fff; }
.icon-btn.on { color: var(--action); }
.measured-flag { font-size: .7rem; color: var(--action); display: block; margin-top: 2px; }
.m-code { display: none; font-weight: 600; font-size: .8rem; }
.remark { font-size: .78rem; color: var(--muted); margin-top: 3px; font-style: italic; }
.saving { opacity: .55; }

.totals-bar { background: var(--ink); color: #fff; padding: 10px 22px; display: flex; flex-wrap: wrap; gap: 8px 28px; align-items: center; }
.totals-bar .t-label { font-size: .75rem; color: rgba(255,255,255,.62); display: block; }
.totals-bar .t-val { font-weight: 600; font-variant-numeric: tabular-nums; font-size: 1rem; }
.totals-bar .t-grand .t-val { color: var(--hi); font-size: 1.2rem; }
.totals-bar .t-grand { margin-left: auto; text-align: right; }

.summary-card { margin: 18px 22px 0; }
.summary-table td, .summary-table th { padding: .5rem .8rem; }
.summary-table .bill-row td { font-weight: 600; background: #f7f8fa; }
.summary-table .grand td { font-weight: 700; font-size: 1.05rem; border-top: 2px solid var(--ink); }

/* measurement modal */
.meas-table input { font-size: .85rem; padding: .25rem .4rem; text-align: right; font-variant-numeric: tabular-nums; }
.meas-table input.m-desc { text-align: left; }
.meas-table td { padding: 4px; vertical-align: middle; }
.meas-table th { font-size: .75rem; color: var(--muted); font-weight: 600; padding: 4px; }
.meas-table .m-qty { font-variant-numeric: tabular-nums; text-align: right; font-weight: 600; white-space: nowrap; }
.meas-table tr.deduct .m-qty { color: var(--danger); }

.loading { padding: 40px; text-align: center; color: var(--muted); }

@media (max-width: 900px) {
  body.editor { overflow: auto; }
  .editor-shell { height: auto; min-height: calc(100vh - 54px); }
  .editor-main { grid-template-columns: minmax(0, 1fr); }
  .rail { border-right: 0; border-bottom: 1px solid var(--rule); overflow: visible; }
  .rail-views { grid-template-columns: 1fr 1fr; }
  .rail-sections { display: flex; overflow-x: auto; gap: 6px; padding: 8px 12px; scrollbar-width: thin; }
  .sec-link { flex: 0 0 auto; width: auto; grid-template-columns: auto; padding: 3px; position: relative; }
  .sec-link .sec-name { display: none; }
  .sec-link .sec-code { width: 38px; }
  .sec-link .sec-sel { position: absolute; top: -4px; right: -4px; min-width: 16px; padding: 0 4px; font-size: .65rem; }
  .work { overflow: visible; }
  .work-head { position: static; padding: 12px 14px 8px; }
  .grp { margin: 12px 10px 0; }
  table.items .c-unit, table.items .c-rate, table.items .c-more, table.items .c-code { display: none; }
  .m-code { display: block; }
  table.items .c-chk { width: 30px; padding-left: 8px; }
  table.items .c-qty { width: 92px; }
  table.items .c-amt { width: 78px; font-size: .8rem; }
  .qty-wrap { flex-wrap: wrap; }
  .qty-input { width: 72px; }
  .desc { -webkit-line-clamp: 3; }
  .proj-bar .actions { margin-left: 0; }
  .totals-bar { position: sticky; bottom: 0; padding: 8px 14px; gap: 4px 18px; }
  .totals-bar > div:nth-child(2), .totals-bar > div:nth-child(3) { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.code-chip { font-size: 1.9rem; font-weight: 700; line-height: 1; background: var(--hi); padding: 4px 10px; border-radius: 6px; }

/* ------------------------------------------------ rate library editing */
.lock-note { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--rule); border-left: 4px solid var(--ink); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 18px; font-size: .9rem; }
.lock-note > .bi { font-size: 1.2rem; color: var(--ink); }
.rate-diff { font-size: .72rem; font-weight: 500; white-space: nowrap; }
.rate-diff.up { color: #9A3412; }
.rate-diff.down { color: var(--ok); }
.lib-tags { display: flex; gap: 4px; margin-top: 3px; }
.tag { font-size: .68rem; font-weight: 600; padding: 0 6px; border-radius: 3px; line-height: 1.6; }
.tag-added { background: var(--hi); color: var(--ink); }
.tag-edited { background: var(--hi-tint); color: var(--ink); border: 1px solid #F2D86B; }
.tag-hidden { background: #eceef2; color: var(--muted); }
tr.is-hidden td { opacity: .55; }
tr.is-hidden td.lib-actions { opacity: 1; }
.lib-table .lib-actions { width: 104px; }
.chg-old { color: var(--muted); text-decoration: line-through; }
.chg-new { font-weight: 600; }
.diff-table td, .diff-table th { padding: .45rem .6rem; font-size: .85rem; vertical-align: top; }
