/* App-local components on top of cu-eng-theme.css: app shell, panels, button
   levels, forms, drop zones, progress, steps, timeline, sensor layout.
   Same tokens, same one-hue-plus-neutrals rule.

   Structure of every page:
     app bar (site navigation)  ->  page head (what this page is)  ->  panels.
   A panel is one unit of work: title + one-line purpose on the left, its own
   actions on the right, content below. Panels sit on a light grey ground so
   their edges are always visible.

   Button levels: .cu-btn (primary - at most one per panel), .cu-btn--ghost
   (secondary), .btn-text (row actions such as Delete). */

body { background: #F3F2F2; }
.cu-page { padding-top: calc(var(--cu-band-top) + 4px); }

/* ---------------------------------------------------------------- app bar */
.app-bar { display: flex; align-items: center; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap;
           padding: 14px 0; border-bottom: 1px solid var(--cu-line); }
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; color: var(--cu-ink); }
.brand:hover { color: var(--cu-ink); }
.brand span { border-left: 1px solid var(--cu-line); padding-left: 14px; font-weight: 700; font-size: 15px; }
.app-nav { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 14px; }
.app-nav a:not(.cu-btn) { font-weight: 600; text-decoration: none; color: var(--cu-grey); padding: 6px 12px; }
.app-nav a:not(.cu-btn):hover { color: var(--cu-ink); }
.app-nav a[aria-current="page"] { color: var(--cu-ink); box-shadow: inset 0 -2px 0 var(--cu-maroon); }
.app-nav .cu-btn { margin-left: 8px; text-decoration: none; }

.page-head { padding: 26px 0 4px; }
.page-head .cu-title { font-size: clamp(28px, 3.4vw, 36px); }
.page-head .cu-sub { margin-top: 6px; font-size: 16px; }

main { padding: 22px 0 0; min-height: 50vh; }

/* ----------------------------------------------------------------- panels */
.panel { background: var(--cu-surface); border: 1px solid var(--cu-line); padding: 20px 24px 24px; }
.panel + .panel, .panel + .page-actions, * + .panel { margin-top: 18px; }
.panel--muted { background: var(--cu-fill); }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap;
              margin: 0 0 18px; }
.panel-head h2 { margin: 0; font-size: 20px; font-weight: 700; line-height: 1.25; display: flex; align-items: center; gap: 10px; }
.panel-head p { margin: 3px 0 0; color: var(--cu-grey); font-size: 13.5px; max-width: 72ch; }
.panel-head .actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.panel-sub { margin: 22px 0 10px; padding-top: 16px; border-top: 1px solid var(--cu-line-soft);
             font-size: var(--cu-size-micro); font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--cu-grey); }
.num-badge { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
             background: var(--cu-maroon); color: var(--cu-on-maroon); font-size: 14px; font-weight: 700; flex: none; }

/* bottom bar holding the page's next step */
.page-actions { display: flex; justify-content: flex-end; align-items: center; gap: 12px; flex-wrap: wrap;
                background: var(--cu-surface); border: 1px solid var(--cu-line); padding: 14px 24px; }
.page-actions .hint { margin-right: auto; color: var(--cu-grey); font-size: 13.5px; }

