/* ============================================================
   iOS Design System for 丹智慧眼
   参考：Apple Human Interface Guidelines (iOS 17)
   ============================================================ */

/* ---------- Design Tokens ---------- */
:root {
  /* System Colors (light) */
  --ios-blue:        #007AFF;
  --ios-green:       #34C759;
  --ios-indigo:      #5856D6;
  --ios-orange:      #FF9500;
  --ios-pink:        #FF2D55;
  --ios-purple:      #AF52DE;
  --ios-red:         #FF3B30;
  --ios-teal:        #5AC8FA;
  --ios-yellow:      #FFCC00;
  --ios-gray:        #8E8E93;
  --ios-gray2:       #AEAEB2;
  --ios-gray3:       #C7C7CC;
  --ios-gray4:       #D1D1D6;
  --ios-gray5:       #E5E5EA;
  --ios-gray6:       #F2F2F7;

  /* Backgrounds */
  --bg-primary:      #FFFFFF;
  --bg-secondary:    #F2F2F7;
  --bg-tertiary:     #FFFFFF;
  --bg-grouped:      #F2F2F7;
  --bg-elevated:     #FFFFFF;

  /* Labels */
  --label-primary:   #000000;
  --label-secondary: rgba(60,60,67,0.60);
  --label-tertiary:  rgba(60,60,67,0.30);
  --label-quaternary: rgba(60,60,67,0.18);

  /* Separators */
  --separator:       rgba(60,60,67,0.29);
  --separator-opaque: #C6C6C8;

  /* Fills */
  --fill-primary:    rgba(120,120,128,0.20);
  --fill-secondary:  rgba(120,120,128,0.16);
  --fill-tertiary:   rgba(118,118,128,0.12);
  --fill-quaternary: rgba(116,116,128,0.08);

  /* Typography */
  --font-system: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
                 "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --font-rounded: -apple-system-rounded, ui-rounded, "SF Pro Rounded", var(--font-system);

  /* Font Sizes (iOS Type Ramp) */
  --fs-large-title: 34px;
  --fs-title1:      28px;
  --fs-title2:      22px;
  --fs-title3:      20px;
  --fs-headline:    17px;
  --fs-body:        17px;
  --fs-callout:     16px;
  --fs-subhead:     15px;
  --fs-footnote:    13px;
  --fs-caption1:    12px;
  --fs-caption2:    11px;

  /* Radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;
  --r-pill: 999px;

  /* Shadows */
  --shadow-1: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.06);
  --shadow-2: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-3: 0 8px 28px rgba(0,0,0,0.14);

  /* Layout */
  --nav-height: 44px;
  --nav-large-height: 96px;
  --tab-height: 83px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast: 0.18s;
  --dur-base: 0.28s;
  --dur-slow: 0.42s;
}

/* ---------- Reset ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-system);
  font-size: var(--fs-body);
  line-height: 1.4;
  color: var(--label-primary);
  background: var(--bg-grouped);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.022em;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
a { color: var(--ios-blue); text-decoration: none; }
img { display: block; max-width: 100%; }
ul, ol { list-style: none; }

/* ---------- App Shell ---------- */
.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg-grouped);
  position: relative;
  padding-bottom: calc(var(--tab-height) + var(--safe-bottom));
}
.app--no-tab { padding-bottom: 0; }

