@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap');

/* ─── Layers ───────────────────────────────────────────────── */
@layer reset, tokens, base, layout, components, utilities;

/* ─── Reset ────────────────────────────────────────────────── */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  img, video { max-width: 100%; display: block; }
  ul, ol { list-style: none; }
  button, input, select, textarea { font: inherit; }
}

/* ─── Tokens ────────────────────────────────────────────────── */
@layer tokens {
  :root {
    --red:        #E31837;
    --red-dark:   #b8102b;
    --dark:       #1A1A2E;
    --dark-mid:   #252540;

    --text:       #111827;
    --text-mid:   #374151;
    --text-muted: #6b7280;

    --border:     #e5e7eb;
    --border-mid: #d1d5db;
    --surface:    #f9fafb;
    --white:      #ffffff;

    --radius-sm:  6px;
    --radius:     8px;
    --radius-lg:  12px;

    --max-w:      740px;
    --pad-x:      1.25rem;
  }
}

/* ─── Base ──────────────────────────────────────────────────── */
@layer base {
  html { scroll-behavior: smooth; }

  body {
    font-family: 'Sarabun', sans-serif;
    font-size: 1rem;
    line-height: 1.75;
    color: var(--text);
    background: var(--white);
    -webkit-font-smoothing: antialiased;
  }

  h1 { font-size: clamp(1.5rem, 4vw, 2rem);   font-weight: 700; line-height: 1.3; }
  h2 { font-size: clamp(1.1rem, 3vw, 1.3rem); font-weight: 600; line-height: 1.4; }
  h3 { font-size: 1rem;                         font-weight: 600; line-height: 1.4; }

  p  { color: var(--text-mid); }
  a  { color: var(--red); text-decoration: none; }
  a:hover { text-decoration: underline; }

  strong { font-weight: 600; color: var(--text); }
}

/* ─── Layout ────────────────────────────────────────────────── */
@layer layout {
  .page-wrap {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }

  main { flex: 1; }

  .container {
    width: 100%;
    max-width: var(--max-w);
    margin-inline: auto;
    padding-inline: var(--pad-x);
  }
}

