@import url('https://fonts.googleapis.com/css2?family=Calistoga&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #f7fafd;
  --muted: #ebf2fa;
  --card: #ffffff;
  --fg: #0d1f35;
  --muted-fg: #5a7a9a;
  --border: #d6e4f0;
  --accent-border: rgba(20, 120, 200, 0.25);
  --accent: #1478c8;
  --accent-2: #2878dc;
  --accent-light: rgba(20, 120, 200, 0.08);
  --shadow-sm: 0 1px 3px rgba(20, 80, 160, 0.07);
  --shadow-md: 0 4px 16px rgba(20, 80, 160, 0.1);
  --shadow-lg: 0 12px 40px rgba(20, 80, 160, 0.14);
  --shadow-accent: 0 6px 24px rgba(20, 120, 200, 0.28);
  --radius: 16px;

  /* 语义状态色，保持克制使用 */
  --success: #0f9f76;
  --warning: #c98a1f;
  --error: #d34747;
  --danger-bg: rgba(211, 71, 71, 0.08);
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: "Inter", sans-serif;
  line-height: 1.6;
}

body {
  position: relative;
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 50% at 10% 20%, rgba(20, 120, 200, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse 60% 60% at 90% 80%, rgba(40, 120, 220, 0.05) 0%, transparent 55%);
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: radial-gradient(circle, rgba(20, 120, 200, 0.12) 1px, transparent 1px);
  background-size: 32px 32px;
  opacity: 0.36;
}

.deco-ring {
  position: fixed;
  inset: auto;
  top: 50%;
  left: 50%;
  border-radius: 50%;
  border: 1px dashed rgba(20, 120, 200, 0.18);
  pointer-events: none;
  z-index: 0;
}

.deco-ring-1 {
  width: 480px;
  height: 480px;
  margin-left: -240px;
  margin-top: -240px;
  animation: rotate-cw 80s linear infinite;
}

.deco-ring-2 {
  width: 700px;
  height: 700px;
  margin-left: -350px;
  margin-top: -350px;
  animation: rotate-ccw 120s linear infinite;
}

.page {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 8px;
  padding: 8px 10px 10px;
}

