/* 织锦包展示系统 · Phase 2 全局样式
   - 移动优先
   - 主色：暖棕 + 米白
*/
:root {
  --bg: #faf7f2;
  --fg: #2a2522;
  --muted: #7a6f66;
  --line: #e7e0d6;
  --accent: #8b5a3c;
  --accent-soft: #f3e9dd;
  --error: #b3261e;
  --warn: #c98a3a;
  --ok: #5a7d4c;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--fg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.9em; background: var(--accent-soft); padding: 1px 4px; border-radius: 3px; }

/* ===== 通用 ===== */
.muted { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 32px 16px; }
.pill { display: inline-block; padding: 2px 8px; background: var(--accent-soft); color: var(--accent); border-radius: 10px; font-size: 11px; margin: 2px; }
.pill.soldout { background: #e8e2d6; color: var(--muted); }
/* 图库文件夹 SKU 关联状态 badge */
.pill-ok   { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.pill-warn { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; cursor: help; }
.primary, button.primary { background: var(--accent); color: #fff; border: 0; padding: 9px 14px; border-radius: 8px; font: inherit; cursor: pointer; display: inline-block; text-align: center; }
.primary:disabled, button.primary:disabled { opacity: 0.6; cursor: not-allowed; }
.primary:hover, button.primary:hover { filter: brightness(1.05); }
button.mini { background: #fff; color: var(--fg); border: 1px solid var(--line); padding: 4px 10px; border-radius: 6px; font-size: 12px; }
button.mini.danger { color: var(--error); border-color: #e8d5d2; }
button.mini:hover { background: var(--accent-soft); }

/* ===== 头部 ===== */
.app-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; background: rgba(255,255,255,0.94);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.app-header h1 { margin: 0; font-size: 15px; flex: 1; min-width: 0; }
.app-header .brand { display: flex; align-items: baseline; gap: 12px; flex: 1; }
.app-header .brand h1 { font-size: 15px; }
.app-header .link-admin { font-size: 12px; color: var(--muted); }
.app-header .stats { color: var(--muted); font-size: 12px; }
.back-link { color: var(--muted); font-size: 13px; }
.link-btn { background: transparent; border: 0; color: var(--accent); font-size: 13px; }

/* ===== 登录页 ===== */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.auth-card { width: 100%; max-width: 360px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 28px 24px; box-shadow: var(--shadow); }
.auth-card h1 { margin: 0 0 4px; font-size: 20px; }
.auth-card .subtitle { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.auth-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 16px; }
.auth-card input { width: 100%; padding: 10px 12px; margin-top: 6px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.auth-card input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.auth-card button[type=submit] { width: 100%; padding: 11px 16px; background: var(--accent); color: #fff; border: 0; border-radius: 8px; }
.auth-card .error { color: var(--error); font-size: 13px; margin: 12px 0 0; }

/* ===== 主页筛选 ===== */
.filter-bar {
  padding: 10px 14px; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 8px;
  position: sticky; top: 45px; z-index: 9;
}
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-row input[type=search] { flex: 1; min-width: 180px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.filter-row select { padding: 7px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.filter-chip { display: inline-flex; align-items: center; gap: 4px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 16px; font-size: 13px; background: #fff; }
.filter-chip input[type=checkbox] { margin: 0; }
.filter-chip-static { color: var(--muted); font-size: 12px; padding: 5px 4px 5px 0; }
.tag-chip { background: #fff; color: var(--fg); border: 1px solid var(--line); border-radius: 16px; padding: 4px 10px; font-size: 12px; }
.tag-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tags-row { max-height: 60px; overflow: auto; flex-wrap: nowrap; }
.tags-row::-webkit-scrollbar { height: 4px; }
.tags-row::-webkit-scrollbar-thumb { background: var(--line); border-radius: 2px; }

/* ===== 瀑布流 ===== */
.masonry {
  column-count: 2; column-gap: 8px; padding: 8px;
}
@media (min-width: 600px) { .masonry { column-count: 3; padding: 14px; column-gap: 14px; } }
@media (min-width: 900px) { .masonry { column-count: 4; } }
.card {
  display: block; break-inside: avoid; margin-bottom: 8px;
  background: #fff; border-radius: 10px; overflow: hidden;
  box-shadow: var(--shadow); color: inherit;
}
@media (min-width: 600px) { .card { margin-bottom: 14px; border-radius: 12px; } }
.card:hover { text-decoration: none; transform: translateY(-1px); transition: transform 0.15s; }
.card-img {
  width: 100%; background-size: cover; background-position: center;
  background-color: var(--accent-soft);
  aspect-ratio: 3/4; /* 兜底高度；实际图加载后由 background-size: cover 自然铺 */
}
.card-body { padding: 8px 10px 10px; }
.card-title { font-size: 13px; font-weight: 500; line-height: 1.3; margin-bottom: 4px; }
.card-meta { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.card-meta .qty { color: var(--ok); }
.card-tags { margin-top: 4px; }

/* 浮动退出 */
.logout-fab { position: fixed; right: 16px; bottom: 24px; width: 44px; height: 44px; border-radius: 50%; background: rgba(0,0,0,0.55); color: #fff; border: 0; font-size: 18px; z-index: 20; }

/* ===== SKU 详情页 ===== */
.sku-main { padding: 14px; }
.sku-info { background: #fff; border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); margin-bottom: 14px; }
.sku-info .info-row { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 8px; }
.sku-info .info-row.tags { gap: 4px; }
.sku-info .kv { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); }
.sku-info .kv b { font-size: 14px; color: var(--fg); margin-top: 2px; }
.sku-info .selling { margin: 8px 0 0; font-size: 13px; line-height: 1.5; color: var(--fg); }
.sku-stock { background: #fff; border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); margin-bottom: 14px; }
.sku-stock h2 { margin: 0 0 8px; font-size: 14px; color: var(--muted); font-weight: 500; }
.stock-total { font-size: 18px; font-weight: 600; color: var(--ok); margin-bottom: 12px; }
.stock-total.sold-out { color: var(--muted); }
.sku-stock ul { list-style: none; padding: 0; margin: 0; }
.sku-stock li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 13px; gap: 8px; }
.sku-stock li:last-child { border-bottom: 0; }
/* 售罄行：整行灰化，让「卖掉了」按钮 disabled 状态视觉上更明显 */
.sku-stock li.zero { opacity: 0.5; }
.sku-stock li.zero .loc-qty, .sku-stock li.zero .loc-name { color: var(--muted); }
.sku-stock li.zero .loc-qty { color: var(--muted); }
.sku-stock .loc-name { flex: 1; }
.sku-stock .loc-qty { font-weight: 600; min-width: 50px; text-align: right; }
.sku-stock .loc-days { color: var(--muted); font-size: 11px; min-width: 56px; text-align: right; }
.sold-out-btn { background: #fff; color: #c33; border: 1px solid #e8d5d2; padding: 4px 10px; border-radius: 6px; font-size: 12px; cursor: pointer; }
.sold-out-btn:hover { background: #fbe; }
.sold-out-btn:disabled { opacity: 0.35; cursor: not-allowed; background: #f5f5f5; color: #aaa; border-color: #ddd; }
.sku-images { background: #fff; border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.sku-images h2 { margin: 12px 0 8px; font-size: 14px; color: var(--muted); font-weight: 500; }
.sku-images h2:first-child { margin-top: 0; }
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.img-card { margin: 0; background: var(--accent-soft); border-radius: 8px; overflow: hidden; }
.img-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.img-card figcaption { padding: 4px 6px; background: #fff; }
.img-card .dl { display: block; text-align: center; font-size: 11px; padding: 3px 0; }
.img-card .dl-btn { display: block; width: 100%; text-align: center; font-size: 11px; padding: 3px 0; border: 0; background: transparent; color: var(--accent); cursor: pointer; }
.img-card .dl-btn:hover { text-decoration: underline; }

/* ===== 后台 ===== */
.admin-tabs { display: flex; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 45px; z-index: 9; }
.admin-tabs .tab { flex: 1; padding: 12px 8px; background: transparent; border: 0; color: var(--muted); border-bottom: 2px solid transparent; }
.admin-tabs .tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.admin-main { padding: 14px; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }
.pane-toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.pane-toolbar input { flex: 1; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.data-table { width: 100%; background: #fff; border-collapse: collapse; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); font-size: 13px; }
.data-table th, .data-table td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--line); }
.data-table th { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.data-table td.op { white-space: nowrap; }
.data-table td.op button { margin-right: 4px; }

/* 可排序表头 */
.data-table.sortable th[data-sort] {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 18px;
}
.data-table.sortable th[data-sort]:hover { background: rgba(217, 83, 79, 0.06); }
.data-table.sortable th[data-sort]::after {
  content: '⇅';
  position: absolute;
  right: 4px;
  color: #ccc;
  font-size: 11px;
  font-weight: 400;
}
.data-table.sortable th.sort-asc::after  { content: '▲'; color: var(--accent); }
.data-table.sortable th.sort-desc::after { content: '▼'; color: var(--accent); }

.upload-form, #importForm { display: grid; gap: 10px; background: #fff; border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.upload-form label, #importForm label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.upload-form input, .upload-form select, #importForm textarea { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
#importForm textarea { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.import-result {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  display: block;
  white-space: pre-wrap;
}
.import-result.ok   { background: #f0fff4; color: #2f7a3b; border: 1px solid #bce5c4; }
.import-result.warn { background: #fff8e1; color: #8a6300; border: 1px solid #f2dc91; }
.import-result.err  { background: #fdecea; color: #a4332c; border: 1px solid #f5c2bf; }
pre { background: #1a1410; color: #f3e9dd; padding: 10px; border-radius: 6px; overflow: auto; font-size: 12px; }

/* ===== 模态 ===== */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 30; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: var(--radius); width: 100%; max-width: 420px; max-height: 90vh; display: flex; flex-direction: column; padding: 0; box-shadow: 0 8px 32px rgba(0,0,0,0.15); }
.modal-card.wide { max-width: 600px; }
.modal-card h2 { margin: 0; padding: 14px 18px 10px; font-size: 16px; border-bottom: 1px solid var(--line); }
.modal-card form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.modal-card .modal-body > label,
.modal-card .modal-body > div > label { display: block; margin: 12px 0 0; font-size: 13px; color: var(--muted); }
.modal-card .modal-body > label { display: block; margin: 12px 0 0; font-size: 13px; color: var(--muted); }
.modal-card .modal-body > div { display: block; }
.modal-card .modal-body label { color: var(--muted); }
.modal-card .modal-body input,
.modal-card .modal-body textarea,
.modal-card .modal-body select { display: block; width: 100%; box-sizing: border-box; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 14px; font-family: inherit; color: var(--fg); background: #fff; }
.modal-card .modal-body select { padding-right: 28px; }   /* 留箭头位 */
.modal-card .modal-body label > small { display: block; margin-top: 4px; }
.modal-card input, .modal-card textarea { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; }
.modal-card form > .modal-actions { padding: 14px 18px; border-top: 1px solid var(--line); background: #faf7f3; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: auto; position: sticky; bottom: 0; }
.modal-actions button { padding: 9px 18px; border: 1px solid var(--line); background: #fff; border-radius: 6px; color: var(--fg); font-size: 14px; line-height: 1.4; min-width: 64px; }
.modal-actions button.primary { background: var(--accent); color: #fff !important; border: 0; font-weight: 500; }
#stockMatrixTable input.entered { padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; font-size: 13px; }

/* ===== 标签编辑器 (chips + 联想) ===== */
.tags-editor { position: relative; }
.tags-editor .chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; min-height: 24px; }
.tags-editor .chips .chip { background: var(--accent-soft, #fcf3e3); color: var(--accent, #b2865a); padding: 2px 6px 2px 10px; border-radius: 12px; font-size: 12px; display: inline-flex; align-items: center; gap: 4px; }
.tags-editor .chips .chip button { background: transparent; border: 0; color: inherit; cursor: pointer; font-size: 14px; line-height: 1; padding: 0 4px; }
.tags-editor .chips .chip button:hover { color: #c33; }
.tags-editor input[type="text"] { width: 100%; box-sizing: border-box; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; }
.tags-editor .tag-suggest { position: absolute; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--line); border-radius: 6px; margin-top: 4px; box-shadow: 0 4px 12px rgba(0,0,0,0.08); max-height: 160px; overflow-y: auto; z-index: 5; }
.tags-editor .tag-suggest .opt { padding: 8px 12px; cursor: pointer; font-size: 13px; }
.tags-editor .tag-suggest .opt:hover,
.tags-editor .tag-suggest .opt.focus { background: var(--accent-soft, #fcf3e3); }

/* ===== skuModal 图片管理：+ 占位 + 预览模态 ===== */
.img-grid-wrap { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; align-items: start; }
.img-grid-wrap .img-sortable { display: contents; }   /* 自己的 li 直接进入父 grid（同级 cell） */
.img-add { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 96px; aspect-ratio: 1/1; border: 1px dashed #c8b89a; background: #fdfaf6; color: var(--accent, #b2865a); border-radius: 6px; cursor: pointer; font: inherit; padding: 0; }
.img-add:hover, .img-add:focus { background: #fcf3e3; border-color: var(--accent, #b2865a); outline: none; }
.img-add .plus { font-size: 32px; line-height: 1; font-weight: 200; margin-top: -2px; }
.img-add .lbl { font-size: 12px; margin-top: 4px; color: var(--accent, #b2865a); }

.preview-modal { background: rgba(0,0,0,0.85); padding: 24px; }
.preview-modal[hidden] { display: none; }
.preview-modal img { display: block; max-width: 92vw; max-height: 92vh; margin: auto; }
.preview-close { position: absolute; top: 16px; right: 16px; width: 36px; height: 36px; background: rgba(0,0,0,0.6); color: #fff; border: 0; border-radius: 50%; font-size: 20px; cursor: pointer; }
.preview-close:hover { background: rgba(0,0,0,0.85); }

/* 缩略图可点击：cursor 提示 */
#skuImagesList li { cursor: pointer; }
#skuImagesList li .del-img,
#skuImagesList li .del-img:hover { z-index: 3; }
.modal-card .modal-body { overflow-y: auto; padding: 8px 18px 18px; flex: 1; min-height: 0; }

/* ===== 批量导图 + 图库浏览 ===== */
.section-divider { border: none; border-top: 1px dashed var(--line); margin: 24px 0 16px; }
.batch-import .dropzone { border: 2px dashed var(--line); border-radius: 8px; padding: 24px; text-align: center; background: #fdfaf6; transition: all .15s; }
.batch-import .dropzone.over { background: #fcf3e3; border-color: var(--accent, #b2865a); }
.batch-import .dropzone p { margin: 6px 0; color: var(--muted); }
.batch-import .dropzone .small { font-size: 12px; }
.batch-import label.as-btn { display: inline-block; cursor: pointer; padding: 8px 14px; border-radius: 6px; }
.batch-import .batch-controls { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; margin-top: 12px; }
.batch-import .batch-controls label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.batch-import .batch-controls select { padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.batch-import .batch-progress { margin-top: 12px; }
.batch-import .batch-progress .bar { background: #ece6da; height: 8px; border-radius: 4px; overflow: hidden; }
.batch-import .batch-progress .fill { background: var(--accent, #b2865a); height: 100%; width: 0; transition: width .25s; }
.batch-import .batch-progress span { display: inline-block; margin-top: 6px; font-size: 13px; color: var(--muted); }
.batch-import .batch-result { margin-top: 12px; padding: 10px 12px; background: #f8f4ec; border-radius: 6px; font-size: 13px; }
.batch-import .batch-result ul { margin: 8px 0 0; padding-left: 18px; max-height: 200px; overflow: auto; }
.batch-import .batch-result li.skip { color: #a4602b; }
.batch-import .batch-result li.orphan { color: #665; }
.batch-import .batch-result li.ok { color: #4a6a3a; }

.folder-list { margin-top: 12px; }
details.folder-row { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 8px; background: #fff; overflow: hidden; }
details.folder-row > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer; user-select: none; }
details.folder-row > summary::-webkit-details-marker { display: none; }
details.folder-row > summary::before { content: '▶'; color: var(--muted); font-size: 11px; transition: transform 0.15s; }
details.folder-row[open] > summary::before { transform: rotate(90deg); }
details.folder-row > summary .bc { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 600; }
details.folder-row > summary .cnt { font-size: 12px; color: var(--muted); }
details.folder-row > summary .del-folder { margin-left: auto; background: transparent; border: 0; color: #c33; font-size: 16px; cursor: pointer; padding: 0 6px; }
details.folder-row > summary .del-folder:hover { color: #800; }
details.folder-row > summary:hover { background: #faf3e8; }
details.folder-row > .thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 6px; padding: 10px; background: #faf7f3; border-top: 1px solid var(--line); }
details.folder-row > .thumb-grid img { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: 4px; background: #ddd; display: block; }

/* ===== 图片排序 + 删除 ===== */
.img-sortable { list-style: none; padding: 0; margin: 8px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.img-sortable li { position: relative; background: #fff; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; cursor: grab; aspect-ratio: 1/1; }
.img-sortable li:active { cursor: grabbing; }
.img-sortable li.drag-over { outline: 2px dashed var(--accent, #b2865a); }
.img-sortable li.cover::before { content: '首图'; position: absolute; top: 4px; left: 4px; background: var(--accent, #b2865a); color: #fff; font-size: 10px; padding: 2px 6px; border-radius: 4px; z-index: 2; }
.img-sortable li img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-sortable li .del-img { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,0.65); color: #fff; border: 0; border-radius: 50%; width: 22px; height: 22px; line-height: 18px; padding: 0; cursor: pointer; font-size: 14px; z-index: 2; }
.img-sortable li .del-img:hover { background: #c33; }
.img-sortable li .orphan-badge { position: absolute; bottom: 4px; left: 4px; background: rgba(160,96,43,0.85); color: #fff; font-size: 10px; padding: 2px 6px; border-radius: 4px; z-index: 2; }
.folder-row .thumb-grid .cell-img { position: relative; }
.folder-row .thumb-grid .cell-img .del-img { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,0.65); color: #fff; border: 0; border-radius: 50%; width: 20px; height: 20px; line-height: 16px; padding: 0; cursor: pointer; font-size: 12px; }
.folder-row .thumb-grid .cell-img .del-img:hover { background: #c33; }
.folder-row .thumb-grid .cell-img .cover-badge { position: absolute; top: 2px; left: 2px; background: var(--accent, #b2865a); color: #fff; font-size: 10px; padding: 1px 5px; border-radius: 4px; }
