/* ============================================
   表单管理系统 - 主样式文件
   ============================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --primary-light: #818cf8;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --dark: #1e293b;
  --gray: #64748b;
  --gray-light: #e2e8f0;
  --bg: #f1f5f9;
  --white: #ffffff;
  --sidebar-w: 240px;
  --header-h: 60px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', sans-serif; font-size: 14px; color: var(--dark); background: var(--bg); line-height: 1.6; }

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* ---- 登录页 ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.login-box { background: var(--white); border-radius: 16px; padding: 48px 40px; width: 400px; box-shadow: var(--shadow-lg); }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo h1 { font-size: 24px; color: var(--dark); font-weight: 700; }
.login-logo p { color: var(--gray); font-size: 13px; margin-top: 4px; }

/* ---- 布局 ---- */
.layout { display: flex; min-height: 100vh; }

/* 侧边栏 */
.sidebar { width: var(--sidebar-w); background: var(--dark); color: #cbd5e1; flex-shrink: 0; display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh; z-index: 100; overflow-y: auto; }
.sidebar-brand { padding: 20px 20px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-brand h2 { font-size: 16px; color: var(--white); font-weight: 700; }
.sidebar-brand p { font-size: 11px; color: #94a3b8; margin-top: 2px; }
.sidebar-nav { padding: 12px 0; flex: 1; }
.nav-section { padding: 8px 20px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #475569; font-weight: 600; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 20px; color: #94a3b8; transition: all .15s; cursor: pointer; }
.nav-item:hover, .nav-item.active { color: var(--white); background: rgba(255,255,255,.06); }
.nav-item.active { border-left: 3px solid var(--primary-light); background: rgba(79,70,229,.2); color: var(--white); }
.nav-item svg { flex-shrink: 0; width: 16px; height: 16px; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; color: #64748b; }

/* 主内容区 */
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.header { height: var(--header-h); background: var(--white); border-bottom: 1px solid var(--gray-light); display: flex; align-items: center; justify-content: space-between; padding: 0 28px; position: sticky; top: 0; z-index: 50; box-shadow: var(--shadow); }
.header-title { font-size: 16px; font-weight: 600; color: var(--dark); }
.header-right { display: flex; align-items: center; gap: 16px; }
.content { padding: 28px; flex: 1; }

/* ---- 卡片 ---- */
.card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--gray-light); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 15px; font-weight: 600; color: var(--dark); }
.card-body { padding: 20px; }

/* ---- 统计卡片 ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 24px; }
.stat-card { background: var(--white); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 16px; }
.stat-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-icon.blue { background: #dbeafe; color: var(--info); }
.stat-icon.green { background: #d1fae5; color: var(--success); }
.stat-icon.purple { background: #ede9fe; color: var(--primary); }
.stat-icon.orange { background: #ffedd5; color: var(--warning); }
.stat-num { font-size: 24px; font-weight: 700; color: var(--dark); }
.stat-label { font-size: 12px; color: var(--gray); margin-top: 2px; }

/* ---- 表格 ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th { background: #f8fafc; padding: 12px 16px; text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--gray); font-weight: 600; border-bottom: 1px solid var(--gray-light); white-space: nowrap; }
tbody td { padding: 13px 16px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f8fafc; }

/* ---- 表单元素 ---- */
.form-group { margin-bottom: 20px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--dark); margin-bottom: 6px; }
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-control { width: 100%; padding: 9px 12px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 14px; color: var(--dark); background: var(--white); transition: border-color .15s, box-shadow .15s; outline: none; }
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.1); }
.form-control::placeholder { color: #94a3b8; }
textarea.form-control { min-height: 80px; resize: vertical; }
select.form-control { cursor: pointer; }
.form-hint { font-size: 12px; color: var(--gray); margin-top: 4px; }
.form-row { display: grid; gap: 16px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ---- 按钮 ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 8px; font-size: 13px; font-weight: 500; cursor: pointer; border: none; transition: all .15s; white-space: nowrap; text-decoration: none; }
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-dark); color: var(--white); }
.btn-success { background: var(--success); color: var(--white); }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-warning { background: var(--warning); color: var(--white); }
.btn-info { background: var(--info); color: var(--white); }
.btn-secondary { background: var(--gray-light); color: var(--dark); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-outline { background: transparent; border: 1px solid var(--gray-light); color: var(--dark); }
.btn-outline:hover { background: var(--gray-light); }

/* ---- 徽章 ---- */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-warning { background: #fef3c7; color: #92400e; }

/* ---- 提示消息 ---- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 20px; font-size: 13px; display: flex; align-items: flex-start; gap: 10px; }
.alert-success { background: #d1fae5; color: #065f46; border-left: 4px solid var(--success); }
.alert-danger  { background: #fee2e2; color: #991b1b; border-left: 4px solid var(--danger); }
.alert-info    { background: #dbeafe; color: #1e40af; border-left: 4px solid var(--info); }

/* ---- 字段构建器 ---- */
#field-builder { }
.field-item { background: #f8fafc; border: 1px solid var(--gray-light); border-radius: 8px; padding: 16px; margin-bottom: 12px; position: relative; }
.field-item-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; cursor: move; }
.field-item-title { font-weight: 600; color: var(--dark); font-size: 13px; }
.drag-handle { color: #94a3b8; cursor: grab; }
.field-add-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

/* ---- 分页 ---- */
.pagination { display: flex; align-items: center; gap: 4px; margin-top: 20px; }
.page-item a, .page-item span { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 8px; font-size: 13px; border: 1px solid var(--gray-light); color: var(--dark); transition: all .15s; }
.page-item.active span { background: var(--primary); color: var(--white); border-color: var(--primary); }
.page-item a:hover { background: var(--primary); color: var(--white); border-color: var(--primary); }

/* ---- 模态框 ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px; opacity: 0; pointer-events: none; transition: opacity .2s; }
.modal-overlay.show { opacity: 1; pointer-events: all; }
.modal { background: var(--white); border-radius: 12px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); transform: scale(.95); transition: transform .2s; }
.modal-overlay.show .modal { transform: scale(1); }
.modal-header { padding: 20px 24px 16px; border-bottom: 1px solid var(--gray-light); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close { width: 28px; height: 28px; border-radius: 6px; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--gray); border: none; background: transparent; font-size: 18px; }
.modal-close:hover { background: var(--gray-light); }
.modal-body { padding: 20px 24px; }
.modal-footer { padding: 16px 24px 20px; display: flex; justify-content: flex-end; gap: 8px; }

/* ---- 代码块 ---- */
.code-block { background: #1e293b; color: #e2e8f0; padding: 16px; border-radius: 8px; font-family: 'SFMono-Regular', Consolas, monospace; font-size: 12px; line-height: 1.6; overflow-x: auto; white-space: pre; }

/* ---- 图片上传预览 ---- */
.img-upload-wrap { border: 2px dashed var(--gray-light); border-radius: 8px; padding: 24px; text-align: center; cursor: pointer; transition: border-color .15s; position: relative; }
.img-upload-wrap:hover { border-color: var(--primary); }
.img-preview { max-width: 100%; max-height: 180px; border-radius: 8px; margin-top: 12px; display: block; }

/* ============================================
   前台表单 — 响应式完整样式
   支持：手机(≤480) / 平板(≤768) / 桌面(>768)
   ============================================ */

/* 页面背景 */
body.public-body {
  background: linear-gradient(160deg, #eef2ff 0%, #f1f5f9 60%);
  min-height: 100vh;
}

/* 外层容器 */
.public-wrap {
  max-width: 680px;
  margin: 0 auto;
  padding: 32px 20px 80px;
  width: 100%;
}

/* 广告横幅 */
.form-banner {
  margin-bottom: 20px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.form-banner img {
  width: 100%;
  display: block;
  border-radius: 12px;
  object-fit: cover;
}
.form-banner a { display: block; }

/* 主卡片 */
.public-card {
  background: var(--white);
  border-radius: 16px;
  padding: 36px 40px;
  box-shadow: 0 4px 24px rgba(79,70,229,.08), 0 1px 4px rgba(0,0,0,.06);
}

/* 表单标题 */
.public-card h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--dark);
  margin-bottom: 6px;
  line-height: 1.35;
}
.public-card .desc {
  color: var(--gray);
  font-size: 14px;
  line-height: 1.7;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--gray-light);
}

/* 字段组 — 前台 */
.public-card .form-group {
  margin-bottom: 20px;
}
.public-card .form-label {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 7px;
  color: var(--dark);
}

/* 输入框 — 手机触控优化 */
.public-card .form-control {
  font-size: 16px; /* 阻止 iOS 自动缩放 */
  padding: 11px 14px;
  border-radius: 10px;
  border: 1.5px solid #cbd5e1;
  transition: border-color .18s, box-shadow .18s;
  -webkit-appearance: none;
  appearance: none;
  background: #fafbfc;
}
.public-card .form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
  background: var(--white);
}
.public-card textarea.form-control {
  min-height: 100px;
  resize: vertical;
}
.public-card select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  cursor: pointer;
}

/* 单选/多选组 */
.checkbox-group, .radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}
.checkbox-group label,
.radio-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  background: #f8fafc;
  border: 1.5px solid var(--gray-light);
  border-radius: 8px;
  padding: 8px 14px;
  transition: border-color .15s, background .15s;
  user-select: none;
  -webkit-user-select: none;
}
.checkbox-group label:hover,
.radio-group label:hover {
  border-color: var(--primary-light);
  background: #f0f0ff;
}
.checkbox-group input[type="checkbox"],
.radio-group input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

