:root {
  --primary: #1D5AA6; --primary-dark: #12355B; --tint: #E3ECF7;
  --text: #1B2A3A; --muted: #4A5D73; --border: #D9E0EA; --bg: #F2F5F9; --surface: #fff;
  --ok: #165443; --ok-bg: #DDF2E8; --warn: #7A3A05; --warn-bg: #FDEBD3; --bad: #8A1F12; --bad-bg: #FBE0DD;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 16px; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: var(--primary); color: #fff; }
.top img { border-radius: 8px; background: #fff; }
.top-name { font-weight: 700; font-size: 18px; }
.top-firm { border: 0; background: transparent; color: #d6e6f8; padding: 0; font-size: 13px; text-align: left; }

main { padding: 16px 16px calc(96px + var(--safe-b)); max-width: 640px; margin: 0 auto; }
h2 { font-size: 18px; margin: 0 0 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.light { background: rgba(255,255,255,.92); border: 0; color: var(--primary-dark); }
.btn.block { width: 100%; }
.btn.big { min-height: 120px; font-size: 20px; flex-direction: column; border-radius: 16px; }
.btn.big svg { width: 44px; height: 44px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.banner { border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; font-size: 14px; }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.info { background: var(--tint); color: var(--primary-dark); }
.banner .btn { margin-top: 10px; min-height: 40px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
.field input, .field select, .field textarea { min-height: 46px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font-size: 16px; }
.field textarea { padding: 10px 12px; min-height: 90px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 15px; }
.check input { width: 22px; height: 22px; }

.list { display: flex; flex-direction: column; }
.item { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.item:last-child { border-bottom: 0; }
.item .main { flex: 1; min-width: 0; }
.item .t { font-weight: 600; }
.item .s { font-size: 13px; color: var(--muted); }
.item .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; display: inline-block; }
.tag.sent { background: var(--ok-bg); color: var(--ok); }
.tag.wait { background: var(--warn-bg); color: var(--warn); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.chip { flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 8px 14px; font-size: 14px; }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.stat { display: flex; justify-content: space-between; align-items: baseline; }
.stat .n { font-size: 28px; font-weight: 700; color: var(--primary); }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; background: var(--surface); border-top: 1px solid var(--border); padding-bottom: var(--safe-b); }
.tabs button { flex: 1; border: 0; background: none; padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11.5px; color: var(--muted); }
.tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--primary); font-weight: 600; }

.camera { position: fixed; inset: 0; z-index: 20; background: #000; display: flex; flex-direction: column; }
.camera video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.frame { position: absolute; left: 50%; top: 42%; width: min(70vw, 300px); aspect-ratio: 1; transform: translate(-50%, -50%); border: 3px solid #fff; border-radius: 18px; box-shadow: 0 0 0 9999px rgba(0,0,0,.45); }
.camera-txt { position: absolute; left: 16px; right: 16px; top: calc(16px + env(safe-area-inset-top, 0px)); color: #fff; text-align: center; font-weight: 600; text-shadow: 0 1px 3px #000; }
.camera-bar { position: absolute; left: 16px; right: 16px; bottom: calc(24px + var(--safe-b)); display: flex; gap: 10px; }
.camera-bar .btn { flex: 1; }

.sheet-back { position: fixed; inset: 0; z-index: 30; background: rgba(18, 30, 45, .45); }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; background: var(--surface); border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); max-height: 88vh; overflow: auto; max-width: 640px; margin: 0 auto; }
.sheet h3 { margin: 0 0 4px; font-size: 18px; }
.vehicles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 12px 0; }
.vehicles .btn { min-height: 64px; flex-direction: column; gap: 2px; }
.vehicles .btn.on { border: 2px solid var(--primary); background: var(--tint); }
.vehicles .btn small { font-weight: 400; color: var(--muted); }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(84px + var(--safe-b)); z-index: 40; background: var(--primary-dark); color: #fff; padding: 12px 14px; border-radius: 10px; text-align: center; font-size: 15px; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast.bad { background: var(--bad); }

.scan-row { display: flex; gap: 10px; }
.scan-row .btn.big.primary { flex: 1; }
.btn.big.attach { flex: 0 0 104px; font-size: 14px; line-height: 1.25; background: #fff; color: #1D5AA6; border: 1px solid #C3CEDD; text-align: center; }
.btn.big.attach svg { width: 34px; height: 34px; }

.item .view-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; margin-left: 8px; border-radius: 10px; border: 1px solid #C3CEDD; color: #1D5AA6; background: #fff; flex: none; }
.item .view-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.keep { margin-top: 12px; padding: 10px 12px; border: 1px solid #D9E0EA; border-radius: 12px; background: #F8FAFC; }
.keep .check { margin: 6px 0; }
.tag.warr { background: #E7F1FB; color: #1D5AA6; }
.search { width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid #C3CEDD; border-radius: 12px; font: inherit; margin: 8px 0 4px; background: #fff; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag:not(.ok):not(.bad):not(.sent):not(.wait):not(.warr) { background: var(--tint); color: var(--primary-dark); }
.chips-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 10px; }
.chip-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 99px; padding: 8px 12px; font: inherit; font-size: 14px; }
.chip-btn.on { border-color: var(--primary); background: var(--tint); color: var(--primary-dark); font-weight: 600; }
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0 12px; }
.month-nav .btn { min-width: 48px; font-size: 20px; }
.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.stats-grid > div { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.stats-grid b { font-size: 17px; }
.ok-text { color: var(--ok); }
.bad-text { color: var(--bad); }
.item .amt small { display: block; font-size: 11px; font-weight: 400; color: var(--muted); }

.range-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: -4px 0 12px; }
.range-row label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.range-row input { min-height: 44px; border: 1px solid #C3CEDD; border-radius: 12px; padding: 0 10px; font: inherit; background: #fff; color: var(--text); }
.search-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.search-row .search { margin: 0; flex: 1; min-width: 0; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; flex: none; }
.seg button { border: 0; background: var(--surface); padding: 0 12px; min-height: 44px; font: inherit; font-size: 14px; color: var(--text); }
.seg button.on { background: var(--primary); color: #fff; }
.tbl-wrap { overflow-x: auto; margin: 8px -4px 0; }
.rtable { width: 100%; border-collapse: collapse; font-size: 14px; }
.rtable th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.rtable th[data-sort] { cursor: pointer; color: var(--primary-dark); }
.rtable td { padding: 10px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.rtable tr[data-receipt] { cursor: pointer; }
.rtable .r { text-align: right; white-space: nowrap; }
.rtable small { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rtable .tag { font-size: 11px; padding: 2px 6px; }
.link-btn { border: 0; background: none; color: var(--primary); font: inherit; font-size: 13px; padding: 0; }

.op-client { border: 2px solid var(--primary); }
.op-name { font-size: 22px; font-weight: 700; color: var(--primary-dark); margin: 2px 0; }
button.view-btn { font-size: 22px; line-height: 1; background: var(--surface); }

.lock { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px 24px calc(24px + var(--safe-b)); text-align: center; }
.lock h2 { margin: 4px 0 0; }
.lock .btn { max-width: 360px; }
.pin-input { width: 100%; max-width: 360px; min-height: 52px; font-size: 26px; letter-spacing: 8px; text-align: center; border: 1px solid #C3CEDD; border-radius: 12px; background: #fff; color: var(--text); }
body.is-locked > :not(.lock):not(.toast) { visibility: hidden; }

/* dodavanje računa: po PFR broju i fotografija */
.add-row { display: flex; gap: 10px; margin-top: 10px; }
.add-row .btn { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--surface); color: var(--primary); border: 1px solid var(--border); font-weight: 600; }
.add-row .btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.add-row .btn:disabled { opacity: .5; }
.steps { padding-left: 20px; margin: 8px 0 12px; }
.steps li { margin-bottom: 12px; font-size: 15px; }
.doc-photo { display: block; width: 100%; max-height: 42vh; object-fit: contain; background: var(--bg, #EEF2F7); border-radius: 10px; margin-bottom: 8px; }
.doc-photo.empty { height: 120px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 14px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kind-seg { display: flex; margin-bottom: 10px; }
.kind-seg button { flex: 1; }
.two > * { min-width: 0; }
.two .field input, .two .field select { width: 100%; min-width: 0; }
