/* ============================================================
   Stock Tracker Dashboard — Dark Theme
   金融工具标配深色主题
   ============================================================ */

/* ---------- CSS Variables ---------- */
:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-card: #1c2128;
    --bg-hover: #252b35;
    --bg-input: #21262d;

    --border: #30363d;
    --border-light: #21262d;

    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-dim: #484f58;

    --green: #3fb950;
    --green-bg: rgba(63, 185, 80, 0.1);
    --yellow: #d29922;
    --yellow-bg: rgba(210, 153, 34, 0.1);
    --orange: #db6d28;
    --orange-bg: rgba(219, 109, 40, 0.1);
    --red: #f85149;
    --red-bg: rgba(248, 81, 73, 0.1);
    --blue: #58a6ff;
    --blue-bg: rgba(88, 166, 255, 0.1);
    --purple: #bc8cff;

    --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', Consolas, monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;

    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
}

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

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: var(--blue);
    text-decoration: none;
    transition: color 0.15s;
}
a:hover {
    color: var(--purple);
    text-decoration: underline;
}

/* ---------- Layout ---------- */
.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header .logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.app-header .logo:hover {
    text-decoration: none;
}

.app-nav {
    display: flex;
    gap: 4px;
}
.app-nav a {
    padding: 8px 16px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s;
}
.app-nav a:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    text-decoration: none;
}
.app-nav a.active {
    background: var(--blue-bg);
    color: var(--blue);
}

.app-main {
    flex: 1;
    padding: 24px;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* ---------- Cards ---------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

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

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ---------- Market Pulse Hero ---------- */
.pulse-hero {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px 28px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    box-shadow: var(--shadow);
}

.pulse-hero.bullish { border-left: 4px solid var(--green); }
.pulse-hero.neutral { border-left: 4px solid var(--yellow); }
.pulse-hero.cautious { border-left: 4px solid var(--orange); }
.pulse-hero.bearish { border-left: 4px solid var(--red); }

.pulse-main {
    display: flex;
    align-items: center;
    gap: 16px;
}

.pulse-emoji {
    font-size: 40px;
    line-height: 1;
}

.pulse-info h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 2px;
}

.pulse-info .pulse-meta {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    gap: 16px;
}

.pulse-scores {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.pulse-score-item {
    text-align: center;
    min-width: 70px;
}

.pulse-score-item .label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pulse-score-item .value {
    font-size: 20px;
    font-weight: 700;
    font-family: var(--font-mono);
}

/* ---------- Score Bar ---------- */
.score-bar {
    height: 6px;
    background: var(--bg-hover);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 4px;
}

.score-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.score-bar-fill.green { background: var(--green); }
.score-bar-fill.yellow { background: var(--yellow); }
.score-bar-fill.orange { background: var(--orange); }
.score-bar-fill.red { background: var(--red); }

/* ---------- Strategy Grid ---------- */
.strategy-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

@media (max-width: 900px) {
    .strategy-grid {
        grid-template-columns: 1fr;
    }
}

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

.strategy-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.strategy-card-header h3 {
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.strategy-count {
    font-size: 13px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.signal-list {
    list-style: none;
}

.signal-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 14px;
}
.signal-item:last-child {
    border-bottom: none;
}

.signal-item .ticker-link {
    font-weight: 600;
    font-family: var(--font-mono);
    min-width: 60px;
}

.signal-item .name {
    color: var(--text-secondary);
    font-size: 12px;
    flex: 1;
    margin: 0 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.signal-item .score {
    font-family: var(--font-mono);
    font-weight: 600;
    min-width: 32px;
    text-align: right;
}

.empty-state {
    text-align: center;
    padding: 20px;
    color: var(--text-dim);
    font-size: 13px;
}

/* ---------- Signal Timeline ---------- */
.timeline {
    list-style: none;
}

.timeline-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 14px;
}
.timeline-item:last-child {
    border-bottom: none;
}

.timeline-date {
    font-size: 12px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    min-width: 80px;
    flex-shrink: 0;
}

.timeline-emoji {
    font-size: 16px;
    flex-shrink: 0;
}

.timeline-content {
    flex: 1;
}

.timeline-content .ticker {
    font-weight: 600;
    font-family: var(--font-mono);
}

.timeline-content .detail {
    color: var(--text-secondary);
    font-size: 12px;
}

/* ---------- Table ---------- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th {
    text-align: left;
    padding: 10px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.data-table th:hover {
    color: var(--text-primary);
}
.data-table th.sort-asc::after { content: " ▲"; font-size: 10px; }
.data-table th.sort-desc::after { content: " ▼"; font-size: 10px; }

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background 0.1s;
}
.data-table tbody tr:hover {
    background: var(--bg-hover);
}

.data-table .col-ticker {
    font-weight: 600;
    font-family: var(--font-mono);
}

.data-table .col-name {
    color: var(--text-secondary);
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.data-table .col-num {
    text-align: right;
    font-family: var(--font-mono);
}

.data-table .col-center {
    text-align: center;
}

/* Strategy column badges */
.signal-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 13px;
    font-family: var(--font-mono);
    font-weight: 600;
}

.signal-badge.active {
    background: var(--green-bg);
    color: var(--green);
}
.signal-badge.vcp-active {
    background: var(--blue-bg);
    color: var(--blue);
}
.signal-badge.bf-active {
    background: var(--orange-bg);
    color: var(--orange);
}
.signal-badge.bc-active {
    background: rgba(188, 140, 255, 0.1);
    color: var(--purple);
}
.signal-badge.inactive {
    color: var(--text-dim);
}

/* ---------- Filters ---------- */
.filters-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.filter-select, .filter-input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color 0.15s;
}
.filter-select:focus, .filter-input:focus {
    border-color: var(--blue);
}

