/* ============================================================
   拼豆图案转换器 · 专属样式
   基座：../shared/theme.css（先加载），本文件只做局部覆盖与新增
   约定：新增令牌一律 --bf-* 前缀、新增类一律 bf- 前缀，
        不重定义 --brand-* 等全站设计系统令牌
   ============================================================ */

:root {
  --bf-accent:      #e8590c;   /* 拼豆豆暖橙：主点缀 */
  --bf-accent-dark: #c2410c;
  --bf-accent-soft: #fff2e8;
  --bf-ink:         #243043;
  --bf-line:        #e3e6ed;
  --bf-panel:       #f7f8fb;
  --bf-paper:       #ffffff;   /* 图纸“纸张”底色：任何主题下都保持浅底，便于打印与辨色 */
  --bf-grid-minor:  #c9d0dc;
  --bf-grid-major:  #8d97a8;
  --bf-ruler:       #5b6473;
  --bf-cell-line:   rgba(0,0,0,.16);
  --bf-shadow-sm:   0 2px 8px rgba(20,26,40,.08);
  --bf-shadow-md:   0 6px 22px rgba(20,26,40,.12);
  --bf-radius:      12px;
  --bf-radius-sm:   8px;
}

body.theme-dark {
  --bf-accent-soft: #3a2415;
  --bf-ink:         #e6e9f0;
  --bf-line:        #2e3850;
  --bf-panel:       #1f2638;
  --bf-shadow-sm:   0 2px 8px rgba(0,0,0,.35);
  --bf-shadow-md:   0 6px 22px rgba(0,0,0,.45);
}

/* ---------- 外壳 ---------- */
.app-shell {
  min-height: 100vh;
  background: var(--surface-soft);
  display: flex;
  flex-direction: column;
}
.app-header {
  background: linear-gradient(135deg, var(--bf-accent-dark) 0%, var(--bf-accent) 55%, #f6a04d 100%) !important;
  position: relative;
}
.app-header .lead { font-size: .98rem; }
.header-actions {
  position: absolute;
  top: var(--space-5);
  right: var(--space-5);
  display: flex;
  gap: .5rem;
}
.bf-header-badge {
  background: rgba(255,255,255,.22);
  color: #fff;
  border: none;
  font-size: .68rem;
  letter-spacing: .02em;
}
.app-body {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

/* 大图工具页里卡片“抬起”会带动画布抖动，只保留阴影变化 */
.card { box-shadow: var(--bf-shadow-sm); }
.card:hover { transform: none; box-shadow: var(--bf-shadow-sm); }
.card-header {
  display: flex;
  align-items: center;
  gap: .55rem;
  color: var(--bf-ink);
}
.card-header > i { color: var(--bf-accent); }
.app-footer { background: var(--surface); }

/* ---------- 提示条 ---------- */
.bf-notice-stack { display: flex; flex-direction: column; gap: .6rem; }
.notice { align-items: flex-start; line-height: 1.55; }
.notice i { margin-top: .15rem; }
.notice-info {
  background: rgba(54,185,204,.14);
  border-color: var(--brand-info);
  color: #17627a;
}
body.theme-dark .notice-info { color: #7fd6e8; }

/* ---------- 上传区 ---------- */
.bf-drop {
  border: 2px dashed var(--bf-accent);
  border-radius: var(--bf-radius);
  background: var(--bf-accent-soft);
  padding: 1.6rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: background var(--transition-base), border-color var(--transition-base);
}
.bf-drop:hover, .bf-drop.is-over { background: #ffe7d5; border-color: var(--bf-accent-dark); }
body.theme-dark .bf-drop:hover, body.theme-dark .bf-drop.is-over { background: #4a2c17; }
.bf-drop > i { font-size: 1.9rem; color: var(--bf-accent); display: block; margin-bottom: .5rem; }
.bf-drop-title { font-weight: 700; color: var(--bf-ink); }
.bf-drop-sub { font-size: .8rem; color: var(--text-muted); margin-top: .3rem; }
.bf-src-thumb { display: none; width: 260px; max-width: 100%; border-radius: 8px; margin: 0 auto .55rem; }
.bf-drop.is-loaded { border-style: solid; border-color: var(--bf-accent-dark); background: var(--bf-panel); padding: 1rem 1rem .9rem; }
.bf-drop.is-loaded > i, .bf-drop.is-loaded .bf-drop-sub { display: none; }
.bf-drop.is-loaded .bf-src-thumb { display: block; }
.bf-drop.is-loaded .bf-drop-title { font-size: .85rem; color: var(--bf-accent-dark); }
body.theme-dark .bf-drop.is-loaded { background: #171d2b; }
.bf-file { display: none; }
.bf-src-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: .8rem; margin-top: .7rem; font-size: .85rem; flex-wrap: wrap;
}

/* ---------- 参数区两栏 ---------- */
.bf-param-grid { display: grid; grid-template-columns: 1fr; gap: 1.2rem; }
@media (min-width: 900px) { .bf-param-grid { grid-template-columns: minmax(280px, 42%) 1fr; } }

.bf-frame-col { display: flex; flex-direction: column; gap: .6rem; }
.bf-frame-wrap {
  position: relative;
  background: var(--bf-panel);
  border: 1px solid var(--bf-line);
  border-radius: var(--bf-radius-sm);
  overflow: hidden;
  min-height: 210px;
  display: flex; align-items: center; justify-content: center;
}
.bf-frame-canvas { display: block; max-width: 100%; touch-action: none; cursor: crosshair; }
.bf-frame-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: .85rem; text-align: center; padding: 1rem;
}
.bf-frame-toolbar { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.bf-frame-toolbar .form-range { flex: 1 1 110px; min-width: 96px; }
.bf-frame-hint { font-size: .76rem; color: var(--text-muted); }

.bf-form-col { display: flex; flex-direction: column; gap: .85rem; }
.bf-field { display: flex; flex-direction: column; gap: .35rem; }
.bf-inline { display: flex; align-items: center; gap: .5rem; }
.bf-inline .form-control { width: 96px; }
.bf-x { color: var(--text-muted); font-weight: 700; }
.bf-custom-size { display: none; }
.bf-custom-size.is-open { display: flex; }
/* 拼幅面板本身绝不隐藏：开关 #tileModeCheck 就在面板里，一隐藏用户就再也找不到它 */
.bf-tile-row { border: 1px dashed var(--bf-line); border-radius: var(--bf-radius-sm); padding: .6rem .7rem; background: var(--bf-panel); }
.bf-tile-row > .bf-check { font-weight: 600; }
.bf-tile-detail { display: none; }
.bf-tile-detail.is-open { display: flex; }
.bf-field-muted { opacity: .5; }
.bf-size-info { font-size: .78rem; color: var(--text-muted); }
.bf-size-info.bf-warn-text { color: var(--brand-danger); font-weight: 600; }
.bf-val { color: var(--bf-accent-dark); font-weight: 700; font-variant-numeric: tabular-nums; }
body.theme-dark .bf-val { color: var(--bf-accent); }

/* 滑块：theme.css 未提供，本地补一套 */
.form-range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 22px; background: transparent; cursor: pointer;
}
.form-range::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px; background: var(--surface-muted);
}
.form-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 50%; margin-top: -6px;
  background: var(--bf-accent); border: 2px solid #fff; box-shadow: var(--bf-shadow-sm);
}
.form-range::-moz-range-track { height: 6px; border-radius: 3px; background: var(--surface-muted); }
.form-range::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--bf-accent); border: 2px solid #fff;
}
.bf-range-sm { max-width: 130px; }

