/* ============================================================================
   Product Summary card (v2) — token-based, one calm surface.
   Structure comes from weight + spacing + dividers, NOT tint. Semantic color is
   reserved for small carriers (score-band gauge, alignment rules, status tags).
   Used by home (short), products (detail), and the directory modal (detail).
   ========================================================================== */

.pcard { padding: 0; overflow: visible; }

/* Product modal (directory): drop W3.CSS's .w3-container side padding (16px) so the detail
   card fills the modal width — the card already supplies its own internal padding. */
#productModal .w3-container { padding: 0; }

/* Inside the modal, give the card a little top breathing room (clears the close button). */
.w3-modal-content .pcard { padding-top: var(--space-4); }

/* Modal close button — a subtle design-system icon button, top-right of the modal surface
   (.w3-modal-content is position:relative), replacing W3.CSS's red × button. */
.modal-close { position: absolute; top: var(--space-3); right: var(--space-3); z-index: 1; }

/* Stacked short cards (home dashboard) — even vertical rhythm between cards. */
.pcard-stack { display: flex; flex-direction: column; gap: var(--space-5); }

/* --- Header ------------------------------------------------------------- */
.pcard__head { padding: var(--space-5) var(--space-5) var(--space-4); }
.pcard__head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-5);
  flex-wrap: wrap;
}
.pcard__head-left { flex: 1 1 240px; min-width: 0; }
.pcard__title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
}
.pcard__title a { color: var(--text); text-decoration: none; }
.pcard__title a:hover { color: var(--primary-text); }
.pcard__title .cc-icon { color: var(--text-subtle); }
.pcard__index { color: var(--text-subtle); }
.pcard__links { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-3); }
.pcard__repo {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--primary-text); text-decoration: none; font-size: var(--text-sm);
}
.pcard__repo:hover { text-decoration: underline; }

/* --- Status tags (the only place small semantic color lives in the header) */
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: var(--weight-medium); white-space: nowrap;
}
.tag .cc-icon { width: 0.95em; height: 0.95em; }
.tag--ok     { background: var(--success-subtle); color: var(--success-text); }
.tag--muted  { background: var(--bg-subtle);      color: var(--text-muted); }
.tag--warn   { background: var(--warning-subtle); color: var(--warning-text); }
.tag--danger { background: var(--danger-subtle);  color: var(--danger-text); }

/* --- Right to Win — single compact line, right-aligned in the header ----- */
.rtw { flex: 0 0 auto; display: inline-flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; justify-content: flex-end; }
.rtw__label {
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted);
}
.rtw__score { display: inline-flex; align-items: baseline; gap: 1px; font-family: var(--font-mono); line-height: 1; }
.rtw__score b { font-size: var(--text-xl); font-weight: var(--weight-bold); }
.rtw__score span { font-size: var(--text-sm); color: var(--text-subtle); }
.rtw__gauge { width: 48px; height: 5px; background: var(--bg-subtle); border-radius: var(--radius-full); overflow: hidden; }
.rtw__gauge i { display: block; height: 100%; border-radius: inherit; }
.rtw__verdict { font-size: var(--text-sm); font-weight: var(--weight-medium); }

.band-high .rtw__score b, .band-high .rtw__verdict { color: var(--success-text); }
.band-high .rtw__gauge i { background: var(--success); }
.band-med  .rtw__score b, .band-med  .rtw__verdict { color: var(--warning-text); }
.band-med  .rtw__gauge i { background: var(--warning); }
.band-low  .rtw__score b, .band-low  .rtw__verdict { color: var(--danger-text); }
.band-low  .rtw__gauge i { background: var(--danger); }

/* --- Lede / summary (full width, below the header) ---------------------- */
.pcard__lede-wrap { padding: 0 var(--space-5) var(--space-5); min-width: 0; }
.pcard__lede { color: var(--text-muted); font-size: var(--text-base); line-height: var(--leading-relaxed); overflow-wrap: anywhere; word-break: break-word; }
.pcard__lede p { margin: 0 0 var(--space-2); }
.pcard__lede p:last-child { margin-bottom: 0; }
.pcard__lede.is-clamped { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Right-to-Win reasoning — clearly labelled, accented in the score band colour */
.pcard__why { margin-top: var(--space-4); padding-left: var(--space-3); border-left: 3px solid var(--border-strong); }
.pcard__lede-wrap > .pcard__why:first-child { margin-top: 0; }
.pcard__why.band-high { border-left-color: var(--success); }
.pcard__why.band-med  { border-left-color: var(--warning); }
.pcard__why.band-low  { border-left-color: var(--danger); }
.pcard__why-label {
  display: block; font-size: var(--text-xs); font-weight: var(--weight-semibold);
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 3px;
}
.pcard__why-text { color: var(--text-muted); font-size: var(--text-sm); line-height: var(--leading-relaxed); overflow-wrap: anywhere; }
.pcard__why-text p { margin: 0; }

/* --- Chapters (lightweight labeled dividers; only render when populated) - */
.pchapter { border-top: 1px solid var(--border); padding: var(--space-5); }
.pchapter__title {
  margin: 0 0 var(--space-4);
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-subtle);
}

/* --- Metrics: ONE consistent presentation ------------------------------- */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--space-3); }
.metric { position: relative; background: var(--bg-subtle); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-3); }
.metric__name {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); margin-bottom: 4px;
}
.metric__name > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.metric__value { font-size: var(--text-lg); font-weight: var(--weight-bold); color: var(--text); line-height: 1.2; }

/* Per-metric info affordance — sits at the top-right of the metric, on the
   name row (only present when the metric has a description). */
