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

:root {
  /* Colors */
  --primary: #7c3aed;
  --primary-light: #ede9fe;
  --accent: #f43f5e;
  --accent-light: #fef2f2;
  
  --success: #10b981;
  --success-light: #ecfdf5;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --info: #0ea5e9;
  --info-light: #f0f9ff;
  
  /* Light Theme (Default) */
  --bg-body: #f9fafb;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f3f4f6;
  --bg-input: #f9fafb;
  
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
  
  /* Layout */
  --sidebar-width: 200px;
  
  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Dark Theme */
[data-theme="dark"] {
  --bg-body: #111827;
  --bg-sidebar: #1f2937;
  --bg-card: #1f2937;
  --bg-hover: #374151;
  --bg-input: #374151;
  
  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  
  --border: #374151;
  --border-light: #4b5563;
  
  --primary-light: rgba(124, 58, 237, 0.2);
  --success-light: rgba(16, 185, 129, 0.2);
  --warning-light: rgba(245, 158, 11, 0.2);
  --danger-light: rgba(239, 68, 68, 0.2);
  --info-light: rgba(14, 165, 233, 0.2);
  --accent-light: rgba(244, 63, 94, 0.2);
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-body);
  -webkit-font-smoothing: antialiased;
}

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

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  position: fixed;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.logo-icon {
  font-size: 24px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 6px;
  margin-bottom: 2px;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

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

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

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.theme-toggle:hover {
  color: var(--text-primary);
  border-color: var(--primary);
}

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 24px 32px;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

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

/* ===== VIEW HEADER ===== */
.view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.view-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.view-header h2 span {
  color: var(--accent);
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: #6d28d9;
}

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

.btn-secondary:hover {
  background: var(--border);
}

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

.btn-back {
  background: none;
  color: var(--text-secondary);
  padding: 8px 0;
}

.btn-back:hover {
  color: var(--text-primary);
}

/* ===== STATS GRID ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-card-highlight {
  border-color: var(--primary);
  background: var(--primary-light);
}

.stat-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-hover);
  border-radius: 8px;
  font-size: 18px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===== SECTIONS ===== */
.section {
  margin-bottom: 24px;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
}

/* ===== STATUS GRID ===== */
.status-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.status-grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.status-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}

.status-count {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.status-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.status-completed { border-color: var(--success); background: var(--success-light); }
.status-completed .status-count { color: var(--success); }

.status-running { border-color: var(--info); background: var(--info-light); }
.status-running .status-count { color: var(--info); }

.status-pending { border-color: var(--warning); background: var(--warning-light); }
.status-pending .status-count { color: var(--warning); }

.status-failed { border-color: var(--danger); background: var(--danger-light); }
.status-failed .status-count { color: var(--danger); }

/* ===== RESPONSE TYPES ===== */
.response-types-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.response-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}

.response-count {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.response-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.response-api { border-color: var(--primary); background: var(--primary-light); }
.response-api .response-count { color: var(--primary); }

.response-scraping { border-color: var(--info); background: var(--info-light); }
.response-scraping .response-count { color: var(--info); }

/* ===== FORM ELEMENTS ===== */
.search-input,
.filter-select {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  min-width: 140px;
  font-family: inherit;
}

.search-input:focus,
.filter-select:focus {
  outline: none;
  border-color: var(--primary);
}

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

.filter-select {
  cursor: pointer;
}

/* ===== BRANDS LIST (Card Style like Traqer) ===== */
.brands-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.brand-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.brand-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.brand-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
  overflow: hidden;
}

.brand-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

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

.brand-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-domain {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.brand-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.brand-stat {
  text-align: center;
}

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

.brand-stat-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.demo-badge {
  display: inline-block;
  padding: 2px 6px;
  background: var(--warning);
  color: white;
  font-size: 9px;
  font-weight: 600;
  border-radius: 4px;
  text-transform: uppercase;
}

/* ===== STATUS BADGE ===== */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 20px;
}

.status-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-badge.completed, .status-badge.completed {
  color: var(--success);
  background: var(--success-light);
}
.status-badge.completed::before, .status-badge.completed::before { background: var(--success); }

.status-badge.running {
  color: var(--info);
  background: var(--info-light);
}
.status-badge.running::before { background: var(--info); }

.status-badge.pending {
  color: var(--warning);
  background: var(--warning-light);
}
.status-badge.pending::before { background: var(--warning); }

.status-badge.failed {
  color: var(--danger);
  background: var(--danger-light);
}
.status-badge.failed::before { background: var(--danger); }

/* ===== PROGRESS BAR ===== */
.progress-container {
  width: 100px;
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}

.progress-fill.completed, .progress-fill.completed { background: var(--success); }
.progress-fill.running { background: var(--info); }
.progress-fill.pending { background: var(--warning); }
.progress-fill.failed { background: var(--danger); }

