:root {
  --bg-color: #07060d;
  --bg-color-2: #0b0717;
  --chat-bg: rgba(16, 14, 26, 0.55);
  --user-msg-bg: rgba(59, 130, 246, 0.18);
  --ai-msg-bg: rgba(16, 14, 26, 0.45);
  --text-color: rgba(255, 255, 255, 0.92);
  --muted-color: rgba(255, 255, 255, 0.6);
  --accent-color: #3b82f6;
  --accent-color-2: #60a5fa;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-color-2: rgba(255, 255, 255, 0.12);
  --input-bg: rgba(255, 255, 255, 0.04);
}

body {
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto,
    Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: radial-gradient(1200px 700px at 50% -120px,
      rgba(59, 130, 246, 0.35),
      transparent 60%),
    radial-gradient(900px 500px at 10% 0%,
      rgba(96, 165, 250, 0.22),
      transparent 55%),
    linear-gradient(180deg, var(--bg-color-2), var(--bg-color));
  color: var(--text-color);
  margin: 0;
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar / Config Area */
.sidebar {
  width: 35%;
  background: var(--chat-bg);
  border-right: 1px solid var(--border-color);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow: hidden;
  backdrop-filter: blur(14px);
}

.sidebar h2 {
  margin: 0 0 10px 0;
  font-size: 1.2rem;
  color: rgba(255, 255, 255, 0.92);
}

.sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-right: 6px;
}

.bottom-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.log-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px;
  height: 120px;
  overflow: auto;
  font-size: 0.85rem;
  color: #bdbdbd;
  line-height: 1.4;
}

.progress-bar {
  height: 4px;
  background-color: #555;
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
  width: 100%;
}

.progress-fill {
  height: 100%;
  background-color: #00ff88;
  width: 0%;
  transition: width 0.3s ease;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-size: 0.9rem;
  color: var(--muted-color);
}

.form-control {
  background-color: var(--input-bg);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  padding: 8px 12px;
  border-radius: 6px;
  outline: none;
  font-size: 0.9rem;
}

.form-control:focus {
  border-color: var(--accent-color);
}

.btn {
  background: linear-gradient(135deg,
      rgba(59, 130, 246, 0.85),
      rgba(37, 99, 235, 0.85));
  color: white;
  border: none;
  padding: 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.2s;
  font-weight: 500;
}

.btn:hover {
  opacity: 0.9;
}

.btn:disabled {
  background-color: #555;
  cursor: not-allowed;
}

.chat-input {
  background-color: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text-color);
  resize: none;
  height: 92px;
  outline: none;
  line-height: 1.4;
  font-size: 0.9rem;
}

.chat-input:focus {
  border-color: var(--accent-color);
}

.main {
  width: 65%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-area {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-message {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 920px;
}

.chat-message.user {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-message.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-bubble {
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 12px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
  background: rgba(255, 255, 255, 0.03);
}

.chat-message.user .chat-bubble {
  background: var(--user-msg-bg);
  border-color: rgba(59, 130, 246, 0.35);
}

.chat-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 0.82rem;
  color: #9d9d9d;
}

.chat-media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  width: 100%;
}

.chat-media-item {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  background: #111;
}

.chat-media-item img,
.chat-media-item video {
  width: 100%;
  height: auto;
  display: block;
}

.chat-media-footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.03);
  color: #bdbdbd;
  font-size: 0.82rem;
}

.composer {
  border-top: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.18);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.composer-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.composer-row.bottom {
  align-items: flex-end;
}

.chat-input-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.upload-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color-2);
  font-size: 0.85rem;
  padding: 10px 12px;
  border-radius: 10px;
}

.image-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.03);
}

.image-preview img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 10px;
  background: #111;
}

.image-preview .name {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.85rem;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-color);
  border-radius: 10px;
  padding: 6px 10px;
  cursor: pointer;
}

.icon-btn:hover {
  border-color: rgba(255, 255, 255, 0.35);
}

