/* ============================================================
   TradeJournal — Dashboard Charts Stylesheet
   5 chart cards below the 6-stat strip: 2-up row, then 3-up row.
   Design system: Supabase spec (white canvas, emerald accent,
   flat hairline cards, no atmospheric shadows)
   ============================================================ */

:root {
    /* Neutral "breakeven" accent — used only for chart data points,
       per the design guide's rule that extra accent colors are
       reserved for chart points, not system UI. */
    --neutral-amber: #f5a623;
    --neutral-amber-deep: #d1891f;
}

/* ── Row layout ─────────────────────────────────────────── */
.chart-row {
    display: grid;
    gap: var(--s-xl);
    margin-bottom: var(--s-xl);
}

.chart-row--2 {
    grid-template-columns: repeat(2, 1fr);
}

.chart-row--3 {
    grid-template-columns: repeat(3, 1fr);
}

/* ── Card shell ─────────────────────────────────────────── */
.chart-card {
    position: relative;
    /* anchor for the floating tooltip */
    display: flex;
    flex-direction: column;
    background: var(--canvas);
    border: 1px solid var(--hairline-cool);
    border-radius: var(--r-lg);
    padding: var(--s-xl);
    min-width: 0;
    /* prevents grid blowout with wide svg */
    transition: border-color 160ms ease;
}

.chart-card:hover {
    border-color: var(--hairline-strong);
}

.chart-card__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--s-md);
    margin-bottom: var(--s-lg);
}

.chart-card__eyebrow {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--ink-mute-2);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 4px;
}

.chart-card__title {
    font-size: 20px;
    font-weight: 500;
    color: var(--ink);
    letter-spacing: -0.2px;
    line-height: 1.25;
}

.chart-card--sm .chart-card__title {
    font-size: 16px;
}

.chart-card--sm .chart-card__body {
    flex: 1;
    min-height: 168px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-card__foot {
    margin-top: var(--s-md);
    font-size: 12px;
    color: var(--ink-mute-2);
}

/* ── Trend badge (pill, top-right of head) ─────────────── */
.chart-card__badge {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 3px 9px;
    border-radius: var(--r-full);
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.chart-card__badge.is-positive {
    background: var(--profit-tint);
    color: var(--primary-deep);
}

.chart-card__badge.is-negative {
    background: var(--loss-tint);
    color: var(--loss-deep);
}

/* ── Chart body — svg fills the card width ─────────────── */
.chart-card__body {
    width: 100%;
    line-height: 0;
    /* kill inline-svg baseline gap */
}

.chart-card__body svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}

/* Shown inside a chart body when the active date filter matches
   zero trades (Dashboard "Filter Date" popup) */
.chart-empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 160px;
    padding: var(--s-lg);
    text-align: center;
    font-size: 13px;
    color: var(--ink-mute-2);
}

.chart-card__body--donut {
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-card__body--donut svg {
    width: 168px;
    height: 168px;
}

/* ── Legend (below donut) — mirrors calendar's legend chip ─ */
.chart-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: var(--s-lg);
    margin-top: var(--s-lg);
}

.chart-legend__item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--ink-mute);
}

.chart-legend__item strong {
    color: var(--ink);
    font-weight: 600;
}

.chart-legend__dot {
    width: 8px;
    height: 8px;
    border-radius: var(--r-full);
    flex: none;
}

.chart-legend__dot.is-win {
    background: var(--primary);
}

.chart-legend__dot.is-loss {
    background: var(--loss);
}

.chart-legend__dot.is-breakeven {
    background: var(--neutral-amber);
}

/* ── SVG helper classes (shared across all 5 charts) ────── */
.cchart-grid {
    stroke: var(--hairline-cool);
    stroke-width: 1;
}

.cchart-baseline {
    stroke: var(--hairline-strong);
    stroke-width: 1;
}

.cchart-axis-label {
    font-family: var(--font);
    font-size: 10px;
    fill: var(--ink-mute-2);
}

.cchart-bar-value {
    font-family: var(--font);
    font-size: 10px;
    font-weight: 500;
    fill: var(--ink-mute);
}

.cchart-symbol-label {
    font-family: var(--font);
    font-size: 12px;
    font-weight: 500;
    fill: var(--ink-secondary);
}

.cchart-donut-value {
    font-family: var(--font);
    font-size: 26px;
    font-weight: 500;
    fill: var(--ink);
}

.cchart-donut-label {
    font-family: var(--font);
    font-size: 11px;
    fill: var(--ink-mute);
}

/* ============================================================
   FLOATING TOOLTIP — mirrors the Calendar's .cal-day__tooltip
   (light card, dot + label + value, shadow-3), positioned by JS
   ============================================================ */
.chart-tooltip {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 40;
    min-width: 108px;
    background: var(--canvas);
    border: 1px solid var(--hairline-cool);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-3);
    padding: var(--s-sm) var(--s-md);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, calc(-100% - 10px));
    transition: opacity 120ms ease;
    will-change: transform, opacity;
}

.chart-tooltip.is-visible {
    opacity: 1;
}

.chart-tooltip__title {
    font-size: 12px;
    font-weight: 500;
    color: var(--ink);
    margin-bottom: 4px;
    white-space: nowrap;
}

.chart-tooltip__row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--ink-mute);
    white-space: nowrap;
}

.chart-tooltip__dot {
    width: 7px;
    height: 7px;
    border-radius: 2px;
    flex: none;
}

.chart-tooltip__value {
    font-weight: 600;
    color: var(--ink);
    margin-left: auto;
    padding-left: 10px;
}

/* ── Crosshair guide for the equity line ───────────────── */
.cchart-crosshair {
    stroke: var(--ink-faint);
    stroke-width: 1;
    stroke-dasharray: 3 3;
    opacity: 0;
    transition: opacity 120ms ease;
    pointer-events: none;
}

.cchart-crosshair.is-visible {
    opacity: 1;
}

.cchart-hit {
    fill: transparent;
    cursor: crosshair;
}

/* ── Bar hover ──────────────────────────────────────────── */
.cchart-bar {
    cursor: pointer;
    transition: opacity 120ms ease, filter 120ms ease;
    transform-box: fill-box;
    transform-origin: center;
}

.cchart-bar:hover {
    filter: brightness(0.93);
}

.cchart-bar--h {
    transform-origin: left center;
}

/* ── Equity line ────────────────────────────────────────── */
.cchart-line {
    /* draw-in animation removed for now */
}

.cchart-area {
    /* fade-in animation removed for now */
}

.cchart-point:hover,
.cchart-point.is-active {
    r: 5.5;
}

/* ── Donut segment hover ────────────────────────────────── */
.cchart-donut-seg {
    cursor: pointer;
    transition: stroke-width 140ms ease, opacity 140ms ease;
}

.cchart-donut-seg:hover {
    stroke-width: 23;
}

.chart-card__body--donut svg {
    overflow: visible;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1100px) {
    .chart-row--3 {
        grid-template-columns: repeat(2, 1fr);
    }

    .chart-row--3 .chart-card:nth-child(3) {
        grid-column: 1 / -1;
    }
}

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

@media (max-width: 640px) {
    .chart-row--3 {
        grid-template-columns: 1fr;
    }

    .chart-row--3 .chart-card:nth-child(3) {
        grid-column: auto;
    }

    .chart-card {
        padding: var(--s-lg);
    }
}