:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans SC', sans-serif;
  background: radial-gradient(circle at top right, #f0f6ff 0%, var(--gray-50) 50%, #eefcf9 100%);
  color: var(--gray-800);
  line-height: 1.6;
}

/* ========== Layout ========== */
.app-header {
  background: linear-gradient(180deg, #f9fcff 0%, #eef5ff 100%);
  border-bottom: 1px solid #cfe0ff;
  padding: 0 24px;
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

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

.app-header .logo .logo-img {
  width: 136px;
  height: 88px;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 2px 8px rgba(30, 84, 200, 0.25));
}

.app-header .logo .logo-text {
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 0.8px;
  line-height: 1;
  background: linear-gradient(90deg, #0b43b8 0%, #1e5ad1 52%, #25c9f5 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

.header-nav {
  display: flex;
  gap: 4px;
}

.header-nav button {
  background: none;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  color: #2756b4;
  transition: all 0.15s;
}

.header-nav button:hover { background: #e7f0ff; color: #0f3e93; }
.header-nav button.active {
  background: linear-gradient(90deg, #dbe9ff 0%, #d6f5ff 100%);
  color: #0f3e93;
  font-weight: 700;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-user {
  font-size: 14px;
  color: #2756b4;
  font-weight: 600;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

/* ========== Auth Pages ========== */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 60px);
}

.auth-card {
  background: white;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 420px;
}

.auth-card h2 {
  font-size: 24px;
  margin-bottom: 8px;
  color: var(--gray-900);
}

.auth-card p.subtitle {
  color: var(--gray-500);
  margin-bottom: 24px;
  font-size: 14px;
}

/* ========== Forms ========== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--gray-700);
}

.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
  transition: border-color 0.15s;
  outline: none;
}

.form-group input:focus, .form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline {
  background: white;
  border: 1px solid var(--gray-300);
  color: var(--gray-700);
}
.btn-outline:hover { background: var(--gray-50); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 14px;
  padding: 0;
}

.btn-link:hover { text-decoration: underline; }

/* ========== Cards ========== */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  margin-bottom: 16px;
  border: 1px solid #edf2ff;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-header h3 { font-size: 18px; }

/* ========== Stats Grid ========== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  text-align: center;
}

.stat-card .stat-value {
  font-size: 36px;
  font-weight: 700;
  color: var(--primary);
}

.stat-card .stat-label {
  font-size: 14px;
  color: var(--gray-500);
  margin-top: 4px;
}

.stat-card.success .stat-value { color: var(--success); }
.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.danger .stat-value { color: var(--danger); }

/* ========== Upload Zone ========== */
.upload-zone {
  border: 2px dashed var(--gray-300);
  border-radius: 12px;
  padding: 60px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: white;
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-zone svg {
  width: 48px;
  height: 48px;
  color: var(--gray-400);
  margin-bottom: 12px;
}

.upload-zone h3 { margin-bottom: 8px; color: var(--gray-700); }
.upload-zone p { color: var(--gray-500); font-size: 14px; }

.upload-progress {
  margin-top: 20px;
}

/* ========== Progress Bar ========== */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--gray-200);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar .fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
  background: var(--primary);
}

.progress-bar .fill.success { background: var(--success); }
.progress-bar .fill.danger { background: var(--danger); }

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--gray-500);
  margin-top: 6px;
}

/* ========== Task List ========== */
.task-item {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid #eef2ff;
  padding: 16px 20px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: box-shadow 0.15s;
}

.task-item:hover { box-shadow: var(--shadow-lg); }

.task-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
}

.task-icon.pending { background: var(--gray-100); }
.task-icon.processing { background: #dbeafe; }
.task-icon.completed { background: #d1fae5; }
.task-icon.failed { background: #fee2e2; }

.task-info { flex: 1; min-width: 0; }
.task-info .task-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.task-info .task-step {
  font-size: 13px;
  color: var(--gray-500);
  margin-top: 2px;
}

.task-progress { width: 200px; flex-shrink: 0; }
.task-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ========== Status Badge ========== */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-pending { background: var(--gray-100); color: var(--gray-600); }
.badge-processing { background: #dbeafe; color: #1e40af; }
.badge-completed { background: #d1fae5; color: #065f46; }
.badge-failed { background: #fee2e2; color: #991b1b; }

/* ========== Table ========== */
.table-wrap { overflow-x: auto; }

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

th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
  font-size: 14px;
}

th {
  font-weight: 600;
  color: var(--gray-600);
  background: var(--gray-50);
}

/* ========== Log viewer ========== */
.log-viewer {
  background: var(--gray-900);
  color: #e5e7eb;
  border-radius: var(--radius);
  padding: 16px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
  max-height: 400px;
  overflow-y: auto;
  line-height: 1.8;
}

.log-viewer .log-line { white-space: pre-wrap; word-break: break-all; }
.log-viewer .log-info { color: #93c5fd; }
.log-viewer .log-warn { color: #fbbf24; }
.log-viewer .log-error { color: #f87171; }
.log-viewer .log-time { color: var(--gray-500); }

/* ========== Tabs ========== */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--gray-200);
  margin-bottom: 24px;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: 10px 20px;
  font-size: 14px;
  cursor: pointer;
  color: var(--gray-500);
  transition: all 0.15s;
}

.tab-btn:hover { color: var(--gray-700); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* ========== Misc ========== */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--gray-400);
}

.empty-state svg { width: 64px; height: 64px; margin-bottom: 16px; }
.empty-state h3 { color: var(--gray-600); margin-bottom: 8px; }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--gray-800);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 9999;
  animation: slideIn 0.3s ease;
  box-shadow: var(--shadow-lg);
}

.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

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

.hidden { display: none !important; }

/* ========== Server Status ========== */
.server-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.server-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.server-dot.online { background: var(--success); }
.server-dot.offline { background: var(--danger); }

/* ========== Pipeline Stages ========== */
.pipeline-stages {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.stage-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 12px;
  background: var(--gray-50);
  border-radius: var(--radius);
  flex: 1;
  min-width: 140px;
}

.stage-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
}

.stage-dot.pending { background: var(--gray-300); }
.stage-dot.running { background: #3b82f6; animation: pulse 1.5s infinite; }
.stage-dot.success { background: var(--success); }
.stage-dot.failed { background: var(--danger); }
.stage-dot.retrying { background: var(--warning); animation: pulse 1.5s infinite; }

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

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

/* ========== Responsive ========== */
@media (max-width: 768px) {
  .container { padding: 16px; }
  .task-item { flex-wrap: wrap; }
  .task-progress { width: 100%; order: 3; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .header-nav { display: none; }
  .pipeline-stages { flex-direction: column; }
}