/* 文件上传 */
.public-card input[type="file"].form-control {
  padding: 8px 12px;
  background: #f8fafc;
  cursor: pointer;
  font-size: 14px;
}

/* 提交按钮 */
.submit-btn {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  margin-top: 12px;
  transition: background .18s, transform .1s, box-shadow .18s;
  letter-spacing: .02em;
  -webkit-tap-highlight-color: transparent;
}
.submit-btn:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(79,70,229,.3);
}
.submit-btn:active {
  transform: scale(.98);
}
.submit-btn:disabled {
  opacity: .6;
  cursor: not-allowed;
  transform: none;
}

/* 成功状态 */
.success-icon {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, #d1fae5, #a7f3d0);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  font-size: 40px;
  box-shadow: 0 4px 16px rgba(16,185,129,.2);
}

/* 错误提示 */
.public-card .alert-danger {
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.6;
  flex-direction: column;
  gap: 4px;
}

/* 必填星号 */
.public-card .form-label span[style*="danger"] {
  margin-left: 2px;
}

/* ---- 平板适配 (≤ 768px) ---- */
@media (max-width: 768px) {
  .public-wrap {
    padding: 20px 12px 60px;
  }
  .public-card {
    padding: 24px 20px;
    border-radius: 14px;
  }
  .public-card h1 {
    font-size: 20px;
  }
  .form-banner {
    border-radius: 10px;
    margin-bottom: 14px;
  }
  .form-banner img {
    border-radius: 10px;
  }
}

