/* ============================================================
   质检助手 · "Precision" 设计系统
   面向车间一线的工业级移动端 UI（PWA）
   设计原则：高对比、大触控、克制配色、清晰层级
   ============================================================ */

/* ============ 设计令牌 ============ */
:root {
    /* 主色 — 深邃可信的工业蓝 */
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-darker: #1e3a8a;
    --primary-tint: #eff4ff;
    --primary-tint-2: #dbeafe;

    /* 语义色 */
    --pass: #16a34a;
    --pass-dark: #15803d;
    --pass-tint: #dcfce7;
    --fail: #dc2626;
    --fail-dark: #b91c1c;
    --fail-tint: #fee2e2;
    --warn: #d97706;
    --warn-dark: #b45309;
    --warn-tint: #fef3c7;

    /* 中性色阶（10 级） */
    --gray-50:  #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;

    /* 语义别名 */
    --bg: var(--gray-50);
    --card-bg: #ffffff;
    --text: var(--gray-900);
    --text-light: var(--gray-500);
    --text-lighter: var(--gray-400);
    --border: var(--gray-200);
    --border-strong: var(--gray-300);

    /* 圆角 */
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* 阴影（分层投影系统） */
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.07), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.10), 0 4px 6px -4px rgba(15, 23, 42, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.12), 0 8px 10px -6px rgba(15, 23, 42, 0.06);

    /* 聚焦环 */
    --ring: 0 0 0 3px rgba(37, 99, 235, 0.18);

    /* 间距节奏 */
    --space: 4px;

    /* 动效 */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --dur: 0.18s;

    /* 安全区 */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ============ 全局重置 ============ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 0.9375rem;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding-bottom: calc(68px + var(--safe-bottom));
    text-rendering: optimizeLegibility;
}
input, button, select, textarea { font-family: inherit; font-size: 16px; color: inherit; }
::selection { background: var(--primary-tint-2); color: var(--primary-darker); }

/* 全局聚焦环（无障碍） */
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-sm); }

/* ============ 顶部应用栏 ============ */
.page-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    padding: calc(12px + var(--safe-top)) 8px 12px 8px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(30, 58, 138, 0.25);
    display: flex;
    align-items: center;
    gap: 4px;
}
.page-header h1 {
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 4px;
}
.page-header .back {
    color: #fff;
    text-decoration: none;
    font-size: 1.5rem;
    font-weight: 300;
    line-height: 1;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    transition: background var(--dur) var(--ease);
    flex-shrink: 0;
}
.page-header .back:active { background: rgba(255, 255, 255, 0.18); }
.page-header .actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}
.page-header .actions a,
.page-header .actions button {
    color: #fff;
    background: transparent;
    border: none;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: var(--radius-full);
    text-decoration: none;
    transition: background var(--dur) var(--ease);
    line-height: 1.2;
}
.page-header .actions a:active,
.page-header .actions button:active { background: rgba(255, 255, 255, 0.18); }

/* ============ 通用布局 ============ */
.container { max-width: 640px; margin: 0 auto; padding: 16px 14px; }

/* ============ 按钮 ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 11px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease), opacity var(--dur) var(--ease);
    min-height: 48px;
    line-height: 1.2;
    letter-spacing: 0.01em;
    user-select: none;
    -webkit-user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn-block { display: flex; width: 100%; }
.btn-lg { padding: 15px 24px; font-size: 1.0625rem; min-height: 56px; border-radius: var(--radius); }

.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:active { background: var(--primary-dark); }

.btn-success { background: var(--pass); color: #fff; box-shadow: var(--shadow-sm); }
.btn-success:active { background: var(--pass-dark); }

.btn-danger { background: var(--fail); color: #fff; box-shadow: var(--shadow-sm); }
.btn-danger:active { background: var(--fail-dark); }

.btn-warn { background: var(--warn); color: #fff; box-shadow: var(--shadow-sm); }
.btn-warn:active { background: var(--warn-dark); }

.btn-outline {
    background: var(--card-bg);
    border: 1.5px solid var(--primary);
    color: var(--primary);
}
.btn-outline:active { background: var(--primary-tint); }

.btn-outline-gray {
    background: var(--card-bg);
    border: 1.5px solid var(--border-strong);
    color: var(--gray-600);
}
.btn-outline-gray:active { background: var(--gray-100); }

.btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
.btn:disabled:active { transform: none; }

/* ============ 卡片 ============ */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-xs);
}
.card-tap {
    cursor: pointer;
    transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.card-tap:active {
    transform: scale(0.985);
    box-shadow: var(--shadow-sm);
    border-color: var(--primary-tint-2);
}
.card-deleted { opacity: 0.5; }

/* ============ 表单 ============ */
.form-group { margin-bottom: 18px; }
.form-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 7px;
    letter-spacing: 0.01em;
}
.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 16px; /* ≥16px 防止 iOS 聚焦缩放 */
    background: var(--card-bg);
    color: var(--text);
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
    -webkit-appearance: none;
    appearance: none;
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-lighter); }
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--ring);
}
.form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 40px;
}
.form-textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; min-width: 0; }
.form-hint { font-size: 0.8125rem; color: var(--text-light); margin-top: 6px; line-height: 1.4; }
.form-error { font-size: 0.8125rem; color: var(--fail); margin-top: 6px; font-weight: 500; }

