/* ==========================================================================
   RefertAI Blog — lightweight static design system
   Recreates the "Magic UI Blog" look (clean, neutral, bordered grid) with zero
   framework, zero build. Branded RefertAI: neutral base + teal accent.
   Light default + automatic/manual dark mode. ~1 file, no JS required.
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  /* Neutral scale (light) */
  --bg:              #ffffff;
  --fg:              #0a0a0a;
  --card:            #ffffff;
  --muted:           #f5f5f5;
  --muted-fg:        #6b7280;
  --border:          #e6e6e6;
  --border-strong:   #d4d4d4;

  /* RefertAI brand — teal */
  --accent:          #0d9488; /* teal-600 */
  --accent-hover:    #0f766e; /* teal-700 */
  --accent-soft:     #ccfbf1; /* teal-100 */
  --accent-fg:       #ffffff;

  /* Signals */
  --warn-bg:         #fff7ed;
  --warn-border:     #fed7aa;
  --warn-fg:         #9a3412;

  --radius:          0.625rem;
  --radius-sm:       0.4rem;
  --maxw:            80rem;   /* 7xl */
  --readw:           46rem;   /* comfortable reading measure */

  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 16px rgba(0,0,0,.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0a0a0a;
    --fg:            #fafafa;
    --card:          #131313;
    --muted:         #1a1a1a;
    --muted-fg:      #a1a1aa;
    --border:        #262626;
    --border-strong: #333333;
    --accent:        #2dd4bf; /* teal-400 for contrast on dark */
    --accent-hover:  #5eead4;
    --accent-soft:   #0f3d38;
    --accent-fg:     #04211d;
    --warn-bg:       #26170a;
    --warn-border:   #7c2d12;
    --warn-fg:       #fdba74;
    --shadow-md:     0 4px 16px rgba(0,0,0,.5);
  }
}
/* Manual override */
[data-theme="dark"] {
  --bg:#0a0a0a; --fg:#fafafa; --card:#131313; --muted:#1a1a1a; --muted-fg:#a1a1aa;
  --border:#262626; --border-strong:#333; --accent:#2dd4bf; --accent-hover:#5eead4;
  --accent-soft:#0f3d38; --accent-fg:#04211d; --warn-bg:#26170a; --warn-border:#7c2d12;
  --warn-fg:#fdba74; --shadow-md:0 4px 16px rgba(0,0,0,.5);
}

/* ---------- Reset / base ---------- */
*,*::before,*::after { box-sizing: border-box; }
* { border-color: var(--border); }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

.skip-link {
  position:absolute; left:-9999px; top:0; background:var(--accent); color:var(--accent-fg);
  padding:.6rem 1rem; border-radius:0 0 var(--radius-sm) 0; z-index:100;
}
.skip-link:focus { left:0; }

.container { max-width: var(--maxw); margin-inline: auto; width: 100%; }

/* ---------- Header / nav ---------- */
.site-header {
  position: sticky; top: 0; z-index: 30;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: saturate(150%) blur(10px);
}
.site-header .container {
  display: flex; align-items: center; justify-content: space-between;
  height: 3.5rem; padding-inline: 1.5rem;
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 650; letter-spacing: -.02em; color: var(--fg); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 1.9rem; height: 1.9rem; border-radius: .5rem;
  background: var(--accent); color: var(--accent-fg);
  display: grid; place-items: center; font-weight: 800; font-size: .95rem;
}
.nav-links { display: flex; align-items: center; gap: 1.25rem; }
.nav-links a { color: var(--muted-fg); font-size: .9rem; font-weight: 500; }
.nav-links a:hover { color: var(--fg); text-decoration: none; }
.btn-theme {
  background: transparent; border: 1px solid var(--border); color: var(--fg);
  width: 2rem; height: 2rem; border-radius: var(--radius-sm); cursor: pointer;
  display: grid; place-items: center; font-size: 1rem; line-height: 1;
}
.btn-theme:hover { background: var(--muted); }

