/* ═══════════════════════════════════════════════════════
   CANSLIM Market Monitor — v1.0.14
   8-ETF layout: 4 × 2 on desktop, 2 on tablet, 1 on mobile
   Charts: PHP GD PNG images (no TradingView)
   IBD Distribution Day + Follow-Through Day
   DeepSeek FT-style commentary
═══════════════════════════════════════════════════════ */

/* ── Design tokens (FT palette) ── */
:root {
  --cmm-bg:      #FFF1E5;
  --cmm-bg2:     #F2DFCE;
  --cmm-fg:      #33302E;
  --cmm-mid:     #66605C;
  --cmm-muted:   #9E9890;
  --cmm-rule:    #E6D9CE;
  --cmm-claret:  #990F3D;
  --cmm-teal:    #0D7680;
  --cmm-bear:    #CC0000;
  --cmm-bull:    #006E3A;
  --cmm-neut:    #E06B00;

  /* DD risk colours */
  --cmm-dd-high: #CC0000;   /* ≥ 6 days */
  --cmm-dd-med:  #E06B00;   /* 4–5 days */
  --cmm-dd-low:  #006E3A;   /* 0–3 days */
}

/* ── Widget wrapper ── */
.cmm-widget {
  background: var(--cmm-bg);
  border: 1px solid var(--cmm-rule);
  border-top: 3px solid var(--cmm-claret);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
  color: var(--cmm-fg);
}

/* ── Inline shortcode / content-filter variant ── */
/* Full-width breakout: match theme block max-width, flush left/right */
.cmm-widget-inline {
  display: block;
  position: relative;
  width: 100vw;
  left: 50%;
  transform: translateX(-50%);
  max-width: 100vw;
  box-sizing: border-box;
}
.cmm-widget-inline .cmm-widget {
  width: 100%;
  max-width: 100%;
  margin: 0;
  box-sizing: border-box;
}

/* ── Lightbox overlay ── */
.cmm-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: rgba(0,0,0,.85);
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.cmm-lightbox.cmm-lb-open {
  display: flex;
}
.cmm-lightbox img {
  max-width: 95vw;
  max-height: 90vh;
  width: auto;
  height: auto;
  display: block;
  border: 2px solid #FFF1E5;
  image-rendering: auto;
}
.cmm-lightbox-close {
  position: fixed;
  top: 14px;
  right: 18px;
  font-size: 28px;
  color: #FFF1E5;
  cursor: pointer;
  line-height: 1;
  user-select: none;
}

/* Chart image clickable cursor */
.cmm-chart-img {
  cursor: zoom-in;
}

/* ── Header ── */
.cmm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 13px 7px;
  border-bottom: 1px solid var(--cmm-rule);
}
.cmm-title {
  font-family: Georgia, serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--cmm-fg);
  margin: 0;
  padding: 0;
  border: none;
  display: block;
  /* prevent title from overlapping price badge */
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding-right: 8px;
}
.cmm-updated {
  font-size: 10px;
  color: var(--cmm-muted);
}

/* ════════════════════════════════════════════════════
   HORIZONTAL CHART ROW — 8 columns
   Desktop ≥1200: 4 columns per row (2 rows of 4)
   Tablet  ≤900: 2 columns
   Mobile  ≤480: 1 column
════════════════════════════════════════════════════ */
.cmm-chart-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--cmm-gap-v, 0px) var(--cmm-gap-h, 0px);
  box-sizing: border-box;
  border-bottom: 1px solid var(--cmm-rule);
}

/* Each ETF panel */
.cmm-etf-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--cmm-rule);
  min-width: 0;
}
.cmm-etf-panel:nth-child(4n) {
  border-right: 0;
}
.cmm-etf-panel:nth-child(-n+4) {
  border-bottom: 1px solid var(--cmm-rule);
}

/* ETF label bar */
.cmm-etf-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  background: var(--cmm-bg2);
  border-bottom: 1px solid var(--cmm-rule);
}
.cmm-etf-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--cmm-claret);
}

/* ── Price + % change badge (upper right of label bar) ── */
.cmm-price-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 600;
  color: var(--cmm-fg);
  flex-shrink: 0;
}
.cmm-price-val {
  font-variant-numeric: tabular-nums;
}
.cmm-chg-pos {
  color: var(--cmm-bull);
}
.cmm-chg-neg {
  color: var(--cmm-bear);
}
.cmm-chg-flat {
  color: var(--cmm-muted);
}

