/* ============================================================
   基金看板 — 移动端优先
   ============================================================ */

:root {
    --bg: #0d1117;
    --bg-alt: #161b22;
    --card: #1c2333;
    --card-hover: #212a3a;
    --border: #30363d;
    --accent: #4a90d9;
    --text: #e6edf3;
    --text2: #8b949e;
    --text3: #6e7681;
    --green: #3fb950;
    --red: #f85149;
    --radius: 10px;
    --radius-sm: 6px;
    --max-w: 960px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

/* ======================== HEADER ======================== */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-alt);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 8px;
}

.app-title {
    font-size: 1rem;
    font-weight: 700;
    white-space: nowrap;
}

.subtitle {
    display: none;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.nav-link {
    font-size: 0.72rem;
    color: var(--accent);
    text-decoration: none;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 99px;
    white-space: nowrap;
    transition: background 0.2s;
}
.nav-link:active, .nav-link:hover { background: var(--card); }

.market-status {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 99px;
    font-size: 0.72rem;
    font-weight: 500;
    background: var(--card);
    white-space: nowrap;
}

.status-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--text3);
    flex-shrink: 0;
}

.market-status.open .status-dot { background: var(--green); box-shadow: 0 0 6px var(--green); }
.market-status.closed .status-dot { background: var(--red); }

.last-update {
    display: none;
    font-size: 0.7rem;
    color: var(--text3);
    font-family: 'JetBrains Mono', monospace;
}

/* ======================== SEARCH ======================== */

.search-section {
    padding: 12px 16px;
    position: sticky;
    top: 48px;
    z-index: 99;
    background: var(--bg);
}

.search-bar {
    display: flex;
    gap: 8px;
}

#searchInput {
    flex: 1;
    min-width: 0;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.2s;
    -webkit-appearance: none;
}

#searchInput:focus {
    outline: none;
    border-color: var(--accent);
}

#searchInput::placeholder { color: var(--text3); }

.btn {
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    font-family: inherit;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    flex-shrink: 0;
}

.btn-primary:active { opacity: 0.8; }

.search-error {
    color: var(--red);
    font-size: 0.78rem;
    margin-top: 6px;
    min-height: 18px;
}

/* ======================== CARDS ======================== */

.watchlist {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 16px 80px;
    max-width: var(--max-w);
    margin: 0 auto;
}

.stock-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: border-color 0.2s;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
}

.stock-card:active { border-color: var(--accent); }
.stock-card.skeleton { pointer-events: none; }

/* Flash */
.stock-card.flash-up { animation: flashUp 0.6s; }
.stock-card.flash-down { animation: flashDown 0.6s; }

@keyframes flashUp {
    0% { box-shadow: 0 0 0 0 var(--green); }
    50% { box-shadow: 0 0 20px 4px rgba(63,185,80,0.15); }
    100% { box-shadow: 0 0 0 0 transparent; }
}
@keyframes flashDown {
    0% { box-shadow: 0 0 0 0 var(--red); }
    50% { box-shadow: 0 0 20px 4px rgba(248,81,73,0.15); }
    100% { box-shadow: 0 0 0 0 transparent; }
}

.price-flash-up { animation: priceUp 0.5s; }
.price-flash-down { animation: priceDown 0.5s; }

@keyframes priceUp {
    0%, 100% { color: var(--text); }
    50% { color: var(--green); }
}
@keyframes priceDown {
    0%, 100% { color: var(--text); }
    50% { color: var(--red); }
}

/* Skeleton */
.skeleton-line {
    background: linear-gradient(90deg, var(--card) 25%, var(--card-hover) 50%, var(--card) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Card content — horizontal layout */
.card-info {
    flex: 1;
    min-width: 0;
}

.card-symbol {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--accent);
    font-family: 'JetBrains Mono', monospace;
    margin-right: 6px;
}

.card-company {
    font-size: 0.72rem;
    color: var(--text3);
    display: inline;
}

.card-price {
    font-size: 1.3rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    margin-top: 2px;
}

.card-change {
    font-size: 0.82rem;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
}

.card-change.up { color: var(--green); }
.card-change.down { color: var(--red); }

.card-sparkline {
    width: 70px;
    height: 36px;
    flex-shrink: 0;
    display: none;
}

.card-sparkline svg { width: 100%; height: 100%; }

.btn-remove {
    position: absolute;
    top: 0; right: 0;
    width: 36px; height: 36px;
    border: none;
    background: transparent;
    color: var(--text3);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    opacity: 0;
}

.btn-remove:active, .stock-card:hover .btn-remove { opacity: 1; color: var(--red); }

/* ======================== EMPTY STATE ======================== */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text3);
}

