:root {
    --primary: #1677ff;
    --primary-dark: #0958d9;
    --primary-soft: #e6f4ff;
    --text: #1f2937;
    --muted: #667085;
    --line: #e5e7eb;
    --bg: #f4f7fb;
    --card: #ffffff;
    --danger: #dc2626;
    --success: #059669;
    --warning: #d97706;
    --sidebar: #0f2a4a;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
    line-height: 1.55;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }

.topbar {
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark {
    width: 28px; height: 28px; border-radius: 8px;
    display: inline-grid; place-items: center;
    color: #fff; background: linear-gradient(135deg, #1677ff, #0ea5e9);
}

.public-shell { padding: 34px 16px 60px; }
.public-card {
    width: min(880px, 100%);
    margin: 0 auto;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 35px rgba(15, 42, 74, .08);
    padding: 44px 56px;
}
.form-title { text-align: center; margin-bottom: 34px; }
.form-title h1 { margin: 0 0 8px; font-size: 28px; font-weight: 650; }
.form-title p { margin: 0; color: var(--success); font-weight: 600; }
.form-intro { color: var(--muted); background: #f8fafc; border-left: 4px solid var(--primary); padding: 12px 14px; border-radius: 6px; margin-bottom: 26px; }

.section { margin-top: 28px; }
.section-title { font-size: 17px; font-weight: 700; margin-bottom: 12px; }
.section-title .required, .required { color: #ef4444; }
.help { color: var(--muted); font-size: 13px; margin: 5px 0 8px; }
.field { margin-bottom: 21px; }
.field label.main-label { display: block; font-weight: 650; margin-bottom: 7px; }
.input, .select, .textarea {
    width: 100%; border: 1px solid #d7dde5; background: #fff;
    border-radius: 7px; padding: 10px 12px; color: var(--text);
    outline: none; transition: .15s border-color, .15s box-shadow;
}
.textarea { min-height: 98px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22, 119, 255, .12); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    min-height: 40px; padding: 9px 16px; border-radius: 7px; border: 1px solid transparent;
    cursor: pointer; font-weight: 650; text-decoration: none !important;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; border-color: #cfd7e3; color: var(--text); }
.btn-danger { background: #fff1f2; border-color: #fecdd3; color: #be123c; }
.btn-small { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }
.submit-row { margin-top: 30px; display: flex; justify-content: center; }
.submit-row .btn { width: min(260px, 100%); }

.alert { border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; border: 1px solid; }
.alert-success { background: #ecfdf5; border-color: #a7f3d0; color: #047857; }
.alert-error { background: #fff1f2; border-color: #fecdd3; color: #be123c; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #a16207; }

.terminal-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.terminal-option { position: relative; }
.terminal-option input { position: absolute; opacity: 0; pointer-events: none; }
.terminal-option label {
    display: flex; align-items: center; gap: 10px; padding: 13px 14px;
    border: 1px solid #dbe3ef; border-radius: 9px; cursor: pointer; background: #fff;
    transition: .15s ease;
}
.terminal-dot { width: 12px; height: 12px; border-radius: 999px; box-shadow: 0 0 0 4px rgba(22,119,255,.10); }
.terminal-option input:checked + label { border-color: var(--terminal-color, var(--primary)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--terminal-color, var(--primary)) 15%, transparent); background: color-mix(in srgb, var(--terminal-color, var(--primary)) 6%, #fff); }

.history-wrap { margin-top: 18px; }
.history-empty { padding: 18px; border: 1px dashed #cbd5e1; color: var(--muted); text-align: center; border-radius: 9px; }
.history-card { border: 1px solid #dce5f0; border-left: 5px solid var(--history-color, var(--primary)); border-radius: 9px; margin-bottom: 12px; overflow: hidden; }
.history-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding: 12px 14px; background: #f8fbff; }
.history-head strong { color: #0f3e75; }
.history-body { padding: 8px 14px 14px; }
.history-item { padding: 8px 0; border-bottom: 1px dashed #e5e7eb; }
.history-item:last-child { border-bottom: 0; }
.history-label { color: var(--muted); font-size: 13px; }
.history-value { white-space: pre-wrap; word-break: break-word; }
.compare-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px; }
.compare-table th, .compare-table td { border: 1px solid #e2e8f0; padding: 9px; vertical-align: top; text-align: left; }
.compare-table th { background: #f8fafc; }

.admin-shell { min-height: 100vh; display: grid; grid-template-columns: 240px minmax(0, 1fr); }
.sidebar { background: var(--sidebar); color: #dbeafe; padding: 22px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .logo { color: #fff; font-size: 19px; font-weight: 750; padding: 5px 10px 20px; }
.sidebar .logo small { display: block; color: #93c5fd; font-size: 12px; font-weight: 500; margin-top: 4px; }
.nav { display: grid; gap: 5px; }
.nav a { color: #cbd5e1; padding: 10px 12px; border-radius: 8px; display: block; }
.nav a:hover, .nav a.active { color: #fff; background: rgba(255,255,255,.11); text-decoration: none; }
.admin-main { min-width: 0; }
.admin-header { height: 64px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; position: sticky; top: 0; z-index: 20; }
.admin-content { padding: 24px; }
.page-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-title h1 { margin: 0; font-size: 24px; }
.card { background: #fff; border: 1px solid #e7ebf0; border-radius: 10px; padding: 18px; box-shadow: 0 3px 14px rgba(15, 42, 74, .04); margin-bottom: 18px; }
.card h2, .card h3 { margin-top: 0; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: #fff; border: 1px solid #e7ebf0; border-radius: 10px; padding: 17px; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 28px; font-weight: 750; margin-top: 5px; color: #0f3e75; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; min-width: 760px; }
.table th, .table td { border-bottom: 1px solid #edf0f4; padding: 11px 10px; text-align: left; vertical-align: top; }
.table th { color: #475467; background: #f8fafc; font-size: 13px; white-space: nowrap; }
.table tr:hover td { background: #fbfdff; }
.badge { display: inline-block; border-radius: 999px; padding: 3px 8px; font-size: 12px; background: #e6f4ff; color: #0958d9; }
.badge-muted { background: #f1f5f9; color: #64748b; }
.badge-danger { background: #fff1f2; color: #be123c; }
.color-chip { width: 14px; height: 14px; border-radius: 50%; display: inline-block; vertical-align: -2px; margin-right: 5px; }
.filters { display: grid; grid-template-columns: repeat(5, minmax(130px, 1fr)); gap: 10px; align-items: end; }
.filters .field { margin: 0; }
.pagination { display: flex; gap: 5px; margin-top: 14px; flex-wrap: wrap; }
.pagination a, .pagination span { border: 1px solid #dbe3ef; padding: 6px 10px; border-radius: 6px; background: #fff; }
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 20% 20%, #e6f4ff, #f4f7fb 55%); }
.login-card { width: min(420px, 100%); background: #fff; border-radius: 14px; padding: 30px; box-shadow: 0 20px 60px rgba(15, 42, 74, .13); }
.login-card h1 { margin-top: 0; }
.muted { color: var(--muted); }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.code-box { background: #f8fafc; border: 1px solid #dbe3ef; border-radius: 7px; padding: 10px; word-break: break-all; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }
.footer { text-align: center; color: #94a3b8; font-size: 13px; padding: 22px; }

@media (max-width: 980px) {
    .admin-shell { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; }
    .nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
    .public-card { padding: 28px 18px; }
    .form-title h1 { font-size: 23px; }
    .grid-2, .grid-3, .terminal-grid, .stats, .filters { grid-template-columns: 1fr; }
    .admin-content { padding: 16px; }
    .admin-header { padding: 0 16px; }
    .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .page-title { align-items: flex-start; flex-direction: column; }
}

/* v2：默认公开表单与商户独立档案 */
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.archive-tip {
    margin: -10px 0 24px;
    padding: 12px 14px;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    background: #eff6ff;
    color: #1e40af;
    font-size: 14px;
}
.new-merchant-panel {
    margin: 0 0 22px;
    padding: 18px;
    border: 1px dashed #93c5fd;
    border-radius: 10px;
    background: #f8fbff;
}
.new-merchant-panel .field:last-child { margin-bottom: 0; }
.merchant-summary-card { box-shadow: none; background: #f8fbff; }
.stat-date { font-size: 18px; line-height: 1.4; padding-top: 7px; }
.archive-meta { display: grid; gap: 0; }
.archive-meta > div {
    display: grid;
    grid-template-columns: minmax(120px, 38%) minmax(0, 1fr);
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px dashed #e5e7eb;
}
.archive-meta > div:last-child { border-bottom: 0; }
.archive-meta span { color: var(--muted); font-size: 13px; }
.archive-meta strong { word-break: break-word; }
.latest-problem {
    margin-top: 16px;
    padding: 14px;
    border-left: 4px solid var(--primary);
    border-radius: 7px;
    background: #f8fbff;
}

@media (max-width: 680px) {
    .topbar { padding: 0 14px; }
    .topbar-actions .muted { display: none; }
    .archive-meta > div { grid-template-columns: 1fr; gap: 3px; }
}
.latest-followup-banner {
    border: 1px solid #bfdbfe;
    border-left: 5px solid var(--history-color, var(--primary));
    border-radius: 9px;
    background: #eff6ff;
    padding: 14px 16px;
    margin-bottom: 14px;
}
.latest-followup-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; color: #1e3a8a; }
.latest-followup-head span { color: var(--muted); font-size: 13px; }
.latest-followup-item { margin-top: 10px; padding-top: 10px; border-top: 1px dashed #bfdbfe; }
.latest-followup-item > span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 3px; }
.latest-followup-item > div { white-space: pre-wrap; word-break: break-word; }
