/* ============================================
   AI小牛马 H5 - 对话式远程控制台
   ============================================ */

:root {
  --color-primary: #3b82f6;
  --color-primary-light: #60a5fa;
  --color-primary-dark: #2563eb;
  --color-primary-glow: rgba(59, 130, 246, 0.25);
  --color-success: #22c55e;
  --color-success-bg: rgba(34, 197, 94, 0.12);
  --color-warning: #f59e0b;
  --color-danger: #ef4444;
  --bg-base: #0f1117;
  --bg-surface: #161922;
  --bg-elevated: #1c2030;
  --bg-card: rgba(28, 32, 48, 0.65);
  --text-primary: #f0f2f5;
  --text-secondary: #8b92a5;
  --text-tertiary: #5a6178;
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-light: rgba(255, 255, 255, 0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --transition-fast: 0.15s ease;
  --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
}
input, button { font-family: inherit; font-size: inherit; }
.view { min-height: 100vh; min-height: 100dvh; }

/* ============ 登录页 ============ */
.login-container {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh; padding: 32px;
  background: radial-gradient(ellipse at 50% 0%, rgba(59,130,246,0.12) 0%, transparent 60%), var(--bg-base);
}
.login-brand { text-align: center; margin-bottom: 32px; }
.login-logo { width: 64px; height: 64px; margin: 0 auto 16px; }
.login-logo svg { width: 100%; height: 100%; filter: drop-shadow(0 4px 12px rgba(59,130,246,0.3)); }
.login-title {
  font-size: 28px; font-weight: 700; letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text-primary), var(--color-primary-light));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.login-subtitle { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }
.login-form { width: 100%; max-width: 360px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
.form-group input {
  width: 100%; height: 48px; padding: 0 16px; background: var(--bg-elevated);
  border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  color: var(--text-primary); font-size: 15px; outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.form-group input:focus { border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-glow); }
.form-group input::placeholder { color: var(--text-tertiary); }
.btn-primary {
  height: 48px; border: none; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: transform var(--transition-fast);
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-full { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 24px; }
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.login-error { color: var(--color-danger); font-size: 13px; text-align: center; margin-top: 16px; min-height: 20px; }

/* ============ 顶栏 ============ */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  height: 52px; padding: 0 var(--space-md); padding-top: var(--safe-top);
  background: rgba(15, 17, 23, 0.92); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
.topbar-logo { display: flex; align-items: center; }
.topbar-title { font-size: 15px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-balance { font-size: 13px; font-weight: 500; color: var(--color-warning); }
.connection-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--color-danger); box-shadow: 0 0 6px var(--color-danger);
  transition: background var(--transition-smooth);
}
.connection-dot.online { background: var(--color-success); box-shadow: 0 0 6px var(--color-success); }
.btn-topbar {
  background: none; border: none; color: var(--text-tertiary);
  cursor: pointer; padding: 4px; opacity: 0.7;
}

/* ============ 状态条 ============ */
.stats-strip {
  position: fixed; top: 52px; left: 0; right: 0; z-index: 99;
  display: flex; align-items: center; justify-content: center;
  gap: 8px; padding: 6px var(--space-md);
  background: rgba(22, 25, 34, 0.95); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 12px; color: var(--text-tertiary);
}
.stats-strip b { color: var(--text-primary); font-weight: 600; }
.strip-sep { color: var(--border-light); }

/* ============ 聊天区域 ============ */
.chat-area {
  position: fixed;
  top: calc(52px + 32px);
  bottom: calc(60px + var(--safe-bottom));
  left: 0; right: 0;
  overflow-y: auto;
  padding: var(--space-md);
  -webkit-overflow-scrolling: touch;
}

.chat-row {
  display: flex; margin-bottom: 12px;
  animation: msg-in 0.25s ease-out;
}
.chat-row.ai { justify-content: flex-start; }
.chat-row.user { justify-content: flex-end; }
.chat-row.system { justify-content: center; }

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-bubble-wrap { max-width: 85%; }

.chat-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}
.chat-row.ai .chat-bubble {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-top-left-radius: 4px;
  color: var(--text-primary);
}
.chat-row.user .chat-bubble {
  background: linear-gradient(135deg, var(--color-primary), #6366f1);
  border-top-right-radius: 4px;
  color: #fff;
}
.chat-row.system .chat-bubble {
  background: transparent;
  color: var(--text-tertiary);
  font-size: 12px;
  padding: 4px 12px;
}

.chat-label {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-bottom: 3px;
  padding-left: 2px;
}

.typing-dots { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-tertiary);
  animation: typing 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

.cmd-tags { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.cmd-tag {
  display: inline-block; font-size: 11px; padding: 2px 8px;
  border-radius: 4px;
}
.cmd-tag.ok { background: var(--color-success-bg); color: var(--color-success); }
.cmd-tag.fail { background: rgba(239,68,68,0.12); color: var(--color-danger); }

/* ============ 输入栏 ============ */
.input-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  display: flex; align-items: center; gap: 8px;
  padding: 10px var(--space-md);
  padding-bottom: calc(10px + var(--safe-bottom));
  background: rgba(15, 17, 23, 0.95);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
}
.chat-input {
  flex: 1; height: 40px; padding: 0 14px;
  background: var(--bg-elevated); border: 1px solid var(--border-light);
  border-radius: 20px; color: var(--text-primary); font-size: 14px;
  outline: none; transition: border-color var(--transition-fast);
}
.chat-input:focus { border-color: var(--color-primary); }
.chat-input::placeholder { color: var(--text-tertiary); }
.btn-mic, .btn-send {
  width: 40px; height: 40px; flex-shrink: 0;
  border: none; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition-fast);
}
.btn-mic {
  background: var(--bg-elevated); color: var(--text-secondary);
  border: 1px solid var(--border-light);
}
.btn-mic:active, .btn-mic.recording {
  background: var(--color-danger); color: #fff; border-color: var(--color-danger);
}
.btn-send {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: #fff;
}
.btn-send:active { transform: scale(0.9); }
.btn-send:disabled { opacity: 0.4; }

