:root {
  --navy: #1f3a5f; --navy-2: #2c5282; --bg: #f3f5f8; --card: #fff; --text: #1a202c; --muted: #5f6b7a;
  --line: #d5dbe3; --ok: #1e7b45; --ok-bg: #e3f4ea; --bad: #b42318; --bad-bg: #fde8e6; --warn: #8a5a00; --warn-bg: #fff4d6;
  --info-bg: #e8f0fb; --radius: 10px; --tap: 48px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text); background: var(--bg); font-size: 16px; line-height: 1.45;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); min-height: 100vh; }
a { color: var(--navy-2); }
h1 { font-size: 1.45rem; margin: 0.2em 0 0.4em; }
h2 { font-size: 1.2rem; margin: 1em 0 0.5em; }
h3 { font-size: 1.05rem; margin: 0.8em 0 0.4em; }
.boot { padding: 2rem; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.hidden { display: none !important; }
.sr { position: absolute; left: -9999px; }

/* Topp og navigasjon */
.topbar { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 20; box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.topbar-inner { display: flex; align-items: center; gap: 12px; padding: 8px 14px; max-width: 1200px; margin: 0 auto; }
.brand { font-weight: 700; font-size: 1.05rem; color: #fff; text-decoration: none; white-space: nowrap; }
.brand small { display: block; font-weight: 400; font-size: 0.72rem; opacity: 0.8; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.userbox button { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.5); min-height: 38px; padding: 4px 12px; }
.nav { display: flex; gap: 2px; overflow-x: auto; padding: 0 8px; max-width: 1200px; margin: 0 auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: #dce6f2; text-decoration: none; padding: 10px 12px; white-space: nowrap; border-bottom: 3px solid transparent; font-size: 0.95rem; min-height: 44px; display: flex; align-items: center; }
.nav a.active { color: #fff; border-bottom-color: #f6c343; font-weight: 600; }
.envbanner { background: #b42318; color: #fff; text-align: center; font-weight: 700; padding: 4px; font-size: 0.85rem; }
.netbanner { background: var(--warn-bg); color: var(--warn); text-align: center; padding: 6px; font-weight: 600; border-bottom: 1px solid #e8c766; }

main { max-width: 1200px; margin: 0 auto; padding: 14px 14px 80px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.card.tight { padding: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.stack > * + * { margin-top: 10px; }

/* Knapper og skjema */
button, .btn { font: inherit; min-height: var(--tap); padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; touch-action: manipulation; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary, button.primary { background: var(--navy-2); color: #fff; border-color: var(--navy-2); font-weight: 600; }
.btn-danger, button.danger { background: #fff; color: var(--bad); border-color: var(--bad); }
.btn-ok, button.okbtn { background: var(--ok); color: #fff; border-color: var(--ok); font-weight: 600; }
button.link { background: none; border: none; color: var(--navy-2); text-decoration: underline; min-height: 36px; padding: 4px 6px; }
button.small, .btn.small { min-height: 38px; padding: 4px 10px; font-size: 0.9rem; }
.btn-big { min-height: 60px; font-size: 1.05rem; width: 100%; justify-content: flex-start; text-align: left; }
label.field { display: block; margin-bottom: 10px; }
label.field > span, .field-label { display: block; font-weight: 600; font-size: 0.92rem; margin-bottom: 4px; }
input, select, textarea { font: inherit; width: 100%; min-height: var(--tap); padding: 8px 10px; border: 1px solid #b8c2cf; border-radius: 8px; background: #fff; color: var(--text); }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 3px solid #9cc3f5; outline-offset: 1px; }
input[type=checkbox] { width: 24px; min-height: 24px; height: 24px; }
.check { display: flex; gap: 10px; align-items: center; min-height: var(--tap); }
.hint { font-size: 0.85rem; color: var(--muted); margin-top: 3px; }
.error-text { color: var(--bad); font-weight: 600; }
.formgrid { display: grid; gap: 0 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

/* Merker og statuser */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; background: #eef1f5; color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.info { background: var(--info-bg); color: var(--navy-2); }
.notice { padding: 10px 12px; border-radius: 8px; margin: 8px 0; border: 1px solid transparent; }
.notice.info { background: var(--info-bg); border-color: #bcd2f0; }
.notice.warn { background: var(--warn-bg); border-color: #e8c766; }
.notice.bad { background: var(--bad-bg); border-color: #f1a9a1; }
.notice.ok { background: var(--ok-bg); border-color: #9fd3b4; }
.savestatus { font-size: 0.9rem; font-weight: 600; }
.savestatus.saving { color: var(--warn); }
.savestatus.saved { color: var(--ok); }
.savestatus.failed { color: var(--bad); }

/* Dagvisning */
.datebar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.datebar input[type=date] { width: auto; }
.datebar h1 { margin: 0; flex: 1 1 100%; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin: 12px 0; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; min-height: 44px; display: flex; align-items: center; }
.tabs a.active { color: var(--navy); border-bottom-color: var(--navy-2); }
.round-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.temptable { width: 100%; border-collapse: collapse; }
.temptable th { text-align: left; font-size: 0.82rem; color: var(--muted); padding: 6px; border-bottom: 2px solid var(--line); }
.temptable td { padding: 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.temptable tr.clickable { cursor: pointer; }
.temptable tr.clickable:hover { background: #f7f9fc; }
.temptable tr.st-missed td { background: #fff7f6; }
.mobile-only { display: none; }
td.editor-cell { padding: 0 !important; border: none !important; }
.nr { font-weight: 800; font-size: 1.15rem; }
.tempval { font-weight: 700; font-size: 1.1rem; white-space: nowrap; }
.tempval.bad { color: var(--bad); }
.editor { background: #f8fafc; border: 2px solid var(--navy-2); border-radius: var(--radius); padding: 12px; margin: 6px 0 12px; }
.tempinput { display: flex; gap: 8px; align-items: stretch; }
.tempinput input { font-size: 1.4rem; font-weight: 700; text-align: center; max-width: 160px; }
.tempinput button { min-width: 56px; font-size: 1.3rem; font-weight: 700; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.quick button { min-width: 52px; min-height: 46px; padding: 4px 8px; font-weight: 600; }
.quick button.sel { background: var(--navy-2); color: #fff; }
.sigbox { border: 2px solid var(--text); border-radius: 4px; padding: 10px; margin-top: 12px; background: #fff; }
.sigbox-title { font-weight: 700; }
.siglist { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 6px; }
.sigitem { border: 1px solid var(--line); border-radius: 8px; padding: 8px; min-width: 220px; max-width: 320px; background: #fff; }
.sigitem img { max-width: 100%; height: 60px; object-fit: contain; display: block; background: #fff; }
.sigitem.outdated { border-color: var(--bad); background: #fff8f7; }

/* Mobil: tabellrader som kort */
@media (max-width: 720px) {
  .temptable thead { display: none; }
  .temptable, .temptable tbody, .temptable tr, .temptable td { display: block; width: 100%; }
  .temptable tr { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; background: #fff; padding: 6px 4px; display: grid; grid-template-columns: 64px 1fr auto; align-items: center; }
  .temptable td { border: none; padding: 2px 6px; }
  .temptable td.c-kl, .temptable td.c-ref { display: none; }
  .mobile-only { display: block; }
  .temptable tr.editor-row { display: block; border: none; padding: 0; background: none; }
  .temptable tr.st-missed { background: #fff7f6; border-color: #f1c4bf; }
  .temptable tr.st-missed td { background: transparent; }
  .brand small { display: none; }
  .userbox span { font-size: 0.75rem; white-space: normal; max-width: 110px; }
  .temptable td.c-nr { grid-row: span 2; }
  .temptable td.c-avvik, .temptable td.c-tiltak { grid-column: 2 / 4; font-size: 0.85rem; }
  .temptable td.c-avvik:empty, .temptable td.c-tiltak:empty { display: none; }
  main { padding: 10px 10px 80px; }
  .card { padding: 10px; }
}

/* Signaturfelt */
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55); z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 720px) { .modal-back { align-items: center; } }
.modal { background: #fff; width: 100%; max-width: 720px; max-height: 94vh; overflow: auto; border-radius: 14px 14px 0 0; padding: 16px; }
@media (min-width: 720px) { .modal { border-radius: 14px; } }
.sigpad-wrap { border: 2px dashed #8796a8; border-radius: 10px; background: #fff; position: relative; touch-action: none; }
.sigpad-wrap canvas { width: 100%; height: 200px; display: block; touch-action: none; }
.sigpad-line { position: absolute; left: 16px; right: 16px; bottom: 44px; border-bottom: 1px solid #c9d1db; pointer-events: none; }
.sigpad-label { position: absolute; left: 16px; bottom: 20px; color: #8796a8; font-size: 0.8rem; pointer-events: none; }
.statement { background: var(--info-bg); padding: 10px; border-radius: 8px; font-size: 0.92rem; }

/* Kalender */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .wd { text-align: center; font-size: 0.8rem; font-weight: 700; color: var(--muted); padding: 4px 0; }
.cal a.day { display: block; min-height: 74px; border-radius: 8px; padding: 5px; text-decoration: none; color: var(--text); border: 1px solid var(--line); background: #fff; font-size: 0.78rem; }
.cal a.day b { font-size: 1rem; display: block; }
.cal a.day.today { outline: 3px solid #f6c343; }
.cal a.day.st-complete { background: var(--ok-bg); border-color: #9fd3b4; }
.cal a.day.st-partial, .cal a.day.st-missing { background: var(--bad-bg); border-color: #f1a9a1; }
.cal a.day.st-in_progress { background: var(--warn-bg); border-color: #e8c766; }
.cal a.day.st-future, .cal a.day.st-before_start, .cal a.day.st-excepted { background: #f1f3f6; color: var(--muted); }
.cal .blank { min-height: 74px; }
@media (max-width: 560px) { .cal a.day { min-height: 56px; padding: 3px; font-size: 0.68rem; } .cal a.day .calinfo { display: none; } }
.legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 0.82rem; margin-top: 10px; }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; background: var(--c); border: 1px solid rgba(0,0,0,.15); }

/* Renholdsark (papirvisning) */
.sheet { background: #fff; border: 1px solid var(--line); padding: 16px; margin-bottom: 16px; }
.sheet h2 { text-decoration: underline; margin: 0; font-family: "Times New Roman", serif; font-size: 1.25rem; }
.papertable { width: 100%; border-collapse: collapse; table-layout: fixed; margin-top: 10px; }
.papertable th, .papertable td { border: 1px solid #555; padding: 3px 5px; vertical-align: top; }
.papertable th { font-family: "Times New Roman", serif; text-align: left; font-size: 1.05rem; }
.papertable td { height: 46px; font-size: 0.8rem; }
.papertable td img { height: 30px; max-width: 100%; object-fit: contain; display: block; }

/* Lister */
.list { list-style: none; padding: 0; margin: 0; }
.list li { border-bottom: 1px solid var(--line); padding: 10px 2px; }
.list li:last-child { border-bottom: none; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.data th, table.data td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.data th { font-size: 0.8rem; color: var(--muted); }
.scroll-x { overflow-x: auto; }
.history { border-left: 3px solid var(--line); padding-left: 10px; margin: 6px 0; }
.history .ver { margin-bottom: 8px; }
.change { font-size: 0.88rem; }
.change del { color: var(--bad); }
.change ins { color: var(--ok); text-decoration: none; font-weight: 600; }
.toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); background: #1a202c; color: #fff; padding: 12px 18px; border-radius: 10px; z-index: 200; max-width: 92vw; box-shadow: 0 4px 14px rgba(0,0,0,.3); }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }
.login { max-width: 420px; margin: 8vh auto; }
.kpi { font-size: 1.6rem; font-weight: 800; }
pre.body { white-space: pre-wrap; font-family: inherit; margin: 0; }

@media print {
  .topbar, .nav, .tabs, .noprint, button { display: none !important; }
  main { padding: 0; max-width: none; }
  .sheet { border: none; page-break-after: always; }
  body { background: #fff; }
}
