/* ============================================================
   SN 序列号查询系统 - 前端样式
   极简单页：标题 + 简介 + 搜索框 + 结果
   完全本地化，系统字体栈，无外链资源。
   ============================================================ */

:root {
    --ink:        #1F2937;      /* 主文字：深灰蓝（不再纯黑） */
    --ink-2:      #374151;      /* 次级文字 */
    --slate-700:  #374151;
    --slate-600:  #4B5563;
    --slate-500:  #6B7280;
    --slate-400:  #9CA3AF;
    --slate-300:  #D1D5DB;
    --slate-200:  #E5E7EB;
    --slate-100:  #F3F4F6;
    --slate-50:   #F9FAFB;
    --bg:         #F9FAFB;      /* 页面背景：浅灰白（不再纯白刺眼） */
    --bg-card:    #FFFFFF;      /* 卡片背景：纯白 */

    --accent:     #2563EB;      /* 主色调：蓝 */
    --accent-2:   #1D4ED8;
    --accent-soft:#EFF6FF;
    --success:    #059669;
    --success-soft:#ECFDF5;
    --warn:       #D97706;
    --warn-soft:  #FFFBEB;
    --danger:     #DC2626;
    --danger-soft:#FEF2F2;

    --radius:     14px;
    --radius-sm:  10px;
    --radius-md:  12px;
    --radius-lg:  20px;

    --shadow-sm:  0 1px 3px rgba(31, 41, 55, .06), 0 1px 2px rgba(31, 41, 55, .04);
    --shadow-md:  0 4px 16px rgba(31, 41, 55, .08), 0 1px 3px rgba(31, 41, 55, .04);
    --shadow-lg:  0 12px 40px rgba(31, 41, 55, .10), 0 4px 12px rgba(31, 41, 55, .05);
    --shadow-focus: 0 0 0 4px rgba(37, 99, 235, .15);

    --container: 960px;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
            "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica,
            Arial, sans-serif;
}

/* ---------- 重置 ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.6;
    color: var(--ink);
    background: var(--bg);
    background-image:
        radial-gradient(circle at 20% 0%, rgba(37, 99, 235, 0.04) 0%, transparent 50%),
        radial-gradient(circle at 80% 100%, rgba(37, 99, 235, 0.03) 0%, transparent 50%);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    min-height: 100vh;
    min-height: 100dvh;  /* 动态视口高度，避免移动端地址栏收起后 footer 消失 */
    display: flex;
    flex-direction: column;
}
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font: inherit; }

.container {
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: 0 24px;
}

/* ---------- 无障碍 ---------- */
.visually-hidden {
    position: absolute !important; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0);
    white-space: nowrap; border: 0;
}
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ============================================================
   页面主体（查询区位于视口约 2/5 位置，避免正中过于呆板）
   ============================================================ */
.page {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 56px 0;
}
/* 在垂直居中(50%)基础上整体上移，PC 视觉中心落到约 2/5 位置 */
.page > .container {
    transform: translateY(-8vh);
}

.hero-copy { text-align: center; margin-bottom: 32px; }
.hero-copy h1 {
    font-size: clamp(24px, 5vw, 32px);
    line-height: 1.2;
    letter-spacing: -.02em;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 10px;
}
.hero-sub {
    font-size: 15px;
    color: var(--slate-500);
    line-height: 1.6;
}

/* ---------- 搜索卡片 ---------- */
.search-card {
    background: var(--bg-card);
    border: 1px solid var(--slate-200);
    border-radius: var(--radius-lg);
    padding: 10px;
    box-shadow: var(--shadow-lg);
    transition: box-shadow .2s, border-color .2s;
    max-width: 100%;
    overflow: hidden;
}
.search-card:focus-within {
    border-color: var(--accent);
    box-shadow: var(--shadow-lg), var(--shadow-focus);
}
.search-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.search-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--slate-400);
    flex: none;
    padding: 0 6px 0 10px;
}
.search-input {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-size: 16px;
    color: var(--ink);
    padding: 14px 4px;
    letter-spacing: .01em;
    overflow: visible;
    text-overflow: clip;
}
.search-input::placeholder { color: var(--slate-400); }
.search-btn {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    padding: 13px 30px;
    border: none;
    border-radius: var(--radius);
    transition: background .15s, transform .1s;
    min-width: 92px;
}
.search-btn:hover { background: var(--accent-2); }
.search-btn:active { transform: scale(.98); }
.search-btn[disabled] { opacity: .7; cursor: progress; }
.btn-spinner {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, .35);
    border-top-color: #fff;
    animation: spin .7s linear infinite;
    display: none;
}
.search-btn.loading .btn-label { opacity: .85; }
.search-btn.loading .btn-spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.search-help {
    margin-top: 14px;
    text-align: center;
    font-size: 13px;
    color: var(--slate-500);
}

