/* ═══════════════════════════════════════════════
   OpenClaw Corgi Chat - ASCII Cute Corgi Theme
   ═══════════════════════════════════════════════ */

:root {
  /* 柯基配色 */
  --corgi-orange: #E8985E;
  --corgi-tan: #F4C28F;
  --corgi-cream: #FFF5E6;
  --corgi-brown: #B8734A;
  --corgi-dark: #8B5E3C;
  --corgi-nose: #3D2B1F;
  --corgi-white: #FFFAF0;

  /* 终端配色 */
  --bg-primary: #161622;
  --bg-secondary: #1E1E30;
  --bg-tertiary: #262640;
  --bg-input: #1A1A2C;

  /* 文字 */
  --text-primary: #F5E6D3;
  --text-secondary: #C4A882;
  --text-muted: #7A6B5E;
  --text-accent: #FFB347;

  /* 功能色 */
  --online: #7FD87F;
  --error: #E87461;
  --link: #7EB8DA;

  /* 间距 */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;

  /* 圆角 */
  --radius: 4px;
  --radius-lg: 8px;
}

/* ─── 基础重置 ─── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Cascadia Code', 'Consolas', 'Courier New', 'Microsoft YaHei', monospace;
  font-size: 14px;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
}

/* CRT 扫描线效果 */
body::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.03) 2px,
    rgba(0, 0, 0, 0.03) 4px
  );
}

pre {
  font-family: inherit;
  font-size: inherit;
  line-height: 1.2;
  margin: 0;
}

/* ─── 启动画面 ─── */
.splash {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: splashFadeOut 0.5s ease-in 2.5s forwards;
}

.splash-logo {
  position: relative;
}

.splash-corgi-img {
  width: 180px;
  height: 180px;
  object-fit: contain;
  image-rendering: pixelated;
  animation: corgiPulse 1.5s ease-in-out infinite;
  filter: drop-shadow(0 0 20px rgba(232, 152, 94, 0.4));
}

.splash-text {
  margin-top: var(--space-lg);
  color: var(--text-secondary);
  font-size: 16px;
}

.typing-text {
  overflow: hidden;
  white-space: nowrap;
  animation: typewriter 1.5s steps(8) forwards;
  display: inline-block;
  width: 0;
}

.splash-dots {
  margin-top: var(--space-sm);
  color: var(--corgi-tan);
  font-size: 24px;
}

.splash-dots span {
  animation: dotBounce 1.4s ease-in-out infinite;
  display: inline-block;
}

.splash-dots span:nth-child(2) { animation-delay: 0.2s; }
.splash-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes splashFadeOut {
  to { opacity: 0; pointer-events: none; }
}

@keyframes corgiPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

@keyframes typewriter {
  to { width: 8em; }
}

@keyframes dotBounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-8px); }
}

/* ─── 主应用容器 ─── */
.app {
  display: none;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  max-width: 100%;
  margin: 0;
}

.app.visible {
  display: flex;
  animation: fadeIn 0.5s ease-out forwards;
}

@keyframes fadeIn {
  to { opacity: 1; }
}

/* ─── 顶部栏 ─── */
.header {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--bg-tertiary);
}

.header-corgi-img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  image-rendering: pixelated;
  flex-shrink: 0;
  transition: transform 0.3s;
  filter: drop-shadow(0 0 6px rgba(232, 152, 94, 0.3));
}

.header-corgi-img:hover {
  transform: scale(1.1) rotate(-5deg);
}

.header-center {
  flex: 1;
}

.title {
  font-size: 22px;
  font-weight: 700;
  color: var(--corgi-orange);
  letter-spacing: 2px;
  text-shadow: 0 0 15px rgba(232, 152, 94, 0.4);
  margin: 0;
}

.subtitle {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 3px;
}

.status {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  margin-top: 2px;
}

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

.status-dot.online {
  background: var(--online);
  box-shadow: 0 0 8px rgba(127, 216, 127, 0.5);
  animation: pulse 2s ease-in-out infinite;
}

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

