:root {
  --green: #0b6e4f;
  --green-dark: #08533c;
  --green-light: #e6f4ee;
  --ink: #1b2a24;
  --muted: #6b7d74;
  --line: #dfe8e3;
  --bg: #f2f6f4;
  --white: #ffffff;
  --danger: #b3261e;
  --warn: #8a6d00;
  --ok: #146c1c;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 40, 30, 0.08), 0 8px 24px rgba(20, 40, 30, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.empty { text-align: center; padding: 16px 0; }

.screen { min-height: 100vh; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 15px; font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--green-light); }
.btn.small { padding: 7px 11px; font-size: 13px; }
.btn.scan { background: var(--green-light); border-color: var(--green); color: var(--green-dark); }
.btn.wide { width: 100%; }
.btn.shutting { background: #eef1f0; color: var(--muted); }

/* ---------- cards ---------- */
.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 14px; font-size: 18px; }
.card h3 { margin: 20px 0 10px; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }

/* ---------- login ---------- */
.login-card { max-width: 380px; margin: 6vh auto; padding: 28px; }
.brand { text-align: center; margin-bottom: 22px; }
.brand h1 { font-size: 22px; margin: 10px 0 2px; }
.brand-mark {
  display: inline-block; background: var(--green); color: #fff;
  font-weight: 800; border-radius: 10px; padding: 6px 12px; letter-spacing: .02em;
}
.brand-mark.small { padding: 3px 8px; font-size: 13px; border-radius: 7px; }

#login-form label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 14px; }
#login-form input { margin-top: 6px; }
#login-form .btn { width: 100%; margin-top: 6px; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--white); border-bottom: 1px solid var(--line);
  padding: 12px 18px; position: sticky; top: 0; z-index: 20;
}
.brand-inline { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 10px; font-size: 14px; }

.pill {
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: #eef1f0; color: var(--muted);
}
.pill[data-state="synced"] { background: var(--green-light); color: var(--ok); }
.pill[data-state="syncing"] { background: #fff4d6; color: var(--warn); }
.pill[data-state="error"] { background: #fbe9e7; color: var(--danger); }
.pill[data-state="offline"] { background: #fbe9e7; color: var(--danger); }

.content { max-width: 680px; margin: 0 auto; padding: 16px; }

/* ---------- forms ---------- */
input[type="text"], input[type="password"], input[type="date"], select {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 16px; background: var(--white); color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--green-light); border-color: var(--green); }
label { font-weight: 600; font-size: 14px; }

.scan-row { margin-bottom: 14px; }
.scan-row > label { display: block; margin-bottom: 6px; }
.field-with-actions { display: flex; gap: 8px; }
.field-with-actions input { flex: 1; min-width: 0; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.form-grid label { display: block; }
.form-grid input { margin-top: 6px; }
.select { margin-top: 6px; margin-bottom: 4px; }

.error { color: var(--danger); font-size: 14px; margin-top: 10px; min-height: 20px; }

/* ---------- photos ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.photo-slot { border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: center; }
.photo-label { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.photo-preview {
  width: 100%; aspect-ratio: 4/3; background: #eef1f0; border-radius: 8px;
  background-size: cover; background-position: center; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px;
}
.photo-actions { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }

/* ---------- history ---------- */
.history-head { display: flex; align-items: center; justify-content: space-between; }
.history-list { list-style: none; margin: 0; padding: 0; }
.history-list li {
  border-top: 1px solid var(--line); padding: 12px 0; display: flex; gap: 12px; align-items: flex-start;
}
.history-list li:first-child { border-top: none; }
.history-main { flex: 1; min-width: 0; }
.history-main .strong { font-weight: 700; }
.history-meta { font-size: 13px; color: var(--muted); }
.badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge.synced { background: var(--green-light); color: var(--ok); }
.badge.pending { background: #fff4d6; color: var(--warn); }
.badge.failed { background: #fbe9e7; color: var(--danger); }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; background: #0c1512f2; z-index: 50;
  display: flex; align-items: stretch; justify-content: center; padding: 0;
}
.overlay-inner {
  width: 100%; max-width: 560px; background: var(--bg); display: flex; flex-direction: column;
  padding: 16px; gap: 12px; overflow-y: auto;
}
.overlay-head { display: flex; align-items: center; justify-content: space-between; }
.overlay-head h2 { margin: 0; font-size: 18px; }
.controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.ctrl { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.ctrl select { width: auto; padding: 8px; }
.ctrl input[type="range"] { width: 120px; }

.video-wrap { position: relative; border-radius: 12px; overflow: hidden; background: #000; }
.video-wrap video { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
.scan-box {
  position: absolute; left: 50%; top: 50%; width: 62%; height: 34%;
  transform: translate(-50%, -50%);
  border: 2px solid var(--green); border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.35);
}
.scanner-result { font-size: 14px; min-height: 20px; text-align: center; }
.scan-manual { display: flex; gap: 8px; }
.scan-manual input { flex: 1; }
.overlay-actions { margin-top: auto; }

@media (max-width: 420px) {
  .form-grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
}