:root {
  --brand: #0277bd;
  --brand-dark: #01579b;
  --ink: #1c2320;
  --muted: #6b7772;
  --bg: #f3f5f4;
  --card: #ffffff;
  --line: #dfe4e1;
  --danger: #c0392b;
  --ok: #1f8a4c;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--brand); color: #fff;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.status { display: flex; gap: 6px; align-items: center; }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: rgba(255,255,255,.2); }
.pill.online { background: #1f8a4c; }
.pill.offline { background: #b0453a; }
.pill.muted { background: rgba(255,255,255,.18); }

.view { padding: 16px; max-width: 640px; margin: 0 auto; }
/* !important because later single-class rules (.backdrop, .grid3) also set
   display and would otherwise win on equal specificity, leaving every dialog
   on screen at load — the fullscreen camera among them */
.hidden { display: none !important; }
h1 { font-size: 22px; margin: 8px 0 14px; }
h2 { font-size: 16px; margin: 0; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
input, select, textarea {
  width: 100%; font-size: 17px; color: var(--ink);
  padding: 12px; margin-top: 4px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 8px; }
.photo input { padding: 10px; }
label.nomb { margin-bottom: 0; }
.mb { margin-bottom: 12px; }

/* a measured value: input + unit selector + camera on one line */
.field { margin-bottom: 12px; }
.field > label { margin-bottom: 2px; }
.withunit { display: flex; align-items: stretch; gap: 6px; }
.withunit input { flex: 1 1 auto; min-width: 0; margin-top: 0; }
select.unit { flex: 0 0 auto; width: 86px; margin-top: 0; padding: 12px 4px; font-size: 15px; }
input.bad { border-color: var(--danger); }
.msg.small { font-size: 12px; }

button.cam {
  flex: 0 0 auto; width: 48px; font-size: 20px; padding: 0;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
}
button.wide { width: 100%; margin-bottom: 12px; }
button.auto { width: auto; }
.row.end { justify-content: flex-end; }

/* segmented choice (dynamic level vs suction gauge) */
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1 1 0; background: #fff; color: var(--muted); font-size: 14px; border-radius: 0; }
.seg button.on { background: var(--brand); color: #fff; }

.switch { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--ink); }
.switch input { width: 22px; height: 22px; margin-top: 0; flex: 0 0 auto; }

h2.sec {
  font-size: 13px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin: 22px 0 10px; padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.thumb { position: relative; width: 74px; height: 74px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.thumb .del {
  position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; padding: 0;
  font-size: 12px; line-height: 1; border-radius: 999px; background: var(--danger); color: #fff;
}

.backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.dialog {
  background: var(--card); border-radius: 14px; padding: 18px;
  width: 100%; max-width: 360px; max-height: 88vh; overflow-y: auto;
}
.dialog h2 { margin-bottom: 12px; }

/* collapsible sections keep the long create forms navigable on a phone */
.dialog details { border-top: 1px solid var(--line); padding: 10px 0 2px; }
.dialog details:first-of-type { border-top: none; }
.dialog summary {
  font-size: 13px; font-weight: 600; color: var(--brand);
  cursor: pointer; padding: 4px 0 10px; list-style: none;
}
.dialog summary::-webkit-details-marker { display: none; }
.dialog summary::before { content: '▸ '; }
.dialog details[open] > summary::before { content: '▾ '; }
.dialog select[multiple] { padding: 6px; }

/* entity pickers: select + "create new" */
.pick { display: flex; gap: 6px; }
.pick select { flex: 1 1 auto; min-width: 0; margin-top: 0; }
button.add {
  flex: 0 0 auto; width: 48px; padding: 0; font-size: 22px; line-height: 1;
  background: var(--brand); color: #fff;
}

/* in-app camera */
.cam-full { padding: 0; background: #000; }
.camwrap { position: relative; width: 100%; height: 100%; display: flex;
           align-items: center; justify-content: center; }
#cam-video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.cambar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 18px 22px calc(18px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.6));
}
.shutter {
  width: 72px; height: 72px; border-radius: 999px; padding: 0;
  background: #fff; border: 5px solid rgba(255,255,255,.45);
}
.shutter:active { background: #ddd; }
.camcount {
  position: absolute; top: calc(14px + env(safe-area-inset-top)); left: 0; right: 0;
  text-align: center; color: #fff; font-size: 14px; margin: 0;
  text-shadow: 0 1px 3px rgba(0,0,0,.7);
}

button {
  font-size: 16px; border: none; border-radius: 10px; padding: 12px 16px;
  cursor: pointer; font-weight: 600;
}
button.primary { background: var(--brand); color: #fff; width: 100%; }
button.primary:active { background: var(--brand-dark); }
button.big { padding: 16px; font-size: 18px; }
button.ghost { background: #fff; border: 1px solid var(--line); color: var(--ink); }
button.link { background: none; color: #fff; padding: 4px 8px; font-weight: 500; }

.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; }
.row.gap { gap: 12px; }
.mt { margin-top: 18px; }
.small { font-size: 12px; }
.muted { color: var(--muted); }
.msg { min-height: 18px; font-size: 14px; }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--danger); }

.list { list-style: none; padding: 0; margin: 10px 0 40px; }
.list li {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 8px; font-size: 14px;
  display: flex; justify-content: space-between; align-items: center;
}
.list .tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.tag.pending { background: #fdeecb; color: #8a5b00; }
.tag.synced { background: #d8f0e0; color: #1f8a4c; }

button.add.edit { background: #fff; border: 1px solid var(--line); color: var(--brand); font-size: 18px; }
.brand .logo { height: 26px; width: auto; display: block; filter: brightness(0) invert(1); }

/* searchable catalog picker: a text box with a filtered list under it */
.combo { position: relative; }
.combo input { margin-top: 0; }
.options {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 20;
  margin: 4px 0 0; padding: 0; list-style: none; max-height: 210px; overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.options li { padding: 11px 12px; font-size: 15px; border-bottom: 1px solid var(--line); cursor: pointer; }
.options li:last-child { border-bottom: none; }
.options li:active { background: #e8f2f8; }
.options li.empty { color: var(--muted); cursor: default; }

/* language toggle in the top bar */
.lang { display: flex; border: 1px solid rgba(255,255,255,.45); border-radius: 999px; overflow: hidden; }
.lang button {
  background: transparent; color: #fff; font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 0; line-height: 1.4;
}
.lang button.on { background: #fff; color: var(--brand); }

/* station map */
.map { height: 200px; border-radius: 10px; border: 1px solid var(--line); margin-top: 4px; background: #eef2f4; }
.map.dead { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.leaflet-container { font: inherit; }

/* files already on the server, listed next to the new ones */
.existing { margin-top: 8px; }
.existing .head { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.existing .files { display: flex; flex-wrap: wrap; gap: 8px; }
.existing .file {
  display: flex; align-items: center; gap: 6px; max-width: 100%;
  background: #f6f8f9; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 13px;
}
.existing .file a { color: var(--brand); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.existing .file button { background: none; padding: 2px 4px; font-size: 13px; color: var(--danger); }
button.pickfile {
  flex: 0 0 auto; width: 48px; font-size: 20px; padding: 0;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
}