.feature-row {
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 12px;
    position: relative;
    background: var(--gray-50);
    transition: border-color var(--dur) var(--ease);
}
.feature-row:focus-within { border-color: var(--primary-tint-2); }
.feature-row .remove-feat {
    position: absolute;
    top: 10px; right: 10px;
    background: var(--fail-tint);
    color: var(--fail-dark);
    border: none;
    border-radius: var(--radius-full);
    width: 30px; height: 30px;
    font-size: 1.125rem;
    cursor: pointer;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.feature-row .remove-feat:active { transform: scale(0.9); background: var(--fail); color: #fff; }

/* ============ 列表 ============ */
.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 4px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}
.list-item:last-child { border-bottom: none; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1.4;
}
.badge-pass { background: var(--pass-tint); color: var(--pass-dark); }
.badge-fail { background: var(--fail-tint); color: var(--fail-dark); }
.badge-warn { background: var(--warn-tint); color: var(--warn-dark); }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* ============ 搜索栏 ============ */
.search-bar {
    padding: 10px 14px calc(10px + var(--safe-top) * 0);
    background: var(--card-bg);
    position: sticky;
    top: 0;
    z-index: 90;
    border-bottom: 1px solid var(--border);
}
.search-bar input {
    width: 100%;
    padding: 11px 16px 11px 42px;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-full);
    font-size: 16px;
    background: var(--gray-50) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat 14px center;
    color: var(--text);
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.search-bar input::placeholder { color: var(--text-lighter); }
.search-bar input:focus {
    outline: none;
    border-color: var(--primary);
    background-color: var(--card-bg);
    box-shadow: var(--ring);
}

/* ============ 底部状态栏 ============ */
.status-bar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    padding: 10px 16px calc(10px + var(--safe-bottom));
    display: flex;
    justify-content: space-around;
    align-items: center;
    font-size: 0.8125rem;
    color: var(--text-light);
    z-index: 90;
    box-shadow: 0 -2px 12px rgba(15, 23, 42, 0.06);
    backdrop-filter: saturate(180%) blur(8px);
    -webkit-backdrop-filter: saturate(180%) blur(8px);
}
.status-bar span { font-weight: 500; }
.status-bar .num { color: var(--primary); font-weight: 700; }

/* ============ 空状态 ============ */
.empty-state {
    text-align: center;
    padding: 56px 24px;
    color: var(--text-light);
}
.empty-state .icon {
    width: 88px; height: 88px;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    background: var(--gray-100);
    border-radius: var(--radius-xl);
    opacity: 0.7;
}
.empty-state .title { font-size: 1.0625rem; font-weight: 600; margin-bottom: 6px; color: var(--gray-700); }
.empty-state .desc { font-size: 0.875rem; margin-bottom: 24px; line-height: 1.5; }

