/* Technical Visit — minimal, tablet-friendly UI. No external dependencies (works offline on the VPN). */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --accent: #111827;
  --accent-ink: #ffffff;
  --brand: #f5b301;
  --ok: #15803d;
  --ok-bg: #ecfdf3;
  --warn: #b45309;
  --warn-bg: #fff7e6;
  --err: #b91c1c;
  --err-bg: #fef2f2;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
a { color: inherit; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.inline { display: inline; }
.pre { white-space: pre-line; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: .6rem 1.25rem; position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 6px;
  background: var(--ink); color: var(--brand); font-size: .75rem; font-weight: 800; letter-spacing: .02em;
}
.nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.nav a { text-decoration: none; padding: .4rem .7rem; border-radius: 6px; color: var(--muted); }
.nav a:hover { background: var(--bg); color: var(--ink); }
.nav a.active { background: var(--bg); color: var(--ink); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 1rem; }
.lang-switch { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.lang-switch button { border: 0; background: none; padding: .3rem .6rem; cursor: pointer; font: inherit; font-size: .8rem; color: var(--muted); }
.lang-switch button.on { background: var(--ink); color: #fff; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; font-size: .85rem; }
.link-btn:hover { color: var(--ink); text-decoration: underline; }

/* Layout */
.container { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.container.wide { max-width: 1400px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.breadcrumb { font-size: .85rem; color: var(--muted); margin-bottom: .35rem; }
.breadcrumb a { color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.card.flush { padding: 0; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.split { display: grid; grid-template-columns: 260px 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 900px) {
  .grid-2, .grid-3, .split { grid-template-columns: 1fr; }
  .topbar { gap: .75rem; }
  .topbar-right { margin-left: 0; }
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 550; font-size: .9rem; line-height: 1;
  padding: .65rem 1rem; min-height: 40px; border-radius: 6px; cursor: pointer; text-decoration: none;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { opacity: .9; }
.btn.danger { color: var(--err); border-color: #f3c2c2; }
.btn.danger:hover { border-color: var(--err); }
.btn.ghost { border-color: transparent; background: none; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: var(--bg); }
.btn.sm { padding: .4rem .65rem; min-height: 32px; font-size: .8rem; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* Forms */
label { font-size: .85rem; font-weight: 550; display: block; margin-bottom: .3rem; }
.input, select.input, textarea.input {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 6px; padding: .55rem .7rem; min-height: 40px;
}
textarea.input { resize: vertical; min-height: 64px; }
.input:focus { outline: 2px solid var(--ink); outline-offset: -1px; border-color: var(--ink); }
.input[disabled] { background: var(--bg); color: var(--muted); }
.field { margin-bottom: .9rem; }
.field .help { font-size: .78rem; color: var(--muted); margin-top: .25rem; }
.field .errors { color: var(--err); font-size: .8rem; margin-top: .25rem; }
.checkbox { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.checkbox input { width: 18px; height: 18px; }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; margin-top: .5rem; }
.lang-pair { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
@media (max-width: 700px) { .lang-pair { grid-template-columns: 1fr; } }
.lang-tag { display: inline-block; font-size: .65rem; font-weight: 700; padding: .05rem .3rem; border-radius: 3px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); margin-left: .3rem; vertical-align: 1px; }

/* Messages & badges */
.messages { margin-bottom: 1rem; display: grid; gap: .5rem; }
.msg { padding: .65rem .9rem; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); }
.msg-success { background: var(--ok-bg); border-color: #bbe5c8; color: var(--ok); }
.msg-error { background: var(--err-bg); border-color: #f3c2c2; color: var(--err); }
.msg-info, .msg-warning { background: var(--warn-bg); border-color: #f5d9a6; color: var(--warn); }
.badge { display: inline-block; font-size: .72rem; font-weight: 650; padding: .15rem .5rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.draft { background: var(--warn-bg); color: var(--warn); border-color: #f5d9a6; }
.badge.published, .badge.closed { background: var(--ok-bg); color: var(--ok); border-color: #bbe5c8; }
.badge.req { background: var(--err-bg); color: var(--err); border-color: #f3c2c2; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafafa; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #fafbfc; }
.table-wrap { overflow-x: auto; }
.empty { padding: 2rem; text-align: center; color: var(--muted); }

/* Progress */
.progress { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--ok); }

/* Chapter tabs (visit + editor) */
.tabs { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 72px; }
.tabs a, .tabs .tab {
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  padding: .55rem .7rem; border-radius: 6px; text-decoration: none; color: var(--muted); font-size: .88rem;
}
.tabs a:hover { background: var(--surface); color: var(--ink); }
.tabs a.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: inset 3px 0 0 var(--ink); }
.tabs .count { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.tabs .count.done { color: var(--ok); font-weight: 650; }
@media (max-width: 900px) {
  .tabs { flex-direction: row; overflow-x: auto; position: static; padding-bottom: .25rem; }
  .tabs a { white-space: nowrap; }
}

/* Chapter header photo */
.chapter-photo { max-width: 100%; max-height: 360px; border-radius: 6px; border: 1px solid var(--line); display: block; background: #fff; cursor: zoom-in; }
.thumb { width: 64px; height: 48px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); cursor: zoom-in; background: #fff; }

/* Question lines (visit) */
.q { display: grid; grid-template-columns: 2.2rem 1fr minmax(260px, 38%); gap: .75rem 1rem; padding: .9rem 1.25rem; border-bottom: 1px solid var(--line); align-items: start; }
.q:last-child { border-bottom: 0; }
.q-num { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; padding-top: .45rem; }
.q-label { padding-top: .35rem; }
.q-label .ref { font-size: .8rem; color: var(--muted); }
.q-label .help { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.q-answer { display: grid; gap: .45rem; }
.q-answer .comment { font-size: .88rem; min-height: 38px; }
.q.filled .q-num { color: var(--ok); font-weight: 700; }
@media (max-width: 800px) {
  .q { grid-template-columns: 2rem 1fr; }
  .q-answer { grid-column: 1 / -1; }
}

/* Segmented Yes / No / NA */
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { margin: 0; padding: .55rem 1.1rem; min-width: 64px; text-align: center; cursor: pointer; font-weight: 550; border-right: 1px solid var(--line-strong); user-select: none; }
.seg label:last-of-type { border-right: 0; }
.seg input:checked + label { background: var(--ink); color: #fff; }
.seg input:focus-visible + label { outline: 2px solid var(--brand); outline-offset: -2px; }
.seg input[disabled] + label { cursor: default; }
.seg.sm label { padding: .4rem .6rem; min-width: 44px; font-size: .85rem; }
.checks { display: grid; gap: .3rem; }
.checks label { font-weight: 450; display: flex; gap: .45rem; align-items: center; margin: 0; }
.checks input { width: 18px; height: 18px; }

/* Parts table (visit) */
.parts th, .parts td { padding: .5rem .6rem; }
.parts td .input { min-height: 36px; padding: .4rem .5rem; }
.parts .col-num { width: 2.5rem; color: var(--muted); }
.parts .col-ref { width: 12rem; font-size: .85rem; color: var(--muted); }
.parts .col-freq { width: 11rem; }
.parts .col-qty { width: 6rem; }
.parts .col-wear { width: 8rem; }
.parts tr.filled .col-num { color: var(--ok); font-weight: 700; }

/* Sticky save bar */
.savebar {
  position: sticky; bottom: 0; z-index: 10; background: rgba(245, 246, 248, .96); backdrop-filter: blur(4px);
  border-top: 1px solid var(--line); padding: .75rem 0; margin-top: 1rem;
  display: flex; gap: .5rem; align-items: center; flex-wrap: wrap;
}
.savebar .status { font-size: .82rem; color: var(--muted); margin-right: auto; }
.savebar .status.saving { color: var(--warn); }
.savebar .status.saved { color: var(--ok); }
.savebar .status.error { color: var(--err); }

/* Editor */
.drag-list { list-style: none; margin: 0; padding: 0; }
.drag-item { display: flex; align-items: center; gap: .75rem; padding: .65rem 1rem; border-bottom: 1px solid var(--line); background: var(--surface); }
.drag-item:last-child { border-bottom: 0; }
.drag-item.dragging { opacity: .5; }
.drag-item.over { box-shadow: inset 0 2px 0 var(--ink); }
.handle { cursor: grab; color: var(--muted); user-select: none; font-size: 1.1rem; line-height: 1; padding: .2rem; }
.drag-item .grow { flex: 1; min-width: 0; }
.line-item { display: block; padding: 0; }
.line-item > summary { list-style: none; display: flex; align-items: center; gap: .75rem; padding: .65rem 1rem; cursor: pointer; }
.line-item > summary::-webkit-details-marker { display: none; }
.line-item > summary:hover { background: #fafbfc; }
.line-item[open] > summary { background: #fafbfc; border-bottom: 1px solid var(--line); }
.line-item .body { padding: 1rem 1.25rem; }
.line-title { font-weight: 550; }
.line-sub { font-size: .8rem; color: var(--muted); }
.type-pill { font-size: .72rem; padding: .15rem .45rem; border-radius: 4px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.readonly-note { background: var(--warn-bg); border: 1px solid #f5d9a6; color: var(--warn); border-radius: 6px; padding: .65rem .9rem; margin-bottom: 1rem; }

/* Stat tiles */
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; }
.stat .n { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: .8rem; color: var(--muted); }

/* Lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(17, 24, 39, .85); display: none; place-items: center; z-index: 100; cursor: zoom-out; padding: 2rem; }
.lightbox.on { display: grid; }
.lightbox img { max-width: 100%; max-height: 100%; background: #fff; border-radius: 6px; }

/* Login */
.login-wrap { min-height: calc(100vh - 60px); display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; }

.grid-editor { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: start; }
.grid-code { grid-template-columns: 110px 1fr 1fr; }
@media (max-width: 900px) { .grid-editor, .grid-code { grid-template-columns: 1fr; } }
.card input[type=password], .card input[type=email] { width: 100%; font: inherit; border: 1px solid var(--line-strong); border-radius: 6px; padding: .55rem .7rem; min-height: 40px; }
.parts td:nth-child(2) { min-width: 200px; }
.parts td:last-child input, .parts td:nth-last-child(2) input[name$="__comment"] { min-width: 160px; }
.parts .col-wear .seg label { min-width: 40px; }
a.line-title { text-decoration: none; } a.line-title:hover { text-decoration: underline; }

/* Photos of findings */
.photos { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-start; }
.photo { position: relative; margin: 0; width: 120px; }
.photo img { width: 120px; height: 90px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; background: #fff; cursor: zoom-in; }
.photo .photo-caption { width: 100%; font: inherit; font-size: .75rem; border: 1px solid var(--line); border-radius: 4px; padding: .25rem .35rem; margin-top: .25rem; background: var(--surface); }
.photo figcaption { font-size: .75rem; color: var(--muted); margin-top: .2rem; }
.photo .photo-del { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(17, 24, 39, .75); color: #fff; cursor: pointer; line-height: 1; font-size: 1rem; }
.photo.uploading { height: 90px; display: grid; place-items: center; border: 1px dashed var(--line-strong); border-radius: 6px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.photo-add { display: inline-flex; align-items: center; gap: .35rem; margin: 0; font-weight: 550; font-size: .8rem; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: 6px; padding: .45rem .7rem; min-height: 36px; cursor: pointer; background: var(--surface); }
.photo-add:hover { color: var(--ink); border-color: var(--ink); }
.photo-add input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.parts .col-photo { min-width: 110px; }
.parts .col-photo .photo, .parts .col-photo .photo img { width: 80px; }
.parts .col-photo .photo img { height: 60px; }

.demo-badge { font-size: .7rem; font-weight: 800; letter-spacing: .08em; padding: .2rem .5rem; border-radius: 4px; background: var(--brand); color: var(--ink); }
.demo-accounts { margin-top: 1.25rem; padding: .75rem .9rem; border: 1px dashed var(--line-strong); border-radius: 6px; font-size: .85rem; display: grid; gap: .2rem; }
.demo-accounts code { background: var(--bg); padding: 0 .3rem; border-radius: 3px; }

.split > * { min-width: 0; }
.m-label { display: none; }
/* Tablet / phone: each spare-part row becomes a compact card */
@media (max-width: 1000px) {
  .parts thead { display: none; }
  .parts, .parts tbody { display: block; }
  .parts tr { display: grid; grid-template-columns: 2rem 1fr 1fr 1fr; gap: .45rem .6rem; padding: .8rem 1rem; border-bottom: 1px solid var(--line); align-items: center; }
  .parts td { display: block; border: 0; padding: 0; min-width: 0 !important; width: auto !important; }
  .parts td:nth-child(1) { grid-column: 1; grid-row: 1; }
  .parts td:nth-child(2) { grid-column: 2 / 4; grid-row: 1; font-weight: 550; }
  .parts td:nth-child(3) { grid-column: 4; grid-row: 1; text-align: right; }
  .parts td:nth-child(4) { grid-column: 2; grid-row: 2; }
  .parts td:nth-child(5) { grid-column: 3; grid-row: 2; }
  .parts td:nth-child(6) { grid-column: 4; grid-row: 2; display: flex; align-items: center; gap: .4rem; justify-content: flex-end; }
  .parts td:nth-child(7) { grid-column: 2 / 5; grid-row: 3; }
  .parts td:nth-child(8) { grid-column: 2 / 5; grid-row: 4; }
  .parts td:nth-child(9) { grid-column: 1; grid-row: 2; }
  .parts td .input { width: 100%; }
  .parts td:last-child input { min-width: 0; }
  .m-label { display: inline; font-size: .75rem; color: var(--muted); }
  .q-answer .parts tr { padding: 0; grid-template-columns: 1fr 1fr 1fr; }
  .q-answer .parts td:nth-child(1) { grid-column: 1; grid-row: 1; }
  .q-answer .parts td:nth-child(2) { grid-column: 2; grid-row: 1; font-weight: 400; }
  .q-answer .parts td:nth-child(3) { grid-column: 3; grid-row: 1; }
  .q-answer .parts td:nth-child(4) { grid-column: 1 / 4; grid-row: 2; }
}
