// Restock price/stock history graph + inline watchlist roll-down.
// Used by the diff page (#restock-graph) and the watchlist inline graph (.restock-inline-graph);
// both containers get the .js-restock-graph class from restock-price-graph.js.

#restock-diff { width: 100%; box-sizing: border-box; }

#restock-diff-summary {
  margin-top: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.restock-latest-price {
  font-size: 1.4rem;
  font-weight: 700;
}

.restock-badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;

  &.in-stock { background: rgba(31, 164, 99, 0.15); color: #1fa463; }
  &.out-of-stock { background: rgba(231, 76, 60, 0.15); color: #e74c3c; }
}

// Diff page: tab content sits in a white box connected to the tabs, exactly like #diff-ui on
// the text-diff page. This is the readable surface for the graph/table/screenshot, and it sets
// the theme text colour so the chart's labels/line (currentColor) contrast (the parent .box
// uses white text, which would be invisible on this light surface).
#restock-tabs {
  background: var(--color-background);
  color: var(--color-text);
  padding: 1rem;
  border-radius: 5px;

  // Current-screenshot pane: centre the image like the text-diff page does.
  .tab-pane-inner#screenshot {
    text-align: center;
    img { max-width: 99%; }
  }
}

#restock-graph {
  margin-top: 1rem;
  box-sizing: border-box;   // width:100% (from .js-restock-graph) + padding must fit the parent

  // On wide screens, cap the chart width and centre it so it doesn't stretch too far.
  @media (min-width: 1200px) {
    max-width: 80%;
    margin-left: auto;
    margin-right: auto;
  }
}

.js-restock-graph {
  position: relative;
  width: 100%;
  // The SVG is drawn at a measured pixel width; on shrink it would otherwise overflow and
  // cause horizontal page scroll until the (debounced) resize redraw. max-width:100% caps it
  // to the container so it never pushes the viewport wider (brief squish during an active
  // resize, then the redraw restores the correct width).
  svg { display: block; max-width: 100%; }
  .rg-axis { stroke: var(--color-border-notification, rgba(127, 127, 127, 0.4)); stroke-width: 1; }
  .rg-label { fill: currentColor; opacity: 0.7; font-size: 12px; }
  // Neutral single-colour price line; stock status is shown by the dot colours, not the line.
  .rg-line { stroke: currentColor; opacity: 0.55; }
  // Surface-coloured ring so the bigger stock dots sit clearly on top of the line.
  .rg-dot { stroke: var(--color-background, #fff); stroke-width: 1.5; }

  .rg-legend {
    display: flex;
    justify-content: center;
    gap: 1.1rem;
    margin-top: 0.4rem;
    font-size: 0.78rem;
    opacity: 0.85;

    .rg-legend-item { display: inline-flex; align-items: center; gap: 0.35rem; }
    .rg-legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
    .rg-legend-dot.in { background: #1fa463; }
    .rg-legend-dot.out { background: #e74c3c; }
  }

  // Header row above the graph: status pill (left) and summary stats (right) on one line.
  .rg-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
  }

  .rg-stats {
    font-size: 0.8rem;
    opacity: 0.7;
    text-align: right;
    margin-left: auto;   // pin to the right even when the pill is absent
  }

  // Analyser overlays: typical-range band + dashed average line.
  .rg-band { fill: rgba(120, 130, 150, 0.14); }
  .rg-avg-line { stroke: var(--color-text, #555); opacity: 0.45; stroke-width: 1; }
  .rg-avg-text { opacity: 0.5; }
}

// "Currently low/typical/high" pill above the graph (Google-Flights style).
.rg-status {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
  padding: 0.2rem 0.6rem;
  border-radius: 1rem;
  font-size: 0.85rem;

  .rg-status-label { font-weight: 700; }
  .rg-status-sub { font-size: 0.78rem; opacity: 0.8; }

  &.rg-status-low { background: rgba(31, 164, 99, 0.16); color: #1fa463; }
  &.rg-status-typical { background: rgba(120, 130, 150, 0.16); color: var(--color-text, #555); }
  &.rg-status-high { background: rgba(231, 76, 60, 0.16); color: #e74c3c; }
}

.rg-tooltip {
  position: absolute;
  display: none;
  pointer-events: none;
  z-index: 5;
  transform: translateY(-50%);
  white-space: nowrap;
  background: var(--color-background, #fff);
  color: var(--color-text, #222);
  border: 1px solid var(--color-border-notification, rgba(127, 127, 127, 0.4));
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 12px;
  line-height: 1.4;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

#restock-history-table {
  margin-left: auto;   // centre the table horizontally within its container
  margin-right: auto;

  td, th { text-align: left; }
}

.restock-table-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;   // centre the title + download link above the centred table
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

// ── Watchlist: restock rows keep the "History" button even in AI mode ──
// (AI mode swaps History->Summary for LLM watches; restock has its own graph roll-down instead.)
html[data-ai-mode="true"] body.llm-configured tr.processor-restock_diff {
  .btn-label-history { display: inline; }
  .btn-label-summary { display: none; }
}

// ── Watchlist: inline restock graph roll-down (mirrors .ai-inline-summary-row, teal/green) ──
.restock-inline-row {
  td {
    white-space: normal !important;
    word-break: break-word;
    padding: 0.6rem 1rem 0.8rem 1.4rem !important;
    background: linear-gradient(135deg, #e6fbf0, #e8f6ff) !important;
    border-top: 1px solid #9fe3c2 !important;
    border-left: 3px solid #1fa463 !important;
    color: #06281a !important;
    line-height: 1.5;
  }

  html[data-darkmode="true"] & td {
    background: linear-gradient(135deg, #0c2a1c, #0d2230) !important;
    border-top: 1px solid #1f5e40 !important;
    border-left-color: #1fa463 !important;
    color: #d6ffe9 !important;
  }

  .restock-inline-graph {
    width: 100%;
    min-height: 40px;
  }

  .restock-inline-history-link {
    display: inline-block;
    margin-top: 0.5rem;
    font-size: 0.78rem;
    font-weight: 700;
    opacity: 0.75;
    white-space: nowrap;

    &:hover { opacity: 1; }
  }

  .restock-inline-error { color: #c0392b; }
}
