/* ==========================================================================
   Staetvast — opnametool. Mobiel-eerst: dit draait op een gsm ter plaatse.
   ========================================================================== */

:root{
  --cobalt: #0047AB;
  --navy: #000080;
  --sky: #82C8E5;
  --slate: #6D8196;
  --ink: #14213d;
  --muted: #52657d;
  --bg: #f3f7fb;
  --card: #ffffff;
  --line: #dce6ef;
  --ok: #12805c;
  --warn: #b4530a;
  --bad: #b3261e;
  --radius: 12px;
}

*{ box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body{ margin: 0; padding: 0; }
body{
  font-family: "Manrope", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2{ line-height: 1.2; margin: 0 0 .4em; }
img{ max-width: 100%; height: auto; display: block; }

.sr-only{
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted{ color: var(--muted); }
.small{ font-size: .87rem; }

/* Moet vóór de display-regels hieronder staan én ze overrulen: een class als
   .screen--center zet display:grid en wint anders van het hidden-attribuut,
   waardoor een verborgen scherm gewoon zichtbaar blijft. */
[hidden]{ display: none !important; }

.screen{ min-height: 100dvh; }
.screen--center{ display: grid; place-items: center; padding: 24px; }
.wrap{ max-width: 780px; margin: 0 auto; padding: 16px 16px 96px; }

/* --------------------------------------------------------------- Aanmelden */
.login-card{
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px 26px;
  width: min(400px, 100%);
  box-shadow: 0 12px 40px rgba(0,0,64,.12);
  display: grid;
  gap: 14px;
}
.login-card h1{ font-size: 1.4rem; margin: 6px 0 0; }
.login-card p{ margin: 0; }
.pass-row{ position: relative; }
.pass-row input{ width: 100%; padding-right: 74px; }
.pass-toggle{
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
  background: none; border: 0; color: var(--cobalt);
  font: inherit; font-weight: 700; font-size: .85rem;
  cursor: pointer; padding: 8px 10px;
}
.check-inline{ display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); }
/* Zonder dit erft het vinkje width:100% van de algemene input-regel en duwt
   het de tekst de kaart uit. */
.check-inline input[type="checkbox"]{ width: auto; flex: 0 0 auto; margin: 0; }
.form-error{ color: var(--bad); font-size: .9rem; margin: 0; min-height: 1.2em; font-weight: 600; }

/* ------------------------------------------------------------------ Topbar */
.topbar{
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: var(--navy);
  color: #fff;
  min-height: 52px;
}
.topbar-title{ font-weight: 800; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linkbtn{
  background: none; border: 0; color: var(--sky);
  font: inherit; font-weight: 700; cursor: pointer; padding: 6px 2px;
}
.saved{ font-size: .78rem; color: var(--sky); opacity: 0; transition: opacity .3s; }
.saved.show{ opacity: 1; }

/* -------------------------------------------------------------------- Tabs */
.tabs{
  position: sticky; top: 52px; z-index: 19;
  display: flex; background: var(--card); border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tab{
  flex: 1 0 auto; padding: 13px 16px; border: 0; background: none;
  font: inherit; font-weight: 700; font-size: .93rem; color: var(--muted);
  cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap;
}
.tab.is-active{ color: var(--cobalt); border-bottom-color: var(--cobalt); }

/* ----------------------------------------------------------------- Velden */
.field{ display: grid; gap: 5px; margin-bottom: 14px; }
.field label{ font-weight: 700; font-size: .85rem; color: var(--navy); }
input, select, textarea{
  font: inherit; width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
}
textarea{ resize: vertical; }
input:focus, select:focus, textarea:focus{
  outline: 2px solid var(--cobalt); outline-offset: 1px; border-color: transparent;
}
.grid2{ display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 520px){ .grid2{ grid-template-columns: 1fr; gap: 0; } }
.inline-add{ display: flex; gap: 8px; }
.inline-add input{ flex: 1; }
.pane-title{ font-size: 1.05rem; color: var(--navy); margin: 26px 0 12px; }
.pane-title:first-child{ margin-top: 4px; }

/* ---------------------------------------------------------------- Knoppen */
.btn{
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 12px 18px; border-radius: 999px; border: 2px solid transparent;
  font: inherit; font-weight: 700; font-size: .95rem;
  cursor: pointer; text-decoration: none;
}
.btn--primary{ background: var(--cobalt); color: #fff; }
.btn--outline{ border-color: var(--cobalt); color: var(--cobalt); background: transparent; }
.btn--block{ width: 100%; }
.btn--sm{ padding: 8px 14px; font-size: .87rem; }
.btn--danger{ border-color: var(--bad); color: var(--bad); background: transparent; }
.btn:disabled{ opacity: .5; cursor: default; }

/* ------------------------------------------------------------- Dossiers */
.dossier-list{ display: grid; gap: 10px; margin: 18px 0; }
.dossier-card{
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; display: flex; align-items: center; gap: 12px;
}
.dossier-card .grow{ flex: 1; min-width: 0; cursor: pointer; }
.dossier-card h3{ margin: 0; font-size: 1rem; color: var(--navy); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dossier-card p{ margin: 2px 0 0; font-size: .84rem; color: var(--muted); }

/* -------------------------------------------------------------- Ruimtes */
.room-list{ display: grid; gap: 8px; margin-top: 14px; }
.room-row{
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px 14px; display: flex; align-items: center; gap: 12px;
}
.room-row.is-on{ border-color: var(--cobalt); }
.room-toggle{ display: flex; align-items: center; gap: 12px; flex: 1; padding: 11px 0; cursor: pointer; }
.room-toggle input{ width: 22px; height: 22px; accent-color: var(--cobalt); flex: 0 0 auto; }
.room-name{ font-weight: 700; }
.room-open{
  background: none; border: 0; color: var(--cobalt); font: inherit; font-weight: 700;
  cursor: pointer; padding: 11px 0; white-space: nowrap;
}
.room-progress{ font-size: .8rem; color: var(--muted); font-weight: 600; }
.group-head{ font-size: .78rem; letter-spacing: .1em; text-transform: uppercase; color: var(--slate); font-weight: 800; margin: 18px 0 4px; }

/* ------------------------------------------------------------- Elementen */
.item-list{ display: grid; gap: 10px; margin-top: 6px; }
.item{
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
}
.item.has-state{ border-left: 4px solid var(--cobalt); }
.item-head{ display: flex; align-items: center; gap: 10px; }
.item-name{ font-weight: 700; flex: 1; }
.item-del{ background: none; border: 0; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 2px 6px; }
.states{ display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; }
.state{
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  border-radius: 999px; padding: 6px 12px; font: inherit; font-size: .8rem;
  font-weight: 700; cursor: pointer;
}
.state.is-on{ background: var(--cobalt); border-color: var(--cobalt); color: #fff; }
.state[data-s="Beschadigd"].is-on, .state[data-s="Defect"].is-on{ background: var(--bad); border-color: var(--bad); }
.state[data-s="Normale slijtage"].is-on{ background: var(--warn); border-color: var(--warn); }
.state[data-s="Nieuw"].is-on, .state[data-s="Goede staat"].is-on{ background: var(--ok); border-color: var(--ok); }
.item textarea{ margin-top: 10px; }
.media-bar{ display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.thumbs{ display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.thumb{ position: relative; width: 76px; height: 76px; }
.thumb img{ width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.thumb button{
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px;
  border-radius: 50%; border: 0; background: var(--bad); color: #fff;
  font-size: .8rem; line-height: 1; cursor: pointer;
}
.audio-row{ display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.audio-row audio{ flex: 1; height: 34px; }
.rec-on{ background: var(--bad) !important; border-color: var(--bad) !important; color: #fff !important; }
.transcript-label{
  display: block;
  margin-top: 10px;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
.transcript{
  display: block;
  width: 100%;
  margin-top: 4px;
  font: inherit;
  font-size: .87rem;
  color: var(--ink);
  background: #eef4fa;
  border: 1px solid #d5e3f0;
  border-radius: 8px;
  padding: 8px 10px;
  resize: vertical;
}
.transcript:focus{ outline: 2px solid var(--cobalt); background: #fff; }

/* --------------------------------------------------------------- Rapport */
.report-actions{ display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

/* Voortgang ondertekening op afstand */
.onderteken-status{
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin: 4px 0 14px;
}
.onderteken-status .os-titel{ font-weight: 700; color: var(--navy); margin: 0 0 8px; }
.onderteken-status .os-lijst{ list-style: none; margin: 0 0 10px; padding: 0; }
.onderteken-status .os-lijst li{ display: flex; align-items: center; gap: 9px; padding: 3px 0; }
.onderteken-status .os-punt{
  width: 12px; height: 12px; border-radius: 50%; background: var(--line);
  border: 2px solid var(--line); flex: 0 0 auto;
}
.onderteken-status li.is-getekend .os-punt{ background: var(--ok); border-color: var(--ok); }
.onderteken-status li.is-getekend{ color: var(--ok); }
.report-editor{
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 44px 46px; min-height: 320px; line-height: 1.7; color: var(--ink);
  max-width: 820px; margin: 0 auto;
  box-shadow: 0 10px 40px rgba(0,0,64,.06);
}
.report-editor:focus{ outline: 2px solid var(--cobalt); outline-offset: 2px; }
@media (max-width: 600px){ .report-editor{ padding: 24px 20px; } }

/* Briefhoofd bovenaan het document (niet bewerkbaar, wordt niet opgeslagen) */
.report-editor:not(:empty)::before{
  content: "STAETVAST";
  display: block; font-weight: 800; letter-spacing: .2em;
  color: var(--cobalt); font-size: .8rem; margin-bottom: 20px;
}

.report-editor h1{
  font-size: 1.55rem; color: var(--navy); font-weight: 800; letter-spacing: -.01em;
  margin: 0 0 .55em; padding-bottom: .4em; border-bottom: 3px solid var(--sky);
}
/* Eerste alinea onder de titel = adres-/metablok */
.report-editor h1 + p{
  background: #f6f9fc; border-left: 3px solid var(--cobalt);
  padding: 13px 17px; border-radius: 0 8px 8px 0; margin: 0 0 1.5em;
}
.report-editor h2{
  font-size: 1.02rem; color: var(--navy); font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
  margin: 2em 0 .7em; padding-bottom: .35em; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 9px;
}
.report-editor h2::before{
  content: ""; width: 9px; height: 9px; flex: 0 0 auto;
  background: var(--cobalt); border-radius: 2px;
}
.report-editor h3{ font-size: .98rem; color: var(--navy); margin-top: 1.2em; }
.report-editor p{ margin: .6em 0; }

.report-editor table{
  width: 100%; border-collapse: separate; border-spacing: 0; font-size: .9rem;
  margin: 1.1em 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
}
.report-editor thead th{
  background: var(--navy); color: #fff; font-weight: 700;
  font-size: .74rem; letter-spacing: .04em; text-transform: uppercase;
  padding: 9px 12px; text-align: left;
}
.report-editor tbody td, .report-editor tbody th{
  padding: 9px 12px; text-align: left; vertical-align: top;
  border-top: 1px solid var(--line);
}
.report-editor tbody tr:first-child td, .report-editor tbody tr:first-child th{ border-top: 0; }
.report-editor tbody tr:nth-child(even){ background: #f6f9fc; }
.report-editor tbody th{ font-weight: 600; color: var(--navy); background: #f1f5fa; width: 38%; }

.staat-badge{
  display: inline-block; padding: 2px 11px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; line-height: 1.5; white-space: nowrap;
}
.staat--ok{ background: rgba(18,128,92,.12); color: var(--ok); }
.staat--warn{ background: rgba(180,83,10,.13); color: var(--warn); }
.staat--bad{ background: rgba(179,38,30,.12); color: var(--bad); }
.staat--neutral{ background: #eef2f7; color: var(--muted); }

.report-editor img{
  max-width: 180px; border-radius: 8px; border: 1px solid var(--line);
  margin: 6px 8px 6px 0; display: inline-block;
}
/* Fotobijlage per ruimte: nette rasterweergave op volle grootte */
.report-editor .report-photos{
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px; margin: 1em 0;
}
.report-editor figure.rfoto{ margin: 0; break-inside: avoid; page-break-inside: avoid; }
.report-editor .report-photos img{
  width: 100%; height: auto; max-width: none; margin: 0;
  border-radius: 8px; border: 1px solid var(--line); display: block;
  background: #f1f5fa;
}
.report-editor figure.rfoto figcaption{
  font-size: .8rem; color: var(--muted); margin-top: 5px;
}

/* --------------------------------------------------------- Ondertekening */
.signblock{ margin-top: 26px; }
.signblock h3{ font-size: 1.05rem; color: var(--navy); margin: 0 0 4px; }
.sign-grid{
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
  margin-top: 12px;
}
.sign-pad{
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.sign-label{ display: block; font-weight: 700; font-size: .9rem; margin-bottom: 6px; }
.sign-naam{ width: 100%; margin-bottom: 8px; }
.sign-pad canvas{
  width: 100%;
  height: 150px;
  display: block;
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: 8px;
  /* Zonder dit scrollt de pagina mee terwijl er getekend wordt. */
  touch-action: none;
  cursor: crosshair;
}
.sign-pad canvas.is-signed{ border-style: solid; }
.sign-meta{ margin-top: 10px; font-size: .82rem; color: var(--muted); }

@media print{
  @page{ size: A4; margin: 16mm 15mm; }
  .topbar, .tabs, .report-actions, #genStatus, .no-print{ display: none !important; }
  body{ background: #fff; }
  .wrap{ padding: 0; max-width: none; }
  .report-editor{
    border: 0; border-radius: 0; box-shadow: none; padding: 0;
    max-width: none; margin: 0; line-height: 1.55;
  }
  /* Tabelkoppen herhalen op elke pagina, rijen niet middenin afbreken */
  .report-editor thead{ display: table-header-group; }
  .report-editor tr, .report-editor img{ break-inside: avoid; page-break-inside: avoid; }
  .report-editor h1, .report-editor h2, .report-editor h3{ break-after: avoid; }
  /* Kleuren mee laten printen (navy koppen, zebra-rijen, badges) */
  .report-editor thead th, .report-editor tbody th,
  .report-editor tbody tr:nth-child(even), .staat-badge{
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .signblock{ break-inside: avoid; page-break-inside: avoid; }
  .sign-pad{ border: 0; padding: 0; }
  .sign-naam{ border: 0; padding: 0; font-weight: 600; }
  .sign-pad canvas{ border: 0; border-bottom: 1px solid #333; border-radius: 0; height: 120px; }
}
