/* ============================================================
   AbOpt Optimizer — 暗色主题样式
   基于 design-spec.md 严格实现
   ============================================================ */

/* ----- CSS 变量（设计 Token）----- */
:root {
  /* 背景色 */
  --bg-primary: #121826;
  --bg-secondary: #1A1F2E;
  --bg-elevated: #1E2532;
  --bg-input: #1E2532;
  --bg-dropdown: #0F1219;

  /* 文字色 */
  --text-primary: #FFFFFF;
  --text-secondary: #8B9BB4;
  --text-placeholder: #5A6580;

  /* 边框色 */
  --border-default: #2A3042;
  --border-hover: #3A4460;

  /* 强调色 */
  --accent-primary: #0CD3A0;
  --accent-hover: #0EEAB6;
  --accent-active: #0ABF90;
  --accent-bg: rgba(12, 211, 160, 0.10);
  --accent-bg-light: rgba(12, 211, 160, 0.05);

  /* 状态色 */
  --status-success: #10B981;
  --status-warning: #F59E0B;
  --status-error: #EF4444;

  /* 字体 */
  --font-family: "Inter", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", "Source Code Pro", monospace;

  /* 间距 */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* 圆角 */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 50%;

  /* 动效 */
  --duration-fast: 150ms;
  --duration-normal: 200ms;
  --easing-default: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ----- Reset ----- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

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

body {
  font: 400 14px/1.5 var(--font-family);
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font-family: inherit;
  border: none;
  background: none;
  cursor: pointer;
  color: inherit;
}

input, textarea, select {
  font-family: inherit;
  border: none;
  outline: none;
}

ul {
  list-style: disc;
  padding-left: 20px;
}

/* ----- 自定义滚动条 ----- */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

/* ============================================================
   布局 — 三栏固定
   ============================================================ */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ----- 左侧栏 ----- */
.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-content {
  flex: 1;
  padding: var(--space-4);
}

.logo-area {
  margin-bottom: var(--space-6);
}

.logo-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.logo-subtitle {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-top: var(--space-1);
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 40px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 400;
  color: var(--text-secondary);
  transition: background var(--duration-fast) var(--easing-default),
              color var(--duration-fast) var(--easing-default);
}

.nav-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.nav-item.active {
  color: var(--accent-primary);
  background: var(--accent-bg);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border-top: 1px solid var(--border-default);
  flex-shrink: 0;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--border-default);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  flex-shrink: 0;
}

.user-info {
  min-width: 0;
}

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

.user-role {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
}

/* ----- 中间主区域 ----- */
.main-area {
  flex: 1;
  min-width: 600px;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Tab 面板 */
.tab-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.tab-panel.active {
  display: flex;
}

/* 顶栏 */
.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--border-default);
  flex-shrink: 0;
}

.main-title {
  font-size: 18px;
  font-weight: 500;
  color: var(--text-primary);
}