.progress-text {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  text-align: center;
}

/* ===== BRAND DETAIL ===== */
.brand-detail-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}

.brand-detail-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.brand-detail-avatar {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-secondary);
  overflow: hidden;
}

.brand-detail-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-detail-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-detail-link {
  font-size: 13px;
  color: var(--primary);
  text-decoration: none;
}

.brand-detail-link:hover {
  text-decoration: underline;
}

.brand-detail-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.detail-item {
  padding: 12px;
  background: var(--bg-hover);
  border-radius: 8px;
}

.detail-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.detail-value {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.timestamp-row {
  display: flex;
  gap: 24px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.timestamp-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.timestamp-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
}

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

.text-muted {
  color: var(--text-muted) !important;
  font-style: italic;
}

/* ===== STATS MINI GRID ===== */
.stats-mini-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.stat-mini-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}

.stat-mini-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-mini-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 2px;
}

/* ===== TOPICS LIST ===== */
.topics-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.topic-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

.topic-info h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.topic-info p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.topic-meta {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* ===== KEYWORDS LIST ===== */
.keywords-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.keyword-card {
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
}

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

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

.keyword-scores {
  display: flex;
  gap: 20px;
}

.score-item {
  text-align: center;
}

.score-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
}

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

/* ===== TABLE (for leads) ===== */
.table-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

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

.data-table th,
.data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg-hover);
}

.data-table td {
  font-size: 13px;
  color: var(--text-primary);
}

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

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* ===== PAGINATION ===== */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-top: 20px;
}

.page-btn {
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.page-btn:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}

.page-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-ellipsis {
  color: var(--text-muted);
  padding: 0 4px;
}

/* ===== LOADING ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.8);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

[data-theme="dark"] .loading-overlay {
  background: rgba(0,0,0,0.6);
}

.loading-overlay.active {
  display: flex;
}

.loader {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

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

.empty-state-small {
  text-align: center;
  padding: 16px;
  color: var(--text-muted);
  font-size: 12px;
}

/* ===== CLICKABLE CARDS ===== */
.clickable {
  cursor: pointer;
  transition: all 0.15s ease;
}

.clickable:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.status-card.clickable:hover {
  filter: brightness(0.95);
}

.response-card.clickable:hover {
  filter: brightness(0.95);
}

/* ===== SCHEDULED BRANDS SECTION ===== */
.scheduled-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

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

.scheduled-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-hover);
}

.scheduled-icon {
  font-size: 24px;
}

.scheduled-header h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.scheduled-header p {
  font-size: 12px;
  color: var(--text-muted);
  margin: 2px 0 0 0;
}

.scheduled-count {
  margin-left: auto;
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
}

.scheduled-list {
  max-height: 200px;
  overflow-y: auto;
}

.scheduled-brand-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background 0.15s ease;
}

.scheduled-brand-item:last-child {
  border-bottom: none;
}

.scheduled-brand-item:hover {
  background: var(--bg-hover);
}

.scheduled-brand-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.scheduled-brand-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.scheduled-brand-domain {
  font-size: 11px;
  color: var(--text-muted);
}

.scheduled-brand-time {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

.scheduled-more {
  text-align: center;
  padding: 8px;
  font-size: 12px;
  color: var(--primary);
  background: var(--bg-hover);
  cursor: pointer;
}

/* ===== BRANDS SUMMARY ===== */
.brands-summary {
  margin-bottom: 16px;
}

.brands-count {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ===== KEYWORD ACTIONS ===== */
.keyword-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.refresh-btn {
  font-size: 11px !important;
  padding: 4px 8px !important;
}

.btn-success {
  background: var(--success) !important;
  color: white !important;
  border-color: var(--success) !important;
}

/* ===== DEMO BADGE ===== */
.demo-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  color: var(--warning);
  background: var(--warning-light);
  border-radius: 4px;
  margin-left: 8px;
  text-transform: uppercase;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .stats-mini-grid { grid-template-columns: repeat(4, 1fr); }
  .scheduled-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .status-grid { grid-template-columns: repeat(2, 1fr); }
  .status-grid-2 { grid-template-columns: repeat(2, 1fr); }
  .brand-detail-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -100%;
    z-index: 100;
    transition: left 0.2s ease;
  }
  
  .sidebar.open { left: 0; }
  
  .main-content {
    margin-left: 0;
    padding: 16px;
  }
  
  .stats-mini-grid { grid-template-columns: repeat(3, 1fr); }
  
  .brand-meta { display: none; }
  
  .timestamp-row { flex-wrap: wrap; gap: 12px; }

  .header-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  .stats-grid,
  .status-grid,
  .response-types-grid { grid-template-columns: 1fr; }
  
  .brand-detail-grid { grid-template-columns: 1fr; }
  .stats-mini-grid { grid-template-columns: repeat(2, 1fr); }
}
