:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: #1a2235;
  --bg-card-hover: #1f2a40;
  --border: #2a3550;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.3);
  --green: #10b981;
  --green-glow: rgba(16, 185, 129, 0.2);
  --red: #ef4444;
  --red-glow: rgba(239, 68, 68, 0.2);
  --yellow: #f59e0b;
  --purple: #8b5cf6;
  --cyan: #06b6d4;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

.app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-brand {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.sidebar-brand h1 {
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-brand .brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.sidebar-nav {
  list-style: none;
  padding: 0 8px;
}

.sidebar-nav li {
  margin-bottom: 2px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}

.sidebar-nav a:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.sidebar-nav a.active {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent);
}

.sidebar-nav .nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-nav .nav-section {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  padding: 16px 16px 6px;
  font-weight: 600;
}

.main-content {
  margin-left: 240px;
  flex: 1;
  padding: 24px 32px;
  min-height: 100vh;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.page-header h2 {
  font-size: 22px;
  font-weight: 700;
}

.page-header .page-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 32px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}

.header h1 {
  font-size: 24px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.header-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.formula-badge {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--cyan);
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  transition: border-color 0.2s;
}

.card:hover {
  border-color: rgba(59, 130, 246, 0.3);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title .icon { font-size: 16px; }

/* Grid Layouts */
.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

/* Stat Cards */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}

.stat-card.profit::before { background: linear-gradient(90deg, var(--green), var(--cyan)); }
.stat-card.roi::before { background: linear-gradient(90deg, var(--accent), var(--purple)); }
.stat-card.ctr::before { background: linear-gradient(90deg, var(--yellow), #fb923c); }
.stat-card.count::before { background: linear-gradient(90deg, var(--purple), #ec4899); }

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  font-family: var(--font-mono);
  line-height: 1;
}

.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--red); }
.stat-value.neutral { color: var(--accent); }

.stat-change {
  font-size: 12px;
  margin-top: 6px;
  font-family: var(--font-mono);
}

/* Control Panel */
.control-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}

.control-row {
  display: flex;
  gap: 16px;
  align-items: end;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-group label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.control-group input,
.control-group select {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
  min-width: 160px;
}

.control-group input:focus,
.control-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #2563eb);
  color: white;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: var(--bg-primary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.btn-green {
  background: linear-gradient(135deg, var(--green), #059669);
  color: white;
  box-shadow: 0 4px 12px var(--green-glow);
}

.btn-green:hover {
  transform: translateY(-1px);
}

/* Chart Container */
.chart-container {
  position: relative;
  height: 300px;
  width: 100%;
}

/* Results Table */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  background: var(--bg-primary);
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 11px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(42, 53, 80, 0.5);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
}

tbody tr:hover {
  background: var(--bg-card-hover);
}

.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font);
}

.tag-scale { background: rgba(16, 185, 129, 0.15); color: var(--green); }
.tag-keep { background: rgba(59, 130, 246, 0.15); color: var(--accent); }
.tag-watch { background: rgba(245, 158, 11, 0.15); color: var(--yellow); }
.tag-kill { background: rgba(239, 68, 68, 0.15); color: var(--red); }

/* Prompt Preview */
.prompt-cell {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font) !important;
  font-size: 12px !important;
  color: var(--text-secondary);
}

/* Loading */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Progress */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-primary);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 12px;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), var(--cyan));
  transition: width 0.5s ease;
}

/* Round Pills */
.round-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.round-pill {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: all 0.2s;
}

.round-pill:hover, .round-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Param Tag */
.param-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.param-tag {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent);
  font-family: var(--font-mono);
}

/* Responsive */
@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .app { padding: 16px; }
  .grid-4 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .control-row { flex-direction: column; }
  .header { flex-direction: column; gap: 12px; align-items: flex-start; }
}

/* Fade in animation */
.fade-in {
  animation: fadeIn 0.4s ease;
}

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

/* Trend indicator */
.trend-up::before { content: '▲ '; color: var(--green); }
.trend-down::before { content: '▼ '; color: var(--red); }
.trend-flat::before { content: '— '; color: var(--text-muted); }

/* Section divider */
.section-title {
  font-size: 18px;
  font-weight: 700;
  margin: 32px 0 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 14px;
  max-width: 400px;
  margin: 0 auto;
  line-height: 1.6;
}

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