/* ---------- Hero ---------- */
.hero {
  position: relative; border-bottom: 1px solid var(--border); overflow: hidden;
}
.hero::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 200px; z-index: 0;
  background:
    radial-gradient(60% 120% at 20% 0%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%),
    radial-gradient(50% 120% at 90% 0%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 55%);
  -webkit-mask-image: linear-gradient(to top, transparent 20%, #000 95%);
          mask-image: linear-gradient(to top, transparent 20%, #000 95%);
  pointer-events: none;
}
.hero .container { position: relative; z-index: 1; padding: 2.75rem 1.5rem; }
.hero h1 { margin: 0; font-size: clamp(2rem, 4vw, 3rem); font-weight: 600; letter-spacing: -.035em; }
.hero .lede { margin: .5rem 0 0; color: var(--muted-fg); font-size: 1.05rem; max-width: 46rem; }

/* ---------- Tag chips ---------- */
.tags { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.5rem; }
.chip {
  display: inline-flex; align-items: center; gap: .4rem;
  height: 1.9rem; padding-inline: .75rem;
  font-size: .8rem; font-weight: 500; color: var(--muted-fg);
  background: var(--muted); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.chip:hover { color: var(--fg); text-decoration: none; border-color: var(--border-strong); }
.chip[aria-current="true"], .chip.is-active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.chip .count { opacity: .6; font-variant-numeric: tabular-nums; }

/* ---------- Card grid (index) ---------- */
.card-grid {
  display: grid; grid-template-columns: 1fr;
  border-left: 1px solid var(--border); border-right: 1px solid var(--border);
}
@media (min-width: 48rem)  { .card-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 64rem)  { .card-grid { grid-template-columns: 1fr 1fr 1fr; } }
.card {
  display: flex; flex-direction: column; color: var(--fg);
  border-bottom: 1px solid var(--border); border-right: 1px solid var(--border);
}
.card:hover { text-decoration: none; background: color-mix(in srgb, var(--muted) 50%, transparent); }
.card-thumb { position: relative; aspect-ratio: 16/9; overflow: hidden; background: var(--muted); }
.card-thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .3s ease; }
.card:hover .card-thumb img { transform: scale(1.04); }
.card-body { padding: 1.25rem; display: flex; flex-direction: column; gap: .5rem; }
.card-body h3 { margin: 0; font-size: 1.15rem; font-weight: 600; letter-spacing: -.01em; }
.card:hover .card-body h3 { color: var(--accent); }
.card-body p { margin: 0; color: var(--muted-fg); font-size: .9rem; }
.card-meta { color: var(--muted-fg); font-size: .8rem; font-weight: 500; margin-top: .25rem; }

/* ---------- Article layout ---------- */
.article-head { border-bottom: 1px solid var(--border); position: relative; }
.article-head .container { padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.crumbs { display:flex; flex-wrap:wrap; align-items:center; gap:.6rem; font-size:.85rem; color:var(--muted-fg); }
.crumbs a { color: var(--muted-fg); }
.crumbs a:hover { color: var(--fg); }
.back-btn {
  display:inline-grid; place-items:center; width:1.6rem; height:1.6rem;
  border:1px solid var(--border); border-radius:var(--radius-sm); color:var(--fg);
}
.back-btn:hover { background: var(--muted); text-decoration:none; }
.article-head h1 {
  margin: 0; font-weight: 600; letter-spacing: -.035em; text-wrap: balance;
  font-size: clamp(2rem, 5vw, 3.5rem); line-height: 1.05;
}
.article-head .lede { margin: 0; color: var(--muted-fg); font-size: 1.15rem; max-width: 52rem; text-wrap: balance; }
.byline { display:flex; flex-wrap:wrap; align-items:center; gap:.5rem .9rem; font-size:.85rem; color:var(--muted-fg); }
.byline strong { color: var(--fg); font-weight: 600; }
.byline .dot { opacity:.5; }

.article-wrap {
  display: grid; grid-template-columns: 1fr; position: relative;
  border-left: 1px solid var(--border); border-right: 1px solid var(--border);
  max-width: var(--maxw); margin-inline: auto;
}
@media (min-width: 64rem) { .article-wrap { grid-template-columns: minmax(0,1fr) 340px; } }
.article-main { min-width: 0; }
.hero-image { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-bottom: 1px solid var(--border); background: var(--muted); }

/* Sidebar */
.sidebar { display: none; border-left: 1px solid var(--border); background: color-mix(in srgb, var(--muted) 55%, transparent); }
@media (min-width: 64rem) { .sidebar { display: block; } }
.sidebar-inner { position: sticky; top: 4.5rem; padding: 2rem 1.5rem; display: flex; flex-direction: column; gap: 1.75rem; }

/* ---------- Prose ---------- */
.prose { padding: 1.75rem 1.5rem; max-width: none; }
@media (min-width: 64rem) { .prose { padding: 2.5rem; } }
.prose > * { max-width: var(--readw); }
.prose > .full, .prose > figure, .prose > table, .prose > .table-scroll { max-width: none; }
.prose p, .prose li { font-size: 1.06rem; }
.prose p { margin: 0 0 1.15rem; text-wrap: pretty; }
.prose h2 {
  margin: 2.4rem 0 1rem; font-size: 1.7rem; font-weight: 650; letter-spacing: -.02em;
  scroll-margin-top: 5rem; line-height: 1.2; text-wrap: balance;
}
.prose h3 { margin: 1.9rem 0 .75rem; font-size: 1.28rem; font-weight: 600; scroll-margin-top: 5rem; }
.prose h2 + h3 { margin-top: 1rem; }
.prose ul, .prose ol { margin: 0 0 1.15rem; padding-left: 1.35rem; }
.prose li { margin: .4rem 0; }
.prose li::marker { color: var(--accent); }
.prose a { font-weight: 500; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.prose strong { font-weight: 650; color: var(--fg); }
.prose blockquote {
  margin: 1.5rem 0; padding: .25rem 1.1rem; border-left: 3px solid var(--accent);
  color: var(--muted-fg); font-style: italic;
}
.prose img, .prose figure { border-radius: var(--radius); margin: 1.75rem 0; }
.prose figure { margin-inline: 0; }
.prose figcaption { color: var(--muted-fg); font-size: .85rem; margin-top: .5rem; text-align: center; }
.prose code {
  font-family: var(--font-mono); font-size: .875em;
  background: var(--muted); padding: .15em .4em; border-radius: 5px; border: 1px solid var(--border);
}
.prose pre {
  background: var(--muted); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem; overflow-x: auto; font-size: .9rem;
}
.prose pre code { background: none; border: 0; padding: 0; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 2.5rem 0; }

/* Tables (comparison — GEO loves these) */
.table-scroll { overflow-x: auto; margin: 1.75rem 0; border: 1px solid var(--border); border-radius: var(--radius); }
.prose table { width: 100%; border-collapse: collapse; font-size: .92rem; margin: 0; }
.prose thead { background: var(--muted); }
.prose th, .prose td { text-align: left; padding: .7rem .9rem; border-bottom: 1px solid var(--border); }
.prose th { font-weight: 650; }
.prose tbody tr:last-child td { border-bottom: 0; }
.prose td:first-child, .prose th:first-child { font-weight: 600; }

/* ---------- TL;DR box (AEO extract target) ---------- */
.tldr {
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent-soft) 40%, transparent);
  border-radius: var(--radius); padding: 1.1rem 1.25rem; margin: 0 0 2rem; max-width: var(--readw);
}
.tldr .k { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; color: var(--accent); }
.tldr p { margin: .4rem 0 0; font-size: 1rem; }

/* Key takeaways */
.takeaways { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem 1.4rem; margin: 2rem 0; background: var(--card); max-width: var(--readw); }
.takeaways h2 { margin: 0 0 .6rem; font-size: 1.15rem; }
.takeaways ul { margin: 0; }

/* Callout / medical disclaimer */
.callout {
  display: flex; gap: .75rem; align-items: flex-start;
  background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-fg);
  border-radius: var(--radius); padding: .9rem 1.1rem; margin: 1.75rem 0; font-size: .95rem; max-width: var(--readw);
}
.callout .ico { flex: 0 0 auto; font-size: 1.1rem; line-height: 1.4; }

