/* TPS Civic Widgets — namespaced, theme-adaptive styles.
   Everything is scoped under .tpscw so it never leaks into the host theme.

   Specificity: card-internal rules are written as `.tpscw .tpscw-*` (two
   classes = 0,2,x) so they out-specify common host content-wrapper rules like
   `.entry-content h3` / `.brz-rich-text h3` / `.entry-content img` (0,1,1).
   Single-class widget rules would only tie those and lose on source order.
   (Theme rules using `!important` are out of scope — the documented
   `--tpscw-*-override` CSS vars are the supported way to retune colors.)

   Override hooks (set these in Brizy / theme custom CSS):
     .tpscw { --tpscw-surface-override: #fff; --tpscw-ink-override: #111;
              --tpscw-muted-override: #666;  --tpscw-border-override: rgba(0,0,0,.1);
              --tpscw-radius-override: 12px; }
   Dark placement:
     add the `theme="dark"` shortcode attr (emits .tpscw--dark), or set the
     *-override vars above to a dark palette. See PLUGIN-GUIDE.md. */

/* ---- Palette tokens -------------------------------------------------------
   A card has its own background, so surface + ink + muted + border are ONE
   palette that flips together. Defaults are light; .tpscw--dark flips the set.
   Never derive ink from `currentColor` while surface is fixed — that inverts
   on dark sections (light text on a white card). */
