/* Oswald (SIL Open Font License) – bundled locally, no Internet needed */
@font-face { font-family: 'Oswald'; font-style: normal; font-weight: 500; font-display: swap; src: url(fonts/oswald-vietnamese-500-normal.woff2) format('woff2'); unicode-range: U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB; }
@font-face { font-family: 'Oswald'; font-style: normal; font-weight: 500; font-display: swap; src: url(fonts/oswald-latin-ext-500-normal.woff2) format('woff2'); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: 'Oswald'; font-style: normal; font-weight: 500; font-display: swap; src: url(fonts/oswald-latin-500-normal.woff2) format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'Oswald'; font-style: normal; font-weight: 600; font-display: swap; src: url(fonts/oswald-vietnamese-600-normal.woff2) format('woff2'); unicode-range: U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB; }
@font-face { font-family: 'Oswald'; font-style: normal; font-weight: 600; font-display: swap; src: url(fonts/oswald-latin-ext-600-normal.woff2) format('woff2'); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: 'Oswald'; font-style: normal; font-weight: 600; font-display: swap; src: url(fonts/oswald-latin-600-normal.woff2) format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'Oswald'; font-style: normal; font-weight: 700; font-display: swap; src: url(fonts/oswald-vietnamese-700-normal.woff2) format('woff2'); unicode-range: U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB; }
@font-face { font-family: 'Oswald'; font-style: normal; font-weight: 700; font-display: swap; src: url(fonts/oswald-latin-ext-700-normal.woff2) format('woff2'); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: 'Oswald'; font-style: normal; font-weight: 700; font-display: swap; src: url(fonts/oswald-latin-700-normal.woff2) format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }

:root {
  --bg: #f3f5f8; --card: #ffffff; --ink: #18212d; --muted: #66727f; --line: #e1e6ec;
  --navy: #00244a; --steel: #1d5a99; --accent: #c41d30; --gold: #cc992b; --ok: #2f8f5b; --warn: #b7791f; --err: #c0392b;
  --radius: 10px; --head: 'Oswald', 'Arial Narrow', 'Segoe UI', sans-serif; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; }
a { color: var(--steel); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 12px; }
/* Headings: Oswald, upper-case, bold */
h1, h2, h3 { font-family: var(--head); font-weight: 700; text-transform: uppercase; letter-spacing: .02em; color: var(--navy); }
h1 { font-size: 26px; margin: 0 0 4px; line-height: 1.15; }
h2 { font-size: 17px; margin: 0 0 12px; padding-left: 10px; border-left: 4px solid var(--accent); line-height: 1.2; }
h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