.main-timestamp {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

/* ----- 消息区 ----- */
.message-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.message {
  max-width: 80%;
}

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

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

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

.assistant-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--accent-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.message-sender {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.message-time {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.message-bubble {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  line-height: 1.5;
}

.assistant-bubble {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.assistant-bubble p {
  margin-bottom: var(--space-2);
}

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

.assistant-bubble ul {
  margin: var(--space-2) 0;
}

.assistant-bubble li {
  margin-bottom: var(--space-1);
}

.assistant-bubble strong {
  color: var(--accent-primary);
}

.user-bubble {
  background: rgba(12, 211, 160, 0.15);
  color: var(--text-primary);
}

/* 输入区 */
.input-area {
  padding: var(--space-4);
  flex-shrink: 0;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  transition: border-color var(--duration-fast) var(--easing-default);
}

.input-wrapper:focus-within {
  border-color: var(--accent-primary);
}

.chat-input {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  padding: var(--space-3) var(--space-4);
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  overflow-y: auto;
}

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

.send-btn {
  width: 36px;
  height: 36px;
  margin: var(--space-1);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--accent-primary);
  color: var(--text-primary);
  transition: background var(--duration-fast) var(--easing-default);
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--accent-hover);
}

.send-btn:active {
  background: var(--accent-active);
}

/* ----- 历史记录 ----- */
.history-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.history-item {
  display: flex;
  align-items: center;
  height: 36px;
  padding: 0 var(--space-4);
  border-radius: 6px;
  gap: var(--space-2);
  transition: background var(--duration-fast) var(--easing-default);
  cursor: pointer;
}

.history-item:hover {
  background: var(--bg-elevated);
}

.history-date {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  flex-shrink: 0;
}

.history-desc {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 状态圆点 */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.status-success {
  background: var(--status-success);
}

.status-warning {
  background: var(--status-warning);
}

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

/* ----- Wetlab 表单 ----- */
.wetlab-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
}

.wetlab-form {
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

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

.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-input {
  height: 40px;
  padding: 0 var(--space-3);
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color var(--duration-fast) var(--easing-default);
}

.form-input:focus {
  border-color: var(--accent-primary);
}

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

.form-textarea {
  min-height: 80px;
  padding: var(--space-3);
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  resize: vertical;
  transition: border-color var(--duration-fast) var(--easing-default);
}

.form-textarea:focus {
  border-color: var(--accent-primary);
}

.form-textarea::placeholder {
  color: var(--text-placeholder);
}

.form-select {
  height: 36px;
  padding: 0 var(--space-3);
  background: var(--bg-dropdown);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238B9BB4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  transition: border-color var(--duration-fast) var(--easing-default);
}

.form-select:focus {
  border-color: var(--accent-primary);
}

.form-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.file-upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 120px;
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--easing-default);
}

.file-upload-area:hover {
  border-color: var(--border-hover);
}

.file-upload-area span {
  font-size: 12px;
  color: var(--text-placeholder);
}

.file-input {
  display: none;
}

/* ----- 搜索 ----- */
.search-content {
  flex: 1;
  padding: var(--space-4);
}

.search-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 0 var(--space-3);
  height: 40px;
  transition: border-color var(--duration-fast) var(--easing-default);
}

.search-bar:focus-within {
  border-color: var(--accent-primary);
}

.search-input {
  flex: 1;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
}

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

/* ----- 分享 ----- */
.share-content {
  flex: 1;
  padding: var(--space-4);
}

.text-secondary {
  color: var(--text-secondary);
  font-size: 14px;
}

/* ----- 工作台 ----- */
.dashboard-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
}

.stat-card {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  text-align: center;
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: var(--space-1);
}

.section-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: var(--space-3);
}

.pipeline-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.pipeline-tag {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
}

/* ----- 报告中心 ----- */
.reports-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.reports-toolbar {
  display: flex;
  gap: var(--space-3);
  align-items: center;
}

.reports-toolbar .search-bar {
  flex: 1;
}

.reports-toolbar .form-select {
  width: 140px;
  flex-shrink: 0;
}

.reports-table {
  width: 100%;
  border-collapse: collapse;
}

.reports-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--border-default);
}

.reports-table td {
  font-size: 14px;
  color: var(--text-primary);
  padding: var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--border-default);
}

.reports-table tbody tr:hover {
  background: var(--bg-elevated);
}

.format-badge {
  display: inline-block;
  padding: var(--space-1) var(--space-2);
  background: var(--accent-bg);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-primary);
}

/* ----- 按钮 ----- */
.btn-primary {
  height: 36px;
  padding: 0 var(--space-4);
  background: var(--accent-primary);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--duration-fast) var(--easing-default);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:active {
  background: var(--accent-active);
}

.btn-primary:disabled {
  background: var(--border-default);
  color: var(--text-placeholder);
  cursor: not-allowed;
}

