:root {
  --bg: #f7f5f2;
  --surface: #ffffff;
  --surface-2: #fbfaf8;
  --line: #e6e1da;
  --line-strong: #d5cec4;
  --text: #241f1a;
  --muted: #7a7167;
  --brand: #8b5a2b;
  --brand-dark: #6f4620;
  --brand-soft: #f3ece3;
  --ok: #1a7f43;
  --ok-bg: #eaf6ee;
  --warn: #9a6207;
  --warn-bg: #fdf5e4;
  --err: #b3261e;
  --err-bg: #fdeceb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(36, 31, 26, .04), 0 8px 24px rgba(36, 31, 26, .06);
}

* { box-sizing: border-box; }

/* hidden 属性优先级高于组件自身的 display（如 .upload-preview 的 flex） */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }

/* ---------- 顶部导航 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 20px;
  height: 60px; display: flex; align-items: center; gap: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); }
.brand:hover { color: var(--text); }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(140deg, #a9723a, #7c4a1e);
  display: grid; place-items: center; color: #fff; font-size: 15px;
}
.brand-sub { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 2px; }
.topnav { display: flex; gap: 4px; margin-left: 8px; }
.topnav a {
  padding: 6px 12px; border-radius: 8px; color: var(--muted); font-size: 14px;
}
.topnav a:hover { background: var(--surface-2); color: var(--text); }
.topnav a.is-active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--line); font-size: 13px;
}
.avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--brand);
  color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 600;
}

/* ---------- 布局 ---------- */
.page { max-width: 1080px; margin: 0 auto; padding: 28px 20px 80px; }
.page-head { margin-bottom: 20px; }
.page-head h1 { margin: 0 0 6px; font-size: 25px; letter-spacing: -.01em; }
.page-head p { margin: 0; color: var(--muted); font-size: 14px; }
.eyebrow {
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--brand); font-weight: 700; margin: 0 0 6px;
}

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px 24px; margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.card-head h2 { margin: 0; font-size: 17px; }
.card-head .hint { margin: 0; color: var(--muted); font-size: 13px; }

.split { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: 18px; align-items: start; }
@media (max-width: 880px) { .split { grid-template-columns: 1fr; } }

/* ---------- 表单 ---------- */
.field { margin-bottom: 18px; }
.field > label, .field-label {
  display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; color: var(--text);
}
.field-hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.input, input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 9px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus, input:focus, select:focus, textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px rgba(139, 90, 43, .12);
}
textarea { resize: vertical; min-height: 84px; }
.name-preview {
  margin-top: 8px; padding: 8px 12px; background: var(--surface-2);
  border: 1px dashed var(--line-strong); border-radius: 8px;
  font-size: 13px; color: var(--muted);
}
.name-preview strong { color: var(--text); font-size: 15px; letter-spacing: .02em; }

/* 上传区 */
.dropzone {
  position: relative; border: 1.5px dashed var(--line-strong); border-radius: 12px;
  background: var(--surface-2); padding: 26px 20px; text-align: center;
  transition: border-color .15s, background .15s; cursor: pointer;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--brand); background: var(--brand-soft); }
