/* ============================================================
   Ads Analytics Dashboard - Premium Dark Theme
   ============================================================ */

/* --- Reset & Base --- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #08080d;
  --bg-secondary: #0e0e16;
  --bg-card: #12121c;
  --bg-card-hover: #181826;
  --bg-elevated: #1a1a2e;

  --border-color: rgba(255, 255, 255, 0.06);
  --border-active: rgba(255, 255, 255, 0.12);

  --text-primary: #f0f0f5;
  --text-secondary: #8888a0;
  --text-muted: #55556a;

  --accent-meta: #3b82f6;
  --accent-meta-bg: rgba(59, 130, 246, 0.08);
  --accent-google: #34d399;
  --accent-google-bg: rgba(52, 211, 153, 0.08);
  --accent-shopify: #96bf48;
  --accent-shopify-bg: rgba(150, 191, 72, 0.08);

  --accent-purple: #a855f7;
  --accent-blue: #3b82f6;
  --accent-green: #22c55e;
  --accent-orange: #f59e0b;
  --accent-red: #ef4444;

  --gradient-meta: linear-gradient(135deg, #3b82f6, #8b5cf6);
  --gradient-google: linear-gradient(135deg, #34d399, #3b82f6);
  --gradient-ai: linear-gradient(135deg, #a855f7, #ec4899);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-elevated: 0 8px 40px rgba(0, 0, 0, 0.5);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* --- Loading --- */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  transition: opacity 0.4s, visibility 0.4s;
}

.loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent-purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  color: var(--text-secondary);
  font-size: 13px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* --- App Layout --- */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* --- Top Bar --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 28px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(20px);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 24px;
}

.logo h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.logo-highlight {
  background: var(--gradient-meta);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

.status-dot.offline {
  background: var(--accent-red);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

.status-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* AI Button */
.ai-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--gradient-ai);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font);
}

.ai-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(168, 85, 247, 0.3);
}

.ai-btn-icon {
  font-size: 16px;
}

/* --- Main Content --- */
.main {
  flex: 1;
  padding: 24px 28px;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
}

/* --- Toolbar --- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  padding: 16px 20px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}

.toolbar-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.preset-btn {
  padding: 7px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font);
}

.preset-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-active);
}

.preset-btn.active {
  background: var(--accent-purple);
  color: white;
  border-color: transparent;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.date-inputs {
  display: none;
  gap: 8px;
}

.date-inputs.visible {
  display: flex;
}

.date-field {
  display: flex;
  align-items: center;
  gap: 6px;
}

.date-field label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.date-field input {
  padding: 6px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 12px;
  font-family: var(--font);
  outline: none;
}

.date-field input:focus {
  border-color: var(--accent-purple);
}

.extract-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  background: var(--gradient-meta);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font);
}

.extract-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(59, 130, 246, 0.3);
}

.extract-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.extract-btn .btn-icon {
  font-size: 14px;
}

/* --- Period Info --- */
.period-info {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-secondary);
  font-size: 14px;
}

.period-info.hidden {
  display: none;
}

.period-info strong {
  color: var(--accent-blue);
}

/* --- Tabs Navigation --- */
.dashboard-tabs {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 1px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 600;
  padding: 10px 20px;
  cursor: pointer;
  position: relative;
  transition: var(--transition);
  font-family: var(--font);
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  color: var(--accent-meta);
}

.tab-btn::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 2px;
  background: transparent;
  transition: var(--transition);
}

.tab-btn.active::after {
  background: var(--accent-meta);
}

/* Tab Content */
.tab-content {
  display: none;
  animation: fadeIn 0.3s ease;
}

.tab-content.active {
  display: block;
}

/* --- Platform Sections --- */
.platforms-container {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.platform-section {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-color);
  padding: 24px;
  transition: var(--transition);
}

.platform-section:hover {
  border-color: var(--border-active);
}

/* Platform Header */
.platform-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.platform-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
}

.platform-badge.meta {
  background: var(--accent-meta-bg);
  border: 1px solid rgba(59, 130, 246, 0.15);
}

.platform-badge.google {
  background: var(--accent-google-bg);
  border: 1px solid rgba(52, 211, 153, 0.15);
}

.platform-badge.shopify {
  background: var(--accent-shopify-bg);
  border: 1px solid rgba(150, 191, 72, 0.15);
}

.platform-icon {
  font-size: 20px;
}

.platform-badge h2 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.platform-badge.meta h2 {
  color: var(--accent-meta);
}

.platform-badge.google h2 {
  color: var(--accent-google);
}

.platform-badge.shopify h2 {
  color: var(--accent-shopify);
}

/* --- Metrics Row --- */
.metrics-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.metric-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}

.metric-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-active);
  box-shadow: var(--shadow-card);
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}

.metric-card.accent-blue::before {
  background: var(--accent-blue);
}

.metric-card.accent-green::before {
  background: var(--accent-green);
}

