:root {
  --navy: #0f1b2d; --navy-2: #1a2a42; --red: #d63f3f; --red-dark: #b83232;
  --bg: #f3f5f8; --card: #fff; --text: #142033; --muted: #66748a; --line: #e2e7ee;
  --green: #1f9d63; --green-bg: #e7f6ee; --amber: #b7791f; --amber-bg: #fdf4e3;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }

.topbar { position: sticky; top: 0; z-index: 5; background: var(--navy); color: #fff;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px; display: flex; align-items: center; gap: 12px; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .back { background: none; border: 0; color: #fff; font-size: 26px; padding: 0 6px 0 0; line-height: 1; }
.topbar .sub { font-size: 12px; opacity: .7; font-weight: 400; display: block; }
.brand-dot { width: 10px; height: 10px; border-radius: 3px; background: var(--red); display: inline-block; margin-right: 8px; }

.page { padding: 16px; padding-bottom: calc(env(safe-area-inset-bottom) + 96px); max-width: 640px; margin: 0 auto; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
  box-shadow: 0 1px 2px rgba(15,27,45,.06); }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn { border: 0; border-radius: 12px; padding: 14px 18px; font-weight: 600; background: var(--navy); color: #fff;
  width: 100%; display: block; text-align: center; text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn.red { background: var(--red); }
.btn.ghost { background: transparent; color: var(--navy); border: 1.5px solid var(--line); }
.btn.small { padding: 8px 12px; width: auto; display: inline-block; font-size: 14px; border-radius: 10px; }
.btn[disabled] { opacity: .5; }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }

.scan-hero { background: linear-gradient(135deg, var(--navy), var(--navy-2)); color: #fff; border-radius: 20px;
  padding: 22px 18px; margin-bottom: 14px; }
.scan-hero .conf { font-size: 13px; opacity: .75; }
.scan-hero select { background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.2); color: #fff;
  border-radius: 10px; padding: 8px 10px; width: 100%; margin: 6px 0 16px; }
.scan-hero select option { color: #000; }
.big-scan { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 20px; padding: 20px;
  background: var(--red); border-radius: 16px; color: #fff; border: 0; width: 100%; font-weight: 700;
  box-shadow: 0 6px 18px rgba(214,63,63,.35); }

label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=search], textarea, select.input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 10px; padding: 12px; background: #fff; outline: none; }
input:focus, textarea:focus { border-color: var(--navy); }
textarea { min-height: 96px; resize: vertical; }

.list-item { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line);
  text-decoration: none; }
.list-item:last-child { border-bottom: 0; }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--navy-2); color: #fff; display: flex;
  align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; object-fit: cover; font-size: 16px; }
.avatar.xl { width: 96px; height: 96px; font-size: 32px; }
.pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 99px;
  background: var(--line); color: var(--text); white-space: nowrap; }
