:root {
  --bg: #f3f4f8;
  --panel: #ececf2;
  --line: #d8dbe6;
  --text: #12141a;
  --muted: #6c7488;
  --blue: #3a74ff;
  --violet: #7138ff;
  --ok: #1a9b61;
  --warn: #cf5d28;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #f7f8fc, var(--bg));
}

.top-actions {
  position: fixed;
  top: 16px;
  right: 18px;
  z-index: 42;
  display: flex;
  gap: 12px;
  align-items: center;
}

.panel-toggle {
  border: 1px solid #cbd2e6;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 16px;
  line-height: 1;
  font-weight: 700;
  color: #24304a;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 24px rgba(42, 55, 102, 0.18);
}

.video-link {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  text-decoration: none;
  color: #17325f;
  background: linear-gradient(135deg, #eef7ff, #ffffff);
}

.panel-mask {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(31, 40, 69, 0.34);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.layout {
  min-height: 100%;
  display: block;
}

.stage {
  max-width: 920px;
  margin: 0 auto;
  padding: 62px 22px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.avatar-wrap {
  position: relative;
  width: 260px;
  height: 260px;
  margin-bottom: 24px;
}

.avatar-wrap.hidden {
  display: block;
}

.pulse-ring {
  position: absolute;
  inset: -14px;
  border: 5px dotted #c4c7d3;
  border-radius: 50%;
  animation: ring-spin 7s linear infinite;
}

.avatar {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 35% 30%, #f9fbff 0, #edf1ff 52%, #dce5ff 100%);
  border: 1px solid #d3d8ea;
  box-shadow: 0 24px 48px rgba(74, 87, 154, 0.28);
  overflow: hidden;
  transition: transform 0.2s ease, filter 0.2s ease;
}

.avatar img {
  position: absolute;
  width: 76%;
  height: 76%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 10px 14px rgba(53, 68, 126, 0.26));
}

.avatar-countdown {
  position: absolute;
  display: grid;
  place-items: center;
  width: 76%;
  height: 76%;
  font-size: 84px;
  font-weight: 700;
  line-height: 1;
  color: #3b4d86;
  text-shadow: 0 8px 18px rgba(55, 72, 130, 0.28);
}

.avatar-wrap[data-group="neutral"] .avatar {
  transform: translateY(0);
}

.avatar-wrap[data-group="listening"] .avatar {
  animation: avatar-listening 1.1s ease-in-out infinite;
}

.avatar-wrap[data-group="thinking"] .avatar {
  animation: avatar-thinking 1.5s ease-in-out infinite;
}

.avatar-wrap[data-group="happy"] .avatar {
  animation: avatar-happy 0.9s ease-in-out infinite;
}

.avatar-wrap[data-group="serious"] .avatar {
  animation: avatar-serious 1.2s ease-in-out infinite;
}

.avatar-wrap[data-group="error"] .avatar {
  animation: avatar-error 0.9s ease-in-out infinite;
}

.avatar-wrap[data-group="surprised"] .avatar {
  animation: avatar-speaking 0.72s ease-in-out infinite;
}

.avatar-wrap[data-group="sleepy"] .avatar {
  animation: avatar-serious 1.8s ease-in-out infinite;
}

.avatar-wrap[data-speaking="1"] .pulse-ring,
.avatar-wrap[data-group="happy"] .pulse-ring {
  border-color: #9ba2ff;
  animation-duration: 2.2s;
}

.subtitle-card {
  width: min(980px, 100%);
  margin: 0 0 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.64);
  display: grid;
  gap: 8px;
}

.subtitle-line {
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: start;
  gap: 10px;
}

.subtitle-tag {
  border-radius: 999px;
  padding: 4px 10px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: #3b4764;
  background: #dce3f7;
}

.subtitle-text {
  margin: 0;
  font-size: 22px;
  line-height: 1.35;
  color: #2f3b56;
  min-height: 30px;
  word-break: break-word;
}

.actions {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

button {
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-size: 22px;
  font-weight: 600;
  padding: 18px 32px;
}

.call-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  padding: 14px 26px;
  transition: background-color 0.2s ease, transform 0.12s ease;
}

.call-btn.call-idle {
  background: #17b26a;
}

.call-btn.call-active {
  background: #e34747;
}

.call-btn .phone-icon {
  font-size: 20px;
  line-height: 1;
}

.call-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.cta {
  color: #fff;
  background: linear-gradient(100deg, var(--violet), var(--blue));
}

.ghost {
  color: #2c3140;
  background: #dfe2eb;
}

.panel-toggle,
.panel-close {
  border-radius: 999px;
  font-weight: 700;
}

button:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.status {
  min-height: 34px;
  margin: 0 0 18px;
  font-size: 21px;
  color: var(--ok);
}

.status.warn {
  color: var(--warn);
}

.transcript-card,
.history-card {
  width: min(980px, 100%);
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.58);
  padding: 18px;
}

.history-card {
  margin-top: 12px;
}

.transcript-toggle {
  width: 100%;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 24px;
  font-weight: 700;
  color: #18223b;
  line-height: 1.2;
}

.transcript-toggle-text {
  font-size: 16px;
  font-weight: 600;
  color: #45547a;
}

.transcript-body,
.history-body {
  margin-top: 10px;
}

.transcript-card.collapsed,
.history-card.collapsed {
  padding-bottom: 16px;
}

.transcript {
  height: 300px;
  overflow: auto;
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(247, 249, 255, 0.7);
}

.msg {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 19px;
  line-height: 1.45;
}

.msg.user {
  background: rgba(58, 116, 255, 0.14);
}

.msg.assistant {
  background: rgba(113, 56, 255, 0.14);
}