.btn-ghost {
  height: 32px;
  padding: 0 var(--space-3);
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 400;
  border-radius: var(--radius-md);
  transition: background var(--duration-fast) var(--easing-default),
              color var(--duration-fast) var(--easing-default);
}

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

.btn-sm {
  height: 28px;
  font-size: 12px;
  padding: 0 var(--space-2);
}

/* ============================================================
   右侧面板
   ============================================================ */
.right-panel {
  width: 320px;
  flex-shrink: 0;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-scroll {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
}

.panel-header {
  margin-bottom: var(--space-4);
}

.panel-title {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.panel-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: var(--space-1);
}

/* 步骤列表 */
.steps-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.step-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  padding: var(--space-3) var(--space-4);
  background: transparent;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  text-align: left;
  transition: border-color var(--duration-fast) var(--easing-default),
              background var(--duration-fast) var(--easing-default);
}

.step-card:hover {
  border-color: var(--border-hover);
}

.step-card.selected {
  border-color: var(--accent-primary);
  background: var(--accent-bg-light);
}

.step-number {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-default);
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  flex-shrink: 0;
}

.step-card.selected .step-number {
  border-color: var(--accent-primary);
  background: var(--accent-bg);
  color: var(--accent-primary);
}

.step-info {
  flex: 1;
  min-width: 0;
}

.step-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.step-detail {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.step-count {
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

/* 分割线 */
.panel-divider {
  height: 1px;
  background: var(--border-default);
  margin: var(--space-4) 0;
}

/* 配置区 */
.config-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.config-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

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

/* 复选框 */
.config-checkbox {
  margin-top: var(--space-1);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-primary);
}

.checkbox-label input[type="checkbox"] {
  display: none;
}

.checkbox-custom {
  width: 16px;
  height: 16px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--duration-fast) var(--easing-default),
              border-color var(--duration-fast) var(--easing-default);
}

.checkbox-label input[type="checkbox"]:checked + .checkbox-custom {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

.checkbox-label input[type="checkbox"]:checked + .checkbox-custom::after {
  content: "";
  display: block;
  width: 8px;
  height: 5px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
}

/* 统计栏 */
.panel-stats {
  margin-top: var(--space-4);
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
}

.panel-stats strong {
  color: var(--accent-primary);
}

/* 启动按钮 */
.btn-launch {
  margin-top: var(--space-4);
  width: 100%;
}

/* ----- 面板切换按钮（小屏）----- */
.panel-toggle {
  display: none;
  position: fixed;
  bottom: var(--space-4);
  right: var(--space-4);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--accent-primary);
  color: var(--text-primary);
  align-items: center;
  justify-content: center;
  z-index: 100;
  box-shadow: none;
}

/* ============================================================
   Typing indicator
   ============================================================ */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: var(--space-3) var(--space-4);
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--text-secondary);
  animation: typing-bounce 1.4s infinite ease-in-out;
}

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

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

@keyframes typing-bounce {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ============================================================
   Loading spinner
   ============================================================ */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-default);
  border-top-color: var(--accent-primary);
  border-radius: var(--radius-full);
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   消息入场动画
   ============================================================ */
.message-enter {
  animation: message-enter var(--duration-normal) var(--easing-default) both;
}

@keyframes message-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================================
   响应式 — 小屏折叠右侧面板
   ============================================================ */
@media (max-width: 1366px) {
  .right-panel {
    position: fixed;
    right: 0;
    top: 0;
    height: 100vh;
    z-index: 50;
    transform: translateX(100%);
    transition: transform var(--duration-normal) var(--easing-default);
  }

  .right-panel.open {
    transform: translateX(0);
  }

  .panel-toggle {
    display: flex;
  }

  .main-area {
    min-width: 0;
  }
}

/* ============================================================
   Drawer overlay（小屏面板遮罩）
   ============================================================ */
.panel-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
}

.panel-overlay.visible {
  display: block;
}
