/* ==================== TopBar - Reference Design ==================== */

.top-bar {
  height: 56px;
  display: flex;
  align-items: center;
  background-color: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border-light);
  box-shadow: var(--shadow-sm);
  z-index: var(--z-top-bar); /* ✅ 组件层 - TopBar */
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.top-bar-content {
  width: 100%;
  padding: 0 var(--spacing-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-md);
}

/* Status Section - Left side */
.status-section {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  flex: 1;
  justify-content: flex-start;
  min-width: 0;
  overflow-x: auto;
}

/* Actions Section - Right side */
.actions-section {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  flex-shrink: 0;
}

/* Status Badge Styles - Minimalist */
.status-badge {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-xs) var(--spacing-sm);
  background-color: transparent;
  border: none;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  cursor: pointer;
  white-space: nowrap;
  min-height: 32px;
}

.status-badge:hover {
  background-color: var(--color-bg-tertiary);
}

.status-icon {
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
  opacity: 0.7;
}

.status-label {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  font-weight: 400;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* World Info badge - allow more space */
.world-info-badge {
  max-width: 400px;
}

.world-info-badge .status-label {
  max-width: 330px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Action Button Styles - Badge-like (Similar to status-badge) */
.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-sm) var(--spacing-md);
  background-color: transparent;
  color: var(--color-text-secondary);
  border: none;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  cursor: pointer;
  font-size: 1.4rem;  /* 更大的图标 */
  line-height: 1;
  min-height: 36px;   /* 与 status-badge 一致 */
}

.action-btn:hover {
  background-color: var(--color-bg-tertiary);
  color: var(--color-text-primary);
}

.action-btn:active {
  background-color: var(--color-accent-ultra-light);
  color: var(--color-accent);
}

.action-btn svg {
  display: none; /* Hide SVG, use text instead */
}

/* ==================== 弹出面板通用样式 ==================== */

.close-panel-button {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: var(--spacing-xs) var(--spacing-sm);
  margin-left: auto;
  transition: all var(--transition-fast);
  border-radius: var(--radius-sm);
}

.close-panel-button:hover {
  color: var(--color-text-primary);
  background-color: var(--color-bg-tertiary);
}

.panel-overlay {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  /* Optimize backdrop filter for better performance */
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: var(--z-modal-backdrop);
  display: flex;
  justify-content: center;
  padding-top: var(--spacing-xl);
  /* Optimize animation for better performance */
  will-change: opacity;
  animation: fadeIn var(--transition-normal);
}

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

.panel-content {
  background-color: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2xl);
  width: 90%;
  max-width: 1200px;
  max-height: calc(100vh - 80px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  /* Optimize animation for better performance */
  will-change: transform, opacity;
  animation: slideDown var(--transition-smooth);
}

@keyframes slideDown {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.panel-header {
  padding: var(--spacing-md) var(--spacing-lg);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--gradient-subtle);
}

.panel-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
  color: var(--color-text-primary);
}

.panel-body {
  padding: var(--spacing-lg);
  overflow-y: auto;
  flex: 1;
  background-color: var(--color-bg-primary);
}

/* TopBar 全局世界书列表 */
.global-books-list-topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.global-book-item-topbar {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  background: var(--gradient-subtle);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  font-size: 13px;
  color: var(--color-text-primary);
  font-weight: 500;
  transition: all 0.15s ease;
}

.global-book-item-topbar:hover {
  background: linear-gradient(135deg, var(--color-accent-light) 0%, var(--color-accent-light) 100%);
  border-color: var(--color-accent);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px var(--color-accent-light);
}

.global-book-name-topbar {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.no-global-books-topbar {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 14px;
  padding: 20px;
}

/* ==================== 设置面板样式 ==================== */

.setting-section {
  margin-bottom: var(--spacing-xl);
}

.setting-section:last-child {
  margin-bottom: 0;
}

.setting-section h4 {
  margin: 0 0 var(--spacing-md) 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text-primary);
  font-family: var(--font-ui);
}

.setting-options {
  display: flex;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-sm);
}

.setting-option {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-sm) var(--spacing-md);
  background-color: var(--color-bg-secondary);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  position: relative;
}

.setting-option input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.setting-option:hover {
  border-color: var(--color-accent);
  background-color: var(--color-bg-tertiary);
  color: var(--color-text-primary);
}