.status-text {
  font-size: 11px;
  color: var(--text-muted);
}

.header-right {
  flex-shrink: 0;
}

.btn-icon {
  background: none;
  border: 1px solid var(--bg-tertiary);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 10px;
  line-height: 1.1;
  cursor: pointer;
  padding: var(--space-xs);
  border-radius: var(--radius);
  transition: all 0.2s;
  white-space: pre;
}

.btn-icon:hover {
  color: var(--corgi-orange);
  border-color: var(--corgi-orange);
  background: rgba(232, 152, 94, 0.1);
}

/* ─── 装饰分隔线 ─── */
.divider {
  text-align: center;
  font-size: 11px;
  color: var(--bg-tertiary);
  padding: 2px 0;
  user-select: none;
  overflow: hidden;
  white-space: nowrap;
  letter-spacing: -1px;
}

/* ─── 聊天区域 ─── */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md) var(--space-lg);
  scroll-behavior: smooth;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(232, 152, 94, 0.03) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(244, 194, 143, 0.02) 0%, transparent 50%),
    var(--bg-primary);
}

/* 自定义滚动条 */
.chat-area::-webkit-scrollbar {
  width: 6px;
}

.chat-area::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

.chat-area::-webkit-scrollbar-thumb {
  background: var(--corgi-brown);
  border-radius: 3px;
}

.chat-area::-webkit-scrollbar-thumb:hover {
  background: var(--corgi-orange);
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* ─── 消息样式 ─── */
.message {
  display: flex;
  gap: var(--space-sm);
  animation: messageSlideIn 0.3s ease-out;
  max-width: 85%;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

.bot-message {
  align-self: flex-start;
}

.user-message {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-avatar {
  flex-shrink: 0;
  margin-top: 4px;
}

.avatar-img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 4px rgba(232, 152, 94, 0.2));
}

.user-message .message-avatar pre {
  color: var(--text-secondary);
}

.message-content {
  min-width: 0;
}

.message-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: 2px;
  padding: 0 var(--space-xs);
}

.message-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--corgi-tan);
}

.user-message .message-name {
  color: var(--link);
}

.message-time {
  font-size: 10px;
  color: var(--text-muted);
}

.message-bubble {
  background: var(--bg-secondary);
  border: 1px solid var(--bg-tertiary);
  border-radius: var(--radius);
  padding: var(--space-sm) var(--space-md);
  position: relative;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.bot-message .message-bubble {
  border-left: 2px solid var(--corgi-orange);
}

.user-message .message-bubble {
  background: rgba(232, 152, 94, 0.12);
  border: 1px solid rgba(232, 152, 94, 0.25);
  border-right: 2px solid var(--corgi-orange);
}

.message-bubble p {
  margin: 0;
  white-space: pre-wrap;
}

/* 欢迎消息 */
.welcome-msg {
  max-width: 100%;
  align-self: center;
}

.welcome-msg .message-bubble {
  border-left: 2px solid var(--corgi-orange);
  border-right: 2px solid var(--corgi-orange);
}

.welcome-bubble {
  text-align: left;
}

.welcome-bubble .welcome-text p {
  margin: 0 0 4px 0;
  white-space: normal;
}

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

.welcome-bubble strong {
  color: var(--corgi-orange);
}

/* ─── 正在输入指示器 ─── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) 0;
  animation: messageSlideIn 0.3s ease-out;
}

.typing-indicator.hidden {
  display: none;
}

.typing-content {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.typing-dots span {
  animation: dotBounce 1.4s ease-in-out infinite;
  display: inline-block;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

.typing-paw {
  animation: pawWag 0.8s ease-in-out infinite alternate;
  display: inline-block;
}

@keyframes pawWag {
  from { transform: rotate(-10deg); }
  to { transform: rotate(10deg); }
}

/* ─── 输入区域 ─── */
.input-area {
  position: relative;
  z-index: 10000;
  pointer-events: auto;
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-secondary);
  border-top: 1px solid var(--bg-tertiary);
}

