@layer commonpub {
/* ===========================================
   CommonPub Layout Patterns — layouts.css
   Reusable layout classes used across all pages.
   All values use CSS custom properties from base.css.
   =========================================== */

/* ─── PAGE GRIDS ─── */
.cpub-page-grid {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: var(--space-6);
}

.cpub-page-grid-3col {
  display: grid;
  grid-template-columns: 220px 1fr 260px;
  gap: var(--space-6);
}

@media (max-width: 1024px) {
  .cpub-page-grid { grid-template-columns: 1fr; }
  .cpub-page-grid-3col { grid-template-columns: 1fr; }
}

/* ─── HERO ─── */
.cpub-hero {
  padding: var(--space-8) 0;
  border-bottom: var(--border-width-default) solid var(--border2);
  margin-bottom: var(--space-6);
}

.cpub-hero-title {
  font-size: var(--text-2xl);
  font-weight: var(--font-weight-bold);
  margin-bottom: var(--space-2);
  line-height: var(--leading-tight);
}

.cpub-hero-subtitle {
  font-size: var(--text-md);
  color: var(--text-dim);
  line-height: var(--leading-relaxed);
  margin-bottom: var(--space-4);
}

.cpub-hero-actions {
  display: flex;
  gap: var(--space-3);
}

/* ─── SECTIONS ─── */
.cpub-section {
  margin-bottom: var(--space-8);
}

.cpub-section-title {
  font-family: var(--font-mono);
  font-size: var(--text-label);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-widest);
  color: var(--text-faint);
  margin-bottom: var(--space-4);
}

.cpub-section-title-lg {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-bold);
  font-family: var(--font-sans);
  text-transform: none;
  letter-spacing: var(--tracking-normal);
  color: var(--text);
  margin-bottom: var(--space-4);
}

.cpub-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.cpub-section-header .cpub-section-title {
  margin-bottom: 0;
}

.cpub-view-all {
  font-size: var(--text-xs);
  color: var(--accent);
  text-decoration: none;
  font-weight: var(--font-weight-medium);
}

.cpub-view-all:hover {
  text-decoration: underline;
}

/* ─── RESPONSIVE GRIDS ─── */
.cpub-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4);
}

.cpub-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}

.cpub-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
}

@media (max-width: 1024px) {
  .cpub-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .cpub-grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .cpub-grid-4,
  .cpub-grid-3,
  .cpub-grid-2 { grid-template-columns: 1fr; }
}

/* ─── FEED LIST ─── */
.cpub-feed-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}

@media (max-width: 1024px) {
  .cpub-feed-list { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .cpub-feed-list { grid-template-columns: 1fr; }
}

/* ─── SIDEBAR ─── */
.cpub-sidebar-section {
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-6);
  border-bottom: var(--border-width-thin) solid var(--border2);
}

.cpub-sidebar-section:last-child {
  border-bottom: none;
}

.cpub-sidebar-heading {
  font-family: var(--font-mono);
  font-size: var(--text-label);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-widest);
  color: var(--text-faint);
  margin-bottom: var(--space-3);
}

/* ─── STAT BAR ─── */
.cpub-stat-bar {
  display: flex;
  /* Wrap on narrow screens — a profile stat bar can hold 6 items (projects,
     followers, following, posts, views, likes) which otherwise overflow the
     viewport horizontally on mobile (no per-consumer media query reaches these
     globally-styled items — the profile page's `.cpub-profile-stat` rule doesn't
     apply across the StatBar component boundary). */
  flex-wrap: wrap;
  gap: var(--space-6);
  padding: var(--space-4) 0;
}

@media (max-width: 480px) {
  .cpub-stat-bar {
    gap: var(--space-4) var(--space-5);
  }
}

.cpub-stat-bar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.cpub-stat-bar-value {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-bold);
  color: var(--text);
  font-family: var(--font-mono);
}

.cpub-stat-bar-label {
  font-size: var(--text-xs);
  /* --text-dim (not --text-faint) to clear WCAG AA 4.5:1 on --surface2 in both
     themes; --text-faint was 2.30:1 (light). See theme-contrast.test.ts. */
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  font-family: var(--font-mono);
}

/* ─── TAB BAR ─── */
.cpub-tab-bar {
  display: flex;
  gap: 0;
  border-bottom: var(--border-width-default) solid var(--border);
  position: sticky;
  top: var(--nav-height);
  background: var(--bg);
  z-index: var(--z-sticky);
}

.cpub-tab {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-dim);
  text-decoration: none;
  border-bottom: var(--border-width-default) solid transparent;
  margin-bottom: -2px;
  transition: color var(--transition-fast), border-color var(--transition-fast);
  cursor: pointer;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: inherit;
}

.cpub-tab:hover {
  color: var(--text);
}

.cpub-tab.active,
.cpub-tab[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: var(--font-weight-medium);
}

/* ─── EMPTY STATE ─── */
.cpub-empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-4);
  color: var(--text-faint);
}

.cpub-empty-state-icon {
  font-size: var(--text-3xl);
  margin-bottom: var(--space-4);
  opacity: 0.3;
}

