/* 菜谱工作台 · 设计规范落地
   目标：把「手机里一个一个加菜」变成「PC 上批量录、一次导出、群里分发」。
   语言：与 App 同源的暖橙品牌 + 桌面端克制的中性底色；信息密度优先，装饰最少。 */

:root {
  /* 品牌色：#FF7043 直接取 App 主题；深一档用于 hover / 按下，浅底用于选中态 */
  --brand: #ff7043;
  --brand-deep: #d94f27;
  --brand-soft: #fff3ed;
  --brand-border: #ffccbc;
  /* 表面：页面比卡片略深，让三层结构一眼可辨 */
  --bg: #faf8f6;
  --surface: #ffffff;
  --surface-2: #f7f3f0;
  --surface-3: #efe9e4;
  --border: #e6ded8;
  --border-strong: #d4c8c0;
  /* 文本：正文对比度 > 7:1，辅助文字仍 > 4.5:1 */
  --ink: #2b2420;
  --ink-2: #6f6157;
  --ink-3: #8b7c72;
  /* 语义色：只用于状态，不用于装饰 */
  --success: #246e4b;
  --success-bg: #e7f4ec;
  --warn: #8a5a00;
  --warn-bg: #fff3dc;
  --danger: #b3342b;
  --danger-deep: #96281f;
  --danger-bg: #fdebe8;
  --info: #2c6296;
  --info-bg: #eaf2fa;
  /* 4px 间距刻度 */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 20px;
  --s6: 24px;
  --s8: 32px;
  /* 圆角：控件 8 / 卡片 12 / 弹层 16 / 标签全圆 */
  --r-control: 8px;
  --r-card: 12px;
  --r-pop: 16px;
  --r-pill: 999px;
  --shadow: 0 1px 2px rgba(43, 36, 32, 0.06);
  --font: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Hiragino Sans GB", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--bg); }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
h2 { font-size: 16px; font-weight: 600; letter-spacing: 0.01em; }
h3 { font-size: 13px; font-weight: 600; color: var(--ink); }
code { font-family: var(--mono); font-size: 12px; color: var(--brand-deep); background: var(--brand-soft); border-radius: 4px; padding: 1px 5px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 100;
  background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 0 0 8px 8px;
}
.skip-link:focus { top: 0; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- 顶栏 ---------- */
.topbar {
  height: 64px; padding: 0 var(--s6);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s4);
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: var(--s3); }
.brand-mark {
  width: 28px; height: 28px; border-radius: 9px; flex: none;
  background: var(--brand); position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; left: 9px; top: 9px;
  width: 10px; height: 10px; border-radius: 50%; background: #fff;
}
.brand-title { font-size: 16px; font-weight: 600; line-height: 1.25; }
.brand-sub { font-size: 12px; color: var(--ink-3); line-height: 1.25; }
.top-actions { display: flex; align-items: center; gap: var(--s2); }

/* ---------- 按钮：default / primary / mini / icon，含 hover active disabled focus ---------- */
.btn {
  min-height: 34px; padding: 0 var(--s3);
  border: 1px solid var(--border-strong); border-radius: var(--r-control);
  background: var(--surface); color: var(--ink);
  font-family: inherit; font-size: 13px; font-weight: 500; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  cursor: pointer; white-space: nowrap;
  transition: background 120ms, border-color 120ms, transform 80ms;
}
/* 统一线性图标：跟随按钮文字色，尺寸随按钮档位缩放 */
.btn .ico { width: 15px; height: 15px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn-mini .ico { width: 13px; height: 13px; }
/* chip 内的小删除按钮：同一套线性图标，缩到 11px */
.chip button .ico, .tag button .ico {
  width: 11px; height: 11px; vertical-align: -1px;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--brand-border); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-deep); border-color: var(--brand-deep); }
.btn-mini { min-height: 28px; padding: 0 10px; font-size: 12px; }
.btn-icon { min-height: 28px; width: 28px; padding: 0; font-size: 18px; line-height: 1; color: var(--ink-2); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); border-color: var(--danger); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover:not(:disabled) { background: var(--danger-deep); border-color: var(--danger-deep); }

/* 顶栏入口的状态徽标：有错误时最醒目 */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: var(--s1);
  border-radius: var(--r-pill); background: rgba(255, 255, 255, 0.24);
  color: #fff; font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.badge.has-warn { background: var(--warn-bg); color: var(--warn); }
.badge.has-error { background: var(--danger-bg); color: var(--danger); }

/* ---------- 全宽布局：配置 + 编辑；导出恒为抽屉 ----------
   顶栏 64px，layout 占满剩余视口；四周统一 16px，两栏等高并各自内部滚动。 */
