:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5d6877;
  --border: #dde2e8;
  --accent: #1f4e8c;
  --accent-text: #ffffff;
  --ok: #1d7a46;
  --ok-bg: #e3f4ea;
  --warn: #a8321f;
  --warn-bg: #fbe7e3;
  --amber: #8a5a00;
  --amber-bg: #fdf1d8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b;
    --surface: #1a2029;
    --text: #e6e9ee;
    --muted: #9aa5b4;
    --border: #2c3542;
    --accent: #5b8fd6;
    --accent-text: #0b1220;
    --ok: #5cc98a;
    --ok-bg: #173323;
    --warn: #f08b77;
    --warn-bg: #3a1d18;
    --amber: #f0c060;
    --amber-bg: #3a2e12;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 72px; /* room for the mobile tab bar */
}

a { color: var(--accent); }

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.75rem; }

.container { max-width: 1100px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 640px; }

/* ---- navigation */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .container { display: flex; align-items: center; gap: 24px; padding-top: 10px; padding-bottom: 10px; }
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.topnav { display: none; gap: 18px; flex: 1; }
.topnav a, .user-menu a, .user-menu button { color: var(--muted); text-decoration: none; font-size: 0.95rem; }
.topnav a.active { color: var(--accent); font-weight: 600; }
.user-menu { margin-left: auto; display: flex; gap: 14px; align-items: center; }
.user-menu form { margin: 0; }
.user-menu button { background: none; border: 0; cursor: pointer; padding: 0; font: inherit; }

.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tabbar a {
  text-align: center;
  padding: 10px 2px 8px;
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: none;
}
.tabbar a .icon { display: block; font-size: 1.25rem; line-height: 1.2; }
.tabbar a.active { color: var(--accent); font-weight: 600; }
.tabbar a.primary .icon {
  background: var(--accent); color: var(--accent-text);
  width: 40px; height: 40px; line-height: 40px; border-radius: 50%; margin: -14px auto 2px;
}

@media (min-width: 800px) {
  body { padding-bottom: 0; }
  .topnav { display: flex; }
  .tabbar { display: none; }
}

/* ---- surfaces */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 800px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

.stat { padding: 14px 16px; }
.stat .value { font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .label { color: var(--muted); font-size: 0.85rem; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; justify-content: space-between; margin-bottom: 12px; }
.page-head h1 { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-danger { color: var(--warn); }
.btn-block { width: 100%; }
.btn-big { min-height: 64px; font-size: 1.1rem; }

/* ---- forms */
.field { margin-bottom: 16px; }
.field > label, .field-label { display: block; font-weight: 600; margin-bottom: 6px; }
.help { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }
.errorlist { color: var(--warn); margin: 4px 0 0; padding: 0; list-style: none; font-size: 0.9rem; }
.form-errors { background: var(--warn-bg); color: var(--warn); padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }

input[type=text], input[type=password], input[type=date], input[type=datetime-local], input[type=search],
input[type=number], select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.outcome-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.outcome-choice div { margin: 0; }
.outcome-choice label {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; border: 2px solid var(--border); border-radius: 10px;
  font-weight: 700; cursor: pointer; background: var(--surface);
}
.outcome-choice input { position: absolute; opacity: 0; pointer-events: none; }
.outcome-choice label:has(input[value=normal]:checked) { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
.outcome-choice label:has(input[value=abnormal]:checked) { border-color: var(--warn); background: var(--warn-bg); color: var(--warn); }
.outcome-choice ul, .outcome-choice { list-style: none; padding: 0; margin: 0; }

.photo-input {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 2px dashed var(--border); border-radius: 10px; padding: 18px; text-align: center; cursor: pointer;
}
.photo-input input { display: none; }
.photo-input .help { display: block; }
.photo-previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; margin-top: 10px; }
.photo-previews img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; }
.photo-status { color: var(--muted); font-size: 0.85rem; margin-top: 6px; }

.check-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.check-photos label { display: block; font-size: 0.85rem; }
.check-photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; margin-bottom: 4px; }

.gps-status { font-size: 0.85rem; color: var(--muted); }

.filters { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.filters .full { grid-column: 1 / -1; }
@media (min-width: 800px) { .filters { grid-template-columns: repeat(6, 1fr); align-items: end; } .filters .full { grid-column: auto; } }

/* ---- lists and tables */
.entry-list { list-style: none; margin: 0; padding: 0; }
.entry-list li { border-bottom: 1px solid var(--border); }
.entry-list li:last-child { border-bottom: 0; }
.entry-list a { display: flex; gap: 12px; align-items: center; padding: 12px 4px; color: inherit; text-decoration: none; }
.entry-list .thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; flex: none; background: var(--border); }
.entry-list .main { flex: 1; min-width: 0; }
.entry-list .title { font-weight: 600; }
.entry-list .meta { color: var(--muted); font-size: 0.85rem; }
.entry-list .snippet { color: var(--muted); font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.badge-normal, .badge-closed { background: var(--ok-bg); color: var(--ok); }
.badge-abnormal, .badge-high, .badge-critical, .badge-open { background: var(--warn-bg); color: var(--warn); }
.badge-medium { background: var(--amber-bg); color: var(--amber); }
.badge-low, .badge-muted { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

dl.details { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; }
.prose { white-space: pre-wrap; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.gallery img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 8px; display: block; }

.history { list-style: none; padding: 0; margin: 0; font-size: 0.9rem; }
.history li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.history .who { color: var(--muted); }
.history .chg { margin: 4px 0 0 0; padding-left: 16px; }
.history del { color: var(--warn); }
.history ins { color: var(--ok); text-decoration: none; }

.messages { list-style: none; padding: 0; margin: 0 0 12px; }
.messages li { padding: 10px 14px; border-radius: 8px; background: var(--ok-bg); color: var(--ok); margin-bottom: 6px; }
.messages li.error { background: var(--warn-bg); color: var(--warn); }

.pagination { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 12px; color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }
.muted { color: var(--muted); }
.messages-note { padding: 10px 14px; border-radius: 8px; background: var(--amber-bg); color: var(--amber); margin-bottom: 16px; }
.link-button { background: none; border: 0; padding: 0; color: inherit; font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; }

.site-footer { color: var(--muted); font-size: 0.8rem; text-align: center; }
.site-footer .container { padding-top: 4px; padding-bottom: 20px; }

.chart-box { position: relative; height: 260px; }
