/*
 * Market Bot - Application Styles
 */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: #333;
  background: #f5f5f5;
  line-height: 1.5;
}

/* Navbar */
.navbar {
  background: #1a1a2e;
  color: white;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 32px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand a { color: white; text-decoration: none; font-weight: 700; font-size: 16px; }
.nav-links { display: flex; gap: 4px; }
.nav-links a {
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  transition: background 0.15s;
}
.nav-links a:hover { background: rgba(255,255,255,0.1); color: white; }

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

/* Flash */
.flash { padding: 12px 24px; font-size: 14px; }
.flash-notice { background: #d4edda; color: #155724; border-bottom: 1px solid #c3e6cb; }
.flash-alert { background: #f8d7da; color: #721c24; border-bottom: 1px solid #f5c6cb; }

/* Page Header */
.page-header { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.page-header h1 { font-size: 24px; font-weight: 700; flex: 1; }
.subtitle { color: #666; font-size: 14px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center;
  padding: 8px 16px; border-radius: 6px; border: 1px solid transparent;
  cursor: pointer; font-size: 14px; font-weight: 500; text-decoration: none;
  transition: all 0.15s;
}
.btn-primary { background: #4f46e5; color: white; border-color: #4f46e5; }
.btn-primary:hover { background: #4338ca; }
.btn-secondary { background: white; color: #333; border-color: #ddd; }
.btn-secondary:hover { background: #f5f5f5; }
.btn-danger { background: #dc3545; color: white; border-color: #dc3545; }
.btn-danger:hover { background: #c82333; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.stat-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.stat-card.stat-active { border: 2px solid #4f46e5; }
.stat-number { font-size: 32px; font-weight: 700; color: #4f46e5; }
.stat-label { font-size: 12px; color: #666; margin-top: 4px; }

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 768px) { .dashboard-grid { grid-template-columns: 1fr; } }

/* Section */
.section { background: white; border-radius: 12px; padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-header h2 { font-size: 18px; font-weight: 600; }

/* Status Badges */
.status-badge {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 600;
}
.status-pending { background: #e9ecef; color: #666; }
.status-scraping { background: #cff4fc; color: #055160; }
.status-completed { background: #d1e7dd; color: #0a3622; }
.status-failed { background: #f8d7da; color: #58151c; }

/* Keyword Row */
.keyword-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border-radius: 8px; margin-bottom: 8px;
  background: #fafafa; border: 1px solid #eee;
  flex-wrap: wrap;
}
.keyword-row:hover { background: #f0f0f0; }
.keyword-info { display: flex; align-items: center; gap: 8px; flex: 1; }
.keyword-term { font-weight: 600; font-size: 15px; }
.keyword-meta { display: flex; gap: 12px; color: #666; font-size: 12px; }
.keyword-actions { display: flex; gap: 6px; }
.error-message { width: 100%; color: #dc3545; font-size: 12px; padding: 4px 0; }

/* App Grid */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/* App Card */
.app-card {
  background: white; border-radius: 12px; padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  display: flex; gap: 12px;
  transition: box-shadow 0.15s;
}
.app-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.app-icon { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; flex-shrink: 0; }
.app-icon-placeholder { width: 56px; height: 56px; border-radius: 12px; background: #e9ecef; display: flex; align-items: center; justify-content: center; font-size: 24px; flex-shrink: 0; }
.app-info { flex: 1; min-width: 0; }
.app-title { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.app-title a { text-decoration: none; color: inherit; }
.app-title a:hover { color: #4f46e5; }
.app-developer { font-size: 12px; color: #666; margin-bottom: 6px; }
.app-metrics { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.metric { font-size: 12px; color: #555; }
.app-footer { display: flex; gap: 6px; align-items: center; }
.app-category { font-size: 11px; color: #888; background: #f0f0f0; padding: 2px 6px; border-radius: 4px; }

/* App Detail */
.app-detail { background: white; border-radius: 12px; padding: 24px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin-bottom: 24px; }
.app-detail-header { display: flex; gap: 20px; margin-bottom: 24px; }
.app-icon-large { width: 96px; height: 96px; border-radius: 20px; object-fit: cover; flex-shrink: 0; }
.app-icon-placeholder-large { width: 96px; height: 96px; border-radius: 20px; background: #e9ecef; display: flex; align-items: center; justify-content: center; font-size: 40px; flex-shrink: 0; }
.app-detail-info h1 { font-size: 22px; margin-bottom: 4px; }
.developer { color: #666; margin-bottom: 12px; }
.app-metrics-large { display: flex; gap: 20px; margin-bottom: 12px; flex-wrap: wrap; }
.metric-item { text-align: center; }
.metric-value { display: block; font-size: 18px; font-weight: 700; color: #333; }
.metric-label { display: block; font-size: 11px; color: #888; }
.app-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.price-badge { background: #e8f5e9; color: #2e7d32; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.ads-badge { background: #fff3e0; color: #e65100; padding: 2px 8px; border-radius: 12px; font-size: 11px; }
.app-actions { display: flex; gap: 8px; }
.description { color: #444; line-height: 1.7; }
.keyword-tags { display: flex; gap: 8px; flex-wrap: wrap; }
.keyword-tag { background: #ede9fe; color: #5b21b6; padding: 4px 12px; border-radius: 16px; text-decoration: none; font-size: 13px; }
.keyword-tag:hover { background: #ddd6fe; }

/* Rating Distribution */
.rating-distribution { display: flex; flex-direction: column; gap: 6px; max-width: 360px; }
.rating-bar { display: flex; align-items: center; gap: 8px; }
.star-label { width: 24px; text-align: right; font-size: 12px; color: #555; }
.bar-bg { flex: 1; height: 12px; background: #e9ecef; border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: #ffc107; border-radius: 6px; transition: width 0.3s; }
.bar-count { width: 28px; font-size: 12px; color: #666; }

/* Reviews */
.review-card {
  padding: 16px; border-bottom: 1px solid #eee;
}
.review-card:last-child { border-bottom: none; }
.review-header { display: flex; justify-content: space-between; margin-bottom: 6px; align-items: center; }
.review-author-info { display: flex; align-items: center; gap: 8px; }
.review-author { font-weight: 600; font-size: 13px; }
.review-stars { color: #ffc107; font-size: 13px; }
.review-date { font-size: 12px; color: #888; }
.review-title { font-size: 13px; margin-bottom: 4px; }
.review-text { color: #555; font-size: 13px; line-height: 1.6; }

/* Filter Bar */
.filter-bar { display: flex; gap: 6px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.filter-btn { padding: 4px 12px; border-radius: 16px; text-decoration: none; font-size: 13px; background: #f0f0f0; color: #555; border: 1px solid #ddd; }
.filter-btn:hover { background: #e0e0e0; }
.filter-btn.active { background: #4f46e5; color: white; border-color: #4f46e5; }

/* Form */
.form-container { max-width: 480px; }
.keyword-form { background: white; padding: 24px; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.form-input { width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 6px; font-size: 14px; }
.form-input:focus { outline: none; border-color: #4f46e5; box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
.field-hint { font-size: 12px; color: #888; margin-top: 4px; }
.actions { display: flex; gap: 8px; margin-top: 20px; }
.errors { background: #f8d7da; color: #721c24; padding: 12px; border-radius: 6px; margin-bottom: 16px; }

/* Empty State */
.empty-state { text-align: center; padding: 40px; color: #888; }
.empty-state a { color: #4f46e5; }

/* Link More */
.link-more { display: block; text-align: right; color: #4f46e5; text-decoration: none; font-size: 13px; margin-top: 8px; }

/* App List */
.app-list { display: flex; flex-direction: column; gap: 8px; }

/* ===== Keyword Analysis Page ===== */
.analysis-section { margin-bottom: 24px; }

/* Analysis Table */
.analysis-table-wrap { overflow-x: auto; }
.analysis-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.analysis-table thead { border-bottom: 2px solid #e9ecef; }
.analysis-table th {
  text-align: left; padding: 10px 8px;
  font-weight: 600; color: #555; font-size: 12px; white-space: nowrap;
}
.analysis-table td {
  padding: 10px 8px; border-bottom: 1px solid #f0f0f0; vertical-align: middle;
}
.analysis-table tbody tr:hover { background: #fafafe; }
.analysis-table .col-rank { width: 36px; text-align: center; color: #888; }
.analysis-table .col-rating { white-space: nowrap; }
.analysis-table .col-votes,
.analysis-table .col-installs,
.analysis-table .col-reviews { text-align: right; }

.table-app-cell { display: flex; align-items: center; gap: 8px; }
.table-app-cell a { text-decoration: none; color: #333; font-weight: 500; }
.table-app-cell a:hover { color: #4f46e5; }
.table-app-icon { width: 32px; height: 32px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.table-developer { display: block; font-size: 11px; color: #888; }

.star-color { color: #ffc107; }

/* AI Analysis Form */
.ai-analysis-form { margin-bottom: 20px; }
.ai-form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.ai-form-field { display: flex; flex-direction: column; gap: 4px; }
.ai-form-field label { font-size: 12px; font-weight: 600; color: #555; }
.ai-form-field select { min-width: 260px; }
.ai-form-actions { display: flex; align-items: flex-end; gap: 8px; }
.ai-form-hint { font-size: 12px; color: #888; margin-top: 8px; }
.btn-ai-analyze { padding: 10px 24px; font-size: 14px; }

/* AI Results */
.ai-results-area { background: #f8f9fa; border-radius: 8px; padding: 24px; min-height: 80px; }
.ai-results-meta {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  font-size: 12px; color: #888; margin-bottom: 16px;
  padding-bottom: 12px; border-bottom: 1px solid #e9ecef;
}
.ai-results-content { color: #333; font-size: 14px; line-height: 1.8; }
.ai-results-content strong { color: #1a1a2e; }
.ai-results-placeholder-text { color: #999; font-size: 13px; text-align: center; }
.ai-error { background: #f8d7da; color: #721c24; padding: 12px; border-radius: 6px; font-size: 13px; }

/* Prompt Preview */
.ai-prompt-preview { background: #1a1a2e; color: #e0e0e0; border-radius: 8px; padding: 16px; margin-top: 16px; }
.ai-prompt-preview-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid #333;
}
.ai-prompt-preview-header strong { color: #a5b4fc; font-size: 13px; }
.ai-prompt-text {
  white-space: pre-wrap; word-break: break-word;
  font-size: 12px; line-height: 1.7; color: #d1d5db;
  max-height: 500px; overflow-y: auto; margin: 0;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
}

/* Analysis list */
.analyses-list { display: flex; flex-direction: column; gap: 12px; }
.analysis-card {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
  padding: 16px; transition: box-shadow 0.15s;
}
.analysis-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.analysis-card-header {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 8px;
}
.analysis-card-info { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.analysis-card-model { font-weight: 600; color: #1a1a2e; }
.analysis-card-date { color: #888; }
.analysis-card-actions { display: flex; gap: 6px; }
.analysis-card-preview {
  margin-top: 10px; padding-top: 10px; border-top: 1px solid #f0f0f0;
  font-size: 13px; color: #666; line-height: 1.6;
}
.analysis-detail {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 24px;
}
.btn-danger {
  background: #dc3545; color: #fff; border: none; cursor: pointer;
}
.btn-danger:hover { background: #c82333; }

/* Markdown body */
.markdown-body h1 { font-size: 1.5em; font-weight: 700; margin: 24px 0 12px; padding-bottom: 8px; border-bottom: 1px solid #eee; }
.markdown-body h2 { font-size: 1.3em; font-weight: 700; margin: 20px 0 10px; color: #1a1a2e; }
.markdown-body h3 { font-size: 1.1em; font-weight: 600; margin: 16px 0 8px; color: #333; }
.markdown-body p { margin: 8px 0; }
.markdown-body ul, .markdown-body ol { margin: 8px 0; padding-left: 24px; }
.markdown-body li { margin: 4px 0; }
.markdown-body strong { color: #1a1a2e; }
.markdown-body blockquote {
  margin: 12px 0; padding: 8px 16px;
  border-left: 3px solid #4f46e5; background: #f8f9fa; color: #555;
}
.markdown-body code {
  background: #f0f0f0; padding: 2px 6px; border-radius: 3px;
  font-size: 0.9em; font-family: "SF Mono", "Fira Code", monospace;
}
.markdown-body pre {
  background: #1a1a2e; color: #e0e0e0; padding: 16px;
  border-radius: 6px; overflow-x: auto; margin: 12px 0;
}
.markdown-body pre code { background: none; padding: 0; color: inherit; }
.markdown-body table { border-collapse: collapse; width: 100%; margin: 12px 0; }
.markdown-body th, .markdown-body td {
  border: 1px solid #ddd; padding: 8px 12px; text-align: left; font-size: 13px;
}
.markdown-body th { background: #f8f9fa; font-weight: 600; }
.markdown-body hr { border: none; border-top: 1px solid #eee; margin: 20px 0; }

/* Review app badge */
.review-app-badge {
  background: #ede9fe; color: #5b21b6;
  padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 500; white-space: nowrap;
}

/* Filter divider & load more */
.filter-divider { color: #ccc; margin: 0 2px; }
.load-more-hint {
  text-align: center; color: #888; font-size: 13px;
  padding: 16px 0; border-top: 1px solid #eee; margin-top: 8px;
}