.send-btn {
  height: 46px;
  padding: 0 16px;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color-2);
}

.btn-secondary:disabled {
  background-color: #555;
}

.chat-actions {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-input.chat-input-with-actions {
  width: 100%;
  padding-right: 240px;
}

#cancel-btn {
  display: none;
  height: 46px;
  padding: 0 14px;
}

.history-panel {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-header h3 {
  margin: 0;
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.92);
}

.history-clear-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color-2);
  font-size: 0.8rem;
  padding: 8px 10px;
  border-radius: 10px;
}

.composer-row {
  width: 100%;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: clamp(220px, 32vh, 420px);
  overflow: auto;
  padding-right: 4px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.12);
}

.history-item.selected {
  border-color: rgba(59, 130, 246, 0.55);
  background: rgba(59, 130, 246, 0.12);
}

.history-item.failed {
  border-color: rgba(255, 77, 79, 0.55);
  background: rgba(255, 77, 79, 0.08);
}

.history-item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-item-title {
  font-size: 0.88rem;
  color: #eaeaea;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-sub {
  font-size: 0.78rem;
  color: #9d9d9d;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-del-btn {
  padding: 6px 10px;
  font-size: 0.8rem;
  line-height: 1;
  border-radius: 10px;
}

.chat-ops {
  display: flex;
  gap: 10px;
  align-items: center;
}

.chat-op-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color-2);
  color: var(--text-color);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
}

.chat-op-btn:hover {
  border-color: rgba(255, 255, 255, 0.35);
}

.chat-op-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Status Dot */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #6c757d;
  display: inline-block;
  margin-right: 6px;
}

.status-dot.connected {
  background-color: #52c41a;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.connection-toggle-btn {
  margin-left: auto;
  padding: 6px 14px;
  font-size: 13px;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
}

.connection-toggle-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.connection-toggle-btn.active {
  background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
}

.connection-toggle-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.toggle-switch-wrapper {
  position: relative;
  display: inline-block;
  width: 54px;
  height: 28px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.toggle-switch-input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-switch {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(180deg, rgba(108, 117, 125, 0.38), rgba(108, 117, 125, 0.26));
  border: 1px solid var(--border-color);
  border-radius: 999px;
  transition: background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.toggle-switch::before {
  content: "启用";
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: rgba(255, 255, 255, 0.95);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.toggle-slider {
  position: absolute;
  height: 22px;
  width: 22px;
  left: 3px;
  top: 3px;
  background: linear-gradient(180deg, #ffffff, #f2f4f8);
  border-radius: 50%;
  transition: transform 0.28s cubic-bezier(0.68, -0.55, 0.27, 1.55), box-shadow 0.25s ease, background 0.25s ease;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22), 0 2px 6px rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(0, 0, 0, 0.12);
  will-change: transform;
}

.toggle-switch-input:checked+.toggle-switch {
  background-color: var(--accent-color);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0));
  border-color: var(--accent-color);
  box-shadow: 0 8px 22px rgba(0, 123, 255, 0.18), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.toggle-switch-input:checked+.toggle-switch::before {
  opacity: 1;
}

.toggle-switch-input:checked+.toggle-switch+.toggle-slider {
  transform: translateX(26px);
}

.toggle-switch-wrapper:hover .toggle-switch-input:not(:checked)+.toggle-switch {
  border-color: rgba(0, 123, 255, 0.6);
}

.toggle-switch-input:focus-visible+.toggle-switch {
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.35);
}

select.form-control option {
  background-color: #1a1a1a;
  color: #ffffff;
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: #1a1b26;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  width: 60%;
  max-width: 800px;
  min-width: 300px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text-color);
}

.modal-close {
  background: none;
  border: none;
  color: #888;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.modal-close:hover {
  color: #fff;
}

.modal-body {
  padding: 20px;
  color: #ddd;
  font-size: 0.95rem;
  line-height: 1.6;
  max-height: 60vh;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}