.metric__info {
  display: none; flex-shrink: 0; align-items: center; justify-content: center;
  width: 15px; height: 15px; padding: 0; border: none; background: none;
  color: var(--text-subtle); cursor: help;
}
.metric__info .cc-icon { width: 14px; height: 14px; }
.metric__info:hover, .metric__info:focus-visible { color: var(--primary-text); }

/* Base description (inline fallback look) */
.metric__desc { margin-top: 6px; font-size: var(--text-xs); color: var(--text-subtle); line-height: 1.45; }

/* --- Metric-info display mode (toggle with "i"; persisted) ---------------
   Default = compact 'tooltip' (info icon + reveal on hover/focus).
   'inline' = print the description text under the value (no icon). */
:root[data-metric-info="inline"] .metric__info { display: none; }

:root[data-metric-info="tooltip"] .metric__info { display: inline-flex; }
:root[data-metric-info="tooltip"] .metric__desc {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 60;
  margin-top: 0; padding: var(--space-2) var(--space-3);
  background: var(--gray-900); color: var(--gray-25);
  border-radius: var(--radius-md); box-shadow: var(--shadow-md);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity var(--transition-fast), visibility var(--transition-fast);
}
:root[data-metric-info="tooltip"] .metric:hover .metric__desc,
:root[data-metric-info="tooltip"] .metric:focus-within .metric__desc { opacity: 1; visibility: visible; }

/* --- Economics stat row ------------------------------------------------- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: var(--space-4); margin-bottom: var(--space-4); }
.stat__label { font-size: var(--text-xs); color: var(--text-muted); margin-bottom: 2px; }
.stat__value { font-size: var(--text-lg); font-weight: var(--weight-bold); }
.stat__value small { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text-muted); }
.stat__sub { margin-top: var(--space-2); font-size: var(--text-xs); color: var(--text-subtle); }

.pchart { margin-bottom: var(--space-4); }
.pchart h4 { margin: 0 0 var(--space-3); font-size: var(--text-sm); color: var(--text-muted); font-weight: var(--weight-semibold); }
.pchart__canvas { position: relative; height: 240px; }
@media (max-width: 600px) { .pchart__canvas { height: 200px; } }

/* --- Disclosure (collapsible subsection) -------------------------------- */
.disclosure { border: 1px solid var(--border); border-radius: var(--radius-md); margin-top: var(--space-3); }
.disclosure__head {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3); cursor: pointer; user-select: none;
  font-size: var(--text-base); font-weight: var(--weight-medium); color: var(--text);
}
.disclosure__head:hover { background: var(--surface-hover); border-radius: inherit; }
.disclosure__head .cc-icon { color: var(--text-subtle); transition: transform var(--transition-fast); }
.disclosure__head .count { margin-left: auto; }
.disclosure.is-open > .disclosure__head .cc-icon-toggle { transform: rotate(90deg); }
.disclosure__body { display: none; padding: 0 var(--space-3) var(--space-3); font-size: var(--text-sm); color: var(--text-muted); line-height: var(--leading-relaxed); }
.disclosure.is-open > .disclosure__body { display: block; }
.disclosure__body :is(h1,h2,h3,h4) { font-size: var(--text-base); color: var(--text); }
.disclosure__body code { background: var(--bg-subtle); padding: 1px 5px; border-radius: var(--radius-sm); font-family: var(--font-mono); font-size: 0.9em; }

/* Sub-box inside a disclosure (e.g. Current Project Focus) */
.subbox { margin-top: var(--space-3); padding: var(--space-3); background: var(--bg-subtle); border-left: 3px solid var(--border-strong); border-radius: var(--radius-sm); }
.subbox__title { font-size: var(--text-xs); font-weight: var(--weight-semibold); text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); margin-bottom: 4px; }
.subbox__body { color: var(--text); }

/* --- Roadmap items: neutral surface + alignment left-rule + small tag ---- */
.road-item { border: 1px solid var(--border); border-left: 3px solid var(--border-strong); border-radius: var(--radius-md); padding: var(--space-3); margin-bottom: var(--space-2); }
.road-item.align-high { border-left-color: var(--success); }
.road-item.align-med  { border-left-color: var(--warning); }
.road-item.align-low  { border-left-color: var(--danger); }
.road-item__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); cursor: pointer; user-select: none; }
.road-item__title { display: flex; align-items: center; gap: var(--space-2); font-weight: var(--weight-medium); }
.road-item__title .cc-icon { color: var(--text-subtle); transition: transform var(--transition-fast); }
.road-item.is-open .road-item__title .cc-icon-toggle { transform: rotate(90deg); }
.road-item__body { display: none; margin-top: var(--space-3); font-size: var(--text-sm); color: var(--text-muted); line-height: var(--leading-relaxed); }
.road-item.is-open .road-item__body { display: block; }
.road-item__notes { margin-top: var(--space-2); padding: var(--space-2) var(--space-3); background: var(--warning-subtle); border-radius: var(--radius-sm); color: var(--text); }

/* --- Card footer: when the card data was generated + model used ---------- */
.pcard__foot {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4);
  border-top: 1px solid var(--border); padding: var(--space-3) var(--space-5);
  font-size: var(--text-xs); color: var(--text-subtle);
}
.pcard__foot-item { display: inline-flex; align-items: center; gap: 6px; }
.pcard__foot-item .cc-icon { color: var(--text-subtle); }

@media (max-width: 600px) {
  .pcard__head, .pcard__lede-wrap, .pchapter, .pcard__foot { padding-left: var(--space-4); padding-right: var(--space-4); }
  .rtw { justify-content: flex-start; }
}