/* ============================================================
   结果区
   ============================================================ */
.result-area { margin-top: 28px; }
.result-area:empty { display: none; }

/* ---------- 最近查询（紧凑版） ---------- */
.recent-area { margin-top: 16px; }
.recent-area:empty { display: none; }
.recent-card {
    background: #fff;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    box-shadow: var(--shadow-sm);
}
/* PC 端：最近查询窗口固定高度，尽可能多显示记录 */
.recent-list {
    overflow: hidden;
    max-height: 168px;   /* 固定高度，约 5-6 行，JS 会在此高度内尽可能多显示 */
}
.recent-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.recent-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--slate-500);
    letter-spacing: .03em;
    text-transform: uppercase;
}
.recent-clear {
    border: none;
    background: transparent;
    color: var(--slate-400);
    font-size: 11px;
    cursor: pointer;
    padding: 3px 7px;
    border-radius: 4px;
    transition: color .15s, background .15s;
}
.recent-clear:hover { color: var(--accent); background: var(--slate-50); }
.recent-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.recent-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    background: var(--slate-50);
    border: 1px solid var(--slate-200);
    border-radius: 999px;
    font-size: 12px;
    color: var(--slate-700);
    text-decoration: none;
    cursor: pointer;
    transition: all .15s;
    max-width: 100%;
}
.recent-item:hover {
    background: #fff;
    border-color: var(--accent);
    color: var(--accent);
}
.recent-sn {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.recent-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex: none;
}
.recent-dot.ok { background: #10b981; }
.recent-dot.fail { background: var(--slate-300); }

.result-card {
    background: #fff;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    padding: 28px 28px 24px;
    box-shadow: var(--shadow-md);
    animation: rise .35s cubic-bezier(.2, .7, .3, 1);
}
@keyframes rise {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.result-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 999px;
    margin-bottom: 18px;
}
.result-status.ok { color: var(--success); background: var(--success-soft); }
.result-status.err { color: var(--danger); background: var(--danger-soft); }
.result-status .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.result-title {
    font-size: 20px;
    font-weight: 650;
    letter-spacing: -.01em;
    margin-bottom: 4px;
    color: var(--ink);
}
.result-sn {
    font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
    font-size: 13px;
    color: var(--slate-500);
    letter-spacing: .02em;
    word-break: break-all;
    margin-bottom: 22px;
}

.result-grid {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 1px;
    background: var(--slate-200);
    border: 1px solid var(--slate-200);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.result-field {
    background: #fff;
    padding: 22px 32px;
    flex: 1 1 auto;
    min-width: max-content;
    white-space: nowrap;
}
.result-field .label {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .03em;
    color: var(--slate-500);
    text-transform: uppercase;
    margin-bottom: 6px;
}
.result-field .value {
    font-size: 16px;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.4;
    white-space: nowrap;
}
.result-field .value.muted {
    color: var(--slate-400);
    font-weight: 500;
}

.result-meta {
    margin-top: 18px;
    font-size: 13px;
    color: var(--slate-500);
    display: flex;
    align-items: center;
    gap: 8px;
}

.result-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--slate-500);
}
.result-empty .big {
    font-size: 18px;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 6px;
}
.result-empty .small { font-size: 14px; }

.result-msg {
    padding: 16px 18px;
    border-radius: var(--radius-sm);
    font-size: 14.5px;
    font-weight: 500;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    border: 1px solid transparent;
}
.result-msg.error {
    color: var(--danger);
    background: var(--danger-soft);
    border-color: #FECACA;
}
.result-msg.warn {
    color: var(--warn);
    background: var(--warn-soft);
    border-color: #FDE68A;
}

