/* PCM lab app: clean admin look, system fonts, no external requests. */
:root {
  --bg: #f1f1f1;
  --surface: #ffffff;
  --surface-muted: #f7f7f7;
  --surface-hover: #f5f5f5;
  --nav-bg: #1a1a1a;
  --nav-text: #e3e3e3;
  --nav-muted: #a1a1a1;
  --nav-active: #303030;
  --text: #303030;
  --text-muted: #616161;
  --text-subtle: #8a8a8a;
  --border: #e3e3e3;
  --border-strong: #c9c9c9;
  --input-border: #8a8a8a;
  --primary: #303030;
  --primary-hover: #1a1a1a;
  --link: #005bd3;
  --focus: #005bd3;
  --success-bg: #cdfee1; --success-text: #0c5132; --success-dot: #29845a;
  --warning-bg: #ffef9d; --warning-text: #4f4700; --warning-dot: #b28400;
  --info-bg: #e0f0ff; --info-text: #00527c; --info-dot: #0094d5;
  --critical-bg: #fedad9; --critical-text: #8e0b21; --critical-dot: #e51c00;
  --neutral-bg: #e3e3e3; --neutral-text: #4a4a4a; --neutral-dot: #8a8a8a;
  --radius: 8px;
  --radius-lg: 12px;
  --card-shadow: 0 1px 0 0 rgba(26, 26, 26, .07), inset 0 -1px 0 0 rgba(0, 0, 0, .05), inset 0 0 0 1px rgba(0, 0, 0, .06);
  --btn-shadow: 0 1px 0 0 #e3e3e3 inset, 1px 0 0 0 #e3e3e3 inset, -1px 0 0 0 #e3e3e3 inset, 0 -1px 0 0 #b5b5b5 inset;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 13px/1.45 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; color: var(--text); }
h1 { font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 14px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 650; }
p { margin: 0 0 8px; }
.num, td.num, .tabular { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.danger-text { color: var(--critical-text); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* ---- Shell ---------------------------------------------------------------- */
.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.nav { background: var(--nav-bg); color: var(--nav-text); padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.nav-brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 14px; font-weight: 650; font-size: 14px; color: #fff; }
.nav-logo { width: 28px; height: 28px; border-radius: 8px; background: #fff; color: #1a1a1a; display: grid; place-items: center; font-size: 12px; font-weight: 750; letter-spacing: -.02em; flex: none; }
.nav a.nav-item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: var(--radius); color: var(--nav-text); font-weight: 550; text-decoration: none; }
.nav a.nav-item:hover { background: #2a2a2a; }
.nav a.nav-item.active { background: var(--nav-active); color: #fff; }
.nav-item svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; opacity: .9; }
.nav-count { margin-left: auto; background: #3d3d3d; color: #fff; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 10px; }
.nav-section { color: var(--nav-muted); font-size: 12px; font-weight: 550; padding: 14px 8px 4px; }
.nav-foot { margin-top: auto; border-top: 1px solid #2e2e2e; padding-top: 10px; display: flex; align-items: center; gap: 10px; padding-left: 8px; }
.avatar { width: 28px; height: 28px; border-radius: 8px; background: #36fba1; color: #0c5132; display: grid; place-items: center; font-size: 11px; font-weight: 700; flex: none; }
.nav-user { min-width: 0; flex: 1; }
.nav-user div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-user .role { color: var(--nav-muted); font-size: 12px; }
.nav-foot a { color: var(--nav-muted); font-size: 12px; }
.topbar { display: none; }

.main { padding: 20px 32px 64px; min-width: 0; }
.page { max-width: 1200px; margin: 0 auto; }
.page.narrow { max-width: 1000px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; min-height: 36px; }
.page-head .title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-head .sub { color: var(--text-muted); width: 100%; margin-top: -8px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.back { width: 32px; height: 32px; border-radius: var(--radius); display: grid; place-items: center; color: var(--text); background: transparent; }
.back:hover { background: rgba(0,0,0,.06); text-decoration: none; }
.back svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }

/* ---- Cards ---------------------------------------------------------------- */
.card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--card-shadow); margin-bottom: 16px; }
.card-body { padding: 16px; }
.card-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 0; }
.card-head .actions { margin-left: auto; display: flex; gap: 8px; }
.card-head + .card-body { padding-top: 12px; }
.card-section { padding: 14px 16px; border-top: 1px solid var(--border); }
.card-section:first-child { border-top: 0; }
.card.flush { overflow: hidden; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.stack > * + * { margin-top: 4px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; }
.aside-block + .aside-block { border-top: 1px solid var(--border); }
.aside-block { padding: 14px 16px; }
.aside-block h3 { margin-bottom: 8px; }
.empty { padding: 40px 16px; text-align: center; color: var(--text-muted); }
.empty h2 { margin-bottom: 4px; }

/* Metrics strip */
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric { padding: 12px 16px; border-left: 1px solid var(--border); }
.metric:first-child { border-left: 0; }
.metric .label { color: var(--text-muted); font-weight: 550; border-bottom: 1px dashed var(--border-strong); display: inline-block; }
.metric .value { font-size: 20px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.metric .value.alert { color: var(--critical-text); }

/* ---- Tables ------------------------------------------------------------- */
.toolbar { display: flex; align-items: center; gap: 8px; padding: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.tab { padding: 5px 10px; border-radius: var(--radius); color: var(--text-muted); font-weight: 550; }
.tab:hover { background: var(--surface-hover); text-decoration: none; color: var(--text); }
.tab.active { background: #e3e3e3; color: var(--text); }
.search { position: relative; flex: 1; min-width: 200px; }
.search svg { position: absolute; left: 9px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); stroke: var(--text-subtle); fill: none; stroke-width: 2; pointer-events: none; }
.search input[type=search] { padding-left: 32px; background: var(--surface); border-color: var(--border-strong); }
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th { text-align: left; font-weight: 550; color: var(--text-muted); background: var(--surface-muted); padding: 8px 12px; white-space: nowrap; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.table td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr[data-href] { cursor: pointer; }
.table tr[data-href]:hover td { background: var(--surface-hover); }
.table .strong, .table td a.strong { font-weight: 650; color: var(--text); }
.table .right, .right { text-align: right; }
.table td.nowrap, .nowrap { white-space: nowrap; }
.table .flags { color: var(--warning-text); font-size: 12px; margin-top: 2px; }
.table.compact td { padding: 6px 8px; }
.table.compact th { padding: 7px 8px; }
.table input, .table select { min-width: 0; }
.pager { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.pager span { color: var(--text-muted); }

/* ---- Badges --------------------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: var(--radius); font-size: 12px; font-weight: 550; white-space: nowrap; background: var(--neutral-bg); color: var(--neutral-text); line-height: 18px; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--neutral-dot); }
.badge.plain::before { display: none; }
.badge.success { background: var(--success-bg); color: var(--success-text); } .badge.success::before { background: var(--success-dot); }
.badge.warning { background: var(--warning-bg); color: var(--warning-text); } .badge.warning::before { background: transparent; border: 1.5px solid var(--warning-text); width: 5px; height: 5px; }
.badge.info { background: var(--info-bg); color: var(--info-text); } .badge.info::before { background: var(--info-dot); }
.badge.critical { background: var(--critical-bg); color: var(--critical-text); } .badge.critical::before { background: var(--critical-dot); }
.badge.large { font-size: 13px; padding: 3px 10px; }

/* ---- Buttons ------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: var(--radius); border: 0; background: var(--surface); color: var(--text); font: 600 13px/1 var(--font); box-shadow: var(--btn-shadow); cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: #fafafa; text-decoration: none; }
.btn:active { background: #f0f0f0; box-shadow: inset 0 1px 2px rgba(0,0,0,.12); }
.btn.primary { background: var(--primary); color: #fff; box-shadow: 0 -1px 0 1px rgba(0,0,0,.8) inset, 0 0 0 1px #303030 inset, 0 .5px 0 1.5px rgba(255,255,255,.25) inset; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { background: #c70a24; color: #fff; box-shadow: none; }
.btn.plain { background: transparent; box-shadow: none; color: var(--link); padding: 0 6px; }
.btn.plain:hover { text-decoration: underline; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }
.btn-row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ---- Forms ----------------------------------------------------------------- */
label { display: block; font-weight: 550; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input[type=tel],
input[type=datetime-local], input[type=date], input:not([type]), select, textarea {
  width: 100%; height: 32px; padding: 0 10px; border: 1px solid var(--input-border); border-radius: var(--radius);
  font: 13px var(--font); color: var(--text); background: #fdfdfd; transition: border-color .1s;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; }
select { padding-right: 28px; appearance: none; background: #fdfdfd url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23616161' stroke-width='2'%3E%3Cpath d='m5 6 3 3 3-3'/%3E%3C/svg%3E") no-repeat right 8px center; }
input:hover, select:hover, textarea:hover { border-color: #616161; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
input[type=number] { font-variant-numeric: tabular-nums; }
input[disabled], input[readonly] { background: var(--surface-muted); color: var(--text-muted); border-color: var(--border-strong); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; flex: none; }
input[type=file] { font: 13px var(--font); }
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field .help { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.field.check { display: flex; align-items: flex-start; gap: 8px; }
.field.check label { margin: 0; font-weight: 450; }
.errors, .errorlist { color: var(--critical-text); font-size: 12px; margin: 4px 0 0; padding: 0; list-style: none; }
.has-error input, .has-error select, .has-error textarea, td.has-error input { border-color: var(--critical-dot); background: #fff4f4; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 14px; }
.form-foot { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
.banner { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--radius-lg); margin-bottom: 16px; background: var(--info-bg); color: var(--info-text); }
.banner.critical { background: var(--critical-bg); color: var(--critical-text); }
.banner.warning { background: var(--warning-bg); color: var(--warning-text); }
.banner.success { background: var(--success-bg); color: var(--success-text); }
.banner ul { margin: 4px 0 0; padding-left: 18px; }
.dropzone { border: 1.5px dashed var(--border-strong); border-radius: var(--radius-lg); padding: 14px; text-align: center; color: var(--text-muted); background: var(--surface-muted); }
.dropzone.drag { border-color: var(--focus); background: var(--info-bg); }
.dropzone input { display: block; margin: 8px auto 0; max-width: 100%; }
.file-list { list-style: none; margin: 0; padding: 0; }
.file-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.file-list li:first-child { border-top: 0; }
.file-icon { width: 36px; height: 36px; border-radius: var(--radius); border: 1px solid var(--border); display: grid; place-items: center; color: var(--text-muted); font-size: 10px; font-weight: 700; flex: none; background: var(--surface-muted); overflow: hidden; }
.file-icon img { width: 100%; height: 100%; object-fit: cover; }
.file-list .meta { min-width: 0; flex: 1; }
.file-list .meta a { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-weight: 550; }

/* Sample entry grid */
.sample-grid td { padding: 6px 3px; }
.sample-grid td:first-child { padding-left: 10px; color: var(--text-subtle); width: 28px; }
.sample-grid td:last-child { padding-right: 8px; width: 34px; }
.sample-grid tr.deleted { display: none; }
.sample-grid .col-id { width: 15%; } .sample-grid .col-type { width: 13%; } .sample-grid .col-num { width: 10%; }
.icon-btn { width: 28px; height: 28px; border-radius: var(--radius); border: 0; background: transparent; color: var(--text-muted); cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-hover); color: var(--critical-text); }
.icon-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }
.grid-foot { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-top: 1px solid var(--border); color: var(--text-muted); flex-wrap: wrap; }

/* Results entry */
.result-cell { font-weight: 650; white-space: nowrap; }
.result-cell .flags { font-weight: 450; white-space: normal; max-width: 200px; margin-left: auto; line-height: 1.3; }
@media (max-width: 1280px) { .hide-md { display: none; } }
.row-blank td { background: #fafafa; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline li { position: relative; padding: 0 0 14px 22px; }
.timeline li::before { content: ""; position: absolute; left: 1px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--border-strong); }
.timeline li:first-child::before { border-color: var(--text); }
.timeline .when { color: var(--text-muted); font-size: 12px; }

/* Messages */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #1a1a1a; color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 550; box-shadow: 0 8px 20px rgba(0,0,0,.2); animation: toast 4s forwards; }
.toast.error { background: #8e0b21; }
@keyframes toast { 0% { opacity: 0; transform: translateY(8px); } 6%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* ---- Auth pages ----------------------------------------------------------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 16px; box-shadow: var(--card-shadow); padding: 28px; }
.auth-card.wide { max-width: 520px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; font-weight: 650; font-size: 15px; }
.auth-brand .nav-logo { background: #1a1a1a; color: #fff; }
.auth-card h1 { font-size: 18px; margin-bottom: 6px; }
.auth-card p { color: var(--text-muted); }
.auth-card form p, .auth-card .field { margin: 0 0 14px; }
.auth-card button[type=submit], .auth-card .btn.full { width: 100%; height: 36px; margin-top: 4px; }
.auth-card .qr { display: block; margin: 8px auto 16px; width: 180px; height: 180px; }
.auth-card .alt { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 12px; text-align: center; }
.auth-card .panel { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 14px; }
.auth-card ul.actions { list-style: none; padding: 0; margin: 10px 0 0; display: flex; gap: 8px; flex-wrap: wrap; }
.auth-card code, .codes { font-family: var(--mono); }
.auth-card .helptext { display: block; color: var(--text-muted); font-size: 12px; margin-top: 4px; font-weight: 400; }
.auth-card .btn-group { display: flex; flex-direction: column; gap: 8px; }

/* ---- Responsive ------------------------------------------------------------ */
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
  .main { padding: 16px 16px 48px; }
}
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .15s ease; }
  .nav.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .topbar { display: flex; align-items: center; gap: 10px; background: var(--nav-bg); color: #fff; padding: 8px 12px; position: sticky; top: 0; z-index: 30; font-weight: 650; }
  .topbar button { background: transparent; border: 0; color: #fff; width: 32px; height: 32px; display: grid; place-items: center; cursor: pointer; }
  .topbar svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(3) { border-left: 0; }
  .metric:nth-child(n+3) { border-top: 1px solid var(--border); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
.manage-card { margin: 8px auto; }
.manage-card form + form, .manage-card .panel + .panel { margin-top: 14px; }
.card.flush > .card-head { padding-bottom: 12px; }
.w-count { width: 110px; }
.form-top { gap: 0 16px; align-items: start; }
.sample-grid input, .sample-grid select { padding: 0 6px; height: 30px; }
.sample-grid select { padding-right: 22px; background-position: right 4px center; min-width: 90px; }
.sample-grid input[type=number] { min-width: 56px; }
.sample-grid input[data-time] { min-width: 62px; }
.sample-grid input[type=date] { min-width: 112px; }
.sample-grid input[name$=client_sample_id] { min-width: 80px; }
.sample-grid input[name$=location] { min-width: 124px; }
.sample-grid input[name$=pump_no] { min-width: 44px; }
.sample-grid th { font-size: 12px; white-space: normal; line-height: 1.2; padding: 6px 3px; }
.table th.center { text-align: center; }
.toolbar select, .toolbar input[type=date] { width: auto; flex: none; }
.toolbar select { max-width: 220px; }
.inline-form { display: flex; gap: 8px; }
.inline-form select { flex: 1; }
.right-link { float: right; font-weight: 450; font-size: 12px; }
.w-check { width: 36px; }
.muted-row td { color: var(--text-subtle); }
