/* ===== 基础变量 ===== */
:root {
  --primary: #c8281c;
  --primary-hover: #a51e15;
  --primary-soft: #fceaea;
  --bg: #fafafa;
  --card-bg: #ffffff;
  --border: #e5e5e5;
  --text: #1f1f1f;
  --text-soft: #6b6b6b;
  --text-faint: #9a9a9a;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  --radius: 10px;
  --max-w: 1100px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; }
input { font-family: inherit; font-size: 14px; }

/* ===== 顶栏 ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 24px; }
.brand h1 { margin: 0; font-size: 17px; font-weight: 600; }

/* ===== 主容器 ===== */
.container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 20px 16px 80px;
}

/* ===== 卡片 ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ===== 上传区 ===== */
.upload-card { padding: 0; overflow: hidden; }
.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  border: 2px dashed #d9d9d9;
  border-radius: var(--radius);
  margin: 20px;
  cursor: pointer;
  transition: all 0.2s;
  background: #fafafa;
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.dz-inner { text-align: center; padding: 40px 20px; pointer-events: none; }
.dz-icon { font-size: 56px; margin-bottom: 8px; }
.dz-title { margin: 0 0 6px; font-size: 16px; font-weight: 500; }
.dz-tip { margin: 0; color: var(--text-faint); font-size: 12px; }

.status {
  margin: 0 20px 20px;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
}
.status.error { background: #fff1f0; color: #a8071a; border: 1px solid #ffa39e; }
.status.info { background: #e6f4ff; color: #003a8c; border: 1px solid #91caff; }

/* ===== 编辑区 ===== */
.edit-grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 24px;
}
.preview-pane { display: flex; flex-direction: column; }
.preview-frame {
  background: #f0f0f0;
  border-radius: 8px;
  overflow: hidden;
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 100px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-frame img { width: 100%; height: auto; display: block; }
.preview-tip { margin: 8px 2px 0; color: var(--text-faint); font-size: 12px; }

.form-pane h2.form-title {
  margin: 0 0 14px;
  font-size: 16px;
  color: var(--primary);
  border-left: 3px solid var(--primary);
  padding-left: 10px;
}
.form-pane h3.form-subtitle {
  margin: 18px 0 10px;
  font-size: 14px;
  color: var(--text-soft);
}

.meta-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}
.meta-row.total-row { margin-top: 18px; }
.meta-row .span-2 { grid-column: span 1; }
.meta-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-soft); }
.meta-row input {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.meta-row input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(200,40,28,0.12); }

