/* Project page, overview and the lines grid. MSE tokens only; widths through data-w (CSP). */

/* Overview */
.ov { display: grid; gap: var(--sp-4); }
.ov-tiles .stat { height: 100%; }
.meter-card { display: grid; gap: 12px; }
.meter-lede { font-size: var(--fs-md); color: var(--text-2); }
.meter-lede b { font-family: "Geist Mono", ui-monospace, monospace; font-size: var(--fs-xl); color: var(--text); font-weight: 650; }
.mt { margin-top: 10px; margin-bottom: 10px; }
.ov-checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.ov-checks a { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 10px; color: var(--text); min-height: var(--tap); }
.ov-checks a:hover { background: oklch(from var(--blue) l c h / .08); text-decoration: none; }
.ov-checks a span:nth-child(3) { flex: 1; min-width: 0; }
.ov-checks .mono { color: var(--text-3); font-size: 12px; }
.bad-ink { color: var(--bad-ink); }

/* Lines screen */
.lines-screen { display: grid; gap: 0; min-width: 0; }
.lines-screen .toolbar { margin-bottom: 10px; }
.lines-screen .toolbar select.input { max-width: 190px; padding-right: 34px; }
.l-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.l-state { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.bulk-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 12px; margin-bottom: 12px; border-radius: var(--radius-sm);
  border: 1px solid oklch(from var(--blue) l c h / .35); background: oklch(from var(--blue) l c h / .07); position: sticky; top: calc(var(--bar-h) + 6px); z-index: 3; }
.bulk-bar select, .bulk-bar input:not([type]) , .bulk-bar input[name] { padding: 7px 10px; border-radius: 9px; border: 1px solid var(--card-edge); background: var(--field); max-width: 180px; }
.bulk-bar .tag-editor { min-height: 36px; padding: 3px 6px; max-width: 260px; }
.bulk-bar .tag-in { min-width: 90px; }

/* The grid scrolls inside its own box on a desktop when there are many zones; the page itself never scrolls sideways. */
.lines-wrap { overflow: auto; max-height: min(74vh, 1100px); border-top: 1px solid var(--rule); margin: 0 -4px; }
.lines-wrap[aria-busy="true"] { opacity: .6; }
table.lines-grid { min-width: 100%; }
.lines-grid th { z-index: 2; }
.lines-grid td, .lines-grid th { padding: 6px 6px; }
.lines-grid .c-sel { width: 44px; min-width: 44px; max-width: 44px; padding: 0; }
/* A 44 px target around each small checkbox. */
.cb-hit { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 40px; cursor: pointer; }
.cb-hit input { width: 18px; height: 18px; accent-color: var(--fill-blue); margin: 0; cursor: pointer; }
.lines-grid .c-code { width: 64px; min-width: 64px; max-width: 64px; }
/* A wide name column keeps rows near MSE's 38-40 px instead of wrapping bilingual names over four lines. */
.lines-grid .c-name { min-width: 260px; max-width: none; white-space: normal; }
.lines-grid .c-unit { width: 44px; max-width: 64px; color: var(--text-2); padding-left: 12px; white-space: normal; overflow-wrap: anywhere; line-height: 1.25; }
.lines-grid thead th.c-unit, .lines-grid thead th.c-qty, .lines-grid thead th.c-rate { letter-spacing: .02em; }
.lines-grid thead th.c-unit { white-space: nowrap; overflow-wrap: normal; }
.lines-grid .c-qty { min-width: 68px; }
.lines-grid .c-rate { min-width: 96px; }
.lines-grid .c-cv { width: 132px; min-width: 132px; max-width: 132px; }
.lines-grid .c-amt { width: 120px; min-width: 120px; max-width: 120px; }
.u-ph { display: none; }
/* Freeze code and name on the left and the state and money on the right, so no column ever hides off the side. */
@media (min-width: 641px) {
  .lines-grid td.c-sel, .lines-grid th.c-sel { position: sticky; left: 0; z-index: 1; background: var(--card-solid); }
  .lines-grid tr.l-row td.c-code, .lines-grid thead th.c-code { position: sticky; left: 44px; z-index: 1; background: var(--card-solid); }
  .lines-grid tr.l-row td.c-name, .lines-grid thead th.c-name { position: sticky; left: 108px; z-index: 1; background: var(--card-solid); box-shadow: 1px 0 0 var(--rule); }
  .lines-grid td.c-amt, .lines-grid th.c-amt { position: sticky; right: 0; z-index: 1; background: var(--card-solid); box-shadow: -1px 0 0 var(--rule); }
  .lines-grid.money tr.l-row td.c-cv, .lines-grid.money thead th.c-cv { position: sticky; right: 120px; z-index: 1; background: var(--card-solid); box-shadow: -1px 0 0 var(--rule); }
  .lines-grid:not(.money) tr.l-row td.c-cv, .lines-grid:not(.money) thead th.c-cv { position: sticky; right: 0; z-index: 1; background: var(--card-solid); box-shadow: -1px 0 0 var(--rule); }
  .lines-grid thead th.c-sel, .lines-grid thead th.c-code, .lines-grid thead th.c-name, .lines-grid thead th.c-amt,
  .lines-grid.money thead th.c-cv, .lines-grid:not(.money) thead th.c-cv { z-index: 3; }
  .lines-grid tr.g-row td.c-gname .g-in { position: sticky; left: 50px; display: inline-flex; align-items: center; flex-wrap: wrap; gap: 0 2px; max-width: calc(100vw - 600px); }
  .lines-grid tr.g-row td.c-amt { background: var(--work-2); }
  .lines-grid tr.g-row.g-grp td.c-amt { background: var(--work); }
}