/* ---------- FAQ (AEO powerhouse) ---------- */
.faq { margin: 2.5rem 0; max-width: var(--readw); }
.faq h2 { margin-bottom: 1rem; }
.faq details {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .1rem 1rem; margin-bottom: .6rem; background: var(--card);
}
.faq details[open] { border-color: var(--border-strong); }
.faq summary {
  cursor: pointer; list-style: none; padding: .85rem 0; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--accent); font-size: 1.3rem; line-height: 1; transition: transform .2s; }
.faq details[open] summary::after { transform: rotate(45deg); }
.faq details p { margin: 0 0 .9rem; color: var(--muted-fg); }

/* ---------- Author card (E-E-A-T) ---------- */
.author { display: flex; gap: .85rem; align-items: flex-start; }
.author img, .author .avatar {
  width: 3rem; height: 3rem; border-radius: 50%; object-fit: cover; flex: 0 0 auto;
  background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700;
}
.author .name { font-weight: 650; }
.author .role { color: var(--muted-fg); font-size: .85rem; }
.author .bio { color: var(--muted-fg); font-size: .85rem; margin-top: .4rem; }

/* Sidebar TOC */
.toc-box { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; background: var(--card); }
.toc-box .k { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; color: var(--muted-fg); margin-bottom: .5rem; }
.toc-box ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .1rem; }
.toc-box a { display: block; padding: .3rem .5rem; border-radius: 6px; color: var(--muted-fg); font-size: .88rem; border-left: 2px solid transparent; }
.toc-box a:hover { color: var(--fg); background: var(--muted); text-decoration: none; }
.toc-box a.active { color: var(--accent); border-left-color: var(--accent); background: var(--muted); }

