/* ============ Tokens (iOS system colours) ============ */
:root {
  color-scheme: light;
  --bg: #f2f2f7;
  --bg-elev: #ffffff;
  --bg-elev-2: #f2f2f7;
  --fill: rgba(120, 120, 128, 0.12);
  --fill-2: rgba(120, 120, 128, 0.08);
  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.62);
  --label-3: rgba(60, 60, 67, 0.32);
  --sep: rgba(60, 60, 67, 0.2);
  --accent: #007aff;
  --accent-soft: rgba(0, 122, 255, 0.12);
  --danger: #ff3b30;
  --success: #34c759;
  --warning: #ff9500;
  --swatch-edge: rgba(0, 0, 0, 0.08);
  --glass: rgba(255, 255, 255, 0.58);
  --glass-strong: rgba(255, 255, 255, 0.82);
  --glass-edge: rgba(255, 255, 255, 0.75);
  --glass-shine: rgba(255, 255, 255, 0.55);
  --glass-shadow: 0 10px 30px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.06);
  --sheet-bg: #f2f2f7;
  --sheet-card: #ffffff;
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 14px rgba(0, 0, 0, 0.05);
  --radius: 16px;
  --tabbar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-round: ui-rounded, "SF Pro Rounded", -apple-system, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #000000;
    --bg-elev: #1c1c1e;
    --bg-elev-2: #2c2c2e;
    --fill: rgba(120, 120, 128, 0.26);
    --fill-2: rgba(120, 120, 128, 0.16);
    --label: #ffffff;
    --label-2: rgba(235, 235, 245, 0.62);
    --label-3: rgba(235, 235, 245, 0.32);
    --sep: rgba(84, 84, 88, 0.55);
    --accent: #0a84ff;
    --accent-soft: rgba(10, 132, 255, 0.2);
    --danger: #ff453a;
    --success: #30d158;
    --warning: #ff9f0a;
    --swatch-edge: rgba(255, 255, 255, 0.14);
    --glass: rgba(44, 44, 48, 0.55);
    --glass-strong: rgba(36, 36, 40, 0.86);
    --glass-edge: rgba(255, 255, 255, 0.14);
    --glass-shine: rgba(255, 255, 255, 0.12);
    --glass-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
    --sheet-bg: #1c1c1e;
    --sheet-card: #2c2c2e;
    --card-shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --bg-elev: #1c1c1e;
  --bg-elev-2: #2c2c2e;
  --fill: rgba(120, 120, 128, 0.26);
  --fill-2: rgba(120, 120, 128, 0.16);
  --label: #ffffff;
  --label-2: rgba(235, 235, 245, 0.62);
  --label-3: rgba(235, 235, 245, 0.32);
  --sep: rgba(84, 84, 88, 0.55);
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.2);
  --danger: #ff453a;
  --success: #30d158;
  --warning: #ff9f0a;
  --swatch-edge: rgba(255, 255, 255, 0.14);
  --glass: rgba(44, 44, 48, 0.55);
  --glass-strong: rgba(36, 36, 40, 0.86);
  --glass-edge: rgba(255, 255, 255, 0.14);
  --glass-shine: rgba(255, 255, 255, 0.12);
  --glass-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
  --sheet-bg: #1c1c1e;
  --sheet-card: #2c2c2e;
  --card-shadow: none;
}

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
html.layer-open { overflow: hidden; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--label);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.35;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; -webkit-user-select: none; user-select: none; touch-action: manipulation; }
button:disabled { opacity: 0.4; cursor: default; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
.ic { width: 22px; height: 22px; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ============ Liquid-glass material ============ */
.glass {
  position: relative;
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(1.9);
  backdrop-filter: blur(22px) saturate(1.9);
  border: 0.5px solid var(--glass-edge);
  box-shadow: var(--glass-shadow), inset 0 1px 0 var(--glass-shine);
}
.glass::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(180deg, var(--glass-shine) 0%, transparent 42%, transparent 70%, rgba(255, 255, 255, 0.06) 100%);
  opacity: 0.6;
}

/* ============ Top bar (appears on scroll) ============ */
.navbar {
  position: fixed;
  z-index: 30;
  top: 0; left: 0; right: 0;
  height: calc(var(--safe-top) + 50px);
  padding: var(--safe-top) 12px 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  pointer-events: none;
}
.navbar::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  backdrop-filter: blur(20px) saturate(1.8);
  border-bottom: 0.5px solid var(--sep);
  opacity: 0;
  transition: opacity 0.2s;
}
.navbar .nav-title {
  grid-column: 2;
  position: relative;
  font-weight: 600;
  font-size: 17px;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
}
.navbar .nav-actions {
  grid-column: 3;
  justify-self: end;
  position: relative;
  display: flex;
  gap: 8px;
  pointer-events: auto;
}
body.scrolled .navbar::before { opacity: 1; }
body.scrolled .navbar .nav-title { opacity: 1; transform: none; }

