:root {
  --red: #B91C1C; --red-dark: #991B1B; --red-soft: #FDECEC; --ink: #1F2937; --muted: #6B7280;
  --line: #E5E7EB; --bg: #F3F4F6; --card: #fff; --green: #15803D; --amber: #B45309; --blue: #1D4ED8;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  --tap: 50px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  background: var(--red); color: #fff; padding: calc(var(--sat) + 8px) calc(var(--sar) + 14px) 10px calc(var(--sal) + 14px);
  min-height: calc(var(--sat) + 56px); box-shadow: 0 1px 0 rgba(0,0,0,.15); }
.brand { display: flex; align-items: baseline; gap: 10px; flex: 1; min-width: 0; }
.logo { font-weight: 800; font-size: 24px; letter-spacing: .5px; }
#title { font-weight: 600; font-size: 17px; opacity: .95; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#savestate { font-size: 13px; opacity: .85; }
.icon-btn { background: none; border: 0; color: #fff; font-size: 34px; line-height: 1; width: 40px; height: 40px; padding: 0 0 4px; margin-left: -8px; }

#view { padding: 12px calc(var(--sar) + 12px) calc(var(--sab) + 96px) calc(var(--sal) + 12px); outline: none; max-width: 720px; margin: 0 auto; }

#tabbar, #actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: rgba(255,255,255,.97);
  border-top: 1px solid var(--line); padding: 6px calc(var(--sar) + 8px) calc(var(--sab) + 6px) calc(var(--sal) + 8px);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
#tabbar { display: flex; }
#tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; min-height: 50px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600; }
#tabbar a .ti { font-size: 22px; line-height: 1; }
#tabbar a.on { color: var(--red); }
#actionbar { display: flex; align-items: center; gap: 8px; }
#actionbar .tot { flex: 1; min-width: 0; }
#actionbar .tot small { display: block; color: var(--muted); font-size: 12px; }
#actionbar .tot b { font-size: 21px; }
#actionbar .btn { min-height: 48px; padding: 0 14px; font-size: 16px; }

.card { background: var(--card); border-radius: 14px; padding: 14px; margin: 0 0 12px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.card h2 { margin: 0 0 10px; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--red); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.right { text-align: right; }

label.f { display: block; margin: 0 0 10px; }
label.f > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 4px; }
input[type=text], input[type=tel], input[type=email], input[type=url], input[type=date], input[type=password], input[type=search], select, textarea {
  width: 100%; min-height: var(--tap); border: 1px solid #D1D5DB; border-radius: 10px; background: #fff; padding: 10px 12px; font-size: 17px;
  -webkit-appearance: none; appearance: none; }
input[type=date] { display: block; }
select { background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236B7280' stroke-width='2' fill='none'/%3E%3C/svg%3E") no-repeat right 12px center; padding-right: 32px; }
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(185,28,28,.35); border-color: var(--red); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); padding: 0 18px; border-radius: 12px;
  border: 1px solid #D1D5DB; background: #fff; font-weight: 600; font-size: 17px; text-decoration: none; color: var(--ink); cursor: pointer; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: #FCA5A5; }
.btn.block { display: flex; width: 100%; margin: 0 0 10px; }
.btn.sm { min-height: 40px; padding: 0 12px; font-size: 15px; }
.btn[disabled] { opacity: .5; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btns .btn { flex: 1 1 auto; }

.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; letter-spacing: .02em; }
.pill.Draft { background: #E5E7EB; color: #374151; }
.pill.Sent { background: #DBEAFE; color: var(--blue); }
.pill.Paid { background: #DCFCE7; color: var(--green); }

.summary { display: flex; gap: 10px; }
.summary .card { flex: 1; margin-bottom: 12px; }
.summary .k { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.summary .v { font-size: 26px; font-weight: 800; }
.summary .v.red { color: var(--red); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; }
.chip { flex: none; min-height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid #D1D5DB; background: #fff; font-weight: 600; font-size: 15px; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.search { margin-bottom: 10px; }

.inv-item { display: block; background: #fff; border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; text-decoration: none; color: inherit;
  box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.inv-item .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.inv-item .no { font-weight: 700; font-size: 16px; }
.inv-item .cust { font-weight: 600; margin-top: 2px; }
.inv-item .meta { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; color: var(--muted); font-size: 14px; margin-top: 2px; }
.inv-item .meta > span:first-child { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inv-item .amt { font-weight: 800; color: var(--ink); font-size: 17px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

.fab { position: fixed; right: calc(var(--sar) + 16px); bottom: calc(var(--sab) + 78px); z-index: 21; min-height: 56px; padding: 0 22px; border-radius: 999px;
  background: var(--red); color: #fff; border: 0; font-weight: 700; font-size: 17px; box-shadow: 0 6px 16px rgba(185,28,28,.35); }

.invno { font-size: 22px; font-weight: 800; letter-spacing: .01em; }
.line { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; background: #FAFAFA; }
.line .lhead { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.line .lhead select { flex: 1; min-height: 44px; font-weight: 700; }
.line .amt { font-weight: 800; font-size: 18px; min-width: 90px; text-align: right; }
.line .del { width: 44px; height: 44px; border-radius: 10px; border: 1px solid #FCA5A5; background: #fff; color: var(--red); font-size: 22px; flex: none; }
.line .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.line .grid.three { grid-template-columns: 1fr 1fr 1fr; }
.line label.f { margin-bottom: 6px; }
.line .hint { font-size: 13px; color: var(--muted); }
.addlines { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.addlines .btn { font-size: 16px; padding: 0 8px; }

.totals .tr { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; }
.totals .tr.total { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 10px; font-size: 22px; font-weight: 800; }
.switch { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.switch input { width: 26px; height: 26px; accent-color: var(--red); }

.dates .d { display: flex; gap: 8px; margin-bottom: 8px; }
.dates .d input { flex: 1; }
.dates .d button { width: 50px; flex: none; }

.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.photos .ph { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #eee; }
.photos .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos .ph button { position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 18px; }
.filebtn { position: relative; overflow: hidden; }
.filebtn input { position: absolute; inset: 0; opacity: 0; font-size: 100px; }

.linkbox { background: var(--red-soft); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; word-break: break-all; }
.warn { background: #FEF3C7; color: #78350F; border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; font-size: 15px; }
.okbox { background: #DCFCE7; color: #14532D; border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; font-size: 15px; }
.note { font-size: 13px; color: var(--muted); margin: -2px 0 10px; }

/* sheets / overlays */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(17,24,39,.5); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: #fff; width: 100%; max-width: 720px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0;
  padding: 16px calc(var(--sar) + 16px) calc(var(--sab) + 16px) calc(var(--sal) + 16px); -webkit-overflow-scrolling: touch; }
.sheet h3 { margin: 0 0 12px; font-size: 20px; }
.qr-full { position: fixed; inset: 0; z-index: 60; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(var(--sat) + 12px) calc(var(--sar) + 16px) calc(var(--sab) + 16px) calc(var(--sal) + 16px); text-align: center; }
.qr-full .lg { font-weight: 800; font-size: 30px; color: var(--red); margin: 0; }
.qr-full .amt { font-size: 40px; font-weight: 800; margin: 2px 0 0; }
.qr-full .sub { color: var(--muted); font-size: 16px; margin: 0 0 12px; }
.qr-full canvas { display: block; margin: 6px auto 10px; image-rendering: pixelated; }
.qr-full .cap { font-weight: 700; font-size: 18px; margin: 0 0 4px; }
.qr-full .url { font-size: 15px; color: var(--muted); margin: 0 0 16px; word-break: break-all; }
.qr-full .btns { width: 100%; max-width: 420px; }
.qr-full .paidbanner { background: var(--green); color: #fff; font-size: 28px; font-weight: 800; padding: 12px 20px; border-radius: 14px; margin-bottom: 10px; }

#toast { position: fixed; left: 50%; top: calc(var(--sat) + 66px); transform: translateX(-50%) translateY(-12px); opacity: 0; pointer-events: none;
  background: rgba(17,24,39,.94); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 15px; z-index: 80; max-width: 90vw; transition: all .2s; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.custlist .ci { display: block; background: #fff; border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.06); width: 100%; text-align: left; border: 0; }
.custlist .ci b { display: block; font-size: 17px; }
.billto { background: #F9FAFB; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 15px; margin: 8px 0 10px; white-space: pre-line; }

.list-bottom { margin: 14px 0 84px; }

/* ---- scan material invoice (v1.1) ---- */
.red { color: var(--red); }
.green { color: var(--green); }
.badbox { background: #FEE2E2; color: #991B1B; border: 2px solid #DC2626; border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; font-size: 15px; }
.spinner.dark { border-color: rgba(0,0,0,.15); border-top-color: var(--red); vertical-align: -3px; margin-right: 6px; }
.scan-full { position: fixed; inset: 0; z-index: 55; background: var(--bg, #F3F4F6); display: flex; flex-direction: column; }
.scan-top { display: flex; align-items: center; gap: 10px; background: var(--red); color: #fff; padding: calc(var(--sat, 0px) + 8px) 14px 8px; font-size: 18px; }
.scan-top .icon-btn { margin-left: 0; }
.scan-body { flex: 1; overflow: auto; padding: 12px 12px 20px; -webkit-overflow-scrolling: touch; }
.scan-bar { display: flex; gap: 10px; padding: 10px 12px calc(var(--sab, 0px) + 10px); background: #fff; border-top: 1px solid var(--line); }
.scan-bar .btn { flex: 1; }
.scan-bar .btn.primary { flex: 2; }
.thumb { width: 64px; height: 84px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); flex: none !important; }
.thumbs { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 4px 0; }
.sline { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; background: #FAFAFA; }
.sline.bad { border: 2px solid #F59E0B; background: #FFFBEB; }
.sline.off { opacity: .5; }
.sline .grid.three { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.sline label.f { margin-bottom: 6px; }
.sline .calc { min-height: 44px; display: flex; align-items: center; font-weight: 800; font-size: 18px; }
.sinc { min-height: 36px; font-weight: 600; }
.flags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.flag { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: #E5E7EB; color: #374151; }
.flag.red { background: #FEE2E2; color: #991B1B; }
.zoom { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.92); display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; overflow: auto; }
.zoom img { max-width: 100%; max-height: 90vh; }
.batch { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; background: #FAFAFA; }
.batch .bh { margin-bottom: 2px; }
/* v1.2 — sign-in, time clock, admin */
body.locked #tabbar, body.locked #actionbar, body.locked #view, body.locked #topbar { visibility: hidden; }
#login { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: flex; align-items: flex-start; justify-content: center; overflow: auto;
  padding: calc(env(safe-area-inset-top) + 28px) 18px calc(env(safe-area-inset-bottom) + 18px); }
.login-box { width: 100%; max-width: 360px; text-align: center; }
.login-box h1 { margin: 10px 0 2px; font-size: 26px; }
.login-logo { display: inline-block; background: var(--red); color: #fff; font-weight: 800; font-size: 26px; letter-spacing: 1px; padding: 8px 16px; border-radius: 12px; }
.login-msg { min-height: 22px; margin: 6px 0 10px; font-weight: 600; }
.pin-input { width: 100%; box-sizing: border-box; text-align: center; font-size: 30px; letter-spacing: 8px; padding: 10px; margin: 12px 0 10px; border: 2px solid #D1D5DB; border-radius: 14px; background: #fff; }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 8px; }
.pk { min-height: 58px; font-size: 26px; font-weight: 600; border-radius: 14px; border: 1px solid #D1D5DB; background: #fff; color: var(--ink); }
.pk.fn { font-size: 17px; background: #F3F4F6; }
.pk:active { background: #E5E7EB; }
.pin-sheet { text-align: center; }
.pin-sheet .btns { justify-content: stretch; } .pin-sheet .btns .btn { flex: 1; }
.whochip { margin-left: 8px; border: 1px solid rgba(255,255,255,.5); background: transparent; color: inherit; border-radius: 999px; padding: 4px 10px; font-size: 13px; white-space: nowrap; }
#tabbar a { font-size: 12px; }
.clockcard .k { font-size: 14px; color: var(--muted, #6B7280); }
.clockstate { font-size: 28px; font-weight: 800; margin: 2px 0 4px; }
.clockcard.state-in .clockstate { color: var(--green); } .clockcard.state-break .clockstate { color: #B45309; }
.clockbtns { display: flex; gap: 10px; margin: 12px 0 6px; } .clockbtns .btn { flex: 1; }
.btn.big { min-height: 64px; font-size: 21px; font-weight: 800; }
.weektot { display: flex; gap: 8px; margin: 8px 0; } .weektot > div { flex: 1; background: #F9FAFB; border-radius: 10px; padding: 6px 8px; }
.weektot small { display: block; font-size: 12px; color: #6B7280; } .weektot b { font-size: 19px; }
table.days { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 15px; } table.days td { padding: 5px 2px; border-top: 1px solid #F3F4F6; } td.r { text-align: right; font-variant-numeric: tabular-nums; }
.shift, .punchrow, .auditrow { border-top: 1px solid #F3F4F6; padding: 8px 0; }
.shift .top, .personcard .top, .userrow .top, [data-job] .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.personcard { display: block; color: inherit; text-decoration: none; }
.admintabs .chip { text-decoration: none; color: inherit; display: inline-flex; align-items: center; }
.admintabs .chip.on { color: #fff; }
.bigpin { font-size: 44px; font-weight: 800; letter-spacing: 8px; text-align: center; margin: 12px 0; font-variant-numeric: tabular-nums; }
.lbemp { display: block; margin: 8px 0; } .lbemp .small { display: block; margin-left: 28px; }
.green { color: var(--green); }
.row .btn.wknav { flex: none; width: 48px; min-width: 48px; font-size: 22px; }
.syncchip { margin-left: auto; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: rgba(255,255,255,.18); white-space: nowrap; }
.syncchip.wait { background: #FEF3C7; color: #78350F; } .syncchip.ok { background: rgba(255,255,255,.18); }
#savestate { margin-left: 6px; }