.pill.green { background: var(--green-bg); color: var(--green); }
.pill.red { background: #fde8e8; color: var(--red-dark); }
.pill.blue { background: #e6f0fb; color: #2463a6; }
.pill.amber { background: var(--amber-bg); color: var(--amber); }

.banner { border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.banner.green { background: var(--green-bg); border: 1.5px solid #bfe6d1; }
.banner.amber { background: var(--amber-bg); border: 1.5px solid #f3dcb0; }
.banner.blue { background: #e9eef7; border: 1.5px solid #cfd9ea; }
.banner strong { display: block; font-size: 17px; margin-bottom: 2px; }

.note { padding: 12px 0; border-bottom: 1px solid var(--line); }
.note:last-child { border-bottom: 0; }
.note .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.note .body { white-space: pre-wrap; }
.note .del { margin-left: auto; background: none; border: 0; color: var(--muted); font-size: 12px; }

.profile-head { text-align: center; padding: 8px 0 4px; }
.profile-head .avatar { margin: 0 auto 10px; }
.profile-head h2 { font-size: 22px; text-transform: none; letter-spacing: 0; color: var(--text); margin: 0; }
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 6px 10px; font-size: 14px; }
.kv div:nth-child(odd) { color: var(--muted); }
.kv div:nth-child(even) { word-break: break-word; }

/* scanner */
.scanner { position: fixed; inset: 0; background: #000; z-index: 20; display: flex; flex-direction: column; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner .frame { position: absolute; left: 50%; top: 42%; width: 68vmin; height: 68vmin; transform: translate(-50%,-50%);
  border-radius: 22px; box-shadow: 0 0 0 9999px rgba(0,0,0,.5); }
.scanner .frame::before, .scanner .frame::after { content: ""; position: absolute; inset: -3px; border-radius: 24px;
  border: 4px solid transparent; border-top-color: var(--red); border-bottom-color: var(--red); }
.scanner .laser { position: absolute; left: 8%; right: 8%; height: 2px; background: var(--red); top: 50%;
  box-shadow: 0 0 12px var(--red); animation: laser 1.8s ease-in-out infinite; }
@keyframes laser { 0%,100% { top: 10%; } 50% { top: 90%; } }
.scanner .msg { position: absolute; top: calc(env(safe-area-inset-top) + 18px); left: 16px; right: 16px; color: #fff;
  text-align: center; font-weight: 600; text-shadow: 0 1px 3px #000; }
.scanner .controls { position: absolute; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 20px);
  display: grid; gap: 10px; }
.scanner .controls .btn.ghost { color: #fff; border-color: rgba(255,255,255,.4); background: rgba(0,0,0,.35); }
.scanner.no-cam { background: var(--navy); }

.fab { position: fixed; right: 18px; bottom: calc(env(safe-area-inset-bottom) + 18px); width: 64px; height: 64px;
  border-radius: 50%; background: var(--red); color: #fff; border: 0; font-size: 26px; z-index: 6;
  box-shadow: 0 8px 20px rgba(214,63,63,.4); display: flex; align-items: center; justify-content: center; }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 96px); transform: translateX(-50%) translateY(20px);
  background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .2s;
  z-index: 50; pointer-events: none; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); }

.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px;
  background: var(--navy); color: #fff; }
.login .logo { font-size: 28px; font-weight: 800; margin-bottom: 4px; display: flex; align-items: center; gap: 10px; }
.login .card { color: var(--text); margin-top: 24px; }
.demo-creds { font-size: 13px; background: #f6f8fb; border-radius: 10px; padding: 10px 12px; margin-top: 12px; }
.demo-creds button { background: none; border: 0; color: var(--red); font-weight: 700; padding: 2px 0; }
.empty { text-align: center; color: var(--muted); padding: 22px 8px; }
.raw { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: #f6f8fb; padding: 10px; border-radius: 8px;
  white-space: pre-wrap; word-break: break-all; max-height: 160px; overflow: auto; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button { flex: 1; border: 0; background: var(--card); padding: 10px; border-radius: 10px; font-weight: 600; color: var(--muted); }
.tabs button.on { background: var(--navy); color: #fff; }
.badge-img { width: 100%; max-height: 320px; object-fit: contain; border-radius: 10px; background: #f6f8fb; display: block; }
.badge-thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; display: block; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.action { border: 0; border-radius: 16px; padding: 16px 12px; background: rgba(255,255,255,.1); color: #fff; text-align: left;
  display: flex; flex-direction: column; gap: 4px; cursor: pointer; border: 1px solid rgba(255,255,255,.18); }
.action b { font-size: 17px; margin-top: 4px; }
.action span { font-size: 12px; opacity: .75; }
.action.red { background: var(--red); border-color: var(--red); grid-column: 1 / -1; box-shadow: 0 6px 18px rgba(214,63,63,.35); }
.action:active { transform: scale(.98); }
.reading { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: var(--navy); color: #fff; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid rgba(255,255,255,.2); border-top-color: var(--red);
  animation: spin .8s linear infinite; margin-bottom: 10px; }
@keyframes spin { to { transform: rotate(360deg); } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1.5px solid var(--line); background: #f6f8fb; border-radius: 99px; padding: 7px 12px; font-size: 14px; }
.chip:active { background: var(--navy); color: #fff; }
input.flash { border-color: var(--green); background: var(--green-bg); transition: none; }
.list-item .badge-thumb { width: 48px; height: 48px; }
.scanner .frame.badge-frame { width: 72vmin; height: 96vmin; max-height: 62vh; max-width: 46.5vh; top: 44%; }
.shutter { width: 76px; height: 76px; border-radius: 50%; background: #fff; border: 6px solid rgba(255,255,255,.45);
  background-clip: padding-box; justify-self: center; box-shadow: 0 0 0 3px var(--red); }
.shutter:active { transform: scale(.94); background: #eee; }
.sec { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 6px 0 8px; }
.conf-pick { display: flex; flex-direction: column; align-items: flex-start; width: 100%; text-align: left; background: var(--card);
  border: 2px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-bottom: 10px; gap: 2px; }
.conf-pick b { font-size: 17px; } .conf-pick span { color: var(--muted); font-size: 14px; }
.conf-pick.on { border-color: var(--red); }
.pm-card { display: flex; gap: 12px; align-items: center; background: linear-gradient(135deg, #fff4d6, #ffe7a3); border: 2px solid #f3c969;
  border-radius: 14px; padding: 14px 16px; margin-bottom: 14px; text-decoration: none; color: #5c4300; }
.pm-alert { background: linear-gradient(135deg, #ffcf4a, #ff9d2e); color: #3a2200; border-radius: 16px; padding: 18px 16px; margin-bottom: 14px;
  box-shadow: 0 8px 24px rgba(255,157,46,.45); animation: pmpulse 1.2s ease-in-out 3; }
.pm-title { font-size: 26px; font-weight: 900; letter-spacing: .04em; }
.pm-sub { font-weight: 600; margin-top: 2px; }
.pm-contact { margin-top: 10px; background: rgba(255,255,255,.55); border-radius: 10px; padding: 10px 12px; font-size: 16px; }
.pm-notes { margin-top: 10px; white-space: pre-wrap; font-size: 15px; }
@keyframes pmpulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.02); } }
.target-row { color: inherit; }
.btn.agenda { background: var(--card); color: var(--navy); border: 1.5px solid var(--navy); margin-bottom: 10px; }