.round-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--label);
  background: var(--fill);
  transition: transform 0.15s, background 0.15s;
}
.round-btn .ic { width: 20px; height: 20px; }
.round-btn.glass { background: var(--glass); }
.round-btn.accent { color: var(--accent); }
.round-btn:active { transform: scale(0.92); }

/* ============ Page ============ */
#view {
  padding: calc(var(--safe-top) + 50px) 16px calc(var(--tabbar-h) + var(--safe-bottom) + 40px);
  max-width: 980px;
  margin: 0 auto;
  min-height: 100dvh;
}
.page-head { padding: 2px 4px 10px; }
.large-title {
  margin: 0;
  font-size: 34px;
  line-height: 1.12;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.page-sub { margin: 4px 0 0; color: var(--label-2); font-size: 15px; }
.view-enter { animation: viewIn 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ============ Search field ============ */
.searchbar { display: flex; gap: 10px; align-items: center; margin: 4px 0 14px; }
.search-field {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 44px;
  padding: 0 8px 0 12px;
  border-radius: 22px;
  background: var(--fill);
  color: var(--label-2);
}
.search-field .ic { width: 19px; height: 19px; }
.search-field input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--label);
  font-size: 17px;
  height: 100%;
}
.search-field input::placeholder { color: var(--label-2); }
.search-field input::-webkit-search-cancel-button { display: none; }
.search-clear {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--label-3);
  color: var(--bg-elev);
  display: grid;
  place-items: center;
}
.search-clear .ic { width: 14px; height: 14px; stroke-width: 3; }
.scan-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 40%, transparent);
  transition: transform 0.15s;
}
.scan-btn:active { transform: scale(0.92); }

/* ============ Chips ============ */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 0 -16px 14px;
  padding: 2px 16px 4px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border-radius: 17px;
  background: var(--bg-elev);
  color: var(--label);
  font-size: 15px;
  font-weight: 500;
  box-shadow: var(--card-shadow);
  border: 0.5px solid var(--sep);
  transition: transform 0.15s, background 0.15s;
}
.chip:active { transform: scale(0.95); }
.chip.on { background: var(--label); color: var(--bg-elev); border-color: transparent; }
.chip .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 0.5px var(--swatch-edge), 0 0 0 1px rgba(255,255,255,.4); }
.chip .n { color: var(--label-2); font-variant-numeric: tabular-nums; font-size: 13px; }
.chip.on .n { color: inherit; opacity: 0.6; }

/* ============ Colour families ============ */
.family { margin: 6px 0 26px; }
.family-head { display: flex; align-items: center; gap: 10px; margin: 0 4px 12px; }
.family-head h2 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: 0; }
.family-head .count { color: var(--label-2); font-size: 15px; font-weight: 500; }
.family-head .sub { margin-left: auto; color: var(--label-2); font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; }
.family-bar { width: 6px; height: 22px; border-radius: 3px; background: var(--c); box-shadow: 0 0 0 1px var(--swatch-edge); }

.swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 12px;
}
.swatch-card {
  position: relative;
  display: flex;
  flex-direction: column;
  text-align: left;
  border-radius: 18px;
  overflow: hidden;
  background: var(--bg-elev);
  box-shadow: var(--card-shadow);
  border: 0.5px solid var(--sep);
  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.swatch-card:active { transform: scale(0.96); }
.swatch {
  position: relative;
  height: 76px;
  background: var(--c);
  box-shadow: inset 0 -0.5px 0 var(--swatch-edge);
}
.swatch::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 90% at 15% 0%, rgba(255, 255, 255, 0.32), transparent 55%),
    linear-gradient(180deg, transparent 60%, rgba(0, 0, 0, 0.08));
}
.swatch-info { padding: 9px 11px 11px; min-height: 58px; }
.swatch-code { font-family: var(--font-round); font-weight: 700; font-size: 18px; letter-spacing: 0; line-height: 1.15; word-break: break-word; }
.swatch-alts {
  margin-top: 3px;
  color: var(--label-2);
  font-size: 12.5px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.review-dot {
  position: absolute;
  top: 8px; right: 8px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85);
}

/* ============ Lists (inset grouped) ============ */
.list {
  background: var(--bg-elev);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--card-shadow);
  margin-bottom: 22px;
}
.list-title { margin: 22px 16px 7px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--label-2); font-weight: 500; }
.list-foot { margin: -14px 16px 22px; font-size: 13px; color: var(--label-2); line-height: 1.4; }
.row {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 13px;
  min-height: 52px;
  padding: 10px 14px;
  text-align: left;
  background: transparent;
  transition: background 0.12s;
}
.row + .row::before {
  content: "";
  position: absolute;
  top: 0; right: 0;
  left: var(--inset, 16px);
  border-top: 0.5px solid var(--sep);
}
button.row:active, a.row:active { background: var(--fill-2); }
.row-main { flex: 1; min-width: 0; }
.row-main > span { display: block; }
.row-main > .match-tag { display: inline-flex; width: fit-content; margin-top: 3px; }
.row-title { font-size: 17px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 14px; color: var(--label-2); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; }
.row-value { color: var(--label-2); font-size: 16px; }
.row .chev { width: 16px; height: 16px; color: var(--label-3); stroke-width: 2.6; }
.row-icon {
  width: 30px; height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--c, var(--accent));
}
.row-icon .ic { width: 18px; height: 18px; }
.row.danger .row-title { color: var(--danger); }
.row.accent .row-title { color: var(--accent); }
.row-swatch {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--c);
  flex: none;
  box-shadow: inset 0 0 0 0.5px var(--swatch-edge);
}
.code { font-family: var(--font-round); font-weight: 700; letter-spacing: 0; }
.match-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
}

/* Big card for an exact colour match */
.hero-color {
  display: block;
  width: 100%;
  text-align: left;
  border-radius: 24px;
  overflow: hidden;
  margin-bottom: 18px;
  background: var(--bg-elev);
  box-shadow: var(--card-shadow);
  border: 0.5px solid var(--sep);
}
.hero-color .swatch { height: 150px; }
.hero-color .hero-body { padding: 14px 18px 18px; }
.hero-label { font-size: 13px; color: var(--label-2); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.hero-code { font-size: 44px; line-height: 1.05; margin: 2px 0 8px; }
.hero-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--label-2); font-size: 15px; }

