/* ═══ 手作计算器 · iOS HIG ═══ */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --ink: #1c1c1e;
  --ink-soft: #3c3c43;
  --muted: #8e8e93;
  --accent: #8b5e3c;
  --accent-light: #c9a574;
  --accent-bg: rgba(139, 94, 60, 0.08);
  --border: #e5e5ea;
  --separator: rgba(60, 60, 67, 0.12);
  --danger: #ff3b30;
  --radius-card: 10pt;
  --radius-btn: 8pt;
  --nav-h: 44px;
  --tab-h: 49px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --shadow: none;
}
html { -webkit-text-size-adjust: 100%; }

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px var(--accent-bg);
}
html, body { height: 100%; }
body {
  font-family: -apple-system, "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 640px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }

/* ── Nav Bar 44pt ── */
.app-header {
  position: sticky; top: 0; z-index: 50;
  height: calc(var(--nav-h) + var(--safe-top));
  padding: var(--safe-top) 16px 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(242, 242, 247, 0.85);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 0.5px solid var(--separator);
}
.app-header h1 { font-size: 17px; font-weight: 600; color: var(--ink); letter-spacing: -0.2px; }
.view-subtitle { display: none; }
.help-btn {
  position: absolute; right: 12px;
  top: calc(var(--safe-top) + var(--nav-h) / 2); transform: translateY(-50%);
  width: 28px; height: 28px; border-radius: 50%;
  border: 1.5px solid var(--muted); background: none;
  color: var(--accent); font-size: 15px; font-weight: 700;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-family: inherit;
}
.help-btn:active { background: var(--accent-bg); }

/* ── 主区 ── */
#main { flex: 1; padding: 12px 12px calc(76px + var(--safe-bottom)); }
.view { display: none; }
.view.active { display: block; }

/* ── 操作条（吸顶）── */
.action-bar {
  position: sticky; top: calc(var(--nav-h) + var(--safe-top)); z-index: 40;
  margin: 0 -12px 10px; padding: 8px 12px;
  background: rgba(242, 242, 247, 0.94);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
}
.action-seg {
  display: flex; gap: 0;
  background: rgba(255,255,255,0.92);
  border-radius: 12px;
  overflow: hidden; margin: 0;
  border: 0.5px solid var(--separator);
}
.seg-action {
  flex: 1; padding: 9px 0; border: none; background: none;
  font-size: 13px; font-family: inherit; color: var(--accent);
  cursor: pointer; border-right: 0.5px solid var(--separator);
  text-align: center;
}
.seg-action:last-child { border-right: none; }
.seg-action:active { background: var(--accent-bg); }
.seg-action.seg-primary { color: var(--accent); font-weight: 600; }

/* ── 卡片 ── */
.card {
  background: var(--card); border-radius: var(--radius-card);
  padding: 14px; margin-bottom: 10px;
  border: 0.5px solid var(--separator);
}
.card-title { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.3px; }

/* ── 按钮 ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 14px; min-height: 36px;
  border: none; border-radius: var(--radius-btn);
  background: var(--accent-bg); color: var(--accent);
  font-size: 14px; font-family: inherit; cursor: pointer;
}
.btn:active { opacity: 0.7; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { display: flex; width: 100%; margin-top: 10px; }
.btn-dashed { border: 1px dashed var(--accent-light); color: var(--accent); background: none; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; min-height: 46px; padding: 8px 4px; font-size: 15px; }

/* ── 配方卡 ── */
.recipe-title { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.recipe-label { font-size: 12px; color: var(--muted); }
.recipe-name { font-size: 17px; font-weight: 600; color: var(--ink); }

/* ── 行 ── */
.spice-row, .oil-row, .lipbalm-row {
  display: flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 4px 0;
  border-bottom: 0.5px solid var(--separator);
}
.spice-row:last-child, .oil-row:last-child, .lipbalm-row:last-child { border-bottom: none; }
.row-idx { font-size: 13px; color: var(--muted); width: 20px; flex-shrink: 0; text-align: center; }
.row-name { flex: 1; font-size: 15px; font-weight: 400; word-break: break-all; }
.row-weight { position: relative; flex-shrink: 0; }
.row-weight input {
  width: 88px; padding: 8px 26px 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-btn);
  font-size: 15px; font-family: inherit; text-align: right;
  background: var(--bg);
}
.row-weight::after { content: "g"; position: absolute; right: 9px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--muted); pointer-events: none; }
.row-del {
  width: 32px; height: 32px; flex-shrink: 0;
  border: none; background: none; color: var(--muted);
  font-size: 18px; cursor: pointer; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.row-del:active { background: var(--accent-bg); color: var(--danger); }
.empty-hint { text-align: center; color: var(--muted); font-size: 13px; padding: 14px 0; }

/* ── 结果大数字 ── */
.result-card { background: var(--card); }
.big-row { display: flex; justify-content: space-between; align-items: center; min-height: 44px; padding: 2px 0; border-bottom: 0.5px solid var(--separator); }
.big-row:last-child { border-bottom: none; }
.big-label { font-size: 15px; color: var(--ink); }
.big-val { text-align: right; }
.big-val b { font-size: 17px; font-weight: 600; color: var(--ink); }
.big-val i { font-style: normal; font-size: 12px; color: var(--muted); margin-left: 3px; }

/* ── 缩进明细（三计算器统一：行高 44 / 16px 缩进 / 行行分隔线）── */
.indent-detail { padding: 0; }
.indent-detail .detail-cat {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 500; color: var(--ink);
  padding: 4px 0; min-height: 44px;
  border-bottom: 0.5px solid var(--separator);
}
.indent-detail .detail-cat .dc-val { font-size: 15px; font-weight: 600; color: var(--ink); }
.indent-detail .detail-item {
  font-size: 14px; color: var(--ink);
  padding: 4px 0 4px 16px;
  display: flex; justify-content: space-between; align-items: center;
  min-height: 44px;
  border-bottom: 0.5px solid var(--separator);
}
.indent-detail .detail-item .di-val { color: var(--ink-soft); font-weight: 500; }
.indent-detail .detail-item .di-val i { font-style: normal; font-size: 11px; color: var(--muted); margin-left: 2px; }

/* ── 百分比条 ── */
.pct-bars .pct-row { margin-bottom: 12px; }
.pct-row .pct-head { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; color: var(--ink); }
.pct-row .pct-head b { color: var(--accent); font-weight: 600; }
.pct-bar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.pct-bar .pct-fill { height: 100%; background: var(--accent); border-radius: 3px; }

/* ── 百公斤/明细 ── */
.kg-list .kg-row { display: flex; justify-content: space-between; align-items: center; min-height: 44px; padding: 4px 0; border-bottom: 0.5px solid var(--separator); font-size: 15px; }
.kg-list .kg-row:last-child { border-bottom: none; }
.kg-list .kg-name { flex: 1; }
.kg-list .kg-val { color: var(--ink); font-weight: 500; }
.kg-list .kg-val i { font-style: normal; font-size: 12px; color: var(--muted); font-weight: 400; margin: 0 10px 0 2px; }

/* ── 开关 ── */
.row-between { display: flex; justify-content: space-between; align-items: center; min-height: 44px; }
.toggle-label { font-size: 15px; }
.toggle { position: relative; width: 51px; height: 31px; background: rgba(120,120,128,0.16); border-radius: 16px; cursor: pointer; transition: background 0.2s; flex-shrink: 0; }
.toggle-knob { position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; background: #fff; border-radius: 50%; transition: left 0.2s; box-shadow: 0 2px 4px rgba(0,0,0,0.15); }
.toggle.on { background: var(--accent); }
.toggle.on .toggle-knob { left: 22px; }

/* ── 参数 ── */
.param-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; flex-wrap: wrap; min-height: 44px; }
.param-label { font-size: 15px; color: var(--ink); min-width: 80px; flex-shrink: 0; }
.param-input-wrap { display: inline-flex; align-items: center; gap: 6px; }
.param-input-wrap input[type="number"], .num-input {
  width: 90px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-btn);
  font-size: 15px; font-family: inherit; text-align: right; background: var(--bg);
}
.param-unit { font-size: 13px; color: var(--muted); }
.seg-group { display: flex; flex: 1; border-radius: var(--radius-btn); overflow: hidden; background: var(--bg); }
.seg-btn { flex: 1; padding: 8px 6px; border: none; background: none; font-size: 13px; font-family: inherit; color: var(--ink-soft); cursor: pointer; text-align: center; }
.seg-btn.active { background: var(--accent); color: #fff; font-weight: 600; }

/* ── 特性（皂 + 润唇膏共用同一渲染）── */
.quality-list .q-row { margin-bottom: 14px; padding-bottom: 12px; border-bottom: 0.5px solid var(--separator); }
.quality-list .q-row:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.q-row .q-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.q-row .q-name { font-weight: 600; font-size: 15px; color: var(--ink); }
.q-row .q-status { font-size: 13px; font-weight: 600; flex-shrink: 0; }
.q-bar { position: relative; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; margin-bottom: 8px; }
.q-bar .q-fill { height: 100%; border-radius: 4px; background: var(--accent); }
.q-bar .q-fill.over { background: #c0653a; }
.q-bar .q-zone { position: absolute; top: 0; bottom: 0; background: rgba(139, 94, 60, 0.18); border-left: 1px solid var(--accent); border-right: 1px solid var(--accent); }
.q-desc { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--ink-soft); }
.q-desc b { color: var(--ink); font-weight: 600; }
.q-desc-text { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.5; }

/* ── pH ── */
.ph-value { font-size: 28px; font-weight: 700; color: var(--accent); text-align: center; padding: 8px 0; }
.warn { background: #fff3e0; border: 1px solid #ffcc80; color: #e65100; border-radius: var(--radius-btn); padding: 8px 12px; font-size: 13px; margin-top: 8px; }
.ph-note { font-size: 11px; color: var(--muted); margin-top: 8px; text-align: center; }
.ph-legend { font-size: 11px; color: var(--muted); text-align: center; margin-top: 6px; }

/* ── 底部 Tab Bar 49pt ── */
.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  max-width: 640px; margin: 0 auto;
  display: flex; background: rgba(249, 249, 249, 0.94);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 0.5px solid var(--separator);
  z-index: 50;
  padding-bottom: var(--safe-bottom);
  height: calc(var(--tab-h) + var(--safe-bottom));
}
.tab {
  flex: 1; border: none; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; cursor: pointer; font-family: inherit;
  color: rgba(60, 60, 67, 0.6);
  padding: 6px 0 2px;
}
.tab-icon { font-size: 22px; line-height: 1; }
.tab-label { font-size: 10px; font-weight: 500; }
.tab.active { color: var(--accent); }
.tab.active .tab-label { font-weight: 600; }

/* ── 浮层 ── */
.overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100; align-items: flex-end; justify-content: center;
}
.overlay.show { display: flex; }
.sheet {
  width: 100%; max-width: 640px;
  background: var(--card); border-radius: 16px 16px 0 0;
  padding-bottom: var(--safe-bottom);
  max-height: 82vh; overflow: hidden;
  display: flex; flex-direction: column;
}
.sheet-head {
  position: relative; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px; padding: 8px 16px;
  border-bottom: 0.5px solid var(--separator);
  background: var(--card);
}
.sheet-head b { font-size: 17px; font-weight: 600; }
.sheet-head.center-title b {
  position: absolute; left: 50%; transform: translateX(-50%);
  max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  pointer-events: none;
}
.sheet-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px calc(20px + var(--safe-bottom));
}
.sheet-close, .sheet-cancel {
  border: none; background: none; color: var(--accent); font-size: 16px;
  font-family: inherit; cursor: pointer;
  min-width: 52px; min-height: 44px; padding: 0 2px;
  display: flex; align-items: center;
}
.sheet-cancel { justify-content: flex-start; }
.sheet-close { justify-content: flex-end; }
.sheet-close:active, .sheet-cancel:active { opacity: 0.5; }