.cpub-empty-state-title {
  font-size: var(--text-md);
  color: var(--text-dim);
  margin-bottom: var(--space-2);
}

.cpub-empty-state-desc {
  font-size: var(--text-sm);
  color: var(--text-faint);
}

/* ─── BADGE ─── */
.cpub-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: var(--text-xs);
  font-weight: var(--font-weight-medium);
  border: var(--border-width-default) solid var(--border2);
  background: var(--surface2);
  color: var(--text-dim);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

.cpub-badge-accent { background: var(--accent-bg); color: var(--accent); border-color: var(--accent-border); }
.cpub-badge-green { background: var(--green-bg); color: var(--green-text); border-color: var(--green-border); }
.cpub-badge-yellow { background: var(--yellow-bg); color: var(--yellow-text); border-color: var(--yellow-border); }
.cpub-badge-red { background: var(--red-bg); color: var(--red-text); border-color: var(--red-border); }
.cpub-badge-purple { background: var(--purple-bg); color: var(--purple-text); border-color: var(--purple-border); }
.cpub-badge-teal { background: var(--teal-bg); color: var(--teal-text); border-color: var(--teal-border); }
.cpub-badge-pink { background: var(--pink-bg); color: var(--pink-text); border-color: var(--pink-border); }

/* ─── CARD ─── */
.cpub-card {
  background: var(--surface);
  border: var(--border-width-default) solid var(--border);
  overflow: hidden;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  /* Glass treatment hook — `none` default is a true no-op. */
  -webkit-backdrop-filter: var(--surface-backdrop, none);
  backdrop-filter: var(--surface-backdrop, none);
}

.cpub-card:hover {
  transform: translate(-2px, -2px);
  box-shadow: var(--shadow-md);
}

.cpub-card-body {
  padding: var(--space-4);
}

/* ─── TOOLBAR ─── */
.cpub-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--surface);
  border: var(--border-width-default) solid var(--border);
}

/* ─── FILTER BAR ─── */
.cpub-filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.cpub-filter-chip {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-dim);
  border: var(--border-width-default) solid var(--border2);
  background: var(--surface);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: inherit;
}

.cpub-filter-chip:hover {
  border-color: var(--border);
  color: var(--text);
}

.cpub-filter-chip.active,
.cpub-filter-chip[aria-pressed="true"] {
  background: var(--accent);
  color: var(--color-on-accent);
  border-color: var(--accent);
}

/* ─── FIXED OVERLAY SURFACE ─── */
/*
 * An element docked over the page (a consent banner, a mobile action bar) must
 * be OPAQUE. `--surface` alone is not enough: a theme may legitimately define
 * it with alpha for in-flow cards (the deveco theme uses 0.88), and page
 * content then shows through the bar and makes its text hard to read.
 * Compositing the surface tint over an opaque `--bg` keeps the theme's colour
 * while guaranteeing coverage, with no hardcoded value.
 */
.cpub-overlay-surface {
  background-color: var(--bg);
  background-image: linear-gradient(var(--surface), var(--surface));
}

/* ─── BUTTONS (shared) ─── */
.cpub-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: var(--border-width-default) solid var(--border);
  cursor: pointer;
  font-family: var(--font-sans);
  font-weight: var(--font-weight-medium);
  transition: all var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-4);
  background: var(--surface);
  color: var(--text);
  /* Without these, a <button class="cpub-btn"> inherits the UA button font
     shorthand's `line-height: normal` (~37px tall) while an <a class="cpub-btn">
     inherits body's --leading-normal 1.7 (~44px). Side by side in one flex row
     — which is every CTA row in the app — they visibly disagreed. 44px is the
     height .cpub-btn-sm already declares, so this makes the base match the
     house decision instead of contradicting it. */
  min-height: 44px;
  line-height: var(--leading-snug);
}

.cpub-btn:hover {
  background: var(--surface2);
}

.cpub-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cpub-btn-primary {
  background: var(--accent);
  color: var(--color-on-accent);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.cpub-btn-primary:hover {
  box-shadow: var(--shadow-md);
  transform: translate(-1px, -1px);
}

.cpub-btn-sm {
  padding: 4px 10px;
  font-size: var(--text-xs);
  min-height: 44px;
}

/* Dense row actions (admin tables, chip rows). Was declared only in page-scoped
   CSS which set padding + font-size but no height, so when .cpub-btn gained a
   44px floor these 10px-font buttons inflated into slabs — scoped specificity
   beat the base for padding but there was nothing to override min-height.
   28px is the honest size for this control; it is below the 44px touch target
   and is therefore for pointer-dense admin surfaces only. */
.cpub-btn-xs {
  padding: 3px 8px;
  font-size: 10px;
  min-height: 28px;
}

.cpub-btn-lg {
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-base);
}

.cpub-btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}

.cpub-btn-ghost:hover {
  background: var(--surface2);
  color: var(--text);
}

/* ─── LINK ─── */
.cpub-link {
  color: var(--accent);
  text-decoration: none;
}

.cpub-link:hover {
  text-decoration: underline;
}

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 0; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
}