.input-wrapper {
  position: relative;
  z-index: 10001;
  pointer-events: auto;
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
  background: var(--bg-input);
  border: 1px solid var(--bg-tertiary);
  border-radius: var(--radius-lg);
  padding: var(--space-sm) var(--space-md);
  transition: border-color 0.2s;
}

.input-wrapper:focus-within {
  border-color: var(--corgi-orange);
  box-shadow: 0 0 12px rgba(232, 152, 94, 0.15);
}

.input-prompt {
  font-size: 12px;
  color: var(--corgi-orange);
  font-weight: 600;
  white-space: nowrap;
  padding-bottom: 2px;
  user-select: none;
}

.input-field {
  position: relative;
  z-index: 10001;
  pointer-events: auto;
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  min-height: 24px;
  max-height: 120px;
  caret-color: var(--corgi-orange);
}

.input-field::placeholder {
  color: var(--text-muted);
}

.send-btn {
  background: var(--corgi-orange);
  border: none;
  color: var(--bg-primary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: 14px;
  transition: all 0.2s;
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--corgi-tan);
  transform: scale(1.05);
}

.send-btn:active {
  transform: scale(0.95);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.input-hints {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-xs) var(--space-sm);
  font-size: 10px;
  color: var(--text-muted);
}

.paw-trail {
  margin-left: auto;
  letter-spacing: 4px;
  animation: pawTrail 3s ease-in-out infinite;
}

@keyframes pawTrail {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.8; }
}

/* ─── 设置面板 ─── */
.settings-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  animation: fadeIn 0.2s ease-out;
}

.settings-overlay.hidden {
  display: none;
}

.settings-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--corgi-orange);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  width: 90%;
  max-width: 440px;
  box-shadow: 0 0 40px rgba(232, 152, 94, 0.15);
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-lg);
}

.settings-header pre {
  color: var(--corgi-orange);
  font-size: 12px;
}

.btn-close {
  background: none;
  border: 1px solid var(--text-muted);
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-close:hover {
  color: var(--error);
  border-color: var(--error);
}

.settings-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.setting-label {
  font-size: 12px;
  color: var(--corgi-tan);
  font-weight: 500;
}

.setting-input {
  background: var(--bg-input);
  border: 1px solid var(--bg-tertiary);
  border-radius: var(--radius);
  padding: var(--space-sm) var(--space-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.setting-input:focus {
  border-color: var(--corgi-orange);
}

.setting-input::placeholder {
  color: var(--text-muted);
}

.toggle-group {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.toggle-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--text-muted);
  border-radius: var(--radius);
  padding: var(--space-xs) var(--space-md);
  color: var(--online);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-btn:hover {
  border-color: var(--corgi-orange);
}

.save-btn {
  background: none;
  border: none;
  color: var(--corgi-orange);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: var(--space-sm);
  transition: all 0.2s;
  white-space: pre;
  text-align: center;
  margin-top: var(--space-sm);
}

.save-btn:hover {
  color: var(--corgi-tan);
  text-shadow: 0 0 10px rgba(232, 152, 94, 0.3);
}

/* ─── 时间戳分隔 ─── */
.time-separator {
  text-align: center;
  font-size: 10px;
  color: var(--text-muted);
  padding: var(--space-sm) 0;
  user-select: none;
}

.time-separator::before,
.time-separator::after {
  content: ' ━━━ ';
  color: var(--bg-tertiary);
}

/* ─── 系统消息 ─── */
.system-message {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  padding: var(--space-xs) 0;
}

/* ─── 隐藏类 ─── */
.hidden {
  display: none !important;
}

/* ─── 响应式 ─── */
@media (max-width: 600px) {
  .header {
    padding: var(--space-sm) var(--space-md);
    gap: var(--space-sm);
  }

  .header-corgi-img {
    width: 42px;
    height: 42px;
  }

  .splash-corgi-img {
    width: 140px;
    height: 140px;
  }

  .title {
    font-size: 18px;
  }

  .chat-area {
    padding: var(--space-sm) var(--space-md);
  }

  .input-area {
    padding: var(--space-sm) var(--space-md);
  }

  .input-prompt {
    font-size: 11px;
  }

  .message {
    max-width: 95%;
  }

  .welcome-art {
    font-size: 11px;
  }

  .divider {
    font-size: 9px;
  }
}

/* ─── 消息文字选择 ─── */
::selection {
  background: rgba(232, 152, 94, 0.3);
  color: var(--text-primary);
}

/* ─── 柯基走路动画 (底部装饰) ─── */
@keyframes corgiWalk {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100vw); }
}

/* ─── 消息中的代码块 ─── */
.message-bubble code {
  background: var(--bg-tertiary);
  padding: 1px 4px;
  border-radius: 2px;
  font-size: 13px;
  color: var(--corgi-tan);
}

.message-bubble pre code {
  display: block;
  padding: var(--space-sm);
  overflow-x: auto;
}

/* ─── 链接 ─── */
.message-bubble a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px dashed var(--link);
}