/* ===== 菜品表格 ===== */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 480px;
}
.items-table th, .items-table td {
  padding: 6px 6px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.items-table th {
  background: #fafafa;
  font-weight: 500;
  color: var(--text-soft);
  font-size: 12px;
  white-space: nowrap;
}
.items-table tr:last-child td { border-bottom: none; }
.items-table input {
  width: 100%;
  padding: 6px 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  outline: none;
  color: var(--text);
}
.items-table input:hover { border-color: var(--border); }
.items-table input:focus { border-color: var(--primary); background: #fff; }
.items-table td.del-col { text-align: center; }
.items-table .del-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  border-radius: 4px;
}
.items-table .del-btn:hover { color: var(--primary); background: var(--primary-soft); }

.row-actions {
  display: flex;
  gap: 8px;
  margin: 10px 0 0;
}

/* ===== 按钮 ===== */
.primary, .ghost {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 500;
}
.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.primary:active { transform: translateY(1px); }
.primary:disabled { background: #ccc; border-color: #ccc; cursor: not-allowed; }

.ghost {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}
.ghost:hover { color: var(--primary); border-color: var(--primary); }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
.form-actions .primary { min-width: 160px; padding: 11px 18px; font-size: 15px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 100;
  max-width: 80vw;
  text-align: center;
}

/* ===== Loading ===== */
.loading {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 50;
  gap: 12px;
}
/* 关键：[hidden] 优先级要高于 .loading 的 display: flex */
.loading[hidden] {
  display: none;
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #f0f0f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.loading-text { color: var(--text-soft); font-size: 14px; }
.loading-text .timer { font-variant-numeric: tabular-nums; color: var(--primary); font-weight: 500; margin-left: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 底部 ===== */
.footer {
  text-align: center;
  padding: 16px;
  color: var(--text-faint);
  font-size: 12px;
}

/* ===== 响应式：手机端 ===== */
@media (max-width: 768px) {
  .container { padding: 12px 10px 60px; }
  .topbar { padding: 12px 14px; }
  .brand h1 { font-size: 15px; }
  .card { padding: 14px; }
  .edit-grid { grid-template-columns: 1fr; gap: 16px; }
  .preview-frame { position: static; max-height: 50vh; }
  .meta-row { grid-template-columns: 1fr; }
  .dropzone { min-height: 220px; margin: 12px; }
  .dz-inner { padding: 28px 16px; }
  .dz-icon { font-size: 44px; }
  .items-table { font-size: 12px; }
  .form-actions { justify-content: stretch; }
  .form-actions .primary { flex: 1; min-width: 0; }
}

/* ===== 顶部 Tabs ===== */
.tabs {
  display: flex;
  gap: 4px;
  align-items: center;
  background: var(--bg);
  border-radius: 8px;
  padding: 3px;
}
.tab {
  background: transparent;
  border: none;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text-soft);
  cursor: pointer;
  border-radius: 6px;
  font-weight: 500;
  transition: all 0.15s;
}
.tab:hover { color: var(--primary); }
.tab.active {
  background: var(--card-bg);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
.tab-pane { animation: fadein 0.2s; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ===== 勾选生成页 ===== */
.builder-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 16px;
  align-items: start;
}
.builder-left { padding: 14px; position: sticky; top: 80px; max-height: calc(100vh - 100px); display: flex; flex-direction: column; }
.builder-header {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.builder-header input[type="search"] {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
}
.builder-header input[type="search"]:focus { border-color: var(--primary); }

.builder-categories { overflow-y: auto; flex: 1; padding-right: 4px; }
.cat-block { margin-bottom: 14px; }
.cat-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 4px 10px;
  border-radius: 4px;
  margin-bottom: 6px;
  display: inline-block;
}
.dish-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
}
.dish-item:hover { background: var(--bg); }
.dish-item.checked { background: var(--primary-soft); }
.dish-item .checkbox {
  width: 18px; height: 18px;
  border: 1.5px solid var(--border);
  border-radius: 3px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: #fff;
}
.dish-item.checked .checkbox {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.dish-item .checkbox::after {
  content: "✓";
  font-size: 12px;
  font-weight: 700;
  display: none;
}
.dish-item.checked .checkbox::after { display: block; }
.dish-item .dish-name { flex: 1; font-size: 14px; }
.dish-item .dish-price { color: var(--text-soft); font-size: 13px; font-variant-numeric: tabular-nums; }
.dish-item .dish-qty {
  width: 44px;
  padding: 3px 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-align: center;
  font-size: 12px;
  display: none;
}
.dish-item.checked .dish-qty { display: block; }

/* ===== 右侧已选 + 表单 ===== */
.builder-right { display: flex; flex-direction: column; gap: 14px; }
.builder-summary { padding: 14px; }
.empty-hint { color: var(--text-faint); font-size: 13px; padding: 30px 0; text-align: center; }
.selected-list { list-style: none; margin: 0; padding: 0; }
.selected-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 4px;
  border-bottom: 1px dashed var(--border);
  font-size: 13px;
}
.selected-list li:last-child { border-bottom: none; }
.selected-list .name { flex: 1; }
.selected-list .qty { color: var(--text-soft); font-variant-numeric: tabular-nums; }
.selected-list .amount { color: var(--primary); font-weight: 500; font-variant-numeric: tabular-nums; min-width: 60px; text-align: right; }
.selected-list .remove {
  border: none; background: transparent; color: var(--text-faint); cursor: pointer; font-size: 16px; padding: 0 4px;
}
.selected-list .remove:hover { color: var(--primary); }
.selected-total { margin-top: 12px; padding-top: 10px; border-top: 2px solid var(--primary); }
.total-line { display: flex; justify-content: space-between; font-size: 15px; }
.total-line b { color: var(--primary); font-size: 17px; font-variant-numeric: tabular-nums; }

.builder-form { padding: 14px; }
.builder-form .meta-row { grid-template-columns: 1fr 1fr; }
.builder-form .full-row { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-soft); margin-bottom: 10px; }
.builder-form .full-row input {
  padding: 9px 10px; border: 1px solid var(--border); border-radius: 6px; outline: none; background: #fff;
}
.builder-form .full-row input:focus { border-color: var(--primary); }

/* ===== 菜品库管理页 ===== */
.library-header {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; flex-wrap: wrap;
}
.library-actions { display: flex; gap: 8px; align-items: center; }
.library-actions input[type="search"] {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; outline: none; width: 160px;
}
.library-actions select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; outline: none; background: #fff;
}
.lib-count { font-size: 13px; color: var(--text-soft); font-weight: 400; margin-left: 4px; }
.lib-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 760px; }
.lib-table th, .lib-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.lib-table th { background: #fafafa; font-size: 12px; color: var(--text-soft); font-weight: 500; }
.lib-table tr:hover td { background: #fafafa; }
.lib-table .status-on { color: #389e0d; font-size: 12px; }
.lib-table .status-off { color: var(--text-faint); font-size: 12px; }
.lib-table .row-actions-inline { display: flex; gap: 4px; }
.lib-table .mini-btn {
  background: #fff; border: 1px solid var(--border); padding: 3px 8px; border-radius: 4px;
  font-size: 12px; cursor: pointer; color: var(--text-soft);
}
.lib-table .mini-btn:hover { color: var(--primary); border-color: var(--primary); }
.lib-table .mini-btn.danger:hover { color: #c8281c; border-color: #c8281c; }

/* ===== 弹窗 ===== */
.modal {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
}
.modal[hidden] { display: none; }
.modal-mask { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.4); }
.modal-body {
  position: relative; width: min(440px, 92vw); padding: 20px;
  max-height: 90vh; overflow-y: auto;
}
.modal-body h3 { margin: 0 0 14px; font-size: 16px; color: var(--primary); }
.modal-body .meta-row { grid-template-columns: 1fr 1fr; }
.modal-body .full-row { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-soft); margin: 10px 0; }
.modal-body .full-row input,
.modal-body .meta-row input,
.modal-body .meta-row select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; outline: none; background: #fff;
}
.modal-body .full-row input:focus,
.modal-body .meta-row input:focus,
.modal-body .meta-row select:focus { border-color: var(--primary); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }

/* 小按钮 */
.small { padding: 6px 12px !important; font-size: 13px !important; }

/* ===== 响应式：手机端 ===== */
@media (max-width: 900px) {
  .builder-grid { grid-template-columns: 1fr; }
  .builder-left { position: static; max-height: 60vh; }
  .tabs .tab { padding: 6px 10px; font-size: 12px; }
  .lib-table { font-size: 12px; }
}
