/* Machines System — dark, mobile first. */

:root {
  --bg: #0f1216;
  --surface: #181d24;
  --surface-2: #202834;
  --border: #2a323e;
  --text: #e6eaf0;
  --muted: #8b95a5;
  --accent: #4c8dff;
  --accent-ink: #ffffff;
  --ok: #35c07f;
  --danger: #ff5c5c;
  --radius: 12px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

h1 { font-size: 1.4rem; margin: 0 0 .6rem; }
h2 { font-size: 1.1rem; margin: 1.6rem 0 .6rem; }

a { color: var(--accent); text-decoration: none; }

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 14px 40px;
}

/* --- top bar --------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: rgba(15, 18, 22, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand { color: var(--text); font-weight: 700; letter-spacing: .3px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-right form { margin: 0; }
.who { color: var(--muted); font-size: .85rem; }

/* --- cards and text -------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin: 0 0 12px;
}

.centre { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.empty { color: var(--muted); text-align: center; }
.back { display: inline-block; padding: 6px 0; font-size: .95rem; }

.flash {
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 0 0 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.flash.ok { border-color: rgba(53, 192, 127, .5); color: var(--ok); }
.flash.error { border-color: rgba(255, 92, 92, .5); color: var(--danger); }

/* --- forms ----------------------------------------------------------- */

label {
  display: block;
  margin: 12px 0 6px;
  font-size: .85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}
label:first-child { margin-top: 0; }

input, textarea, select {
  width: 100%;
  padding: 13px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px; /* keeps iOS from zooming on focus */
  font-family: inherit;
}

input:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

textarea { resize: vertical; }

.row { display: flex; gap: 10px; }
.row > div { flex: 1; min-width: 0; }
.row label { margin-top: 12px; }

.with-scan { display: flex; gap: 8px; align-items: stretch; }
.with-scan input { flex: 1; min-width: 0; }

/* --- buttons --------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 46px;
  padding: 11px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: .98rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: rgba(255, 92, 92, .45); color: var(--danger); }
.btn.block { display: flex; width: 100%; margin-top: 16px; }
.btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2;
           stroke-linecap: round; stroke-linejoin: round; }

.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font: inherit;
  font-size: .9rem;
  cursor: pointer;
}
.link.danger { color: var(--danger); }

.toolbar { display: flex; gap: 8px; margin: 0 0 14px; flex-wrap: wrap; }
.toolbar .btn { flex: 1; min-width: 140px; }

/* --- search ---------------------------------------------------------- */

.search { display: flex; gap: 8px; margin: 0 0 12px; }
.search input { flex: 1; min-width: 0; }
.btn.scan { white-space: nowrap; }

/* --- machine list ---------------------------------------------------- */

.cards { list-style: none; margin: 0; padding: 0; }

.machine { display: block; color: var(--text); }
.machine:active { border-color: var(--accent); }
.machine-head { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.machine-head strong { font-size: 1.05rem; }

.badge {
  flex: none;
  display: inline-block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: .72rem;
  color: var(--muted);
  white-space: nowrap;
}
.badges { flex: none; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.badge.done { border-color: rgba(53, 192, 127, .5); color: var(--ok); }
.badge.open { border-color: rgba(76, 141, 255, .55); color: var(--accent); }

/* --- top bar nav ------------------------------------------------------ */

.nav { display: flex; gap: 16px; margin-right: auto; margin-left: 18px; }
.nav a { color: var(--muted); font-size: .92rem; font-weight: 600; white-space: nowrap; }
.nav a:hover { color: var(--text); }

/* Brand + three links + username will not fit a narrow phone, so drop the
   least useful parts rather than letting the bar wrap or scroll. */
@media (max-width: 480px) {
  .topbar { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .nav { gap: 12px; margin-left: 12px; }
  .nav a { font-size: .85rem; }
  .who { display: none; }
}
@media (max-width: 380px) {
  .brand { display: none; }
}

/* --- checkbox --------------------------------------------------------- */

label.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 1rem;
  color: var(--text);
  cursor: pointer;
}
label.check input {
  width: 22px;
  height: 22px;
  flex: none;
  accent-color: var(--accent);
}

/* --- live scan list --------------------------------------------------- */

.scanned-row {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  padding: 10px 14px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.scanned-row .what { color: var(--muted); }

.serial {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: var(--accent);
  letter-spacing: .5px;
  margin-top: 2px;
}
.serial.big { font-size: 1.25rem; margin: 6px 0 12px; }

.client { color: var(--muted); font-size: .92rem; }

.meters {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: .82rem;
  color: var(--muted);
}
.meters b { color: var(--text); font-weight: 600; }

.totals { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.totals b { color: var(--text); }

/* --- machine detail -------------------------------------------------- */

.machine-title { margin-bottom: 0; }

.details { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; }
.details dt { color: var(--muted); font-size: .85rem; }
.details dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.note-form textarea { margin-bottom: 10px; }
.notes { list-style: none; margin: 0; padding: 0; }
.note-meta { color: var(--muted); font-size: .78rem; }
.note-text { margin: 4px 0 8px; white-space: pre-wrap; }
.danger-zone { margin-top: 32px; }

/* --- login ----------------------------------------------------------- */

.login { max-width: 380px; margin: 8vh auto 0; text-align: center; }
.login h1 { font-size: 1.8rem; margin-bottom: 0; }
.login p { margin-top: 4px; }
.login .card { margin-top: 24px; text-align: left; }

/* --- scanner overlay ------------------------------------------------- */

.scanner {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scanner[hidden] { display: none; }

.scanner video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Must line up with CROP_W / CROP_H in app.js: what you aim at is what
   actually gets decoded. */
.scanner-frame {
  position: absolute;
  left: 7%;
  right: 7%;
  height: 34%;
  border: 2px solid rgba(255, 255, 255, .9);
  border-radius: 12px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45);
  pointer-events: none;
}

.scanner-status {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  text-align: center;
  color: #fff;
  background: rgba(0, 0, 0, .55);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0;
  font-size: .9rem;
}

.scanner-actions {
  position: absolute;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: center;
  gap: 10px;
}
.scanner-actions .btn {
  min-width: 130px;
  background: rgba(255, 255, 255, .12);
  border-color: rgba(255, 255, 255, .35);
  color: #fff;
}
.scanner-actions .btn.on {
  background: rgba(255, 255, 255, .85);
  color: #111;
}
.scanner-actions .btn[hidden] { display: none; }

@media (min-width: 640px) {
  .toolbar .btn { flex: 0 1 auto; }
}
