:root {
  --ink: #0d2f57; --ink-soft: #4d4f52; --muted: #6d6f72; --paper: #f4f5f7; --white: #fff; --line: #dfe2e6;
  --accent: #12427b; --accent-soft: color-mix(in srgb, var(--accent) 11%, white); --ok: #1f7a4d; --warn: #9a6200; --bad: #b3261e;
  --radius: 16px; --shadow: 0 12px 32px rgba(13, 47, 87, .06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); -webkit-font-smoothing: antialiased; min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

/* layout */
.topbar { max-width: 1080px; margin: 0 auto; padding: 16px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); min-width: 0; }
.brand-mark { width: 40px; height: 40px; border-radius: 11px; background: var(--ink); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 15px; flex: none; overflow: hidden; }
.brand-mark img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand-mark.has-logo { background: #fff; border: 1px solid var(--line); padding: 3px; }
.brand-mark.big { width: 64px; height: 64px; border-radius: 16px; font-size: 22px; }
.brand-name { font-weight: 700; letter-spacing: -.3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-name small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.spacer { flex: 1; }
.page { max-width: 1080px; margin: 0 auto; padding: 0 16px 48px; }
.narrow { max-width: 440px; margin: 8vh auto 0; }

/* text */
h1 { font-size: 26px; letter-spacing: -.5px; margin: 0 0 6px; }
h2 { font-size: 19px; letter-spacing: -.3px; margin: 0 0 12px; }
.eyebrow { font-size: 11px; font-weight: 800; letter-spacing: 1.6px; color: var(--muted); margin: 0 0 6px; text-transform: uppercase; }
.helper { color: var(--muted); font-size: 14px; margin: 6px 0 0; }
.lead { color: var(--ink-soft); margin: 0 0 20px; }

/* panels and cards */
.panel { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); margin-bottom: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.card { text-align: left; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--ink); }
.card:hover { border-color: var(--accent); }
.card strong { font-size: 16px; }
.card small { color: var(--muted); }
.card.disabled { opacity: .55; pointer-events: none; }
.card-icon { width: 38px; height: 38px; border-radius: 11px; background: var(--accent-soft); display: grid; place-items: center; font-size: 18px; margin-bottom: 4px; }

/* forms */
form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--ink-soft); }
input, select { border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; background: #fff; width: 100%; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 14px; color: var(--ink); cursor: pointer; }
.check input { width: auto; margin: 0; }
.check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.error { color: var(--bad); font-size: 14px; margin: 0; }
.notice { background: var(--accent-soft); border-radius: 11px; padding: 12px 14px; font-size: 14px; }

/* buttons */
.btn { border: 1px solid transparent; border-radius: 11px; padding: 11px 16px; font-weight: 700; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
.btn:disabled { opacity: .6; cursor: default; }
.btn-secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-danger { background: #fff; color: var(--bad); border-color: #f0c9c6; }
.btn-small { padding: 7px 11px; font-size: 14px; }
.btn-link { background: none; border: none; color: var(--accent); padding: 0; font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* lists */
.list { display: grid; gap: 8px; }
.row { display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fff; }
.row-main { flex: 1; min-width: 0; }
.row-main strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.chip.muted { background: #eef0f2; color: var(--muted); }
.chip.warn { background: #fdf1dc; color: var(--warn); }

/* header controls */
.org-switch { max-width: 220px; padding: 8px 10px; }
.menu-btn { border: 1px solid var(--line); background: #fff; border-radius: 11px; padding: 8px 12px; font-weight: 600; white-space: nowrap; }
.back { display: inline-block; margin-bottom: 14px; font-weight: 600; text-decoration: none; }

/* dialog */
dialog { color: var(--ink); border: none; border-radius: var(--radius); padding: 22px; width: min(460px, calc(100vw - 32px)); box-shadow: 0 24px 64px rgba(13, 47, 87, .25); }
dialog::backdrop { background: rgba(13, 47, 87, .35); }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 20px; letter-spacing: 1px; background: var(--paper); border-radius: 11px; padding: 14px; text-align: center; user-select: all; }

.toast { position: fixed; z-index: 30; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; opacity: 0; transition: .2s; pointer-events: none; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }
.loading { color: var(--muted); padding: 24px 0; }

@media (max-width: 560px) {
  .grid-2 { grid-template-columns: 1fr; }
  .brand-name small { display: none; }
  .org-switch { max-width: none; flex: 1; min-width: 0; }
  .topbar:has(#orgSwitch:not([hidden])) .brand-name,
  .topbar:has(#orgSwitch:not([hidden])) .spacer { display: none; }
  h1 { font-size: 22px; }
}

/* visits and factories */
textarea { border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; background: #fff; width: 100%; resize: vertical; }
textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.field-label { display: block; font-size: 14px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.picker { position: relative; }
.picker-list { position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); max-height: 320px; overflow: auto; padding: 4px; }
.picker-item { display: block; width: 100%; text-align: left; background: none; border: none; border-radius: 9px; padding: 10px 12px; }
.picker-item:hover, .picker-item.selected { background: var(--accent-soft); }
.picker-item strong { display: block; }
.picker-item small { color: var(--muted); }
.picker-add strong { color: var(--accent); }
dialog .picker-list { position: static; margin-top: 6px; box-shadow: none; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; }
.inline-form input { flex: 2 1 200px; }
.inline-form select { flex: 1 1 150px; width: auto; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.section-head h2 { margin: 0; }
button.row { width: 100%; text-align: left; font: inherit; color: inherit; }
a.row { text-decoration: none; color: inherit; }
.row:hover { border-color: var(--accent); }
.btn-dark { background: var(--ink); }
.btn-large { width: 100%; padding: 15px; font-size: 16px; }
.card-status { color: var(--accent) !important; font-weight: 700; }
h1 .chip { vertical-align: middle; font-size: 12px; }

/* navigation */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(10px); padding-top: calc(12px + env(safe-area-inset-top)); padding-bottom: 12px; }
.top-nav { display: flex; gap: 4px; margin-left: 12px; }
.top-nav a { text-decoration: none; color: var(--ink-soft); font-weight: 600; padding: 8px 12px; border-radius: 10px; display: flex; gap: 6px; align-items: center; }
.top-nav a.active { background: var(--accent-soft); color: var(--accent); }
.top-nav .nav-icon { font-size: 15px; }
.avatar-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: #fff; color: var(--ink); font-weight: 800; font-size: 14px; flex: none; }
.bottom-nav { display: none; }
@media (max-width: 760px) {
  .top-nav { display: none; }
  .bottom-nav:not([hidden]) { display: flex; position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 700; padding: 4px 0; border-radius: 10px; }
  .bottom-nav .nav-icon { font-size: 20px; line-height: 1.2; }
  .bottom-nav a.active { color: var(--accent); }
  body.has-bottom-nav .page { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  body.has-bottom-nav .toast { bottom: calc(82px + env(safe-area-inset-bottom)); }
}

/* visit in progress banner */
.visit-banner:not([hidden]) { max-width: 1048px; margin: 0 auto 14px; display: flex; align-items: center; gap: 12px; background: var(--ink); color: #fff; border-radius: 14px; padding: 10px 12px 10px 16px; }
@media (max-width: 1080px) { .visit-banner:not([hidden]) { margin: 0 16px 14px; } }
.visit-banner-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.visit-banner-copy small { font-size: 10px; letter-spacing: 1.4px; font-weight: 800; opacity: .75; }
.visit-banner-copy strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.visit-banner-btn { background: #fff; color: var(--ink); text-decoration: none; font-weight: 800; padding: 9px 14px; border-radius: 10px; white-space: nowrap; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: #5fd38d; box-shadow: 0 0 0 0 rgba(95, 211, 141, .7); animation: pulse 1.8s infinite; flex: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 10px rgba(95, 211, 141, 0); } 100% { box-shadow: 0 0 0 0 rgba(95, 211, 141, 0); } }

/* home hero */
.hero { background: var(--ink); color: #fff; border-radius: 22px; padding: 26px 24px; margin-bottom: 16px; }
.hero h1 { color: #fff; font-size: 28px; }
.hero p { margin: 0 0 16px; opacity: .9; }
.eyebrow.light { color: rgba(255, 255, 255, .7); }
.hero-visit .actions { margin-top: 12px; }
.hero-live { display: flex; gap: 12px; align-items: center; background: rgba(255, 255, 255, .1); border-radius: 14px; padding: 12px 14px; }
.hero-live span:last-child { display: flex; flex-direction: column; min-width: 0; }
.hero-live small { font-size: 12px; opacity: .8; }
.hero-live small:first-child { font-size: 10px; letter-spacing: 1.4px; font-weight: 800; }
.hero-live strong { font-size: 18px; }
.btn-hero { background: #fff; color: var(--ink); padding: 13px 18px; }
.btn-hero-secondary { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .45); padding: 13px 18px; }
.hero-note { margin: 12px 0 0 !important; }
.hero-note a { color: #fff; font-weight: 700; }

/* misc */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 800; font-size: 13px; flex: none; }
.chip-removable { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; padding: 5px 6px 5px 12px; }
.chip-removable button { border: none; background: none; color: inherit; font-size: 16px; line-height: 1; padding: 0 4px; }
.colour-field { display: flex; align-items: center; gap: 10px; }
.colour-field input[type=color] { width: 52px; height: 40px; padding: 2px; border-radius: 10px; }
.colour-field code { font-size: 14px; color: var(--muted); }
.brand-preview { display: flex; gap: 14px; align-items: center; }
.brand-preview small { display: block; color: var(--muted); }
.file-btn { cursor: pointer; }
.fold summary { cursor: pointer; font-weight: 700; color: var(--accent); }
.sep { border: none; border-top: 1px solid var(--line); margin: 20px 0; }
.row-danger strong { color: var(--bad); }
.btn-danger-solid { background: var(--bad); }
.version { margin-top: 16px; font-size: 12px; }
.login-mark { display: grid; place-items: center; margin-bottom: 16px; }
.login-mark img { width: 64px; height: 64px; border-radius: 16px; }
dialog.confirm { width: min(380px, calc(100vw - 32px)); }

/* visit: work buttons and saved items */
.work-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.work-actions .btn-large { width: 100%; }
.tabs { display: flex; gap: 6px; background: var(--paper); padding: 4px; border-radius: 12px; margin-bottom: 14px; }
.tab { flex: 1; border: none; background: none; padding: 9px; border-radius: 9px; font-weight: 700; color: var(--muted); }
.tab.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(13, 47, 87, .1); }
.row-thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: var(--paper); flex: none; display: block; }

/* product cards */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.product-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; text-decoration: none; color: inherit; display: flex; flex-direction: column; }
.product-card:hover { border-color: var(--accent); }
.product-image { position: relative; aspect-ratio: 1; background: var(--paper); display: grid; place-items: center; }
.product-image img { width: 100%; height: 100%; object-fit: cover; display: block; }
.no-image { font-size: 28px; color: var(--muted); }
.photo-count, .order-badge { position: absolute; font-size: 11px; font-weight: 800; padding: 3px 8px; border-radius: 999px; }
.photo-count { left: 8px; bottom: 8px; background: rgba(13, 47, 87, .75); color: #fff; }
.order-badge { right: 8px; top: 8px; background: var(--ok); color: #fff; }
.product-info { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.product-info strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product-info small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product-info .price { font-weight: 800; color: var(--accent); font-size: 14px; margin-top: 2px; }

/* capture form */
.product-form { display: block; }
.product-form .panel { display: grid; gap: 14px; }
.photo-actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: stretch; }
.photo-take { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 2px dashed color-mix(in srgb, var(--accent) 45%, white);
  border-radius: 14px; padding: 18px 12px; cursor: pointer; color: var(--accent); text-align: center; background: var(--accent-soft); }
.photo-take span { font-size: 26px; }
.photo-take small { color: var(--muted); font-weight: 500; }
.photo-roll { align-self: center; }
.photo-strip { display: flex; flex-wrap: wrap; gap: 10px; }
.photo-thumb { position: relative; width: 84px; height: 84px; border-radius: 12px; overflow: hidden; background: var(--paper); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb button { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: none; background: rgba(13, 47, 87, .8); color: #fff; font-size: 16px; line-height: 1; }
.photo-thumb .cover { position: absolute; left: 4px; bottom: 4px; background: #fff; color: var(--ink); font-size: 10px; font-weight: 800; padding: 2px 6px; border-radius: 6px; }
.optional { font-weight: 500; color: var(--muted); font-size: 12px; }
.variants { display: grid; gap: 12px; }
.variant-row { border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: #fcfcfd; display: grid; gap: 10px; }
.variant-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.variant-grid label { font-size: 13px; }
.variant-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.v-sell { font-weight: 800; color: var(--accent); font-size: 14px; }
.v-remove { color: var(--bad); font-size: 14px; }
.v-more summary { font-size: 14px; }
.v-more .variant-grid { margin-top: 10px; }
.inline-label { display: flex; align-items: center; gap: 10px; }
.inline-label input { max-width: 120px; }
.converter { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; background: var(--paper); border-radius: 12px; padding: 12px; font-size: 14px; font-weight: 700; color: var(--ink-soft); }
.converter label { display: flex; flex-direction: row; align-items: center; gap: 6px; }
.converter input { width: 110px; padding: 8px 10px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 6px 0 16px; }
@media (max-width: 760px) {
  .form-actions { position: sticky; bottom: calc(70px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--paper) 94%, transparent); padding: 10px 0; backdrop-filter: blur(8px); }
  .form-actions .btn { flex: 1; }
}

/* product details */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin: 14px 0 16px; }
.gallery button { padding: 0; border: none; border-radius: 12px; overflow: hidden; aspect-ratio: 1; background: var(--paper); }
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.facts span { display: block; font-size: 12px; color: var(--muted); font-weight: 700; }
.facts a { text-decoration: none; }
.variant-view.ordered { border-color: color-mix(in srgb, var(--ok) 40%, white); }
.variant-price { text-align: right; display: flex; flex-direction: column; }
.variant-price small { color: var(--muted); }
.prewrap { white-space: pre-wrap; margin: 0; }
.card-photo { padding: 0; border: none; background: none; border-radius: 12px; overflow: hidden; display: block; width: 100%; margin-top: 12px; }
.card-photo img { width: 100%; display: block; }
.filters { display: grid; gap: 10px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filter-row select { flex: 1 1 160px; width: auto; }
.empty { text-align: center; }

/* full-screen photo viewer */
dialog.viewer { width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 0; border-radius: 0; background: #000; }
dialog.viewer img { width: 100%; height: 100%; object-fit: contain; }
.viewer-btn { position: absolute; border: none; background: rgba(255, 255, 255, .15); color: #fff; width: 44px; height: 44px; border-radius: 50%; font-size: 22px; }
.viewer-close { top: calc(14px + env(safe-area-inset-top)); right: 14px; }
.viewer-prev { left: 12px; top: 50%; transform: translateY(-50%); }
.viewer-next { right: 12px; top: 50%; transform: translateY(-50%); }
.viewer-count { position: absolute; bottom: calc(18px + env(safe-area-inset-bottom)); left: 0; right: 0; text-align: center; color: #fff; margin: 0; }
