:root {
  --bg: #EEF1F4;
  --surface: #FFFFFF;
  --surface-2: #E6EBF0;
  --surface-3: #DCE3EA;
  --text: #2C3A45;
  --text-sec: #6E7C88;
  --accent: #6B8299;
  --accent-dark: #4F6577;
  --border: #DCE3EA;
  --green: #7DA57D;
  --orange: #D4A056;
  --red: #C66B6B;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(44, 58, 69, 0.08);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro", "Inter", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: none;
}

#app {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100%;
  position: relative;
  background: var(--bg);
}

.page {
  display: none;
  padding: 16px 16px calc(120px + env(safe-area-inset-bottom)) 16px;
  animation: fadeIn 0.18s ease;
}

.page.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-header {
  padding: 8px 0 16px;
}

.page-header h1 {
  margin: 0;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.header-with-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-sec);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn:active { background: var(--surface-2); }

.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-bottom: 14px;
  color: var(--text-sec);
}

.search-bar input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--text);
  outline: none;
}

.search-bar input::placeholder {
  color: var(--text-sec);
}

.chips {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 16px;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-sec);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.temp-filter {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 16px;
}

.temp-filter-label {
  display: block;
  font-size: 13px;
  color: var(--text-sec);
  margin-bottom: 10px;
}

.temp-inputs, .range-inputs {
  display: flex;
  align-items: center;
  gap: 10px;
}

.temp-inputs input, .range-inputs input {
  width: 80px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 16px;
  color: var(--text);
  text-align: center;
}

.temp-sep { color: var(--text-sec); font-weight: 500; }
.temp-unit { color: var(--text-sec); font-size: 14px; margin-left: 4px; }

.food-filter {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 16px;
}
.food-filter-label {
  display: block;
  font-size: 13px;
  color: var(--text-sec);
  margin-bottom: 10px;
}
.food-filter .chips {
  margin-bottom: 0;
}

/* 作品列表 */
.date-group {
  margin-bottom: 22px;
}

.date-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-sec);
  margin-bottom: 12px;
  font-weight: 500;
}

.works-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.work-card {
  background: var(--surface-2);
  border-radius: var(--radius-md);
  overflow: hidden;
  aspect-ratio: 1 / 1;
  position: relative;
  cursor: pointer;
  border: 1px solid var(--border);
}

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

.work-card .placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-sec);
}

.work-card .placeholder svg {
  width: 42%;
  height: 42%;
  opacity: 0.5;
}

.work-card-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 6px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  background: linear-gradient(to top, rgba(61,50,38,0.55), transparent);
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.work-check {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid var(--border);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.work-check svg { width: 14px; height: 14px; stroke: #fff; display: none; }
#page-works.selecting .work-check { display: flex; }
#page-works.selecting .work-card { -webkit-touch-callout: none; user-select: none; }
.work-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.work-card.selected .work-check { background: var(--accent); border-color: var(--accent); }
.work-card.selected .work-check svg { display: block; }

.empty-state {
  text-align: center;
  color: var(--text-sec);
  padding: 48px 20px;
  font-size: 15px;
}

/* 原料卡片 */
.materials-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.material-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  cursor: pointer;
}

.material-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-sec);
  flex-shrink: 0;
}

.material-icon svg { width: 24px; height: 24px; }

.material-info { flex: 1; min-width: 0; overflow: hidden; }
.material-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}
.material-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-sec);
  flex-wrap: wrap;
}

.material-card > svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.material-tag {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
}
.material-safe {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.material-safe.yes {
  color: var(--green);
  border-color: var(--green);
  background: rgba(125, 165, 125, 0.12);
}
.material-safe.no {
  color: var(--text-sec);
}
.material-card > svg {
  color: var(--text-sec);
  flex-shrink: 0;
}

.material-card {
  position: relative;
}

.material-thumb {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-sec);
}

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

.material-thumb.empty svg {
  width: 22px;
  height: 22px;
  opacity: 0.5;
}

.mat-check {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid var(--border);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.mat-check svg { width: 14px; height: 14px; stroke: #fff; display: none; }
#page-materials.selecting .mat-check { display: flex; }
#page-materials.selecting .material-card { -webkit-touch-callout: none; user-select: none; }
.material-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.material-card.selected .mat-check { background: var(--accent); border-color: var(--accent); }
.material-card.selected .mat-check svg { display: block; }

/* 表单 */
.form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 20px;
}

.form-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.text-btn {
  background: transparent;
  border: none;
  font-size: 16px;
  color: var(--text-sec);
  cursor: pointer;
  padding: 6px 4px;
}

.text-btn.primary {
  color: var(--accent);
  font-weight: 600;
}

.form-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
}

.form-label {
  display: block;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
}

input[type="text"],
input[type="date"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 16px;
  color: var(--text);
  outline: none;
  font-family: inherit;
}

input::placeholder, textarea::placeholder { color: #B0A89B; }

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238B7E6E' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.category-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
}

.cat-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 4px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-sec);
  font-size: 12px;
  cursor: pointer;
}

.cat-tab.active {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--accent);
}

.stock-options {
  display: flex;
  gap: 10px;
}

.stock-option {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-sec);
  font-size: 14px;
  cursor: pointer;
}

.stock-option.active {
  border-color: var(--green);
  background: rgba(125, 165, 125, 0.12);
  color: var(--text);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.photo-add-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font-size: 16px;
  font-weight: 500;
  background: transparent;
  border: none;
  padding: 4px 0 10px;
  cursor: pointer;
}

.photo-preview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.photo-thumb {
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

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

.photo-thumb .remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(61,50,38,0.6);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.delete-btn {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--red);
  background: rgba(198, 107, 107, 0.08);
  color: var(--red);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 6px;
}

/* 底部导航 */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 10px 20px calc(10px + env(safe-area-inset-bottom)) 20px;
  z-index: 50;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: transparent;
  border: none;
  color: var(--text-sec);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px;
}

.tab-item.active {
  color: var(--accent);
}

.fab {
  position: fixed;
  bottom: calc(68px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  z-index: 60;
  cursor: pointer;
}

.fab:active { transform: translateX(-50%) scale(0.96); }

.batch-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  background: var(--accent-dark);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom)) 20px;
  z-index: 70;
  box-shadow: 0 -4px 16px rgba(44, 58, 69, 0.18);
}
.batch-cancel {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.92);
  font-size: 16px;
  cursor: pointer;
  padding: 6px 4px;
}
.batch-delete {
  background: #fff;
  color: var(--accent-dark);
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  padding: 10px 22px;
  cursor: pointer;
}
.batch-delete.disabled { opacity: 0.45; }

.hidden { display: none !important; }
