/* 3D 仿真车模 · 全局样式（DOC-05） */

:root {
  --bg: #0d1015;
  --surface: rgba(22, 26, 33, 0.72);
  --surface-solid: #161a21;
  --border: rgba(255, 255, 255, 0.08);
  --text: #e9edf3;
  --text-dim: #8b94a3;
  --accent: #3a86ff;
  --ok: #2ecc71;
  --warn: #f5a623;
  --err: #ff4d4f;
  --radius-card: 14px;
  --radius-ctl: 10px;
  --gutter: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

#app { position: fixed; inset: 0; }

#viewport {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
  outline: none;
}
#viewport:active { cursor: grabbing; }

/* ---------- 毛玻璃卡片 ---------- */
#topbar, #view-controls .view-list, #view-controls .view-toggle, #panel, #voice-bar, .hint {
  background: var(--surface);
  border: 1px solid var(--border);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

/* ---------- 顶栏 ---------- */
#topbar {
  position: absolute;
  top: var(--gutter);
  left: var(--gutter);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px 10px 12px;
  border-radius: var(--radius-card);
  max-width: calc(100% - 2 * var(--gutter));
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 30px; height: 30px; color: var(--accent); flex: none; }
.brand h1 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: 0.02em; }
.brand .sub { margin: 0; font-size: 12px; color: var(--text-dim); }
.status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--text-dim); }
.status:empty { display: none; }

/* ---------- 视角按钮 ---------- */
#view-controls {
  position: absolute;
  left: var(--gutter);
  top: 84px;
}
#view-controls .view-list {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius-card);
}
#view-controls .view-toggle { display: none; }
#view-controls button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-ctl);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s;
}
#view-controls button svg { width: 16px; height: 16px; }
#view-controls .view-list button:hover { background: rgba(255, 255, 255, 0.08); }
#view-controls .view-list button.active { background: var(--accent); color: #fff; }

/* ---------- 控制面板（DOC-05 §4） ---------- */
#panel {
  position: absolute;
  top: var(--gutter);
  right: var(--gutter);
  width: 320px;
  max-height: calc(100% - 2 * var(--gutter));
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-card);
  overflow: hidden;
}
.panel-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 8px 16px; }
.panel-head h2 { flex: 1; margin: 0; font-size: 14px; font-weight: 600; }
.collapse-btn {
  width: 28px; height: 28px; border: 0; border-radius: 8px;
  background: rgba(255, 255, 255, 0.06); cursor: pointer; font-size: 16px; line-height: 1;
}
.collapse-btn:hover { background: rgba(255, 255, 255, 0.12); }
#panel.collapsed .panel-body { display: none; }
.drawer-handle, .panel-tabs { display: none; }
.panel-body { overflow-y: auto; padding: 0 16px 16px; overscroll-behavior: contain; }
.panel-sec { padding: 12px 0; border-top: 1px solid var(--border); }
.panel-sec h3, .panel-sec summary { margin: 0 0 10px; font-size: 12px; font-weight: 600; color: var(--text-dim); letter-spacing: 0.04em; }
.panel-sec summary { cursor: pointer; margin: 0; }
.log[open] summary { margin-bottom: 8px; }

#panel button:not(.swatch):not(.collapse-btn):not(.drawer-handle) {
  min-height: 34px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius-ctl);
  background: rgba(255, 255, 255, 0.04); cursor: pointer; transition: background-color 0.15s, border-color 0.15s;
}
#panel button:not(.swatch):not(.collapse-btn):not(.drawer-handle):hover { background: rgba(255, 255, 255, 0.1); }
.btn-row, .btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn-row { margin-top: 6px; }
.door-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* 滑块 */
.slider-row { display: grid; grid-template-columns: 64px 1fr 40px; align-items: center; gap: 10px; margin: 4px 0; font-size: 13px; }
.slider-row .value { text-align: right; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.sunroof-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; }
input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }

/* 开关按钮 */
#panel .switch { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-start; }
.switch .dot { width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 255, 255, 0.25); transition: background-color 0.2s, box-shadow 0.2s; }
#panel .switch[aria-checked="true"] { border-color: rgba(58, 134, 255, 0.6); background: rgba(58, 134, 255, 0.16); }
.switch[aria-checked="true"] .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.switch.hazard[aria-checked="true"] .dot { background: var(--warn); box-shadow: 0 0 8px var(--warn); animation: hazard 0.833s steps(1) infinite; }
@keyframes hazard { 50% { opacity: 0.15; } }

/* 车锁 */
#panel .lock-switch { width: 100%; min-height: 44px; display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; }
.lock-switch svg { width: 18px; height: 18px; }
#panel .lock-switch[aria-checked="true"] { border-color: rgba(46, 204, 113, 0.6); background: rgba(46, 204, 113, 0.14); color: var(--ok); }

/* 车漆色块 */
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer; padding: 0;
  background: var(--c); border: 2px solid rgba(255, 255, 255, 0.18); box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s;
}
.swatch:hover { transform: scale(1.08); }
.swatch[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(58, 134, 255, 0.35); }

/* 操作日志 */
.log-list { list-style: none; margin: 0; padding: 0; max-height: 180px; overflow-y: auto; font-size: 12px; }
.log-list:empty::after { content: "暂无操作"; color: var(--text-dim); }
.log-list li { display: grid; grid-template-columns: 58px 18px 1fr 14px; gap: 6px; padding: 4px 0; border-bottom: 1px dashed var(--border); }
.log-list time { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.log-list .log-text { overflow-wrap: anywhere; }
.log-list .success .log-mark { color: var(--ok); }
.log-list .info .log-mark { color: var(--accent); }
.log-list .warn .log-mark { color: var(--warn); }
.log-list .error .log-mark { color: var(--err); }

/* 被拒绝时抖动 */
.shake { animation: shake 0.3s; }
@keyframes shake { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }

/* ---------- tooltip（DOC-05 §3.3） ---------- */
#tooltip {
  position: fixed; left: 0; top: 0; z-index: 5; pointer-events: none;
  padding: 8px 12px; border-radius: 10px; max-width: 240px;
  background: rgba(10, 12, 16, 0.88); border: 1px solid var(--border); font-size: 13px;
}
#tooltip[hidden] { display: none; }
#tooltip .tip-action { color: var(--text-dim); font-size: 12px; margin-top: 2px; }

