/* 拾光票根 — Semantic fallback + helpers + shared components */

/* 全局默认缩放 75%（安卓手机浏览器比例） */
html { zoom: 0.75; }

/* SPA 页面切换 */
.sg-page { display: none; }
.sg-page.is-active { display: block; }
.sg-page.is-active > * { animation: sg-page-in 0.22s ease; }
@keyframes sg-page-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 票根编号固定前缀 */
.sg-uid-prefix {
  padding: 0 4px 0 12px;
  height: 44px;
  display: flex;
  align-items: center;
  font-size: 15px;
  color: var(--sg-muted-foreground);
  background: var(--sg-muted);
  border: 1px solid var(--sg-border);
  border-right: none;
  border-radius: var(--sg-radius-medium) 0 0 var(--sg-radius-medium);
  white-space: nowrap;
}
.sg-uid-prefix + .sg-input {
  border-radius: 0 var(--sg-radius-medium) var(--sg-radius-medium) 0;
}

/* Semantic token fallback (matches Tailwind semantic utilities) */
.bg-background { background-color: var(--sg-background); }
.text-background { color: var(--sg-background); }
.border-background { border-color: var(--sg-background); }
.bg-foreground { background-color: var(--sg-foreground); }
.text-foreground { color: var(--sg-foreground); }
.border-foreground { border-color: var(--sg-foreground); }
.bg-card { background-color: var(--sg-card); }
.text-card { color: var(--sg-card); }
.border-card { border-color: var(--sg-card); }
.bg-card-foreground { background-color: var(--sg-card-foreground); }
.text-card-foreground { color: var(--sg-card-foreground); }
.border-card-foreground { border-color: var(--sg-card-foreground); }
.bg-popover { background-color: var(--sg-popover); }
.text-popover { color: var(--sg-popover); }
.border-popover { border-color: var(--sg-popover); }
.bg-popover-foreground { background-color: var(--sg-popover-foreground); }
.text-popover-foreground { color: var(--sg-popover-foreground); }
.border-popover-foreground { border-color: var(--sg-popover-foreground); }
.bg-primary { background-color: var(--sg-primary); }
.text-primary { color: var(--sg-primary); }
.border-primary { border-color: var(--sg-primary); }
.bg-primary-foreground { background-color: var(--sg-primary-foreground); }
.text-primary-foreground { color: var(--sg-primary-foreground); }
.border-primary-foreground { border-color: var(--sg-primary-foreground); }
.bg-muted { background-color: var(--sg-muted); }
.text-muted { color: var(--sg-muted); }
.border-muted { border-color: var(--sg-muted); }
.bg-muted-foreground { background-color: var(--sg-muted-foreground); }
.text-muted-foreground { color: var(--sg-muted-foreground); }
.border-muted-foreground { border-color: var(--sg-muted-foreground); }
.bg-border { background-color: var(--sg-border); }
.text-border { color: var(--sg-border); }
.border-border { border-color: var(--sg-border); }
.bg-input { background-color: var(--sg-input); }
.text-input { color: var(--sg-input); }
.border-input { border-color: var(--sg-input); }
.bg-ring { background-color: var(--sg-ring); }
.text-ring { color: var(--sg-ring); }
.border-ring { border-color: var(--sg-ring); }

/* opacity helpers (used in design via primary/10, muted/50 etc.) */
.bg-primary\/10 { background-color: color-mix(in srgb, var(--sg-primary) 10%, transparent); }
.bg-primary\/5 { background-color: color-mix(in srgb, var(--sg-primary) 5%, transparent); }
.bg-muted\/50 { background-color: color-mix(in srgb, var(--sg-muted) 50%, transparent); }
.bg-muted\/40 { background-color: color-mix(in srgb, var(--sg-muted) 40%, transparent); }
.bg-card\/90 { background-color: color-mix(in srgb, var(--sg-card) 90%, transparent); }
.bg-card\/80 { background-color: color-mix(in srgb, var(--sg-card) 80%, transparent); }
.bg-background\/80 { background-color: color-mix(in srgb, var(--sg-background) 80%, transparent); }
.bg-foreground\/5 { background-color: color-mix(in srgb, var(--sg-foreground) 5%, transparent); }
.ring-primary\/20 { --tw-ring-color: color-mix(in srgb, var(--sg-primary) 20%, transparent); }
.text-muted-foreground\/50 { color: color-mix(in srgb, var(--sg-muted-foreground) 50%, transparent); }
.text-muted-foreground\/70 { color: color-mix(in srgb, var(--sg-muted-foreground) 70%, transparent); }
.text-primary\/80 { color: color-mix(in srgb, var(--sg-primary) 80%, transparent); }

/* Helpers */
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

[data-icon] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  background-color: currentColor;
}

/* Keep form inputs at 16px to prevent iOS auto-zoom on focus */
.sg-input, input.sg-input { font-size: 16px; }
@media (min-width: 480px) {
  .sg-input, input.sg-input { font-size: 15px; }
}