.msg.system {
  background: rgba(130, 139, 161, 0.14);
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-session {
  width: 100%;
  border: 1px solid #d6dbea;
  border-radius: 12px;
  padding: 12px 14px;
  background: rgba(247, 249, 255, 0.86);
  color: #22304f;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  text-align: left;
  font-size: 16px;
}

.history-session.active {
  border-color: #7896ff;
  background: rgba(58, 116, 255, 0.12);
}

.history-session-title {
  font-weight: 700;
}

.history-session-meta {
  color: #687694;
  font-size: 13px;
}

.history-detail {
  margin-top: 10px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 10px;
  min-height: 86px;
  max-height: 320px;
  overflow: auto;
  background: rgba(247, 249, 255, 0.7);
  display: grid;
  gap: 8px;
}

.history-empty {
  margin: 0;
  color: #6b758d;
  font-size: 15px;
}

.history-msg {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.history-msg.user {
  background: rgba(58, 116, 255, 0.14);
}

.history-msg.assistant {
  background: rgba(113, 56, 255, 0.14);
}

.history-msg-time {
  display: block;
  margin-bottom: 4px;
  color: #687694;
  font-size: 12px;
}

.quick-input {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.quick-input input,
.quick-input button {
  height: 54px;
  border-radius: 12px;
  border: 1px solid var(--line);
  font-size: 20px;
}

.quick-input input {
  padding: 0 12px;
  background: #fff;
}

.quick-input button {
  background: #2f3546;
  color: #fff;
  border: none;
}

.panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 41;
  width: min(540px, 94vw);
  height: 100%;
  padding: 18px 16px 24px;
  background: linear-gradient(180deg, #f2f3f8, #eeeef4);
  border-left: 1px solid var(--line);
  overflow: auto;
  transform: translateX(102%);
  transition: transform 0.2s ease;
}

body.persona-open,
body.kb-open {
  overflow: hidden;
}

body.persona-open #personaPanel,
body.kb-open #kbPanel {
  transform: translateX(0);
}

body.persona-open .panel-mask,
body.kb-open .panel-mask {
  opacity: 1;
  pointer-events: auto;
}

.kb-panel {
  z-index: 43;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 2px 6px 14px;
}

.panel-head h3 {
  margin: 0;
  font-size: 24px;
}

.panel-close {
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 700;
  color: #2a344e;
  background: #dfe4f2;
}

.panel-block {
  border-top: 1px solid var(--line);
  padding: 14px 8px 18px;
}

.hidden-block {
  display: none !important;
}

.panel-block h3 {
  margin: 10px 0 10px;
  font-size: 20px;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 16px;
  color: #232a3b;
}

.switch-row {
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 10px 2px;
}

.switch-row input[type="checkbox"] {
  width: 44px;
  height: 24px;
  accent-color: #4d6bff;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid #cfd3df;
  border-radius: 12px;
  background: #f6f7fb;
  font-size: 18px;
  color: #2b3245;
  padding: 11px 12px;
  resize: vertical;
  outline: none;
}

textarea {
  min-height: 70px;
}

.inline-actions {
  display: flex;
  gap: 8px;
}

.inline-actions button {
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 16px;
  background: #2f3546;
  color: #fff;
}

.kb-summary {
  margin: 0 0 10px;
  font-size: 14px;
  color: #5f6b87;
}

.kb-tip {
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: #657293;
}

.kb-list {
  display: grid;
  gap: 10px;
}

.kb-item {
  border: 1px solid #cfd5e8;
  border-radius: 12px;
  padding: 10px;
  background: #f9faff;
}

.kb-item-title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 700;
  color: #243250;
}

.kb-item-meta {
  margin: 0 0 10px;
  font-size: 13px;
  color: #677493;
}

.kb-item .inline-actions {
  justify-content: flex-end;
}

.kb-item .inline-actions button {
  background: #d33d3d;
  padding: 8px 14px;
  font-size: 14px;
}

.kb-empty {
  margin: 0;
  border: 1px dashed #cbd3e8;
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
  color: #677493;
  background: #f7f9ff;
}

@keyframes ring-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes avatar-listening {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  35% {
    transform: translateY(-3px) rotate(-2.4deg);
  }
  70% {
    transform: translateY(-1px) rotate(2.4deg);
  }
}

@keyframes avatar-thinking {
  0%,
  100% {
    transform: translateY(0);
    filter: saturate(1);
  }
  50% {
    transform: translateY(-5px);
    filter: saturate(1.08);
  }
}

@keyframes avatar-speaking {
  0%,
  100% {
    transform: scale(1) translateY(0);
  }
  40% {
    transform: scale(1.04) translateY(-3px);
  }
  70% {
    transform: scale(0.99) translateY(1px);
  }
}

@keyframes avatar-happy {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

@keyframes avatar-serious {
  0%,
  100% {
    transform: scale(1) translateY(0);
  }
  50% {
    transform: scale(1.01) translateY(-2px);
  }
}

@keyframes avatar-error {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-3px);
  }
  40% {
    transform: translateX(3px);
  }
  60% {
    transform: translateX(-2px);
  }
  80% {
    transform: translateX(2px);
  }
}

@media (max-width: 1480px) {
  .subtitle-text {
    font-size: 20px;
  }
}

@media (max-width: 1080px) {
  .top-actions {
    top: 10px;
    right: 10px;
    left: 10px;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
  }

  .panel-toggle {
    font-size: 14px;
    padding: 9px 14px;
  }

  .stage {
    padding: 52px 12px 18px;
  }

  .avatar-wrap {
    width: 188px;
    height: 188px;
  }

  .subtitle-text {
    font-size: 16px;
    min-height: 22px;
  }

  .status {
    font-size: 16px;
  }

  .transcript-card,
  .history-card {
    width: 100%;
  }

  .panel {
    width: 100%;
    max-width: 100%;
  }
}