.empty-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state h2 { font-size: 1.1rem; color: var(--text2); margin-bottom: 6px; }
.empty-state p { font-size: 0.85rem; }

/* ======================== BANNER ======================== */

.status-banner {
    position: fixed;
    bottom: 50%;
    left: 50%;
    transform: translate(-50%, 50%);
    background: var(--bg-alt);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 18px;
    border-radius: var(--radius);
    font-size: 0.82rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    z-index: 200;
    animation: fadeIn 0.25s;
}

.status-banner.error { border-color: var(--red); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ======================== FOOTER ======================== */

.footer {
    text-align: center;
    padding: 12px 16px;
    font-size: 0.68rem;
    color: var(--text3);
    border-top: 1px solid var(--border);
    background: var(--bg);
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 50;
}

.footer a { color: var(--accent); text-decoration: none; }
.divider { margin: 0 6px; opacity: 0.4; }

/* ======================== CHART MODAL ======================== */

.chart-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 300;
    display: flex;
    align-items: flex-end;
    animation: fadeIn 0.2s;
}

.chart-modal {
    background: var(--bg-alt);
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-height: 94vh;
    overflow-y: auto;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.chart-close {
    position: absolute;
    top: 12px; right: 12px;
    width: 32px; height: 32px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--card);
    color: var(--text2);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    -webkit-tap-highlight-color: transparent;
}

.chart-header {
    padding: 20px 20px 8px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.chart-symbol {
    font-size: 1.1rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
}

.chart-name {
    font-size: 0.78rem;
    color: var(--text3);
    display: block;
    margin-top: 2px;
}

.chart-price {
    font-size: 1.15rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    text-align: right;
}

.chart-change {
    font-size: 0.78rem;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    text-align: right;
    margin-top: 1px;
}

.chart-container {
    padding: 4px 8px;
    position: relative;
}

.chart-container svg {
    width: 100%;
    height: auto;
    max-height: 280px;
}

.chart-loading {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text3);
    font-size: 0.85rem;
}

.chart-periods {
    display: flex;
    justify-content: center;
    gap: 4px;
    padding: 8px 12px 20px;
    flex-wrap: wrap;
}

.period-btn {
    padding: 8px 14px;
    border: none;
    background: transparent;
    color: var(--text2);
    font-size: 0.8rem;
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    border-radius: 4px;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s;
}

.period-btn:active { background: var(--card); }
.period-btn.active { color: var(--text); font-weight: 600; position: relative; }
.period-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0; left: 50%; margin-left: -10px;
    width: 20px; height: 2px;
    background: var(--accent);
    border-radius: 2px;
}

/* ======================== TABLET ======================== */

@media (min-width: 600px) {
    .header { padding: 14px 24px; }
    .app-title { font-size: 1.15rem; }
    .subtitle { display: inline; font-size: 0.75rem; color: var(--text3); margin-left: 8px; }
    .last-update { display: inline; }
    .search-section { padding: 16px 24px 8px; top: 52px; }
    .watchlist {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        padding: 8px 24px 60px;
    }
    .stock-card {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
        padding: 16px;
    }
    .card-price { font-size: 1.6rem; }
    .card-sparkline { display: block; }
    .chart-modal { max-width: 500px; margin: 0 auto; }
    .chart-container svg { max-height: 300px; }
}

/* ======================== DESKTOP ======================== */

@media (min-width: 900px) {
    .header { padding: 16px 32px; }
    .app-title { font-size: 1.25rem; }
    .search-section { padding: 20px 32px 8px; }
    .search-bar { max-width: var(--max-w); margin: 0 auto; }
    .watchlist {
        grid-template-columns: repeat(3, 1fr);
        gap: 16px;
        padding: 12px 32px 60px;
    }
    .stock-card:hover {
        border-color: var(--accent);
        box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    }
    .btn-primary:hover { background: #3a7bc8; }
    .chart-modal {
        max-width: 720px;
        border-radius: 20px 20px 0 0;
    }
    .chart-container svg { max-height: 340px; }
    .chart-symbol { font-size: 1.3rem; }
    .chart-price { font-size: 1.3rem; }
    .btn-remove { opacity: 0; }
    .stock-card:hover .btn-remove { opacity: 1; }
}
