:root {
  --bg-dark: #0f1117;
  --bg-card: #181b24;
  --bg-card-hover: #212634;
  --bg-input: #12151e;
  --border-color: #2b3245;
  --border-highlight: #3b82f6;
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  
  --primary: #3b82f6;
  --primary-glow: rgba(59, 130, 246, 0.35);
  --accent-cyan: #06b6d4;
  --accent-green: #10b981;
  --accent-yellow: #f59e0b;
  --accent-red: #ef4444;
  --accent-purple: #8b5cf6;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --shadow-card: 0 8px 24px rgba(0, 0, 0, 0.4);
  --font-main: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Fira Code', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  line-height: 1.5;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  padding: 0 16px 32px;
}

/* ================= Navbar ================= */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 16px;
  gap: 16px;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 2rem;
  filter: drop-shadow(0 0 10px var(--primary-glow));
}

.brand-name {
  font-size: 1.35rem;
  font-weight: 900;
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-tag {
  font-size: 0.72rem;
  background: linear-gradient(135deg, #ec4899, #8b5cf6);
  color: #fff;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-weight: 700;
}

.brand-slogan {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.server-status-pill {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  gap: 8px;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-dot.online {
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}

.divider {
  opacity: 0.3;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.token-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent-yellow);
}

.token-value {
  font-family: var(--font-mono);
  font-size: 1rem;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.user-pill:hover {
  border-color: var(--primary);
  background: var(--bg-card-hover);
}

.edit-hint {
  font-size: 0.75rem;
  opacity: 0.6;
}

/* ================= Tab Bar ================= */
.tab-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  background: rgba(0, 0, 0, 0.2);
  padding: 6px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.tab-sub {
  font-size: 0.7rem;
  opacity: 0.8;
  font-weight: 400;
}

.tab-badge {
  background: var(--accent-red);
  color: #fff;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-weight: 700;
  animation: pulse 2s infinite;
}

/* ================= Tab Panes ================= */
.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
  animation: fadeIn 0.25s ease-out;
}

/* ================= Common Cards ================= */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
}

/* ================= TAB 1: ASK AI ================= */
.ask-layout {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.ask-control-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.model-select-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.form-group-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.custom-select {
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  outline: none;
  cursor: pointer;
}

.prompt-type-toggle {
  display: flex;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  padding: 3px;
  border: 1px solid var(--border-color);
}

.type-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

.type-btn.active {
  background: var(--border-color);
  color: var(--text-main);
}

.prompt-input-wrapper {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 14px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-family: inherit;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}

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

.prompt-action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.quick-samples {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.sample-label {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.sample-chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}

.sample-chip:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover {
  background: #2563eb;
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-success {
  background: var(--accent-green);
  color: #fff;
}

.btn-success:hover {
  background: #059669;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  color: var(--accent-red);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 12px 28px;
  font-size: 1rem;
}

/* Chat View */
.chat-view-card {
  min-height: 280px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.6;
}

.empty-state h3 {
  font-size: 1.15rem;
  margin-bottom: 8px;
}

.empty-state p {
  color: var(--text-muted);
  font-size: 0.88rem;
  max-width: 500px;
  margin: 0 auto 16px;
}

.mechanism-tip {
  display: inline-block;
  background: rgba(6, 182, 212, 0.1);
  border: 1px solid rgba(6, 182, 212, 0.25);
  color: var(--accent-cyan);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
}

/* Active Session */
.active-session {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.session-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
}

.session-status-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pulse-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-yellow);
  animation: pulse 1.5s infinite;
}

.message-bubble {
  padding: 16px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-message {
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.ai-message {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
}

.bubble-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
}

.meta-role {
  font-weight: 700;
  color: var(--text-main);
}

.meta-time {
  color: var(--text-dim);
}

.meta-tag {
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  color: var(--accent-cyan);
}

.live-stream-tag {
  color: var(--accent-red);
  font-weight: 700;
  font-size: 0.75rem;
  animation: pulse 1s infinite;
}

.bubble-content {
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.image-response-container {
  margin-top: 12px;
  text-align: center;
  background: #000;
  border-radius: var(--radius-md);
  padding: 10px;
  border: 1px solid var(--border-color);
}

.image-response-container img {
  max-width: 100%;
  max-height: 400px;
  border-radius: var(--radius-sm);
}

/* Typing indicator */
.typing-placeholder {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.88rem;
}

.dot-typing {
  position: relative;
  width: 6px;
  height: 6px;
  border-radius: 5px;
  background-color: var(--accent-cyan);
  animation: dotTyping 1.5s infinite linear;
}

/* RLHF Rating */
.rlhf-panel {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px dashed var(--border-color);
}

.rlhf-title {
  font-size: 0.85rem;
  color: var(--accent-yellow);
  margin-bottom: 10px;
  font-weight: 600;
}

.rlhf-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.rlhf-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.rlhf-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-2px);
}

.rlhf-good:hover {
  border-color: var(--accent-green);
  color: var(--accent-green);
}

.rlhf-robot:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.rlhf-slop:hover {
  border-color: var(--accent-yellow);
  color: var(--accent-yellow);
}

/* ================= TAB 2: WORKER ================= */
.work-layout {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.lobby-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.lobby-title-group h3 {
  font-size: 1.25rem;
  margin-bottom: 4px;
}

.lobby-title-group p {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.task-queue-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty-queue-tip {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.tip-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
}

.task-card-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  padding: 14px 18px;
  border-radius: var(--radius-md);
  gap: 16px;
  transition: all 0.2s;
}

.task-card-item:hover {
  border-color: var(--accent-cyan);
  background: var(--bg-card-hover);
}

.task-info-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.task-meta-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.task-type-badge {
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-cyan);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-weight: 600;
}

.task-prompt-snippet {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-main);
}

/* Workbench */
.workbench-card {
  border: 2px solid var(--accent-cyan);
  box-shadow: 0 0 30px rgba(6, 182, 212, 0.15);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.workbench-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 14px;
}

.worker-task-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.task-badge {
  background: var(--accent-purple);
  color: #fff;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 700;
}

.asker-name-tag {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.timer-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.timer-countdown {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent-yellow);
}

.timer-bar-wrap {
  width: 100px;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.timer-bar {
  width: 100%;
  height: 100%;
  background: var(--accent-yellow);
  transition: width 1s linear;
}

.worker-prompt-display {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  padding: 16px;
  border-radius: var(--radius-md);
}

.prompt-label {
  font-size: 0.78rem;
  color: var(--accent-cyan);
  margin-bottom: 6px;
  font-weight: 600;
}

.prompt-text-large {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
}

.cliche-bar {
  margin-bottom: 10px;
}

.cliche-title {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  display: block;
}

.cliche-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cliche-btn {
  background: rgba(139, 92, 246, 0.15);
  border: 1px solid rgba(139, 92, 246, 0.3);
  color: #c4b5fd;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}

.cliche-btn:hover {
  background: rgba(139, 92, 246, 0.3);
  color: #fff;
}

/* Canvas Editor */
.worker-canvas-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-input);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  flex-wrap: wrap;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}

.tool-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.canvas-wrapper {
  background: #111;
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  justify-content: center;
  padding: 10px;
}

canvas {
  background: #1a1a24;
  border-radius: var(--radius-sm);
  cursor: crosshair;
  touch-action: none;
}

.canvas-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}

.workbench-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
}