/* ---------- Toast（DOC-05 §6.2） ---------- */
#toasts {
  position: absolute; top: var(--gutter); left: 50%; transform: translateX(-50%); z-index: 6;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
  width: max-content; max-width: calc(100% - 2 * var(--gutter));
}
.toast {
  display: flex; align-items: center; gap: 8px; padding: 9px 14px; border-radius: 10px;
  background: rgba(16, 19, 25, 0.92); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  font-size: 13px; animation: toast-in 0.2s ease-out; transition: opacity 0.2s, transform 0.2s;
}
.toast.success { border-left-color: var(--ok); }
.toast.warn { border-left-color: var(--warn); }
.toast.error { border-left-color: var(--err); }
.toast.success .toast-icon { color: var(--ok); }
.toast.info .toast-icon { color: var(--accent); }
.toast.warn .toast-icon { color: var(--warn); }
.toast.error .toast-icon { color: var(--err); }
.toast.leaving { opacity: 0; transform: translateY(-6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- 语音栏（DOC-06 §2） ---------- */
#voice-bar {
  position: absolute;
  left: calc((100% - 336px) / 2); /* 居中于面板左侧的可视区域 */
  bottom: calc(var(--gutter) + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(560px, calc(100% - 336px - 2 * var(--gutter)));
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 18px;
  font-size: 13px;
  z-index: 3;
}
#panel.collapsed ~ #voice-bar { left: 50%; width: min(560px, calc(100% - 2 * var(--gutter))); }
.vb-row { display: flex; align-items: center; gap: 10px; }
#voice-bar .mic {
  position: relative; flex: none; display: grid; place-items: center;
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: var(--accent); color: #fff; cursor: pointer; transition: background-color 0.2s;
}
#voice-bar .mic svg { width: 20px; height: 20px; }
#voice-bar .mic:disabled { background: rgba(255, 255, 255, 0.08); color: var(--text-dim); cursor: not-allowed; }
#voice-bar[data-state="listening"] .mic { background: var(--err); animation: mic-pulse 1.2s infinite; }
#voice-bar[data-state="starting"] .mic, #voice-bar[data-state="processing"] .mic { opacity: 0.75; }
@keyframes mic-pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0.55); }
  70% { box-shadow: 0 0 0 12px rgba(255, 77, 79, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0); }
}
.vb-main { flex: 1; min-width: 0; }
.vb-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.engine-badge {
  flex: none; padding: 1px 8px; border-radius: 999px; font-size: 11px;
  background: rgba(58, 134, 255, 0.16); color: var(--accent);
}
.engine-badge[data-engine="cloud"] { background: rgba(46, 204, 113, 0.16); color: var(--ok); }
.engine-badge[data-engine="text"] { background: rgba(255, 255, 255, 0.08); color: var(--text-dim); }
.transcript { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.transcript.interim { color: var(--text-dim); }
.vb-result { min-height: 18px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--text-dim); }
.vb-result.success { color: var(--ok); }
.vb-result.info { color: var(--accent); }
.vb-result.warn { color: var(--warn); }
.vb-result.error { color: var(--err); }
.icon-btn {
  flex: none; display: grid; place-items: center; width: 36px; height: 36px;
  border: 1px solid var(--border); border-radius: 10px; background: rgba(255, 255, 255, 0.04); cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn[aria-expanded="true"], .icon-btn[aria-pressed="true"] { border-color: rgba(58, 134, 255, 0.5); color: var(--accent); }
.vb-text { display: flex; gap: 8px; }
.vb-text[hidden] { display: none; }
.vb-text input {
  flex: 1; min-width: 0; height: 36px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px;
  background: rgba(0, 0, 0, 0.25); color: var(--text); font: inherit;
}
.vb-text button { height: 36px; padding: 0 14px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; cursor: pointer; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 28px; padding: 0 10px; border: 1px solid var(--border); border-radius: 999px;
  background: rgba(255, 255, 255, 0.04); color: var(--text-dim); font-size: 12px; cursor: pointer;
}
.chip:hover { background: rgba(255, 255, 255, 0.1); color: var(--text); }

/* 隐私提示（NFR-08） */
dialog.privacy {
  max-width: min(380px, calc(100% - 2 * var(--gutter))); padding: 20px; border: 1px solid var(--border); border-radius: var(--radius-card);
  background: var(--surface-solid); color: var(--text);
}
dialog.privacy::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog.privacy h2 { margin: 0 0 8px; font-size: 16px; }
dialog.privacy p { margin: 0 0 16px; color: var(--text-dim); }
.privacy-actions { display: flex; justify-content: flex-end; gap: 8px; }
.privacy-actions button { height: 36px; padding: 0 14px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; cursor: pointer; }
.privacy-actions .secondary { background: rgba(255, 255, 255, 0.08); color: var(--text); }

/* ---------- 操作提示 ---------- */
.hint {
  position: absolute;
  left: 50%;
  bottom: calc(var(--gutter) + var(--safe-bottom) + 140px);
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--text);
  pointer-events: none;
  transition: opacity 0.6s;
}
.hint.fade { opacity: 0; }

/* ---------- 加载遮罩（FR-01） ---------- */
#loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--bg);
  color: var(--accent);
  transition: opacity 0.4s;
  z-index: 10;
}
#loading.done { opacity: 0; pointer-events: none; }
.loading-car { width: 120px; height: 48px; }
.loading-car path { stroke-dasharray: 320; stroke-dashoffset: 320; animation: draw 1.6s ease-in-out infinite alternate; }
@keyframes draw { to { stroke-dashoffset: 0; } }
#loading .progress { width: 200px; height: 3px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
#loading .bar { width: 0; height: 100%; background: var(--accent); transition: width 0.3s; }
#loading .step { margin: 0; color: var(--text-dim); font-size: 13px; }

