/* dashboard/css/style.css */

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

:root {
    --bg:        #0d0f14;
    --bg2:       #141720;
    --bg3:       #1c2030;
    --border:    #2a2f45;
    --text:      #e2e8f0;
    --text-dim:  #64748b;
    --gold:      #f5c842;
    --gold-dim:  #a88520;
    --positive:  #22c55e;
    --negative:  #ef4444;
    --neutral:   #94a3b8;
    --accent:    #6366f1;
    --radius:    12px;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    min-height: 100vh;
}

/* ── Sticky top wrapper ── */
/* Header + status strip are wrapped together so they scroll as one unit.
   This avoids the `top: 57px` brittle offset that breaks when header
   height changes across breakpoints.                                      */
.sticky-top {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg2);
}

/* ── Header ── */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 28px;
    border-bottom: 1px solid var(--border);
    background: var(--bg2);
    /* sticky is handled by .sticky-top wrapper — not needed here */
}

.logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--gold);
    letter-spacing: 2px;
}

.subtitle {
    margin-left: 12px;
    color: var(--text-dim);
    font-size: 13px;
}

.last-update {
    color: var(--text-dim);
    font-size: 12px;
    margin-right: 12px;
}

.btn-refresh {
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}

.btn-refresh:hover { background: var(--border); }

/* ── Status Strip ── */
/* Sits inside .sticky-top — no independent sticky needed */
.status-strip {
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 6px 28px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    color: var(--text-dim);
}

.status-strip strong { color: var(--text); }
.strip-sep           { opacity: 0.3; }
.strip-loading       { opacity: 0.5; }

/* ── Container ── */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ── Cards ── */
.card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.card-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    margin-bottom: 10px;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 16px;
}

.card-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}

/* ── Row 1: Signal Cards ── */
.cards-row {
    display: grid;
    grid-template-columns: 1.2fr 1fr 1fr 1fr;
    gap: 16px;
}

/* Signal Card */
.signal-card { border-left: 3px solid var(--gold); }

.signal-badge {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: 2px;
    margin-bottom: 4px;
}

.signal-badge.bullish { color: var(--positive); }
.signal-badge.bearish { color: var(--negative); }
.signal-badge.neutral { color: var(--neutral); }

.signal-strength {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

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

/* Stat Card */
.stat-value {
    font-size: 36px;
    font-weight: 700;
    color: var(--gold);
    margin-bottom: 10px;
}

.stat-bar-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-dim);
}

.dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.dot.positive { background: var(--positive); }
.dot.negative { background: var(--negative); }
.dot.neutral  { background: var(--neutral); }

/* Sentiment Bar */
.sentiment-bar-wrap { margin-top: 8px; }

.sentiment-bar-track {
    position: relative;
    height: 8px;
    background: var(--bg3);
    border-radius: 4px;
    overflow: visible;
    margin-bottom: 4px;
}

.sentiment-bar-fill {
    position: absolute;
    height: 100%;
    background: linear-gradient(90deg, var(--negative), var(--positive));
    border-radius: 4px;
    transition: width 0.5s ease;
    top: 0; left: 0;
}

.sentiment-bar-center {
    position: absolute;
    left: 50%; top: -3px;
    width: 2px; height: 14px;
    background: var(--border);
}

.sentiment-bar-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--text-dim);
}

/* Impact Stars */
.impact-stars {
    font-size: 18px;
    margin-top: 4px;
    letter-spacing: 2px;
}

/* ── Row 2: Charts ── */
.charts-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
}

/* Chart cards are flex-column so the canvas can flex-grow to fill the card.
   CSS grid makes both cards equal height → the taller pie card stretches the
   sentiment card too.  flex: 1 on the canvas fills that extra space instead
   of leaving a blank gap at the bottom.                                       */
.chart-card {
    padding: 20px;
    display: flex;
    flex-direction: column;
}

/* Wrapper gets flex:1 so it fills the remaining card height.
   position:relative is required for the absolutely-positioned tooltip inside. */
.chart-wrapper {
    flex: 1;
    position: relative;
    min-height: 220px;
}

/* LightweightCharts container — must fill the wrapper exactly.
   LightweightCharts manages its own canvas; we just give it a sized div.    */