.layout {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  gap: var(--s4);
  align-items: stretch;
  width: 100%;
  height: calc(100vh - 64px);
  min-height: 480px;
  padding: var(--s4);
}
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-card); box-shadow: var(--shadow);
  padding: var(--s5);
  min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.panel > .panel-head, .panel > .lead { flex: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin-bottom: var(--s2); }
.panel-head .hint { font-size: 12px; color: var(--ink-3); }
.lead { font-size: 12px; color: var(--ink-2); line-height: 1.6; margin-bottom: var(--s4); }
.counter { font-size: 12px; font-weight: 400; color: var(--ink-3); margin-left: var(--s1); }

/* ---------- 左：配置基线（内容超出时自身滚动，与右栏底部对齐） ---------- */
.config { overflow-y: auto; }
.config-section { border-top: 1px solid var(--border); padding-top: var(--s4); margin-top: var(--s4); }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s3); }
.type-list, .chip-list { list-style: none; margin: 0; padding: 0; }
.type-list { display: grid; gap: var(--s2); }
.type-row { display: flex; align-items: center; gap: var(--s2); }
.type-row input[type="text"] { min-width: 0; flex: 1; }
.emoji-input { width: 42px; text-align: center; flex: none; }
.type-row .btn-icon { flex: none; }
.chip-list { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip {
  display: inline-flex; align-items: center; gap: var(--s1);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-pill); padding: 3px 6px 3px 10px; font-size: 12px;
}
.chip button { border: 0; background: none; color: var(--ink-3); cursor: pointer; font-size: 14px; line-height: 1; padding: 0 2px; }
.chip button:hover { color: var(--danger); }
.inline-add { display: flex; gap: var(--s2); margin-top: var(--s3); }
.inline-add input { min-width: 0; flex: 1; }
.config-foot {
  margin-top: var(--s5); padding: var(--s3); border-radius: var(--r-control);
  background: var(--surface-2); color: var(--ink-2); font-size: 12px;
}
.config-foot.is-ready { background: var(--success-bg); color: var(--success); }

/* ---------- 中：全列平铺表格（1920 宽屏一次看全） ---------- */
.editor-actions { display: flex; gap: var(--s2); }
.table-wrap { flex: 1; min-height: 0; overflow: auto; border: 1px solid var(--border); border-radius: var(--r-control); }
.dish-table { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 1500px; table-layout: fixed; font-size: 13px; }
.dish-table th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2); color: var(--ink-2); font-weight: 600; text-align: left;
  padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.dish-table td { padding: var(--s2); border-bottom: 1px solid var(--border); vertical-align: top; }
.dish-table tbody tr:last-child td { border-bottom: 0; }
.dish-row:hover { background: #fdfaf8; }
.dish-row.has-error { background: var(--danger-bg); }
.col-no { width: 40px; }
.col-name { width: 140px; }
.col-type { width: 110px; }
.col-method { width: 116px; }
.col-ing { width: 190px; }
.col-aux { width: 150px; }
.col-sea { width: 160px; }
.col-time { width: 78px; }
.col-active { width: 78px; }
.col-steps { width: 250px; }
.col-video { width: 170px; }
.col-del { width: 40px; }
.row-no { color: var(--ink-3); font-size: 12px; text-align: center; }
.cell-time input { padding: 6px 4px; text-align: center; }
.cell-steps textarea { resize: vertical; min-height: 54px; line-height: 1.5; }
.cell-ops { text-align: center; white-space: nowrap; }

input[type="text"], input[type="number"], select, textarea, .field-label + input {
  font-family: inherit; font-size: 13px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-control); padding: 6px 8px; width: 100%;
}
input:hover, select:hover, textarea:hover { border-color: var(--brand-border); }
input:focus, select:focus, textarea:focus { border-color: var(--brand); outline: 2px solid var(--brand-soft); outline-offset: 0; }
input[type="number"] { font-variant-numeric: tabular-nums; }