/* ---------- Navigation Bar ---------- */
.navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--nav-height);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  background: rgba(248,248,248,0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
}
.navbar__title {
  font-size: var(--fs-headline);
  font-weight: 600;
  letter-spacing: -0.4px;
}
.navbar__leading,
.navbar__trailing {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}
.navbar__leading  { left: 8px; }
.navbar__trailing { right: 8px; }
.navbar__btn {
  font-size: var(--fs-body);
  color: var(--ios-blue);
  padding: 6px 8px;
  border-radius: var(--r-sm);
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.navbar__btn:active { opacity: 0.5; }
.navbar__btn--icon {
  width: 32px;
  height: 32px;
  justify-content: center;
  padding: 0;
}

/* Large Title style */
.large-title {
  padding: 4px 20px 12px;
  background: var(--bg-grouped);
}
.large-title h1 {
  font-size: var(--fs-large-title);
  font-weight: 700;
  letter-spacing: -0.8px;
}
.large-title p {
  margin-top: 4px;
  font-size: var(--fs-subhead);
  color: var(--label-secondary);
}

/* ---------- Tab Bar ---------- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: calc(var(--tab-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: rgba(248,248,248,0.86);
  backdrop-filter: saturate(180%) blur(28px);
  -webkit-backdrop-filter: saturate(180%) blur(28px);
  border-top: 0.5px solid var(--separator);
  z-index: 40;
}
.tabbar__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--ios-gray);
  font-size: 10px;
  letter-spacing: 0;
  transition: color var(--dur-fast);
}
.tabbar__item svg { width: 26px; height: 26px; }
.tabbar__item.is-active { color: var(--ios-blue); }
.tabbar__item:active { opacity: 0.6; }

/* ---------- Sections / Lists (iOS Grouped Inset) ---------- */
.section {
  margin: 16px 0 8px;
  padding: 0 20px;
}
.section__title {
  font-size: var(--fs-footnote);
  text-transform: uppercase;
  color: var(--label-secondary);
  letter-spacing: 0.3px;
  margin-bottom: 6px;
  padding-left: 4px;
}
.section__footer {
  margin-top: 6px;
  padding: 0 4px;
  font-size: var(--fs-footnote);
  color: var(--label-secondary);
}

.list {
  background: var(--bg-elevated);
  border-radius: var(--r-lg);
  overflow: hidden;
  margin: 0 16px;
  box-shadow: var(--shadow-1);
}
.list__row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  min-height: 44px;
  background: var(--bg-elevated);
  position: relative;
  transition: background var(--dur-fast);
}
.list__row + .list__row::before {
  content: "";
  position: absolute;
  top: 0; left: 16px; right: 0;
  height: 0.5px;
  background: var(--separator);
}
.list__row.is-link:active { background: var(--fill-quaternary); }
.list__row-icon {
  width: 28px; height: 28px;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.list__row-text { flex: 1; min-width: 0; }
.list__row-title {
  font-size: var(--fs-body);
  color: var(--label-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list__row-subtitle {
  font-size: var(--fs-footnote);
  color: var(--label-secondary);
  margin-top: 2px;
}
.list__row-value {
  font-size: var(--fs-body);
  color: var(--label-secondary);
  flex-shrink: 0;
}
.list__row-chevron {
  color: var(--ios-gray3);
  flex-shrink: 0;
  width: 8px;
  height: 13px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-elevated);
  border-radius: var(--r-lg);
  padding: 16px;
  margin: 0 16px;
  box-shadow: var(--shadow-1);
}
.card + .card { margin-top: 12px; }
.card__title {
  font-size: var(--fs-title3);
  font-weight: 600;
  letter-spacing: -0.45px;
}
.card__subtitle {
  font-size: var(--fs-subhead);
  color: var(--label-secondary);
  margin-top: 4px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 50px;
  padding: 0 22px;
  border-radius: var(--r-lg);
  font-size: var(--fs-headline);
  font-weight: 600;
  letter-spacing: -0.4px;
  transition: transform var(--dur-fast) var(--ease-out),
              background var(--dur-fast),
              opacity var(--dur-fast);
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); opacity: 0.85; }
.btn--filled {
  background: var(--ios-blue);
  color: #fff;
}
.btn--tinted {
  background: rgba(0,122,255,0.12);
  color: var(--ios-blue);
}
.btn--gray {
  background: var(--fill-tertiary);
  color: var(--label-primary);
}
.btn--plain {
  background: transparent;
  color: var(--ios-blue);
  height: 44px;
}
.btn--destructive {
  background: var(--ios-red);
  color: #fff;
}
.btn--block { width: 100%; }
.btn--sm { height: 34px; padding: 0 14px; font-size: var(--fs-subhead); border-radius: var(--r-md); }
.btn--xs { height: 28px; padding: 0 12px; font-size: var(--fs-footnote); border-radius: var(--r-md); }
.btn[disabled], .btn.is-disabled { opacity: 0.4; pointer-events: none; }

/* ---------- Inputs ---------- */
.input,
.textarea {
  width: 100%;
  background: var(--fill-quaternary);
  border: none;
  border-radius: var(--r-md);
  padding: 12px 14px;
  font-size: var(--fs-body);
  color: var(--label-primary);
  outline: none;
  transition: background var(--dur-fast);
}
.input:focus, .textarea:focus { background: var(--fill-tertiary); }
.input::placeholder, .textarea::placeholder { color: var(--label-tertiary); }
.textarea { resize: vertical; min-height: 88px; }

.field { margin-bottom: 12px; }
.field__label {
  font-size: var(--fs-footnote);
  color: var(--label-secondary);
  margin-bottom: 6px;
  padding-left: 4px;
}

/* Search bar (iOS) */
.searchbar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--fill-tertiary);
  border-radius: var(--r-md);
  padding: 8px 10px;
  margin: 0 16px 12px;
}
.searchbar svg { width: 16px; height: 16px; color: var(--label-secondary); flex-shrink: 0; }
.searchbar input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: var(--fs-callout);
  color: var(--label-primary);
}
.searchbar input::placeholder { color: var(--label-secondary); }

