:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #17212b;
  --muted: #5c6b78;
  --line: #dde3e9;
  --brand: #0f3d5e;
  --brand-2: #1d6fa5;
  --ok: #17803d;
  --ok-bg: #e6f4ea;
  --bad: #c62828;
  --bad-bg: #fdecea;
  --warn: #9a6200;
  --warn-bg: #fff4dc;
  --info-bg: #e8f1f9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 15px; line-height: 1.45; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px;
  background: var(--brand); color: #fff; padding: 0 16px; height: 54px;
}
.brand { color: #fff; font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.logo { background: #fff; color: var(--brand); border-radius: 6px; width: 24px; height: 24px; display: grid; place-items: center; font-size: 15px; }
#nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
#nav a { color: #cfe0ee; padding: 8px 11px; border-radius: 7px; white-space: nowrap; font-size: 14px; }
#nav a.active, #nav a:hover { background: rgba(255,255,255,.13); color: #fff; text-decoration: none; }
.user { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #cfe0ee; white-space: nowrap; }
.user button { background: transparent; border: 1px solid rgba(255,255,255,.35); color: #fff; padding: 4px 10px; }

main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 80px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* cards & layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* KPI tiles */
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 2px; }
.kpi.alert .value { color: var(--bad); }

/* category cards */
.cat-card { display: flex; flex-direction: column; gap: 6px; }
.cat-card .name { font-weight: 650; font-size: 16px; }
.cat-card .stats { display: flex; gap: 12px; font-size: 13px; color: var(--muted); }
.cat-card.disabled { opacity: .6; }

/* forms */
input.auto { background: #f1f5f9; border-style: dashed; color: var(--ink); }
input.auto.lot { font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .02em; color: var(--brand); }
.qty { display: flex; align-items: center; gap: 8px; }
.qty span { white-space: nowrap; }
[data-vphint] { min-height: 0; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.f .req { color: var(--bad); }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid #c5ced7; border-radius: 8px;
  padding: 8px 10px; min-height: 40px; width: 100%;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc7ea; border-color: var(--brand-2); }
input:disabled, select:disabled, textarea:disabled { background: #f1f3f5; color: #555; }
button, .btn {
  font: inherit; font-weight: 550; border-radius: 8px; border: 1px solid #c5ced7; background: #fff; color: var(--ink);
  padding: 8px 14px; min-height: 38px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover, .btn:hover { background: #f3f6f9; text-decoration: none; }
button.primary, .btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
button.primary:hover, .btn.primary:hover { background: #185d8b; }
button.danger { color: var(--bad); border-color: #f0b6b6; }
button.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
button.ok.solid { background: var(--ok); color: #fff; border-color: var(--ok); }
button.ghost { border-color: transparent; background: transparent; }
button.sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.b-in_progress { background: var(--info-bg); color: var(--brand-2); }
.b-submitted { background: #efe7fb; color: #6a3fb5; }
.b-accepted { background: var(--ok-bg); color: var(--ok); }
.b-accepted_deviation { background: var(--warn-bg); color: var(--warn); }
.b-rejected { background: var(--bad-bg); color: var(--bad); }
.b-on_hold { background: #eceff1; color: #455a64; }
.b-flag { background: var(--bad-bg); color: var(--bad); }

.st { display: inline-block; min-width: 64px; text-align: center; padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; }
.st-OK { background: var(--ok-bg); color: var(--ok); }
.st-LOW, .st-HIGH, .st-OUT, .st-NOT_OK { background: var(--bad); color: #fff; }
.st-NO_SPEC { background: var(--warn-bg); color: var(--warn); }
.st-PENDING { background: #eef1f4; color: #8795a1; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--line); padding: 8px; white-space: nowrap; }
td { border-bottom: 1px solid #edf0f3; padding: 8px; vertical-align: top; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f7fafc; }
td.num, th.num { text-align: right; }

/* filters */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters > * { width: auto; min-width: 140px; }

/* inspection page */
.insp-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.insp-head .meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.progress { height: 6px; background: #e8edf1; border-radius: 99px; overflow: hidden; width: 160px; }
.progress > div { height: 100%; background: var(--ok); }
.steps { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0 4px; }
.step { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 8px; background: #fff; border: 1px solid var(--line); font-size: 13px; color: var(--ink); }
.step:hover { text-decoration: none; border-color: var(--brand-2); }
.step .dot { width: 9px; height: 9px; border-radius: 50%; background: #c5ced7; }
.step.done .dot { background: var(--ok); }
.step.partial .dot { background: #e3a008; }
.step.flag .dot { background: var(--bad); }

.section { scroll-margin-top: 70px; }
.section > .card-head h2 { display: flex; align-items: center; gap: 8px; }
.run { border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-top: 12px; background: #fcfdfe; }
.run-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.run-head .title { font-weight: 650; }
.subhead { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; margin: 16px 0 8px; }

/* parameter rows */
.params { border-top: 1px solid var(--line); }
.prow { display: grid; grid-template-columns: minmax(150px, 1.3fr) minmax(130px, 1fr) minmax(220px, 1.6fr) 80px minmax(120px, 1fr); gap: 10px; align-items: start; padding: 10px 4px; border-bottom: 1px solid #edf0f3; }
.prow.head { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 6px 4px; }
.prow.flagged { background: #fff6f6; }
.prow .pname { font-weight: 600; }
.prow .pspec { font-size: 13px; color: var(--muted); }
.prow .pspec.nospec { color: var(--warn); }
.vals { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.vals input { width: 92px; min-height: 38px; text-align: right; }
.vals input.bad { border-color: var(--bad); background: #fff4f4; color: var(--bad); font-weight: 600; }
.okbtns { display: inline-flex; border: 1px solid #c5ced7; border-radius: 8px; overflow: hidden; }
.okbtns button { border: 0; border-radius: 0; min-height: 36px; padding: 6px 12px; }
.okbtns button + button { border-left: 1px solid #c5ced7; }
.okbtns button.on-ok { background: var(--ok); color: #fff; }
.okbtns button.on-bad { background: var(--bad); color: #fff; }
.obs-text { margin-top: 6px; }
.stat-line { font-size: 12px; color: var(--muted); margin-top: 4px; }
.saving { opacity: .55; }

/* shot / cavity chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chip { min-height: 32px; padding: 4px 10px; font-size: 13px; border-radius: 999px; gap: 6px; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: #c5ced7; }
.chip.done .dot { background: var(--ok); }
.chip.partial .dot { background: #e3a008; }
.chip.flag .dot { background: var(--bad); }
.chip.on { border-color: var(--brand-2); background: var(--info-bg); box-shadow: 0 0 0 1px var(--brand-2) inset; }
.chip b.bad { color: var(--bad); }
.sample-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 12px 0 4px; flex-wrap: wrap; }

/* attachments */
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.slot { border: 1px dashed #b8c4cf; border-radius: 10px; padding: 10px; background: #fff; }
.slot .slot-title { font-weight: 600; font-size: 13px; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.file { position: relative; width: 84px; font-size: 11px; color: var(--muted); }
.file .thumb { width: 84px; height: 64px; border-radius: 6px; border: 1px solid var(--line); background: #eef2f5 center/cover no-repeat; display: grid; place-items: center; font-size: 22px; color: var(--muted); overflow: hidden; }
.file .thumb img { width: 100%; height: 100%; object-fit: cover; }
.file .fname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.file .x { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; min-height: 0; padding: 0; border-radius: 50%; justify-content: center; font-size: 13px; background: #fff; }
.upload-btn { position: relative; overflow: hidden; }
.upload-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* sign-offs */
.signs { display: flex; flex-wrap: wrap; gap: 8px; }
.sign { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 190px; background: #fff; font-size: 13px; }
.sign .role { color: var(--muted); font-size: 12px; }
.sign.done { border-color: #b7dfc3; background: var(--ok-bg); }
.sign .who { font-weight: 650; }

.callout { border-radius: 8px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.callout.bad { background: var(--bad-bg); color: #8e1b1b; }
.callout.warn { background: var(--warn-bg); color: #6f4700; }
.callout.info { background: var(--info-bg); color: #164f78; }
.callout.ok { background: var(--ok-bg); color: #0f5a2a; }
.callout ul { margin: 6px 0 0 18px; padding: 0; }

.log { font-size: 13px; max-height: 320px; overflow: auto; }
.log div { padding: 5px 0; border-bottom: 1px solid #eef1f4; }

/* login */
.login { max-width: 360px; margin: 10vh auto; }
.login .brandline { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.login .logo { background: var(--brand); color: #fff; width: 34px; height: 34px; font-size: 20px; border-radius: 8px; }

/* admin spec editor */
.spec-table input, .spec-table select { min-height: 34px; padding: 5px 7px; font-size: 14px; }
.spec-table td { padding: 5px 4px; vertical-align: middle; }
.spec-table input.n { width: 82px; text-align: right; }
.spec-table tr.inactive td { opacity: .5; }
.spec-table tr.dirty td { background: #fffbe8; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; color: var(--muted); }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand-2); }

/* toast & modal */
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: #17212b; color: #fff; padding: 10px 16px; border-radius: 9px; z-index: 100; max-width: min(92vw, 560px); white-space: pre-line; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.err { background: var(--bad); }
dialog { border: 0; border-radius: 12px; padding: 0; width: min(94vw, 520px); box-shadow: 0 20px 50px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(15, 25, 35, .45); }
#modal-body { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
#modal-body .actions { display: flex; gap: 8px; justify-content: flex-end; }

.empty { text-align: center; padding: 30px; color: var(--muted); }

@media (max-width: 860px) {
  .prow.head { display: none; }
  .prow { grid-template-columns: 1fr auto; gap: 6px 10px; padding: 12px 2px; }
  .prow .c-name { grid-column: 1; }
  .prow .c-status { grid-column: 2; grid-row: 1; justify-self: end; }
  .prow .c-spec, .prow .c-obs, .prow .c-rem { grid-column: 1 / -1; }
  .user .uname { display: none; }
  .topbar { gap: 10px; }
  .brand .txt { display: none; }
  h1 { font-size: 19px; }
}

@media print {
  .topbar, button, .upload-btn, .filters, .no-print, .file .x { display: none !important; }
  body { background: #fff; font-size: 12px; }
  main { padding: 0; max-width: none; }
  .card, .run { box-shadow: none; break-inside: avoid; border-color: #bbb; }
  input, select, textarea { border: 0; padding: 0; min-height: 0; background: transparent; }
}