/* 标签输入器：对齐 App 的 AppTagField，chip 可删、半截文字留输入框 */
.tagfield {
  border: 1px solid var(--border-strong); border-radius: var(--r-control);
  background: var(--surface); padding: var(--s1); min-height: 54px;
}
.tagfield:focus-within { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.tag-chips { display: flex; flex-wrap: wrap; gap: var(--s1); }
.tag {
  display: inline-flex; align-items: center; gap: 3px;
  background: var(--brand-soft); color: var(--brand-deep);
  border: 1px solid var(--brand-border); border-radius: var(--r-pill);
  padding: 1px 4px 1px 8px; font-size: 12px; line-height: 1.5;
}
.tag button { border: 0; background: none; color: inherit; cursor: pointer; font-size: 13px; line-height: 1; padding: 0 2px; }
.tag button:hover { color: var(--danger); }
.tagfield input { border: 0; padding: 2px 4px; min-width: 72px; width: 100%; outline: none; background: transparent; }
.tagfield input:focus { outline: none; box-shadow: none; }
.empty-state { padding: var(--s8) var(--s4); text-align: center; color: var(--ink-3); }
.empty-state p { margin-bottom: var(--s3); }

/* ---------- 导出：任何宽度都收在右侧抽屉里，编辑区拿满宽度 ---------- */
#btn-output { display: inline-flex; align-items: center; }
.output {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 60;
  width: min(420px, 92vw); border-radius: 0;
  box-shadow: -12px 0 36px rgba(43, 36, 32, 0.18);
  transform: translateX(102%); transition: transform 180ms ease;
  overflow-y: auto;
}
.output.is-open { transform: none; }
.output-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); margin-bottom: var(--s2); }
.output-actions .btn { padding: 0 var(--s2); }
.btn-wide { width: 100%; margin-bottom: var(--s4); }
.output-close { display: inline-flex; align-items: center; justify-content: center; }
.scrim { position: fixed; inset: 0; z-index: 55; background: rgba(43, 36, 32, 0.34); }
body.drawer-open { overflow: hidden; }

.output .report { border-top: 1px solid var(--border); padding-top: var(--s4); margin-top: var(--s4); }
.output .report:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.report h3 { margin-bottom: var(--s2); display: flex; align-items: baseline; justify-content: space-between; gap: var(--s2); }
.report-item { font-size: 12px; line-height: 1.55; padding: 3px 0; color: var(--ink-2); display: flex; gap: var(--s2); align-items: flex-start; }
.report-item.error { color: var(--danger); }
.report-item.warn { color: var(--warn); }
.report-item.ok { color: var(--success); }
.pill {
  display: inline-block; font-size: 11px; font-weight: 600; line-height: 1.6;
  border-radius: var(--r-pill); padding: 0 8px; flex: none;
  background: var(--surface-3); color: var(--ink-2);
}
.pill.error { background: var(--danger-bg); color: var(--danger); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.ok { background: var(--success-bg); color: var(--success); }
.pill.info { background: var(--info-bg); color: var(--info); }

.preview-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s2);
  border-bottom: 1px solid var(--border); margin-bottom: var(--s2);
}
.preview-head .btn { margin-bottom: var(--s1); }
.tabs { display: flex; gap: var(--s1); flex: 1; min-width: 0; }
.tab {
  border: 0; border-bottom: 2px solid transparent; background: none;
  padding: var(--s2) var(--s3); font-family: inherit; font-size: 12px;
  color: var(--ink-3); cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--brand-deep); border-bottom-color: var(--brand); font-weight: 600; }
.code-box {
  font-family: var(--mono); font-size: 11px; line-height: 1.6;
  background: var(--surface-2); color: var(--ink-2);
  width: 100%; min-height: 280px; max-height: 520px; resize: vertical;
}
.guide summary {
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink);
  list-style: none;
}
.guide summary::-webkit-details-marker { display: none; }
.guide summary::after { content: "＋"; float: right; color: var(--ink-3); font-weight: 400; }
.guide[open] summary::after { content: "－"; }
.guide ol { margin: var(--s2) 0 0; padding-left: 18px; font-size: 12px; color: var(--ink-2); line-height: 1.75; }
.guide b { color: var(--ink); font-weight: 600; }

/* ---------- 弹层 / 提示 ---------- */
dialog {
  border: 1px solid var(--border); border-radius: var(--r-pop);
  padding: 0; width: min(720px, calc(100vw - 32px));
  box-shadow: 0 16px 48px rgba(43, 36, 32, 0.18);
  color: var(--ink); background: var(--surface);
}
dialog::backdrop { background: rgba(43, 36, 32, 0.38); }
.dialog-form { padding: var(--s5); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s3); }
.dialog-head h2 { font-size: 16px; }
.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: var(--s2); }
#paste-area { font-family: var(--mono); font-size: 12px; line-height: 1.6; resize: vertical; min-height: 220px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s4); }
.toast {
  position: fixed; right: var(--s5); bottom: var(--s5); z-index: 80;
  max-width: min(420px, calc(100vw - 40px));
  background: var(--ink); color: #fff; font-size: 13px;
  padding: var(--s3) var(--s4); border-radius: var(--r-control);
  box-shadow: 0 8px 24px rgba(43, 36, 32, 0.2);
}

/* ---------- 多端适配 ---------- */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 232px minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; min-height: calc(100vh - 64px); }
  .panel { overflow: visible; }
  .table-wrap { flex: none; min-height: 0; }
  .topbar { height: auto; min-height: 64px; flex-wrap: wrap; padding: var(--s3) var(--s4); }
}
@media (max-width: 560px) {
  .top-actions { width: 100%; }
  .top-actions .btn { flex: 1; }
  .panel { padding: var(--s4); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
