:root {
  --brand: #1f4e8c;
  --bg: #f4f6f9;
  --card: #fff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --ok: #15803d;
  --warn: #b45309;
  --err: #b91c1c;
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { margin: 0 0 .5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.icon { width: 1.3em; height: 1.3em; vertical-align: -.25em; }
.icon.inline { width: 1.1em; height: 1.1em; }

/* Layout */
.center-screen { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .75rem; padding: 2rem; text-align: center; }
.hero-icon { width: 88px; height: 88px; border-radius: 22px; box-shadow: 0 6px 20px rgba(0,0,0,.15); }
.content { padding: 1rem; max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 1rem; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  padding: calc(env(safe-area-inset-top) + .5rem) .75rem .5rem;
  background: var(--brand-gradient, var(--brand)); color: #fff;
}
.topbar-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.topbar-title { font-weight: 600; font-size: 1.05rem; text-align: center; }
.topbar-left .btn.link { color: #fff; padding-left: 0; }
.avatar-btn { justify-self: end; background: none; border: 0; padding: 0; }
.avatar {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: rgba(255,255,255,.3); color: #fff; font-weight: 700; font-size: .9rem; flex: none;
}
.company-toggle {
  display: flex; gap: 4px; margin-top: .6rem; padding: 4px;
  background: rgba(0,0,0,.2); border-radius: 12px;
}
.company-toggle button {
  flex: 1; border: 0; border-radius: 9px; padding: .55rem .5rem; font: inherit; font-weight: 600; font-size: .95rem;
  background: transparent; color: rgba(255,255,255,.85);
}
.company-toggle button.active { background: #fff; color: var(--brand); box-shadow: 0 1px 3px rgba(0,0,0,.2); }

/* Buttons */
.btn {
  font: inherit; font-weight: 600; border-radius: 10px; border: 1px solid transparent;
  padding: .7rem 1rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:disabled { opacity: .6; }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--text); }
.btn.danger { color: var(--err); }
.btn.link { background: none; color: var(--brand); padding: .4rem; font-weight: 500; }
.btn.big { padding: 1rem 1.4rem; font-size: 1.05rem; width: 100%; max-width: 360px; }
.btn.full { width: 100%; margin-top: .5rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; }

.scan-button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem;
  width: 100%; aspect-ratio: 2 / 1; max-height: 260px;
  border: 0; border-radius: 22px; background: var(--brand-gradient, var(--brand)); color: #fff;
  font: inherit; font-size: 1.4rem; font-weight: 700; box-shadow: 0 10px 25px rgba(0,0,0,.18);
}
.scan-button .icon { width: 64px; height: 64px; }
.scan-button:active { transform: scale(.98); }
.save-to { text-align: center; font-size: .9rem; }
.install { text-align: center; font-size: .9rem; align-self: center; }

/* Cards, banners */
.card { background: var(--card); border-radius: var(--radius); padding: 1rem; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.path { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9rem; word-break: break-all; background: var(--bg); padding: .5rem .6rem; border-radius: 8px; }
.banner { border-radius: 10px; padding: .7rem .9rem; font-size: .92rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.banner.info { background: #e0ecff; color: #1e3a8a; }
.banner.ok { background: #dcfce7; color: #14532d; }
.banner.warn { background: #fef3c7; color: #78350f; }
.banner.error { background: #fee2e2; color: #7f1d1d; }

.section-title { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; margin: .5rem 0; }
.history { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.history li { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; border-top: 1px solid var(--line); }
.history li:first-child { border-top: 0; }
.h-main { flex: 1; min-width: 0; }
.h-name { font-size: .92rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-sub { font-size: .8rem; }
.pill { font-size: .72rem; padding: .2rem .5rem; border-radius: 999px; white-space: nowrap; }
.pill.saved { background: #dcfce7; color: var(--ok); }
.pill.queued { background: #fef3c7; color: var(--warn); }

/* Receipt form */
.pages { display: flex; gap: .6rem; overflow-x: auto; padding-bottom: .25rem; }
.page-thumb { position: relative; flex: none; }
.page-thumb img { height: 150px; border-radius: 10px; display: block; box-shadow: 0 2px 8px rgba(0,0,0,.15); background: #fff; }
.thumb-x { position: absolute; top: -8px; right: -8px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: #0f172a; color: #fff; font-size: 1.1rem; line-height: 1; }
.add-page {
  flex: none; width: 100px; height: 150px; border-radius: 10px; border: 2px dashed var(--line); background: #fff;
  color: var(--muted); font: inherit; font-size: .85rem; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem;
}

form { display: flex; flex-direction: column; gap: 1rem; background: var(--card); border-radius: var(--radius); padding: 1rem; }
.field { display: flex; flex-direction: column; gap: .35rem; }
.field > span { font-weight: 600; font-size: .9rem; }
.field em { font-style: normal; font-weight: 400; }
input[type=text], input[type=date] {
  font: inherit; font-size: 16px; /* 16px stops iOS zooming in */
  padding: .75rem .8rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text); width: 100%;
  min-height: 48px; -webkit-appearance: none; appearance: none;
}
input:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.money { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding-left: .8rem; }
.money:focus-within { outline: 2px solid var(--brand); outline-offset: -1px; }
.money input { border: 0; outline: 0 !important; }
.money > span { color: var(--muted); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-block; padding: .5rem .85rem; border-radius: 999px; border: 1px solid var(--line); background: #fff; font-size: .92rem; }
.chip input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }

.project-field { position: relative; }
.suggestions {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 4; list-style: none; margin: .25rem 0 0; padding: .25rem 0;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 280px; overflow-y: auto;
}
.suggestions li { padding: .7rem .9rem; font-size: .95rem; }
.suggestions li + li { border-top: 1px solid var(--line); }
.suggestions li b { margin-right: .4rem; }
.pstatus { display: inline-block; margin-left: .3rem; padding: .05rem .45rem; border-radius: 999px; background: var(--bg); color: var(--muted); font-size: .75rem; white-space: nowrap; }
.suggestions li.free, .suggestions li.clear { color: var(--brand); }
.suggestions li:active { background: var(--bg); }

.filename-preview { font-size: .85rem; word-break: break-word; }
.filename-preview b { color: var(--text); font-weight: 600; }
.save { position: sticky; bottom: calc(env(safe-area-inset-bottom) + .5rem); max-width: none; }

/* Bottom sheet */
.backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 85vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 1rem 1rem calc(env(safe-area-inset-bottom) + 1rem);
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-head { text-align: center; margin-bottom: .75rem; }
.accounts, .browser { list-style: none; margin: 0 0 .5rem; padding: 0; background: #fff; border-radius: var(--radius); overflow: hidden; }
.accounts li, .browser li { display: flex; align-items: center; gap: .75rem; padding: .85rem 1rem; border-top: 1px solid var(--line); cursor: pointer; }
.accounts li:first-child, .browser li:first-child { border-top: 0; }
.acct-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.acct-text .muted { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; }
.check { color: var(--brand); font-weight: 700; }
.crumb { font-size: .85rem; margin-bottom: .5rem; word-break: break-all; }

.btn.dropbox { background: #0061fe; }

/* Branding */
.logo-chip, .toggle-logo, .brand-logo, .logo-tile {
  display: inline-grid; place-items: center; flex: none; background: #fff; overflow: hidden;
}
.logo-chip img, .toggle-logo img, .brand-logo img, .logo-tile img { width: 100%; height: 100%; object-fit: contain; }
.logo-chip { width: 44px; height: 44px; border-radius: 10px; padding: 4px; border: 1px solid var(--line); }
.logo-chip.small { width: 34px; height: 34px; border-radius: 8px; padding: 3px; }
.toggle-logo { width: 24px; height: 24px; border-radius: 6px; padding: 2px; }
.company-toggle button { display: flex; align-items: center; justify-content: center; gap: .45rem; }
.brand-hero { display: flex; align-items: center; gap: .85rem; }
.brand-logo { width: 64px; height: 64px; border-radius: 16px; padding: 6px; box-shadow: 0 2px 10px rgba(0,0,0,.08); }
.brand-name { font-size: 1.3rem; font-weight: 700; color: var(--brand); line-height: 1.2; }
.logo-row { display: flex; gap: 1rem; margin-bottom: .5rem; }
.logo-tile { width: 92px; height: 92px; border-radius: 22px; padding: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.12); }

/* Admin */
.admin .section-title { display: flex; align-items: center; gap: .5rem; }
.add-row { display: flex; gap: .5rem; margin: .5rem 0 .75rem; }
.add-row input, .company-name-row input[type=text] {
  flex: 1; font: inherit; font-size: 16px; padding: .65rem .75rem; border: 1px solid var(--line); border-radius: 10px; min-width: 0;
}
.user-list { display: flex; flex-direction: column; gap: .5rem; }
.user-card { padding: 0; overflow: hidden; }
.user-head { display: flex; align-items: center; gap: .5rem; width: 100%; padding: .85rem 1rem; background: none; border: 0; font: inherit; text-align: left; color: inherit; }
.user-head .acct-text { gap: .1rem; }
.chev { color: var(--muted); }
.user-body { padding: 0 1rem 1rem; display: flex; flex-direction: column; gap: .75rem; border-top: 1px solid var(--line); padding-top: .85rem; }
.access { display: flex; flex-direction: column; gap: .4rem; }
.check { display: flex; align-items: center; gap: .55rem; font-weight: 600; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); }
.warn-text { color: var(--warn); }
.pill.admin { background: #e0e7ff; color: #3730a3; font-weight: 600; }
.company-card { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .5rem; }
.company-name-row { display: flex; gap: .5rem; align-items: center; }
.company-name-row input[type=color] { width: 44px; height: 44px; border: 0; padding: 0; background: none; }

/* Scanner */
body.scanning { overflow: hidden; }
.scanner {
  position: fixed; inset: 0; z-index: 40; background: #000; color: #fff;
  display: flex; flex-direction: column; touch-action: none; user-select: none; -webkit-user-select: none;
}
.scanner video, .scan-overlay { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner.flash::after { content: ''; position: absolute; inset: 0; background: #fff; animation: flash .25s ease-out forwards; pointer-events: none; }
@keyframes flash { to { opacity: 0; } }
.scan-top {
  position: relative; z-index: 2; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: calc(env(safe-area-inset-top) + .5rem) .75rem .6rem; background: linear-gradient(rgba(0,0,0,.6), transparent);
}
.scan-top button { justify-self: start; background: none; border: 0; color: #fff; font: inherit; font-weight: 600; padding: .4rem; }
.scan-top button.toggle { justify-self: end; border: 1px solid rgba(255,255,255,.5); border-radius: 999px; padding: .3rem .8rem; font-size: .85rem; opacity: .7; }
.scan-top button.toggle.on { background: #fff; color: #000; opacity: 1; }
.scan-title { font-weight: 600; text-align: center; }
.scan-hint {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 130px); transform: translateX(-50%); z-index: 2;
  background: rgba(0,0,0,.6); padding: .5rem .9rem; border-radius: 999px; font-size: .92rem; text-align: center; max-width: 90%; width: max-content;
}
.scan-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; justify-items: center;
  padding: 1rem 1rem calc(env(safe-area-inset-bottom) + 1.25rem); background: linear-gradient(transparent, rgba(0,0,0,.65));
}
.scan-bottom.single { grid-template-columns: 1fr; }
.scan-small { background: rgba(255,255,255,.15); border: 0; color: #fff; border-radius: 12px; padding: .45rem .7rem; font: inherit; font-size: .78rem; line-height: 1.15; }
.scan-small.on { background: #fde047; color: #000; }
.shutter { width: 78px; height: 78px; border-radius: 50%; border: 0; padding: 0; background: #fff; box-shadow: 0 0 0 4px rgba(255,255,255,.35); }
.shutter svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.shutter .ring-bg { fill: none; stroke: #e5e7eb; stroke-width: 6; }
.shutter .ring { fill: none; stroke: #22c55e; stroke-width: 6; stroke-dasharray: 100; stroke-dashoffset: 100; transition: stroke-dashoffset .12s linear; }
.shutter:active { transform: scale(.94); }
.scanner.no-camera .shutter { opacity: .3; pointer-events: none; }
.scanner.no-camera [data-s="camera-app"] { background: #fff; color: #000; font-size: .95rem; padding: .7rem 1rem; }

.scanner.review { background: #111; }
.review-stage { position: relative; flex: 1; margin: 0 .5rem calc(env(safe-area-inset-bottom) + 100px); }
.review-img, .review-lines { position: absolute; inset: 0; }
.handle {
  position: absolute; left: -22px; top: -22px; width: 44px; height: 44px; border-radius: 50%; touch-action: none;
  background: rgba(255,255,255,.25); border: 3px solid #fff; box-shadow: 0 1px 6px rgba(0,0,0,.5);
}
.handle.drag { background: rgba(255,255,255,.5); transform-origin: center; }
.use-btn { width: 100%; max-width: 360px; padding: 1rem; border: 0; border-radius: 12px; background: #fff; color: #000; font: inherit; font-weight: 700; font-size: 1.05rem; }
.use-btn:disabled { opacity: .7; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 1.25rem); transform: translate(-50%, 150%);
  background: #0f172a; color: #fff; padding: .8rem 1.1rem; border-radius: 12px; z-index: 30; max-width: calc(100% - 2rem);
  font-size: .92rem; box-shadow: 0 8px 24px rgba(0,0,0,.25); transition: transform .25s ease;
}
.toast.error { background: var(--err); }
.toast.show { transform: translate(-50%, 0); }

.spinner { width: 1.1em; height: 1.1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
