@import "/assets/css/style.css";

/* ==========================================================================
   Blog — App-Specific Styles
   All tokens from /assets/css/base.css. No hardcoded values.
   ========================================================================== */

/* Natural document scroll. The shared base.css body (min-height: 100dvh,
   flex column) and layout.css main provide the shell. The only thing left to
   account for is the sticky glass-header (56px tall): scroll-padding-top keeps
   anchored content — the #main skip-link target and the inline post detail
   from scrollIntoView — from landing underneath it. */
html {
  scroll-padding-top: 64px;
}

/* Visually hidden — SEO h1 kept out of the visual layout but present for
   crawlers and screen readers (the SPA grid is the visual heading). */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* No-JS fallback — static post links shown only when JavaScript is disabled.
   app.js overwrites #blogGrid when it runs, so this never renders for JS users. */
.noscript-posts {
  list-style: none;
  padding: 0;
  margin: 0;
  text-align: center;
}

.noscript-posts li {
  margin-bottom: var(--space-sm);
}

.noscript-posts a {
  color: var(--color-accent);
}

/* Blog section — grid + pagination stack. Plain flex column; the page scrolls
   naturally, nothing is pinned to the viewport. */
.blog-section {
  display: flex;
  flex-direction: column;
  width: 100%;
  gap: var(--space-md);
}

/* Fluid grid — columns adapt to the container width alone, with no media
   queries (4+ on wide screens → 1 on small phones). Unscoped on purpose:
   #blogGrid also carries class="cards" from shared pages.css, which sets fixed
   column counts; keeping this rule outside any media query lets our auto-fill
   grid always win over .cards by source order. */
.blog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr));
  gap: var(--space-md);
  width: 100%;
}

/* Blog card — quiet, bordered, same icons and labels at every size. No
   scale/shadow flourishes; hover only tints the surface. */
.blog-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
  color: var(--color-text);
  padding: var(--space-lg) var(--space-md);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--border-radius-md);
  background: var(--color-bg);
  transition: background 0.2s ease;
  min-width: 0;
  cursor: pointer;
}

.blog-card:hover {
  background: var(--color-surface);
}

.blog-card:focus-within {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Blog card icon — one consistent size on every device */
.blog-card-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text);
  margin-bottom: var(--space-sm);
}

.blog-card-icon svg {
  width: 18px;
  height: 18px;
}

/* Blog card title — clamped to two lines so it wraps cleanly at any column
   width. Note: font: shorthand, not font-size — the --text-* tokens are
   font-shorthand values (14px/1.5), so font-size: var(--text-sm) would be
   invalid and silently inherit. */
.blog-card-title {
  font: 600 var(--text-base) var(--font-sans);
  line-height: 1.35;
  letter-spacing: -0.022em;
  margin-bottom: var(--space-xs);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  max-width: 100%;
}

.blog-card-link {
  color: var(--color-text);
  text-decoration: none;
  transition: color 0.2s ease;
}

.blog-card:hover .blog-card-link,
.blog-card-link:hover {
  color: var(--color-accent);
}

/* Blog card excerpt — two lines, clipped */
.blog-card-excerpt {
  font: var(--text-sm) var(--font-sans);
  color: var(--color-text-secondary);
  width: 100%;
  text-align: center;
  margin-bottom: var(--space-xs);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Blog card meta — category badge, date, read time */
.blog-card-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  font: var(--text-xs) var(--font-sans);
  color: var(--color-text-secondary);
  flex-wrap: wrap;
  width: 100%;
}

.blog-card-category {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--border-radius-sm);
  font: 600 var(--text-xs) var(--font-sans);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #fff;
}

.blog-card-category[data-category="finance"] {
  background: var(--color-accent);
}

.blog-card-category[data-category="tech"] {
  background: var(--color-success);
}

.blog-card-date,
.blog-card-readtime {
  color: var(--color-text-secondary);
}

/* Post detail view */
.post-detail {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-md);
  width: 100%;
}

.post-detail-header {
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--color-border);
}

.post-detail-title {
  font: 700 var(--text-2xl) var(--font-sans);
  letter-spacing: -0.021em;
  line-height: 1.2;
  margin: 0 0 var(--space-sm);
}

.post-detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  font: var(--text-sm) var(--font-sans);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-md);
}

.post-detail-meta a {
  color: var(--color-accent);
}

.post-detail-body {
  font: var(--text-base) var(--font-sans);
  line-height: 1.7;
  color: var(--color-text);
}

.post-detail-body p {
  margin-bottom: 1.2em;
}

.post-detail-body h2,
.post-detail-body h3 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

.post-detail-body ul,
.post-detail-body ol {
  padding-left: var(--space-lg);
  margin-bottom: 1.2em;
}

.post-detail-body li {
  margin-bottom: var(--space-xs);
}

.post-detail-body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--color-surface);
  padding: 2px 6px;
  border-radius: var(--border-radius-sm);
}

.post-detail-body pre {
  background: var(--color-surface);
  padding: var(--space-md);
  border-radius: var(--border-radius-md);
  overflow-x: auto;
  margin-bottom: 1.2em;
}

.post-detail-body pre code {
  background: none;
  padding: 0;
}

.post-detail-body a {
  color: var(--color-accent);
}

.post-detail-body figure {
  margin: var(--space-lg) 0;
  text-align: center;
}

.post-detail-body figcaption {
  font: var(--text-sm) var(--font-sans);
  color: var(--color-text-secondary);
  margin-top: var(--space-sm);
}

.post-detail-body blockquote {
  border-left: 3px solid var(--color-accent);
  padding-left: var(--space-md);
  color: var(--color-text-secondary);
  margin: 1.2em 0;
}

.post-detail-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--border-radius-md);
}

.post-detail-body svg {
  max-width: 100%;
  height: auto;
}

.post-detail-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.2em;
  font: var(--text-sm) var(--font-sans);
}

.post-detail-body caption {
  font: var(--text-sm) var(--font-sans);
  color: var(--color-text-secondary);
  text-align: left;
  margin-bottom: var(--space-sm);
}

.post-detail-body th,
.post-detail-body td {
  border: 1px solid var(--color-border);
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  vertical-align: top;
}

.post-detail-body thead th {
  background: var(--color-surface);
  font-weight: 600;
}

.post-detail-body tbody tr:nth-child(even) {
  background: var(--color-surface);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--space-3xl);
  color: var(--color-text-secondary);
  font: var(--text-sm) var(--font-sans);
  grid-column: 1 / -1;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--space-xs);
  padding: var(--space-sm) 0;
}

.page-btn {
  min-width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--space-sm);
  font: var(--text-sm) var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.page-btn:hover:not(:disabled):not(.active) {
  background: var(--color-surface);
}

.page-btn.active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

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

.page-ellipsis {
  color: var(--color-text-secondary);
  padding: 0 var(--space-xs);
  user-select: none;
}

/* Responsive — kept minimal. Column count needs no media queries (the grid is
   fluid); only the gutter and the detail view get phone adjustments. */
@media (max-width: 480px) {
  /* Keep a comfortable gutter on phones — the shared pages.css ≤480px main
     rule would otherwise shrink it to ~6–8px via viewport-proportional tokens. */
  main {
    padding: var(--space-md);
  }

  .post-detail {
    padding: var(--space-md) var(--space-sm);
  }
}

@media (prefers-reduced-motion: reduce) {
  .blog-card,
  .blog-card-link,
  .page-btn {
    transition: none;
  }
}