.setting-option.active {
  border-color: var(--color-accent);
  background-color: var(--color-accent-light);
  color: var(--color-accent);
  font-weight: 600;
}

.setting-description {
  margin: var(--spacing-xs) 0 0 0;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}

/* 主内容区域 */
.main-container {
  margin-top: 50px;
  height: calc(100vh - 50px);
  display: flex;
  overflow: hidden;
}

/* ==================== 设置面板专用样式 ==================== */

.settings-panel .panel-body {
  overflow-y: auto;
  max-height: calc(100vh - 200px);
}

.settings-tabs {
  display: flex;
  gap: 8px;
  padding: 0 16px;
  border-bottom: 1px solid var(--color-border);
}

.settings-tabs .tab-button {
  padding: 8px 16px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.settings-tabs .tab-button:hover {
  color: var(--color-text-primary);
  background-color: var(--color-bg-tertiary);
}

.settings-tabs .tab-button.active {
  color: white;
  border-bottom-color: var(--color-accent);
  background-color: var(--color-accent);
}

.settings-section {
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message {
  padding: 12px;
  margin-bottom: 16px;
  border-radius: 4px;
  font-size: 14px;
}

.message.success {
  background: rgba(76, 175, 80, 0.1);
  border: 1px solid #4caf50;
  color: #4caf50;
}

.message.error {
  background: rgba(244, 67, 54, 0.1);
  border: 1px solid #f44336;
  color: #f44336;
}

.btn-primary {
  padding: 10px 20px;
  background: var(--color-accent);
  border: none;
  border-radius: 4px;
  color: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-accent-hover, #0056b3);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* 设置面板输入框 */
.settings-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  color: var(--color-text-primary);
  font-size: 14px;
  box-sizing: border-box;
  transition: all 0.2s;
}

.settings-input:focus {
  outline: none;
  border-color: var(--color-accent);
  background: var(--color-bg-secondary);
}

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

/* 设置面板代码块 */
.settings-code {
  display: block;
  padding: 8px 12px;
  background: var(--color-bg-tertiary);
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  color: var(--color-accent);
  margin-bottom: 8px;
}

/* 设置面板文件列表 */
.settings-file-list {
  margin: 0;
  padding-left: 20px;
  list-style: none;
  font-size: 13px;
  color: var(--color-text-secondary);
}

.settings-file-list li {
  padding: 4px 0;
}

/* 设置面板提示文字 */
.settings-hint {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--color-text-muted);
}

/* 设置面板预览框 */
.preview-box {
  padding: 12px;
  background: var(--color-bg-tertiary);
  border-radius: 4px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* ==================== 正则规则列表样式 ==================== */

.regex-rules-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
}

.regex-rule-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--color-bg-tertiary);
  border-radius: 8px;
  transition: all 0.2s;
}

.regex-rule-item:hover {
  background: var(--color-bg-hover);
}

.regex-rule-drag {
  cursor: grab;
  color: var(--color-text-muted);
  font-size: 16px;
  user-select: none;
}

.regex-rule-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.regex-rule-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.regex-badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  white-space: nowrap;
  flex-shrink: 0;
}

.regex-badge.disabled {
  background: var(--color-error);
  color: white;
}

.regex-badge.prompt {
  background: var(--color-info);
  color: white;
}

.regex-badge.markdown {
  /* 注意：Markdown 徽章使用固定紫色，作为功能标识色 */
  background: #8844ff;
  color: white;
}

.regex-rule-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* 开关按钮 */
.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  display: inline-block;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--color-border);
  transition: 0.3s;
  border-radius: 24px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--color-accent);
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(20px);
}

.icon-btn-sm {
  padding: 4px 6px;
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: 4px;
  font-size: 12px;
  transition: all 0.2s;
}

.icon-btn-sm:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
}

.btn-icon {
  padding: 6px 10px;
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
  border-color: var(--color-text-muted);
}

.btn-add-rule {
  width: 100%;
  padding: 12px;
  background: var(--color-bg-tertiary);
  border: 2px dashed var(--color-border);
  border-radius: 8px;
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.btn-add-rule:hover {
  background: var(--color-bg-hover);
  border-color: var(--color-text-muted);
  color: var(--color-text-primary);
}
