:root {
    --brand: #2563eb;
    --brand-dark: #1d4ed8;
    --text: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --bg: #f5f6f8;
    --surface: #ffffff;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --success: #15803d;
    --success-bg: #f0fdf4;
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    line-height: 1.6;
}

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

a:hover {
    text-decoration: underline;
}

h1, h2, h3 {
    margin: 0 0 16px;
    font-weight: 600;
}

/* ---------- 顶栏 ---------- */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 8px 24px;
    display: flex;
    align-items: center;
    gap: 8px 16px;
    /* 窄窗口下换行而不是挤压，避免品牌名与导航文字被竖向拆字 */
    flex-wrap: wrap;
    min-height: 56px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar .logo {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin-right: 16px;
    white-space: nowrap;
}

.topbar nav {
    display: flex;
    gap: 4px;
    flex: 1;
    flex-wrap: wrap;
}

.topbar nav a {
    padding: 8px 14px;
    border-radius: var(--radius);
    color: var(--text-muted);
    white-space: nowrap;
}

.topbar nav a:hover {
    background: var(--bg);
    text-decoration: none;
}

.topbar nav a.active {
    background: #eff6ff;
    color: var(--brand-dark);
    font-weight: 600;
}

.topbar .user-area {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.inline {
    display: inline;
    margin: 0;
}

/* ---------- 布局 ---------- */
.container {
    max-width: 1200px;
    margin: 24px auto;
    padding: 0 24px 48px;
}

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

.page-head h1 {
    margin: 0;
    font-size: 20px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat .label {
    color: var(--text-muted);
    margin-bottom: 6px;
}

.stat .value {
    font-size: 28px;
    font-weight: 700;
}

.stat .value.warn {
    color: var(--danger);
}

/* ---------- 表单 ---------- */
label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
}

input[type="text"], input[type="password"], input[type="number"],
select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    color: inherit;
    background: var(--surface);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

textarea {
    min-height: 110px;
    resize: vertical;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.form-grid .full {
    grid-column: 1 / -1;
}

.field-error {
    color: var(--danger);
    font-size: 13px;
    margin-top: 4px;
}

.hint {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 4px;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
    margin-bottom: 16px;
}

.filters .field {
    flex: 1 1 170px;
    min-width: 150px;
}

.form-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 24px;
}

/* ---------- 按钮 ---------- */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font: inherit;
    white-space: nowrap;
}

.btn:hover {
    background: var(--bg);
    text-decoration: none;
}

.btn-primary {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}

.btn-primary:hover {
    background: var(--brand-dark);
    border-color: var(--brand-dark);
    color: #fff;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 13px;
}

.link-btn {
    background: none;
    border: none;
    color: var(--brand);
    cursor: pointer;
    font: inherit;
    padding: 0;
}

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

.link-btn:hover {
    text-decoration: underline;
}

/* ---------- 表格 ---------- */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
}

th, td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

th {
    background: #fafafa;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

tbody tr:hover {
    background: #fbfcfe;
}

.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

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

.thumb {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    display: block;
}

.thumb-empty {
    width: 56px;
    height: 56px;
    border-radius: 6px;
    border: 1px dashed var(--border);
    background: var(--bg);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.thumb-large {
    max-width: 320px;
    max-height: 320px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.pre-wrap {
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
    font-family: inherit;
}

/* ---------- 提示 ---------- */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.alert-success {
    background: var(--success-bg);
    border-color: #bbf7d0;
    color: var(--success);
}

.alert-error {
    background: var(--danger-bg);
    border-color: #fecaca;
    color: var(--danger);
}

.empty {
    padding: 48px;
    text-align: center;
    color: var(--text-muted);
}

/* ---------- 分页 ---------- */
.pagination {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-top: 16px;
    flex-wrap: wrap;
}

.pagination a, .pagination span.current {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
}

.pagination span.current {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}

.pagination a:hover {
    border-color: var(--brand);
    text-decoration: none;
}

.pagination .disabled {
    color: var(--text-muted);
    padding: 6px 12px;
}

.page-info {
    color: var(--text-muted);
    margin-left: auto;
}

/* ---------- 登录页 ---------- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #eff6ff 0%, #f5f6f8 60%);
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px;
    box-shadow: 0 8px 30px rgba(15, 23, 42, 0.06);
}

.login-card h1 {
    font-size: 20px;
    text-align: center;
    margin-bottom: 4px;
}

.login-card .sub {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.login-card .field {
    margin-bottom: 16px;
}

.login-card .btn {
    width: 100%;
    justify-content: center;
    padding: 10px;
}

.definition {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr);
    gap: 10px 16px;
    max-width: 720px;
}

.definition dt {
    color: var(--text-muted);
}

.definition dd {
    margin: 0;
}

.footer {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    padding: 24px;
}

/* ---------- 模板里引用但前面未定义的补充类 ---------- */

/* 操作列：保持 td 默认的 table-cell 布局，否则该列不参与行列对齐，会整列错位；
   间距改用兄弟元素 margin 而不是 flex gap */
.actions {
    white-space: nowrap;
}

.actions > * + * {
    margin-left: 8px;
}

.table-wrap {
    padding: 0;
    overflow-x: auto;
    margin-top: 16px;
}

.table-wrap table {
    border: none;
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.image-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    background: var(--surface);
}

.grid-img {
    width: 100%;
    height: 132px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    display: block;
}

/* 图片下方的一行：封面标记 / 序号 + 删除勾选 */
.image-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.badge {
    background: var(--brand);
    color: #fff;
    border-radius: 999px;
    padding: 1px 8px;
    font-size: 12px;
    white-space: nowrap;
}

.seq {
    width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    border-radius: 50%;
    background: var(--bg);
    font-size: 12px;
}

.check {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
}

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.gallery-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    background: var(--surface);
}

.gallery-img {
    width: 100%;
    height: 150px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    display: block;
}

/* 列表缩略图容器，右上角叠加图片总数角标 */
.thumb-cell {
    position: relative;
    width: 56px;
}

.count-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 18px;
    height: 18px;
    line-height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    border: 1px solid var(--surface);
    background: var(--brand);
    color: #fff;
    font-size: 12px;
    text-align: center;
}

.thumb-placeholder {
    width: 320px;
    height: 200px;
    max-width: 100%;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

.section {
    margin-top: 16px;
}

.section h2 {
    font-size: 16px;
}

.page-head h2 {
    margin: 0;
    font-size: 16px;
}

.form-actions.centered {
    justify-content: center;
}

.error-page {
    text-align: center;
    padding: 80px 24px;
}

.error-page .code {
    font-size: 56px;
    font-weight: 700;
    color: var(--brand);
    margin: 0;
}

.error-page .msg {
    color: var(--text-muted);
    margin: 12px 0 24px;
}

/* ---------- 父子模块层级 ---------- */

/* 子模块子表紧贴父行下方：去掉外层单元格留白，用浅底与主表区分 */
.sub-row > td {
    padding: 0;
    background: var(--bg);
}

.subtable {
    background: var(--surface);
    border-top: 1px solid var(--border);
    font-size: 13px;
}

.subtable td {
    padding: 8px 10px;
}

.subtable tbody tr:last-child td {
    border-bottom: none;
}

/* 子表里的缩略图比主表再小一号，避免层级视觉上比父行更抢眼 */
.subtable .thumb-cell {
    width: 40px;
}

.subtable .thumb,
.subtable .thumb-empty {
    width: 40px;
    height: 40px;
}

/* 树形连接符，强调该行属于上面的父产品 */
.sub-flag {
    color: var(--text-muted);
    margin-right: 4px;
}

/* 子产品名称用绿色，与主表蓝色链接区分层级 */
.subtable .sub-link {
    color: var(--success);
}

.subtable .sub-link:hover {
    color: #15603d;
}

@media (max-width: 820px) {
    .form-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .topbar {
        padding: 0 12px;
    }

    .topbar .logo {
        margin-right: 12px;
    }
}