/* ============ Parts ============ */
.part-row { gap: 14px; min-height: 84px; }
.thumb {
  width: 64px; height: 64px;
  flex: none;
  border-radius: 14px;
  background: #fff;
  overflow: hidden;
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.1);
  color: #b0b0b6;
}
.thumb { position: relative; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.thumb .ic { width: 26px; height: 26px; }
.cell-badge {
  flex: none;
  min-width: 58px;
  padding: 6px 8px;
  border-radius: 12px;
  text-align: center;
  background: var(--accent-soft);
  color: var(--accent);
  line-height: 1.1;
}
.cell-badge small { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.cell-badge b { font-family: var(--font-round); font-size: 20px; }

/* ============ Empty state ============ */
.empty { text-align: center; padding: 48px 24px; color: var(--label-2); }
.empty .ic { width: 46px; height: 46px; color: var(--label-3); margin-bottom: 10px; }
.empty h3 { margin: 0 0 4px; color: var(--label); font-size: 20px; }
.empty p { margin: 0; font-size: 15px; }

/* ============ Floating tab bar ============ */
.tabbar {
  position: fixed;
  z-index: 40;
  left: 0; right: 0;
  bottom: max(calc(var(--safe-bottom) - 6px), 14px);
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 10px;
  padding: 0 16px;
  pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.tabs {
  pointer-events: auto;
  position: relative;
  flex: 1;
  max-width: 360px;
  height: var(--tabbar-h);
  border-radius: 32px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 4px;
  transition: height 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.tab-indicator {
  position: absolute;
  top: 4px; bottom: 4px; left: 4px;
  width: calc((100% - 8px) / 3);
  border-radius: 28px;
  background: var(--fill);
  transform: translateX(calc(var(--i, 0) * 100%));
  transition: transform 0.38s cubic-bezier(0.3, 1.25, 0.4, 1), opacity 0.2s;
}
.tabbar.no-active .tab-indicator { opacity: 0; }
.tab {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 28px;
  color: var(--label);
  text-decoration: none;
  font-size: 11px;
  font-weight: 600;
  transition: color 0.2s, transform 0.15s;
}
.tab .ic { width: 25px; height: 25px; }
.tab.on { color: var(--accent); }
.tab:active { transform: scale(0.94); }
.tab-label { transition: opacity 0.2s, height 0.25s; height: 13px; line-height: 13px; }
.fab {
  pointer-events: auto;
  width: var(--tabbar-h);
  height: var(--tabbar-h);
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--label);
  transition: width 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.15s, color 0.2s;
}
.fab .ic { width: 25px; height: 25px; }
.fab.on { color: var(--accent); }
.fab:active { transform: scale(0.92); }
/* Minimised while scrolling down, like iOS */
.tabbar.compact .tabs { height: 50px; }
.tabbar.compact .fab { width: 50px; height: 50px; }
.tabbar.compact .tab-label { opacity: 0; height: 0; }
.tabbar.compact .tab .ic { width: 23px; height: 23px; }

/* ============ Sheets ============ */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.32);
  opacity: 0;
  transition: opacity 0.3s;
}
.sheet-backdrop.in { opacity: 1; }
.sheet {
  position: fixed;
  z-index: 61;
  left: 0; right: 0; bottom: 0;
  margin: 0 auto;
  max-width: 640px;
  max-height: calc(100dvh - var(--safe-top) - 10px);
  display: flex;
  flex-direction: column;
  background: var(--sheet-bg);
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.18);
  transform: translateY(105%);
  transition: transform 0.38s cubic-bezier(0.2, 0.9, 0.25, 1);
  overscroll-behavior: contain;
}
.sheet.in { transform: none; }
.sheet-grab { display: flex; justify-content: center; padding: 7px 0 0; touch-action: none; }
.sheet-grab span { width: 38px; height: 5px; border-radius: 3px; background: var(--label-3); }
.sheet-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 10px;
  touch-action: none;
}
.sheet-title { margin: 0; font-size: 17px; font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 56vw; }
.sheet-side { display: flex; }
.sheet-side.end { justify-content: flex-end; }
.sheet-btn { color: var(--accent); font-size: 17px; padding: 6px 4px; }
.sheet-btn.strong { font-weight: 600; }
.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 16px calc(var(--safe-bottom) + 24px);
  overscroll-behavior: contain;
}

