:root {
  --bg: #F5F7F7;
  --surface: #FFFFFF;
  --ink: #16211F;
  --muted: #5E6E6C;
  --faint: #8A9795;
  --line: #E2E7E6;
  --line-strong: #CCD4D3;
  --teal: #0C7C7C;
  --teal-dark: #094E4E;
  --teal-wash: #E6F1F0;
  --amber-bg: #FBEFD9;
  --amber-ink: #8A4F08;
  --red-bg: #FBE9E9;
  --red-ink: #A12D2D;
  --green-bg: #E5F2E9;
  --green-ink: #1C6E3F;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--teal-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Top bar ---- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 1000;
}
.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand-dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-wash);
}
.brand small {
  font-weight: 400;
  color: var(--faint);
  font-size: 13px;
  margin-left: 2px;
}

.preview-note {
  background: var(--teal-dark);
  color: #DDEEED;
  font-size: 13px;
  text-align: center;
  padding: 6px 14px;
}
.preview-note b { color: #fff; font-weight: 500; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 20px 18px 56px; }

h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; margin: 4px 0 2px; }
.subhead { color: var(--muted); margin: 0 0 20px; font-size: 15px; }

/* ---- Map ---- */
#map {
  height: 340px;
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  margin-bottom: 24px;
  z-index: 1;
}

/* ---- Container list ---- */
.list-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 12px;
}
.count { color: var(--faint); font-size: 14px; font-variant-numeric: tabular-nums; }

.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
  color: var(--ink);
  transition: border-color .12s ease, transform .12s ease;
}
.card:hover { text-decoration: none; border-color: var(--line-strong); transform: translateY(-1px); }

.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.code { font-family: var(--mono); font-size: 15px; font-weight: 600; letter-spacing: -0.02em; }
.client { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card-notes { color: var(--faint); font-size: 13px; margin-top: 8px; }

.card-foot {
  margin-top: 12px; padding-top: 11px; border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  font-size: 13px; color: var(--muted);
}
.card-foot .meta { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green-ink); display: inline-block; }
.dot.warn { background: var(--amber-ink); }

/* ---- Badges / pills ---- */
.pill {
  font-size: 12px; font-weight: 500; padding: 2px 9px; border-radius: 999px;
  white-space: nowrap; line-height: 1.5;
}
.pill.gen { background: var(--teal-wash); color: var(--teal-dark); }
.pill.alert { background: var(--red-bg); color: var(--red-ink); }
.pill.routine { background: var(--teal-wash); color: var(--teal-dark); }
.pill.emergency { background: var(--red-bg); color: var(--red-ink); }
.pill.specialist { background: #ECEAF7; color: #4A3F95; }

.status { font-size: 12px; font-weight: 500; padding: 2px 9px; border-radius: 6px; white-space: nowrap; }
.status.ok { background: var(--green-bg); color: var(--green-ink); }
.status.attention { background: var(--amber-bg); color: var(--amber-ink); }
.status.fault { background: var(--red-bg); color: var(--red-ink); }

/* ---- Detail page ---- */
.back { color: var(--muted); font-size: 14px; display: inline-block; margin-bottom: 14px; }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.detail-head h1 { font-family: var(--mono); }

.banner {
  background: var(--amber-bg); color: var(--amber-ink);
  border-radius: var(--radius-sm); padding: 10px 14px; margin: 14px 0 0;
  font-size: 14px;
}

.section { margin-top: 30px; }
.section h2 {
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--faint); margin: 0 0 12px;
}

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }

.equip-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
}
.equip-row:last-child { border-bottom: none; }
.equip-type { font-weight: 500; }
.equip-model { color: var(--muted); font-size: 13px; }
.equip-meta { text-align: right; font-size: 13px; }
.expiry { color: var(--muted); font-size: 12px; margin-top: 3px; }
.expiry.bad { color: var(--red-ink); font-weight: 500; }

/* ---- Visit timeline ---- */
.visit { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 16px; margin-bottom: 12px; }
.visit-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.visit-date { font-family: var(--mono); font-size: 14px; font-weight: 600; }
.visit-by { color: var(--muted); font-size: 13px; }
.visit-checks { display: flex; gap: 8px; flex-wrap: wrap; margin: 11px 0 0; }
.chk { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.chk.done { color: var(--green-ink); }
.tick { width: 15px; text-align: center; }
.visit-notes { margin: 11px 0 0; font-size: 14px; white-space: pre-wrap; }
.gen-note { margin-top: 8px; font-size: 13px; color: var(--muted); background: var(--bg); border-radius: var(--radius-sm); padding: 8px 11px; }

.empty { color: var(--faint); font-size: 14px; padding: 18px; text-align: center; background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); }

@media (max-width: 560px) {
  .wrap { padding: 16px 14px 48px; }
  #map { height: 280px; }
  .cards { grid-template-columns: 1fr; }
}