/* ============ 测量页全屏判定 ============ */
.judge-fullscreen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    color: #fff;
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    animation: judgeIn 0.25s var(--ease);
}
.judge-pass { background: linear-gradient(160deg, var(--pass) 0%, var(--pass-dark) 100%); }
.judge-fail { background: linear-gradient(160deg, var(--fail) 0%, var(--fail-dark) 100%); }
.judge-fullscreen .icon { font-size: 5rem; margin-bottom: 16px; animation: judgePop 0.35s var(--ease); }
.judge-fullscreen .detail { font-size: 1.5rem; margin-top: 12px; font-weight: 600; opacity: 0.95; }
@keyframes judgeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes judgePop { 0% { transform: scale(0.4); opacity: 0; } 60% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ============ 相似产品警告 ============ */
.similar-warn {
    background: var(--warn-tint);
    border: 1px solid #fcd34d;
    border-left: 4px solid var(--warn);
    padding: 10px 14px;
    margin: 6px 0;
    font-size: 0.8125rem;
    color: var(--warn-dark);
    border-radius: var(--radius-sm);
    line-height: 1.5;
    font-weight: 500;
}

/* ============ 特征项 ============ */
.feature-item {
    background: var(--gray-50);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 10px;
}
.feature-item .name { font-weight: 600; font-size: 1rem; color: var(--gray-800); }
.feature-item .spec { font-size: 0.875rem; color: var(--text-light); margin-top: 5px; font-variant-numeric: tabular-nums; }
.feature-item .caution { font-size: 0.8125rem; color: var(--warn-dark); margin-top: 6px; line-height: 1.4; }

/* ============ 数字大输入 ============ */
.measure-input {
    font-size: 2.25rem !important;
    font-weight: 700;
    text-align: center;
    padding: 22px !important;
    border: 2px solid var(--primary) !important;
    border-radius: var(--radius-lg) !important;
    width: 100%;
    color: var(--gray-900);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    box-shadow: var(--shadow-sm);
}
.measure-input:focus { box-shadow: var(--ring), var(--shadow-sm) !important; }

/* ============ 统计卡片 ============ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 14px;
}
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 12px;
    text-align: center;
    box-shadow: var(--shadow-xs);
}
.stat-card .value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}
.stat-card .label { font-size: 0.8125rem; color: var(--text-light); margin-top: 6px; font-weight: 500; }

/* ============ 工具栏 ============ */
.toolbar {
    display: flex;
    gap: 8px;
    padding: 8px 0;
    flex-wrap: wrap;
}
.toolbar .btn { flex: 1; min-width: 120px; }

/* ============ 开关 ============ */
.switch { position: relative; display: inline-block; width: 52px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; inset: 0;
    background: var(--gray-300); transition: background var(--dur) var(--ease); border-radius: var(--radius-full);
}
.slider:before {
    position: absolute; content: ""; height: 24px; width: 24px; left: 3px; bottom: 3px;
    background: #fff; transition: transform var(--dur) var(--ease); border-radius: 50%;
    box-shadow: var(--shadow-sm);
}
input:checked + .slider { background: var(--pass); }
input:checked + .slider:before { transform: translateX(22px); }

/* ============ 设置项 ============ */
.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 2px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}
.setting-item:last-child { border-bottom: none; }
.setting-item .label { font-size: 0.9375rem; font-weight: 500; color: var(--gray-800); }
.setting-item .desc { font-size: 0.8125rem; color: var(--text-light); margin-top: 3px; line-height: 1.4; }

/* ============ 确认弹窗 ============ */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    display: flex; align-items: center; justify-content: center;
    z-index: 8000;
    padding: 24px;
    animation: fadeIn 0.15s var(--ease);
}
.modal {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 26px 24px 22px;
    max-width: 92%;
    width: 400px;
    text-align: center;
    box-shadow: var(--shadow-xl);
    animation: modalIn 0.22s var(--ease);
}
@keyframes modalIn { from { transform: scale(0.92) translateY(8px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }
.modal h3 { margin-bottom: 10px; font-size: 1.125rem; font-weight: 700; color: var(--gray-900); }
.modal p { color: var(--text-light); margin-bottom: 22px; font-size: 0.9375rem; line-height: 1.5; }
.modal .actions { display: flex; gap: 10px; }
.modal .actions .btn { flex: 1; }

/* ============ 趋势图 ============ */
.chart-container {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-xs);
    overflow-x: auto;
}
canvas { max-width: 100%; display: block; }

/* ============ 色块标记 ============ */
.pass-mark { color: var(--pass); font-weight: 700; }
.fail-mark { color: var(--fail); font-weight: 700; }

/* ============ 排版工具 ============ */
h1, h2, h3 { color: var(--gray-900); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-light); }
.text-small { font-size: 0.8125rem; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.hidden { display: none !important; }

/* ============ 可访问性 · 动效降级 ============ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}


/* ============ 自定义数字键盘 ============ */
.num-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 14px;
}
.pad-key {
    height: 60px;
    font-size: 24px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    background: var(--gray-100);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background .12s, transform .05s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.pad-key:active {
    background: var(--gray-300);
    transform: scale(0.96);
}
.pad-key.pad-back { font-size: 22px; }

/* 语音输入按钮 */
.voice-wrap { margin-top: 10px; }
.btn-voice {
    width: 100%;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--gray-100);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 15px;
    cursor: pointer;
    transition: background .15s, transform .05s;
    -webkit-tap-highlight-color: transparent;
}
.btn-voice:active { transform: scale(0.98); }
.btn-voice.listening {
    background: #fee2e2;
    border-color: #ef4444;
    color: #dc2626;
    animation: voice-pulse 1.2s infinite;
}
.btn-voice.listening .mic-icon { animation: voice-bounce .6s infinite; }
@keyframes voice-pulse { 0%,100%{opacity:1} 50%{opacity:0.6} }
@keyframes voice-bounce { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-3px)} }
.voice-status.ok { color: #16a34a; }
.voice-status.err { color: #dc2626; }
.voice-status.listening { color: #dc2626; }

/* 文本按钮（清空等） */
.btn-text {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 14px;
    padding: 4px 8px;
    cursor: pointer;
}
.btn-text:active { color: var(--primary); }


/* ============ 内联 SVG 图标 ============ */
.icon-inline { display: inline-flex; vertical-align: middle; margin-right: 4px; }
.icon-inline svg { display: block; }
