/* ========================================
   CryptoHub - Crypto Market Tracker
   Stylesheet
   ======================================== */

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

:root {
    --primary: #1652f0;
    --primary-light: #3b6ff5;
    --primary-dark: #0d3fd4;
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --bg-hover: #f1f5f9;
    --bg-thead: #f8fafc;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --green: #16a34a;
    --green-bg: #dcfce7;
    --red: #dc2626;
    --red-bg: #fee2e2;
    --star: #f59e0b;
    --radius: 10px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --header-h: 64px;
    --max-w: 1280px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    display: block;
    max-width: 100%;
}

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

.header-inner {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 0 24px;
    height: 100%;
    display: flex;
    align-items: center;
    gap: 32px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 20px;
    font-weight: 800;
    color: var(--primary);
    white-space: nowrap;
}

.logo-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary), #6366f1);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 18px;
}

.nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
}

.nav a {
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all .15s ease;
    white-space: nowrap;
}

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

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.search-box {
    position: relative;
    width: 220px;
}

.search-box input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
    background: var(--bg-body);
}

.search-box input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(22, 82, 240, .1);
}

.search-box .search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 16px;
}

.search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: 400px;
    overflow-y: auto;
    display: none;
    z-index: 200;
}

.search-results.show {
    display: block;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background .1s ease;
}

.search-result-item:hover {
    background: var(--bg-hover);
}

.search-result-item img {
    width: 24px;
    height: 24px;
    border-radius: 50%;
}

.search-result-item .sr-symbol {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 50px;
}

.search-result-item .sr-name {
    font-weight: 500;
    font-size: 14px;
}

/* --- Layout --- */
.main {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 24px;
}

.page-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}

.page-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* --- Global Stats Bar --- */
.global-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
}

.stat-card .stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

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

.stat-card .stat-change {
    font-size: 13px;
    font-weight: 600;
    margin-left: 8px;
}

.stat-change.up {
    color: var(--green);
}

.stat-change.down {
    color: var(--red);
}

/* --- Filter Bar --- */
.filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 16px;
    flex-wrap: wrap;
}

.filter-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
}

.filter-tab {
    padding: 7px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all .15s ease;
    border: none;
    background: transparent;
}

.filter-tab:hover {
    color: var(--text-primary);
}

.filter-tab.active {
    background: var(--primary);
    color: #fff;
}

.filter-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-size-select {
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    outline: none;
}

/* --- Coin Table --- */
.coin-table-wrap {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
}

.coin-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 900px;
}

.coin-table thead th {
    background: var(--bg-thead);
    padding: 12px 16px;
    text-align: right;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .03em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    position: sticky;
    top: 0;
}

.coin-table thead th:hover {
    color: var(--primary);
}

.coin-table thead th.left {
    text-align: left;
}

.coin-table thead th.center {
    text-align: center;
}

.coin-table thead th .sort-arrow {
    font-size: 10px;
    margin-left: 2px;
    opacity: .5;
}

.coin-table thead th.sorted .sort-arrow {
    opacity: 1;
    color: var(--primary);
}

.coin-table tbody td {
    padding: 14px 16px;
    text-align: right;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.coin-table tbody td.left {
    text-align: left;
}

.coin-table tbody td.center {
    text-align: center;
}

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

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

/* Star / Favorite */
.star-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: var(--text-muted);
    padding: 0;
    transition: color .15s ease, transform .1s ease;
}

.star-btn:hover {
    transform: scale(1.2);
}

.star-btn.active {
    color: var(--star);
}

/* Coin Info Cell */
.coin-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.coin-info img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
}

.coin-info .coin-names {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.coin-info .coin-name {
    font-weight: 600;
    font-size: 14px;
}

.coin-info .coin-symbol {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* Price change */
.pct-up {
    color: var(--green);
    font-weight: 600;
}

.pct-down {
    color: var(--red);
    font-weight: 600;
}

.pct-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
}

.pct-badge.up {
    background: var(--green-bg);
    color: var(--green);
}

.pct-badge.down {
    background: var(--red-bg);
    color: var(--red);
}

/* Sparkline */
.sparkline-cell {
    width: 140px;
}

.sparkline-cell canvas {
    display: block;
    margin: 0 auto;
}

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

.pagination button {
    min-width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: all .15s ease;
    padding: 0 10px;
}

.pagination button:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
}

.pagination button.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.pagination button:disabled {
    opacity: .4;
    cursor: not-allowed;
}

.pagination .page-info {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0 8px;
}

/* --- Loading & Error --- */
.loading-overlay,
.error-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    gap: 16px;
}

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

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

.loading-text {
    color: var(--text-secondary);
    font-size: 14px;
}

.error-overlay {
    color: var(--red);
}

.retry-btn {
    padding: 8px 20px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}

.retry-btn:hover {
    background: var(--primary-dark);
}

/* --- Footer --- */
.footer {
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    margin-top: 48px;
    padding: 32px 24px;
}

.footer-inner {
    max-width: var(--max-w);
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.footer-text {
    font-size: 13px;
    color: var(--text-muted);
}

.footer-links {
    display: flex;
    gap: 20px;
}

.footer-links a {
    font-size: 13px;
    color: var(--text-secondary);
}

.footer-links a:hover {
    color: var(--primary);
}

/* --- Detail Page --- */
.detail-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.detail-header img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

.detail-header h1 {
    font-size: 28px;
    font-weight: 700;
}

.detail-header .detail-symbol {
    font-size: 16px;
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 8px;
    text-transform: uppercase;
}

.detail-header .detail-rank {
    display: inline-block;
    padding: 3px 10px;
    background: var(--bg-hover);
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-left: 12px;
}

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

.detail-main {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.detail-sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.price-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.price-card .price-top {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 8px;
}

.price-card .price-main {
    font-size: 32px;
    font-weight: 700;
}

.price-card .price-btc {
    font-size: 14px;
    color: var(--text-muted);
}

.price-card .price-change {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 16px;
    font-weight: 600;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

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

.chart-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.chart-timeframes {
    display: flex;
    gap: 4px;
    background: var(--bg-body);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 3px;
}

.chart-timeframe {
    padding: 5px 12px;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border: none;
    background: transparent;
    transition: all .15s ease;
}

.chart-timeframe:hover {
    color: var(--text-primary);
}

.chart-timeframe.active {
    background: var(--primary);
    color: #fff;
}

#priceChart {
    width: 100%;
    height: 320px;
}

/* Stats Panel */
.stats-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.stats-panel h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.stats-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stats-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stats-row .stat-key {
    font-size: 13px;
    color: var(--text-secondary);
}

.stats-row .stat-val {
    font-size: 14px;
    font-weight: 600;
}

/* About Section */
.about-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.about-card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

.about-card .about-content {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-secondary);
}

.about-card .about-content p {
    margin-bottom: 12px;
}

.about-card .about-content a {
    color: var(--primary);
}

/* Links */
.detail-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.detail-links a {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-secondary);
    transition: all .15s ease;
}

.detail-links a:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    .global-stats {
        grid-template-columns: repeat(2, 1fr);
    }
    .detail-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .header-inner {
        gap: 12px;
        padding: 0 16px;
    }
    .nav {
        display: none;
    }
    .search-box {
        width: 160px;
    }
    .main {
        padding: 16px;
    }
    .global-stats {
        grid-template-columns: 1fr;
    }
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .price-card .price-main {
        font-size: 24px;
    }
}

/* Back link */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    transition: color .15s ease;
}

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