/* ============ Detail views ============ */
.sheet .list, .sheet .note-box, .sheet .ticket-card, .sheet .input, .sheet .select, .sheet .textarea,
.sheet .chip-editor, .sheet .tone-row, .sheet .toggle-line, .sheet .slider-row, .sheet .photo-add { background-color: var(--sheet-card); }
.sheet .chip-add .input { background: var(--fill-2); }
.detail-swatch {
  position: relative;
  height: 190px;
  border-radius: 24px;
  overflow: hidden;
  background: var(--c);
  box-shadow: inset 0 0 0 0.5px var(--swatch-edge);
  margin-bottom: 16px;
}
.detail-swatch::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(110% 80% at 10% 0%, rgba(255, 255, 255, 0.3), transparent 55%), linear-gradient(180deg, transparent 55%, rgba(0, 0, 0, 0.1));
}
.tone-tag {
  position: absolute;
  z-index: 1;
  left: 12px; bottom: 12px;
  padding: 5px 10px;
  border-radius: 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: #000;
  background: rgba(255, 255, 255, 0.62);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.detail-code { font-size: 46px; line-height: 1; margin: 0 0 6px; }
.detail-meta { display: flex; gap: 8px; align-items: center; color: var(--label-2); margin-bottom: 18px; flex-wrap: wrap; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 10px;
  background: var(--fill);
  color: var(--label);
  font-size: 14px;
  font-weight: 500;
}
.pill .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 0.5px var(--swatch-edge); }
.alt-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px; }
.alt-chip {
  padding: 6px 12px;
  border-radius: 10px;
  background: var(--fill);
  font-family: var(--font-round);
  font-weight: 700;
  font-size: 16px;
}
.alt-chip.hit { background: var(--accent); color: #fff; }
.note-box, .warn-box, .info-box {
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 15px;
  margin-bottom: 16px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.note-box { background: var(--bg-elev); }
.warn-box { background: color-mix(in srgb, var(--warning) 16%, transparent); }
.info-box { background: var(--fill-2); color: var(--label-2); font-size: 13.5px; }
.note-box .ic, .warn-box .ic, .info-box .ic { width: 19px; height: 19px; margin-top: 1px; }
.warn-box .ic { color: var(--warning); }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 50px;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  transition: transform 0.15s, opacity 0.15s;
}
.btn:active { transform: scale(0.98); opacity: 0.85; }
.btn.secondary { background: var(--fill); color: var(--accent); }
.btn.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.btn .ic { width: 20px; height: 20px; }
.btn-row { display: flex; gap: 10px; margin: 8px 0 12px; }
.btn-row .btn { flex: 1; }
.stack > * + * { margin-top: 10px; }

.gallery {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  margin: 0 -16px 16px;
  padding: 0 16px;
  scrollbar-width: none;
}
.gallery::-webkit-scrollbar { display: none; }
.gallery figure {
  margin: 0;
  flex: 0 0 100%;
  scroll-snap-align: center;
  background: #fff;
  border-radius: 22px;
  height: min(52vh, 420px);
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.08);
}
.gallery.multi figure { flex-basis: 88%; }
.gallery figure { position: relative; }
.gallery img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: 12px; }
.gallery .no-photo { color: #9a9aa0; display: grid; justify-items: center; gap: 6px; font-size: 15px; }
.gallery .no-photo .ic { width: 40px; height: 40px; }
.part-title { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.part-title .detail-code { font-size: 36px; word-break: break-word; }
.part-desc { color: var(--label-2); margin: 0 0 16px; font-size: 16px; }
.cell-big {
  flex: none;
  text-align: center;
  padding: 10px 16px;
  border-radius: 18px;
  background: var(--accent);
  color: #fff;
  line-height: 1;
}
.cell-big small { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.85; margin-bottom: 4px; }
.cell-big b { font-family: var(--font-round); font-size: 32px; }

/* ============ Ticket result ============ */
.ticket-read {
  text-align: center;
  margin: 0 0 16px;
}
.ticket-read small { display: block; color: var(--label-2); font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.ticket-read .code { font-size: 30px; }
.ticket-grid { display: grid; gap: 12px; margin-bottom: 14px; }
.ticket-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  padding: 14px;
  border-radius: 20px;
  background: var(--bg-elev);
  box-shadow: var(--card-shadow);
}
.ticket-card .label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--label-2); font-weight: 600; }
.ticket-card .big { font-size: 26px; line-height: 1.1; }
.ticket-card .thumb, .ticket-card .row-swatch { width: 72px; height: 72px; border-radius: 16px; }
.ticket-card.missing { opacity: 0.75; }