.message-bubble a:hover {
  color: var(--corgi-tan);
  border-bottom-color: var(--corgi-tan);
}

.message-file {
  display: inline-block;
  margin-top: 2px;
  padding: 2px 0;
  font-size: 13px;
}

.message-file .file-icon {
  margin-right: 4px;
}

.message-file a {
  margin-left: 6px;
}

/* ─── 错误消息 ─── */
.error-bubble {
  border-color: var(--error) !important;
  border-left-color: var(--error) !important;
}

.error-bubble .error-text {
  color: var(--error);
  font-size: 12px;
}

/* ─── 图片按钮 ─── */
.img-btn {
  background: none;
  border: 1px solid var(--bg-tertiary);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s;
  flex-shrink: 0;
}

.img-btn:hover {
  color: var(--corgi-orange);
  border-color: var(--corgi-orange);
  background: rgba(232, 152, 94, 0.1);
}

/* ─── 图片预览栏 ─── */
.image-preview-bar {
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-input);
  border: 1px solid var(--bg-tertiary);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.image-preview-bar + .input-wrapper {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.image-preview-list {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.image-preview-item {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--bg-tertiary);
}

.image-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-preview-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  background: rgba(0, 0, 0, 0.7);
  color: var(--text-primary);
  border: none;
  border-radius: 50%;
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background 0.2s;
}

.image-preview-remove:hover {
  background: var(--error);
}

/* ─── 消息中的图片 ─── */
.message-images {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
}

.message-images:first-child {
  margin-top: 0;
}

.message-img-wrap {
  max-width: 280px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--bg-tertiary);
  cursor: pointer;
  transition: border-color 0.2s;
}

.message-img-wrap:hover {
  border-color: var(--corgi-orange);
}

.message-img-wrap img {
  display: block;
  max-width: 100%;
  height: auto;
  max-height: 300px;
  object-fit: contain;
  background: var(--bg-tertiary);
}

/* ─── 图片灯箱 ─── */
.lightbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  cursor: zoom-out;
  animation: fadeIn 0.2s ease-out;
}

.lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
}

/* ─── 拖拽上传高亮 ─── */
.drag-over .chat-area {
  outline: 2px dashed var(--corgi-orange);
  outline-offset: -4px;
  background:
    radial-gradient(ellipse at center, rgba(232, 152, 94, 0.08) 0%, transparent 70%),
    var(--bg-primary);
}

.drag-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(232, 152, 94, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  pointer-events: none;
}

.drag-overlay-text {
  font-size: 18px;
  color: var(--corgi-orange);
  padding: var(--space-lg) var(--space-xl);
  border: 2px dashed var(--corgi-orange);
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
}

@media (max-width: 600px) {
  .message-img-wrap {
    max-width: 200px;
  }

  .message-img-wrap img {
    max-height: 200px;
  }
}