.metric-card.accent-purple::before {
  background: var(--accent-purple);
}

.metric-card.accent-orange::before {
  background: var(--accent-orange);
}

.metric-card.accent-red::before {
  background: var(--accent-red);
}

.metric-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.metric-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.5px;
  line-height: 1;
}

.metric-value.small {
  font-size: 18px;
}

/* --- Ranking Section --- */
.ranking-section {
  margin-top: 4px;
}

.ranking-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.ranking-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.sort-select {
  padding: 6px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  outline: none;
}

.sort-select:focus {
  border-color: var(--accent-purple);
}

/* Ranking Table */
.ranking-table {
  width: 100%;
}

.ranking-table-header {
  display: grid;
  grid-template-columns: 40px 2fr repeat(4, 1fr);
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
}

.ranking-table-header span {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.ranking-table-header span:not(:first-child):not(:nth-child(2)) {
  text-align: right;
}

.ranking-row {
  display: grid;
  grid-template-columns: 40px 2fr repeat(4, 1fr);
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
  transition: var(--transition);
  align-items: center;
}

.ranking-row:hover {
  background: var(--bg-card-hover);
}

.ranking-row:last-child {
  border-bottom: none;
}

.ranking-position {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
}

.ranking-position.top {
  color: var(--accent-orange);
}

.ranking-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ranking-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: right;
}

.ranking-value.positive {
  color: var(--accent-green);
}

.ranking-value.negative {
  color: var(--accent-red);
}

/* --- Chat Drawer --- */
.chat-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 998;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
}

.chat-overlay.open {
  opacity: 1;
  visibility: visible;
}

.chat-drawer {
  position: fixed;
  top: 0;
  right: -420px;
  width: 420px;
  height: 100vh;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  z-index: 999;
  display: flex;
  flex-direction: column;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-elevated);
}

.chat-drawer.open {
  right: 0;
}

.chat-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-card);
}

.chat-drawer-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.agent-avatar {
  font-size: 28px;
}

.chat-drawer-title h3 {
  font-size: 15px;
  font-weight: 600;
}

.agent-status {
  font-size: 11px;
  color: var(--accent-green);
  font-weight: 500;
}

.chat-close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.chat-close-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* Chat Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 16px;
  gap: 12px;
}

.empty-icon {
  font-size: 40px;
}

.empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.empty-state p {
  font-size: 13px;
  color: var(--text-secondary);
  max-width: 280px;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  justify-content: center;
}

.quick-btn {
  padding: 8px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font);
}

.quick-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--accent-purple);
}

/* Messages */
.message {
  margin-bottom: 16px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.6;
  max-width: 90%;
}

.message.user .message-bubble {
  background: var(--gradient-meta);
  color: white;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
  font-size: 14px;
  font-weight: 700;
  margin: 12px 0 6px;
}

.message-bubble h1:first-child,
.message-bubble h2:first-child,
.message-bubble h3:first-child {
  margin-top: 0;
}

.message-bubble ul,
.message-bubble ol {
  padding-left: 20px;
  margin: 8px 0;
}

.message-bubble li {
  margin-bottom: 4px;
}

.message-bubble strong {
  color: var(--accent-blue);
}

.message-bubble code {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes bounce {

  0%,
  80%,
  100% {
    transform: scale(0.6);
    opacity: 0.4;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Chat Input */
.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-card);
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  transition: var(--transition);
}

.chat-input-wrapper:focus-within {
  border-color: var(--accent-purple);
}

.chat-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font);
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.5;
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--gradient-ai);
  color: white;
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.send-btn:hover {
  transform: scale(1.05);
}

/* --- Responsive --- */
@media (max-width: 1100px) {
  .metrics-row {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 768px) {
  .topbar {
    padding: 10px 16px;
  }

  .main {
    padding: 16px;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-presets {
    justify-content: center;
  }

  .toolbar-actions {
    justify-content: center;
    flex-wrap: wrap;
  }

  .metrics-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .ranking-table-header,
  .ranking-row {
    grid-template-columns: 30px 1.5fr repeat(4, 1fr);
    font-size: 11px;
  }

  .chat-drawer {
    width: 100%;
    right: -100%;
  }

  .platform-section {
    padding: 16px;
  }
}

@media (max-width: 480px) {
  .metrics-row {
    grid-template-columns: 1fr 1fr;
  }

  .ranking-table-header,
  .ranking-row {
    grid-template-columns: 24px 1fr repeat(2, 1fr);
  }

  .ranking-table-header span:nth-child(4),
  .ranking-table-header span:nth-child(5),
  .ranking-row>*:nth-child(4),
  .ranking-row>*:nth-child(5) {
    display: none;
  }
}

/* --- Utility --- */
.hidden {
  display: none !important;
}

/* Pulse animation for extract button when loading */
.extract-btn.loading {
  position: relative;
  pointer-events: none;
}

.extract-btn.loading::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}