#sentimentChart {
    width: 100%;
    height: 100%;
}

/* ── TradingView-style floating crosshair tooltip ── */
.tv-tooltip {
    display: none;
    position: absolute;
    z-index: 10;
    pointer-events: none;          /* never intercepts mouse events            */
    background: #1e293b;
    border: 1px solid #2a2f45;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 12px;
    line-height: 1.6;
    color: #e2e8f0;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    min-width: 130px;
    white-space: nowrap;
}
.tv-tooltip-time {
    color: #64748b;
    font-size: 11px;
    margin-bottom: 4px;
    font-variant-numeric: tabular-nums;
}
.tv-tooltip-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}
.tv-tooltip-label { color: #64748b; }
.tv-tooltip-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ── Chart legend dots (bullish / bearish) ── */
.chart-legend {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: #64748b;
}
.legend-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

/* Pie/doughnut chart: self-sizing via maintainAspectRatio:true + aspectRatio:1.
   align-self: center keeps it centred when the card is taller than the chart. */
#pieChart {
    display: block;
    max-width: 100%;
    align-self: center;
}

/* ── Row 3: News ── */
.news-row {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 16px;
}

/* ── Empty State ── */
/* Used for Top5, news list, and chart placeholders when there's no data */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 28px 16px;
    color: var(--text-dim);
    text-align: center;
    gap: 6px;
}

.empty-state .empty-icon { font-size: 28px; opacity: 0.5; }
.empty-state .empty-hint { font-size: 11px; opacity: 0.6; margin-top: 2px; }
.empty-state.error       { color: #f97316; }

/* ── Top News ── */
.top-news-list { display: flex; flex-direction: column; gap: 10px; }

.top-news-item {
    padding: 10px 12px;
    background: var(--bg3);
    border-radius: 8px;
    border-left: 3px solid var(--gold-dim);
    cursor: pointer;
    transition: border-color 0.2s;
}

.top-news-item:hover { border-color: var(--gold); }

.top-news-title {
    font-size: 13px;
    color: var(--text);
    margin-bottom: 4px;
    line-height: 1.4;
}

.top-news-meta {
    display: flex;
    gap: 8px;
    font-size: 11px;
    color: var(--text-dim);
    align-items: center;
}

/* ── News List ── */
.news-list { display: flex; flex-direction: column; gap: 8px; }

.news-item {
    padding: 12px 14px;
    background: var(--bg3);
    border-radius: 8px;
    border: 1px solid transparent;
    transition: border-color 0.2s;
}

/* Only show pointer cursor if the item has a summary to expand */
.news-item.has-summary { cursor: pointer; }
.news-item.has-summary:hover { border-color: var(--border); }

.news-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 6px;
}

.news-item-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.news-title {
    font-size: 13px;
    color: var(--text);
    line-height: 1.4;
    flex: 1;
}

/* Expand/collapse chevron */
.expand-icon {
    font-size: 9px;
    color: var(--text-dim);
    transition: transform 0.2s;
    user-select: none;
}

/* AI summary panel — collapsed by default, revealed on click */
.news-summary {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.2s ease;
}

.news-summary.open {
    max-height: 200px;
    padding-bottom: 8px;
}

.news-summary-text {
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.6;
    padding: 8px 10px;
    background: rgba(99,102,241,0.06);
    border-left: 2px solid var(--accent);
    border-radius: 4px;
    margin-bottom: 6px;
}

.badge {
    font-size: 10px;
    padding: 2px 7px;
    border-radius: 10px;
    white-space: nowrap;
    font-weight: 600;
}

.badge.positive { background: rgba(34,197,94,0.15);  color: var(--positive); }
.badge.negative { background: rgba(239,68,68,0.15);  color: var(--negative); }
.badge.neutral  { background: rgba(148,163,184,0.15); color: var(--neutral); }

.news-item-footer {
    display: flex;
    gap: 12px;
    font-size: 11px;
    color: var(--text-dim);
}

.impact-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    margin-right: 3px;
    vertical-align: middle;
}

