/* AppStoreStatistics - Main Styles */

:root {
    --primary: #007aff;
    --primary-dark: #0056b3;
    --secondary: #34c759;
    --danger: #ff3b30;
    --warning: #ff9500;
    --bg: #f5f7fa;
    --card-bg: #ffffff;
    --text: #1c1c1e;
    --text-muted: #8e8e93;
    --border: #e5e5ea;
    --radius: 12px;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --max-width: 1200px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.site-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.site-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}

.main-nav a {
    margin-left: 24px;
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    transition: color 0.2s;
}

.main-nav a:hover,
.main-nav a.active {
    color: var(--primary);
}

/* Hero */
.hero {
    text-align: center;
    padding: 48px 0 24px;
}

.hero h1 {
    font-size: 2.2rem;
    margin-bottom: 8px;
}

.hero p {
    color: var(--text-muted);
    font-size: 1.05rem;
}

/* Search */
.search-section {
    max-width: 700px;
    margin: 0 auto 32px;
}

.search-box {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

#searchInput {
    width: 100%;
    padding: 14px 16px;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 12px;
    outline: none;
    transition: border-color 0.2s;
}

#searchInput:focus {
    border-color: var(--primary);
}

.search-type-filters,
.device-filters {
    display: flex;
    gap: 20px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.search-type-filters label,
.device-filters label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    color: var(--text);
}

.search-type-filters input[type="radio"],
.device-filters input[type="radio"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
}

#searchBtn {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

#searchBtn:hover {
    background: var(--primary-dark);
}

.error-message {
    color: var(--danger);
    text-align: center;
    margin-top: 12px;
    font-size: 0.9rem;
}

/* Stats Bar */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

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

.stat-value {
    display: block;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Results */
.results-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 16px;
}

.results-header h2 {
    font-size: 1.3rem;
}

#resultsCount {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
}

.result-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    text-decoration: none;
    color: inherit;
    display: block;
}

.result-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}

.result-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.result-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    object-fit: cover;
    flex-shrink: 0;
}

.result-info h3 {
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 3px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.result-info .dev {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 1;
    line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.result-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.8rem;
}

.meta-badge {
    background: var(--bg);
    padding: 4px 8px;
    border-radius: 6px;
    color: var(--text-muted);
}

.meta-badge.rating {
    color: var(--warning);
}

/* App Detail */
.app-detail {
    padding: 24px 0;
}

.app-header {
    display: flex;
    gap: 20px;
    margin-bottom: 24px;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    flex-wrap: wrap;
}

.app-icon-large {
    width: 120px;
    height: 120px;
    border-radius: 22px;
    object-fit: cover;
    flex-shrink: 0;
}

.app-header-info {
    flex: 1;
    min-width: 200px;
}

.app-header-info h1 {
    font-size: 1.5rem;
    margin-bottom: 6px;
}

.developer {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 4px;
}

.genre {
    color: var(--primary);
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 14px;
}

.app-header-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.btn {
    display: inline-block;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
}

.btn:hover {
    opacity: 0.9;
}

.btn:active {
    transform: scale(0.97);
}

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

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

.btn-danger {
    background: var(--danger);
    color: #fff;
}

/* Detail Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.detail-stat .stat-value {
    font-size: 1.3rem;
}

/* Detail Sections */
.detail-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}

.detail-section h2 {
    font-size: 1.15rem;
    margin-bottom: 12px;
}

.section-help {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 14px;
}

.description-text {
    white-space: pre-wrap;
    line-height: 1.6;
    color: #333;
}

/* Keywords */
.keywords-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.keyword-tag {
    background: #e8f0fe;
    color: var(--primary-dark);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}

/* Screenshots */
.screenshots-container {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 8px;
}