/* ---------- 致命错误（FR-05） ---------- */
#fatal {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--gutter);
  background: var(--bg);
  z-index: 20;
}
#fatal[hidden] { display: none; }
.fatal-card {
  max-width: 420px;
  padding: 24px;
  border-radius: var(--radius-card);
  background: var(--surface-solid);
  border: 1px solid var(--border);
  text-align: center;
}
.fatal-card h2 { margin: 0 0 8px; font-size: 17px; }
.fatal-card .msg { margin: 0 0 18px; color: var(--text-dim); }
.fatal-card .reload {
  height: 36px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--radius-ctl);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

/* ---------- 调试信息（?debug=1&stats=1） ---------- */
#debug-stats {
  position: absolute;
  bottom: var(--gutter);
  left: var(--gutter);
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: #9fe870;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre;
  pointer-events: none;
}

/* ---------- 焦点 ---------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 移动端（FR-71） ---------- */
@media (max-width: 767px) {
  #topbar { padding: 8px 12px 8px 10px; max-width: calc(100% - 2 * var(--gutter) - 112px); }
  .brand { flex: none; }
  .brand-mark { width: 26px; height: 26px; }
  .brand .sub { display: none; }

  /* 控制面板 → 底部抽屉：收起 / 半屏 / 全屏 */
  #panel {
    top: auto; right: 0; left: 0; bottom: 0; width: auto;
    max-height: none; height: 85vh;
    border-radius: 18px 18px 0 0; border-bottom: 0;
    transform: translateY(calc(100% - 52px - var(--safe-bottom)));
    transition: transform 0.3s ease;
    z-index: 4;
    padding-bottom: var(--safe-bottom);
  }
  #panel[data-drawer="half"] { transform: translateY(calc(100% - 50vh)); }
  #panel[data-drawer="full"] { transform: none; }
  .panel-head { position: relative; padding: 18px 16px 8px; touch-action: none; }
  .collapse-btn { display: none; }
  .drawer-handle {
    display: block; position: absolute; inset: 0; width: 100%; border: 0; background: transparent; cursor: pointer;
  }
  .drawer-handle::before {
    content: ""; position: absolute; top: 7px; left: 50%; width: 40px; height: 4px; margin-left: -20px;
    border-radius: 2px; background: rgba(255, 255, 255, 0.3);
  }
  .panel-tabs { display: flex; gap: 6px; padding: 0 16px 8px; overflow-x: auto; }
  #panel[data-drawer="collapsed"] .panel-tabs { visibility: hidden; }
  #panel .panel-tabs button { flex: none; min-height: 32px; border-radius: 999px; }
  #panel button:not(.swatch):not(.drawer-handle) { min-height: 40px; }
  .slider-row { grid-template-columns: 72px 1fr 40px; }

  #voice-bar, #panel.collapsed ~ #voice-bar { left: 50%; width: calc(100% - 2 * var(--gutter)); bottom: calc(52px + 10px + var(--safe-bottom)); }
  #voice-bar .mic { width: 52px; height: 52px; }
  .hint { bottom: calc(52px + 150px + var(--safe-bottom)); }
  #toasts { top: 76px; }

  #view-controls {
    left: auto;
    right: var(--gutter);
    top: var(--gutter);
    bottom: auto;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
  }
  #view-controls .view-toggle {
    display: inline-flex;
    height: 44px;
    border-radius: var(--radius-card);
  }
  #view-controls .view-list { display: none; flex-direction: column; align-items: stretch; }
  #view-controls.open .view-list { display: flex; }
  #view-controls .view-list button { height: 40px; }

}

@media (prefers-reduced-motion: reduce) {
  .loading-car path { animation: none; stroke-dashoffset: 0; }
  #loading, .hint, #loading .bar, #panel, .toast { transition: none; }
  .toast, .shake, #voice-bar[data-state="listening"] .mic { animation: none; }
}