/* ── Chart image area ── */
.cmm-chart-wrap {
  width: 100%;
  /* NO fixed height — let the 2× retina PNG define its own height */
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
  background: var(--cmm-bg);
  line-height: 0;  /* remove img bottom-gap */
}

/* PHP GD PNG chart fills the wrap */
.cmm-chart-img {
  width: 100%;
  height: auto;
  display: block;
  image-rendering: auto;
}

/* ── Loading / error placeholder inside chart wrap ── */
.cmm-chart-placeholder {
  width: 100%;
  height: 155px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--cmm-muted);
  background: var(--cmm-bg);
}

/* ════════════════════════════════════════════════════
   COMMENTARY  — FT paragraph style
════════════════════════════════════════════════════ */
.cmm-commentary {
  font-size: 8px;
  color: var(--cmm-fg);
  line-height: 1.65;
  padding: 5px 8px 4px;
  border-top: 1px solid var(--cmm-rule);
  font-style: italic;
  background: var(--cmm-bg);
  flex: 1;
  min-height: 30px;
}
.cmm-commentary-src {
  font-size: 7px;
  color: var(--cmm-muted);
  font-style: normal;
  display: block;
  margin-top: 2px;
}

/* ════════════════════════════════════════════════════
   DISTRIBUTION DAYS + FOLLOW-THROUGH DAY ROW
════════════════════════════════════════════════════ */
.cmm-dd-row {
  display: flex;
  flex-direction: column;
  padding: 5px 7px 6px;
  gap: 3px;
  border-top: 1px solid var(--cmm-rule);
}

.cmm-dd-block,
.cmm-ftd-block {
  display: flex;
  align-items: baseline;
  gap: 5px;
  flex-wrap: wrap;
  min-width: 0;
}

/* Section label */
.cmm-dd-lbl {
  font-size: 7.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--cmm-muted);
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.3;
}

/* Distribution count badge */
.cmm-dd-count {
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
  flex-shrink: 0;
}
.cmm-dd-high { color: var(--cmm-dd-high); }
.cmm-dd-med  { color: var(--cmm-dd-med);  }
.cmm-dd-low  { color: var(--cmm-dd-low);  }

/* Status text */
.cmm-dd-status {
  font-size: 7.5px;
  color: var(--cmm-mid);
  font-style: italic;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Individual DD dates row */
.cmm-dd-dates {
  font-size: 7px;
  color: var(--cmm-bear);
  font-weight: 600;
  letter-spacing: .02em;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-left: 1px;
}

/* Follow-Through Day value */
.cmm-ftd-val {
  font-size: 8px;
  color: var(--cmm-bull);
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cmm-ftd-val.cmm-ftd-fail {
  color: var(--cmm-muted);
  text-decoration: line-through;
}

.cmm-dd-empty {
  font-size: 10px;
  color: var(--cmm-muted);
}

/* ── Footer ── */
.cmm-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 11px;
  font-size: 9px;
  color: var(--cmm-muted);
  border-top: 1px solid var(--cmm-rule);
}

/* ════════════════════════════════════
   RESPONSIVE
════════════════════════════════════ */

/* Tablet: 2 columns */
@media (max-width: 900px) {
  .cmm-chart-row {
    grid-template-columns: repeat(2, 1fr);
  }
  .cmm-etf-panel:nth-child(4n) {
    border-right: 1px solid var(--cmm-rule);
  }
  .cmm-etf-panel:nth-child(2n) {
    border-right: 0;
  }
  .cmm-etf-panel:nth-child(-n+4) {
    border-bottom: 0;
  }
  .cmm-etf-panel:not(:nth-last-child(-n+2)) {
    border-bottom: 1px solid var(--cmm-rule);
  }
}

/* Mobile: 1 column */
@media (max-width: 480px) {
  .cmm-chart-row {
    grid-template-columns: 1fr;
  }
  .cmm-etf-panel {
    border-right: 0;
    border-bottom: 1px solid var(--cmm-rule);
  }
  .cmm-etf-panel:last-child {
    border-bottom: 0;
  }
  .cmm-etf-panel:nth-child(4n),
  .cmm-etf-panel:nth-child(2n) {
    border-right: 0;
  }
  .cmm-etf-panel:nth-child(-n+4) {
    border-bottom: 1px solid var(--cmm-rule);
  }
  .cmm-commentary {
    font-size: 9px;
  }
}