/* CTA box */
.cta {
  border: 1px solid var(--accent); border-radius: var(--radius); padding: 1.25rem;
  background: color-mix(in srgb, var(--accent-soft) 45%, var(--card));
}
.cta h4 { margin: 0 0 .35rem; font-size: 1rem; }
.cta p { margin: 0 0 .9rem; color: var(--muted-fg); font-size: .9rem; }
.btn {
  display: inline-flex; align-items: center; gap: .5rem; justify-content: center;
  background: var(--accent); color: var(--accent-fg); font-weight: 600; font-size: .9rem;
  padding: .6rem 1.1rem; border-radius: var(--radius-sm); border: 0; cursor: pointer;
}
.btn:hover { background: var(--accent-hover); color: var(--accent-fg); text-decoration: none; }
.btn-block { width: 100%; }

/* ---------- Read more ---------- */
.readmore { border-top: 1px solid var(--border); padding: 2rem 1.5rem; }
@media (min-width: 64rem) { .readmore { padding: 2.5rem; } }
.readmore h2 { margin: 0 0 1.25rem; font-size: 1.35rem; font-weight: 650; letter-spacing: -.02em; }
.readmore-grid { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 48rem) { .readmore-grid { grid-template-columns: 1fr 1fr; } }
.readmore-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; color: var(--fg); }
.readmore-card:hover { border-color: var(--accent); text-decoration: none; }
.readmore-card h3 { margin: 0 0 .3rem; font-size: 1.02rem; font-weight: 600; }
.readmore-card p { margin: 0; color: var(--muted-fg); font-size: .85rem; }

/* ---------- Mobile TOC ---------- */
.mobile-toc { display: block; margin: 0 1.5rem 1.75rem; max-width: var(--readw); }
@media (min-width: 64rem) { .mobile-toc { display: none; } }
.mobile-toc summary { cursor: pointer; font-weight: 600; padding: .75rem 1rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--card); }
.mobile-toc ul { list-style: none; margin: .5rem 0 0; padding: .5rem 1rem; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.mobile-toc a { color: var(--muted-fg); display: block; padding: .3rem 0; font-size: .9rem; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); background: var(--bg); }
.site-footer .container { padding: 2rem 1.5rem; display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; align-items: center; }
.site-footer p { margin: 0; color: var(--muted-fg); font-size: .85rem; }
.site-footer nav { display: flex; gap: 1.25rem; flex-wrap: wrap; }
.site-footer nav a { color: var(--muted-fg); font-size: .85rem; }
.site-footer nav a:hover { color: var(--fg); }

/* ---------- Utilities ---------- */
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); border:0; }
.mt-0 { margin-top: 0; }
@media print {
  .site-header, .sidebar, .mobile-toc, .readmore, .cta, .btn-theme { display: none !important; }
  .article-wrap { border: 0; display: block; }
  a { color: #000; text-decoration: underline; }
}
