* { margin: 0; padding: 0; box-sizing: border-box; }
/* 全局兜底：hidden 属性必须始终能隐藏元素。否则像 .menu{display:flex} 这类
   带 display 的选择器会覆盖 [hidden] 的 display:none，导致元素关不掉（曾坑过登录框、导出菜单）*/
[hidden] { display: none !important; }
:root {
  --bg: #f6f6f8; --card: #fff; --accent: #4f6ef7; --accent-soft: #e8ecfe;
  --text: #1d1d1f; --muted: #8a8a90; --danger: #e5484d;
}
html, body { height: 100%; }
body {
  font: 16px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column;
}

header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: var(--card); border-bottom: 1px solid #e6e6ea;
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; }
.actions { display: flex; gap: 6px; align-items: center; }
.actions button {
  border: none; background: transparent; font-size: 20px; cursor: pointer;
  padding: 6px; border-radius: 8px; opacity: .45;
}
.actions button.on, .actions button:active { opacity: 1; background: var(--accent-soft); }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 110%; background: var(--card);
  border: 1px solid #e6e6ea; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.12);
  display: flex; flex-direction: column; min-width: 130px; overflow: hidden;
}
.menu a { padding: 10px 14px; text-decoration: none; color: var(--text); font-size: 14px; }
.menu a:hover { background: var(--accent-soft); }

#recordsPanel {
  position: fixed; top: 53px; right: 0; bottom: 0; width: min(340px, 92vw);
  background: var(--card); border-left: 1px solid #e6e6ea; z-index: 9;
  overflow-y: auto; box-shadow: -4px 0 20px rgba(0,0,0,.08);
}
.panel-head { padding: 12px 14px; font-weight: 600; border-bottom: 1px solid #eee; }
#recordsList { list-style: none; }
#recordsList li { padding: 10px 14px; border-bottom: 1px solid #f2f2f4; font-size: 14px; }
#recordsList li.done .rec-text { text-decoration: line-through; color: var(--muted); }
.rec-meta { color: var(--muted); font-size: 12px; display: flex; gap: 8px; margin-bottom: 2px; }
.rec-ops { margin-top: 4px; display: flex; gap: 10px; }
.rec-ops button {
  border: none; background: none; cursor: pointer; font-size: 12px; color: var(--accent); padding: 0;
}
.rec-ops button.del { color: var(--danger); }

main {
  flex: 1; overflow-y: auto; padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.msg { max-width: 86%; padding: 10px 14px; border-radius: 16px; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--card); border-bottom-left-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.msg.error { align-self: flex-start; background: #fdecec; color: var(--danger); }
.msg.pending { color: var(--muted); animation: blink 1.2s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .4; } }

.card-badge {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  font-size: 12px; padding: 1px 8px; border-radius: 999px; margin-right: 6px;
}
.card-fields { color: var(--muted); font-size: 13px; margin-top: 4px; }
.card-ops { margin-top: 6px; }
.card-ops button, .speak-btn {
  border: none; background: none; cursor: pointer; font-size: 13px; color: var(--muted); padding: 0;
}
.card-ops button.del { color: var(--danger); }
.matched { margin-top: 8px; font-size: 13px; color: var(--muted); }
.matched summary { cursor: pointer; }
.matched li { margin: 4px 0 0 16px; }

footer {
  display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid #e6e6ea; position: sticky; bottom: 0;
}
#micBtn {
  border: none; font-size: 20px; background: var(--accent-soft); border-radius: 50%;
  width: 44px; height: 44px; cursor: pointer; flex-shrink: 0;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
#micBtn.recording { background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
#input {
  flex: 1; border: 1px solid #e0e0e4; border-radius: 22px; padding: 0 16px;
  font-size: 16px; outline: none; background: var(--bg);
}
#input:focus { border-color: var(--accent); }
#sendBtn {
  border: none; background: var(--accent); color: #fff; border-radius: 22px;
  padding: 0 18px; font-size: 15px; cursor: pointer; flex-shrink: 0;
}
#sendBtn:disabled { opacity: .5; }

#loginOverlay {
  position: fixed; inset: 0; background: var(--bg); z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: var(--card); border-radius: 16px; padding: 32px 28px;
  box-shadow: 0 8px 32px rgba(0,0,0,.12); width: min(320px, 86vw);
  display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login-title { font-size: 22px; font-weight: 700; }
.login-box input {
  border: 1px solid #e0e0e4; border-radius: 10px; padding: 10px 14px;
  font-size: 16px; outline: none;
}
.login-box input:focus { border-color: var(--accent); }
.login-box button {
  border: none; background: var(--accent); color: #fff; border-radius: 10px;
  padding: 10px; font-size: 16px; cursor: pointer;
}
#loginErr { color: var(--danger); font-size: 13px; }
.login-box.shake { animation: shake .4s; }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}
