/* ============================================================
   AI 3D 模型生成平台 · 单机版 设计系统（零外部依赖）
   ============================================================ */
:root {
    --bg: #f4f6fb;
    --card: #ffffff;
    --line: #e5e9f2;
    --line-strong: #d5dbe8;
    --text: #1e2537;
    --muted: #6b7590;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef2ff;
    --ok: #16a34a;
    --ok-soft: #ecfdf3;
    --bad: #dc2626;
    --bad-soft: #fef2f2;
    --warn: #d97706;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.6 system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { line-height: 1.35; }
code { background: #f1f4fb; padding: 1px 6px; border-radius: 6px; font-size: 12px; }

/* ---------- 顶栏 ---------- */
.topbar { position: sticky; top: 0; z-index: 50; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 0 24px; height: 58px; display: flex; align-items: center; gap: 26px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 700; font-size: 15px; }
.brand-mark { color: #fff; background: linear-gradient(135deg, #6366f1, #22d3ee); width: 28px; height: 28px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; font-size: 15px; }
.brand-mark.big { width: 52px; height: 52px; font-size: 26px; border-radius: 15px; }
.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a { color: var(--muted); padding: 7px 13px; border-radius: 9px; font-weight: 500; }
.topnav a:hover { color: var(--text); background: #f1f4fb; }
.topnav a.active { color: var(--primary); background: var(--primary-soft); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-name { color: var(--muted); font-size: 13px; }
.credit-pill { display: inline-flex; align-items: center; gap: 5px; background: linear-gradient(135deg, #eef2ff, #ecfeff); border: 1px solid #e0e7ff; color: var(--primary); font-weight: 700; padding: 5px 12px; border-radius: 999px; }
.credit-pill:hover { filter: brightness(.98); }
.credit-icon { font-size: 12px; }
.credit-unit { font-size: 11px; font-weight: 500; color: #818cf8; }

/* ---------- 布局 ---------- */
.container { max-width: 1240px; margin: 0 auto; padding: 26px 24px 40px; }
.footer { text-align: center; color: #9aa4bd; font-size: 12px; padding: 18px 0 26px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card-title { font-size: 16px; font-weight: 700; margin: 0 0 14px; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.sec-head .card-title { margin: 0; }
.inline-form { display: inline; }

/* ---------- 提示条 ---------- */
.toast { position: fixed; top: 70px; right: 20px; z-index: 100; padding: 11px 18px; border-radius: 12px; font-size: 13px; box-shadow: var(--shadow); border: 1px solid; max-width: 420px; }
.toast-success { background: var(--ok-soft); color: #166534; border-color: #bbf7d0; }
.toast-error { background: var(--bad-soft); color: #991b1b; border-color: #fecaca; }

/* ---------- 按钮 ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--line-strong); background: #fff; color: var(--text); font-size: 13px; font-weight: 500; cursor: pointer; transition: all .15s; }
.btn:hover { border-color: #b9c2d8; background: #f8fafd; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-sm { padding: 5px 11px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; padding: 11px; font-size: 14px; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: #f1f4fb; }
.btn-danger-ghost { border-color: transparent; background: transparent; color: var(--bad); }
.btn-danger-ghost:hover { background: var(--bad-soft); }
.btn-link { border: 0; background: none; color: var(--primary); cursor: pointer; font-size: 12px; padding: 0 4px; }

/* ---------- 表单 ---------- */
.form-row { margin-bottom: 14px; }
.form-row label, .field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
    width: 100%; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: 10px;
    font: inherit; color: var(--text); background: #fff; outline: none; transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: #a5b4fc; box-shadow: 0 0 0 3px rgba(99, 102, 241, .14); }
textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
input[readonly] { background: #f8fafc; color: var(--muted); }
.field-error { color: var(--bad); font-size: 12px; margin: 5px 0 0; }
.checkbox-row { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-size: 13px; color: var(--text); }
.checkbox-row input { width: 15px; height: 15px; accent-color: var(--primary); }
.select-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.select-inline select { width: auto; padding: 6px 10px; }
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr) auto; gap: 12px; align-items: end; }
.form-grid .form-row { margin: 0; }
.form-grid .checkbox-row { padding-bottom: 10px; }

/* ---------- 提示文字 ---------- */
.hint { color: var(--muted); font-size: 13px; margin: 8px 0; }
.hint.small { font-size: 12px; }
.hint.ok { color: var(--ok); }
.muted { color: var(--muted); }
.pos { color: var(--ok); font-weight: 600; }
.neg { color: var(--bad); font-weight: 600; }

/* ---------- 徽章 ---------- */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge-pending { background: #f1f5f9; color: #64748b; }
.badge-processing { background: var(--primary-soft); color: var(--primary); animation: pulse 1.6s infinite; }
.badge-succeeded { background: var(--ok-soft); color: #15803d; }
.badge-failed { background: var(--bad-soft); color: #b91c1c; }
.badge-admin { background: #fef3c7; color: #92400e; font-size: 11px; margin-left: 4px; }
.badge-type-grant { background: var(--ok-soft); color: #15803d; }
.badge-type-consume { background: var(--primary-soft); color: var(--primary); }
.badge-type-refund { background: #fff7ed; color: #c2410c; }
.badge-type-adjust { background: #f1f5f9; color: #64748b; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }

/* ---------- 进度条 ---------- */
.progress { height: 6px; border-radius: 4px; background: #edf0f7; overflow: hidden; margin: 8px 0 2px; }
.progress-lg { height: 10px; width: 260px; max-width: 80%; }
.progress-bar { height: 100%; border-radius: 4px; background: linear-gradient(90deg, #6366f1, #22d3ee); transition: width .6s ease; }

/* ---------- 登录页 ---------- */
.guest-body { background: linear-gradient(160deg, #1e1b4b 0%, #312e81 45%, #0e7490 130%); }
.guest-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 30px 16px; }
.guest-brand { text-align: center; color: #fff; margin-bottom: 26px; }
.guest-brand h1 { font-size: 24px; margin: 14px 0 6px; }
.guest-brand p { color: #c7d2fe; font-size: 13px; margin: 0; }
.guest-brand .brand-mark { margin: 0 auto; }
.guest-card { width: 380px; max-width: 100%; padding: 28px; }
.card-title { margin-bottom: 18px; }
.guest-foot { color: #a5b4fc; font-size: 12px; margin-top: 18px; }

/* ---------- 工作台 ---------- */
.dash-grid { display: grid; grid-template-columns: 400px minmax(0, 1fr); gap: 22px; align-items: start; }
.seg-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.seg-tab { border: 1px solid var(--line-strong); background: #fff; border-radius: 11px; padding: 10px 8px; cursor: pointer; font: inherit; font-weight: 600; font-size: 13px; color: var(--text); text-align: center; transition: all .15s; }
.seg-tab small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; margin-top: 2px; }
.seg-tab.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.seg-tab.active small { color: #818cf8; }
#modeHint { margin: 2px 0 14px; }

.dropzone { border: 2px dashed #c4cbe0; border-radius: 12px; padding: 26px 14px; text-align: center; cursor: pointer; transition: all .15s; background: #fafbfe; }
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: var(--primary-soft); }
.dz-icon { font-size: 26px; color: #a5b4fc; line-height: 1; }
.dz-main { font-weight: 600; margin: 8px 0 2px; }
.dz-sub { color: var(--muted); font-size: 12px; margin: 0; }

.file-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.file-item { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; }
.file-item img, .file-item .fi-ph { width: 38px; height: 38px; border-radius: 8px; object-fit: cover; background: #eef1f8; display: flex; align-items: center; justify-content: center; color: #a5b4fc; font-size: 16px; flex: none; }
.fi-info { flex: 1; min-width: 0; }
.fi-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fi-sub { font-size: 11px; color: var(--muted); }
.fi-progress { height: 4px; border-radius: 2px; background: #edf0f7; margin-top: 5px; overflow: hidden; }
.fi-progress > div { height: 100%; background: linear-gradient(90deg, #6366f1, #22d3ee); transition: width .3s; }
.fi-done { color: var(--ok); font-size: 12px; flex: none; }
.fi-remove { border: 0; background: none; color: #9aa4bd; cursor: pointer; font-size: 16px; padding: 2px 6px; flex: none; }
.fi-remove:hover { color: var(--bad); }
.fi-error { color: var(--bad); font-size: 12px; flex: none; }

.options-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 16px 0 4px; flex-wrap: wrap; }
.cost-box { display: flex; align-items: center; justify-content: space-between; background: #f8fafd; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin: 14px 0; font-size: 13px; }
.cost-box b { font-size: 15px; }
.cost-balance { color: var(--muted); }
.cost-box.over b#costPreview { color: var(--bad); }
#submitBtn { margin-top: 2px; }

.dash-right .gen-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(225px, 1fr)); gap: 16px; }
.gen-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.gen-thumb { display: block; aspect-ratio: 1; background: linear-gradient(150deg, #eef1f8, #e3e8f5); position: relative; }
.gen-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gen-thumb.is-placeholder { display: flex; align-items: center; justify-content: center; }
.thumb-ph { font-size: 30px; font-weight: 700; color: #b6c0d9; letter-spacing: 2px; }
.gen-body { padding: 12px 13px 13px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.gen-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.gen-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gen-meta { font-size: 12px; color: var(--muted); }
.gen-error { font-size: 12px; color: var(--bad); background: var(--bad-soft); border-radius: 8px; padding: 5px 9px; }
.gen-actions { display: flex; gap: 7px; margin-top: auto; padding-top: 6px; flex-wrap: wrap; }

.empty-state { border: 1px dashed var(--line-strong); border-radius: var(--radius); text-align: center; padding: 60px 20px; color: var(--muted); background: #fafbfe; }
.empty-icon { font-size: 40px; color: #c3cce4; margin-bottom: 8px; }
.empty-state p { margin: 4px 0; }

/* ---------- 详情页 ---------- */
.page-head { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.back-link { color: var(--muted); font-size: 13px; }
.back-link:hover { color: var(--primary); }
.page-head-main { display: flex; align-items: center; gap: 12px; }
.page-title { font-size: 20px; margin: 0; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(340px, 1fr); gap: 20px; align-items: start; }
.detail-side { display: flex; flex-direction: column; gap: 20px; }
model-viewer { width: 100%; height: 470px; border-radius: 12px; background: transparent; --poster-color: transparent; }
.viewer-wrap { position: relative; }
.load-overlay { position: absolute; inset: 0; z-index: 3; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: rgba(15, 23, 42, .38); border-radius: 12px; }
.load-overlay[hidden] { display: none; }
.lo-text { color: #fff; font-size: 14px; font-weight: 600; text-shadow: 0 1px 4px rgba(0, 0, 0, .5); }
.lo-val { color: #a5f3fc; }
.lo-bar { width: 240px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .25); overflow: hidden; }
.lo-bar-in { height: 100%; width: 0; background: linear-gradient(90deg, #6366f1, #22d3ee); border-radius: 3px; transition: width .4s; }

/* 画质切换（默认预览版 / 超清完整版） */
.quality-seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 9px; overflow: hidden; }
.quality-seg button { border: 0; background: #fff; padding: 5px 14px; font-size: 12px; cursor: pointer; color: var(--muted); transition: all .15s; }
.quality-seg button:hover { color: var(--text); }
.quality-seg button.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.viewer-bar { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
.viewer-placeholder { min-height: 470px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 20px; }
.viewer-placeholder p { margin: 0; font-weight: 600; }
.viewer-placeholder .hint { font-weight: 400; max-width: 380px; }
.vp-icon { font-size: 42px; color: #a5b4fc; }
.spin { animation: rotate 2.2s linear infinite; display: inline-block; }
@keyframes rotate { to { transform: rotate(360deg); } }

.info-list { margin: 0 0 12px; }
.info-list > div { display: grid; grid-template-columns: 86px 1fr; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.info-list dt { color: var(--muted); }
.info-list dd { margin: 0; }
.src-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.src-strip img { width: 58px; height: 58px; object-fit: cover; border-radius: 9px; border: 1px solid var(--line); }
.dl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.copy-row { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 12px; }
.copy-row input, .copy-row textarea { flex: 1; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.copy-row .btn { flex: none; }

/* ---------- 积分页 ---------- */
.credit-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; flex-wrap: wrap; }
.balance-num { font-size: 38px; font-weight: 800; margin: 2px 0 0; color: var(--primary); }
.balance-num .unit { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.balance-rules { color: var(--muted); font-size: 13px; line-height: 1.9; }
.balance-rules p { margin: 0; }

/* ---------- 表格 ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 9px 10px; border-bottom: 1px solid #f0f3f9; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; }
.table th.num { text-align: right; }
.empty-cell { text-align: center; color: var(--muted); padding: 34px 10px !important; }
.pager { margin-top: 14px; }
.pager .pagination { display: flex; gap: 6px; list-style: none; margin: 0; padding: 0; flex-wrap: wrap; }
.pager .page-link { display: inline-block; padding: 5px 11px; border: 1px solid var(--line-strong); border-radius: 8px; color: var(--text); font-size: 13px; }
.pager .page-item.active .page-link { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager .page-item.disabled .page-link { color: #b6c0d9; pointer-events: none; }
.pager .page-link:hover { background: #f1f4fb; }

/* ---------- 后台 ---------- */
.admin-tabs { display: inline-flex; gap: 4px; background: #fff; border: 1px solid var(--line); padding: 5px; border-radius: 12px; margin-bottom: 20px; box-shadow: var(--shadow); }
.admin-tabs a { padding: 7px 16px; border-radius: 8px; color: var(--muted); font-weight: 500; font-size: 13px; }
.admin-tabs a.active { background: var(--primary-soft); color: var(--primary); }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat { padding: 16px 18px; }
.stat-num { font-size: 26px; font-weight: 800; margin: 0; }
.stat.ok .stat-num { color: var(--ok); }
.stat.bad .stat-num { color: var(--bad); }
.stat-label { color: var(--muted); font-size: 12px; margin: 2px 0 0; }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.search-row { display: flex; gap: 8px; }
.search-row input, .search-row select { width: 180px; }
.op-details { display: inline-block; margin-right: 10px; }
.op-details summary { cursor: pointer; color: var(--primary); font-size: 12px; user-select: none; }
.op-form { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; min-width: 220px; }
.op-form .op-credits { width: 100%; }
.op-form .op-note { width: 100%; }

/* ---------- 响应式 ---------- */
@media (max-width: 1024px) {
    .dash-grid, .detail-grid, .admin-grid { grid-template-columns: 1fr; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid { grid-template-columns: 1fr 1fr; }
}