.dropzone input[type=file] {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer;
}
.dropzone-icon { font-size: 26px; line-height: 1; margin-bottom: 8px; }
.dropzone-title { font-weight: 600; font-size: 14px; }
.dropzone-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.upload-preview {
  display: flex; align-items: center; gap: 14px; margin-top: 14px;
  padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.upload-preview img {
  width: 68px; height: 68px; object-fit: cover; border-radius: 8px; background: #eee;
}
.upload-preview .meta { font-size: 12px; color: var(--muted); }
.upload-preview .meta strong { display: block; color: var(--text); font-size: 13px; margin-bottom: 2px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px; border: 1px solid transparent; border-radius: 9px;
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer;
  background: var(--brand); color: #fff; text-decoration: none;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--brand-dark); color: #fff; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .6; cursor: not-allowed; }
.btn-lg { padding: 12px 26px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--err); }
.btn-danger:hover { background: #94201a; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- 提示 ---------- */
.flash-stack { margin-bottom: 16px; display: grid; gap: 8px; }
.flash {
  padding: 11px 14px; border-radius: 9px; font-size: 14px;
  border: 1px solid transparent; display: flex; gap: 8px;
}
.flash.ok { background: var(--ok-bg); color: #14602f; border-color: #c7e8d2; }
.flash.error { background: var(--err-bg); color: #8c1d17; border-color: #f3c9c6; }
.flash.warn, .flash.message { background: var(--warn-bg); color: #7c4f05; border-color: #f0ddb0; }

/* ---------- 徽章 ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: #f1efec; color: #5d554c; border: 1px solid var(--line);
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.badge.ok { background: var(--ok-bg); color: #14602f; border-color: #c7e8d2; }
.badge.warn { background: var(--warn-bg); color: #7c4f05; border-color: #f0ddb0; }
.badge.err { background: var(--err-bg); color: #8c1d17; border-color: #f3c9c6; }
.badge.info { background: var(--brand-soft); color: var(--brand-dark); border-color: #e3d3bf; }
.badge-plain::before { display: none; }

/* ---------- 文件卡片 ---------- */
.file-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.file-card {
  border: 1px solid var(--line); border-radius: 11px; background: var(--surface);
  padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.file-card .kind { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .04em; }
.file-card .fname { font-weight: 600; font-size: 14px; word-break: break-all; }
.file-card .fmeta { font-size: 12px; color: var(--muted); }
.file-card .btn { margin-top: auto; }

/* ---------- 预览 ---------- */
.preview-frame {
  border: 1px solid var(--line); border-radius: 11px; overflow: hidden;
  background:
    linear-gradient(45deg, #ececec 25%, transparent 25%, transparent 75%, #ececec 75%),
    linear-gradient(45deg, #ececec 25%, #fff 25%, #fff 75%, #ececec 75%);
  background-size: 18px 18px;
  background-position: 0 0, 9px 9px;
}
.preview-frame img { display: block; width: 100%; height: auto; }
/* 生产预览 tab：切换时不改变布局，图片自适应留白 */
.preview-tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 9px; width: max-content; }
.preview-tabs .ptab {
  border: 0; background: none; padding: 6px 12px; border-radius: 7px;
  font: inherit; font-size: 12.5px; color: var(--muted); cursor: pointer;
}
.preview-tabs .ptab.is-active {
  background: var(--surface); color: var(--text); font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
}
.preview-tabs .ptab:disabled { opacity: .4; cursor: default; }
.preview-tabs-bar { margin: 10px 0 12px; }
.preview-frame img.tab-preview {
  width: auto; max-width: 100%; max-height: 520px; margin: 0 auto;
}
.preview-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
/* 打标文样是竖长图，限制高度避免把页面拉太长，点开可看原图 */
.preview-frame img.marking-preview {
  width: auto; max-width: 100%; max-height: 460px; margin: 0 auto;
}
.preview-caption { font-size: 12px; color: var(--muted); margin: 8px 0 0; text-align: center; }

/* ---------- 裁剪编辑器 ---------- */
.crop-editor { max-width: 520px; margin: 0 auto; }
.crop-editor-stage {
  position: relative; width: 100%; aspect-ratio: 1 / 1; overflow: hidden;
  border-radius: 12px; background: #23211f; cursor: grab;
  touch-action: none; user-select: none;
}
.crop-editor-stage.is-dragging { cursor: grabbing; }
.crop-editor-stage img {
  position: absolute; left: 50%; top: 50%;
  transform-origin: center center; pointer-events: none;
  -webkit-user-drag: none; user-select: none; will-change: transform;
}
.crop-editor-mask {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 92%; height: 92%; border-radius: 50%;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .55);
  border: 1.5px solid rgba(255, 255, 255, .85);
  pointer-events: none;
}
.crop-controls { display: grid; gap: 10px; margin-top: 16px; }
.crop-control { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.crop-control > label { flex: none; width: 44px; color: var(--muted); }
.crop-control input[type=range] { flex: 1; min-width: 0; accent-color: var(--brand); }
.crop-control .val {
  flex: none; width: 52px; text-align: right; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.crop-control .btn.is-on { border-color: var(--brand); color: var(--brand-dark); background: var(--brand-soft); }

/* ZIP 下载 */
.zip-box {
  display: flex; align-items: center; gap: 16px; padding: 18px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2);
}
.zip-box .zip-icon {
  flex: none; width: 52px; height: 52px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: var(--brand-soft); color: var(--brand-dark);
  font-weight: 700; font-size: 13px; letter-spacing: .04em;
}
.zip-box .zip-meta { flex: 1; min-width: 0; }
.zip-box .zip-meta strong { display: block; font-size: 15px; word-break: break-all; }
.zip-box .zip-meta span { font-size: 12px; color: var(--muted); }
@media (max-width: 520px) { .zip-box { flex-wrap: wrap; } }

/* ---------- 列表 ---------- */
.list { display: grid; gap: 10px; }
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); transition: border-color .15s;
}
.list-row:hover { border-color: var(--line-strong); }
.list-row .main { min-width: 0; }
.list-row .title { font-weight: 600; font-size: 14px; }
.list-row .sub { font-size: 12px; color: var(--muted); }
.list-row .tail { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.empty {
  padding: 34px 20px; text-align: center; color: var(--muted); font-size: 14px;
  border: 1px dashed var(--line-strong); border-radius: 11px; background: var(--surface-2);
}

/* ---------- 结果页 ---------- */
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.meta-item .k { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.meta-item .v { font-size: 14px; font-weight: 600; word-break: break-all; }

.flag-list { display: flex; flex-wrap: wrap; gap: 8px; }

details.advanced { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 14px; }
details.advanced summary {
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted);
  list-style: none; display: flex; align-items: center; gap: 6px;
}
details.advanced summary::-webkit-details-marker { display: none; }
details.advanced summary::before { content: "▸"; transition: transform .15s; }
details.advanced[open] summary::before { transform: rotate(90deg); }
details.advanced .adv-body { margin-top: 14px; }

.loading-mask {
  position: fixed; inset: 0; z-index: 90; display: none;
  background: rgba(247, 245, 242, .82); backdrop-filter: blur(3px);
  place-items: center;
}
.loading-mask.is-on { display: grid; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line-strong); border-top-color: var(--brand);
  animation: spin .8s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 14px; color: var(--muted); text-align: center; }

/* ---------- 登录页 ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); padding: 30px 28px;
}
.auth-card .brand { justify-content: center; margin-bottom: 18px; }
.auth-card h1 { font-size: 19px; margin: 0 0 4px; text-align: center; }
.auth-card .sub { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 22px; }

/* ---------- 错误页 ---------- */
.error-page { min-height: 70vh; display: grid; place-items: center; text-align: center; }
.error-page .code { font-size: 60px; font-weight: 700; color: var(--line-strong); line-height: 1; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0; }
.mt-16 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }
