:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1d2733;
  --muted: #627080;
  --line: #dde3ea;
  --accent: #1f3a5f;
  --accent-2: #2f6fb3;
  --ok-bg: #e3f5ea; --ok: #1b7a3e;
  --bad-bg: #fde7e7; --bad: #b3261e;
  --head: #eef2f7;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 70px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 "Segoe UI", Arial, sans-serif; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 10px; color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
.right { text-align: right; }

/* The app runs inside the site layout (Bootstrap 5 / Tailwind): restore what their resets change */
.bc-app { font: 14px/1.5 "Segoe UI", Arial, sans-serif; color: var(--ink); }
.bc-app h1, .bc-app h2 { font-weight: 700; line-height: 1.25; }
.bc-app h1 { font-size: 22px; }
.bc-app h2 { font-size: 17px; }
.bc-app ul.list { list-style: disc; padding-left: 20px; }
.bc-app table { border-collapse: collapse; }
.bc-app p { margin: 0 0 10px; }
.bc-app .card { display: block; }
.bc-app .badge { white-space: nowrap; }
.bc-app .btn { line-height: 1.4; font-size: 14px; }
.bc-app .btn-sm { font-size: 12.5px; }
.bc-app summary { display: flex; }
.bc-app svg { display: inline-block; }
.bc-app .figure svg, .bc-app .sheet svg, .bc-app .preview-box svg, .bc-app .preview-svg { display: block; }

/* app sub-bar under the site navbar */
.appbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 14px; padding: 8px 24px;
  background: #fff; border-bottom: 1px solid var(--line); box-shadow: 0 1px 3px rgba(0,0,0,.05); }
.brand { display: flex; align-items: center; gap: 9px; color: var(--accent); font-weight: 700; font-size: 16px; }
.brand:hover { text-decoration: none; }
.tag { font-size: 12px; color: var(--muted); }
.appbar nav { margin-left: auto; display: flex; gap: 14px; align-items: center; }
.appbar nav > a:not(.btn) { color: var(--accent); font-weight: 600; }