.filter-input {
    min-width: 180px;
}

.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
}
.filter-checkbox input {
    accent-color: var(--blue);
}

/* ---------- Ticker Detail ---------- */
.ticker-header {
    margin-bottom: 24px;
}

.ticker-header .back-link {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: inline-block;
}

.ticker-header h1 {
    font-size: 28px;
    font-weight: 700;
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.ticker-header h1 .sector-tag {
    font-size: 13px;
    font-weight: 400;
    color: var(--text-secondary);
    background: var(--bg-hover);
    padding: 2px 8px;
    border-radius: 4px;
}

.ticker-price {
    font-size: 16px;
    margin-top: 4px;
    display: flex;
    gap: 16px;
    align-items: baseline;
}

.ticker-price .price-value {
    font-size: 24px;
    font-weight: 700;
    font-family: var(--font-mono);
}

.ticker-price .price-chg {
    font-size: 14px;
    font-family: var(--font-mono);
}

/* Strategy detail cards */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

@media (max-width: 900px) {
    .detail-grid {
        grid-template-columns: 1fr;
    }
}

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

.detail-card.active {
    border-color: var(--green);
}
.detail-card.inactive {
    opacity: 0.6;
}

.detail-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.detail-card-header h3 {
    font-size: 15px;
    font-weight: 600;
}

.detail-card-status {
    font-size: 12px;
    padding: 2px 10px;
    border-radius: 12px;
    font-weight: 600;
}
.detail-card-status.on {
    background: var(--green-bg);
    color: var(--green);
}
.detail-card-status.off {
    background: var(--bg-hover);
    color: var(--text-dim);
}

.detail-card .stat-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 13px;
}
.detail-card .stat-row .stat-label {
    color: var(--text-secondary);
}
.detail-card .stat-row .stat-value {
    font-family: var(--font-mono);
    font-weight: 500;
}

/* Conditions list */
.conditions-list {
    list-style: none;
}

.condition-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 13px;
}
.condition-item:last-child {
    border-bottom: none;
}