/* ---------------------------------------------------------------- buttons */
.cu-btn { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.cu-btn:disabled { opacity: .45; cursor: not-allowed; }
.cu-btn--small { padding: 5px 11px; font-size: 13px; }
.btn-text { appearance: none; background: none; border: 0; padding: 4px 6px; font: inherit; font-size: 13px; font-weight: 600;
            color: var(--cu-grey); cursor: pointer; text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 3px; }
.btn-text:hover { color: var(--cu-maroon); text-decoration-color: currentColor; }

/* ------------------------------------------------------------------- tabs */
/* Campaign tabs are the workflow: numbered, each with a status. */
.app-tabs { display: flex; flex-wrap: wrap; gap: 0; background: var(--cu-surface); border: 1px solid var(--cu-line);
            position: sticky; top: var(--cu-band-top); z-index: 30; margin-top: 18px; }
.app-tabs .cu-tab { display: flex; align-items: center; gap: 10px; padding: 13px 20px 12px; margin: 0;
                    border-bottom: 3px solid transparent; border-right: 1px solid var(--cu-line-soft); text-align: left; }
.app-tabs .cu-tab .n { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
                       border: 1.5px solid var(--cu-grey); font-size: 12px; font-weight: 700; color: var(--cu-grey); flex: none; }
.app-tabs .cu-tab[aria-selected="true"] { color: var(--cu-ink); border-bottom-color: var(--cu-maroon); background: var(--cu-maroon-wash); }
.app-tabs .cu-tab[aria-selected="true"] .n { background: var(--cu-maroon); border-color: var(--cu-maroon); color: #fff; }
.app-tabs .cu-tab small { display: block; font-size: 12px; font-weight: 400; color: var(--cu-grey); line-height: 1.2; }
.tabpanel { padding-top: 18px; }

/* ------------------------------------------------------------------ forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px 20px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
@media (max-width: 720px) { .form-grid .span-2 { grid-column: 1 / -1; } }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: var(--cu-size-micro); font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--cu-grey); }
.field > span b { color: var(--cu-maroon); }
.field small { color: var(--cu-grey); font-size: 12.5px; }

input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  font: inherit; font-size: 15px; color: var(--cu-ink);
  background: var(--cu-surface);
  border: 1px solid var(--cu-line);
  padding: 7px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--cu-maroon); outline: none; box-shadow: 0 0 0 1px var(--cu-maroon); }
form.was-submitted :is(input, select, textarea):invalid { border-color: var(--cu-maroon); border-style: dashed; }
textarea { min-height: 70px; resize: vertical; }
.cu-table input, .cu-table select { padding: 4px 6px; font-size: 14px; }

.choice { display: flex; gap: 22px; flex-wrap: wrap; margin-bottom: 18px; }
.choice label { display: flex; gap: 8px; align-items: center; cursor: pointer; font-weight: 600; }
.choice input { accent-color: var(--cu-maroon); }

.map { height: 320px; border: 1px solid var(--cu-line); background: var(--cu-fill); }

/* ------------------------------------------------------------- drop zone */
.drop {
  display: block;
  border: 1.5px dashed var(--cu-grey);
  background: var(--cu-fill);
  padding: 26px 18px;
  text-align: center;
  color: var(--cu-grey);
  font-size: 14px;
  cursor: pointer;
}
.drop b { color: var(--cu-ink); }
.drop:hover, .drop.is-over { border-color: var(--cu-maroon); background: var(--cu-maroon-wash); color: var(--cu-ink); }
.drop--compact { padding: 8px 10px; font-size: 13px; }

/* --------------------------------------------------------------- progress */
.progress { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; font-size: 13.5px; }
.progress .cu-meter { margin-top: 0; }
.log { max-height: 220px; overflow-y: auto; border: 1px solid var(--cu-line-soft); padding: 6px 10px;
       font-size: 13px; background: var(--cu-surface); }
.log div { padding: 2px 0; border-bottom: 1px solid var(--cu-line-soft); }
.log div:last-child { border-bottom: 0; }

/* ----------------------------------------------------------------- steps */
.steps { display: flex; gap: 0; flex-wrap: wrap; counter-reset: s; margin: 0; padding: 0; list-style: none; border: 1px solid var(--cu-line); background: var(--cu-surface); }
.steps li { flex: 1 1 160px; padding: 10px 14px; font-size: 14px; color: var(--cu-grey); border-right: 1px solid var(--cu-line); }
.steps li:last-child { border-right: 0; }
.steps li::before { counter-increment: s; content: counter(s); font-weight: 700; margin-right: 8px; color: var(--cu-grey); }
.steps li.is-current { background: var(--cu-maroon-wash); color: var(--cu-ink); font-weight: 600; }
.steps li.is-current::before, .steps li.is-done::before { color: var(--cu-maroon); }
.steps li.is-done { color: var(--cu-ink); }

/* ---------------------------------------------------------------- flags */
.flags { margin: 6px 0 0; padding-left: 18px; font-size: 13.5px; }
.flags li { margin: 2px 0; }
.flags .lv-fail { font-weight: 600; }
.flags .lv-info { color: var(--cu-grey); }

/* -------------------------------------------------------------- timeline */
.timeline { width: 100%; height: auto; display: block; }
.timeline text { font-family: var(--cu-font); font-size: 11px; fill: var(--cu-grey); }
.timeline .lbl { fill: var(--cu-ink); font-size: 12px; }

.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); z-index: 60;
         background: var(--cu-ink); color: #fff; padding: 9px 16px; font-size: 14px; max-width: 90vw; }
.toast[hidden] { display: none; }

.muted-row td { color: var(--cu-grey); }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: 12.5px; }