/* ============ 录音浮层 ============ */
.recording-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}
.recording-content { text-align: center; }
.recording-waves {
  display: flex; gap: 4px; justify-content: center;
  margin-bottom: 16px; height: 40px; align-items: center;
}
.recording-waves span {
  width: 4px; height: 16px; background: var(--color-danger);
  border-radius: 2px; animation: wave 1s ease-in-out infinite;
}
.recording-waves span:nth-child(2) { animation-delay: 0.1s; }
.recording-waves span:nth-child(3) { animation-delay: 0.2s; }
.recording-waves span:nth-child(4) { animation-delay: 0.3s; }
.recording-waves span:nth-child(5) { animation-delay: 0.4s; }
@keyframes wave {
  0%, 100% { height: 16px; }
  50% { height: 36px; }
}
.recording-text { font-size: 18px; font-weight: 500; color: #fff; margin-bottom: 8px; }
.recording-hint { font-size: 13px; color: var(--text-tertiary); }

/* ============ Toast ============ */
.toast-container {
  position: fixed; top: calc(60px + var(--safe-top));
  left: 50%; transform: translateX(-50%); z-index: 500;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  padding: 10px 20px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; backdrop-filter: blur(16px);
  animation: toast-in 0.3s ease-out, toast-out 0.3s ease-in 2.7s forwards;
  pointer-events: auto; white-space: nowrap;
}
.toast-success { background: rgba(34,197,94,0.9); color: #fff; }
.toast-error { background: rgba(239,68,68,0.9); color: #fff; }
.toast-info { background: rgba(59,130,246,0.9); color: #fff; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  from { opacity: 1; }
  to { opacity: 0; transform: translateY(-8px); }
}

@media (max-width: 360px) {
  .stats-strip { font-size: 11px; gap: 6px; }
  .chat-bubble { font-size: 13px; }
}