.condition-icon {
    font-size: 14px;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

.condition-name {
    font-weight: 600;
    min-width: 100px;
    flex-shrink: 0;
}

.condition-detail {
    color: var(--text-secondary);
    flex: 1;
}

/* ---------- Charts ---------- */
.chart-container {
    position: relative;
    height: 200px;
    margin-top: 12px;
}

/* ---------- Utility Classes ---------- */
.text-green { color: var(--green); }
.text-yellow { color: var(--yellow); }
.text-orange { color: var(--orange); }
.text-red { color: var(--red); }
.text-blue { color: var(--blue); }
.text-dim { color: var(--text-dim); }
.text-secondary { color: var(--text-secondary); }
.text-mono { font-family: var(--font-mono); }
.font-bold { font-weight: 600; }

.flex { display: flex; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }

/* ---------- Modal Overlay ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 200;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 480px;
    max-width: 92vw;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 201;
    animation: modalFadeIn 0.2s ease;
}

@keyframes modalFadeIn {
    from { opacity: 0; transform: translate(-50%, -48%); }
    to   { opacity: 1; transform: translate(-50%, -50%); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius);
    transition: all 0.15s;
    line-height: 1;
}
.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

.modal-field {
    margin-bottom: 16px;
}
.modal-field label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.ticker-input-row {
    display: flex;
    gap: 8px;
}

.btn-check-ticker {
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.15s;
}
.btn-check-ticker:hover {
    background: var(--blue-bg);
    border-color: var(--blue);
    color: var(--blue);
}
.btn-check-ticker:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ---------- Ticker Validation Result ---------- */
.ticker-validation {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    line-height: 1.6;
    margin-bottom: 16px;
}

.validation-loading {
    background: var(--blue-bg);
    border: 1px solid rgba(88, 166, 255, 0.2);
    color: var(--blue);
}
.validation-success {
    background: var(--green-bg);
    border: 1px solid rgba(63, 185, 80, 0.2);
    color: var(--green);
}
.validation-restore {
    background: var(--yellow-bg);
    border: 1px solid rgba(210, 153, 34, 0.2);
    color: var(--yellow);
}
.validation-warn {
    background: var(--orange-bg);
    border: 1px solid rgba(219, 109, 40, 0.2);
    color: var(--orange);
}
.validation-error {
    background: var(--red-bg);
    border: 1px solid rgba(248, 81, 73, 0.2);
    color: var(--red);
}

/* ---------- Modal Actions ---------- */
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-light);
}

.btn-cancel {
    background: var(--bg-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 8px 20px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
}
.btn-cancel:hover {
    color: var(--text-primary);
    background: var(--bg-input);
}

.btn-confirm {
    background: var(--green);
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.15s;
}
.btn-confirm:hover {
    filter: brightness(1.1);
}
.btn-confirm:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    filter: none;
}

/* ---------- Add / Remove Ticker Buttons ---------- */
.btn-add-ticker {
    background: var(--green-bg);
    color: var(--green);
    border: 1px solid rgba(63, 185, 80, 0.3);
    padding: 8px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    transition: all 0.15s;
}
.btn-add-ticker:hover {
    background: var(--green);
    color: #fff;
    border-color: var(--green);
}

/* ---------- Refresh Prices Button ---------- */
.btn-refresh-prices {
    background: var(--blue-bg);
    color: var(--blue);
    border: 1px solid rgba(88, 166, 255, 0.3);
    padding: 8px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    transition: all 0.15s;
    margin-left: auto;
}
.btn-refresh-prices:hover {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
}
.btn-refresh-prices:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: none;
}
.btn-refresh-prices.refreshing {
    animation: pulse-glow 1.5s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* ---------- Refresh Progress Panel ---------- */
.refresh-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    animation: modalFadeIn 0.2s ease;
}

.refresh-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 14px;
    font-weight: 600;
}

.refresh-panel-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--radius);
    transition: all 0.15s;
    line-height: 1;
}
.refresh-panel-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.refresh-progress-bar {
    height: 6px;
    background: var(--bg-hover);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.refresh-progress-fill {
    height: 100%;
    background: var(--blue);
    border-radius: 3px;
    transition: width 0.3s ease;
}
.refresh-progress-fill.done {
    background: var(--green);
}
.refresh-progress-fill.has-errors {
    background: var(--orange);
}

.refresh-status {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.refresh-log {
    max-height: 150px;
    overflow-y: auto;
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    line-height: 1.8;
}
.refresh-log .log-item {
    display: flex;
    align-items: center;
    gap: 6px;
}
.refresh-log .log-updated { color: var(--green); }
.refresh-log .log-skipped { color: var(--text-dim); }
.refresh-log .log-error { color: var(--red); }

.btn-remove-ticker {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 18px;
    font-weight: 400;
    line-height: 1;
    padding: 2px 6px;
    border-radius: var(--radius);
    transition: all 0.15s;
}
.btn-remove-ticker:hover {
    background: var(--red-bg);
    color: var(--red);
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .app-main {
        padding: 16px;
    }
    .pulse-hero {
        flex-direction: column;
        align-items: flex-start;
    }
    .pulse-scores {
        width: 100%;
    }
    .filters-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .modal {
        width: 95vw;
    }
}