.bf-check {
  display: flex; align-items: flex-start; gap: .45rem;
  font-size: .82rem; color: var(--text); line-height: 1.5; cursor: pointer;
}
.bf-check .form-check-input { margin-top: .18rem; flex: none; }
.bf-check-inline { display: inline-flex; align-items: center; white-space: nowrap; }

.bf-collapse { border-top: 1px dashed var(--bf-line); padding-top: .5rem; }
.bf-link-btn {
  background: none; border: none; padding: .2rem 0; cursor: pointer;
  color: var(--brand-primary); font-weight: 600; font-size: .84rem;
  display: flex; align-items: center; gap: .4rem; font-family: var(--font-base);
}
.bf-collapse-body { display: none; margin-top: .7rem; }
.bf-collapse.is-open .bf-collapse-body { display: block; }

.bf-progress { display: none; align-items: center; gap: .7rem; }
.bf-progress.is-on { display: flex; }
.bf-progress .progress { flex: 1; }
.bf-progress-text { font-size: .76rem; color: var(--text-muted); min-width: 5.5em; text-align: right; }
.bf-error { color: var(--brand-danger); font-size: .82rem; min-height: 1.1em; }

/* ---------- 图纸工具栏 ---------- */
.bf-count-badge { margin-left: auto; background: var(--bf-accent); font-size: .72rem; }
.bf-toolbar {
  display: flex; align-items: center; gap: .9rem 1.1rem; flex-wrap: wrap;
  padding-bottom: .8rem; margin-bottom: .8rem; border-bottom: 1px solid var(--bf-line);
}
.bf-tool-group { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.bf-mini-label { font-size: .74rem; color: var(--text-muted); font-weight: 600; }
.bf-btn-sm { padding: .3rem .7rem !important; font-size: .78rem !important; border-radius: 999px; }
.bf-zoom-label {
  font-size: .78rem; font-weight: 700; color: var(--bf-ink);
  min-width: 3.6em; text-align: center; font-variant-numeric: tabular-nums;
}
.bf-select-sm { width: auto !important; padding: .28rem .5rem !important; font-size: .78rem !important; }
.bf-header-select { margin-left: auto; }

.bf-tool-btn {
  border: 1.5px solid var(--bf-line);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: .34rem .8rem;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: .35rem;
  font-family: var(--font-base);
  transition: background var(--transition-base), color var(--transition-base), border-color var(--transition-base);
}
.bf-tool-btn:hover { border-color: var(--bf-accent); color: var(--bf-accent-dark); }
.bf-tool-btn.active { background: var(--bf-accent); border-color: var(--bf-accent); color: #fff; }
.bf-tool-btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- 填色条 ---------- */
.bf-palette-row {
  background: var(--bf-panel);
  border: 1px solid var(--bf-line);
  border-radius: var(--bf-radius-sm);
  padding: .6rem .75rem;
  margin-bottom: .8rem;
  display: flex; flex-direction: column; gap: .5rem;
}
.bf-palette-head { display: flex; align-items: baseline; justify-content: space-between; gap: .6rem; flex-wrap: wrap; }
.bf-swatches { display: flex; flex-wrap: wrap; gap: .35rem; }
.bf-swatch {
  width: 42px; border: 1.5px solid var(--bf-line); border-radius: 6px;
  background: var(--surface); cursor: pointer; padding: 0; overflow: hidden;
  font-family: var(--font-base); transition: transform var(--transition-base), border-color var(--transition-base);
}
.bf-swatch:hover { transform: translateY(-2px); }
.bf-swatch .bf-swatch-chip { display: block; height: 22px; border-bottom: 1px solid rgba(0,0,0,.08); }
.bf-swatch .bf-swatch-code { display: block; font-size: .62rem; line-height: 1.5; color: var(--text-muted); font-weight: 700; }
.bf-swatch.active { border-color: var(--bf-accent); box-shadow: 0 0 0 2px var(--bf-accent); }
.bf-swatch.active .bf-swatch-code { color: var(--bf-accent-dark); }
.bf-swap-row { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---------- 拼板导航 ---------- */
.bf-board-strip { display: none; flex-wrap: wrap; gap: .35rem; margin-bottom: .8rem; }
.bf-board-strip.is-on { display: flex; }
.bf-board-chip {
  display: inline-flex; align-items: baseline; gap: .35rem;
  border: 1.5px solid var(--bf-line); border-radius: 999px;
  background: var(--surface); color: var(--text);
  padding: .24rem .68rem; font-size: .78rem; font-weight: 700; cursor: pointer;
  font-family: var(--font-base);
  transition: background var(--transition-base), border-color var(--transition-base), color var(--transition-base);
}
.bf-board-chip span { font-size: .68rem; font-weight: 600; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.bf-board-chip:hover { border-color: var(--bf-accent); }
.bf-board-chip.active { background: var(--bf-accent); border-color: var(--bf-accent); color: #fff; }
.bf-board-chip.active span { color: #ffddc7; }
body.theme-dark .bf-board-chip.active span { color: #3a2415; }
.bf-board-more { border-style: dashed; font-weight: 600; color: var(--text-muted); }
.bf-board-more:hover { color: var(--bf-accent); }

/* ---------- 画布 ---------- */
.bf-canvas-wrap {
  position: relative;
  background: var(--bf-paper);
  border: 1px solid var(--bf-line);
  border-radius: var(--bf-radius-sm);
  overflow: hidden;
  height: clamp(320px, 62vh, 640px);
  touch-action: none;
}
.bf-canvas { display: block; width: 100%; height: 100%; }
.bf-overlay { position: absolute; inset: 0; cursor: crosshair; }
.bf-overlay.is-pan { cursor: grab; }
.bf-overlay.is-pan.is-dragging { cursor: grabbing; }
.bf-canvas-empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .6rem;
  color: var(--text-muted); font-size: .9rem; text-align: center; padding: 1rem;
  background: var(--bf-paper);
}
.bf-canvas-empty i { font-size: 2.2rem; color: var(--bf-line); }
.bf-canvas-wrap.is-ready .bf-canvas-empty { display: none; }

.bf-stats {
  display: flex; flex-wrap: wrap; gap: .4rem .55rem;
  margin-top: .7rem; font-size: .78rem;
}
.bf-stat {
  background: var(--bf-panel); border: 1px solid var(--bf-line);
  border-radius: 999px; padding: .22rem .7rem; color: var(--text);
}
.bf-stat b { color: var(--bf-ink); font-variant-numeric: tabular-nums; }

/* ---------- 图例 ---------- */
.bf-legend-scroll { max-height: 420px; padding: 0; background: var(--surface); border: 1px solid var(--bf-line); }
.bf-legend-scroll table { font-size: .85rem; }
.bf-legend-swatch {
  display: inline-block; width: 34px; height: 18px; border-radius: 4px;
  border: 1px solid rgba(0,0,0,.18); vertical-align: middle;
}
.bf-legend-code { font-family: var(--font-mono); font-weight: 700; color: var(--bf-ink); }
.bf-legend-row { cursor: pointer; }
.bf-export-row {
  display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; margin-top: .8rem;
}
.bf-small { font-size: .76rem; margin-top: .5rem; }

/* ---------- 最近项目 ---------- */
.bf-projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: .7rem; }
.bf-project {
  background: var(--surface); border: 1px solid var(--bf-line); border-radius: var(--bf-radius-sm);
  padding: .5rem; cursor: pointer; text-align: center;
  transition: border-color var(--transition-base), transform var(--transition-base);
}
.bf-project:hover { border-color: var(--bf-accent); transform: translateY(-2px); }
.bf-project img { width: 100%; aspect-ratio: 1; object-fit: contain; background: var(--bf-paper); border-radius: 6px; }
.bf-project-title {
  font-size: .76rem; font-weight: 600; color: var(--bf-ink);
  margin-top: .35rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bf-project-meta { font-size: .68rem; color: var(--text-muted); }
.bf-project-del {
  border: none; background: none; color: var(--text-muted); cursor: pointer;
  font-size: .7rem; padding: .1rem .3rem;
}
.bf-project-del:hover { color: var(--brand-danger); }
.bf-projects-empty { grid-column: 1 / -1; font-size: .82rem; color: var(--text-muted); }

/* ---------- Toast ---------- */
.toast-container {
  position: fixed; bottom: 1.4rem; right: 1.4rem; z-index: 9999;
  display: flex; flex-direction: column; gap: .5rem; pointer-events: none;
}
.toast {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--bf-line); border-radius: var(--bf-radius-sm);
  padding: .6rem 1rem; font-size: .84rem; box-shadow: var(--bf-shadow-md);
  display: flex; align-items: center; gap: .5rem;
  opacity: 0; transform: translateY(8px); transition: opacity .25s ease, transform .25s ease;
  min-width: 200px; max-width: 78vw;
}
.toast.show { opacity: 1; transform: translateX(0) translateY(0); }
.toast-success i { color: #22c55e; }
.toast-info i { color: var(--brand-info); }
.toast-warn i { color: var(--brand-warning); }
.toast-error i { color: var(--brand-danger); }

/* ---------- 模态（iOS 保存兜底 / 整体替换） ---------- */
.bf-modal {
  position: fixed; inset: 0; z-index: 10000;
  background: rgba(15,20,32,.55);
  display: none; align-items: center; justify-content: center; padding: 1rem;
}
.bf-modal.is-open { display: flex; }
.bf-modal-card {
  background: var(--surface); border-radius: var(--bf-radius);
  box-shadow: var(--bf-shadow-md); width: min(520px, 100%);
  max-height: 88vh; overflow: auto; padding: 1.1rem;
  display: flex; flex-direction: column; gap: .8rem;
}
.bf-modal-title { font-weight: 700; color: var(--bf-ink); display: flex; align-items: center; gap: .5rem; }
.bf-modal-body { display: flex; flex-direction: column; gap: .7rem; }
.bf-modal-img { width: 100%; border: 1px solid var(--bf-line); border-radius: var(--bf-radius-sm); background: var(--bf-paper); }
.bf-modal-actions { display: flex; justify-content: flex-end; gap: .6rem; }

/* ---------- 工具 ---------- */
.is-hidden { display: none !important; }
.bf-thumb-ph {
  width: 100%; aspect-ratio: 1; border-radius: 6px;
  background: repeating-linear-gradient(45deg, var(--bf-panel), var(--bf-panel) 6px, var(--surface) 6px, var(--surface) 12px);
  display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 1.2rem;
}

/* ---------- 打印：只留图纸本体 ---------- */
@media print {
  .app-header, .app-footer, .bf-toolbar, .bf-palette-row, .bf-export-row,
  .bf-projects, .bf-drop, .bf-frame-col, .toast-container, .bf-modal, #paramsCard, #legendCard { display: none !important; }
  .app-shell, .card, .app-body { box-shadow: none !important; margin: 0 !important; padding: 0 !important; }
  .bf-canvas-wrap { height: auto; border: none; }
}

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
  .app-body { padding: .8rem; gap: .9rem; }
  .header-actions { position: static; margin-top: .6rem; justify-content: center; }
  .bf-toolbar { gap: .6rem .8rem; }
  .bf-legend-scroll table { font-size: .78rem; }
  .toast-container { left: .8rem; right: .8rem; bottom: .8rem; }
}
@media (prefers-reduced-motion: reduce) {
  .bf-swatch:hover, .bf-project:hover { transform: none; }
  .toast { transition: opacity .2s; transform: none; }
}