/* ============ Shared app components ============ */

/* Bottom navigation — 浮动胶囊式（参考 ji-gongshi 项目） */
.sg-nav {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  pointer-events: auto;
}
.sg-nav-inner {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--sg-card) 80%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  border: 1px solid var(--sg-border);
  border-radius: 999px;
  padding: 10px 10px;
  gap: 4px;
}

.sg-nav-link {
  padding: 11px 18px;
  font-size: 15px;
  color: var(--sg-muted-foreground);
  transition: all 0.2s ease;
  border-radius: 999px;
  text-decoration: none;
  white-space: nowrap;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.sg-nav-link:active { transform: scale(0.92); }
.sg-nav-link.is-active {
  color: #fff;
  font-weight: 600;
  background: linear-gradient(135deg, var(--sg-primary), var(--sg-primary-light, var(--sg-primary)));
  box-shadow: 0 2px 8px color-mix(in srgb, var(--sg-primary) 30%, transparent);
}
.sg-nav-link span { font-size: 15px; font-weight: inherit; line-height: 1; white-space: nowrap; }
.sg-nav-link.is-active span { font-weight: 600; }

/* Toast */
.sg-toast-wrap {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: calc(100px + var(--sg-safe-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: 90vw;
}

.sg-toast {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--sg-radius-full);
  background-color: var(--sg-popover);
  color: var(--sg-popover-foreground);
  border: 1px solid var(--sg-border);
  box-shadow: var(--sg-shadow-lg);
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: auto;
}

.sg-toast.is-show { opacity: 1; transform: translateY(0) scale(1); }
.sg-toast .sg-toast-icon { display: inline-flex; }
.sg-toast-success .sg-toast-icon { color: var(--sg-state-success); }
.sg-toast-error .sg-toast-icon { color: var(--sg-state-error); }
.sg-toast-info .sg-toast-icon { color: var(--sg-state-info); }

/* Modal / overlay */
.sg-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: color-mix(in srgb, var(--sg-gray-900) 45%, transparent);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

.sg-overlay.is-open { opacity: 1; visibility: visible; }

.sg-overlay-panel {
  width: 100%;
  max-width: 420px;
  max-height: 88vh;
  overflow: auto;
  border-radius: var(--sg-radius-large);
  background: var(--sg-popover);
  border: 1px solid var(--sg-border);
  box-shadow: var(--sg-shadow-lg);
  transform: translateY(16px) scale(0.98);
  transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

.sg-overlay.is-open .sg-overlay-panel { transform: translateY(0) scale(1); }

/* Segmented control */
.sg-segment {
  display: inline-flex;
  padding: 3px;
  border-radius: var(--sg-radius-full);
  background: var(--sg-muted);
  border: 1px solid var(--sg-border);
  gap: 2px;
}

.sg-segment-btn {
  border: 0;
  background: transparent;
  color: var(--sg-muted-foreground);
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--sg-radius-full);
  padding: 6px 14px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}

.sg-segment-btn.is-active { background: var(--sg-card); color: var(--sg-primary); box-shadow: var(--sg-shadow-sm); }

/* Switch */
.sg-switch {
  position: relative;
  display: inline-flex;
  width: 46px;
  height: 28px;
  border-radius: var(--sg-radius-full);
  background: var(--sg-border);
  cursor: pointer;
  transition: background 0.2s ease;
  flex-shrink: 0;
  border: 0;
}

.sg-switch[aria-checked="true"] { background: var(--sg-primary); }

.sg-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--sg-white);
  box-shadow: var(--sg-shadow-sm);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.sg-switch[aria-checked="true"]::after { transform: translateX(18px); }

/* Force light "paper" surface while keeping per-ticket theme hue.
   Used on history cards / detail panel so tickets always read as light
   paper even when the app chrome is in dark mode. */
.sg-light-surface {
  --sg-card: var(--sg-white);
  --sg-popover: var(--sg-white);
  --sg-input: var(--sg-white);
  --sg-muted: var(--sg-gray-50);
  --sg-muted-foreground: var(--sg-blue-400);
}

/* Swatch selected ring */
.sg-swatch {
  width: 32px;
  height: 32px;
  border-radius: var(--sg-radius-full);
  border: 1px solid var(--sg-border);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.sg-swatch:active { transform: scale(0.9); }
.sg-swatch.is-active { border-color: var(--sg-primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--sg-primary) 20%, transparent); }

/* Setting row */
.sg-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--sg-border);
}

.sg-row:last-child { border-bottom: 0; }
.sg-row-label { font-size: 15px; color: var(--sg-foreground); }
.sg-row-sub { font-size: 13px; color: var(--sg-muted-foreground); }

/* Generic pressable feedback */
.sg-pressable { transition: transform 0.15s ease; }
.sg-pressable:active { transform: scale(0.97); }

/* Focus ring for keyboard */
.sg-focusable:focus-visible { outline: 2px solid var(--sg-ring); outline-offset: 2px; }

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