:root {
  --brand: #0C4DA2; --brand-dark: #093b7d; --brand-soft: #e8f0fb;
  --ink: #17212f; --muted: #64748b; --line: #dfe5ee; --bg: #f3f5f9; --card: #fff;
  --ok: #15803d; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7; --err: #b91c1c; --err-soft: #fee2e2;
  --mfr: #6d28d9; --mfr-soft: #ede9fe; --whs: #0f766e; --whs-soft: #ccfbf1; --ltr: #c2410c; --ltr-soft: #ffedd5;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg); -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button, select, label.btn, .clickable, summary { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.hidden { display: none !important; }

/* shell */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); background: var(--brand); color: #fff;
}
.topbar h1 { font-size: 19px; font-weight: 700; letter-spacing: .2px; flex: 1; min-width: 0; }
.topbar .chip { background: rgba(255,255,255,.18); border: 0; color: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; white-space: nowrap; }
.topbar .chip.alert { background: #fbbf24; color: #3b2a00; font-weight: 600; }
main { max-width: 860px; margin: 0 auto; padding: 16px 16px 120px; }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: #fff;
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 9px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600; cursor: pointer;
}
.nav a svg { width: 23px; height: 23px; }
.nav a.active { color: var(--brand); }
.footer { margin-top: 36px; text-align: center; color: var(--muted); font-size: 12px; }
.footer .app-line { margin-bottom: 18px; }
.footer .powered { display: inline-flex; flex-direction: column; align-items: center; gap: 4px; text-decoration: none; color: var(--muted); cursor: pointer; }
.footer .powered small { font-size: 10px; letter-spacing: 1.5px; }
.footer .powered img { height: 20px; width: auto; }