.search-input {
  width: 100%; padding: 10px 14px;
  border: none; border-radius: var(--radius-btn);
  font-size: 15px; font-family: inherit; margin-bottom: 10px;
  background: var(--bg);
}
.cat-tabs { display: flex; gap: 6px; margin-bottom: 10px; overflow-x: auto; }
.cat-tab {
  padding: 6px 9px; border: none; border-radius: 14px;
  background: var(--bg); font-size: 13px; font-family: inherit;
  color: var(--ink-soft); cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.cat-tab.active { background: var(--accent); color: #fff; }
.picker-sheet .sheet-body { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; }
.picker-sheet .search-input, .picker-sheet .cat-tabs, .picker-sheet #custom-btn { flex-shrink: 0; }
.picker-list {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(16px + var(--safe-bottom));
}
.picker-sheet #custom-btn { margin: 10px 0 calc(16px + var(--safe-bottom)); }
.picker-item {
  display: flex; justify-content: space-between; align-items: center;
  min-height: 44px; padding: 8px 6px;
  border-bottom: 0.5px solid var(--separator);
  font-size: 15px; cursor: pointer;
}
.picker-item:last-child { border-bottom: none; }
.picker-item:active { background: var(--accent-bg); }
.picker-item .pi-name { flex: 1; }
.picker-item .pi-ins, .picker-item .pi-sap {
  font-size: 12px; color: var(--muted); text-align: right; flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.picker-item .pi-ins { width: 58px; margin-left: 10px; }
.picker-item .pi-sap { width: 72px; margin-left: 8px; }
.picker-item .pi-check { color: var(--accent); font-weight: 700; margin-left: 8px; }
.picker-empty { text-align: center; color: var(--muted); font-size: 13px; padding: 48px 0; }

/* ── 表单 ── */
.form-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; min-height: 44px; }
.form-row label { font-size: 15px; color: var(--ink); min-width: 90px; flex-shrink: 0; }
.form-row input, .form-row select {
  flex: 1; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-btn);
  font-size: 15px; font-family: inherit; background: var(--bg);
}
.error { background: #ffe5e5; border: 1px solid var(--danger); color: var(--danger); border-radius: var(--radius-btn); padding: 8px 12px; font-size: 13px; margin-bottom: 10px; }

/* ── 列表 ── */
.list-rows { min-height: 60px; }
.recipe-item {
  display: flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 8px 4px;
  border-bottom: 0.5px solid var(--separator);
  cursor: pointer; border-radius: 8px;
}
.recipe-item:active { background: var(--accent-bg); }
.recipe-item .ri-name { flex: 1; font-size: 15px; word-break: break-all; }
.recipe-item .ri-meta { font-size: 12px; color: var(--muted); }
.recipe-item .r-btn {
  border: none; background: none; color: var(--accent);
  font-size: 14px; font-family: inherit; cursor: pointer;
  padding: 8px 6px; border-radius: var(--radius-btn); flex-shrink: 0;
}
.recipe-item .r-btn:active { background: var(--accent-bg); }
.recipe-item .r-del { color: var(--danger); }
.list-empty { text-align: center; color: var(--muted); font-size: 13px; padding: 20px 0; }

/* ── 确认 ── */
.confirm-sheet { padding-bottom: 20px; }
.confirm-text { text-align: center; font-size: 15px; padding: 10px 0 18px; }

/* ── 分享 ── */
#share-text {
  width: 100%; padding: 12px;
  border: 1px solid var(--border); border-radius: var(--radius-btn);
  font-size: 13px; font-family: inherit; line-height: 1.7;
  background: var(--bg); resize: vertical;
}

/* ── 备份 / 恢复 ── */
.backup-row { display: flex; gap: 8px; margin-top: 14px; }
.backup-row .btn { flex: 1; }
.backup-hint { font-size: 12px; color: var(--muted); line-height: 1.6; margin-bottom: 8px; }
#backup-text {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-btn);
  font-size: 12px; line-height: 1.5; font-family: inherit;
  background: var(--bg); color: var(--ink); resize: vertical;
  word-break: break-all;
}

