:root {
  --bg: #f3f5fa;
  --card: #ffffff;
  --text: #101828;
  --muted: #667085;
  --line: #e4e7ec;
  --primary: #2f55d4;
  --primary-dark: #1f3b8f;
  --primary-soft: #eaf0ff;
  --navy: #13235b;
  --ok: #12804a;
  --ok-soft: #e7f6ee;
  --warn: #b25e09;
  --warn-soft: #fff4e5;
  --bad: #c4321f;
  --bad-soft: #fdecea;
  --violet-soft: #f0ebff;
  --violet: #6a3fd1;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1rem; } h4 { font-size: .95rem; margin-top: 1rem; }
a { color: var(--primary); }
small { font-size: .8rem; }
.muted { color: var(--muted); }
.ok { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--bad); }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }
[hidden] { display: none !important; }

/* ---- Przyciski i pola ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: .65em 1.1em; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; min-height: 44px; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: #c5cbd6; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.big { font-size: 1.05rem; padding: 1em 1.4em; border-radius: 14px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: #f3c2bb; }
.btn.ok { background: var(--ok-soft); color: var(--ok); border-color: #b6e3c9; }
.btn.ok-outline { background: var(--ok-soft); color: var(--ok); border: 1px solid #b6e3c9; }
.btn.dashed { border-style: dashed; color: var(--primary); background: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: .4em .8em; font-size: .9rem; }
.btn.xs { min-height: 28px; padding: .2em .6em; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--primary); font: inherit; font-weight: 600; cursor: pointer; padding: .4em 0; }
.link.xs { font-size: .78rem; font-weight: 500; margin-left: .5em; }
.link.demo { color: var(--violet); }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 8px; width: 36px; height: 36px; font-size: 1.1rem; cursor: pointer; color: var(--muted); flex: none; }

input, textarea, select {
  width: 100%; font: inherit; color: inherit; background: #fff;
  border: 1px solid #d0d5dd; border-radius: 10px; padding: .6em .75em; min-height: 44px;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input.plain { border-color: transparent; padding-left: 0; background: transparent; }
input.plain:focus { border-color: var(--line); padding-left: .5em; }
.lbl { display: block; font-size: .82rem; font-weight: 600; color: #344054; margin: .2em 0 .35em; }
.lbl .req { color: var(--bad); }
.check { display: flex; gap: .6em; align-items: center; font-weight: 500; }
.check input { width: 22px; min-height: 22px; height: 22px; }
.auto { display: inline-block; font-size: .65rem; font-weight: 700; color: var(--violet); background: var(--violet-soft); padding: 1px 6px; border-radius: 6px; margin-left: .5em; vertical-align: middle; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 1rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0; }
.chip { font-size: .75rem; font-weight: 600; padding: .25em .7em; border-radius: 999px; background: #f2f4f7; color: #344054; white-space: nowrap; }
.chip.violet { background: var(--violet-soft); color: var(--violet); }
.chip.blue { background: var(--primary-soft); color: var(--primary); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.muted { background: #f2f4f7; color: var(--muted); }

/* ---- Przełącznik segmentowy ---- */
.seg { display: flex; flex-wrap: wrap; gap: .4rem; margin: .45rem 0; }
.seg-btn {
  flex: 1 1 auto; min-height: 42px; padding: .45em .9em; border-radius: 10px; border: 1px solid #d0d5dd;
  background: #fff; font: inherit; font-size: .9rem; font-weight: 600; color: #344054; cursor: pointer;
}
.seg-btn.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.seg-btn.on.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.seg-btn.on.bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.seg-btn.on.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.seg-btn.on.muted { background: #f2f4f7; border-color: #98a2b3; color: #475467; }
.seg.wrap .seg-btn { flex: 1 1 30%; }

/* ---- Edytor protokołu ---- */
.pe { position: relative; }
.pe-tabs {
  position: sticky; top: 0; z-index: 5; display: flex; gap: .4rem; overflow-x: auto; padding: .6rem .2rem;
  background: var(--bg); scrollbar-width: none;
}
.pe-tabs::-webkit-scrollbar { display: none; }
.pe-tab {
  flex: none; display: inline-flex; gap: .4em; align-items: center; border: 1px solid var(--line); background: #fff;
  border-radius: 999px; padding: .4em .9em; font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; color: #344054;
}
.pe-tab.complete { border-color: #b6e3c9; color: var(--ok); }
.pe-count { font-size: .75rem; color: var(--muted); }
.pe-tab.complete .pe-count { color: var(--ok); }
.pe-body { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; gap: .9rem; }
.pe-section { scroll-margin-top: 64px; }
.pe-sec-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px solid var(--line); margin: -.2rem 0 .8rem; padding-bottom: .5rem; }
.pe-sec-head h3 { text-transform: uppercase; letter-spacing: .04em; font-size: .82rem; color: #344054; margin: 0; }
.pe-sec-count { font-size: .8rem; color: var(--muted); font-weight: 600; }
.pe-head-top { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.pe-obj-name { font-weight: 700; font-size: 1.1rem; }
.pe-footer {
  position: sticky; bottom: 0; z-index: 5; display: flex; gap: .8rem; align-items: center;
  background: rgba(255,255,255,.96); backdrop-filter: blur(6px); border-top: 1px solid var(--line);
  padding: .7rem 1rem calc(.7rem + env(safe-area-inset-bottom)); margin: 1rem -1rem 0;
}
.pe-footer-info { flex: 1; font-size: .85rem; font-weight: 600; color: #344054; }
.pe-bar { height: 5px; border-radius: 4px; background: var(--line); margin-top: .35rem; overflow: hidden; }
.pe-bar-fill { height: 100%; background: var(--primary); transition: width .3s; }

.fields { display: flex; flex-wrap: wrap; gap: 0 .8rem; }
.field { flex: 1 1 100%; margin-bottom: .7rem; }
.field.half { flex: 1 1 calc(50% - .8rem); min-width: 140px; }

.instr-list { display: grid; gap: .5rem; }
.instr { display: flex; gap: .7rem; text-align: left; border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: .7rem; font: inherit; cursor: pointer; }
.instr.on { border-color: var(--primary); background: var(--primary-soft); }
.instr-check { flex: none; width: 24px; height: 24px; border-radius: 6px; border: 1.5px solid #98a2b3; display: grid; place-items: center; color: #fff; font-weight: 700; }
.instr.on .instr-check { background: var(--primary); border-color: var(--primary); }

.check-item { border-top: 1px solid var(--line); padding: .8rem 0; }
.check-item:first-of-type { border-top: 0; }
.check-item.neg { background: linear-gradient(90deg, var(--bad-soft), transparent 70%); margin: 0 -1rem; padding: .8rem 1rem; }
.check-row { display: flex; gap: .7rem; align-items: flex-start; }
.num { flex: none; width: 26px; height: 26px; border-radius: 50%; background: #f2f4f7; display: grid; place-items: center; font-size: .78rem; font-weight: 700; color: #475467; }
.prev-defect { display: flex; gap: .6rem; align-items: center; justify-content: space-between; background: var(--warn-soft); color: #7a4208; border-radius: 10px; padding: .5rem .7rem; font-size: .85rem; margin: .3rem 0; }
.defect-box { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .7rem; margin-top: .4rem; }

.hint { font-size: .8rem; color: var(--muted); margin: .3rem 0 .7rem; }
.meas { display: grid; gap: .7rem; }
.meas-row { border: 1px solid var(--line); border-radius: 12px; padding: .7rem; background: #fcfcfd; }
.meas-head { display: flex; gap: .6rem; align-items: center; margin-bottom: .5rem; }
.meas-head b { display: block; }
.meas-head small { display: block; }
.sym { flex: none; min-width: 38px; height: 30px; padding: 0 .4em; border-radius: 8px; background: var(--navy); color: #fff; font-weight: 700; font-size: .85rem; display: grid; place-items: center; }
.meas-cells { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: .5rem; }
.meas-cell { border: 1.5px solid var(--line); border-radius: 10px; padding: .4rem .55rem; background: #fff; }
.meas-cell.compact { width: 110px; flex: none; }
.meas-lbl { display: flex; justify-content: space-between; font-size: .75rem; font-weight: 700; color: #475467; }
.meas-lbl small { font-weight: 600; color: var(--muted); }
.meas-in { border: 0; padding: .1em 0; min-height: 34px; font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; background: transparent; }
.meas-in:focus { outline: 0; }
.meas-cell .prev { color: var(--muted); font-size: .72rem; }
.meas-cell.ok { border-color: #8fd3ad; background: var(--ok-soft); }
.meas-cell.ok .meas-in { color: var(--ok); }
.meas-cell.bad { border-color: #f0a197; background: var(--bad-soft); }
.meas-cell.bad .meas-in { color: var(--bad); }
.meas-cell.warn { border-color: #f5c27a; background: var(--warn-soft); }
.meas-cell.warn .meas-in { color: var(--warn); }
.meas-cell:focus-within { border-color: var(--primary); }
.msgs { display: grid; gap: .3rem; margin-top: .4rem; }
.msg { font-size: .8rem; padding: .35rem .6rem; border-radius: 8px; }
.msg.info { background: #f2f4f7; color: #475467; }
.msg.warn { background: var(--warn-soft); color: #7a4208; }
.msg.bad { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.row-edit { display: grid; grid-template-columns: 1fr 1fr; gap: .2rem .6rem; background: #fff; border: 1px dashed #c5cbd6; border-radius: 10px; padding: .6rem; margin-bottom: .6rem; }
.row-edit .wide { grid-column: 1 / -1; }
.row-edit .lbl input, .row-edit .lbl select { margin-top: .2rem; font-weight: 400; }
.row-edit-actions { grid-column: 1 / -1; display: flex; justify-content: space-between; margin-top: .3rem; }
.inline { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: .4rem; }
.inline .seg { flex: 1; margin: 0; }
.bond-row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; border-top: 1px solid var(--line); padding: .6rem 0; }
.bond-row .seg { margin: 0; }
.bond-row.neg { background: var(--bad-soft); }
.meas + .btn, .btn.dashed { margin-top: .7rem; }

.results { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .5rem; margin-bottom: .8rem; }
.result { border: 1px solid var(--line); border-radius: 10px; padding: .5rem .7rem; }
.result small { display: block; color: var(--muted); font-size: .72rem; }

.sigs { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .8rem; }
.sig-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .3rem; }
.sig-canvas { width: 100%; aspect-ratio: 3 / 1; border: 1.5px dashed #c5cbd6; border-radius: 10px; background: #fff; touch-action: none; display: block; }

.photos { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; }
.photo { position: relative; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; background: #eef0f4; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-x { position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(16,24,40,.7); color: #fff; cursor: pointer; line-height: 1; }
.photo-add { width: 84px; height: 84px; border-radius: 10px; border: 1.5px dashed #98a2b3; display: grid; place-items: center; align-content: center; cursor: pointer; font-size: 1.4rem; color: var(--muted); }
.photo-add small { font-size: .65rem; }

/* ---- Tabele, modale, toasty ---- */
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .6rem .7rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #f9fafb; }
.tbl td small { display: block; color: var(--muted); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: grid; place-items: center; z-index: 50; padding: 1rem; }
.modal { background: #fff; border-radius: 16px; padding: 1.2rem; width: min(520px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 20px 40px rgba(0,0,0,.2); }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.toasts { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 60; display: grid; gap: .5rem; width: min(420px, 92vw); }
.toast { background: var(--navy); color: #fff; padding: .75rem 1rem; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.2); transition: opacity .4s, transform .4s; font-weight: 500; }
.toast.bad { background: var(--bad); }
.toast.warn { background: var(--warn); }
.toast.out { opacity: 0; transform: translateY(10px); }

.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(160deg, #13235b, #2f55d4); }
.login-card { width: min(400px, 100%); }
.login-card .brand { display: flex; gap: .7rem; align-items: center; margin-bottom: 1rem; }
.logo { width: 42px; height: 42px; border-radius: 12px; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 1.3rem; flex: none; }
.err { color: var(--bad); font-size: .88rem; min-height: 1.2em; }