.l-open, .l-name { border: 0; background: none; padding: 0; color: inherit; cursor: pointer; text-align: left; font: inherit; }
.l-open { color: var(--blue-ink); font-size: 12px; min-height: 28px; }
.l-name { display: block; min-height: 28px; }
.l-name span { display: block; line-height: 1.35; }
.l-name small { display: block; color: var(--text-3); font-size: 12px; line-height: 1.3; }
.l-name:hover span, .l-open:hover { text-decoration: underline; }


.q-edit { border: 1px solid transparent; background: none; width: 100%; min-height: 32px; padding: 3px 6px; border-radius: 8px; cursor: text; color: inherit; font: inherit; text-align: right; }
.q-edit:hover { border-color: var(--card-edge); background: var(--field); }
.q-edit:focus-visible { border-color: var(--blue); }
.qv { display: grid; justify-items: end; gap: 1px; }
.working { display: block; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.q-in { width: 100%; min-width: 110px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--blue); background: var(--field); color: var(--text);
  font-family: "Geist Mono", ui-monospace, monospace; font-size: 13px; text-align: right; box-shadow: 0 0 0 4px oklch(from var(--blue) l c h / .18); outline: none; }

.l-row.cv-row-na td:not(.c-sel) { color: var(--text-3); }
.l-row.cv-row-na .l-name span { text-decoration: line-through; text-decoration-color: oklch(from var(--text-3) l c h / .5); }
@media (hover: hover) { .l-row:hover td { background: oklch(from var(--blue) l c h / .045); } }
.g-row td { background: var(--work); font-weight: 600; }
.g-row.g-art td { background: var(--work-2); border-top: 1px solid var(--rule); position: sticky; }
.g-row.g-grp td { font-weight: 550; color: var(--text-2); }
.c-gname { white-space: normal; }
.g-toggle { border: 0; background: none; color: var(--text-2); cursor: pointer; width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; vertical-align: middle; }
.g-toggle:hover { background: var(--glass-hi); }
.g-code { font-size: 12px; color: var(--text-3); margin: 0 8px 0 2px; }
.g-row.g-grp .g-code { margin-left: 30px; }
.g-open { margin-left: 10px; font-size: 11px; font-weight: 600; color: var(--brass-ink); background: oklch(from var(--brass) l c h / .14); padding: 2px 8px; border-radius: 999px; }
/* The totals row sits above every frozen cell, so no line shows through it. */
.lines-grid tfoot td { position: sticky; bottom: 0; z-index: 4; background: var(--card-solid); border-top: 1px solid var(--rule); font-weight: 600; }
.lines-grid tfoot td.c-foot b { position: sticky; left: 52px; }
.lines-grid tfoot td.c-amt { right: 0; z-index: 5; }
.g-n { margin-left: 10px; font-size: 12px; font-weight: 500; color: var(--text-3); }
.l-more { display: flex; align-items: center; gap: 12px; padding: 10px 4px 0; }
.l-more .cap { margin: 0; }
.l-top { gap: 10px; align-items: center; }
.l-top input[type=search] { flex: 1 1 260px; max-width: 360px; }
.l-top .views { flex: 3 1 420px; }
.lines-screen .filters-box > summary { display: inline-flex; align-items: center; gap: 8px; list-style: none; cursor: pointer; padding: 6px 4px; min-height: 36px; font-weight: 550; color: var(--text-2); font-size: var(--fs-sm); }
.lines-screen .filters-box > summary::-webkit-details-marker { display: none; }
.lines-screen .filters-box[open] > summary .chev { transform: rotate(180deg); }
.lines-screen .filters-box > .toolbar { padding: 6px 0 4px; }
/* Bulk bar controls look like every other field, and Apply sits at the right end. */
.bulk-bar select.input { max-width: 180px; padding: 7px 34px 7px 10px; }
.bulk-bar input.input { max-width: 200px; padding: 7px 10px; }
.bulk-bar .b-apply { margin-left: auto; }
/* The line drawer: capped at 860 px, money and state in its head, euro fields in mono. */
.drawer-panel.line-panel { width: min(860px, 100%); }
.l-head-sum { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.l-head-amt { font-family: "Geist Mono", ui-monospace, monospace; font-size: var(--fs-xl); font-weight: 650; letter-spacing: -.01em; }
.line-panel input[name=unit] { max-width: 140px; }
.euro-in { position: relative; display: block; }
.euro-in .eur { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); font-size: 13px; pointer-events: none; }
.line-panel input.num-in { font-family: "Geist Mono", ui-monospace, monospace; text-align: right; }
.euro-in input.num-in { padding-right: 30px; width: 100%; }
/* Overview */
.ov-eq .eq-op { align-self: center; color: var(--text-3); font-size: var(--fs-xl); font-weight: 300; }
.ov-eq .eq-term { min-width: 140px; }
.ov-eq .eq-term .v { font-family: "Inter", system-ui, sans-serif; }
.ov-eq .eq-term.result { --accent: var(--sea); }
.ov-final { margin-top: 8px; }
.ov-match { font-size: var(--fs-md); color: var(--text-2); margin-bottom: 10px; }
.ov-match b { color: var(--good-ink); font-weight: 650; }
.ov-note { margin-top: 8px; }
.ov-tiles.five > .span-cb5 { grid-column: span 12; }
@media (min-width: 961px) { .ov-tiles.five { grid-template-columns: repeat(5, minmax(0, 1fr)); } .ov-tiles.five > .span-cb5 { grid-column: auto; } }
/* Project sheet head: the ref pill sits at the right end, not mid-row. */
.proj-sheet .page-head .tags { margin-left: auto; align-items: flex-start; }
.proj-sheet .page-head .refbox { order: 2; }
.proj-sheet .page-head .actions { order: 1; }
.lr-imp { display: inline-flex; align-items: center; gap: 6px; color: var(--text-3); margin-left: 6px; }

