:root {
  --ink: #1d2733;
  --ink-2: #4a5866;
  --ink-3: #7b8794;
  --line: #dde3ea;
  --bg: #f3f5f7;
  --card: #ffffff;
  --accent: #1f5f99;
  --accent-ink: #ffffff;
  --ok: #1f7a55;
  --warn: #b7791f;
  --err: #b42318;
  --raw: #8a4b2a;      /* rust: raw steel */
  --black: #2b2f33;    /* fabricated, ungalvanized */
  --galv: #c27c0e;     /* at galvanizer */
  --white: #9fb3c8;    /* galvanized zinc */
  --aux: #6b4fa0;
  --seg-erected: #1f7a55;
  --seg-full: #2f7fc1;
  --seg-stub: #e0a43a;
  --seg-pending: #e3e8ee;
  --r: 12px;
  --tap: 46px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.45rem; margin: 6px 0 14px; letter-spacing: -0.01em; }
h2 { font-size: 1.08rem; margin: 20px 0 10px; }
h3 { font-size: 0.95rem; margin: 14px 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--ink-3); }
.small { font-size: 0.85rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* ---- shell ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--ink); color: #fff; padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.brand { color: #fff; font-weight: 700; display: flex; align-items: center; gap: 8px; letter-spacing: .01em; }
.brand svg { width: 22px; height: 22px; fill: #fff; color: #fff; }
.who { font-size: .85rem; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; padding: 2px 6px; border-radius: 6px; margin-left: 4px; background: rgba(255,255,255,.15); }
.card .role, .tbl .role { background: var(--bg); color: var(--ink-2); }
.page { max-width: 760px; margin: 0 auto; padding: 14px 16px 24px; }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-around; background: #fff;
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--ink-3); font-size: .72rem; font-weight: 600; padding: 4px 0; max-width: 110px;
}
.bottomnav svg { width: 24px; height: 24px; fill: currentColor; stroke: currentColor; stroke-width: 0; }
.bottomnav a:nth-child(4) svg { fill: none; stroke-width: 2; }
.bottomnav a.on { color: var(--ink); }
.bottomnav a.add svg { background: var(--accent); fill: #fff; border-radius: 50%; width: 30px; height: 30px; padding: 3px; margin-top: -4px; }

/* ---- blocks ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 14px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (min-width: 560px) { .grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; } }
.flash { padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: .95rem; }
.flash-ok { background: #e6f4ed; color: #155b3f; }
.flash-error { background: #fdecea; color: #8a1c13; }
.flash-warn { background: #fff4e0; color: #7a4f0e; }
.empty { text-align: center; color: var(--ink-3); padding: 18px 10px; }

/* ---- tiles (home) ---- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile {
  display: block; background: #fff; border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px; color: var(--ink); position: relative; overflow: hidden; min-height: 92px;
}
.tile::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--c, var(--accent)); }
.tile .t-label { font-size: .8rem; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.tile .t-value { font-size: 1.6rem; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 4px; }
.tile .t-sub { font-size: .8rem; color: var(--ink-3); }
.c-raw { --c: var(--raw); } .c-black { --c: var(--black); } .c-galv { --c: var(--galv); }
.c-white { --c: var(--white); } .c-aux { --c: var(--aux); } .c-site { --c: var(--seg-full); }

.ready { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.ready .r { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.ready .r b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.ready .r .nm { font-weight: 650; font-size: .9rem; }
.ready .r .lim { font-size: .75rem; color: var(--ink-3); }

/* ---- progress bar ---- */
.bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--seg-pending); margin: 6px 0; }
.bar span { display: block; height: 100%; }
.bar .s-erected { background: var(--seg-erected); }
.bar .s-full { background: var(--seg-full); }
.bar .s-stub { background: var(--seg-stub); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: .8rem; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.legend .l-erected { background: var(--seg-erected); } .legend .l-full { background: var(--seg-full); }
.legend .l-stub { background: var(--seg-stub); } .legend .l-pending { background: var(--seg-pending); border: 1px solid #c9d1da; }
.site-row { display: block; color: var(--ink); padding: 10px 0; border-bottom: 1px solid var(--line); }
.site-row:last-child { border-bottom: 0; }
.site-row .top { display: flex; justify-content: space-between; gap: 10px; font-weight: 650; }

/* ---- tables ---- */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -14px; padding: 0 14px; }
.tbl { width: 100%; border-collapse: collapse; font-size: .93rem; }
.tbl th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 650; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl th.num, .tbl td.num { text-align: right; }
.tbl .grp td { background: var(--bg); font-weight: 650; font-size: .82rem; color: var(--ink-2); }
.tbl a.rowlink { color: var(--ink); font-weight: 600; }
.zero { color: #b8c1cb; }
.neg { color: var(--err); font-weight: 700; }

/* ---- tabs / chips ---- */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; padding: 8px 14px; border-radius: 999px; background: #fff; border: 1px solid var(--line); color: var(--ink-2); font-weight: 600; font-size: .9rem; }
.tabs a.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.badge { display: inline-block; font-size: .72rem; font-weight: 650; padding: 2px 7px; border-radius: 6px; background: var(--bg); color: var(--ink-2); white-space: nowrap; }
.badge-warn { background: #fff4e0; color: #7a4f0e; }
.badge-err { background: #fdecea; color: #8a1c13; }
.badge-ok { background: #e6f4ed; color: #155b3f; }
.badge-void { background: #eceff3; color: #6b7684; text-decoration: line-through; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; background: var(--c); }

/* ---- forms ---- */
label { display: block; font-weight: 600; font-size: .9rem; color: var(--ink-2); }
label > input, label > select, label > textarea { margin-top: 5px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff;
  border: 1px solid #c9d1da; border-radius: 10px; padding: 10px 12px; min-height: var(--tap);
}
input[type=checkbox] { width: 22px; min-height: 22px; height: 22px; vertical-align: middle; margin: 0 8px 0 0; }
label.check { display: flex; align-items: center; font-weight: 600; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
textarea { min-height: 70px; }
input[type=number] { font-variant-numeric: tabular-nums; }
.hint { font-size: .8rem; color: var(--ink-3); font-weight: 400; margin-top: 4px; }
.hint.warn { color: var(--warn); font-weight: 600; }
.line.trow { grid-template-columns: 1.5fr 1fr 60px 28px; gap: 6px; }
.line select { padding: 8px 4px 8px 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 650; min-height: var(--tap); padding: 0 18px; border-radius: 10px;
  border: 1px solid #c9d1da; background: #fff; color: var(--ink); cursor: pointer;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-danger { color: var(--err); border-color: #f0b8b2; }
.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: .88rem; }
.btn-link { background: none; border: 0; color: var(--accent); padding: 0; min-height: 0; font-weight: 600; cursor: pointer; font: inherit; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.sticky-submit { position: sticky; bottom: calc(70px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); padding: 14px 0 4px; }

/* dynamic line rows */
.lines { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.line { display: grid; grid-template-columns: 1fr 96px 40px; gap: 8px; align-items: center; padding: 8px; border-bottom: 1px solid var(--line); }
.line.w3 { grid-template-columns: 1fr 84px 96px 40px; }
.line:last-child { border-bottom: 0; }
.line input, .line select { min-height: 42px; padding: 8px 10px; }
.line .x { border: 0; background: none; color: var(--ink-3); font-size: 1.4rem; cursor: pointer; min-height: 42px; }
.line .meta { grid-column: 1 / -1; font-size: .78rem; color: var(--ink-3); margin-top: -4px; }
.line .meta.short { color: var(--err); font-weight: 650; }
.line-head { display: grid; grid-template-columns: 1fr 96px 40px; gap: 8px; padding: 6px 8px; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 650; background: var(--bg); }
.line-head.w3 { grid-template-columns: 1fr 84px 96px 40px; }
.qtygrid { display: grid; grid-template-columns: 1fr 110px; gap: 6px 10px; align-items: center; }
.qtygrid .nm { font-weight: 650; }
.qtygrid .sub { font-size: .78rem; color: var(--ink-3); font-weight: 400; display: block; }

/* entry menu */
.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.menu a { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 14px 12px; color: var(--ink); display: flex; flex-direction: column; gap: 4px; min-height: 96px; position: relative; overflow: hidden; }
.menu a::before { content: ""; position: absolute; left: 0; top: 0; right: 0; height: 4px; background: var(--c, var(--accent)); }
.menu a b { font-size: 1rem; }
.menu a span { font-size: .8rem; color: var(--ink-3); }
.list-links a { display: flex; justify-content: space-between; align-items: center; padding: 14px 4px; border-bottom: 1px solid var(--line); color: var(--ink); font-weight: 600; }
.list-links a:last-child { border-bottom: 0; }
.list-links a::after { content: "›"; color: var(--ink-3); font-size: 1.3rem; }

/* log */
.logitem { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); color: var(--ink); }
.logitem:last-child { border-bottom: 0; }
.logitem .l1 { display: flex; justify-content: space-between; gap: 8px; font-weight: 650; }
.logitem .l2 { font-size: .84rem; color: var(--ink-3); }
.logitem.void { opacity: .55; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; font-size: .93rem; }
dl.kv dt { color: var(--ink-3); }
dl.kv dd { margin: 0; font-weight: 600; }

/* login */
.login-body { padding-bottom: 0; }
.login { max-width: 360px; margin: 9vh auto 0; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 26px 22px; }
.login h1 { margin: 6px 0 2px; }
.login-mark { width: 38px; height: 38px; fill: var(--ink); color: var(--ink); }

/* print: challan */
.challan { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 20px; }
.challan h1 { font-size: 1.2rem; margin: 0; }
.challan .meta { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; margin: 14px 0; font-size: .92rem; }
.challan .sign { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-top: 48px; font-size: .8rem; color: var(--ink-2); }
.challan .sign div { border-top: 1px solid var(--ink-3); padding-top: 4px; text-align: center; }
@media print {
  body { background: #fff; padding: 0; }
  .topbar, .bottomnav, .noprint, .flash { display: none !important; }
  .page { max-width: none; padding: 0; }
  .challan { border: 0; padding: 0; }
}

/* activity log: person filter and change details */
.person-filter { margin-bottom: 10px; }
.person-filter label { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: .9rem; }
.person-filter select { flex: 1; max-width: 340px; }
.logitem.audit details { margin-top: 4px; }
.logitem.audit summary { cursor: pointer; color: var(--ink-2); }
.audit-details { margin: 6px 0 0; padding-left: 18px; font-size: .84rem; color: var(--ink-2); }
.audit-details li { margin: 2px 0; overflow-wrap: anywhere; }