/* ---------- Segmented Control ---------- */
.segmented {
  display: flex;
  background: var(--fill-tertiary);
  border-radius: 9px;
  padding: 2px;
  margin: 0 16px 12px;
  position: relative;
}
.segmented__item {
  flex: 1;
  text-align: center;
  padding: 7px 8px;
  font-size: var(--fs-subhead);
  font-weight: 500;
  color: var(--label-primary);
  border-radius: 7px;
  transition: all var(--dur-fast);
  position: relative;
  z-index: 1;
}
.segmented__item.is-active {
  background: #fff;
  font-weight: 600;
  box-shadow: 0 3px 8px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
}

/* ---------- Chips / Pills / Badges ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--fill-tertiary);
  color: var(--label-primary);
  border-radius: var(--r-pill);
  font-size: var(--fs-footnote);
  white-space: nowrap;
}
.chip--blue   { background: rgba(0,122,255,0.12);  color: var(--ios-blue); }
.chip--green  { background: rgba(52,199,89,0.14);  color: var(--ios-green); }
.chip--orange { background: rgba(255,149,0,0.14);  color: var(--ios-orange); }
.chip--red    { background: rgba(255,59,48,0.12);  color: var(--ios-red); }

.badge {
  display: inline-flex;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--ios-red);
  color: #fff;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  align-items: center;
  justify-content: center;
}

/* ---------- Toast / Banner ---------- */
.toast {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  min-width: 220px;
  max-width: 90%;
  padding: 12px 18px;
  background: rgba(40,40,42,0.92);
  backdrop-filter: blur(20px);
  color: #fff;
  border-radius: var(--r-pill);
  font-size: var(--fs-subhead);
  box-shadow: var(--shadow-3);
  opacity: 0;
  z-index: 10000;
  transition: opacity var(--dur-base), transform var(--dur-base) var(--ease-spring);
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast--success { background: rgba(52,199,89,0.95); }
.toast--error   { background: rgba(255,59,48,0.95); }

/* ---------- Action Sheet / Bottom Sheet ---------- */
.sheet-mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  opacity: 0;
  z-index: 100;
  pointer-events: none;
  transition: opacity var(--dur-base);
}
.sheet-mask.is-show { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  width: 100%;
  max-width: 480px;
  background: var(--bg-elevated);
  border-radius: 16px 16px 0 0;
  z-index: 101;
  transition: transform var(--dur-base) var(--ease-out);
  padding-bottom: var(--safe-bottom);
  max-height: 85vh;
  overflow-y: auto;
}
.sheet.is-show { transform: translateX(-50%) translateY(0); }
.sheet__handle {
  width: 36px; height: 5px;
  background: var(--ios-gray3);
  border-radius: 3px;
  margin: 8px auto 4px;
}
.sheet__header {
  padding: 12px 20px;
  border-bottom: 0.5px solid var(--separator);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sheet__title { font-size: var(--fs-headline); font-weight: 600; }
.sheet__body { padding: 16px 20px; }

/* ---------- Alert (centered modal) ---------- */
.alert-mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.alert-mask.is-show { display: flex; }
.alert {
  width: 270px;
  background: rgba(252,252,252,0.92);
  backdrop-filter: blur(20px);
  border-radius: 14px;
  overflow: hidden;
  animation: alert-pop var(--dur-base) var(--ease-spring);
}
@keyframes alert-pop {
  from { opacity: 0; transform: scale(1.18); }
  to   { opacity: 1; transform: scale(1); }
}
.alert__body {
  padding: 20px 16px 18px;
  text-align: center;
}
.alert__title { font-size: var(--fs-headline); font-weight: 600; }
.alert__msg {
  margin-top: 4px;
  font-size: var(--fs-footnote);
  color: var(--label-primary);
  line-height: 1.4;
}
.alert__actions {
  display: flex;
  border-top: 0.5px solid var(--separator);
}
.alert__btn {
  flex: 1;
  padding: 12px 8px;
  font-size: var(--fs-body);
  color: var(--ios-blue);
  background: transparent;
  border: none;
  cursor: pointer;
}
.alert__btn + .alert__btn { border-left: 0.5px solid var(--separator); }
.alert__btn--bold { font-weight: 600; }
.alert__btn--destructive { color: var(--ios-red); }
.alert__btn:active { background: rgba(0,0,0,0.06); }

/* ---------- Spinner (iOS-style activity indicator) ---------- */
.spinner {
  width: 20px;
  height: 20px;
  position: relative;
  display: inline-block;
}
.spinner::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid var(--fill-secondary);
  border-top-color: var(--ios-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner--lg { width: 32px; height: 32px; }
.spinner--lg::before { border-width: 3px; }
.spinner--white::before { border-color: rgba(255,255,255,0.3); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Skeleton ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--fill-tertiary) 25%, var(--fill-secondary) 50%, var(--fill-tertiary) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.4s infinite;
  border-radius: var(--r-sm);
}
@keyframes skeleton { 0%{background-position:200% 0;} 100%{background-position:-200% 0;} }

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--label-secondary);
}
.empty__icon {
  width: 56px; height: 56px;
  margin: 0 auto 12px;
  opacity: 0.5;
}
.empty__text { font-size: var(--fs-callout); }