/* Leaflet popup tweaks */
.leaflet-popup-content { margin: 11px 13px; font-family: var(--sans); }
.leaflet-popup-content .code { font-size: 14px; }
.popup-client { color: var(--muted); font-size: 12px; margin-top: 2px; }
.popup-link { display: inline-block; margin-top: 7px; font-size: 13px; font-weight: 500; }

/* ---- Auth: user box in top bar ---- */
.userbox { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.user-email { color: var(--muted); font-size: 13px; }
.role-pill { font-size: 12px; font-weight: 500; padding: 2px 10px; border-radius: 999px; }
.role-pill.staff { background: var(--teal-wash); color: var(--teal-dark); }
.role-pill.client { background: #ECEAF7; color: #4A3F95; }
.logout-form { margin: 0; }
.logout-form button {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 13px; padding: 5px 12px; border-radius: var(--radius-sm); cursor: pointer;
}
.logout-form button:hover { border-color: var(--muted); }

/* ---- Login page ---- */
.login-shell { display: flex; justify-content: center; padding: 6vh 0; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 28px 26px 30px;
}
.login-card h1 { margin: 0 0 4px; }
.login-card .subhead { margin-bottom: 22px; }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-form input {
  font: inherit; font-size: 16px; padding: 11px 12px; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); color: var(--ink); background: var(--bg);
}
.login-form input:focus { outline: 2px solid var(--teal); outline-offset: 1px; border-color: var(--teal); }
.btn-primary {
  font: inherit; font-weight: 500; font-size: 15px; padding: 12px; margin-top: 4px;
  background: var(--teal); color: #fff; border: none; border-radius: var(--radius-sm); cursor: pointer;
}
.btn-primary:hover { background: var(--teal-dark); }
.login-error {
  background: var(--red-bg); color: var(--red-ink); font-size: 14px;
  padding: 10px 13px; border-radius: var(--radius-sm); margin-bottom: 18px;
}

@media (max-width: 560px) {
  .userbox .user-email { display: none; }
}

/* ---- Address ---- */
.addr { margin: 4px 0 0; font-size: 14px; color: var(--ink); }
.addr.muted { color: var(--muted); font-size: 13px; }
.card-addr { color: var(--ink); font-size: 13px; margin-top: 3px; }
.popup-addr { color: var(--muted); font-size: 12px; margin-top: 3px; }

/* ---- Detail head actions ---- */
.head-side { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.btn-sm { font-size: 14px; padding: 8px 14px; text-decoration: none; display: inline-block; }
.btn-primary.btn-sm:hover { text-decoration: none; }

.btn-secondary {
  font: inherit; font-size: 14px; font-weight: 500; padding: 8px 14px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); cursor: pointer; text-decoration: none; display: inline-block;
}
.btn-secondary:hover { border-color: var(--muted); text-decoration: none; }

/* equipment rows are now links */
a.equip-row { color: var(--ink); text-decoration: none; }
a.equip-row:hover { background: var(--bg); text-decoration: none; }
.eq-count { color: var(--teal-dark); font-size: 12px; margin-top: 3px; }

/* ---- Photo grids ---- */
.photo-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.photo-grid.small .thumb img { height: 84px; width: 84px; }
.thumb { position: relative; }
.thumb img {
  height: 120px; width: 120px; object-fit: cover; border-radius: var(--radius-sm);
  border: 1px solid var(--line); display: block; image-orientation: from-image; background: var(--bg);
}
.thumb form { position: absolute; top: 4px; right: 4px; margin: 0; }
.thumb-del {
  width: 22px; height: 22px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(20,33,31,.72); color: #fff; font-size: 15px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.thumb-del:hover { background: var(--red-ink); }
.muted-note { color: var(--faint); font-size: 14px; margin: 0 0 12px; }

.upload { display: flex; gap: 10px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.upload input[type=file] { font: inherit; font-size: 14px; max-width: 100%; }

.docs { margin-top: 11px; display: flex; gap: 8px; flex-wrap: wrap; }
.doc-chip {
  font-size: 13px; padding: 5px 11px; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); color: var(--teal-dark); background: var(--surface);
}

/* ---- Visit form ---- */
.visit-form { display: flex; flex-direction: column; gap: 18px; max-width: 560px; margin-top: 10px; }
.field-row { display: flex; gap: 14px; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 140px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea {
  font: inherit; font-size: 16px; padding: 11px 12px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); width: 100%;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--teal); outline-offset: 1px; border-color: var(--teal);
}
.field .hint { color: var(--faint); font-size: 12px; }
.visitor-note { font-size: 14px; color: var(--muted); }
.visitor-note b { color: var(--ink); }
.checkbox { display: flex; align-items: center; gap: 10px; font-size: 16px; color: var(--ink); cursor: pointer; }
.checkbox input { width: 20px; height: 20px; accent-color: var(--teal); }
.gen-block {
  display: flex; flex-direction: column; gap: 14px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
}
.form-actions { display: flex; gap: 12px; align-items: center; }