/* ── Toast ── */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: rgba(28, 28, 30, 0.9); color: #fff;
  padding: 10px 20px; border-radius: 20px;
  font-size: 14px; pointer-events: none;
  opacity: 0; transition: opacity 0.25s; z-index: 200;
  white-space: nowrap;
}
.toast.show { opacity: 1; }

/* ── 特性图例（皂 + 唇膏共用）── */
.quality-legend { display: flex; gap: 16px; margin-bottom: 12px; font-size: 12px; color: var(--muted); }
.ql-item { display: inline-flex; align-items: center; gap: 5px; }
.ql-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }

/* ── pH ── */
.ph-value { font-size: 28px; font-weight: 700; color: var(--accent); text-align: center; padding: 8px 0; }
.warn { background: #fff3e0; border: 1px solid #ffcc80; color: #e65100; border-radius: var(--radius-btn); padding: 8px 12px; font-size: 13px; margin-top: 8px; }
.ph-note { font-size: 11px; color: var(--muted); margin-top: 8px; text-align: center; }

/* ── 配方标题 ── */
.capture-title { font-size: 16px; font-weight: 600; color: var(--ink); margin-bottom: 10px; }

/* ── 杂项 ── */
.row-between { display: flex; justify-content: space-between; align-items: center; min-height: 44px; }
.toggle-label { font-size: 15px; }
#flame-row .toggle { margin-left: auto; flex-shrink: 0; }
.big-row .big-val { flex: 1; text-align: right; }
.help-content {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 16px calc(20px + var(--safe-bottom));
}
.help-content h4 { font-size: 15px; color: var(--accent); margin: 14px 0 6px; }
.help-content h4:first-child { margin-top: 6px; }
.help-content ol, .help-content ul { padding-left: 20px; }
.help-content li { font-size: 13px; color: var(--ink-soft); margin-bottom: 5px; line-height: 1.6; }

/* ── 配方列表标签页 ── */
.list-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.list-tab-btn {
  flex: 1; padding: 9px 0; border: 1px solid var(--border);
  border-radius: var(--radius-btn); background: var(--bg); color: var(--ink-soft);
  font-size: 14px; font-family: inherit; cursor: pointer; text-align: center;
}
.list-tab-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* —— iOS 焦点防缩放：输入框至少 16px —— */
@media (max-width: 480px) {
  #app input.weight,
  #app .num-input,
  #app .search-input,
  #app .form-row input,
  #app .form-row select,
  #app #share-text,
  #app #backup-text,
  #app input[type="number"] {
    font-size: 16px;
  }
}