/* ---------- Utility ---------- */
.row    { display: flex; align-items: center; }
.col    { display: flex; flex-direction: column; }
.gap-4  { gap: 4px; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.flex-1 { flex: 1; min-width: 0; }
.between{ justify-content: space-between; }
.mt-8   { margin-top: 8px; }
.mt-16  { margin-top: 16px; }
.mt-24  { margin-top: 24px; }
.mb-8   { margin-bottom: 8px; }
.mb-16  { margin-bottom: 16px; }
.text-secondary { color: var(--label-secondary); }
.text-tertiary  { color: var(--label-tertiary); }
.text-blue   { color: var(--ios-blue); }
.text-red    { color: var(--ios-red); }
.text-green  { color: var(--ios-green); }
.text-bold   { font-weight: 600; }
.fs-footnote { font-size: var(--fs-footnote); }
.fs-subhead  { font-size: var(--fs-subhead); }
.fs-headline { font-size: var(--fs-headline); font-weight: 600; }
.fs-title2   { font-size: var(--fs-title2); font-weight: 600; letter-spacing: -0.5px; }
.fs-title3   { font-size: var(--fs-title3); font-weight: 600; letter-spacing: -0.45px; }
.text-center { text-align: center; }
.hidden { display: none !important; }

/* ---------- Product Grid (mall) ---------- */
.product-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 0 16px;
}
.product-card {
  background: var(--bg-elevated);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-1);
  display: flex;
  flex-direction: column;
  transition: transform var(--dur-fast);
}
.product-card:active { transform: scale(0.98); }
.product-card__img {
  aspect-ratio: 1 / 1;
  background: var(--bg-secondary);
  display: flex; align-items: center; justify-content: center;
  font-size: 48px;
  color: var(--ios-gray2);
  overflow: hidden;
}
.product-card__img img { width: 100%; height: 100%; object-fit: cover; }
.product-card__body { padding: 10px 12px 12px; flex: 1; display: flex; flex-direction: column; }
.product-card__name {
  font-size: var(--fs-subhead);
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
  min-height: 36px;
}
.product-card__tags {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.product-card__price {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.product-card__price-num {
  font-size: var(--fs-headline);
  font-weight: 700;
  color: var(--ios-red);
}
.product-card__price-num::before { content: "¥"; font-size: 12px; font-weight: 500; }
.product-card__add {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--ios-blue);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.product-card__add:active { transform: scale(0.92); }

/* ---------- Stat tiles (admin) ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 0 16px;
}
.stat-tile {
  background: var(--bg-elevated);
  padding: 14px;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}
.stat-tile__label {
  font-size: var(--fs-footnote);
  color: var(--label-secondary);
}
.stat-tile__value {
  font-size: var(--fs-title1);
  font-weight: 700;
  letter-spacing: -0.6px;
  margin-top: 4px;
}
.stat-tile__delta {
  margin-top: 4px;
  font-size: var(--fs-caption1);
  color: var(--ios-green);
}