/* ---- 手机适配 (≤ 480px) ---- */
@media (max-width: 480px) {
  .public-wrap {
    padding: 12px 0 60px;
  }
  .public-card {
    padding: 20px 16px;
    border-radius: 0;          /* 手机全宽无圆角 */
    box-shadow: none;
    border-top: 1px solid var(--gray-light);
    border-bottom: 1px solid var(--gray-light);
  }
  .public-card h1 {
    font-size: 18px;
  }
  .public-card .desc {
    font-size: 13px;
    margin-bottom: 20px;
    padding-bottom: 14px;
  }
  .form-banner {
    border-radius: 0;
    margin-bottom: 0;
    box-shadow: none;
  }
  .form-banner img {
    border-radius: 0;
  }
  /* 单选/多选在手机上竖排 */
  .checkbox-group,
  .radio-group {
    flex-direction: column;
    gap: 8px;
  }
  .checkbox-group label,
  .radio-group label {
    width: 100%;
    padding: 10px 14px;
    font-size: 15px;
  }
  .submit-btn {
    padding: 15px;
    font-size: 16px;
    border-radius: 8px;
  }
  .public-card .form-group {
    margin-bottom: 18px;
  }
  /* 成功页手机适配 */
  .success-icon {
    width: 64px;
    height: 64px;
    font-size: 32px;
  }
  /* 再次填写按钮 */
  .public-card .btn-outline {
    width: 100%;
    justify-content: center;
    padding: 12px;
  }
}

/* ---- 扫条形码字段 ---- */
.barcode-wrap {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.barcode-wrap .form-control {
  flex: 1;
  min-width: 0;   /* 防止 flex 子项撑破容器 */
  width: auto;    /* 覆盖 .form-control width:100% */
}
.btn-scan {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex-shrink: 0;
  padding: 0 16px;
  min-width: 76px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, opacity .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-scan:hover  { background: var(--primary-dark); }
.btn-scan:active { opacity: .8; }
.btn-scan svg    { flex-shrink: 0; }

/* 扫码全屏遮罩 */
#scanner-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.92);
  z-index: 9999;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#scanner-overlay.active { display: flex; }
#scanner-box {
  position: relative;
  width: 100%;
  max-width: 440px;
  border-radius: 12px;
  overflow: hidden;
}
#scanner-video {
  width: 100%;
  display: block;
  border-radius: 12px;
  background: #000;
}
#scanner-line {
  position: absolute;
  left: 8%;
  right: 8%;
  height: 2px;
  background: rgba(79,70,229,.9);
  box-shadow: 0 0 6px rgba(79,70,229,.7);
  animation: scan-move 2s linear infinite;
  pointer-events: none;
}
@keyframes scan-move {
  0%   { top: 10%; }
  50%  { top: 88%; }
  100% { top: 10%; }
}
#scanner-tip {
  color: #fff;
  font-size: 13px;
  margin-top: 14px;
  opacity: .75;
}
#scanner-close {
  margin-top: 18px;
  padding: 10px 36px;
  border-radius: 8px;
  border: none;
  background: #fff;
  color: #111;
  font-size: 15px;
  cursor: pointer;
  font-weight: 500;
}

/* ---- 搜索栏 ---- */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.search-input { padding: 8px 12px; border: 1px solid var(--gray-light); border-radius: 8px; font-size: 13px; outline: none; min-width: 220px; }
.search-input:focus { border-color: var(--primary); }

/* ---- 响应式 ---- */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .main { margin-left: 0; }
  .form-row.cols-2, .form-row.cols-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