.reward-hint {
  font-size: 0.88rem;
  color: var(--accent-green);
}

/* ================= TAB 3: GALLERY ================= */
.gallery-layout {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.gallery-header-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.gallery-title-box h2 {
  font-size: 1.3rem;
  margin-bottom: 4px;
}

.gallery-title-box p {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.gallery-filter-bar {
  display: flex;
  gap: 6px;
  background: var(--bg-input);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.filter-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  cursor: pointer;
}

.filter-btn.active {
  background: var(--border-color);
  color: var(--text-main);
  font-weight: 600;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 18px;
}

.gallery-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: transform 0.2s, border-color 0.2s;
}

.gallery-card:hover {
  transform: translateY(-3px);
  border-color: var(--primary);
}

.gallery-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.gallery-rating-pill {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-yellow);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-weight: 600;
}

.gallery-prompt {
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  border-left: 3px solid var(--primary);
  padding-left: 10px;
}

.gallery-response {
  background: var(--bg-input);
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 0.88rem;
  color: var(--text-main);
  line-height: 1.6;
  white-space: pre-wrap;
  max-height: 220px;
  overflow-y: auto;
}

.gallery-response img {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.gallery-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-dim);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding-top: 8px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 420px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.close-modal-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.modal-body input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  margin-top: 8px;
  outline: none;
}

.modal-body input:focus {
  border-color: var(--primary);
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--primary);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  color: var(--text-main);
  box-shadow: var(--shadow-card);
  animation: slideIn 0.3s ease-out;
}

.toast.success {
  border-left-color: var(--accent-green);
}

.toast.error {
  border-left-color: var(--accent-red);
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(50px); }
  to { opacity: 1; transform: translateX(0); }
}

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

@keyframes dotTyping {
  0% { transform: scale(1); }
  50% { transform: scale(1.6); }
  100% { transform: scale(1); }
}

/* Responsive */
@media (max-width: 768px) {
  .navbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .nav-right {
    width: 100%;
    justify-content: space-between;
  }
  .tab-title {
    font-size: 0.85rem;
  }
  .tab-sub {
    display: none;
  }
  .model-select-bar {
    flex-direction: column;
    align-items: stretch;
  }
}
