:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --line: #e6e8ec;
  --text: #1c2330;
  --muted: #737b8c;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #eff4ff;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

input, textarea, button, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="search"],
textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  outline: none;
  /* 移动端关键：字号不能小于 16px，否则 iOS Safari 聚焦时会强制放大页面 */
  font-size: 16px;
  transition: border-color .15s, box-shadow .15s;
}

button, .chip, input, textarea, select {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

input:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

textarea { resize: vertical; min-height: 64px; }

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 9px 14px;
  transition: background .15s, border-color .15s, opacity .15s;
}

button:hover:not(:disabled) { background: #f7f8fa; }
button:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }

.btn-danger {
  background: #fff;
  border-color: #f3c7c7;
  color: var(--danger);
}

.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }

.btn-lg { padding: 15px 20px; font-size: 17px; border-radius: 12px; width: 100%; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

.field { margin-bottom: 18px; }

.field label {
  display: block;
  font-weight: 600;
  margin-bottom: 7px;
  font-size: 14px;
}

.field label .opt {
  font-weight: 400;
  color: var(--muted);
  font-size: 13px;
}

.alert {
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 14px;
  margin-bottom: 14px;
  border: 1px solid transparent;
  display: none;
}

.alert.show { display: block; }
.alert-error { background: var(--danger-soft); border-color: #f6cccc; color: #991b1b; }
.alert-ok { background: var(--ok-soft); border-color: #bfe8d5; color: #065f46; }
.alert-warn { background: var(--warn-soft); border-color: #f6e0b0; color: #92400e; }

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(17, 23, 34, .55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 50;
}

.modal-mask.show { display: flex; }

.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 860px;
  max-height: 92vh;
  overflow: auto;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .28);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 2;
  border-radius: 16px 16px 0 0;
}

.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px 20px 22px; }

.x-close {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  padding: 4px 8px;
  color: var(--muted);
}

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
}

.thumb {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #f2f3f5;
  aspect-ratio: 1 / 1;
}

.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.thumb .del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(17, 23, 34, .72);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

@media print {
  body { background: #fff; }
  body.printing-qr > *:not(#qrModal) { display: none !important; }
  #qrModal { position: static; background: none; display: block !important; padding: 0; }
  #qrModal .modal { box-shadow: none; max-width: 640px; margin: 0 auto; }
  #qrModal .no-print { display: none !important; }
}

/* ---------------------------------------------------------------- 移动端适配 */
@media (max-width: 860px) {
  /* 触控目标不小于 42px，手指点得准 */
  button, .chip {
    min-height: 42px;
  }

  .chip {
    display: inline-flex;
    align-items: center;
  }

  input[type="text"],
  input[type="password"],
  input[type="date"],
  input[type="search"],
  textarea,
  select {
    min-height: 46px;
    font-size: 16px;   /* 防止 iOS 聚焦缩放 */
  }

  /* 刘海屏底部安全区 */
  body {
    padding-bottom: env(safe-area-inset-bottom);
  }

  .modal {
    max-height: 88vh;
    border-radius: 14px;
  }

  .modal-body {
    padding: 16px 16px 24px;
  }

  .modal-actions button {
    flex: 1 1 auto;
  }
}

/* 小屏手机（360px 及以下）再收一点间距 */
@media (max-width: 400px) {
  .quick button {
    padding: 9px 11px;
    font-size: 13px;
  }

  .thumb-grid {
    grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  }
}