.container { max-width: 1100px; margin: 22px auto; padding: 0 16px; }
.container.wide { max-width: 1500px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 10px; align-items: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.empty { text-align: center; padding: 40px; }

.btn { display: inline-block; padding: 7px 14px; border-radius: 7px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f0f3f7; text-decoration: none; }
.btn-primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #255d98; }
.btn-light { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.35); color: #fff !important; }
.btn-light:hover { background: rgba(255,255,255,.25); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-danger { color: var(--bad); }
.block { display: block; width: 100%; text-align: center; margin-top: 12px; }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.actions form { margin: 0; }

.msg { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.msg-error { background: var(--bad-bg); color: var(--bad); }
.msg-success { background: var(--ok-bg); color: var(--ok); }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.tbl thead th { background: var(--head); font-weight: 600; font-size: 12.5px; }
.tbl.kv th { width: 30%; background: #f8fafc; font-weight: 600; }
.tbl-wrap { overflow-x: auto; margin-bottom: 12px; }
.tbl.data td { white-space: nowrap; }
.tbl.data td:nth-child(3) { white-space: normal; }
.st-ok { background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.st-bad { background: var(--bad-bg); color: var(--bad); font-weight: 600; }
.caption { font-weight: 600; margin: 14px 0 6px; color: #33414f; }

/* form */
.input-layout { display: grid; grid-template-columns: 200px 1fr 300px; gap: 16px; align-items: start; }
.side-nav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 70px; }
.side-nav a { padding: 6px 10px; border-radius: 6px; color: var(--ink); font-size: 13.5px; }
.side-nav a:hover { background: #e7edf4; text-decoration: none; }
.side-nav .nav-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 10px 10px 4px; }
.side-nav a.dl { color: var(--accent-2); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field label { font-size: 12.5px; font-weight: 600; color: #33414f; }
.field input, .field select { padding: 7px 9px; border: 1px solid #c9d2dc; border-radius: 6px; font: inherit; background: #fff; }
.field input:focus, .field select:focus { outline: 2px solid #b9d3f0; border-color: var(--accent-2); }
.field.check label { display: flex; gap: 8px; align-items: center; font-weight: 500; padding-top: 22px; }
.field.check input { width: 16px; height: 16px; }
.field small { font-size: 11.5px; }
.field .err { color: var(--bad); }
.field.has-error input, .field.has-error select { border-color: var(--bad); }
.dropcheck { position: relative; }
.dropcheck summary { list-style: none; cursor: pointer; padding: 7px 30px 7px 9px; border: 1px solid #c9d2dc; border-radius: 6px;
  background: #fff; position: relative; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dropcheck summary::-webkit-details-marker { display: none; }
.dropcheck summary::after { content: "▾"; position: absolute; right: 10px; top: 6px; color: var(--muted); }
.dropcheck[open] summary { border-color: var(--accent-2); outline: 2px solid #b9d3f0; }
.dropcheck.empty summary { color: var(--bad); border-color: var(--bad); }
.dc-menu { position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0; background: #fff; border: 1px solid #c9d2dc;
  border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,.12); padding: 6px; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
.dc-item { display: flex; align-items: center; gap: 7px; padding: 5px 8px; border-radius: 5px; font-weight: 500 !important; cursor: pointer; }
.dc-item:hover { background: #eef3f9; }
.dc-item input { width: 15px; height: 15px; }
.dc-actions { grid-column: 1 / -1; display: flex; gap: 6px; justify-content: flex-end; border-top: 1px solid var(--line);
  padding-top: 6px; margin-top: 4px; }
.preview { position: sticky; top: 70px; }
.preview-svg { width: 100%; background: #fafbfc; border: 1px solid var(--line); border-radius: 8px; }
.pv-conc { fill: #cfd4da; stroke: #333; stroke-width: 1; }
.pv-cell { fill: #fff; stroke: #333; stroke-width: 1; }
.pv-soil { fill: #efe3c8; }
.derived { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; margin: 12px 0 0; font-size: 13px; }
.derived dt { color: var(--muted); }
.derived dd { margin: 0; font-weight: 600; }

/* report */
.report-layout { display: grid; grid-template-columns: 240px 1fr; gap: 18px; align-items: start; }
.report { min-width: 0; }
.rsection > p { margin: 6px 0 10px; }
.list { margin: 0; padding-left: 20px; }
.list li { margin-bottom: 5px; }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-weight: 500; }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-warn { background: var(--bad-bg); color: var(--bad); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.badge.big { padding: 6px 14px; font-size: 13px; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.calc { border: 1px solid var(--line); border-radius: 8px; margin: 8px 0; }
.calc summary { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 12px;
  cursor: pointer; background: #f8fafc; border-radius: 8px; font-weight: 600; font-size: 13.5px; }
.calc[open] summary { border-bottom: 1px solid var(--line); border-radius: 8px 8px 0 0; }
.calc .tbl { margin: 0; }
.calcsheet { width: 100%; border-collapse: collapse; font-size: 12.8px; }
.calcsheet th { background: var(--head); text-align: left; padding: 6px 8px; font-size: 12px; border-bottom: 1px solid var(--line); }
.calcsheet td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.calcsheet .c-ref { width: 120px; color: #5b6b7c; font-size: 11.8px; border-right: 2px solid #c9d6e3; }
.calcsheet .c-desc { width: 200px; font-weight: 600; color: #33414f; }
.calcsheet .c-calc { font-family: "Cambria Math", Cambria, "Times New Roman", serif; font-size: 13.5px; }
.calcsheet .c-res { width: 150px; text-align: right; font-weight: 700; white-space: nowrap; }
.calcsheet .c-st { width: 70px; text-align: center; }
.calcsheet tr.row-bad td { background: #fff3f3; }
.calc-bad summary { background: #fff6f6; }
.figure { display: block; margin: 12px 0; text-align: center; }
.figure svg { width: 100%; max-width: 760px; height: auto; border: 1px solid var(--line); border-radius: 8px; }
.figure figcaption { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.sheet { margin: 14px 0 22px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.sheet svg { width: 100%; height: auto; border: 1px solid #c9d2dc; box-shadow: 0 2px 8px rgba(0,0,0,.06); background: #fff; }

/* rebar detailing */
.rebar-layout { display: grid; grid-template-columns: minmax(0, 1fr) 560px; gap: 16px; align-items: start; }
.preview-card { position: sticky; top: 70px; }
.preview-box svg { width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab { border: 1px solid var(--line); background: #fff; padding: 5px 12px; border-radius: 99px; cursor: pointer; font: inherit; font-size: 13px; }
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.rebar-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.rebar-stats div { background: #f6f8fb; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; }
.rebar-stats span { font-size: 11.5px; }
.rebar-stats strong { font-size: 15px; }
.rebar-tbl td { vertical-align: middle; }
.rebar-tbl .num { text-align: right; }
.rebar-tbl tr.grp td { background: #eef2f7; font-weight: 700; color: var(--accent); font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
.rebar-tbl tr.rrow { cursor: pointer; }
.rebar-tbl tr.rrow:hover td { background: #f7f9fc; }
.rebar-tbl tr.rrow.custom td { background: #fffbea; }
.rebar-tbl tr.rrow.bad td.mark { color: var(--bad); }
.rebar-tbl .mark { font-weight: 800; font-size: 14px; }
.rebar-tbl select, .rebar-tbl input { padding: 4px 6px; border: 1px solid #c9d2dc; border-radius: 6px; font: inherit; width: 78px; }
.rebar-tbl input.invalid { border-color: var(--bad); background: #fff3f3; }
.ubar { width: 90px; height: 8px; background: #e6ebf1; border-radius: 99px; overflow: hidden; }
.ubar span { display: block; height: 100%; background: #2f9e5b; }
.ubar span.high { background: #d9a400; }
.ubar span.over { background: var(--bad); }
.badge-user { background: #fff1c2; color: #8a6100; }
.detail-info { margin: 4px 0 8px; }
.rebar-tbl tr.drow td { background: #fbfcfe; padding: 8px 12px 14px; }

@media (max-width: 1100px) {
  .rebar-layout { grid-template-columns: 1fr; }
  .preview-card { position: static; }
  .input-layout { grid-template-columns: 1fr; }
  .input-layout .side-nav, .preview { position: static; }
  .input-layout .side-nav { flex-direction: row; flex-wrap: wrap; }
  .report-layout { grid-template-columns: 1fr; }
  .report-layout .side-nav { position: static; }
}
