:root {
  --primary: #5e8c1b;      /* 青柠芒果主题绿（价格/主按钮） */
  --primary-light: #9ccc65;/* 渐变末端浅柠绿 */
  --primary-grad: linear-gradient(135deg, #5e8c1b, #9ccc65);
  --primary-soft: #f1f6e7; /* 浅柠底 */
  --primary-deep: #4a6f14; /* 深一档，用于小字标签 */
  --accent: #f4700c;       /* 辅助橙（AI 按钮/参考图区） */
  --bg: #f7f9f2;
  --card: #fff;
  --line: #e4ecd8;
  --text: #333;
  --muted: #999;
  --wrap: 820px; /* 顶栏/标签页/内容共用的居中宽度 */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  /* 宽屏时左右留白撑大，让顶栏内容与下方 820px 内容对齐；窄屏回落到 14px */
  padding: 10px max(14px, calc((100% - var(--wrap)) / 2 + 12px));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

header h1 { font-size: 17px; margin: 0; }

header input[type="date"] {
  width: 150px;
  flex: 0 0 auto;
}

.tabs {
  max-width: var(--wrap);
  margin: 12px auto -2px;
  padding: 0 12px;
  display: flex;
  gap: 8px;
}

.tab {
  flex: 1;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
}

.tab.on {
  background: var(--primary-grad);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* 标签行右侧的「🔒 管理」：保持内容宽度，不和两个标签抢空间 */
.tabs .mgr-toggle { flex: 0 0 auto; }

main {
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 12px 12px 60px;
  display: grid;
  gap: 12px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.panel h2 { font-size: 15px; margin: 0 0 10px; }

.list { display: grid; gap: 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}

.card.pending { border-color: #f2c94c; }

.card .muted, .muted { color: var(--muted); }

/* 卡片头部：时间段 + 客户 + 配送标签 + 价格（右对齐） */
.card .head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
}

.card .head .slot {
  color: var(--primary);
  font-weight: 700;
  font-size: 16px;
}

.card .head .cust {
  font-weight: 700;
  font-size: 16px;
}

.card .head .dtype {
  font-size: 11px;
  background: var(--primary-soft);
  color: var(--primary-deep);
  border-radius: 999px;
  padding: 2px 9px;
  align-self: center;
}

.card .head .price {
  margin-left: auto;
  font-weight: 600;
  font-size: 14px;
}

/* 取货日期小标签（全部订单视图下用于区分日期；今天/明天/后天额外高亮） */
.card .head .date-chip {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
  align-self: center;
}

.card .head .date-chip .rel {
  color: var(--primary);
  font-weight: 700;
  margin-right: 4px;
}

/* 尺寸/口味是第二视觉焦点 */
.card .line.main { font-size: 15px; font-weight: 500; margin: 10px 0 4px; line-height: 1.5; }
.card .line { font-size: 13px; margin: 7px 0; line-height: 1.55; }
.card .muted, .muted { color: var(--muted); }

/* 图片通栏排列，左对齐，不再挤在角落 */
.card .thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-start;
  margin: 12px 0 4px;
}

.card .ops {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

.card .tag {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
}

button.link {
  border: 0;
  background: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
}
button.link.del { color: #c0392b; }

.empty { color: var(--muted); text-align: center; margin: 8px 0; }

.ai-box {
  background: var(--primary-soft);
  border-radius: 10px;
  padding: 10px;
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.dropzone {
  min-height: 110px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  padding: 14px 12px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.dropzone .zt { font-size: 15px; font-weight: 600; color: var(--text); }
.dropzone .hint { font-size: 13px; }
/* 两个上传区用颜色区分，防止拖错位置：聊天截图=青柠绿，参考图=辅助橙 */
.dropzone.shots { border-color: var(--primary); }
.dropzone.shots .zt { color: var(--primary); }
.dropzone.refs { border-color: var(--accent); }
.dropzone.refs .zt { color: #d95f08; }
.dropzone.focus { border-color: var(--primary); }
.dropzone.drag { background: var(--primary-soft); border-color: var(--primary); }
.dropzone.drag .zt { color: var(--primary); }

.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; justify-content: center; }
.thumbs:empty { display: none; }

.thumb { position: relative; width: 76px; height: 76px; }
.thumbs.small .thumb { width: 96px; height: 96px; }
/* 订单卡片里的缩略图没有 .thumb 容器，直接约束 img */
.thumbs.small img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
  cursor: zoom-in;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; display: block; }

.thumb .rm {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .65);
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
}

.chips { line-height: 1.9; }

.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 4px 12px;
  margin: 0 6px 6px 0;
  font-size: 13px;
  cursor: pointer;
}

.chip.on { background: var(--primary-grad); border-color: var(--primary); color: #fff; }

/* 口味管理模式：chip 带 × 删除钮，可拖动排序 */
.chip.mgr { touch-action: none; cursor: grab; padding-right: 7px; }
.chip.mgr:active { cursor: grabbing; }
.chip.dragging {
  box-shadow: 0 4px 14px rgba(0, 0, 0, .28);
  opacity: .92;
}
.chip-rm {
  margin-left: 7px;
  color: #c0392b;
  font-weight: 700;
  font-size: 14px;
}
.chip.on .chip-rm { color: #fff; }

.head-right { display: flex; align-items: center; gap: 8px; }
.admin-link { text-decoration: none; font-size: 15px; opacity: .65; }
.admin-link:hover { opacity: 1; }

.flavor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.flavor-head label { margin: 10px 0 2px; }

.mgr-toggle {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

.mgr-toggle.on {
  border-color: var(--primary);
  color: var(--primary);
}

#btnAllDates.on {
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.flavor-add { display: flex; gap: 6px; max-width: 260px; }
.flavor-add input { flex: 1; }
.flavor-add button {
  width: 34px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
}

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0 2px;
}

/* 字段行下方的小字提示：说明放这里，标签保持两个字，避免长标签把一行里的输入框挤错位 */
.field-hint {
  font-size: 12px;
  color: var(--muted);
  margin: 2px 0 4px;
  line-height: 1.6;
}

input, textarea, select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}

input:focus, textarea:focus { outline: 1px solid var(--primary); border-color: var(--primary); }

.row {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

textarea { resize: vertical; }

#chatText { background: #fff; }

button.ai {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 14px;
  cursor: pointer;
}
button.ai.off { opacity: .5; }
button.ai:disabled { opacity: .6; cursor: wait; }

.actions { display: flex; gap: 10px; margin-top: 14px; }

button.primary {
  background: var(--primary-grad);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 22px;
  font-size: 15px;
  cursor: pointer;
}

#btnReset {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 9px 16px;
  border-radius: 8px;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
  max-width: 86vw;
  font-size: 13px;
}

#toast.show { opacity: 1; }
#toast.err { background: #c0392b; }

/* ---------- 大图查看器（双指捏合 / 滚轮 / 双击缩放，拖动平移） ---------- */

#lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(10, 10, 10, .92);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

#lightbox[hidden] { display: none; }

#lightboxImg {
  max-width: 100%;
  max-height: 100%;
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
  cursor: grab;
}

#lbClose {
  position: absolute;
  top: 12px;
  right: 16px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, .18);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
}

#lbClose:active { background: rgba(255, 255, 255, .35); }

/* 手机：防快速点按触发双击缩放（口味管理模式 .chip.mgr 的 touch-action:none 优先级更高，拖动排序不受影响） */
button, .chip { touch-action: manipulation; }

@media (max-width: 520px) {
  .row { grid-template-columns: 1fr 1fr; }

  /* 顶栏：标题缩小不换行，挤不下时允许换行兜底（320px 小屏） */
  header { flex-wrap: wrap; padding-left: 10px; padding-right: 10px; row-gap: 6px; }
  header h1 { font-size: 14px; white-space: nowrap; }
  header input[type="date"] { width: 128px; }
  .mgr-toggle { padding: 4px 9px; }
  .tab { padding: 10px 6px; }

  /* iOS Safari：输入控件字号 <16px 聚焦时会强制放大页面，统一 16px 避免 */
  input, select, textarea { font-size: 16px; }

  /* 触屏点按目标加大：编辑/删除、口味 chips、缩略图移除钮 */
  .card .ops { gap: 20px; }
  button.link { font-size: 14px; padding: 8px 4px; margin: -8px 0; }
  .chip { padding: 6px 14px; }
  .thumb .rm { width: 22px; height: 22px; font-size: 14px; line-height: 22px; }

  main { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
}

/* ---------- 密码弹层（页内卡片式，替代浏览器 prompt） ---------- */
.pw-overlay {
  position: fixed; inset: 0; z-index: 999;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.pw-card {
  background: #fff; border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
  padding: 20px; width: min(340px, 100%);
}
.pw-card h3 { margin: 0 0 6px; font-size: 16px; color: var(--text); }
.pw-card .pw-hint { margin: 0 0 12px; font-size: 12px; color: var(--muted); }
.pw-card input {
  width: 100%; padding: 12px;
  border: 1px solid var(--line); border-radius: 8px;
  font-size: 16px; /* iOS 聚焦防缩放 */
  -webkit-appearance: none; appearance: none;
}
.pw-card input:focus { outline: none; border-color: var(--primary); }
.pw-err { display: none; margin-top: 8px; font-size: 12px; color: #d0021b; }
.pw-err.show { display: block; }
.pw-actions { display: flex; gap: 10px; margin-top: 14px; }
.pw-actions button {
  flex: 1; min-height: 44px; border: 0; border-radius: 8px;
  font-size: 14px; cursor: pointer; padding: 0;
}
.pw-ok { background: var(--primary-grad); color: #fff; }
.pw-cancel { background: #e9ece4; color: #666; }