/* ============ Forms ============ */
.form { padding-bottom: 8px; }
.field-label { display: block; margin: 18px 16px 7px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--label-2); font-weight: 500; }
.input, .select, .textarea {
  display: block;
  width: 100%;
  border: 0;
  outline: 0;
  border-radius: 14px;
  background: var(--bg-elev);
  color: var(--label);
  padding: 13px 16px;
  font-size: 17px;
  -webkit-appearance: none;
  appearance: none;
}
.input.code-input { font-family: var(--font-round); font-weight: 700; text-transform: uppercase; }
.textarea { min-height: 88px; resize: vertical; line-height: 1.4; }
.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 18px;
  padding-right: 42px;
}
.field-error { color: var(--danger); font-size: 13.5px; margin: 6px 16px 0; }
.field-hint { color: var(--label-2); font-size: 13px; margin: 6px 16px 0; }
.field-warn { color: var(--warning); font-size: 13.5px; margin: 6px 16px 0; font-weight: 500; }
.chip-editor { background: var(--bg-elev); border-radius: 14px; padding: 10px; }
.chip-editor .alt-chips { padding: 0 0 10px; }
.chip-editor .alt-chips:empty { display: none; }
.chip-editor .alt-chip { display: inline-flex; align-items: center; gap: 6px; padding-right: 6px; }
.chip-editor .alt-chip button { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: var(--label-3); color: var(--bg-elev); }
.chip-editor .alt-chip button .ic { width: 12px; height: 12px; stroke-width: 3; }
.chip-add { display: flex; gap: 8px; }
.chip-add .input { background: var(--fill-2); padding: 10px 14px; }
.chip-add .btn { width: auto; padding: 0 16px; height: auto; }
.tone-row { display: flex; align-items: center; gap: 12px; background: var(--bg-elev); border-radius: 14px; padding: 10px 12px; }
.tone-row input[type="color"] { width: 46px; height: 46px; border: 0; padding: 0; background: none; border-radius: 12px; overflow: hidden; }
.tone-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.tone-row input[type="color"]::-webkit-color-swatch { border: 0.5px solid var(--swatch-edge); border-radius: 12px; }
.tone-row .grow { flex: 1; min-width: 0; font-size: 15px; color: var(--label-2); }
.toggle-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--bg-elev); border-radius: 14px; padding: 12px 16px; margin-top: 10px; }
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--fill); transition: background 0.2s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2); transition: transform 0.25s cubic-bezier(0.3, 1.3, 0.5, 1); }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::after { transform: translateX(20px); }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.photo-tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: 16px;
  background: #fff;
  overflow: hidden;
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.1);
}
.photo-tile img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.photo-tile .remove { position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: rgba(0, 0, 0, 0.55); color: #fff; }
.photo-tile .remove .ic { width: 14px; height: 14px; stroke-width: 3; }
.photo-add {
  aspect-ratio: 1;
  border-radius: 16px;
  border: 1.5px dashed var(--label-3);
  color: var(--accent);
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  background: var(--bg-elev);
}
.photo-add .ic { width: 26px; height: 26px; }

/* ============ Segmented control ============ */
.segmented {
  display: flex;
  padding: 2px;
  border-radius: 10px;
  background: var(--fill);
  gap: 2px;
}
.segmented button {
  flex: 1;
  height: 32px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--label);
  transition: background 0.2s, box-shadow 0.2s;
  white-space: nowrap;
  padding: 0 6px;
}
.segmented button.on { background: var(--bg-elev); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12); font-weight: 600; }
:root[data-theme="dark"] .segmented button.on { background: #636366; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .segmented button.on { background: #636366; } }
.seg-wrap { padding: 12px 14px; }

/* ============ Toast ============ */
.toast {
  position: fixed;
  z-index: 90;
  left: 50%;
  top: calc(var(--safe-top) + 10px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 24px;
  font-size: 15px;
  font-weight: 600;
  transform: translate(-50%, -140%);
  transition: transform 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  width: max-content;
  max-width: calc(100vw - 32px);
}
.toast.in { transform: translate(-50%, 0); }
.toast .ic { width: 19px; height: 19px; color: var(--success); stroke-width: 2.6; }

/* ============ Alert ============ */
.alert-wrap {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.2s;
  padding: 24px;
}
.alert-wrap.in { opacity: 1; }
.alert {
  width: min(290px, 100%);
  border-radius: 18px;
  overflow: hidden;
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(30px) saturate(1.8);
  backdrop-filter: blur(30px) saturate(1.8);
  text-align: center;
  transform: scale(1.08);
  transition: transform 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.alert-wrap.in .alert { transform: none; }
.alert-text { padding: 18px 16px 16px; }
.alert h3 { margin: 0 0 4px; font-size: 17px; font-weight: 600; }
.alert p { margin: 0; font-size: 13.5px; color: var(--label-2); }
.alert-btns { display: grid; grid-template-columns: 1fr 1fr; border-top: 0.5px solid var(--sep); }
.alert-btns button { height: 46px; color: var(--accent); font-size: 17px; }
.alert-btns button + button { border-left: 0.5px solid var(--sep); }
.alert-btns .strong { font-weight: 600; }
.alert-btns .danger { color: var(--danger); font-weight: 600; }

/* ============ Access gate ============ */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: calc(var(--safe-top) + 24px) 24px calc(var(--safe-bottom) + 24px);
  background:
    radial-gradient(80% 50% at 20% 0%, color-mix(in srgb, #ff9f0a 26%, transparent), transparent 70%),
    radial-gradient(70% 50% at 100% 30%, color-mix(in srgb, #0a84ff 24%, transparent), transparent 70%),
    radial-gradient(80% 60% at 30% 100%, color-mix(in srgb, #30d158 20%, transparent), transparent 70%),
    var(--bg);
  transition: opacity 0.35s, transform 0.35s;
}
.gate.out { opacity: 0; transform: scale(1.04); pointer-events: none; }
.gate-card { width: min(380px, 100%); text-align: center; }
.gate-icon { width: 92px; height: 92px; margin: 0 auto 18px; border-radius: 22px; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2); }
.gate h1 { margin: 0 0 6px; font-size: 30px; }
.gate p { margin: 0 0 22px; color: var(--label-2); font-size: 16px; }
.gate .input { text-align: center; font-size: 22px; letter-spacing: 0.12em; font-weight: 600; margin-bottom: 12px; }
.gate .field-error { margin: -4px 0 12px; }
.shake { animation: shake 0.4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* ============ Scanner ============ */
.scanner {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: #000;
  color: #fff;
  opacity: 0;
  transition: opacity 0.25s;
}
.scanner.in { opacity: 1; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-shade {
  position: absolute;
  left: 7%; right: 7%;
  top: 30%;
  height: 20%;
  border-radius: 22px;
  box-shadow: 0 0 0 200vmax rgba(0, 0, 0, 0.55);
  pointer-events: none;
}
.scan-shade::before, .scan-shade::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 24px;
  border: 3px solid #fff;
  -webkit-mask: linear-gradient(#000 0 0) top left / 34px 34px no-repeat, linear-gradient(#000 0 0) top right / 34px 34px no-repeat, linear-gradient(#000 0 0) bottom left / 34px 34px no-repeat, linear-gradient(#000 0 0) bottom right / 34px 34px no-repeat;
  mask: linear-gradient(#000 0 0) top left / 34px 34px no-repeat, linear-gradient(#000 0 0) top right / 34px 34px no-repeat, linear-gradient(#000 0 0) bottom left / 34px 34px no-repeat, linear-gradient(#000 0 0) bottom right / 34px 34px no-repeat;
}
.scan-shade::after { border-color: rgba(255, 255, 255, 0.25); -webkit-mask: none; mask: none; border-width: 1px; }
.scan-line {
  position: absolute;
  left: 6%; right: 6%;
  height: 2px;
  top: 50%;
  background: linear-gradient(90deg, transparent, #34c759, transparent);
  box-shadow: 0 0 12px #34c759;
  animation: scanline 1.8s ease-in-out infinite;
}
@keyframes scanline { 0%, 100% { top: 15%; } 50% { top: 85%; } }
.scan-top, .scan-bottom { position: absolute; left: 0; right: 0; padding: 0 18px; display: flex; align-items: center; }
.scan-top { top: calc(var(--safe-top) + 12px); justify-content: space-between; }
.scan-bottom { bottom: calc(var(--safe-bottom) + 24px); flex-direction: column; gap: 14px; }
.scanner .round-btn { width: 44px; height: 44px; background: rgba(60, 60, 67, 0.55); color: #fff; -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.scanner .round-btn.on { background: #fff; color: #000; }
.scan-hint {
  position: absolute;
  left: 0; right: 0;
  top: calc(30% - 52px);
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
  padding: 0 24px;
}
.scan-status {
  min-height: 40px;
  padding: 9px 16px;
  border-radius: 20px;
  background: rgba(60, 60, 67, 0.55);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  font-size: 15px;
  text-align: center;
  max-width: 100%;
}
.scan-status .code { color: #fff; }
.scan-actions { display: flex; gap: 10px; }
.scan-actions .btn { width: auto; padding: 0 18px; height: 46px; border-radius: 23px; background: rgba(255, 255, 255, 0.92); color: #000; }

/* ============ Photo editor ============ */
.editor-stage {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  background: #fff;
  touch-action: none;
  margin: 0 auto 12px;
  max-height: 56vh;
  display: grid;
  place-items: center;
}
.editor-stage canvas { display: block; max-width: 100%; max-height: 56vh; }
.crop-box {
  position: absolute;
  border: 2px solid #fff;
  box-shadow: 0 0 0 200vmax rgba(0, 0, 0, 0.45);
  border-radius: 4px;
}
.crop-handle {
  position: absolute;
  width: 34px; height: 34px;
  margin: -17px 0 0 -17px;
  touch-action: none;
}
.crop-handle::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
}
.editor-busy {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.6);
  color: #000;
  font-weight: 600;
}
.slider-row { display: flex; align-items: center; gap: 12px; background: var(--bg-elev); border-radius: 14px; padding: 10px 16px; }
.slider-row label { font-size: 15px; white-space: nowrap; }
.slider-row input[type="range"] { flex: 1; accent-color: var(--accent); }

/* ============ Small things ============ */
.offline-pill {
  position: fixed;
  z-index: 35;
  top: calc(var(--safe-top) + 9px);
  left: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--label-2);
}
.offline-pill .ic { width: 16px; height: 16px; }
.update-bar {
  position: fixed;
  z-index: 45;
  left: 16px; right: 16px;
  bottom: calc(max(calc(var(--safe-bottom) - 6px), 14px) + var(--tabbar-h) + 12px);
  margin: 0 auto;
  max-width: 420px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 16px;
  border-radius: 20px;
  font-size: 15px;
  font-weight: 500;
}
.update-bar span { flex: 1; }
.update-bar .btn { width: auto; height: 36px; padding: 0 14px; border-radius: 18px; font-size: 15px; }
.muted { color: var(--label-2); }
.center { text-align: center; }

@media (min-width: 700px) {
  .swatch-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 14px; }
  .swatch { height: 92px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

.spinner {
  width: 34px; height: 34px;
  margin: 0 auto 14px;
  border-radius: 50%;
  border: 3px solid var(--fill);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