/* ---------------------------------------------------------- sensor layout */
.floor-body { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr); gap: 24px; align-items: start; }
@media (max-width: 900px) { .floor-body { grid-template-columns: 1fr; } }
.plan-wrap { border: 1px solid var(--cu-line); background: var(--cu-surface); }
.plan { display: block; width: 100%; height: auto; touch-action: none; user-select: none; }
.plan .hit { cursor: crosshair; }
.plan .grid { stroke: var(--cu-line); stroke-width: 1; pointer-events: none; }
.plan text { font-family: var(--cu-font); }
.plan .dim { font-size: 20px; fill: var(--cu-grey); }
.plan .ax { font-size: 22px; font-weight: 700; fill: var(--cu-ink); }
.plan .mk { cursor: grab; }
.plan .mk:active { cursor: grabbing; }
.plan .mk:focus { outline: none; }
.plan .mk:focus circle.body { stroke-width: 5; }
.plan .mk circle.body { stroke: var(--cu-maroon); stroke-width: 3; }
.plan .mk circle.fixed { fill: var(--cu-maroon); }
.plan .mk circle.roving { fill: var(--cu-maroon-wash); }
.plan .mk.is-active circle.body { stroke-width: 5; stroke: var(--cu-ink); }
/* drag handles at arrow tips: invisible until hovered, generous to grab */
.plan .handle { fill: transparent; stroke: transparent; stroke-width: 2; cursor: grab; }
.plan .handle:hover, .plan .gaxes:hover .gx-handle { fill: rgba(148, 17, 20, .12); stroke: var(--cu-maroon); }
.plan .gring { fill: var(--cu-surface); stroke: var(--cu-line); stroke-width: 1.5; }
.axes-ctl { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--cu-line-soft); }
.axes-ctl input { padding: 4px 6px; font-size: 14px; }
tr.pickrow { cursor: pointer; }
tr.pickrow:not(.is-current):hover td { background: var(--cu-fill); }
.plan .mk line.sx { stroke: var(--cu-maroon); stroke-width: 4; }
.plan .mk line.sy { stroke: var(--cu-grey); stroke-width: 4; stroke-dasharray: 8 5; }
.plan .mk .axl { font-size: 20px; font-weight: 700; stroke: none; }
.plan .mk .axl.sx { fill: var(--cu-maroon); }
.plan .mk .axl.sy { fill: var(--cu-grey); }
.plan .mk .lbl { font-size: 22px; font-weight: 700; fill: var(--cu-ink); paint-order: stroke; stroke: #fff; stroke-width: 5px; }
.sensor-list td { padding: 8px 10px; }
.sensor-list select { width: auto; }
#qc-out:not(:empty) { margin-top: 18px; }

/* ----------------------------------------------------------- point photos */
.photos { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-width: 90px; }
.thumb { position: relative; display: block; }
.thumb img { display: block; width: 46px; height: 46px; object-fit: cover; border: 1px solid var(--cu-line); }
.thumb-del { position: absolute; top: -7px; right: -7px; width: 18px; height: 18px; padding: 0; border-radius: 50%;
             border: 1px solid var(--cu-line); background: var(--cu-surface); color: var(--cu-grey);
             font-size: 13px; line-height: 15px; cursor: pointer; }
.thumb-del:hover { color: var(--cu-maroon); border-color: var(--cu-maroon); }
.photo-add { white-space: nowrap; }
.mini { float: right; margin-left: 8px; }
.mini img { display: block; width: 40px; height: 40px; object-fit: cover; border: 1px solid var(--cu-line); }
/* sensor codes never break across lines */
#rov-body td:first-child, #fixed-sec td:first-child, .sensor-list b.mono, #qc-out td.mono { white-space: nowrap; }
.plan .grid.axis { stroke: var(--cu-grey); stroke-width: 1.5; stroke-dasharray: 8 6; }
.axes-ctl .field > span { font-size: 10px; }

/* all-floors dimensions table */
details.dims { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--cu-line-soft); }
details.dims summary { cursor: pointer; font-weight: 600; color: var(--cu-maroon); }
.dims-table td { padding: 6px 12px; vertical-align: middle; }
.dims-table select, .dims-table input { width: auto; }
.dims-table tr.has-sensors td { background: var(--cu-fill); }
.fill-range select, .fill-range input { width: auto; padding: 4px 6px; font-size: 14px; }
input:disabled, select:disabled { background: var(--cu-fill); color: var(--cu-grey); cursor: not-allowed; }