.tpscw {
  --tpscw-surface: var(--tpscw-surface-override, #fff);
  --tpscw-ink: var(--tpscw-ink-override, #1f2937);
  --tpscw-muted: var(--tpscw-muted-override, #5b6b6b);
  --tpscw-border: var(--tpscw-border-override, rgba(0, 0, 0, 0.1));
  --tpscw-radius: var(--tpscw-radius-override, 12px);
  --tpscw-done: var(--tpscw-done-override, #16a34a);
  --tpscw-pill: var(--tpscw-pill-override, #0f172a);
  --tpscw-pill-ink: var(--tpscw-pill-ink-override, #fff);
  --tpscw-shadow: var(--tpscw-shadow-override, 0 1px 2px rgba(0, 0, 0, 0.06));
  --tpscw-shadow-hover: var(--tpscw-shadow-hover-override, 0 8px 24px rgba(0, 0, 0, 0.12));
  --tpscw-focus: var(--tpscw-focus-override, currentColor);

  color: var(--tpscw-ink);
  font-family: inherit;
}

/* Whole-palette flip for dark placements (theme="dark"). */
.tpscw--dark {
  --tpscw-surface: var(--tpscw-surface-override, #111827);
  --tpscw-ink: var(--tpscw-ink-override, #e5e7eb);
  --tpscw-muted: var(--tpscw-muted-override, #9ca3af);
  --tpscw-border: var(--tpscw-border-override, rgba(255, 255, 255, 0.16));
  --tpscw-pill: var(--tpscw-pill-override, #e5e7eb);
  --tpscw-pill-ink: var(--tpscw-pill-ink-override, #0f172a);
  --tpscw-shadow: var(--tpscw-shadow-override, 0 1px 2px rgba(0, 0, 0, 0.4));
  --tpscw-shadow-hover: var(--tpscw-shadow-hover-override, 0 8px 24px rgba(0, 0, 0, 0.5));
}

/* Optional OS-driven mode (theme="auto"). Note: tracks the VISITOR's OS, not
   the Brizy section — can clash with a light page. Opt-in only. */
@media (prefers-color-scheme: dark) {
  .tpscw--auto {
    --tpscw-surface: var(--tpscw-surface-override, #111827);
    --tpscw-ink: var(--tpscw-ink-override, #e5e7eb);
    --tpscw-muted: var(--tpscw-muted-override, #9ca3af);
    --tpscw-border: var(--tpscw-border-override, rgba(255, 255, 255, 0.16));
    --tpscw-pill: var(--tpscw-pill-override, #e5e7eb);
    --tpscw-pill-ink: var(--tpscw-pill-ink-override, #0f172a);
    --tpscw-shadow: var(--tpscw-shadow-override, 0 1px 2px rgba(0, 0, 0, 0.4));
    --tpscw-shadow-hover: var(--tpscw-shadow-hover-override, 0 8px 24px rgba(0, 0, 0, 0.5));
  }
}

/* ---- Defensive base ---- */
.tpscw,
.tpscw * {
  box-sizing: border-box;
}

/* ---- News grid ---- */
.tpscw-news-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
}
.tpscw .tpscw-card {
  position: relative;
  display: flex;
  flex-direction: column;
  margin: 0;
  border: 1px solid var(--tpscw-border);
  border-radius: var(--tpscw-radius);
  overflow: hidden;
  background: var(--tpscw-surface);
  box-shadow: var(--tpscw-shadow);
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease;
}
.tpscw .tpscw-card:hover,
.tpscw .tpscw-card:focus-within {
  transform: translateY(-2px);
  box-shadow: var(--tpscw-shadow-hover);
}
.tpscw .tpscw-thumb {
  display: block;
  aspect-ratio: 4 / 3;
  overflow: hidden;
}
.tpscw .tpscw-thumb img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}
.tpscw .tpscw-card:hover .tpscw-thumb img,
.tpscw .tpscw-card:focus-within .tpscw-thumb img {
  transform: scale(1.03);
}
.tpscw .tpscw-body {
  padding: 0.9rem 1rem;
}
.tpscw .tpscw-title {
  font-size: clamp(1rem, 0.95rem + 0.3vw, 1.12rem);
  line-height: 1.3;
  font-weight: 600;
  margin: 0 0 0.4rem;
  padding: 0;
}
.tpscw .tpscw-title a {
  text-decoration: none;
  color: var(--tpscw-ink);
  box-shadow: none;
}
.tpscw .tpscw-title a:hover {
  text-decoration: underline;
}
.tpscw .tpscw-meta {
  font-size: 0.8rem;
  color: var(--tpscw-muted);
  margin: 0 0 0.4rem;
  padding: 0;
}
.tpscw .tpscw-desc {
  font-size: 0.86rem;
  line-height: 1.45;
  margin: 0;
  padding: 0;
  color: var(--tpscw-ink);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Keyboard focus ring (a11y) — visible on tab, not on mouse click. */
.tpscw a:focus-visible {
  outline: 2px solid var(--tpscw-focus);
  outline-offset: 2px;
  border-radius: 4px;
}
/* The thumb link sits flush to the card edge under overflow:hidden, so draw
   its ring inside to keep all four sides visible to keyboard users. */
.tpscw .tpscw-thumb:focus-visible {
  outline-offset: -2px;
}

/* Respect reduced-motion preference. */
@media (prefers-reduced-motion: reduce) {
  .tpscw .tpscw-card,
  .tpscw .tpscw-thumb img {
    transition: none;
  }
  .tpscw .tpscw-card:hover,
  .tpscw .tpscw-card:focus-within {
    transform: none;
  }
  .tpscw .tpscw-card:hover .tpscw-thumb img,
  .tpscw .tpscw-card:focus-within .tpscw-thumb img {
    transform: none;
  }
}

/* ---- Featured strip (featured="1") ----
   Lead card spans the full grid width and lays image beside body at wider
   sizes, with a larger headline. Remaining cards flow as the normal grid. */
.tpscw.tpscw-featured .tpscw-card:first-child {
  grid-column: 1 / -1;
}
@media (min-width: 720px) {
  .tpscw.tpscw-featured .tpscw-card:first-child {
    flex-direction: row;
    align-items: stretch;
  }
  .tpscw.tpscw-featured .tpscw-card:first-child .tpscw-thumb {
    /* In the row layout the thumb stretches to the card height (align-items:
       stretch), so an aspect-ratio here would be a no-op — width only. */
    flex: 0 0 48%;
  }
  .tpscw.tpscw-featured .tpscw-card:first-child .tpscw-body {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 1.4rem 1.6rem;
  }
  .tpscw.tpscw-featured .tpscw-card:first-child .tpscw-title {
    font-size: clamp(1.3rem, 1.1rem + 1vw, 1.8rem);
  }
  .tpscw.tpscw-featured .tpscw-card:first-child .tpscw-desc {
    -webkit-line-clamp: 4;
    line-clamp: 4;
    font-size: 0.95rem;
  }
}

/* ---- Responsive tuning ---- */
@media (max-width: 420px) {
  .tpscw-news-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

/* ---- Bill tracker ---- */
.tpscw .tpscw-bt-header {
  margin-bottom: 1rem;
}
.tpscw .tpscw-bt-kicker {
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--tpscw-muted);
  margin: 0 0 0.25rem;
  font-weight: 600;
}
.tpscw .tpscw-bt-title {
  font-size: 1.4rem;
  line-height: 1.2;
  margin: 0 0 0.3rem;
}
.tpscw .tpscw-bt-desc {
  margin: 0.2rem 0;
  color: var(--tpscw-ink);
}
.tpscw .tpscw-bt-org {
  font-size: 0.78rem;
  color: var(--tpscw-muted);
  margin: 0.2rem 0 0;
}
.tpscw .tpscw-bt-list {
  display: grid;
  gap: 0.75rem;
}
.tpscw .tpscw-bt-card {
  border: 1px solid var(--tpscw-border);
  border-radius: var(--tpscw-radius);
  padding: 1rem;
  background: var(--tpscw-surface);
}
.tpscw .tpscw-bt-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.tpscw .tpscw-bt-id {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--tpscw-muted);
}
.tpscw .tpscw-bt-stage {
  background: var(--tpscw-pill);
  color: var(--tpscw-pill-ink);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.72rem;
  font-weight: 500;
  white-space: nowrap;
}
.tpscw .tpscw-bt-billtitle {
  font-size: 1rem;
  line-height: 1.3;
  margin: 0.4rem 0 0.3rem;
}
.tpscw .tpscw-bt-sponsor {
  font-size: 0.8rem;
  color: var(--tpscw-ink);
  margin: 0 0 0.5rem;
}
.tpscw .tpscw-bt-progress {
  margin: 0.6rem 0 0;
}
.tpscw .tpscw-bt-steps {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.tpscw .tpscw-bt-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #cbd5e1;
  flex: 0 0 auto;
}
.tpscw .tpscw-bt-dot.is-done {
  background: var(--tpscw-done);
}
.tpscw .tpscw-bt-bar {
  height: 4px;
  border-radius: 4px;
  background: #cbd5e1;
  flex: 1 1 auto;
}
.tpscw .tpscw-bt-bar.is-done {
  background: var(--tpscw-done);
  opacity: 0.8;
}
.tpscw .tpscw-bt-steplabels {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.3rem;
}
.tpscw .tpscw-bt-steplabels span {
  flex: 1;
  text-align: center;
  font-size: 0.66rem;
  color: var(--tpscw-muted);
}
.tpscw .tpscw-bt-latest {
  font-size: 0.82rem;
  color: var(--tpscw-ink);
  margin: 0.6rem 0 0;
}
.tpscw .tpscw-bt-link {
  display: inline-block;
  margin-top: 0.6rem;
  font-size: 0.78rem;
  text-decoration: none;
  border: 1px solid var(--tpscw-border);
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  color: var(--tpscw-ink);
}
.tpscw .tpscw-bt-link:hover {
  background: var(--tpscw-border);
}
.tpscw .tpscw-bt-empty {
  color: var(--tpscw-muted);
  font-style: italic;
}