.tab {
  padding: 12px 24px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab:hover { color: var(--text-primary); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Layer Tags */
.layer-tag {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
}
.layer-tag.gen { background: rgba(59, 130, 246, 0.15); color: var(--accent); }
.layer-tag.ads { background: rgba(139, 92, 246, 0.15); color: var(--purple); }
.layer-tag.page { background: rgba(6, 182, 212, 0.15); color: var(--cyan); }

.layer-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}
.layer-dot.gen { background: var(--accent); }
.layer-dot.ads { background: var(--purple); }
.layer-dot.page { background: var(--cyan); }

.param-tag.tag-ads {
  background: rgba(139, 92, 246, 0.1);
  color: var(--purple);
}
.param-tag.tag-page {
  background: rgba(6, 182, 212, 0.1);
  color: var(--cyan);
}

/* Lab Panel Layout */
.lab-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

.lab-grid-full {
  grid-column: 1 / -1;
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,0.15);
}

.panel-header h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-body {
  padding: 20px;
}

/* Insight Cards */
.insight-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color 0.2s;
}

.insight-card:hover {
  border-color: rgba(59, 130, 246, 0.3);
}

.insight-card .insight-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.insight-card .insight-value {
  font-size: 22px;
  font-weight: 700;
  font-family: var(--font-mono);
}

/* Priority Badge */
.priority {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
}

.priority-critical { background: rgba(239,68,68,0.15); color: var(--red); }
.priority-high { background: rgba(245,158,11,0.15); color: var(--yellow); }
.priority-medium { background: rgba(59,130,246,0.15); color: var(--accent); }
.priority-low { background: rgba(100,116,139,0.15); color: var(--text-muted); }

/* Status Badge */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
}

.status-todo { background: rgba(100,116,139,0.15); color: var(--text-muted); }
.status-in_progress { background: rgba(59,130,246,0.15); color: var(--accent); }
.status-done { background: rgba(16,185,129,0.15); color: var(--green); }
.status-running { background: rgba(139,92,246,0.15); color: var(--purple); }
.status-win { background: rgba(16,185,129,0.15); color: var(--green); }
.status-loss { background: rgba(239,68,68,0.15); color: var(--red); }

/* Action list */
.action-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.action-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: border-color 0.2s;
}

.action-item:hover {
  border-color: var(--border);
}

.action-item .action-title {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
}

.action-item .action-meta {
  font-size: 11px;
  color: var(--text-muted);
}

/* Mini table inside panels */
.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.mini-table th {
  text-align: left;
  padding: 8px 10px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.mini-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(42,53,80,0.3);
  font-family: var(--font-mono);
  font-size: 11px;
}

.mini-table tr:hover {
  background: var(--bg-card-hover);
}

/* Select/Input inside panels */
.panel-select, .panel-input {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font);
  margin-bottom: 10px;
}

.panel-select:focus, .panel-input:focus {
  border-color: var(--accent);
  outline: none;
}

/* Allocation bar */
.alloc-bar {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  margin: 8px 0;
}

.alloc-bar > div {
  height: 100%;
}

/* Responsive sidebar */
@media (max-width: 900px) {
  .sidebar { width: 60px; min-width: 60px; }
  .sidebar-brand h1, .sidebar-brand .brand-sub, .sidebar-nav .nav-section, .sidebar-nav a span:not(.nav-icon) { display: none; }
  .sidebar-nav a { justify-content: center; padding: 12px; }
  .main-content { margin-left: 60px; padding: 16px; }
}

/* Drawer */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
}
.drawer-overlay.open { display: block; }

.drawer {
  position: fixed;
  top: 0;
  right: -480px;
  width: 480px;
  max-width: 90vw;
  height: 100vh;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  z-index: 201;
  transition: right 0.25s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.drawer.open { right: 0; }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-header h3 { font-size: 15px; font-weight: 600; }

.drawer-body {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

.detail-row {
  margin-bottom: 14px;
}
.detail-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 600;
}
.detail-value {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.5;
}
.detail-value textarea {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 8px;
  font-size: 13px;
  font-family: var(--font);
  resize: vertical;
  min-height: 60px;
}
.detail-value textarea:focus { border-color: var(--accent); outline: none; }

/* Toast (keep at bottom) */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--green);
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  z-index: 9999;
  animation: fadeIn 0.3s ease;
}
