/* Estimating / takeoff module. Loaded after styles.css; everything is prefixed .tk- to avoid touching shared styles. */
.tk-note { background: #fff8ec; border: 1px solid #f0d9ae; border-left: 5px solid var(--accent); margin-bottom: 1rem; }
.tk-subnav { margin-bottom: 1rem; flex-wrap: wrap; }
.tk-subnav .seg { min-height: 48px; }
.tk-warn-text { color: #8a5a00; font-weight: 600; } .tk-ok { color: var(--ok); font-weight: 600; }
.tk-plan h3 { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.tk-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tk-check { display: flex; align-items: center; gap: .3rem; min-height: 44px; font-weight: 500; cursor: pointer; }
.tk-check.inline { display: inline-flex; margin-left: 1rem; }
.card.inset { background: var(--bg); box-shadow: none; margin: .8rem 0; }
.tk-options { display: grid; gap: .1rem; margin-bottom: 1rem; }
[hidden].tk-drawbar, .tk-pop[hidden], .tk-drawbar [hidden], .tk-pagenav[hidden] { display: none !important; }
input.invalid, select.invalid { border-color: var(--bad); background: #fff6f6; }

/* ---- viewer page ---- */
body.tk-fullscreen { overflow: hidden; overscroll-behavior: none; touch-action: manipulation; -webkit-touch-callout: none; }
body.tk-fullscreen main { max-width: none; padding: .4rem calc(.6rem + var(--safe-r)) calc(.4rem + var(--safe-b)) calc(.6rem + var(--safe-l)); }
.tk-wrap { display: flex; flex-direction: column; height: calc(100vh - 76px); height: calc(100dvh - 76px); min-height: 440px; position: relative; }
/* full-screen plan mode: hide the app nav, plan gets the whole screen */
body.tk-immersive .topbar { display: none; }
body.tk-immersive .tk-wrap { position: fixed; inset: 0; z-index: 40; height: auto; min-height: 0; background: var(--bg); padding: calc(.4rem + var(--safe-t)) calc(.6rem + var(--safe-r)) calc(.4rem + var(--safe-b)) calc(.6rem + var(--safe-l)); }
.tk-bar { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; padding: .1rem 0 .45rem; position: relative; }
.tk-title { margin: 0; font-size: 1.05rem; max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tk-spacer { flex: 1; }
.tk-pagenav { display: flex; align-items: center; gap: .3rem; }
.tk-pageno { font-size: .9rem; color: var(--muted); white-space: nowrap; }
.tk-scale.ok { border-color: var(--ok); color: var(--ok); background: #f1faf4; }
.tk-scale.bad { background: #fdecc8; border-color: #e0b04a; color: #6d4300; }
.tk-bbtn { gap: .35rem; min-height: 46px; } .tk-bbtn .ic { font-size: 1.15rem; line-height: 1; }
.tk-bbtn[aria-pressed=true] { background: #e8eef5; border-color: var(--brand); }

.tk-main { overflow: hidden; flex: 1; display: grid; grid-template-columns: 100px minmax(0, 1fr); gap: .5rem; min-height: 0; position: relative; }
.tk-wrap.panel-open:not(.panel-overlay) .tk-main { grid-template-columns: 100px minmax(0, 1fr) 330px; }
.tk-rail { display: grid; grid-template-columns: 1fr 1fr; align-content: start; gap: .3rem; overflow-y: auto; padding-bottom: .3rem; -webkit-overflow-scrolling: touch; }
.tk-rail-h { grid-column: 1 / -1; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: .25rem 0 0 .15rem; }
.tk-tool { grid-column: 1 / -1; min-height: 56px; padding: .2rem; border: 2px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); font: inherit; font-size: .8rem; font-weight: 700; display: flex; flex-direction: row; align-items: center; justify-content: flex-start; gap: .45rem; padding-left: .55rem; cursor: pointer; touch-action: manipulation; text-align: left; line-height: 1.1; }
.tk-tool b { font-size: 1.45rem; line-height: 1; width: 1.6rem; text-align: center; flex: none; }
.tk-tool.active { background: var(--brand); color: #fff; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(232,113,10,.35); }
.tk-tool.toggle { grid-column: auto; min-height: 46px; font-size: .72rem; padding: .1rem; justify-content: center; flex-direction: column; gap: .15rem; }
.tk-tool.toggle .sw { width: 22px; height: 9px; border-radius: 9px; background: #c3cad1; position: relative; }
.tk-tool.toggle .sw::after { content: ''; position: absolute; top: 1px; left: 1px; width: 7px; height: 7px; border-radius: 50%; background: #fff; transition: left .12s; }
.tk-tool.toggle.on { background: #fde8d2; border-color: var(--accent); }
.tk-tool.toggle.on .sw { background: var(--accent); } .tk-tool.toggle.on .sw::after { left: 14px; }

.tk-stage { position: relative; min-height: 0; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; background: #aeb8c2; touch-action: none; }
.tk-stage[data-mode=draw] { border-color: var(--accent); }
.tk-viewer { position: absolute; inset: 0; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overflow: hidden; outline: none; cursor: crosshair; }
.tk-viewer[data-active-tool=pan] { cursor: grab; } .tk-viewer[data-active-tool=pan]:active { cursor: grabbing; } .tk-viewer[data-active-tool=select] { cursor: default; }
.tk-viewer:focus-visible { box-shadow: inset 0 0 0 3px rgba(232,113,10,.45); }
.tk-page { position: absolute; left: 0; top: 0; transform-origin: 0 0; background: #fff; will-change: transform; box-shadow: 0 0 0 1px rgba(0,0,0,.15); }
.tk-overlay { position: absolute; left: 0; top: 0; pointer-events: none; }

body.tk-fullscreen #toasts, body.tk-fullscreen .toast { pointer-events: none; } /* never block taps on the plan */
/* floating controls over the plan */
.tk-toolchip { position: absolute; left: 10px; top: 10px; right: 96px; z-index: 6; display: flex; align-items: center; gap: .6rem; pointer-events: none; background: rgba(255,255,255,.96); border: 2px solid var(--line); border-left: 6px solid var(--brand); border-radius: 12px; padding: .35rem .6rem; box-shadow: 0 2px 10px rgba(0,0,0,.2); max-width: 640px; }
.tk-toolchip[data-mode=draw] { border-left-color: var(--accent); }
.tk-toolchip .btn { pointer-events: auto; flex: none; }
.tk-chip-icon { font-size: 1.5rem; line-height: 1; }
.tk-chip-body { min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.tk-chip-name { font-size: 1rem; } .tk-hint { font-size: .86rem; color: #33414e; }
.tk-zoom { position: absolute; right: 10px; top: 10px; z-index: 6; display: flex; flex-direction: column; align-items: stretch; background: rgba(255,255,255,.96); border: 2px solid var(--line); border-radius: 14px; box-shadow: 0 2px 10px rgba(0,0,0,.25); overflow: hidden; width: 66px; }
.tk-zoom hr { margin: 0; border: 0; border-top: 1px solid var(--line); }
.tk-zbtn { min-height: 52px; border: 0; background: none; font: inherit; color: var(--ink); cursor: pointer; touch-action: manipulation; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05; }
.tk-zbtn b { font-size: 1.5rem; } .tk-zbtn span { font-size: .68rem; font-weight: 700; }
.tk-zbtn:active { background: #eef1f4; } .tk-zbtn[disabled] { opacity: .35; } .tk-zbtn.on { background: #fde8d2; }
.tk-zoompct { text-align: center; font-weight: 800; font-size: .86rem; padding: .15rem 0; font-variant-numeric: tabular-nums; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #f6f7f9; }
.tk-undobar { position: absolute; left: 10px; bottom: 10px; z-index: 6; display: flex; gap: .45rem; }
.tk-fab { min-height: 56px; min-width: 76px; padding: .25rem .8rem; border: 2px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.97); color: var(--ink); font: inherit; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; cursor: pointer; touch-action: manipulation; box-shadow: 0 3px 12px rgba(0,0,0,.3); }
.tk-fab b { font-size: 1.4rem; line-height: 1; }
.tk-fab.tk-undo { background: var(--brand); color: #fff; border-color: var(--brand); min-width: 104px; font-size: 1.05rem; }
.tk-fab.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.tk-fab[disabled] { opacity: .45; box-shadow: none; }
.tk-drawbar { position: absolute; right: 10px; bottom: 10px; z-index: 6; display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; max-width: calc(100% - 260px); }
[hidden].tk-drawbar, .tk-pop[hidden], .tk-drawbar [hidden], .tk-pagenav[hidden], .tk-chip-opt[hidden], .tk-scalewarn[hidden] { display: none !important; }

.tk-pop { position: absolute; right: .2rem; top: calc(100% - .3rem); z-index: 30; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .5rem .9rem .8rem; box-shadow: 0 10px 30px rgba(0,0,0,.25); min-width: 260px; max-width: min(380px, 96%); }
.tk-pop h4 { margin: .2rem 0 .2rem; }
.tk-pop .btn { width: 100%; margin-top: .4rem; }
.tk-pop-row { margin: .5rem 0; } .tk-pop-l { font-weight: 700; margin-bottom: .25rem; } .tk-pop-l small { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; }
.tk-seg { display: flex; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; }
.tk-segb { flex: 1; min-height: 46px; border: 0; background: #fff; font: inherit; font-weight: 700; cursor: pointer; touch-action: manipulation; border-left: 1px solid var(--line); }
.tk-segb:first-child { border-left: 0; } .tk-segb.on { background: var(--brand); color: #fff; }

.tk-panel { overflow-y: auto; -webkit-overflow-scrolling: touch; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .7rem .8rem; }
.tk-wrap:not(.panel-open) .tk-panel { display: none; }
.tk-panel-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.tk-panel-head h2 { font-size: 1.05rem; margin: 0; }
.tk-panel h3 { font-size: 1rem; margin: .4rem 0 .4rem; }
.tk-scalewarn { background: #fdecc8; border: 1px solid #e0b04a; border-radius: 10px; padding: .5rem .7rem; margin-bottom: .6rem; color: #6d4300; display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.tk-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: .35rem; margin: .5rem 0; }
.tk-summary:empty { display: none; }
.tk-stat { background: var(--bg); border-radius: 10px; padding: .35rem .2rem; text-align: center; display: flex; flex-direction: column; }
.tk-stat b { font-size: .95rem; font-variant-numeric: tabular-nums; } .tk-stat span { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tk-list-empty { text-align: left; padding: .8rem; background: #f6f9fc; border: 1px dashed #b9cbe0; border-radius: 12px; }
.tk-field { margin: .45rem 0; } .tk-field label { display: block; font-weight: 600; font-size: .88rem; }
.tk-field input, .tk-field select { margin-top: .2rem; }
.tk-flags { display: grid; grid-template-columns: 1fr 1fr; column-gap: .5rem; }
.tk-flags .tk-check { font-size: .88rem; min-height: 42px; }
.tk-metric { font-weight: 700; margin: .4rem 0; }
.tk-edit { border-top: 1px solid var(--line); margin-top: .4rem; } .tk-edit:empty, .tk-opts:empty { display: none; }
.tk-list { border-top: 1px solid var(--line); margin-top: .5rem; }
.tk-group { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: .6rem 0 .2rem; display: flex; align-items: center; gap: .4rem; }
.tk-group.dim { opacity: .45; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.tk-row { display: flex; align-items: center; gap: .3rem; border-top: 1px solid var(--line); }
.tk-row.sel { background: #fff4e6; }
.tk-row-main { flex: 1; min-width: 0; display: flex; justify-content: space-between; gap: .5rem; align-items: center; min-height: 46px; background: none; border: 0; font: inherit; text-align: left; cursor: pointer; padding: 0 .2rem; }
.tk-row-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; } .tk-row-val { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tk-row-del { min-width: 42px; border-color: transparent; background: none; color: var(--bad); }
.tk-total { margin-top: .6rem; font-weight: 700; padding-top: .5rem; border-top: 2px solid var(--line); }
.tk-label { pointer-events: none; font-family: -apple-system, "SF Pro Text", Roboto, sans-serif; }
.tk-item { pointer-events: none; }
.tk-scale-dlg .btn { width: 100%; }
/* drawer mode (touch devices and narrow screens): the quantities panel slides over the plan instead of squeezing it */
.tk-wrap.panel-overlay .tk-panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(350px, 92%); z-index: 15; box-shadow: -8px 0 28px rgba(0,0,0,.25); }
@media (max-width: 1000px) {
  .tk-wrap .tk-main { grid-template-columns: 96px minmax(0, 1fr) !important; }
  .tk-wrap .tk-panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(350px, 92%); z-index: 15; box-shadow: -8px 0 28px rgba(0,0,0,.25); }
}
@media (max-width: 640px) { .tk-title { max-width: 12ch; } .tk-wrap .tk-main { grid-template-columns: 88px minmax(0, 1fr) !important; } .tk-toolchip { right: 86px; } .tk-bbtn .tx { display: none; } .tk-bbtn { min-width: 46px; } }

/* when the drawer is open, keep the floating controls clear of it */
.tk-wrap.panel-open.panel-overlay .tk-zoom, .tk-wrap.panel-open .tk-main .tk-zoom { right: 10px; }
@media (min-width: 701px) {
  .tk-wrap.panel-open.panel-overlay .tk-zoom { right: 360px; }
  .tk-wrap.panel-open.panel-overlay .tk-toolchip { right: 446px; }
  .tk-wrap.panel-open.panel-overlay .tk-drawbar { right: 360px; max-width: calc(100% - 700px); }
}
@media (max-width: 1000px) and (min-width: 701px) {
  .tk-wrap.panel-open .tk-zoom { right: 360px; } .tk-wrap.panel-open .tk-toolchip { right: 446px; } .tk-wrap.panel-open .tk-drawbar { right: 360px; max-width: calc(100% - 700px); }
}
@media (max-width: 700px) { .tk-wrap.panel-open .tk-zoom { display: none; } }

/* ---- first-use guide ---- */
.tk-guide { display: flex; align-items: center; gap: .5rem .9rem; flex-wrap: wrap; background: #eef6ff; border: 1px solid #bcd7f5; border-radius: 12px; padding: .5rem .7rem; margin-bottom: .5rem; }
.tk-guide.compact { padding: .35rem .6rem; }
.tk-gsteps { list-style: none; display: flex; gap: .3rem; margin: 0; padding: 0; flex-wrap: wrap; }
.tk-gstep { display: inline-flex; align-items: center; gap: .35rem; padding: .25rem .65rem .25rem .3rem; border-radius: 99px; background: #fff; border: 2px solid var(--line); font-weight: 600; font-size: .9rem; color: var(--muted); }
.tk-gstep .n { width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; background: #dfe5ea; color: #4a5762; font-size: .85rem; font-weight: 800; }
.tk-gstep.done { color: var(--ok); border-color: #b7dcc3; } .tk-gstep.done .n { background: var(--ok); color: #fff; }
.tk-gstep.current { color: #fff; background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 3px rgba(232,113,10,.3); } .tk-gstep.current .n { background: #fff; color: var(--accent); }
.tk-gtext { flex: 1 1 220px; font-size: .92rem; min-width: 0; }
.tk-gactions { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.tk-guide.compact .tk-gtext { flex-basis: 140px; }
.tk-gclose { min-width: 42px; }
.tk-empty { padding: 1.4rem 1rem; }
.tk-empty-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .6rem; max-width: 760px; margin: .8rem auto 0; }
.tk-plan-link h3 { overflow-wrap: anywhere; } .tk-link-url { overflow-wrap: anywhere; margin: .3rem 0; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--info); text-decoration: underline; cursor: pointer; min-height: 32px; }

/* ---- takeoff sheet / quick rooms / settings ---- */
.tk-doc { max-width: 1100px; }
.tk-trade { margin-bottom: 1.2rem; break-inside: auto; }
.tk-trade h2 { margin-bottom: .2rem; }
.tk-table th, .tk-table td { padding: .4rem .5rem; font-size: .93rem; }
.tk-table td.note { color: var(--muted); font-size: .85rem; }
.tk-table td.order { background: #fff4e6; }
.tk-sub-row td { padding-top: .1rem; padding-bottom: .1rem; font-size: .82rem; color: var(--muted); border-bottom: 1px dotted var(--line); }
.tk-waste { width: 4.6rem; min-height: 42px; text-align: right; padding: .2rem .4rem; }
.tk-cost { width: 6rem; min-height: 42px; text-align: right; padding: .2rem .4rem; }
.tk-disclaimer { background: #fff8ec; border: 1px solid #f0d9ae; border-radius: 10px; padding: .6rem .8rem; font-size: .9rem; }
.tk-warnings { color: #8a5a00; padding-left: 1.1rem; }
.tk-grand { font-size: 1.1rem; text-align: right; }
.tk-quick input, .tk-quick select { min-height: 44px; min-width: 64px; padding: .3rem .5rem; }
.tk-quick td { padding: .3rem .3rem; } .tk-quick td:first-child input { min-width: 150px; }
.tk-quick .tk-finish-row td { padding: 0 .3rem .6rem; background: var(--bg); border-bottom: 2px solid var(--line); font-size: .9rem; } .tk-quick .tk-finish-row select { width: auto; display: inline-block; min-height: 40px; }
.tk-quick tfoot td { background: var(--bg); }
.tk-settings td:nth-child(2) { min-width: 150px; } .tk-settings td input, .tk-settings td select { min-height: 44px; }
.tk-settings tr.changed td:first-child { box-shadow: inset 4px 0 0 var(--accent); background: #fff8ec; }
.tk-group-row th { background: var(--brand) !important; color: #fff; font-size: .95rem !important; }
td.note { max-width: 36ch; }

@media print {
  body.tk-fullscreen main { padding: 0; }
  .tk-doc { max-width: none; } .tk-table th, .tk-table td { padding: 3px 5px; font-size: 9pt; }
  .tk-table input { border: 0; background: none; padding: 0; min-height: 0; width: 3.2rem; text-align: right; font: inherit; appearance: textfield; -webkit-appearance: none; }
  .tk-trade h2 { break-after: avoid; } .tk-trade { break-inside: auto; }
  .tk-attached-wrap { break-before: page; }
  .tk-table td.order { background: #eee !important; }
  .tk-scroll { overflow: visible; }
}