/* ─── Components ────────────────────────────────────────────── */
@layer components {

  /* Prevent flash of unstyled Web Components */
  site-header:not(:defined),
  site-footer:not(:defined) { display: none; }

  /* Nav */
  site-header { display: block; }

  .nav {
    background: var(--dark);
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .nav__logo {
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.01em;
  }
  .nav__logo span { color: var(--red); }

  .nav__links {
    display: flex;
    gap: 1.25rem;
    align-items: center;
  }

  .nav__links a {
    font-size: 0.8125rem;
    color: #9ca3af;
    transition: color 0.15s;
  }
  .nav__links a:hover,
  .nav__links a[aria-current="page"] { color: #fff; text-decoration: none; }

  .nav__cta {
    background: var(--red);
    color: #fff !important;
    font-size: 0.8125rem;
    font-weight: 600;
    padding: 0.4rem 0.9rem;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
    white-space: nowrap;
  }
  .nav__cta:hover { background: var(--red-dark); text-decoration: none; }

  /* Hero */
  .hero {
    background: var(--dark);
    padding: 3rem var(--pad-x) 2.5rem;
  }

  .hero__inner { max-width: var(--max-w); margin-inline: auto; }

  .hero__label {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-bottom: 0.75rem;
  }

  .hero h1 { color: #fff; margin-bottom: 1rem; }

  .hero__meta {
    font-size: 0.8125rem;
    color: #9ca3af;
    margin-bottom: 1rem;
  }

  .hero__pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
  }

  .pill {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    color: #d1d5db;
    font-size: 0.75rem;
    padding: 0.2rem 0.65rem;
    border-radius: 99px;
  }

  /* Buttons */
  .btn {
    display: inline-block;
    font-weight: 600;
    padding: 0.6rem 1.35rem;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
    cursor: pointer;
    border: none;
    text-decoration: none;
  }

  .btn-primary {
    background: var(--red);
    color: #fff;
  }
  .btn-primary:hover { background: var(--red-dark); text-decoration: none; }

  .btn-outline {
    background: transparent;
    color: #fff;
    border: 1px solid rgba(255,255,255,0.3);
  }
  .btn-outline:hover { background: rgba(255,255,255,0.08); text-decoration: none; }

  /* TOC */
  .toc {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem var(--pad-x);
  }

  .toc__inner { max-width: var(--max-w); margin-inline: auto; }

  .toc__label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
  }

  .toc__list {
    list-style: decimal;
    padding-left: 1.1rem;
    columns: 2;
    column-gap: 1.5rem;
    font-size: 0.8125rem;
  }

  .toc__list li { margin-bottom: 0.2rem; break-inside: avoid; }
  .toc__list a { color: var(--red); }

  /* Article body */
  .article {
    max-width: var(--max-w);
    margin-inline: auto;
    padding: 2rem var(--pad-x) 3rem;
  }

  .article h2 {
    margin-top: 2.5rem;
    margin-bottom: 0.75rem;
    padding-top: 0.25rem;
    color: var(--text);
  }

  .article h2:first-child { margin-top: 0; }

  .article h3 {
    margin-top: 1.25rem;
    margin-bottom: 0.4rem;
    color: var(--text);
  }

  .article p { margin-bottom: 0.75rem; }

  .article ul,
  .article ol {
    list-style: disc;
    padding-left: 1.25rem;
    margin-bottom: 0.75rem;
    color: var(--text-mid);
    font-size: 0.9375rem;
  }

  .article ol { list-style: decimal; }
  .article li { margin-bottom: 0.3rem; }

  .article hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2rem 0;
  }

  /* Callout boxes */
  .box {
    border-radius: 0 var(--radius) var(--radius) 0;
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
    border-left: 3px solid;
    font-size: 0.875rem;
    line-height: 1.65;
  }

  .box p { margin: 0; font-size: inherit; }
  .box strong { font-size: inherit; }

  .box--info    { background: #eff6ff; border-color: #3b82f6; color: #1e3a5f; }
  .box--warn    { background: #fffbeb; border-color: #f59e0b; color: #78350f; }
  .box--success { background: #f0fdf4; border-color: #16a34a; color: #14532d; }
  .box--neutral { background: var(--surface); border-color: var(--border-mid); color: var(--text-mid); }

  /* Tables */
  .table-wrap { overflow-x: auto; margin-bottom: 1rem; }

  table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
  }

  th {
    background: var(--dark);
    color: #fff;
    padding: 0.55rem 0.85rem;
    text-align: left;
    font-weight: 500;
  }

  td {
    border: 1px solid var(--border);
    padding: 0.5rem 0.85rem;
    color: var(--text-mid);
  }

  tr:nth-child(even) td { background: var(--surface); }

  /* Steps */
  .steps { margin-bottom: 1.5rem; }

  .step {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
  }

  .step__num {
    flex-shrink: 0;
    width: 1.75rem;
    height: 1.75rem;
    background: var(--red);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    margin-top: 0.2rem;
  }

  .step__title {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.1rem;
    font-size: 0.9375rem;
  }

  .step__desc {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin: 0;
  }

  /* CTA block */
  .cta-block {
    background: var(--dark);
    border-radius: var(--radius-lg);
    padding: 2rem;
    text-align: center;
    margin: 2rem 0;
  }

  .cta-block__title { font-size: 1.1rem; font-weight: 600; color: #fff; margin-bottom: 0.4rem; }
  .cta-block__sub   { font-size: 0.8125rem; color: #9ca3af; margin-bottom: 1.25rem; }

  /* FAQ */
  .faq { border-top: 1px solid var(--border); }

  .faq details {
    border-bottom: 1px solid var(--border);
  }

  .faq summary {
    padding: 0.9rem 0;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    user-select: none;
  }

  .faq summary::-webkit-details-marker { display: none; }

  .faq summary::after {
    content: '+';
    color: var(--text-muted);
    font-size: 1.25rem;
    font-weight: 300;
    flex-shrink: 0;
    transition: transform 0.2s;
  }

  .faq details[open] summary::after { content: '−'; }

  .faq__answer {
    font-size: 0.875rem;
    color: var(--text-mid);
    line-height: 1.7;
    padding-bottom: 1rem;
  }

  /* Link grid */
  .link-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 0.6rem;
    margin-top: 1.25rem;
  }

  .link-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    text-decoration: none;
    transition: border-color 0.15s;
    display: block;
  }

  .link-card:hover { border-color: var(--red); text-decoration: none; }

  .link-card__title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0.15rem;
  }

  .link-card__desc {
    font-size: 0.75rem;
    color: var(--text-muted);
  }

  /* Card grid (homepage) */
  .card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 2rem;
  }

  .card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    text-decoration: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    display: block;
    color: var(--text);
  }

  .card:hover { border-color: var(--red); box-shadow: 0 2px 12px rgba(0,0,0,0.06); text-decoration: none; }

  .card__icon { font-size: 1.5rem; margin-bottom: 0.6rem; }
  .card__title { font-size: 0.9375rem; font-weight: 600; color: var(--text); margin-bottom: 0.3rem; }
  .card__desc  { font-size: 0.8125rem; color: var(--text-muted); }

  /* Section heading */
  .section-heading {
    text-align: center;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.25rem;
  }

  /* Footer */
  site-footer { display: block; }

  .footer {
    background: var(--dark);
    color: #9ca3af;
    padding: 3rem var(--pad-x) 2rem;
    margin-top: auto;
  }

  .footer__inner {
    max-width: var(--max-w);
    margin-inline: auto;
  }

  .footer__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
  }

  .footer__logo {
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 0.5rem;
  }
  .footer__logo span { color: var(--red); }

  .footer__col-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #e5e7eb;
    margin-bottom: 0.75rem;
  }

  .footer__links {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.8125rem;
  }

  .footer__links a {
    color: #9ca3af;
    transition: color 0.15s;
  }
  .footer__links a:hover { color: #fff; text-decoration: none; }

  .footer__bottom {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding-top: 1.5rem;
    font-size: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .footer__bottom p { color: #6b7280; margin: 0; }

  /* Lang switcher */
  .lang-switch {
    font-size: 0.75rem;
    color: #6b7280;
    margin-left: 0.5rem;
    transition: color 0.15s;
  }
  .lang-switch:hover { color: #fff; text-decoration: none; }

  /* Placeholder pages */
  .placeholder {
    max-width: var(--max-w);
    margin-inline: auto;
    padding: 4rem var(--pad-x);
    text-align: center;
  }

  .placeholder h1 { margin-bottom: 0.75rem; }
  .placeholder p  { color: var(--text-muted); margin-bottom: 1.5rem; }
}

/* ─── Utilities ─────────────────────────────────────────────── */
@layer utilities {
  .sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
  }

  .mt-0 { margin-top: 0 !important; }
  .mb-0 { margin-bottom: 0 !important; }
  .text-sm { font-size: 0.875rem; }
  .text-muted { color: var(--text-muted); }
}

/* ─── Responsive ────────────────────────────────────────────── */
@media (max-width: 600px) {
  .nav__links { display: none; }
  .toc__list  { columns: 1; }
  .footer__grid { grid-template-columns: 1fr; gap: 1.5rem; }
}
