:root {
  --bg: #f4f4f1;
  --fg: #1c1c1c;
  --muted: #5a5a55;
  --line: #d6d6cf;
  --card: #fff;
  --accent: #1d5aa6;
  --accent-fg: #fff;
  --nav: #23262b;
  --brand: #f2b705;
  --warn-bg: #fff5d6;
  --warn: #a86b00;
  --err-bg: #fdecec;
  --err: #b42318;
  --ok-bg: #e6f5ea;
  --ok: #1a7f37;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-wrap: anywhere;
}
main { max-width: 900px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 8px 0 16px; }
h2 { font-size: 1.25rem; margin: 24px 0 8px; }
h3 { font-size: 1.05rem; margin: 16px 0 4px; }
a { color: var(--accent); }
img { max-width: 100%; height: auto; }

nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 16px;
  padding: 4px 16px;
  background: var(--nav);
  border-bottom: 4px solid var(--brand);
}
nav a { display: inline-flex; align-items: center; min-height: 44px; color: #fff; text-decoration: none; font-weight: 600; }
nav form { margin-left: auto; }
nav button { background: transparent; border: 1px solid #888; }

fieldset { min-width: 0; margin: 0 0 16px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
legend { padding: 0 4px; font-weight: 700; }
.field { margin: 0 0 12px; }
label, .label { display: block; margin-bottom: 4px; font-weight: 600; }
input, select, textarea, button { font: inherit; font-size: 16px; }
input:not([type=checkbox]):not([type=file]), select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #b4b4ac;
  border-radius: 6px;
  background: #fff;
  color: var(--fg);
}
textarea { min-height: 120px; resize: vertical; }
label.check { display: flex; align-items: flex-start; gap: 12px; min-height: 44px; padding: 8px 0; font-weight: 400; }
label.check input { flex: none; width: 26px; height: 26px; margin: 0; }

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 10px 18px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.secondary { background: #fff; color: var(--accent); }
.danger { background: var(--err); border-color: var(--err); color: #fff; }
.small { min-height: 40px; padding: 6px 12px; font-size: 15px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.actions > * { flex: 1 1 160px; }

.msg { margin: 8px 0; padding: 10px 12px; border-left: 4px solid; border-radius: 6px; }
.msg p, .msg ul { margin: 0; }
.err { background: var(--err-bg); border-color: var(--err); }
.warn { background: var(--warn-bg); border-color: var(--warn); }
.ok { background: var(--ok-bg); border-color: var(--ok); }
.hint { color: var(--muted); }

details { margin: 0 0 16px; }
summary { min-height: 48px; padding: 12px 0; font-weight: 700; cursor: pointer; }

.list { margin: 0; padding: 0; list-style: none; }
.list a { display: block; margin-bottom: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: inherit; text-decoration: none; }
.list .row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; background: #e4e4de; font-size: .85rem; font-weight: 600; vertical-align: middle; }
.s-bokad { background: #dbe7fb; }
.s-utlamnad { background: #ffeeb8; }
.s-aterlamnad { background: #d6f0dd; }
.s-avbokad { background: #e9e9e9; color: #666; }

.photobox { margin: 0 0 16px; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; margin: 8px 0; }
.photos figure { margin: 0; }
.photos img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; background: #ddd; }
.avtal .photos img { object-fit: contain; } /* avtalet visar hela fotot: skador i kanten är bevis */
.photos form { margin-top: 4px; }
.photos form button { width: 100%; }
.upload { position: relative; width: 100%; overflow: hidden; }
.upload input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.upload-status { min-height: 1.5em; margin: 4px 0; }

canvas.sign { display: block; width: 100%; height: 180px; margin-bottom: 8px; border: 2px dashed #888; border-radius: 6px; background: #fff; touch-action: none; }

dl.kv { margin: 0 0 12px; }
dl.kv div { padding: 6px 0; border-bottom: 1px solid var(--line); }
dl.kv dt { color: var(--muted); font-size: .875rem; }
dl.kv dd { min-height: 1.5em; margin: 0; white-space: pre-line; }
table.deb { width: 100%; border-collapse: collapse; background: var(--card); }
table.deb th, table.deb td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; font-weight: 400; }
table.deb td { text-align: right; white-space: nowrap; }
table.deb tr:last-child { font-weight: 700; }

.avtal section { margin-bottom: 8px; }
.sig { margin: 8px 0 16px; }
.sig p { margin: 4px 0 0; font-size: .9rem; }
img.sign { display: block; width: 100%; max-width: 320px; height: 90px; object-fit: contain; object-position: left bottom; border-bottom: 1px solid #000; }
.sign-line { max-width: 320px; height: 70px; border-bottom: 1px solid #000; }

@media (min-width: 640px) {
  dl.kv div { display: grid; grid-template-columns: 15em 1fr; gap: 12px; }
  dl.kv dt { font-size: 1rem; }
  .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
  .actions > * { flex: 0 1 auto; }
}

@media print {
  @page { size: A4; margin: 15mm; }
  nav, .no-print, .actions, button, form, .upload, .upload-status { display: none !important; }
  body { background: #fff; color: #000; font-size: 10.5pt; }
  main { max-width: none; padding: 0; }
  a { color: inherit; text-decoration: none; }
  h1 { margin-top: 0; }
  h2 { margin: 14pt 0 4pt; padding-bottom: 2pt; border-bottom: 1px solid #000; }
  h2, h3 { break-after: avoid; }
  section, dl.kv div, figure, .sig, table.deb tr { break-inside: avoid; }
  dl.kv div { display: grid; grid-template-columns: 50mm 1fr; gap: 4mm; padding: 2pt 0; }
  dl.kv dt { color: #333; font-size: inherit; }
  .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10mm; }
  .photos { grid-template-columns: repeat(4, 1fr); gap: 3mm; }
  .photos img { aspect-ratio: auto; height: 40mm; object-fit: contain; border-radius: 0; }
  img.sign { height: 22mm; }
  .sign-line { height: 18mm; }
}