.topbar { display: flex; align-items: center; gap: 18px; padding: 8px 20px; background: #fff; color: var(--navy); position: sticky; top: 0; z-index: 10; border-bottom: 3px solid var(--accent); box-shadow: 0 2px 6px rgba(0,36,74,.08); }
.brand { display: flex; align-items: center; gap: 14px; color: var(--navy); }
.brand:hover { text-decoration: none; }
.brand img { height: 44px; width: auto; display: block; }
.brand span { display: flex; flex-direction: column; line-height: 1.15; padding-left: 14px; border-left: 1px solid var(--line); }
.brand b { font-family: var(--head); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; font-size: 17px; color: var(--navy); }
.brand small { color: var(--muted); font-size: 11px; }
.crumbs { flex: 1; display: flex; gap: 8px; align-items: center; color: var(--muted); overflow: hidden; white-space: nowrap; font-family: var(--head); font-weight: 500; letter-spacing: .02em; }
.crumbs a { color: var(--steel); }
.crumbs b { color: var(--navy); font-weight: 700; }
.lang { color: var(--navy); border: 1px solid var(--line); padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.lang:hover { border-color: var(--accent); text-decoration: none; }
@media (max-width: 760px) { .brand span { display: none; } .brand img { height: 36px; } }
.printhead { display: none; }

.wrap { max-width: 1480px; margin: 0 auto; padding: 18px 20px 40px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols > .card { margin-bottom: 16px; }
.cols.wide-left { grid-template-columns: 3fr 2fr; }
@media (max-width: 1000px) { .cols, .cols.wide-left { grid-template-columns: 1fr; } }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 600; }
.btn:hover { text-decoration: none; border-color: #c5ced8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #a3172a; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn.danger { color: var(--err); }
.btn:disabled { opacity: .6; cursor: wait; }

.upload form { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.drop { flex: 1 1 420px; display: flex; align-items: center; gap: 12px; border: 2px dashed #c3ccd7; border-radius: var(--radius); padding: 18px; cursor: pointer; background: #fafbfd; }
.drop.over { border-color: var(--accent); background: #fdf0f1; }
.drop input { display: none; }
.drop-icon { font-size: 22px; color: var(--accent); }
.drop-text { font-weight: 600; }
.drop-name { color: var(--muted); margin-left: auto; }
.progress[hidden] { display: none; }
.progress { flex-basis: 100%; display: flex; flex-direction: column; gap: 6px; color: var(--muted); }
.progress .bar { height: 8px; background: #e8edf3; border-radius: 4px; overflow: hidden; }
.progress .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.progress .bar i.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

.alert { padding: 10px 12px; border-radius: 8px; margin: 0 0 10px; border: 1px solid; }
.alert.err { background: #fdecea; border-color: #f5c2bd; color: #8a1f14; }
.alert.warn { background: #fff7e6; border-color: #f3d9a4; color: #7a4f0a; }
.alert.ok { background: #e9f7ef; border-color: #b9e2c9; color: #1e6b41; }

.modelhead { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.modelhead .mark { color: var(--accent); }
.btn { font-family: var(--head); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.exports { display: flex; gap: 8px; }
.tabs { display: flex; flex-wrap: wrap; gap: 2px 4px; border-bottom: 2px solid var(--line); margin-bottom: 16px; }
.tabs a { padding: 8px 12px; color: var(--muted); font-family: var(--head); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; font-size: 15px; border-bottom: 2px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs a.on { color: var(--navy); border-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs small { font-family: 'Segoe UI', system-ui, sans-serif; letter-spacing: 0; background: #e7ecf2; color: var(--muted); border-radius: 10px; padding: 1px 7px; font-size: 11px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat { border-top: 3px solid var(--gold); }
.stat b { display: block; font-family: var(--head); font-weight: 600; font-size: 24px; color: var(--navy); font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 12px; }

.tablehead { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.filter { flex: 1; max-width: 380px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.tablewrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: 8px; }
.tablewrap.short { max-height: 340px; }
table.grid { border-collapse: collapse; width: 100%; font-size: 13px; }
table.grid.narrow { width: auto; min-width: 420px; }
table.grid th, table.grid td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.grid thead th { position: sticky; top: 0; background: var(--navy); color: #fff; font-family: var(--head); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; font-size: 12.5px; z-index: 1; white-space: nowrap; }
table.grid tfoot th { font-family: var(--head); font-weight: 700; text-transform: uppercase; background: #f7f9fb; position: sticky; bottom: 0; border-top: 2px solid var(--line); }
table.grid tbody tr:hover { background: #f7fafd; }
table.grid tr.main td { background: #fdf4e6; }
table.grid tr.picked td { background: #fff1d6 !important; }
th.num, td.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
th.sorter { cursor: pointer; user-select: none; }
th.sorter:hover { background: #0b3a6b; }
th.sorter[data-dir="asc"]::after { content: " ▲"; font-size: 9px; }
th.sorter[data-dir="desc"]::after { content: " ▼"; font-size: 9px; }
td.actions .act { display: flex; gap: 6px; align-items: center; }
td.actions form { margin: 0; }
table.kv { border-collapse: collapse; width: 100%; font-size: 13px; }
table.kv th { text-align: left; color: var(--muted); font-weight: 500; padding: 5px 12px 5px 0; width: 40%; vertical-align: top; }
table.kv td { padding: 5px 0; border-bottom: 1px dashed var(--line); }

.tag { display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: 1px 6px; border-radius: 4px; background: #e7ecf2; color: #47566a; vertical-align: middle; }
.tag.main { background: #f7e7c4; color: #7a5410; }
.tag.auto { background: #efe6fb; color: #6a3fb0; }
.chip { display: inline-block; padding: 1px 8px; margin: 1px 2px 1px 0; border-radius: 12px; background: #eaf1f9; font-size: 12px; white-space: nowrap; }
.chip.ghost { background: #f1f1f1; color: var(--muted); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; background: #ccc; vertical-align: middle; }
.dim { display: inline-block; margin-right: 10px; white-space: nowrap; }
.dim i { color: var(--muted); font-style: normal; font-size: 12px; }

.viewer-card { padding: 10px; }
.vtools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.vtools button, .vtools select { font: inherit; font-size: 12px; padding: 4px 10px; border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer; }
.vtools button:hover { border-color: var(--steel); }
.vtools label { font-size: 12px; color: var(--muted); display: inline-flex; gap: 4px; align-items: center; margin: 0 4px; }
.viewer { position: relative; height: 480px; border-radius: 8px; overflow: hidden; background: radial-gradient(ellipse at top, #ffffff, #dfe5ec); }
.viewer.tall { height: 72vh; }
.viewer canvas { display: block; width: 100% !important; height: 100% !important; }
.vmsg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.pickinfo { min-height: 22px; padding: 6px 4px 0; font-size: 13px; color: var(--muted); }
.props details { margin-bottom: 8px; }
.props summary { cursor: pointer; font-family: var(--head); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--navy); padding: 4px 0; }

@media print {
  .topbar, .foot, .noprint, .vtools, .tabs, .exports, button { display: none !important; }
  .printhead { display: flex; align-items: center; justify-content: space-between; border-bottom: 2px solid var(--accent); padding-bottom: 8px; margin-bottom: 12px; }
  .printhead img { height: 40px; }
  .printhead span { font-family: var(--head); font-weight: 700; text-transform: uppercase; color: var(--navy); }
  table.grid thead th { background: #00244a !important; color: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .tablewrap { max-height: none; overflow: visible; }
  .viewer { height: 360px; }
}

/* ---- welds ---- */
.stat.weld { border-top-color: #e53935; }
.wbadge { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 12.5px; margin-right: 10px; }
.wbadge i, .wchip i, .wdot { display: inline-block; width: 14px; height: 5px; border-radius: 3px; vertical-align: middle; }
.wdot { margin-right: 5px; }
.wchip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-variant-numeric: tabular-nums; margin-right: 6px; }
.wlegend { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 8px 4px 0; min-height: 20px; }
.wtypes { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; margin-bottom: 16px; }
.wtype { background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--wc); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.wtype b { font-family: var(--head); font-weight: 700; font-size: 24px; color: var(--navy); }
.wtype .wname { font-family: var(--head); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; color: var(--navy); display: flex; align-items: center; gap: 8px; }
.wtype .wname i { width: 18px; height: 6px; border-radius: 3px; background: var(--wc); }
.wtype small { color: var(--muted); font-size: 12px; }

/* ---- sample models ---- */
.samples { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 10px; }
.sample { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 1px solid var(--line); border-left: 4px solid var(--gold); border-radius: 8px; padding: 10px 12px; margin: 0; }

/* ---- component groups ---- */
:root { --g-structural: #00244a; --g-purlin: #cc992b; --g-rod: #2e9d4f; --g-bolt: #6b7785; --g-concrete: #9e9e9e; --g-timber: #8d6e63; --g-other: #78909c; }
.gtag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 10px; white-space: nowrap; color: #fff; background: var(--g-structural); }
.gtag.g-purlin { background: var(--g-purlin); } .gtag.g-rod { background: var(--g-rod); } .gtag.g-concrete { background: var(--g-concrete); }
.gtag.g-timber { background: var(--g-timber); } .gtag.g-other { background: var(--g-other); } .gtag.g-bolt { background: var(--g-bolt); }
.gdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; background: var(--g-structural); }
.gdot.g-purlin { background: var(--g-purlin); } .gdot.g-rod { background: var(--g-rod); } .gdot.g-bolt { background: var(--g-bolt); }
.gdot.g-concrete { background: var(--g-concrete); } .gdot.g-timber { background: var(--g-timber); } .gdot.g-other { background: var(--g-other); }
.gfilter { display: flex; flex-wrap: wrap; gap: 6px; }
.gfilter button { font: inherit; font-size: 12px; border: 1px solid var(--line); background: #fff; border-radius: 16px; padding: 4px 11px; cursor: pointer; display: inline-flex; align-items: center; }
.gfilter button small { color: var(--muted); margin-left: 5px; }
.gfilter button.on { border-color: var(--navy); background: var(--navy); color: #fff; }
.gfilter button.on small { color: #c9d6e6; }
.tablehead { flex-wrap: wrap; }
.groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.grp { border: 1px solid var(--line); border-left: 5px solid var(--g-structural); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 3px; }
.grp.g-purlin { border-left-color: var(--g-purlin); } .grp.g-rod { border-left-color: var(--g-rod); } .grp.g-bolt { border-left-color: var(--g-bolt); }
.grp.g-concrete { border-left-color: var(--g-concrete); } .grp.g-timber { border-left-color: var(--g-timber); } .grp.g-other { border-left-color: var(--g-other); }
.grp b { font-family: var(--head); font-weight: 700; font-size: 22px; color: var(--navy); }
.grp .gname { font-family: var(--head); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; font-size: 13px; color: var(--navy); }
.grp small { color: var(--muted); font-size: 12px; }

.gsec { border-left: 5px solid var(--g-structural); }
.gsec.g-purlin { border-left-color: var(--g-purlin); } .gsec.g-rod { border-left-color: var(--g-rod); } .gsec.g-bolt { border-left-color: var(--g-bolt); }
.gsec.g-concrete { border-left-color: var(--g-concrete); } .gsec.g-timber { border-left-color: var(--g-timber); } .gsec.g-other { border-left-color: var(--g-other); }
.ghead { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.ghead h2 { margin: 0; border: 0; padding: 0; display: flex; align-items: center; }
.gstats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-bottom: 12px; }
.gstats div { background: #f6f8fa; border-radius: 8px; padding: 8px 10px; }
.gstats b { display: block; font-family: var(--head); font-weight: 600; font-size: 20px; color: var(--navy); }
.gstats span { font-size: 12px; color: var(--muted); }
.gvis { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0 0 8px; font-size: 12.5px; }
.gvis label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }

/* ---- documents / folder upload ---- */
.pkg-uploader { display: flex; flex-direction: column; gap: 10px; }
.pkg-drop { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pkg-picks { margin-left: auto; display: flex; gap: 8px; }
.pkg-picks label { cursor: pointer; }
.pkg-summary { font-size: 13px; }
.pkg-start { align-self: flex-start; }
.dkind { display: inline-block; min-width: 34px; text-align: center; font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px; color: #fff; background: #78909c; vertical-align: middle; }
.dkind.k-asm_dwg { background: #c41d30; } .dkind.k-part_dwg { background: #e8792b; } .dkind.k-ga_dwg { background: #00244a; }
.dkind.k-dwg { background: #5c6bc0; } .dkind.k-dxf { background: #2e9d4f; } .dkind.k-nc { background: #8e24aa; }
.dkind.k-report { background: #cc992b; } .dkind.k-model { background: #1e88e5; }
.doclist { list-style: none; margin: 0; padding: 0; }
.doclist li { padding: 5px 0; border-bottom: 1px dashed var(--line); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.doclist .dl { margin-left: auto; }
h3 { font-size: 14px; }

.vstatus { position: absolute; left: 12px; bottom: 12px; background: rgba(0,36,74,.88); color: #fff; padding: 6px 12px; border-radius: 6px; font-size: 12.5px; pointer-events: none; }
.dxfsvg { width: 100%; height: 72vh; background: #fff; color: #1b2430; border: 1px solid var(--line); border-radius: 8px; cursor: grab; }
pre.doctext { max-height: 72vh; overflow: auto; background: #f6f8fa; border: 1px solid var(--line); border-radius: 8px; padding: 12px; font-size: 12px; }
.docframe { width: 100%; height: 80vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.pkg-drop { flex: none; }

/* ---------------------------------------------------------------- project / cutting / requisition / containers */
.pform h3 { margin: 14px 0 6px; font-size: 14px; }
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px 12px; }
.fld { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.fld input:not([type=checkbox]):not([type=radio]), .fld select, .fld textarea, .pform input[type=text], .pform input[type=number], #sheetTbl input { font: 13px/1.3 inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); width: 100%; }
.fld textarea { resize: vertical; font-family: inherit; }
.fld .pair { display: flex; gap: 6px; }
.pform > textarea, .pform > .fld { margin-top: 8px; }
.checks { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::before { content: '▸ '; color: var(--accent); }
details.card[open] > summary::before { content: '▾ '; }
details.nestgrp { border-top: 1px solid var(--line); padding: 8px 0; }
details.nestgrp > summary { cursor: pointer; font-size: 14px; padding: 4px 0; }
.nestgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(460px, 1fr)); gap: 12px; margin-top: 8px; }
.nestcard { margin: 0; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: #fff; }
.nestcard figcaption { font-size: 12px; margin-bottom: 6px; }
svg.nest { width: 100%; height: auto; display: block; }
svg.bar { width: 100%; height: 22px; display: block; }
table.bars td { vertical-align: middle; }
td.remok { color: var(--ok); font-weight: 600; }
.yield { display: inline-block; padding: 1px 8px; border-radius: 10px; font-weight: 600; font-size: 12px; }
.yield.good { background: #e9f7ef; color: #1e6b41; }
.yield.mid { background: #fff7e6; color: #7a4f0a; }
.yield.low { background: #fdecea; color: #8a1f14; }
.contviews { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 10px 0; }
.contviews figure { margin: 0; }
.contviews figcaption { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
svg.cont { width: 100%; height: auto; display: block; }
.pack3d { position: relative; width: 100%; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-top: 8px; }
.pack-tip { position: absolute; display: none; pointer-events: none; background: rgba(0,36,74,.92); color: #fff; font-size: 12px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; }
@media (max-width: 900px) { .contviews { grid-template-columns: 1fr; } .nestgrid { grid-template-columns: 1fr; } }

/* ================================================================ mobile & touch
   Layout fixes for every width, then phone (≤ 760 px) and small phone (≤ 400 px). */
.cols > *, .contviews > *, .nestgrid > * { min-width: 0; }
.exports { flex-wrap: wrap; }
.btn { white-space: nowrap; }
img, svg, canvas { max-width: 100%; }
.tabs { scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }

@media (hover: none) {
  /* touch devices: larger targets, no hover-only affordances */
  .btn { min-height: 40px; }
  .btn.sm { min-height: 34px; padding: 6px 12px; }
  .vtools button, .vtools select { min-height: 34px; }
  table.grid tbody tr:hover { background: inherit; }
  table.grid tbody tr:active { background: #f1f6fc; }
}

@media (max-width: 760px) {
  html { -webkit-text-size-adjust: 100%; }
  body { font-size: 14px; }
  .wrap { padding: 12px 12px 24px; }
  /* the header scrolls away, the tab row sticks instead */
  .topbar { position: relative; padding: 8px 12px; gap: 10px; }
  .crumbs { font-size: 13px; }
  .lang { padding: 4px 10px !important; font-size: 12px; }
  h1 { font-size: 22px; line-height: 1.2; margin: 4px 0 6px; word-break: break-word; }
  h2 { font-size: 16px; }
  .card { padding: 12px; border-radius: 10px; margin-bottom: 12px; }
  .cols { gap: 0; }

  /* model header: one-line subtitle, export button full width */
  .modelhead { align-items: stretch; gap: 8px; margin-bottom: 8px; }
  .modelhead > div:first-child { min-width: 0; }
  .modelhead p.muted { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 12.5px; margin: 0; }
  .modelhead .exports { width: 100%; }
  .modelhead .exports .btn.primary { flex: 1; justify-content: center; }

  /* tabs: one swipeable row that stays on top */
  .tabs { flex-wrap: nowrap !important; overflow-x: auto; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity;
    position: sticky; top: 0; z-index: 20; background: var(--bg); margin: 0 -12px 12px; padding: 0 12px;
    mask-image: linear-gradient(90deg, #000 85%, transparent); -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); }
  .tabs a { padding: 10px 10px; font-size: 14px; scroll-snap-align: start; flex: 0 0 auto; }

  /* KPI tiles: compact 2 columns */
  .stats { grid-template-columns: 1fr 1fr !important; gap: 8px; margin-bottom: 12px; }
  .stat { padding: 8px 10px; }
  .stat b { font-size: 19px; }
  .stat span { font-size: 11.5px; line-height: 1.25; display: block; }
  .gstats { display: grid !important; grid-template-columns: 1fr 1fr; gap: 8px; }
  .groups { grid-template-columns: 1fr 1fr !important; }

  /* tables: swipe sideways, first column stays visible */
  .tablewrap { max-height: 65vh; margin: 0 -2px; -webkit-overflow-scrolling: touch; }
  table.grid { font-size: 12.5px; }
  table.grid th, table.grid td { padding: 6px 8px; }
  table.grid thead th { font-size: 11.5px; }
  .tablewrap table.grid td:first-child, .tablewrap table.grid th:first-child { position: sticky; left: 0; z-index: 1; background: #fff; box-shadow: 1px 0 0 var(--line); }
  .tablewrap table.grid thead th:first-child { z-index: 3; background: var(--navy); }
  .tablewrap table.grid tfoot th:first-child, .tablewrap table.grid tfoot td:first-child { background: #f7f9fb; }
  .tablewrap table.grid td { white-space: nowrap; }
  .tablewrap table.grid td.small, .tablewrap table.grid td.wrap { white-space: normal; min-width: 180px; }
  .tablewrap table.grid td:first-child { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
  table.grid.narrow { min-width: 0; width: 100%; }
  .card > table.grid:not(.narrow), section > table.grid { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.kv th { width: 42%; padding-right: 8px; }
  table.kv td { word-break: break-word; }

  /* filters & chips: full-width search, swipeable chips */
  .tablehead { flex-direction: column; align-items: stretch !important; gap: 8px; min-width: 0; max-width: 100%; }
  .tablehead > * { min-width: 0; max-width: 100%; }
  .tablehead > .btn, .tablehead > a.btn { align-self: flex-start; }
  .card, section { min-width: 0; }
  input.filter, input[type=search] { width: 100% !important; }
  .gfilter { flex-wrap: nowrap !important; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; scrollbar-width: none; }
  .gfilter::-webkit-scrollbar { display: none; }
  .gfilter button { flex: 0 0 auto; }

  /* forms: one column, 16 px inputs (no iOS zoom) */
  .fgrid { grid-template-columns: 1fr !important; }
  input, select, textarea { font-size: 16px !important; }
  .fld .pair { flex-direction: row; }
  #sheetTbl input { min-width: 70px; }
  .inline-form { flex-direction: column; align-items: stretch; }

  /* 3D: room to scroll past the canvas, swipeable toolbar */
  .viewer { height: 52vh; min-height: 280px; }
  .viewer.tall { height: 62vh; }
  .vtools { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; scrollbar-width: none; }
  .vtools::-webkit-scrollbar { display: none; }
  .vtools > * { flex: 0 0 auto; }
  .pickinfo { font-size: 13px; }

  /* cutting / packing */
  .nestgrid { grid-template-columns: 1fr !important; }
  .contviews { grid-template-columns: 1fr !important; }
  .ghead { flex-direction: column; align-items: flex-start !important; gap: 6px; }
  .pack3d { min-height: 300px; }
  table.bars td:nth-child(4) { min-width: 220px; }
  details.card > summary h2 { font-size: 15px; }

  /* upload */
  .pkg-picks { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
  .drop { padding: 18px 12px !important; }
  .samples { grid-template-columns: 1fr !important; }
  .foot { padding: 14px 12px; font-size: 12px; }
}
@media (max-width: 400px) {
  .stat b { font-size: 17px; }
  .brand img { height: 30px !important; }
  .tabs a { font-size: 13px; padding: 9px 8px; }
}
.scrapbox .gstats .okv { background: #e9f7ef; }
.scrapbox .gstats .okv b { color: #1e6b41; }
.scrapbox .gstats .badv { background: #fdecea; }
.scrapbox .gstats .badv b { color: #8a1f14; }

/* ===================================================================== on-canvas 3D controls */
.vtools.vtools-moved { display: none; }
.viewer.has-vui { height: 560px; }
.viewer.tall.has-vui { height: calc(100vh - 230px); min-height: 460px; }
.vui { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.vui > * { pointer-events: auto; }
.vui .vrule, .vui .vlabels { pointer-events: none; position: absolute; inset: 0; }
.vui-tr { position: absolute; top: 10px; right: 10px; display: flex; gap: 2px; align-items: center; padding: 4px; border-radius: 12px;
  background: rgba(255,255,255,.92); box-shadow: 0 4px 18px rgba(0,36,74,.16); border: 1px solid rgba(0,36,74,.08); backdrop-filter: blur(6px); flex-wrap: wrap; justify-content: flex-end; max-width: calc(100% - 40px); }
.vui-bc { position: absolute; bottom: 34px; left: 50%; transform: translateX(-50%); display: flex; gap: 2px; align-items: center; padding: 4px; border-radius: 14px;
  background: rgba(0,36,74,.88); box-shadow: 0 6px 22px rgba(0,18,40,.3); color: #fff; max-width: calc(100% - 40px); }
.vb { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 9px; background: transparent; color: var(--navy); cursor: pointer; padding: 0; touch-action: manipulation; }
.vb:hover { background: #eef2f6; }
.vb.on { background: var(--navy); color: #fff; }
.vui-bc .vb { color: #fff; }
.vui-bc .vb:hover { background: rgba(255,255,255,.14); }
.vui-bc .vb.on { background: var(--gold); color: #00244a; }
.vb.vmode { width: auto; padding: 0 10px; display: inline-flex; gap: 6px; font-size: 12px; font-weight: 600; }
.vsep { width: 1px; height: 22px; background: rgba(0,36,74,.14); margin: 0 3px; }
.vui-bc .vsep { background: rgba(255,255,255,.22); }
.vui-pop { position: absolute; top: calc(100% + 8px); right: 0; width: 260px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; box-shadow: 0 14px 40px rgba(0,36,74,.18); display: grid; gap: 8px; }
.vui-pop[hidden] { display: none; }
.vui-pop label { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--ink); margin: 0; }
.vui-pop select { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 8px; padding: 0 8px; font: inherit; font-size: 13px; }
.vlab { position: absolute; transform: translate(-50%, -50%); background: #1f5fbf; color: #fff; font-size: 11.5px; font-weight: 600; padding: 2px 7px; border-radius: 6px; white-space: nowrap; box-shadow: 0 2px 6px rgba(0,0,0,.2); }
.vlab.meas { background: var(--accent); }
.vhint { position: absolute; top: 12px; left: 34px; background: rgba(196,29,48,.95); color: #fff; padding: 6px 10px; border-radius: 8px; font-size: 12.5px; font-weight: 600; max-width: calc(100% - 80px); }
.viewer.measuring canvas { cursor: crosshair; }
.viewer .vmsg { z-index: 4; }
.viewer-card:fullscreen { background: #fff; padding: 10px; display: flex; flex-direction: column; }
.viewer-card:fullscreen .viewer { flex: 1; height: auto !important; }
.viewer-card.pseudo-full { position: fixed; inset: 0; z-index: 100; margin: 0; border-radius: 0; display: flex; flex-direction: column; }
.viewer-card.pseudo-full .viewer { flex: 1; height: auto !important; }
@media (max-width: 760px) {
  .viewer.has-vui, .viewer.tall.has-vui { height: 68vh; min-height: 360px; }
  .vui-tr { top: 6px; right: 6px; gap: 0; padding: 3px; flex-direction: column; flex-wrap: nowrap; max-width: none; }
  .vui-tr [data-v="shot"] { display: none; }
  .vui-pop { top: 0; right: calc(100% + 6px); width: min(250px, 70vw); }
  .vui-tr .vsep { display: none; }
  .vb { width: 34px; height: 34px; }
  .vui-bc { bottom: 28px; gap: 0; }
  .vb.vmode span { display: none; }
  .vb.vmode { width: 34px; padding: 0; }
  .vhint { left: 28px; top: auto; bottom: 80px; }
}
@media print { .vui { display: none; } }

/* project tab (v3.3) */
.pcol > .card { margin-bottom: 16px; }
.pinfo h3 { display: flex; align-items: center; gap: 8px; margin: 22px 0 10px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 15px; color: var(--navy); }
.pinfo h3:first-of-type { border-top: 0; padding-top: 0; margin-top: 6px; }
.pinfo h3 span { width: 24px; height: 24px; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; font-size: 12px; font-family: var(--head); }
.pinfo form[inert] input, .pinfo form[inert] select, .pinfo form[inert] textarea { background: #f6f8fa; }
.teamgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.teamc { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: #fbfcfd; }
.teamc h4 { margin: 0 0 8px; font-size: 13.5px; color: var(--navy); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.teamc .fld { display: block; } .teamc select { width: 100%; }
.fgrid.sm { grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.psave { position: sticky; bottom: 0; background: #fff; padding: 10px 0 2px; margin: 14px 0 0; border-top: 1px solid var(--line); z-index: 2; }
.pshg { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; align-items: start; }
.pshq svg { width: 130px; height: 130px; display: block; }
.pshl input { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; font: inherit; font-size: 12.5px; background: #f6f8fa; }
@media (max-width: 560px) { .fgrid.sm { grid-template-columns: 1fr; } .pshg { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- forms: shared layout (all admin / form pages)
 * .fgrid          grid of .fld fields; .fld.full (or .span-all) takes a whole row
 * .chkgrp         group of tick boxes / radios shown as wrapping chips: <div class="chkgrp"><label><input type=checkbox> text</label>…</div>
 * .chkgrp.compact smaller chips for table cells
 * .form-actions   row of buttons under a form (whole row of a .fgrid), primary button first
 * .chk            one tick box + text on one line
 */
/* a tick box / radio never takes the width of a text field (bug: 260 px wide boxes with the text below them) */
:is(.fld, .fgrid, .pform, .oform, .sd-form, .mb-grid, .permgrid, .phform, .pmrep, .lbf, .chkgrp, .chk) input:is([type=checkbox], [type=radio]) {
  width: auto; min-width: 0; height: auto; padding: 0; margin: 0; border: 0; flex: none; accent-color: var(--navy); }
.fgrid { align-items: start; }
.fld input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=file]), .fld select { min-height: 34px; }
.fld input[type=color] { height: 34px; padding: 3px; max-width: 120px; cursor: pointer; }
.fgrid > .full, .fgrid > .span-all, .fgrid > .form-actions, .oform > .full, .sd-form > .full { grid-column: 1 / -1; }
.fld > span:first-child { font-weight: 600; color: var(--muted); }
.chkgrp { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chkgrp > label, label.chip-chk { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; padding: 5px 11px 5px 9px; border: 1px solid var(--line);
  border-radius: 999px; background: #fff; color: var(--ink); font-size: 12.5px; line-height: 1.2; cursor: pointer; white-space: nowrap; user-select: none; transition: border-color .12s, background .12s; }
.chkgrp > label:hover { border-color: #b9c4d0; }
.chkgrp > label:has(input:checked) { background: #eaf1f9; border-color: #9db7d6; color: var(--navy); }
.chkgrp > label:has(input:disabled) { opacity: .75; cursor: default; }
.chkgrp.compact { gap: 4px; }
.chkgrp.compact > label { padding: 3px 9px 3px 7px; font-size: 12px; }
.chk { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 0 0; padding-top: 12px; border-top: 1px solid var(--line); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head > h2 { margin: 0; }
td.brk { overflow-wrap: anywhere; min-width: 120px; max-width: 200px; }
.fbar { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; margin: 14px 0 6px; padding-top: 14px; border-top: 1px solid var(--line); }
.fbar.top { margin: 0 0 12px; padding: 0; border: 0; }
.fbar > .fld.grow { flex: 1 1 260px; max-width: 480px; }
.fbar > .btn { min-height: 34px; }
/* bare inputs in small inline forms: same look as form fields (page rules with a class still win) */
:where(form.inl) :where(input:not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=file]):not([type=color]), select) {
  font: inherit; font-size: 13px; min-height: 30px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
.cellform { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; min-width: 260px; max-width: 360px; }
@media (max-width: 760px) {
  .form-actions > .btn { flex: 1 1 auto; justify-content: center; }
  .chkgrp > label { white-space: normal; }
  .cellform { min-width: 220px; }
  /* phone: page form grids go to one column, nothing wider than the screen */
  .na-grid, .tr-grid, .sd-form, .oform, .mb-grid { grid-template-columns: 1fr !important; }
  .tr-grid > *, .sd-form > *, .oform > * { grid-column: auto !important; }
  .tr-grid .tr-big { min-width: 0; }
  main select { max-width: 100%; }
  .mes-filters > label { max-width: 100%; min-width: 0; }
  .mes-filters select, .mes-filters input { min-width: 0; width: 100%; }
  .setrow { flex-wrap: wrap; }
  .setrow img { max-width: 100% !important; }
  .fbar > .fld, .fbar > .fld.grow { flex: 1 1 100%; max-width: none; }
  .fbar > .btn { flex: 1 1 auto; justify-content: center; }
}