.screenshots-container img {
    height: 280px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

/* Charts */
.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.chart-card {
    background: var(--bg);
    border-radius: 10px;
    padding: 16px;
}

.chart-card.wide {
    grid-column: 1 / -1;
}

.chart-card h3 {
    font-size: 0.95rem;
    margin-bottom: 10px;
    color: var(--text-muted);
    font-weight: 500;
}

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

.empty-state p {
    margin-bottom: 16px;
    font-size: 1.05rem;
}

/* Loading / Error */
.loading-state,
.error-state {
    text-align: center;
    padding: 80px 20px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

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

.error-state p {
    margin-bottom: 16px;
    color: var(--text-muted);
}

/* Recent Reviews */
.reviews-summary {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    align-items: flex-start;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.reviews-avg {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 80px;
}

.reviews-avg-score {
    font-size: 2.4rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.reviews-avg-stars {
    font-size: 1rem;
    color: var(--warning);
    letter-spacing: 1px;
}

.reviews-avg-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.reviews-dist {
    flex: 1;
    min-width: 160px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.reviews-dist-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.reviews-dist-star {
    font-size: 0.78rem;
    color: var(--text-muted);
    width: 22px;
    text-align: right;
    flex-shrink: 0;
}

.reviews-dist-bar-bg {
    flex: 1;
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}

.reviews-dist-bar {
    height: 100%;
    background: var(--warning);
    border-radius: 4px;
    transition: width 0.4s ease;
}

.reviews-dist-count {
    font-size: 0.78rem;
    color: var(--text-muted);
    width: 20px;
    flex-shrink: 0;
}

.reviews-sentiment {
    display: flex;
    gap: 16px;
    align-items: center;
}

.sentiment-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 14px;
    border-radius: 10px;
}

.sentiment-pos { background: #d4edda; }
.sentiment-neu { background: #fff3cd; }
.sentiment-neg { background: #f8d7da; }

.sentiment-value {
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1;
}

.sentiment-pos .sentiment-value { color: #1a5c2a; }
.sentiment-neu .sentiment-value { color: #856404; }
.sentiment-neg .sentiment-value { color: #842029; }

.sentiment-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.review-item {
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

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

.review-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.review-stars {
    color: var(--warning);
    font-size: 0.9rem;
    letter-spacing: 1px;
}

.review-version {
    font-size: 0.75rem;
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 10px;
    color: var(--text-muted);
}

.review-author {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-left: auto;
}

.review-title {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text);
}

.review-content {
    font-size: 0.88rem;
    color: #444;
    line-height: 1.5;
    white-space: pre-wrap;
}

/* Compare Page */
.compare-selector {
    max-width: 700px;
    margin: 0 auto 32px;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

.compare-dropdowns {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: end;
    gap: 16px;
    margin-bottom: 16px;
}

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

.compare-dropdown-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.compare-dropdown-group select {
    padding: 12px 14px;
    font-size: 0.95rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
}

.compare-dropdown-group select:focus {
    border-color: var(--primary);
}

.compare-vs {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-muted);
    padding-bottom: 14px;
    text-align: center;
}

.compare-grid {
    display: grid;
    grid-template-columns: 1fr 16px 1fr;
    gap: 0 16px;
}

.compare-spacer {
    border-left: 2px solid var(--border);
    margin: 0 auto;
}

/* Compare app headers */
.compare-headers {
    margin-bottom: 24px;
}

.compare-app-header {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    gap: 14px;
    align-items: flex-start;
}

.compare-app-icon {
    width: 72px;
    height: 72px;
    border-radius: 16px;
    object-fit: cover;
    flex-shrink: 0;
}

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

.compare-app-info h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
    line-height: 1.3;
}

.compare-app-link {
    color: var(--text);
    text-decoration: none;
}

.compare-app-link:hover {
    color: var(--primary);
}

/* Compare section */
.compare-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}

.compare-section-title {
    font-size: 1.1rem;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

/* Stats table */
.compare-stats-table {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.compare-stat-row {
    display: grid;
    grid-template-columns: 1fr 120px 1fr;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.compare-stat-row:last-child {
    border-bottom: none;
}

.compare-stat-cell {
    font-size: 0.95rem;
    font-weight: 500;
}

.compare-stat-a {
    text-align: right;
}

.compare-stat-b {
    text-align: left;
}

.compare-stat-label {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.compare-winner {
    color: var(--secondary);
    font-weight: 700;
}

/* Bar rows */
.compare-bars-row {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
    padding: 4px 0 6px;
}

.compare-bar-wrap {
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    justify-content: flex-end;
}

.compare-bar-wrap-b {
    justify-content: flex-start;
}

.compare-bar {
    height: 100%;
    border-radius: 4px;
    background: var(--primary);
    opacity: 0.5;
    transition: width 0.4s ease;
}

.compare-bar-winner {
    opacity: 1;
}

.compare-bar-a {
    background: #007aff;
}

.compare-bar-b {
    background: #34c759;
}

.compare-bar-center-label {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.compare-bar-suffix {
    color: var(--text-muted);
    font-weight: 400;
}

/* Keywords compare */
.compare-keywords-grid {
    margin-top: 12px;
    align-items: start;
}

.compare-keywords-col {
    align-content: flex-start;
}

.kw-shared {
    background: #d4edda;
    color: #1a5c2a;
}

.kw-unique-a {
    background: #ddeeff;
    color: #004499;
}

.kw-unique-b {
    background: #e6f9ed;
    color: #1a5c2a;
}

.kw-shared-legend,
.kw-unique-a-legend,
.kw-unique-b-legend {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    vertical-align: middle;
}

.kw-shared-legend { background: #d4edda; }
.kw-unique-a-legend { background: #ddeeff; }
.kw-unique-b-legend { background: #e6f9ed; }

@media (max-width: 600px) {
    .compare-dropdowns {
        grid-template-columns: 1fr;
    }
    .compare-vs {
        padding-bottom: 0;
        text-align: center;
    }
    .compare-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .compare-spacer {
        display: none;
    }
    .compare-stat-row {
        grid-template-columns: 1fr 90px 1fr;
    }
    .compare-bars-row {
        grid-template-columns: 1fr auto 1fr;
    }
}

/* Footer */
.site-footer {
    border-top: 1px solid var(--border);
    margin-top: 40px;
    padding: 24px 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Responsive */
@media (max-width: 600px) {
    .hero h1 {
        font-size: 1.6rem;
    }
    .app-header {
        flex-direction: column;
        text-align: center;
    }
    .app-icon-large {
        margin: 0 auto;
    }
    .app-header-actions {
        justify-content: center;
    }
    .screenshots-container img {
        height: 200px;
    }
}
