/* Deal Tracker — see design_handoff_deal_tracker/README.md.
   Tokens come from assets/tokens.css (Peppy Design System).
   One responsive design: master-detail at >= 900px, tap-to-expand list below. */

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--canvas);
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-sans);
    color: var(--ink);
}

/* Scrollbars are hidden on the scrolling surfaces. */
.scroll::-webkit-scrollbar { width: 0; height: 0; }
.scroll { scrollbar-width: none; }

.app {
    min-height: 100vh;
    background: var(--canvas);
    display: flex;
    flex-direction: column;
}

/* ---- Header ---- */

/* Ink bar and controls travel together, pinned at every width. */
.hdr-block {
    position: sticky;
    top: 0;
    z-index: 20;
    flex: 0 0 auto;
    background: var(--canvas);
}

/* Ink band — polarity flip, full bleed. The colour change is the divider. */
.hdr {
    background: var(--ink);
    color: var(--on-primary);
}

.hdr-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: clamp(20px, 2.4vw, 28px) clamp(16px, 4vw, 32px);
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
}

.hdr-lead {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

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

.wordmark img { display: block; flex: 0 0 auto; }

.wordmark-text {
    font-size: clamp(26px, 2.4vw, 32px);
    font-weight: var(--weight-semibold);
    letter-spacing: -0.5px;
    line-height: 1.15;
    color: var(--on-primary);
}

.updated {
    font-size: 12px;
    font-weight: var(--weight-caption);
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--mute-soft);
    white-space: nowrap;
}

.summary {
    margin: 0;
    max-width: 52ch;
    font-size: 14px;
    line-height: 20px;
    color: var(--hairline);
}

/* ---- Sort + store filter (one wrapping row) ---- */

.controls-bar {
    background: var(--canvas);
    border-bottom: 1px solid var(--hairline);
}

.controls {
    max-width: 1280px;
    margin: 0 auto;
    padding: 12px clamp(16px, 4vw, 32px);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.count {
    flex: 0 0 auto;
    font-size: 12px;
    font-weight: var(--weight-caption);
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--mute);
    white-space: nowrap;
}

/* Radio inputs stay in the tab order but are visually replaced by their labels. */
.segmented input, .chips input {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip-path: inset(50%);
}

.segmented {
    flex: 0 0 auto;
    display: inline-flex;
    border: 1px solid var(--hairline);
    border-radius: var(--radius-button);
    overflow: hidden;
}

.segmented label, .chips label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* 44px minimum tap target (handoff, accessibility). */
    min-height: 44px;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: var(--weight-medium);
    line-height: 20px;
    white-space: nowrap;
    background: var(--canvas);
    color: var(--ink);
    cursor: pointer;
    user-select: none;
    transition: background-color var(--duration-fast) var(--ease-standard),
                border-color var(--duration-base) var(--ease-standard),
                color var(--duration-base) var(--ease-standard);
}

.segmented > label + label { border-left: 1px solid var(--hairline); }

/* Dash's own option CSS tints labels purple on :hover/:focus-within and outranks
   plain class selectors — these two rules take the colour back. */
.segmented label, .chips label { color: var(--ink) !important; }

.segmented label:has(input:checked),
.chips label:has(input:checked) {
    background: var(--ink);
    color: var(--on-primary) !important;
    border-color: var(--ink);
}

.segmented label:has(input:focus-visible),
.chips label:has(input:focus-visible) {
    outline: 2px solid var(--ink);
    outline-offset: 2px;
}

@media (hover: hover) {
    .segmented label:hover:not(:has(input:checked)),
    .chips label:hover:not(:has(input:checked)) {
        background: var(--action-secondary-bg-hover);
    }
}

.chips {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    gap: 8px;
    overflow-x: auto;
}

.chips > * { flex: 0 0 auto; }

.chips label {
    border: 1px solid var(--hairline);
    border-radius: var(--radius-button);
}

/* ---- Product list ---- */

/* Below the breakpoint the grid is a passthrough, so the list is the flex child
   that fills the viewport and carries the tint. */
.grid { display: contents; }

.list {
    flex: 1 1 auto;
    padding: 12px clamp(12px, 4vw, 16px) 32px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f7f7f8;
}

.card {
    background: var(--canvas);
    border: var(--elevation-1-border);
    border-radius: var(--radius-card);
    padding: 14px 16px;
}

.card-top {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.card-top::-webkit-details-marker { display: none; }

.card-top:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: 4px;
    border-radius: var(--radius-xs);
}

