:root {
  --ink: #0f1c1d;
  --muted: #5d6b6c;
  --line: #dfe3e1;
  --bg: #f3f4f1;
  --card: #ffffff;
  --brand: #062b2d;
  --brand-2: #0d3c3f;
  --accent: #f7b95a;
  --accent-ink: #3a2405;
  --danger: #b4372b;
  --radius: 12px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ── top bar ───────────────────────────── */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--brand); color: #fff;
  box-shadow: 0 1px 0 rgba(0,0,0,.2);
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand svg { width: 30px; height: 30px; }
.brand strong { display: block; font-size: 16px; letter-spacing: .2px; }
.brand span { display: block; font-size: 12px; opacity: .7; }

.month { display: flex; align-items: center; gap: 4px; }
.month .icon {
  width: 34px; height: 34px; border-radius: 8px; border: 0;
  background: var(--brand-2); color: #fff; font-size: 20px; line-height: 1; cursor: pointer;
}
.month .icon:hover { background: #15504f; }
.month-pick { position: relative; display: block; }
.month-pick span {
  display: block; min-width: 150px; text-align: center; padding: 6px 12px;
  font-weight: 700; font-size: 16px; text-transform: capitalize; border-radius: 8px;
  background: var(--brand-2);
}
.month-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.month-pick input::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }

.actions { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 9px;
  padding: 8px 14px; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #b9c1be; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #ffc76f; }
.btn.ghost { background: transparent; }
.btn.ghost-light { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.btn.ghost-light:hover { border-color: #fff; }
.link {
  border: 0; background: none; padding: 0; color: #0b6b62; font-weight: 600; font-size: 13px;
  cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}
.link.danger { color: var(--danger); }
.link.file { position: relative; overflow: hidden; }
.link.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ── settings ──────────────────────────── */
.settings {
  display: flex; flex-wrap: wrap; gap: 14px 22px; align-items: flex-end;
  margin: 18px 20px 0; padding: 14px 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.field input[type=text], .field input[type=date] {
  height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; min-width: 150px;
}
.field input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; height: 36px; cursor: pointer; }
.check.small { height: auto; font-size: 13px; }
.check input { width: 17px; height: 17px; accent-color: var(--brand); }
.sig-preview {
  width: 120px; height: 36px; border: 1px dashed #c6ccc9; border-radius: 8px; background: #fafbfa;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.sig-preview img { max-width: 100%; max-height: 100%; }
.sig-preview span { font-size: 12px; color: var(--muted); }

.hint { margin: 12px 22px 0; font-size: 13px; color: var(--muted); }

/* ── cards ─────────────────────────────── */
#cards { display: grid; gap: 22px; padding: 14px 20px 40px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.card > .sheet-wrap { margin-top: 10px; }
.card-title { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.card-title h2 { margin: 0; font-size: 18px; }
.meta { font-size: 13px; color: var(--muted); }
.meta b { color: #9a5b00; font-weight: 600; }
.card-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
select {
  height: 36px; padding: 0 30px 0 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.sheet-wrap { padding: 18px; background: #e9ebe8; overflow-x: auto; }
.sheet {
  display: block; width: 100%; min-width: 860px; max-width: 1180px; margin: 0 auto; height: auto;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 6px 22px rgba(0,0,0,.08);
}
.sheet .hit { fill: transparent; cursor: pointer; }
.sheet .hit-cell:hover { fill: rgba(247,185,90,.35); }
.sheet .hit-col:hover, .sheet .hit-row:hover { fill: rgba(13,60,63,.12); }
.sheet .hit-ans:hover { fill: rgba(247,185,90,.4); }
.sheet .hit-inspector:hover, .sheet .hit-findings:hover { fill: rgba(13,60,63,.05); }
.card-hint { margin: 10px 16px 0; font-size: 13px; color: var(--muted); }

/* ── inspection ────────────────────────── */
.insp-form { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 14px; padding: 14px 16px 0; }
.panel { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #fbfbfa; min-width: 0; }
.panel h3 { margin: 0 0 10px; font-size: 14px; }
.panel h3 small { font-weight: 400; color: var(--muted); }
.insp-grid { display: grid; grid-template-columns: 1.1fr 1fr 1fr; gap: 6px 8px; margin-bottom: 10px; }
.insp-grid .lbl { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.insp-grid input, .insp-grid select, .row.tight input { height: 34px; padding: 0 9px; border: 1px solid var(--line); border-radius: 8px; background: #fff; min-width: 0; width: 100%; }
.row.tight { gap: 10px; flex-wrap: nowrap; align-items: flex-end; }
.row.tight .field { flex: 1; min-width: 0; }
.row.tight .field input { min-width: 0; }
.static { height: 34px; display: flex; align-items: center; font-weight: 700; padding: 0 2px; }
.findings { display: grid; gap: 10px; margin-bottom: 8px; }
.findings .empty { margin: 0 0 4px; font-size: 13px; color: var(--muted); }
.finding {
  position: relative;
  display: grid; gap: 6px 8px; align-items: start;
  grid-template-columns: 1.3fr 70px 1fr 1fr;
  grid-template-areas: "loc cls date date" "haz act act taken";
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px 10px;
}
.finding > :nth-child(1) { grid-area: loc; }
.finding > :nth-child(2) { grid-area: haz; }
.finding > :nth-child(3) { grid-area: cls; }
.finding > :nth-child(4) { grid-area: act; }
.finding > :nth-child(5) { grid-area: taken; }
.finding > :nth-child(6) { grid-area: date; }
.finding [data-del] { position: absolute; top: 7px; right: 10px; font-size: 12px; }
.finding label, .dc-field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.dc { position: relative; display: flex; gap: 4px; }
.dc input[type=text] { flex: 1; min-width: 0; }
.dc .mini { flex: none; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; font-size: 15px; line-height: 1; }
.dc .mini:hover { border-color: #b9c1be; }
.dc-date { position: absolute; right: 0; bottom: 0; width: 34px; height: 34px; opacity: 0; pointer-events: none; }
.dc-quick { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #f6f7f5; border-radius: 999px; padding: 2px 8px; font-size: 10.5px; font-weight: 600; cursor: pointer; color: var(--muted); }
.chip:hover { background: #fff3dc; border-color: var(--accent); color: var(--accent-ink); }
.finding label span, .dc-field > span { font-size: 10.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.finding input, .finding textarea, .finding select { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 6px 7px; font-size: 13px; background: #fff; }
.finding textarea { resize: vertical; min-height: 52px; line-height: 1.35; }
.finding input, .finding select { height: 34px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; padding: 14px 16px 0; }
.tab { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.tab b { display: inline-block; min-width: 14px; }
.tab.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.card[data-rep="inspection"] .sheet-wrap { margin-top: 10px; }

@media (max-width: 1100px) {
  .insp-form { grid-template-columns: 1fr; }
  .finding { grid-template-columns: 1.3fr 70px 1fr 1fr; }
}
@media (max-width: 640px) {
  .finding { grid-template-columns: 1fr 70px; grid-template-areas: "loc cls" "date date" "haz haz" "act act" "taken taken"; }
  .insp-grid { grid-template-columns: 1fr 1fr; }
  .insp-grid .lbl:nth-child(3), .insp-grid select { grid-column: span 2; }
}

/* ── dialog + toast ────────────────────── */
dialog { border: 0; border-radius: 14px; padding: 18px; width: min(560px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(6,43,45,.45); }
dialog h3 { margin: 0 0 10px; }
#sigCanvas { width: 100%; height: 200px; border: 1px solid var(--line); border-radius: 10px; background: #fff; touch-action: none; display: block; }
.dlg-actions { display: flex; gap: 8px; margin-top: 12px; }
.grow { flex: 1; }

#toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px);
  background: var(--brand); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

body:not(.ready) #cards { opacity: .3; }

@media (max-width: 720px) {
  .top { padding: 10px 14px; }
  .brand { width: 100%; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; }
  .settings, .hint { margin-left: 14px; margin-right: 14px; }
  #cards { padding: 14px; }
  .sheet-wrap { padding: 10px; }
}