/* batch-input row and typical row in the all-floors table */
.csv-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; font-size: 13px; }
.dims-table tr.is-typical td { background: var(--cu-maroon-wash); }

/* ------------------------------------------------------------ outline editor */
.poly-dlg { width: min(1100px, 96vw); max-height: 94vh; border: 1px solid var(--cu-line); padding: 22px 26px; color: var(--cu-ink);
            font-family: var(--cu-font); box-shadow: 0 20px 60px -20px rgba(0, 0, 0, .45); }
.poly-dlg::backdrop { background: rgba(35, 31, 32, .4); }
.poly-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.poly-head h2 { margin: 0; font-size: 20px; }
.poly-head .cu-drawer-close { position: static; }
.poly-body { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, 1fr); gap: 20px; align-items: start; }
@media (max-width: 860px) { .poly-body { grid-template-columns: 1fr; } }
.poly-canvas { border: 1px solid var(--cu-line); }
.poly-canvas svg { display: block; width: 100%; height: auto; cursor: crosshair; touch-action: none; user-select: none; }
.poly-canvas .bg { fill: var(--cu-surface); }
.poly-canvas .g { stroke: var(--cu-line-soft); stroke-width: 1; }
.poly-canvas .g0 { stroke: var(--cu-grey); stroke-width: 1.2; stroke-dasharray: 6 5; }
.poly-canvas .lab { font: 12px var(--cu-font); fill: var(--cu-grey); }
.poly-canvas .poly { fill: rgba(148, 17, 20, .08); stroke: var(--cu-maroon); stroke-width: 2.5; }
.poly-canvas .vx { cursor: grab; }
.poly-canvas .vx circle { fill: var(--cu-surface); stroke: var(--cu-maroon); stroke-width: 2.5; }
.poly-canvas .vx.sel circle { fill: var(--cu-maroon); }
.poly-canvas .vx text { font: 700 12px var(--cu-font); fill: var(--cu-ink); paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.poly-side { display: flex; flex-direction: column; gap: 12px; }
.poly-table { max-height: 330px; overflow-y: auto; }
.poly-table td { padding: 5px 8px; }
.poly-table input { width: 88px; padding: 4px 6px; font-size: 14px; }
.poly-msg { margin: 0; font-size: 13.5px; }
/* interpolated elevations are shown as grey italic placeholders */
.dims-table [data-elev]::placeholder { color: var(--cu-grey); font-style: italic; opacity: .8; }

/* building geometry: 3D + side views */
details.g3 summary { cursor: pointer; font-weight: 600; color: var(--cu-maroon); font-size: 17px; }
.g3-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin: 14px 0 10px; font-size: 13.5px; }
.g3-tools label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.g3-tools .seg { display: inline-flex; border: 1px solid var(--cu-line-soft); }
.g3-tools .seg button { border: 0; background: #fff; padding: 4px 11px; font: inherit; cursor: pointer; }
.g3-tools .seg button + button { border-left: 1px solid var(--cu-line-soft); }
.g3-tools .seg button:hover { background: var(--cu-maroon); color: #fff; }
.g3-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }
.g3-grid figure { margin: 0; min-width: 0; }
.g3-grid figcaption { font-weight: 600; font-size: 13.5px; margin-bottom: 4px; }
.g3-grid figcaption .cu-grey { font-weight: 400; }
.g3-view { height: 520px; border: 1px solid var(--cu-line-soft); background: #fff; }
.g3-view canvas { display: block; }
.g3-note { font-size: 13px; color: #555; margin: 10px 0 0; }
.g3-story { font: 600 10.5px/1 ui-monospace, Consolas, monospace; color: #666; white-space: nowrap; transform: translateX(6px); }
.g3-story b { color: #231f20; }
.g3-story.measured b { color: var(--cu-maroon); }
.g3-story.interp { font-style: italic; color: #999; }
.g3-story.nosize { opacity: .5; }
.g3-tag { font: 600 10px/1 ui-monospace, Consolas, monospace; color: #fff; background: rgba(242,140,0,.9); padding: 2px 4px; white-space: nowrap; }
.g3-tag.fixed { background: rgba(31,122,224,.9); }
.g3-axis { font: 700 13px var(--cu-font); }
@media (max-width: 1100px) { .g3-grid { grid-template-columns: 1fr 1fr; } .g3-grid figure:first-child { grid-column: 1 / -1; } }
@media (max-width: 640px) { .g3-grid { grid-template-columns: 1fr; } .g3-view { height: 420px; } }
.csv-row .clear-all { margin-left: auto; }

/* global X / floor plan rotation */
.orient-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0 0; }
.orient { padding: 12px 14px; background: #faf8f8; border: 1px solid var(--cu-line-soft); font-size: 14px; display: flex; flex-direction: column; }
.orient p { margin: 0 0 8px; }
.orient .orient-title { margin-bottom: 4px; }
.orient .cu-row { margin-top: auto; }
@media (max-width: 800px) { .orient-pair { grid-template-columns: 1fr; } }

.g3-compass { font: 700 13px var(--cu-font); color: #8a8486; }
.g3-compass.north { color: var(--cu-maroon); }


/* logged-in user menu; admin-only controls */
body:not(.role-admin) [data-admin-only] { display: none !important; }
.user-menu { position: relative; margin-left: 8px; }
.user-menu summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-size: 14px; padding: 4px 6px; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu .user-name { font-weight: 600; }
.user-pop { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--cu-line-soft);
  box-shadow: 0 6px 20px rgba(0,0,0,.08); min-width: 180px; z-index: 50; display: flex; flex-direction: column; }
.user-pop a, .user-pop button { text-align: left; padding: 10px 14px; font: inherit; font-size: 14px; background: none; border: 0;
  color: var(--cu-ink); cursor: pointer; text-decoration: none; }
.user-pop a:hover, .user-pop button:hover { background: var(--cu-maroon-wash); }
.login-wrap { display: flex; justify-content: center; padding: 40px 0 60px; }
.login-panel { width: min(100%, 420px); }

.g3-grid--small .g3-view { height: 420px; }
#geo-preview { margin-top: 12px; }

/* delete / destructive actions: bright red, not the CU maroon of normal buttons */
:root { --danger: #d32f2f; --danger-dark: #b71c1c; --danger-wash: #fdecea; }
.btn-danger { display: inline-flex; align-items: center; gap: 7px; font: 600 15px/1 var(--cu-font); padding: 11px 18px;
  background: var(--danger); color: #fff; border: 1.5px solid var(--danger); cursor: pointer; white-space: nowrap; }
.btn-danger:hover, .btn-danger:focus-visible { background: var(--danger-dark); border-color: var(--danger-dark); }
.btn-danger--outline { background: #fff; color: var(--danger); }
.btn-danger--outline:hover, .btn-danger--outline:focus-visible { background: var(--danger); color: #fff; }
.btn-danger--small, .cu-num .btn-danger { font-size: 13px; padding: 6px 11px; }
.btn-danger .ico, .btn-text.danger .ico { width: 14px; height: 14px; flex: none; }
.btn-text.danger { color: var(--danger); font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.btn-text.danger:hover, .btn-text.danger:focus-visible { color: #fff; background: var(--danger); text-decoration: none; }
.danger-zone { border: 1.5px solid #f2b8b5; background: var(--danger-wash); }
.danger-zone h2 { color: var(--danger-dark); }

/* finished states in green */
.cu-tag.tag-ok { background: #2e7d32; border-color: #2e7d32; color: #fff; }

/* fixed sensors table: the reference row */
.fx-table tr.is-ref td { background: #f6faf6; }
.fx-table .drop--compact { margin-top: 4px; }

.fx-files { min-width: 190px; }
.fx-table .drop--empty { padding: 14px 10px; border-color: var(--cu-maroon); color: var(--cu-ink); }

/* the page fills the window, so short pages (login) keep the footer and the bottom band at the bottom */
html, body { min-height: 100%; }
body { min-height: 100vh; display: flex; flex-direction: column; }
.cu-page { flex: 1 0 auto; display: flex; flex-direction: column; }
.cu-page > main { flex: 1 0 auto; }
.login-wrap { align-items: center; }
.remember { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--cu-ink); cursor: pointer; }
.cu-sign a { color: inherit; }

/* someone else holds the edit lease */
.lease-bar { position: sticky; top: 0; z-index: 60; display: flex; gap: 16px; align-items: center; justify-content: center;
  flex-wrap: wrap; padding: 10px 16px; background: #fff4d6; border-bottom: 1px solid #e8c766; font-size: 14px; color: #5a4300; }
.lease-bar[hidden] { display: none; }
.lease-bar .btn-text { color: #5a4300; text-decoration: underline; }