.card-left {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.name {
    font-size: 14px;
    font-weight: var(--weight-medium);
    line-height: 20px;
    letter-spacing: -0.1px;
    color: var(--ink);
}

.meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.store {
    font-size: 12px;
    font-weight: var(--weight-caption);
    color: var(--mute);
}

.card-right {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.price {
    font-size: 18px;
    font-weight: var(--weight-semibold);
    letter-spacing: -0.2px;
    font-variant-numeric: tabular-nums;
}

.spark { display: block; }

/* ---- Badge (Peppy Badge, tones success/info/neutral) ---- */

.badge {
    display: inline-flex;
    align-items: center;
    font-size: var(--text-caption-size);
    line-height: var(--text-caption-line);
    font-weight: var(--text-caption-weight);
    border-radius: var(--radius-badge);
    padding: var(--pad-badge);
    border: 1px solid transparent;
    white-space: nowrap;
}

.badge-success { background: var(--status-success); color: var(--primary); }
.badge-info    { background: var(--status-info);    color: var(--on-primary); }
.badge-neutral { background: var(--primary);        color: var(--on-primary); }

.badge-soft { background: var(--canvas); border-color: currentColor; }
.badge-soft.badge-success { color: var(--status-success); }
.badge-soft.badge-info    { color: var(--status-info); }
.badge-soft.badge-neutral { color: var(--primary); }

/* ---- Detail (shared by the mobile expand and the desktop pane) ---- */

.detail {
    margin-top: 12px;
    border-top: 1px solid var(--hairline);
    padding-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.history {
    display: block;
    width: 100%;
    height: 110px;
}

.legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: var(--weight-caption);
    color: var(--body);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.dot {
    width: 7px;
    height: 7px;
    border-radius: var(--radius-full);
    flex: 0 0 auto;
}

/* The 3-month average marker is the dashed rule itself, not a dot. */
.rule {
    width: 12px;
    height: 1px;
    flex: 0 0 auto;
}

.stats {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-label {
    font-size: 12px;
    font-weight: var(--weight-caption);
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--mute);
}

.stat-value {
    font-size: 14px;
    font-weight: var(--weight-medium);
    font-variant-numeric: tabular-nums;
}

.cta {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 44px;
    background: var(--action-primary-bg);
    color: var(--action-primary-fg);
    border-radius: var(--radius-button);
    font-size: var(--text-button-size);
    font-weight: var(--text-button-weight);
    letter-spacing: var(--text-button-track);
    text-decoration: none;
    transition: background-color var(--duration-base) var(--ease-standard);
}

.cta:hover { background: var(--action-primary-bg-hover); color: var(--action-primary-fg); text-decoration: none; }
.cta:active { background: var(--action-primary-bg-active); }

/* ---- Empty state ---- */

.empty {
    margin: auto;
    padding: 32px 16px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.empty-title {
    margin: 0;
    font-size: 16px;
    font-weight: var(--weight-medium);
    letter-spacing: -0.16px;
    color: var(--ink);
}

.empty-body {
    margin: 0;
    font-size: 14px;
    line-height: 20px;
    color: var(--body);
}

/* ---- Desktop: master-detail ---- */

.pane { display: none; }

@media (min-width: 900px) {
    .grid {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
        gap: 32px;
        align-items: start;
        width: 100%;
        max-width: 1280px;
        margin: 0 auto;
        padding: 24px clamp(16px, 4vw, 32px) 48px;
    }

    .list {
        padding: 0;
        min-width: 0;
        background: none;
    }

    /* Rows never expand at this width — selection drives the pane instead. */
    .card .detail { display: none; }

    .card {
        cursor: pointer;
        transition: background-color var(--duration-base) var(--ease-standard),
                    border-color var(--duration-base) var(--ease-standard);
    }

    .card-top { gap: 16px; }

    .card.selected {
        background: #f7f7f8;
        border-color: var(--ink);
        border-left: 2px solid var(--ink);
    }

    @media (hover: hover) {
        .card:not(.selected):hover { background: #f7f7f8; }
    }

    /* The pane clears the sticky header; --header-h is measured in accordion.js. */
    .pane {
        display: block;
        position: sticky;
        top: calc(var(--header-h, 148px) + 24px);
        min-width: 0;
    }

    /* The list carries no empty state on desktop; the pane says it instead. */
    .empty { display: none; }
}

.pane-card {
    background: var(--canvas);
    border: var(--elevation-1-border);
    border-radius: var(--radius-card);
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.pane-empty { gap: 8px; }

.pane-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    flex-wrap: wrap;
}

.pane-lead {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.pane-store {
    font-size: 12px;
    font-weight: var(--weight-caption);
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--mute);
}

.pane-name {
    font-size: 22px;
    font-weight: var(--weight-semibold);
    letter-spacing: -0.3px;
    line-height: 28px;
}

.pane-badge { display: flex; }

.pane-price {
    flex: 0 0 auto;
    font-size: 32px;
    font-weight: var(--weight-semibold);
    letter-spacing: -0.5px;
    font-variant-numeric: tabular-nums;
}

.pane-chart {
    display: block;
    width: 100%;
    height: 220px;
}

.pane .legend { gap: 24px; }

.pane .stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    border-top: 1px solid var(--hairline);
    padding-top: 20px;
}

.pane .stat { gap: 4px; }
.pane .stat-value { font-size: 16px; }

.pane-cta { display: flex; }
.pane-cta .cta { width: auto; padding: 0 24px; }

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}