/* The line drawer */
.line-drawer { padding: 0; gap: 22px; }
.l-sec { display: grid; gap: 10px; }
.l-sec > h3 { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--text-3); margin: 0; padding-bottom: 6px; border-bottom: 1px solid var(--rule); }
.l-sec .field { margin-bottom: 0; }
.form-grid.pair { grid-template-columns: 1fr 1fr; gap: 8px; }
.parts { display: grid; gap: 6px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--work); border: 1px solid var(--card-edge); }
.parts-head { display: flex; align-items: center; gap: 8px; }
.parts-head .q-sum { margin-left: auto; font-size: 13px; color: var(--text); }
.parts-rows { display: grid; gap: 6px; }
.part { display: grid; grid-template-columns: 110px minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr) 36px; gap: 6px; align-items: center; }
.part input { padding: 7px 9px; border-radius: 9px; border: 1px solid var(--card-edge); background: var(--field); color: var(--text); min-width: 0; font-size: 13px; }
.part input:first-child { font-family: "Geist Mono", ui-monospace, monospace; text-align: right; }
.part .icon-btn { width: 36px; height: 36px; }
.q-total { font-family: "Geist Mono", ui-monospace, monospace; font-weight: 600; text-align: right; }
.rate-memory h3 { margin-top: 6px; }
.comments { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.comments li { padding: 10px 12px; border-radius: 12px; border-left: 3px solid var(--human); background: oklch(from var(--human) l c h / .06); display: grid; gap: 4px; }
.comments li.answered { border-left-color: var(--good); background: oklch(from var(--good) l c h / .05); }
.comments time { font-size: 12px; color: var(--text-3); }
.c-body { white-space: pre-wrap; }
.c-answer { color: var(--text-2); }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: var(--fs-sm); max-height: 260px; overflow: auto; }
.history time { font-family: "Geist Mono", ui-monospace, monospace; font-size: 11px; color: var(--text-3); margin-right: 8px; }
.drawer-foot.sticky { position: sticky; bottom: -30px; margin: 20px -26px -30px; background: var(--card-solid); border-radius: 0 0 0 22px; }