/* building blocks */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card > h2 { font-size: 16px; margin-bottom: 4px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 10px; }
.field { margin-bottom: 12px; }
.field > label { display: block; font-size: 13px; font-weight: 600; color: #334155; margin-bottom: 5px; }
.input, select.input, textarea.input {
  width: 100%; padding: 11px 12px; border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; min-height: 46px;
}
textarea.input { min-height: 78px; resize: vertical; }
.input:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row > .grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 44px; padding: 9px 16px;
  border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; font-weight: 600; font-size: 15px; white-space: nowrap; text-decoration: none; color: var(--ink);
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.big { width: 100%; min-height: 54px; font-size: 17px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; flex: none;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: #475569;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--brand-soft); color: var(--brand); }
.icon-btn.del:hover { background: var(--err-soft); color: var(--err); }

/* stall type picker */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg button {
  min-height: 62px; padding: 8px 4px; border: 2px solid var(--line); border-radius: 12px; background: #fff;
  font-weight: 700; font-size: 14px; line-height: 1.2; color: #475569;
}
.seg button[data-type=manufacturer].on { border-color: var(--mfr); background: var(--mfr-soft); color: var(--mfr); }
.seg button[data-type=wholesaler].on { border-color: var(--whs); background: var(--whs-soft); color: var(--whs); }
.seg button[data-type=local_trader].on { border-color: var(--ltr); background: var(--ltr-soft); color: var(--ltr); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge.manufacturer { background: var(--mfr-soft); color: var(--mfr); }
.badge.wholesaler { background: var(--whs-soft); color: var(--whs); }
.badge.local_trader { background: var(--ltr-soft); color: var(--ltr); }
.badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.failed { background: var(--err-soft); color: var(--err); }
.badge.done { background: var(--ok-soft); color: var(--ok); }
.badge.plain { background: #eef2f7; color: #475569; }

/* photo sections */
.shots { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.shots:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.shots-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.shots-head h3 { font-size: 15px; flex: 1; min-width: 120px; }
.shots-head .count { color: var(--muted); font-weight: 500; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; }
.thumbs:empty { display: none; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #e2e8f0; border: 1px solid var(--line); cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .pdf { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; font-weight: 800; color: var(--err); font-size: 15px; gap: 2px; padding: 4px; text-align: center; }
.thumb .pdf small { font-weight: 500; color: var(--muted); font-size: 10px; word-break: break-all; line-height: 1.1; max-height: 2.3em; overflow: hidden; }
.thumb .x {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0;
  background: rgba(15,23,42,.72); color: #fff; display: flex; align-items: center; justify-content: center;
}
.thumb .x svg { width: 14px; height: 14px; }

/* lists */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.search { position: relative; flex: 1 1 220px; min-width: 0; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
.search .input { padding-left: 38px; }
.toolbar select.input { flex: 1 1 140px; width: auto; min-width: 0; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; gap: 12px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.item .pic { width: 62px; height: 62px; border-radius: 10px; background: #e2e8f0; flex: none; object-fit: cover; display: flex; align-items: center; justify-content: center; color: #94a3b8; }
.item .pic svg { width: 24px; height: 24px; }
.item .body { flex: 1; min-width: 0; cursor: pointer; }
.item .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 4px; }
.item .actions { display: flex; gap: 6px; flex: none; }
@media (max-width: 420px) { .item .actions { flex-direction: column; } .item .actions .icon-btn { width: 36px; height: 36px; } }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.summary { color: var(--muted); font-size: 13px; margin: 0 2px 10px; }

/* modal + notices */
.backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(15,23,42,.55); display: flex; align-items: center; justify-content: center; padding: 14px; }
.backdrop.clear { background: transparent; pointer-events: none; }
.backdrop.clear > * { pointer-events: auto; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 520px; max-height: calc(100dvh - 28px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 17px; flex: 1; min-width: 0; }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
@media (max-width: 560px) {
  .backdrop.full { padding: 0; }
  .backdrop.full .modal { max-width: none; height: 100dvh; max-height: none; border-radius: 0; }
}
.notice { background: #fff; border-radius: 18px; width: 100%; max-width: 340px; padding: 22px 20px 0; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.3); overflow: hidden; border: 1px solid var(--line); }
.notice .mark { width: 56px; height: 56px; border-radius: 50%; margin: 0 auto 10px; display: flex; align-items: center; justify-content: center; }
.notice .mark svg { width: 28px; height: 28px; }
.notice.ok .mark { background: var(--ok-soft); color: var(--ok); }
.notice.err .mark { background: var(--err-soft); color: var(--err); }
.notice h3 { font-size: 18px; margin-bottom: 6px; }
.notice p { margin: 0 0 16px; color: #475569; overflow-wrap: anywhere; }
.notice .btn { min-width: 120px; margin-bottom: 16px; }
.notice .bar { height: 4px; background: var(--brand); margin: 0 -20px; transform-origin: left; animation: shrink linear forwards; }
.notice:hover .bar { animation-play-state: paused; }
@keyframes shrink { to { transform: scaleX(0); } }
.confirm-actions { display: flex; gap: 8px; justify-content: center; margin-bottom: 18px; }

.viewer { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .close { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.18); color: #fff; display: flex; align-items: center; justify-content: center; }
.viewer .close svg { width: 20px; height: 20px; }

.banner { border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner > span { flex: 1; min-width: 160px; }
.banner.pending { background: var(--warn-soft); color: #7c2d12; }
.banner.failed { background: var(--err-soft); color: #7f1d1d; }
.banner.done { background: var(--ok-soft); color: #14532d; }
.banner.plain { background: #eef2f7; color: #334155; }
.banner .btn { min-height: 36px; padding: 5px 12px; font-size: 14px; }

/* sign in */
.login { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; padding: 24px; }
.login .logo { width: 64px; height: 64px; border-radius: 16px; display: block; margin: 0 auto 12px; }
.login h1 { text-align: center; font-size: 24px; color: var(--brand); }
.login .hint { text-align: center; margin-bottom: 18px; }
.user-menu { position: absolute; right: 12px; top: calc(52px + env(safe-area-inset-top)); z-index: 30; background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.18); min-width: 190px; padding: 6px; }
.user-menu .who { padding: 8px 10px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.user-menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px; border-radius: 8px; font-weight: 600; }
.user-menu button:hover { background: var(--brand-soft); }

/* photo buttons sit on their own row so they never wrap unevenly on a phone */
.shots-head h3 { flex: 1 0 100%; }
.shots-head .btn { flex: 1; }

/* team report */
.datebox { display: flex; align-items: center; gap: 6px; flex: 1 1 150px; min-width: 0; font-size: 13px; font-weight: 600; color: #334155; cursor: default; }
.datebox .input { flex: 1; min-width: 0; }
.section-title { font-size: 16px; margin: 20px 2px 10px; }
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { font-size: 12px; color: var(--muted); font-weight: 700; }
.table td.num, .table th:not(:first-child) { text-align: right; }
.table td.who { white-space: normal; }
.table th, .table td { padding-left: 6px; padding-right: 6px; }
.table td.strong { font-weight: 800; color: var(--brand); }
.table tbody tr:hover { background: var(--brand-soft); }
.table tfoot td { font-weight: 700; border-bottom: 0; background: #f8fafc; }
.table small { color: var(--muted); font-weight: 400; }

/* dd/mm/yyyy date box */
.datefield { position: relative; display: block; flex: 1; min-width: 0; }
.datefield .input { padding-right: 46px; }
.datefield .date-native { position: absolute; right: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; pointer-events: none; }
.datefield .date-btn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 38px; height: 38px; border: 0; background: none; color: var(--muted); display: flex; align-items: center; justify-content: center; border-radius: 8px; }
.datefield .date-btn:hover { background: var(--brand-soft); color: var(--brand); }
.datefield .date-btn svg { width: 18px; height: 18px; }
.datebox > span:first-child { flex: none; }

/* bottom tabs: every tab has its own colour; the open one gets a tinted pill */
.nav a { color: #475569; }
.nav a .ico { display: flex; align-items: center; justify-content: center; width: 52px; height: 30px; border-radius: 999px; color: var(--c); transition: background .15s; }
.nav a.active { color: var(--c); }
.nav a.active .ico { background: var(--c-soft); }
.nav a.active .ico svg { stroke-width: 2.4; }

/* a filter row with dates: the dropdown takes its own line so both date boxes fit side by side */
.toolbar:has(.datebox) select.input { flex: 1 1 100%; }

/* company type tick boxes (several can be on) */
:root { --imp: #1d4ed8; --imp-soft: #dbeafe; --exp: #be185d; --exp-soft: #fce7f3; }
.seg { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 620px) { .seg { grid-template-columns: repeat(5, 1fr); } }
.seg button { display: flex; align-items: center; gap: 9px; min-height: 52px; padding: 8px 10px; text-align: left; }
.seg button .box { width: 22px; height: 22px; flex: none; border: 2px solid #94a3b8; border-radius: 6px; background: #fff; display: flex; align-items: center; justify-content: center; }
.seg button .box svg { width: 15px; height: 15px; stroke-width: 3.2; }
.seg button.on .box { border-color: currentColor; background: currentColor; }
.seg button.on .box svg { color: #fff; }
.seg button[data-type=importer].on { border-color: var(--imp); background: var(--imp-soft); color: var(--imp); }
.seg button[data-type=exporter].on { border-color: var(--exp); background: var(--exp-soft); color: var(--exp); }
.badge.importer { background: var(--imp-soft); color: var(--imp); }
.badge.exporter { background: var(--exp-soft); color: var(--exp); }
.table th, .table td { padding-left: 4px; padding-right: 4px; }