/* Relative-time label: dashed underline hints that hovering shows full HKT time */
.time-ago {
    cursor: help;
    border-bottom: 1px dashed var(--text-dim);
    text-decoration: none;
}

/* Cluster badge */
.cluster-badge {
    font-size: 10px;
    color: var(--accent);
    background: rgba(99,102,241,0.12);
    padding: 1px 6px;
    border-radius: 8px;
}

/* ── Pagination ── */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-top: 14px;
    font-size: 13px;
}

.pagination button {
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

.pagination button:hover:not(:disabled) { background: var(--border); }
.pagination button:disabled { opacity: 0.3; cursor: default; }

/* ── Filter ── */
.filter-row { display: flex; gap: 8px; }

.filter-row select {
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
}

/* ── Toast Notification ── */
/* Appears bottom-right when new articles are detected via digest polling */
.toast {
    position: fixed;
    bottom: 28px;
    right: 28px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 200;

    /* Hidden by default — use both visibility + opacity so button text doesn't bleed through */
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s linear 0.25s;
}

.toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s linear 0s;
}

.toast--success { border-color: var(--positive); }
.toast--warn    { border-color: var(--gold); }
.toast--info    { border-color: var(--accent); }

.toast-close {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 12px;
    padding: 0 2px;
    flex-shrink: 0;
}

.toast-close:hover { color: var(--text); }

/* ── Responsive ── */

/* ── Tablet landscape / narrow desktop (≤ 1100px) ── */
@media (max-width: 1100px) {
    .cards-row  { grid-template-columns: 1fr 1fr; }
    .charts-row { grid-template-columns: 1fr; }
    .news-row   { grid-template-columns: 1fr; }

    /* Pie chart is self-sizing via aspectRatio:1 — no height override needed */
}

/* ── Tablet portrait (≤ 768px) ── */
@media (max-width: 768px) {
    /* Header: allow controls to wrap below the logo row */
    .header {
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px 16px;
    }
    .header-left  { flex: 1 1 auto; }
    .header-right { flex: 0 0 auto; }
    /* Subtitle wastes horizontal space on narrow screens */
    .subtitle { display: none; }

    /* Status strip: let items wrap cleanly onto two lines */
    .status-strip {
        flex-wrap: wrap;
        gap: 6px 12px;
        padding: 6px 16px;
        /* position is handled by .sticky-top wrapper — no override needed */
    }

    /* Card title row: stack filters below the title */
    .card-title-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    /* Filters: stretch the row and let each select grow */
    .filter-row       { width: 100%; flex-wrap: wrap; }
    .filter-row select { flex: 1 1 120px; }

    /* Pagination: reduce spacing so it fits one line */
    .pagination        { gap: 8px; font-size: 12px; }
    .pagination button { padding: 4px 10px; font-size: 12px; }

    /* News footer items can wrap instead of overflowing */
    .news-item-footer { flex-wrap: wrap; gap: 6px; }

    /* Top-news meta can also wrap */
    .top-news-meta { flex-wrap: wrap; gap: 4px 8px; }

    .container { padding: 16px 14px; }
}

/* ── Mobile (≤ 600px) ── */
@media (max-width: 600px) {
    .cards-row { grid-template-columns: 1fr; }

    /* Oversized numbers look odd in a full-width single card */
    .stat-value   { font-size: 28px; }
    .signal-badge { font-size: 26px; }

    /* Cap the flex-grown sentiment chart on small screens.
       Applied to the wrapper (not the canvas) because canvas is position:absolute. */
    .chart-wrapper { max-height: 200px; }
    /* Pie chart is self-sizing — no override needed */

    /* Pagination: let page-info sit on its own line */
    .pagination   { flex-wrap: wrap; justify-content: center; }
    #pageInfo     { width: 100%; text-align: center; }

    .container { padding: 12px; gap: 12px; }
    .card      { padding: 14px; }
    .toast     { right: 12px; bottom: 12px; left: 12px; }
}

/* ── Very small phones (≤ 400px) ── */
@media (max-width: 400px) {
    .logo        { font-size: 15px; }
    /* last-update is redundant — status strip already shows this info */
    .last-update { display: none; }
    .card-label  { font-size: 10px; }
}
