/* ═══════════════════════════════════════════
   智能质检计算器 · 一屏显示深色UI
   核心约束: body 100dvh, 不滚动
   ═══════════════════════════════════════════ */

:root {
  --bg: #0f1117; --surface: #1a1d27; --surface-2: #252835;
  --border: rgba(255,255,255,0.06); --border-glow: rgba(79,140,255,0.4);
  --text: #e8eaed; --text-dim: #8b8fa3; --text-muted: #565b6e;
  --accent: #4f8cff; --accent-dim: rgba(79,140,255,0.15);
  --success: #34d399; --danger: #f87171; --warning: #fbbf24;
  --grad-pass: linear-gradient(135deg, #34d399, #059669);
  --grad-fail: linear-gradient(135deg, #f87171, #dc2626);
  --grad-warn: linear-gradient(135deg, #fbbf24, #d97706);
  --grad-accent: linear-gradient(135deg, #4f8cff, #6366f1);
  --chrome-accent: #818cf8; --chrome-dim: rgba(129,140,248,0.15);
  --radius: 12px; --radius-sm: 8px; --radius-lg: 16px;
}

.theme-chrome {
  --accent: #818cf8; --accent-dim: rgba(129,140,248,0.15);
  --border-glow: rgba(129,140,248,0.4);
  --grad-accent: linear-gradient(135deg, #818cf8, #6366f1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── 顶栏(预留safe-area避让状态栏) ── */
.header {
  padding: max(env(safe-area-inset-top), 20px) 16px 4px;
  flex-shrink: 0;
}
.header-title {
  font-size: 18px; font-weight: 600; letter-spacing: 1px;
  background: var(--grad-accent); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

/* ── 主内容区 ── */
.main {
  flex: 1; min-height: 0;
  padding: 0 12px 4px;
  display: flex; flex-direction: column; gap: 8px;
}

/* ── 顶行: 模式切换 + 公差类型 ── */
.top-row {
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}
.mode-switch {
  display: flex; background: var(--surface); border-radius: var(--radius-sm); padding: 3px;
  border: 1px solid var(--border); flex-shrink: 0;
}
.mode-btn {
  padding: 8px 16px; border: none; background: transparent; color: var(--text-dim);
  font-size: 15px; font-weight: 600; cursor: pointer; border-radius: 6px;
  transition: color 0.2s, background 0.2s;
}
.mode-btn.active {
  color: #fff; background: var(--grad-accent);
  box-shadow: 0 2px 8px rgba(79,140,255,0.3);
}
.theme-chrome .mode-btn.active { box-shadow: 0 2px 8px rgba(129,140,248,0.3); }

.tol-type-chips {
  display: flex; gap: 5px; flex: 1; justify-content: flex-end;
}
.tol-chip {
  height: 32px; padding: 0 10px; border-radius: 16px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim);
  font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.2s;
  white-space: nowrap; display: flex; align-items: center; justify-content: center;
}
.tol-chip.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* ── 输入行(标准值+公差并排) ── */
.input-row {
  display: flex; gap: 8px; flex-shrink: 0;
}
.input-half { flex: 1; min-width: 0; }

.input-card {
  background: var(--surface); border-radius: var(--radius); padding: 8px 12px;
  border: 2px solid transparent; transition: border-color 0.2s, box-shadow 0.2s, opacity 0.2s;
  cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.input-card.focused {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--border-glow), 0 0 12px var(--accent-dim);
}
.input-card:not(.focused) { opacity: 0.65; }

.input-label {
  display: flex; align-items: center; gap: 4px;
  color: var(--text-dim); font-size: 13px; white-space: nowrap; min-width: 48px;
}
.input-value {
  font-size: 28px; font-weight: 700; text-align: right; flex: 1;
  letter-spacing: 0.5px; min-height: 34px; display: flex; align-items: center; justify-content: flex-end;
}
.input-value-main { font-size: 32px; }
.input-measured { background: var(--surface-2); }

.tol-asym-row { display: flex; gap: 6px; }
.input-quarter { flex: 1; min-width: 0; }

.chrome-factor {
  font-size: 11px; color: var(--chrome-accent); background: var(--chrome-dim);
  padding: 1px 5px; border-radius: 4px; font-weight: 600;
}
.hidden { display: none !important; }

/* ── 判定范围(突出显示) ── */
.limits-display {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  flex-shrink: 0;
  background: var(--surface); border-radius: var(--radius-sm); padding: 6px 16px;
  border: 1px solid var(--border);
}
.limit-box {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.limit-label {
  font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px;
}
.limit-value {
  color: var(--accent); font-weight: 700; font-size: 16px;
}
.limit-sep { color: var(--text-muted); font-size: 14px; font-weight: 300; }

/* ── 纠错提示 ── */
.error-hint {
  text-align: center; font-size: 13px; color: var(--warning); padding: 2px;
  animation: fadeIn 0.3s; flex-shrink: 0;
}

/* ── 判定结果 ── */
.result-card {
  border-radius: var(--radius-lg); padding: 10px 20px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  flex-shrink: 0; animation: resultEnter 0.35s cubic-bezier(0.34,1.56,0.64,1);
  min-height: 44px;
}
.result-hidden { display: none; }
.result-pass { background: var(--grad-pass); color: #fff; box-shadow: 0 3px 14px rgba(52,211,153,0.3); }
.result-fail {
  background: var(--grad-fail); color: #fff; box-shadow: 0 3px 14px rgba(248,113,113,0.3);
  animation: resultEnter 0.35s cubic-bezier(0.34,1.56,0.64,1), failPulse 2s ease-in-out infinite;
}
.result-warning { background: var(--grad-warn); color: #1a1d27; box-shadow: 0 3px 14px rgba(251,191,36,0.3); }
.result-icon { font-size: 22px; line-height: 1; }
.result-text { font-size: 20px; font-weight: 700; letter-spacing: 2px; }
.result-detail { font-size: 13px; opacity: 0.85; }
.result-proximity { font-size: 12px; opacity: 0.8; font-weight: 500; }

/* ── 会话统计 ── */
.stats-bar {
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0; padding: 2px 0;
}
.stat-item {
  color: var(--text-dim); font-size: 12px;
  display: flex; align-items: center; gap: 3px;
}
.stat-item b { color: var(--text); font-weight: 700; font-size: 15px; }
.mini-trend {
  width: 50px; height: 26px; flex-shrink: 0; margin-left: auto;
  border-radius: 4px; background: var(--surface);
}

/* ═══ 数字键盘 ═══ */
.keyboard {
  padding: 6px 12px 6px; background: var(--surface);
  border-top: 1px solid var(--border); flex-shrink: 0;
}
.keyboard-numbers { display: flex; flex-direction: column; gap: 5px; }
.keyboard-row { display: flex; gap: 5px; }
.keyboard-key {
  flex: 1; height: 50px; border: none; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); font-size: 22px; font-weight: 500;
  cursor: pointer; position: relative; overflow: hidden;
  transition: transform 0.1s; -webkit-user-select: none; user-select: none;
}
.keyboard-key:active { background: rgba(255,255,255,0.08); }
.keyboard-func { display: flex; gap: 5px; margin-top: 5px; }
.keyboard-func-key {
  flex: 1; height: 42px; border: none; border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600; cursor: pointer; position: relative; overflow: hidden;
  transition: transform 0.1s; -webkit-user-select: none; user-select: none;
}
.keyboard-clear { background: rgba(248,113,113,0.12); color: var(--danger); border: 1px solid rgba(248,113,113,0.2); }
.keyboard-confirm {
  background: var(--grad-accent); color: #fff; border: none;
  box-shadow: 0 2px 8px rgba(79,140,255,0.25);
}
.theme-chrome .keyboard-confirm { box-shadow: 0 2px 8px rgba(129,140,248,0.25); }
.keyboard-ripple {
  position: absolute; border-radius: 50%; background: rgba(255,255,255,0.2);
  transform: translate(-50%,-50%) scale(0); animation: ripple 0.3s ease-out forwards;
  pointer-events: none; width: 80px; height: 80px;
}

/* ── 底部工具栏(恢复图标+文字,正常大小) ── */
.toolbar {
  display: flex; justify-content: space-around;
  padding: 6px 12px max(6px, env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--border); flex-shrink: 0;
}
.toolbar-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; color: var(--text-dim);
  font-size: 11px; cursor: pointer; padding: 4px 8px; transition: color 0.2s;
}
.toolbar-btn svg { width: 20px; height: 20px; }
.toolbar-btn:active { color: var(--accent); }

/* ── 模板抽屉 ── */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 90;
  opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.drawer-open ~ .drawer-overlay { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: -280px; width: 280px; height: 100%;
  background: var(--bg); z-index: 100; transition: right 0.3s ease-out;
  box-shadow: -4px 0 20px rgba(0,0,0,0.4); display: flex; flex-direction: column;
}
.drawer-open { right: 0; }
.drawer-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.drawer-header h2 { font-size: 16px; font-weight: 600; }
.drawer-close { background: none; border: none; color: var(--text-dim); font-size: 18px; cursor: pointer; }
.drawer-body { flex: 1; padding: 12px; overflow-y: auto; }
.template-empty { text-align: center; color: var(--text-muted); font-size: 13px; padding: 20px; }
.template-item { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; background: var(--surface); border-radius: var(--radius-sm); margin-bottom: 6px; cursor: pointer; }
.template-item:active { background: var(--surface-2); }
.template-item-main { display: flex; align-items: center; gap: 8px; }
.template-name { font-size: 14px; font-weight: 500; }
.template-mode-tag { font-size: 10px; padding: 2px 6px; border-radius: 4px; background: var(--accent-dim); color: var(--accent); }
.template-delete { background: none; border: none; color: var(--danger); font-size: 12px; cursor: pointer; opacity: 0.7; }

/* ── 设置面板(底部弹出) ── */
.settings-panel {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 110;
  background: var(--bg); border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0; padding: 0 16px max(16px, env(safe-area-inset-bottom));
  box-shadow: 0 -4px 20px rgba(0,0,0,0.4);
  animation: slideUp 0.3s ease-out;
}
.settings-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 0 10px; }
.settings-header h3 { font-size: 16px; font-weight: 600; }
.settings-close { background: none; border: none; color: var(--text-dim); font-size: 18px; cursor: pointer; }
.settings-btn {
  width: 100%; padding: 12px; margin-bottom: 8px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  font-size: 15px; cursor: pointer; text-align: left; transition: background 0.2s;
}
.settings-btn:active { background: var(--surface-2); }
.settings-btn-danger { color: var(--danger); border-color: rgba(248,113,113,0.2); }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface-2); color: var(--text); padding: 8px 20px; border-radius: 20px;
  font-size: 13px; opacity: 0; transition: opacity 0.3s, transform 0.3s;
  z-index: 200; pointer-events: none; box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.toast-show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ═══ 动画 ═══ */
@keyframes resultEnter {
  0% { opacity: 0; transform: translateY(6px) scale(0.95); }
  70% { transform: translateY(-2px) scale(1.02); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes failPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.88; } }
@keyframes ripple { to { transform: translate(-50%,-50%) scale(2.5); opacity: 0; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ── 响应式 ── */
@media (min-width: 420px) {
  .keyboard-key { height: 54px; font-size: 24px; }
  .input-value { font-size: 30px; }
  .input-value-main { font-size: 34px; }
}