/* Phone: each line becomes a block; quantities and money stay readable, nothing scrolls sideways. */
@media (max-width: 640px) {
  .lines-wrap { overflow-x: hidden; max-height: none; }
  table.lines-grid, .lines-grid tbody, .lines-grid tr, .lines-grid td { display: block; width: 100%; }
  .lines-grid thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .lines-grid tr.l-row { position: relative; padding: 8px 4px 10px 40px; border-bottom: 1px solid var(--rule); }
  .lines-grid tr.l-row td { border: 0; padding: 2px 0; display: grid; grid-template-columns: minmax(84px, 34%) minmax(0, 1fr); gap: 10px; align-items: center; text-align: left; min-width: 0; max-width: none; }
  .lines-grid tr.l-row td::before { content: attr(data-label); color: var(--text-3); font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
  .lines-grid tr.l-row td.c-sel { position: absolute; left: 6px; top: 10px; width: auto; display: block; }
  .lines-grid tr.l-row td.c-sel::before, .lines-grid tr.l-row td.c-name::before, .lines-grid tr.l-row td.c-code::before { content: none; }
  .lines-grid tr.l-row td.c-name, .lines-grid tr.l-row td.c-code { grid-template-columns: 1fr; width: 100%; min-width: 0; }
  /* On a phone a line is three short rows: code and amount, the name, then quantity and state. A tap opens the
     full-screen drawer for everything else. */
  .lines-grid tr.l-row { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; }
  .lines-grid tr.l-row td { display: block; width: auto; }
  .lines-grid tr.l-row td::before { content: none; }
  .lines-grid tr.l-row td.c-zm, .lines-grid tr.l-row td.c-unit, .lines-grid tr.l-row td.c-rate { display: none; }
  .lines-grid tr.l-row td.c-code { order: 1; width: auto; }
  .lines-grid tr.l-row td.c-amt { order: 2; margin-left: auto; width: auto; max-width: none; min-width: 0; text-align: right; }
  .lines-grid tr.l-row td.c-name { order: 3; width: 100%; }
  .lines-grid tr.l-row td.c-total, .lines-grid tr.l-row td.c-z:not(.c-zm) { order: 4; width: auto; min-width: 0; }
  .lines-grid tr.l-row td.c-total::before, .lines-grid tr.l-row td.c-z:not(.c-zm)::before { content: "Qty "; color: var(--text-3); font-size: 11px; font-weight: 600; letter-spacing: .04em; }
  .lines-grid tr.l-row td.c-cv { order: 5; width: auto; max-width: none; min-width: 0; margin-left: auto; }
  .lines-grid tr.l-row td.c-z:not(.c-zm) .q-edit { min-height: 36px; width: auto; }
  .lines-grid tr.l-row td { background: transparent !important; }
  .lines-grid tr.l-row td.c-empty { display: none; }
  .lines-grid tr.l-row { padding-top: 6px; padding-bottom: 8px; }
  .lr-imp { display: none; }
  .u-ph { display: inline; color: var(--text-3); }
  .lines-grid tr.l-row td.c-sel { top: 4px; left: -2px; }
  .lines-grid tfoot td.c-foot b { position: static; }
  .proj-sheet .page-head .refbox { justify-items: start; grid-auto-flow: column; align-items: center; }
  .proj-sheet .page-head .tags { margin-left: 0; }
  .l-top input[type=search] { max-width: none; }
  .lines-grid tr.l-row td.c-qty, .lines-grid tr.l-row td.c-rate, .lines-grid tr.l-row td.c-amt { min-width: 0; }
  .lines-grid .q-edit { min-height: 36px; padding: 4px 8px; border-color: var(--card-edge); background: var(--field); }
  .lines-grid tr.l-row td.num { font-family: inherit; }
  .lines-grid .q-edit, .lines-grid .qv { text-align: left; justify-items: start; min-height: var(--tap); }
  .lines-grid tr.g-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 8px 6px; background: var(--work-2); }
  .lines-grid tr.g-row td { display: inline-block; width: auto; border: 0; padding: 0; background: none; }
  .lines-grid tr.g-row td.c-sel { display: none; }
  .lines-grid tr.g-row.g-grp .g-code { margin-left: 0; }
  .lines-grid tfoot tr { display: flex; justify-content: space-between; padding: 10px 6px; }
  .lines-grid tfoot td { display: inline-block; width: auto; border: 0; position: static; }
  .lines-grid tfoot td:empty { display: none; }
  .part { grid-template-columns: 90px minmax(0, 1fr) 36px; }
  .part input:nth-child(3), .part input:nth-child(4) { grid-column: span 1; }
  .form-grid.pair { grid-template-columns: 1fr 1fr; }
  .bulk-bar { position: static; }
  .drawer-foot.sticky { margin: 20px -16px -30px; }
  .lines-screen .toolbar select.input { max-width: none; flex: 1 1 140px; }
}
@media (pointer: coarse) { .g-toggle { width: var(--tap); height: var(--tap); } .l-open { min-height: var(--tap); } }

/* Filters: open on a desktop, folded on a phone so the lines come first. */
.filters-box > summary { display: none; }
@media (max-width: 640px) {
  .filters-box { border: 1px solid var(--card-edge); border-radius: var(--r-md); background: var(--work); margin-bottom: 10px; }
  .filters-box > summary { display: flex; align-items: center; gap: 8px; list-style: none; cursor: pointer; padding: 10px 14px; min-height: var(--tap); font-weight: 550; color: var(--text-2); }
  .filters-box > summary::-webkit-details-marker { display: none; }
  .filters-box > summary .chev { margin-left: auto; }
  .filters-box[open] > summary .chev { transform: rotate(180deg); }
  .filters-box > .toolbar { padding: 0 10px 10px; margin: 0; }
}

.lines-grid thead th.c-qty { white-space: normal; max-width: 120px; line-height: 1.25; vertical-align: bottom; }
.g-sum { margin-left: 12px; font-size: 12px; color: var(--text); }
.comments li .pill { justify-self: start; }