/* 骨架屏 */
.skeleton {
    background: #fff;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow-md);
}
.skeleton-row {
    height: 14px;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--slate-100) 25%, var(--slate-200) 37%, var(--slate-100) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.4s ease infinite;
    margin-bottom: 14px;
}
.skeleton-row:last-child { margin-bottom: 0; }
@keyframes shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

/* ============================================================
   Footer（单行极简）
   ============================================================ */
.site-footer {
    border-top: 1px solid var(--slate-200);
    background: var(--slate-100);
    margin-top: auto;   /* 始终推到 body 底部，保证贴底显示 */
    flex-shrink: 0;
}
.footer-bottom {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 18px 24px;
    font-size: 13px;
    color: var(--slate-500);
}
/* 自定义 footer HTML（后台配置）下，让内容撑满容器宽度，避免窄屏局促 */
.footer-bottom > div,
.footer-bottom > span,
.footer-bottom > p {
    flex: 1 1 100%;
    width: 100%;
    text-align: center;
}
.footer-icp { color: var(--slate-500); }

/* ============================================================
   响应式
   ============================================================ */
@media (max-width: 760px) {
    .container { padding: 0 18px; }
    /* 手机端：取消垂直居中，改为顶对齐 + 适度顶部留白，内容自然从约 1/3 位置开始 */
    .page {
        align-items: flex-start;
        padding: 14vh 0 24px;
    }
    .page > .container { transform: none; }
    .hero-copy h1 { font-size: clamp(22px, 7vw, 28px); }
    .hero-copy { margin-bottom: 24px; }
    body.result-view .page { padding-top: 5vh; }
    .search-card { padding: 8px; border-radius: 16px; }
    .search-input { font-size: 16px; padding: 12px 2px; }
    .search-btn { padding: 12px 22px; min-width: 80px; font-size: 14px; }

    /* 手机端：用 Grid 精确控制位置，输入框+扫码同一行，查询按钮第二行 */
    .search-row {
        display: grid;
        grid-template-columns: auto 1fr auto;
        grid-template-rows: auto auto;
        gap: 8px;
        flex-wrap: nowrap;
    }
    .search-icon { grid-column: 1; grid-row: 1; }
    .search-input { grid-column: 2; grid-row: 1; min-width: 0; }
    .scan-btn { grid-column: 3; grid-row: 1; margin-right: 0; }
    .search-btn { grid-column: 1 / 4; grid-row: 2; margin-top: 4px; width: 100%; }

    .result-grid { flex-wrap: wrap; }
    .result-field { flex: 1 1 100%; min-width: 0; white-space: normal; padding: 16px 20px; }
    .result-field .value { white-space: normal; word-break: break-all; }
    .result-card { padding: 22px 20px; }

    /* 手机端 footer：增大上下内边距，两行内容自然撑满宽度 */
    .footer-bottom { padding: 16px 18px; gap: 6px; line-height: 1.7; }

    /* 手机端 footer 固定贴底，始终在屏幕内可见 */
    .site-footer {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 100;
        background: var(--slate-100, #f1f5f9);
        border-top: 1px solid var(--slate-200, #e2e8f0);
    }
    /* 防止 footer 遮挡内容，给 body 底部留出空间 */
    body { padding-bottom: 80px; }

    /* 手机端显示"查询其它序列号"按钮 */
    .result-action { display: block !important; }

    /* 手机端最近查询：每条占一行，显示完整 SN */
    .recent-list {
        max-height: none;   /* 手机端不限制高度，JS 固定显示5条 */
        flex-direction: column;
        gap: 6px;
    }
    .recent-item {
        width: 100%;
        justify-content: flex-start;
    }

    /* 手机端结果视图：查询出结果后隐藏表头与搜索框，只显示结果 */
    body.result-view .page {
        padding-top: 5vh;          /* 结果贴顶，仅留少量上边距 */
        align-items: stretch;      /* 内容不再居中 */
    }
    body.result-view .hero-copy,
    body.result-view .search-card,
    body.result-view .recent-area {
        display: none !important;  /* 隐藏标题、搜索框、最近查询 */
    }
    body.result-view .result-area {
        margin-top: 0;             /* 结果区贴顶 */
        padding-bottom: 100px;     /* 留出 fixed footer 的空间，防止按钮被遮挡 */
    }
}

/* "查询其他序列号"按钮：PC 默认隐藏，仅手机端显示 */
.result-action {
    display: none;
    margin-top: 20px;
    text-align: center;
}
.reset-btn {
    appearance: none;
    -webkit-appearance: none;
    display: inline-block;
    width: 100%;
    max-width: 320px;
    padding: 14px 28px;
    font-size: 15px;
    font-weight: 500;
    line-height: 1.4;
    color: var(--ink, #1F2937);
    background: var(--bg-card, #fff);
    border: 1px solid var(--slate-300, #D1D5DB);
    border-radius: 10px;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, transform .1s ease;
    box-sizing: border-box;
}
.reset-btn:hover { background: var(--slate-50, #f8fafc); border-color: var(--slate-400, #94a3b8); }
.reset-btn:active { transform: translateY(1px); }

/* ---------- 扫码按钮（默认隐藏，body.touch 设备显示） ---------- */
.scan-btn {
    appearance: none;
    -webkit-appearance: none;
    display: none;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    margin-right: 8px;
    color: var(--slate-600, #475569);
    background: var(--slate-50, #f8fafc);
    border: 1px solid var(--slate-200, #e2e8f0);
    border-radius: 10px;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s, transform .1s;
    -webkit-tap-highlight-color: transparent;
}
/* 触摸设备显示扫码按钮（由 JS 给 body 加 .touch 类） */
body.touch .scan-btn { display: inline-flex !important; }
.scan-btn:hover { background: var(--slate-100, #f1f5f9); color: var(--slate-800, #1e293b); border-color: var(--slate-300, #cbd5e1); }
.scan-btn:active { transform: scale(0.94); background: var(--slate-200, #e2e8f0); }
.scan-btn svg { display: block; width: 20px; height: 20px; }
/* PC 端扫码按钮稍大 */
@media (min-width: 761px) {
    .scan-btn { width: 48px; height: 48px; border-radius: 12px; }
    .scan-btn svg { width: 24px; height: 24px; }
}

/* ---------- 扫码遮罩层 ---------- */
.scan-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
}
.scan-overlay[hidden] { display: none; }
.scan-modal {
    width: 100%;
    max-width: 480px;
    background: #fff;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.scan-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--slate-200, #e2e8f0);
}
.scan-title { font-size: 15px; font-weight: 600; color: var(--slate-800, #1e293b); }
.scan-close {
    appearance: none;
    background: transparent;
    border: none;
    font-size: 26px;
    line-height: 1;
    color: var(--slate-400, #94a3b8);
    cursor: pointer;
    padding: 0 4px;
}
.scan-close:hover { color: var(--slate-700, #334155); }
.scan-viewport {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    background: #000;
    overflow: hidden;
}
.scan-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.scan-frame {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 70%;
    height: 18%;
    transform: translate(-50%, -50%);
    border: 2px solid rgba(255,255,255,0.9);
    border-radius: 10px;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.4);
    pointer-events: none;
}
.scan-hint {
    position: absolute;
    bottom: 12px;
    left: 0;
    right: 0;
    text-align: center;
    color: #fff;
    font-size: 13px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
    pointer-events: none;
}
/* 闪光灯按钮 */
.scan-torch {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: rgba(0,0,0,0.5);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background .15s, transform .1s;
    -webkit-tap-highlight-color: transparent;
}
.scan-torch svg { display: block; width: 22px; height: 22px; }
.scan-torch:active { transform: scale(0.92); }
.scan-torch[hidden] { display: none; }
.scan-torch.active { background: rgba(250, 204, 21, 0.85); color: #1e293b; }
@media (max-width: 420px) {
    .search-btn { padding: 12px 18px; }
}

/* 触摸设备：去掉 hover 抬升，避免黏滞 */
@media (hover: none) {
    .search-btn:hover { background: var(--ink); }
}

/* 尊重减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