.assistant-panel {
  width: min(98vw, 1800px);
  max-width: 1800px;
  height: min(calc(100vh - 44px), 1280px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #ffffff 0%, #f9fcff 100%);
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.panel-title h2 {
  margin: 0;
  font-size: 1.06rem;
}

.signature {
  margin: 2px 0 0;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--muted-fg);
  text-transform: uppercase;
}

.icon-box {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: var(--shadow-accent);
}

.icon-box svg {
  width: 20px;
  height: 20px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.model-pill {
  border: 1px solid var(--accent-border);
  border-radius: 99px;
  padding: 4px 10px;
  background: var(--accent-light);
  color: var(--accent);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
}

.action-btn {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 12px;
  background: #ffffff;
  color: var(--muted-fg);
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-btn svg {
  width: 14px;
  height: 14px;
}

.action-btn:hover,
.action-btn:focus-visible {
  color: var(--accent);
  border-color: var(--accent-border);
  box-shadow: var(--shadow-sm);
  outline: none;
}

.action-btn.is-syncing {
  color: var(--warning);
  border-color: rgba(201, 138, 31, 0.35);
}

.action-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.status-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  padding: 7px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--muted);
}

.status-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.status-dot.is-syncing {
  background: var(--warning);
  animation: pulse 1s infinite;
}

.status-dot.is-error {
  background: var(--error);
}

.status-label {
  color: var(--muted-fg);
}

.status-value {
  color: var(--fg);
  font-weight: 600;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.messages::-webkit-scrollbar {
  width: 7px;
}

.messages::-webkit-scrollbar-thumb {
  background: #c6d8ea;
  border-radius: 8px;
}

.msg {
  display: flex;
  gap: 10px;
  animation: fade-up 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

.msg.user {
  flex-direction: row-reverse;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
}

.msg.user .avatar {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #ffffff;
}

.msg.ai .avatar {
  background: var(--muted);
  border: 1px solid var(--border);
  color: var(--accent);
}

.bubble {
  max-width: min(90%, 1240px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 11px 15px;
  box-shadow: var(--shadow-sm);
  word-break: break-word;
}

.msg.user .bubble {
  background: linear-gradient(135deg, rgba(20, 120, 200, 0.14), rgba(40, 120, 220, 0.08));
  border-color: var(--accent-border);
  border-bottom-right-radius: 5px;
}

.msg.ai .bubble {
  background: #ffffff;
  border-bottom-left-radius: 5px;
}

.bubble h1,
.bubble h2,
.bubble h3,
.bubble h4,
.bubble h5,
.bubble h6 {
  margin: 0.95em 0 0.45em;
  line-height: 1.32;
}

.bubble p {
  margin: 0.55em 0;
}

.bubble p:first-child {
  margin-top: 0;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble ul,
.bubble ol {
  padding-left: 1.3em;
}

.bubble code {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.88em;
  background: #eff5fb;
  border-radius: 4px;
  padding: 0.15em 0.45em;
  color: #0f3f6b;
}

.bubble pre {
  margin: 0.75em 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.bubble pre code {
  display: block;
  background: #f8fbff !important;
  color: #142940;
  padding: 14px 16px !important;
  line-height: 1.55;
  overflow-x: auto;
}

.code-wrap {
  position: relative;
}

.code-lang {
  position: absolute;
  top: 0;
  right: 0;
  padding: 4px 10px;
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-bottom-left-radius: 8px;
  font-size: 11px;
  color: var(--muted-fg);
  font-family: "JetBrains Mono", monospace;
  background: #f4f9ff;
}

.copy-btn {
  position: absolute;
  top: 4px;
  right: 62px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #ffffff;
  color: var(--muted-fg);
  font-size: 11px;
  padding: 2px 8px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease, color 0.2s ease;
}

.code-wrap:hover .copy-btn,
.copy-btn:focus-visible {
  opacity: 1;
}

.copy-btn:hover {
  color: var(--accent);
}

.bubble blockquote {
  margin: 0.65em 0;
  padding: 0.3em 0.8em;
  border-left: 3px solid var(--accent);
  border-radius: 0 5px 5px 0;
  background: var(--muted);
  color: var(--muted-fg);
}

.bubble table {
  width: 100%;
  margin: 0.65em 0;
  border-collapse: collapse;
  font-size: 0.93em;
}

.bubble th,
.bubble td {
  border: 1px solid var(--border);
  padding: 7px 10px;
}

.bubble th {
  background: var(--muted);
}

.bubble a {
  color: var(--accent);
}

.bubble hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 0.8em 0;
}

.error-text {
  color: var(--error);
}

.cursor-blink::after {
  content: "▍";
  color: var(--accent);
  margin-left: 2px;
  animation: blink 0.7s step-end infinite;
}

.empty-hint {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted-fg);
  gap: 12px;
}

.empty-icon {
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  border: 1px solid var(--accent-border);
  border-radius: 14px;
  color: var(--accent);
  background: var(--accent-light);
}

.empty-icon svg {
  width: 30px;
  height: 30px;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.suggestion-btn {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted-fg);
  font-size: 12px;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.suggestion-btn:hover,
.suggestion-btn:focus-visible {
  color: var(--accent);
  border-color: var(--accent-border);
  background: var(--accent-light);
  outline: none;
}

.input-area {
  padding: 10px 16px 11px;
  border-top: 1px solid var(--border);
  background: #ffffff;
}

.input-wrap {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fdfefe;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-wrap:focus-within {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px rgba(20, 120, 200, 0.1);
}

#userInput {
  flex: 1;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--fg);
  font-family: "Inter", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  min-height: 24px;
  max-height: 220px;
}

#userInput::placeholder {
  color: var(--muted-fg);
}

.send-btn,
.stop-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.send-btn {
  color: #ffffff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.send-btn:hover:not(:disabled),
.send-btn:focus-visible {
  transform: translateY(-1px);
  box-shadow: var(--shadow-accent);
  outline: none;
}

.send-btn:disabled {
  background: #b6c6d6;
  cursor: not-allowed;
}

.stop-btn {
  color: #ffffff;
  background: var(--error);
  display: none;
}

.stop-btn:hover,
.stop-btn:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(211, 71, 71, 0.28);
  outline: none;
}

.send-btn svg,
.stop-btn svg {
  width: 16px;
  height: 16px;
}

.input-hint {
  margin: 6px 0 0;
  text-align: center;
  color: var(--muted-fg);
  font-size: 10px;
  font-family: "JetBrains Mono", monospace;
  letter-spacing: 0.08em;
}

.excel-download {
  margin: 12px 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 10px;
  border: 1px solid var(--accent-border);
  padding: 9px 13px;
  color: var(--accent);
  background: var(--accent-light);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.2s ease;
}

.excel-download:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.excel-download svg {
  width: 16px;
  height: 16px;
}

.excel-download .filename {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
}

.sync-error-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 36px));
  border: 1px solid rgba(211, 71, 71, 0.3);
  border-radius: 12px;
  background: #fff6f6;
  color: #8f2323;
  padding: 11px 14px;
  box-shadow: var(--shadow-md);
  z-index: 5;
  animation: fade-up 0.3s ease;
}

.sync-error-toast.is-hidden {
  display: none;
}

.sync-error-toast .suggestion {
  margin-top: 4px;
  color: #a34a4a;
  font-size: 12px;
}

.page-footer {
  margin-top: 2px;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--muted-fg);
  opacity: 0.56;
}

.fade-up {
  animation: fade-up 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.fade-delay-0 {
  animation-delay: 0s;
}

.fade-delay-1 {
  animation-delay: 0.1s;
}

.fade-delay-2 {
  animation-delay: 0.2s;
}

.fade-delay-3 {
  animation-delay: 0.35s;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.6;
    transform: scale(1.3);
  }
}

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

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

@media (max-width: 920px) {
  .assistant-panel {
    width: 100%;
    max-width: 100%;
    height: min(calc(100vh - 28px), 1040px);
  }

  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 520px) {
  .page {
    padding: 10px 12px 14px;
    gap: 10px;
  }

  .assistant-panel {
    width: 100%;
    max-width: 100%;
    height: min(calc(100vh - 24px), 94vh);
    border-radius: 14px;
  }

  .panel-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .status-row {
    gap: 9px 14px;
  }

  .bubble {
    max-width: 86%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .deco-ring {
    animation: none;
  }

  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
