:root {
    --ink: #14181d;
    --ink-soft: #5b6673;
    --line: #e2e6ec;
    --surface: #ffffff;
    --canvas: #f4f6f9;
    --accent: #1f7a5a;
    --accent-soft: #e6f2ed;
    --danger: #b3261e;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    display: flex;
    min-height: 100vh;
    background: var(--canvas);
    color: var(--ink);
    font: 14px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

h1 { font-size: 22px; margin: 0 0 20px; }
h2 { font-size: 17px; margin: 32px 0 14px; }

.muted { color: var(--ink-soft); }
.hint { color: var(--ink-soft); font-size: 12px; font-weight: 400; margin-left: 6px; }

/* ---------- 侧边导航 ---------- */

.sidebar {
    width: 200px;
    flex-shrink: 0;
    background: var(--ink);
    color: #f2f4f7;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar .brand {
    padding: 22px 20px;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 2px;
    border-bottom: 1px solid #2a2f37;
}

.sidebar nav { padding: 12px 0; flex: 1; overflow-y: auto; }

.sidebar nav a {
    display: block;
    padding: 10px 20px;
    color: #b9c1cc;
    border-left: 3px solid transparent;
}

.sidebar nav a:hover { background: #1d222a; color: #fff; }
.sidebar nav a.active { background: #1d222a; color: #fff; border-left-color: var(--accent); }

.sidebar-foot {
    padding: 16px 20px;
    border-top: 1px solid #2a2f37;
    display: grid;
    gap: 8px;
    font-size: 12px;
    color: #93a0af;
}

.sidebar-foot a { color: #d5dce4; }
.sidebar-foot a:hover { color: #fff; }

/* ---------- 主内容 ---------- */

.content { flex: 1; padding: 28px 32px 60px; min-width: 0; }

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.page-head h1 { margin: 0; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 18px;
    display: grid;
    gap: 6px;
}

.stat span { color: var(--ink-soft); font-size: 12px; }
.stat strong { font-size: 24px; font-weight: 600; }
a.stat:hover { border-color: var(--accent); }

/* ---------- 表格 ---------- */

.table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    background: var(--surface);
}

th, td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
    font-size: 13px;
}

th { background: #fafbfc; font-weight: 600; font-size: 12px; color: var(--ink-soft); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfd; }

/* 列表页：首列多为 ID，末列为操作（不含总览等无 table-wrap 的表） */
.table-wrap table th:first-child,
.table-wrap table td:first-child { width: 52px; max-width: 52px; }
.table-wrap table th:last-child,
.table-wrap table td:last-child { width: 96px; max-width: 110px; }

/* 总览 · 最近订单 */
table.table-recent th:nth-child(1),
table.table-recent td:nth-child(1) { width: 24%; }
table.table-recent th:nth-child(2),
table.table-recent td:nth-child(2) { width: 28%; }
table.table-recent th:nth-child(3),
table.table-recent td:nth-child(3) { width: 12%; }
table.table-recent th:nth-child(4),
table.table-recent td:nth-child(4) { width: 12%; }
table.table-recent th:nth-child(5),
table.table-recent td:nth-child(5) { width: 24%; }

.thumb { width: 40px; height: 40px; object-fit: contain; background: #f2f4f7; border-radius: 6px; }
.thumb-product {
  width: 56px;
  height: 56px;
  max-width: 56px !important;
  border-radius: 8px;
  background: #f1f1f1;
  border: 1px solid var(--line);
}
td:has(> .thumb-product) {
  width: 72px;
  min-width: 72px;
  max-width: 72px;
  vertical-align: middle;
}

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 20px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 12px;
}

.badge.on { background: var(--accent-soft); color: var(--accent); }
.badge.off { background: #f0f1f3; color: var(--ink-soft); }

.row-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-actions form { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.row-actions input { padding: 4px 7px; font-size: 12px; max-width: 88px; }

.link {
    background: none;
    border: 0;
    padding: 0;
    color: var(--accent);
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    text-decoration: underline;
}

.link.danger { color: var(--danger); }

/* ---------- 表单 ---------- */

.editor {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 24px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px 22px;
    max-width: 960px;
}

.editor label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; }
.editor label.wide, .editor .field-group.wide, .editor .form-actions { grid-column: 1 / -1; }

.editor label.inline {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-weight: 400;
    white-space: nowrap;
}

.field-group { display: grid; gap: 8px; }
.field-label { font-size: 13px; font-weight: 600; }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }

input, select, textarea {
    font: inherit;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    width: 100%;
    min-width: 0;
}

input[type="checkbox"] { width: auto; }
textarea { resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

.form-actions { margin-top: 6px; }

/* ---------- 图片本地上传 ---------- */

.image-field .image-upload {
    display: grid;
    grid-template-columns: 120px minmax(0, 1fr);
    gap: 16px;
    align-items: start;
}

.upload-preview {
    width: 120px;
    height: 120px;
    object-fit: contain;
    background: #f2f4f7;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.upload-preview.sm {
    width: 64px;
    height: 64px;
}

.upload-preview.empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ink-soft);
    font-size: 12px;
    font-weight: 400;
}

.image-upload-controls {
    display: grid;
    gap: 10px;
    min-width: 0;
}

.gallery-thumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.file-pick {
    display: inline-flex !important;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    width: fit-content;
}

.file-pick input[type="file"] {
    width: auto;
    max-width: 100%;
    padding: 6px 0;
    border: 0;
    background: transparent;
}

@media (max-width: 820px) {
    .image-field .image-upload {
        grid-template-columns: 1fr;
    }
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.button:hover { filter: brightness(1.08); }
.button.ghost { background: transparent; color: var(--ink); border-color: var(--line); }

.alert {
    padding: 11px 15px;
    border-radius: 6px;
    background: var(--accent-soft);
    color: var(--accent);
    margin: 0 0 18px;
}

.alert.error { background: #fdecea; color: var(--danger); }

/* ---------- 登录页 ---------- */

.login-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 36px 32px;
    width: 100%;
    max-width: 360px;
}

.login-card h1 { margin-bottom: 4px; }
.login-card .muted { margin: 0 0 22px; font-size: 13px; }
.login-card form { display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; }

@media (max-width: 820px) {
    body { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; }
    .sidebar nav { display: flex; overflow-x: auto; padding: 0; }
    .sidebar nav a { white-space: nowrap; border-left: 0; border-bottom: 3px solid transparent; }
    .sidebar nav a.active { border-left: 0; border-bottom-color: var(--accent); }
    .content { padding: 20px 16px 50px; }
    .editor { grid-template-columns: 1fr; padding: 18px; }
}


/* ---------- 分类标签 ---------- */

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    max-width: 100%;
    white-space: normal;
}

.tag {
    display: inline-flex;
    align-items: center;
    padding: 1px 6px;
    border-radius: 999px;
    background: #eef2f6;
    color: #334155;
    font-size: 11px;
    line-height: 1.4;
    max-width: 100%;
}

.tag-goal { background: #e8f5ef; color: #1f7a5a; }
.tag-more { background: transparent; color: var(--ink-soft); padding-left: 2px; }

.tag-picker-group { margin-top: 10px; }
.tag-picker-title {
    font-size: 12px;
    color: var(--ink-soft);
    margin-bottom: 8px;
    font-weight: 600;
}

.tag-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag-option {
    display: inline-flex !important;
    align-items: center;
    gap: 0;
    margin: 0;
    cursor: pointer;
    font-weight: 400 !important;
}

.tag-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.tag-option span {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--ink);
    font-size: 13px;
    transition: border-color .15s, background .15s, color .15s;
}

.tag-option:hover span,
.tag-option.is-on span,
.tag-option input:checked + span {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.js-upload-status.upload-error { color: var(--danger); }
.image-upload-controls input[readonly],
.image-upload-controls textarea[readonly] {
    background: #f7f8fa;
    color: var(--ink-soft);
}

/* 详情视频预览 */
.image-field video.upload-preview {
  width: 180px;
  height: 180px;
  object-fit: contain;
  background: #111;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.image-field .js-clear-upload {
  display: inline-block;
  margin-top: 6px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--danger, #b42318);
  font-size: 13px;
}

/* Product inline SKU editor */
.sku-editor {
  grid-column: 1 / -1;
  margin-top: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafbfc;
}
.sku-editor-head h2 {
  margin: 0 0 4px;
  font-size: 16px;
}
.sku-editor .sku-table input[type="text"],
.sku-editor .sku-table input[type="number"] {
  width: 100%;
  min-width: 72px;
  font-size: 13px;
}
.sku-editor .sku-image-cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 120px;
}
.sku-editor .sku-image-cell .upload-preview.sm {
  width: 56px;
  height: 56px;
}
.file-pick.compact {
  display: inline-flex;
  padding: 4px 8px;
  font-size: 12px;
}
.sku-editor .js-add-sku-row { margin-top: 10px; }

/* ---------- 分页 ---------- */

.list-meta { margin: 0 0 12px; }

.pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 18px;
}

.pager-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 34px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font-size: 13px;
}

a.pager-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.pager-btn.is-current {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}

.pager-btn.is-disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.pager-ellipsis {
    color: var(--ink-soft);
    padding: 0 2px;
}
