:root {
    --bg: #f5f7fb;
    --card: #ffffff;
    --ink: #172033;
    --muted: #6b7280;
    --line: #e5e9f2;
    --brand: #2563eb;
    --brand-dark: #1d4ed8;
    --ok: #0f9d58;
    --warn: #d97706;
    --danger: #dc2626;
    --dark: #0f172a;
    --radius: 14px;
    --shadow: 0 8px 30px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
    font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.6;
    font-size: 15px;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
code, textarea, input, select, button { font-family: inherit; }

.container { width: min(1120px, 100%); margin: 0 auto; padding: 0 20px; }
.main-content { min-height: 62vh; padding-top: 28px; padding-bottom: 60px; }

/* ---------- header / footer ---------- */
.site-header { background: var(--dark); color: #e2e8f0; }
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 68px; gap: 20px; }
.brand { font-size: 19px; font-weight: 700; color: #fff; letter-spacing: .3px; }
.site-nav { display: flex; gap: 22px; font-size: 14px; }
.site-nav a { color: #cbd5e1; }
.site-nav a:hover { color: #fff; }
.site-footer { border-top: 1px solid var(--line); background: #fff; color: var(--muted); font-size: 13px; }
.footer-inner { display: flex; justify-content: space-between; gap: 16px; padding: 22px 20px; flex-wrap: wrap; }

/* ---------- shared ---------- */
.alert { margin: 16px 0; padding: 12px 16px; border-radius: 10px; font-size: 14px; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.notice-bar { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; padding: 12px 16px; border-radius: 10px; margin-bottom: 20px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; border-radius: 9px; border: 1px solid var(--line);
    background: #fff; color: var(--ink); cursor: pointer; font-size: 14px;
    transition: .15s ease; white-space: nowrap;
}
.btn:hover { border-color: #cbd5e1; background: #f8fafc; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-small { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 700; }
.ok-text { color: var(--ok); font-weight: 600; }
.warn-text { color: var(--warn); font-weight: 600; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; }
.badge-ok { background: #ecfdf5; color: #047857; }
.badge-out { background: #f1f5f9; color: #64748b; }
.badge-warn { background: #fffbeb; color: #b45309; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); margin-bottom: 20px; }
.panel h2 { margin: 0 0 16px; font-size: 18px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.page-head h1 { margin: 0 0 4px; font-size: 24px; }
.page-head p { margin: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 26px 0 14px; }
.section-head h2 { margin: 0; font-size: 20px; }
.section-head span { color: var(--muted); font-size: 13px; }

.empty-state { background: #fff; border: 1px dashed #cbd5e1; border-radius: var(--radius); padding: 46px 24px; text-align: center; color: var(--muted); }
.empty-state h2 { color: var(--ink); margin-top: 0; }

/* ---------- home ---------- */
.hero {
    background: linear-gradient(120deg, #0f172a 0%, #1e3a8a 65%, #2563eb 100%);
    color: #fff; border-radius: 20px; padding: 42px 40px; margin-bottom: 30px;
    display: flex; align-items: center; justify-content: space-between; gap: 24px;
    box-shadow: 0 18px 50px rgba(37, 99, 235, .18);
}
.hero h1 { margin: 8px 0 10px; font-size: 34px; line-height: 1.25; }
.hero p { margin: 0; color: #dbeafe; max-width: 560px; }
.hero-kicker { font-size: 12px; letter-spacing: 2px; text-transform: uppercase; background: rgba(255,255,255,.14); padding: 4px 10px; border-radius: 999px; }
.hero-mark { font-size: 56px; font-weight: 800; color: rgba(255,255,255,.22); }
.hero-mark span { color: rgba(255,255,255,.4); }

.category-nav { display: flex; flex-wrap: wrap; gap: 8px 6px; align-items: center; margin: 0 0 20px; padding: 12px 16px; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.cat-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cat-item { padding: 6px 12px; border-radius: 999px; font-size: 13px; color: #475569; background: #f1f5f9; }
.cat-item:hover { background: #e2e8f0; }
.cat-item.active { background: var(--brand); color: #fff; }
.cat-top { font-weight: 600; }
.cat-child { font-size: 12px; }

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 18px; }
.product-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); transition: .18s ease; display: flex; flex-direction: column; }
.product-card:hover { transform: translateY(-3px); box-shadow: 0 16px 36px rgba(15, 23, 42, .1); }
.product-cover { height: 130px; background: linear-gradient(135deg, #dbeafe, #eff6ff); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.product-cover img { width: 100%; height: 100%; object-fit: cover; }
.product-cover-text { font-size: 34px; font-weight: 800; color: #93c5fd; letter-spacing: 2px; }
.product-body { padding: 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.product-body h3 { margin: 0; font-size: 16px; }
.product-desc { margin: 0; color: var(--muted); font-size: 13px; min-height: 20px; }
.product-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; padding-top: 8px; }
.price { color: var(--brand); font-weight: 700; font-size: 17px; }
.price-lg { font-size: 26px; }
.support-line { margin-top: 28px; color: var(--muted); font-size: 13px; }

/* ---------- product detail ---------- */
.product-detail { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.back-link { display: inline-block; margin-bottom: 14px; color: var(--muted); font-size: 13px; }
.detail-cover { height: 220px; border-radius: var(--radius); overflow: hidden; background: linear-gradient(135deg, #dbeafe, #eff6ff); display: flex; align-items: center; justify-content: center; margin-bottom: 20px; }
.detail-cover img { width: 100%; height: 100%; object-fit: cover; }
.detail-cover span { font-size: 60px; font-weight: 800; color: #93c5fd; }
.detail-main h1 { margin: 0 0 10px; font-size: 28px; }
.detail-meta { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.detail-description { color: #334155; white-space: normal; }
.buy-box { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); position: sticky; top: 20px; }
.buy-box h2 { margin: 0 0 16px; font-size: 18px; }
.buy-box label, .query-form label, .form-grid label, .stack-form label { display: block; margin-bottom: 14px; font-size: 13px; color: #475569; }
.buy-box input, .query-form input, .form-grid input, .form-grid textarea, .form-grid select, .stack-form input, .filter-form input, .filter-form select, .chat-form input {
    width: 100%; margin-top: 6px; padding: 10px 12px; border: 1px solid #dbe2ee; border-radius: 9px; background: #fff; font-size: 14px; color: var(--ink);
}
.buy-box input:focus, textarea:focus, input:focus, select:focus { outline: 2px solid #bfdbfe; border-color: var(--brand); }
.buy-hint { color: var(--muted); font-size: 12px; margin-top: 12px; }
.buy-empty { color: var(--warn); }

/* ---------- order / query ---------- */
.order-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.order-head h1, .order-head h2 { margin: 2px 0 0; font-size: 22px; }
.order-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.status-pill { display: inline-block; padding: 5px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.status-pending { background: #eff6ff; color: #1d4ed8; }
.status-paid { background: #fffbeb; color: #b45309; }
.status-delivered { background: #ecfdf5; color: #047857; }
.status-closed { background: #f1f5f9; color: #64748b; }
.status-void { background: #fef2f2; color: #b91c1c; }
.kv { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 8px 14px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; word-break: break-all; }
.card-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.card-item { display: flex; gap: 10px; align-items: flex-start; background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.card-secret { flex: 1; resize: none; border: 0; background: transparent; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; color: var(--ink); }
.order-help { color: var(--muted); font-size: 13px; margin-top: 18px; }
.query-page { max-width: 720px; margin: 0 auto; }
.query-head h1 { margin: 0 0 6px; }
.query-head p { margin: 0 0 22px; color: var(--muted); }
.query-form { display: grid; gap: 4px; }
.query-result { margin-top: 20px; }
.error-page { text-align: center; padding: 60px 20px; }
.error-code { width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 50%; background: #fef2f2; color: var(--danger); font-size: 32px; font-weight: 800; line-height: 64px; }

/* ---------- chat widget ---------- */
.chat-toggle { position: fixed; right: 22px; bottom: 22px; z-index: 60; border: 0; border-radius: 999px; background: var(--brand); color: #fff; padding: 12px 18px; font-size: 14px; box-shadow: 0 10px 28px rgba(37,99,235,.35); cursor: pointer; }
.chat-badge { display: inline-block; min-width: 18px; height: 18px; margin-left: 6px; padding: 0 5px; border-radius: 999px; background: #ef4444; color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.chat-panel { position: fixed; right: 22px; bottom: 78px; z-index: 61; width: min(360px, calc(100vw - 32px)); height: min(520px, calc(100vh - 120px)); background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 20px 60px rgba(15,23,42,.22); display: flex; flex-direction: column; overflow: hidden; }
.chat-panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--dark); color: #fff; font-size: 14px; }
.chat-panel-head button { border: 0; background: transparent; color: #cbd5e1; font-size: 20px; cursor: pointer; line-height: 1; }
.chat-messages { flex: 1; overflow-y: auto; padding: 14px; background: #f8fafc; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { display: flex; flex-direction: column; max-width: 84%; }
.chat-msg .bubble { padding: 9px 12px; border-radius: 12px; font-size: 13px; word-break: break-word; }
.chat-msg.from-visitor { align-self: flex-start; }
.chat-msg.from-admin { align-self: flex-end; align-items: flex-end; }
.chat-msg.from-admin .bubble { background: var(--brand); color: #fff; }
.chat-msg.from-visitor .bubble { background: #e8edf5; color: var(--ink); }
.chat-msg.from-system { align-self: center; max-width: 96%; }
.chat-msg.from-system .bubble { background: #fff7ed; color: #9a3412; font-size: 12px; }

/* 前台浮窗为访客视角：自己的消息在右（蓝色），客服在左（灰色）；后台工作台保持访客左、客服右 */
#chat-widget .chat-msg.from-visitor { align-self: flex-end; align-items: flex-end; }
#chat-widget .chat-msg.from-visitor .bubble { background: var(--brand); color: #fff; }
#chat-widget .chat-msg.from-admin { align-self: flex-start; align-items: flex-start; }
#chat-widget .chat-msg.from-admin .bubble { background: #e8edf5; color: var(--ink); }
.chat-msg img { max-width: 220px; border-radius: 10px; border: 1px solid var(--line); }
.chat-time { font-size: 11px; color: #94a3b8; margin-top: 3px; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); background: #fff; }
.chat-form input[type=text] { flex: 1; margin: 0; }
.chat-form button[type=submit] { border: 0; border-radius: 9px; background: var(--brand); color: #fff; padding: 0 16px; cursor: pointer; }
.chat-upload { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 9px; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--muted); font-size: 20px; }
.chat-upload:hover { background: #f8fafc; }

/* ---------- admin ---------- */
.admin-body { background: #f1f5f9; }
.admin-shell { display: flex; min-height: 100vh; }
.admin-sidebar { width: 228px; flex: 0 0 228px; background: var(--dark); color: #cbd5e1; display: flex; flex-direction: column; }
.admin-brand { padding: 22px 20px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.admin-brand strong { display: block; color: #fff; font-size: 16px; }
.admin-brand span { font-size: 12px; color: #94a3b8; }
.admin-nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.admin-nav a { padding: 10px 12px; border-radius: 9px; font-size: 14px; color: #cbd5e1; display: flex; align-items: center; justify-content: space-between; }
.admin-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.admin-nav a.active { background: var(--brand); color: #fff; }
.nav-badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: #ef4444; color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.admin-sidebar-foot { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.08); display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.admin-sidebar-foot a { color: #94a3b8; }
.admin-sidebar-foot a:hover { color: #fff; }
.admin-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.admin-topbar { height: 58px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; font-size: 13px; color: var(--muted); }
.admin-content { padding: 24px; max-width: 1280px; width: 100%; }
.admin-content > .alert { margin-top: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card strong { display: block; margin-top: 6px; font-size: 26px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid #eef2f7; vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
.table tr:hover td { background: #fafcff; }
.table .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.table .actions form { display: inline; }
.secret-cell, .log-cell { display: inline-block; max-width: 380px; word-break: break-all; color: #334155; font-size: 12px; }
.filter-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filter-form input, .filter-form select { margin: 0; padding: 9px 12px; border: 1px solid #dbe2ee; border-radius: 9px; }
.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 18px; }
.page-link { padding: 6px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.page-link.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 18px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid textarea, .stack-form textarea { width: 100%; padding: 10px 12px; border: 1px solid #dbe2ee; border-radius: 9px; margin-top: 6px; resize: vertical; }
.form-actions { display: flex; gap: 10px; padding-top: 8px; }
.stack-form { padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px dashed var(--line); }
.stack-form:last-child { border-bottom: 0; margin-bottom: 0; }
.cover-preview { max-width: 260px; border-radius: 10px; border: 1px solid var(--line); }
.small-note { color: var(--muted); font-size: 12px; }

/* ---------- admin chat ---------- */
.chat-admin { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; height: calc(100vh - 210px); min-height: 480px; }
.chat-conversations { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; overflow-y: auto; }
.conversation-list { display: flex; flex-direction: column; }
.conversation-item { display: block; padding: 11px 10px; border-radius: 10px; border-bottom: 1px solid #f1f5f9; }
.conversation-item:hover { background: #f8fafc; }
.conversation-item.active { background: #eff6ff; }
.conversation-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
.conversation-preview { color: var(--muted); font-size: 12px; margin: 4px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-meta { display: flex; justify-content: space-between; color: #94a3b8; font-size: 11px; }
.chat-workspace { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; }
.chat-workspace-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.chat-workspace-head .muted { display: block; font-size: 12px; }
.chat-workspace-head .actions { display: flex; gap: 8px; }
.admin-chat-messages { flex: 1; overflow-y: auto; padding: 18px; background: #f8fafc; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.admin-chat-form { margin: 0; }
.quick-replies { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 12px; border-top: 1px solid var(--line); background: #fff; }

/* ---------- login ---------- */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at top, #1e3a8a, #0f172a 60%); padding: 20px; }
.login-card { width: min(400px, 100%); background: #fff; border-radius: 18px; padding: 32px; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand strong { display: block; font-size: 21px; }
.login-brand span { color: var(--muted); font-size: 13px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 13px; color: #475569; }
.login-card input { width: 100%; margin-top: 6px; padding: 11px 12px; border: 1px solid #dbe2ee; border-radius: 9px; }
.login-foot { text-align: center; margin: 18px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
    .hero { padding: 30px 24px; }
    .hero h1 { font-size: 26px; }
    .hero-mark { display: none; }
    .product-detail { grid-template-columns: 1fr; }
    .buy-box { position: static; }
    .order-grid { grid-template-columns: 1fr; }
    .admin-shell { flex-direction: column; }
    .admin-sidebar { width: 100%; flex: none; }
    .admin-nav { flex-direction: row; flex-wrap: wrap; }
    .admin-sidebar-foot { flex-direction: row; }
    .chat-admin { grid-template-columns: 1fr; height: auto; }
    .chat-conversations { max-height: 260px; }
    .chat-workspace { min-height: 480px; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .span-2 { grid-column: span 1; }
    .secret-cell, .log-cell { max-width: 220px; }
}
