*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --color-bg: #f5f5f5;
  --color-white: #ffffff;
  --color-primary: #3b82f6;
  --color-primary-light: #60a5fa;
  --color-accent: #f59e0b;
  --color-accent-light: #fbbf24;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-text-light: #94a3b8;
  --color-border: #e2e8f0;
  --color-border-light: #f1f5f9;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
  --font: "IBM Plex Sans Thai Looped", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, sans-serif;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.8;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
}

/* ================================================================
   NAVBAR
   ================================================================ */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
}

.navbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  max-width: 1100px;
  margin: 0 auto;
}

.navbar-search {
  position: relative;
  flex: 1;
}

.navbar-search .icon-search {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-light);
  pointer-events: none;
}

.hamburger-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-white);
  cursor: pointer;
  color: var(--color-text);
  flex-shrink: 0;
  transition: background 0.15s;
}

.hamburger-btn:hover {
  background: var(--color-border-light);
}

/* ================================================================
   SEARCH INPUT (shared between navbar & home)
   ================================================================ */
.search-input {
  width: 100%;
  padding: 0.65rem 1rem 0.65rem 2.5rem;
  font-size: 0.9rem;
  font-family: var(--font);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-white);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input::placeholder {
  color: var(--color-text-light);
}

.search-input:focus {
  border-color: var(--color-primary-light);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Search results dropdown */
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  max-height: 320px;
  overflow-y: auto;
  display: none;
  z-index: 200;
}

.search-results.active {
  display: block;
}

.search-result-item {
  display: block;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--color-border-light);
  color: var(--color-text);
  transition: background 0.15s;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover,
.search-result-item.highlighted {
  background: var(--color-border-light);
}

.search-result-item.highlighted {
  outline: 2px solid var(--color-primary-light);
  outline-offset: -2px;
}

.search-result-title {
  font-size: 0.9rem;
  font-weight: 500;
}

.search-result-parent {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-top: 0.15rem;
}

.search-no-results {
  padding: 1rem;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

/* ================================================================
   DRAWER
   ================================================================ */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 500;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.drawer-overlay.active {
  opacity: 1;
  visibility: visible;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 300px;
  max-width: 85vw;
  background: var(--color-white);
  z-index: 501;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.drawer.active {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
}

.drawer-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text);
}

.drawer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: background 0.15s;
}

.drawer-close:hover {
  background: var(--color-border-light);
}

.drawer-menu {
  list-style: none;
  padding: 0.5rem 0;
}

.drawer-link {
  display: block;
  padding: 0.75rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--color-text);
  transition: background 0.15s;
}

.drawer-link:hover {
  background: var(--color-border-light);
  color: var(--color-primary);
}

.drawer-submenu {
  list-style: none;
  padding: 0 0 0.25rem;
}

.drawer-sublink {
  display: block;
  padding: 0.5rem 1.25rem 0.5rem 2.25rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  transition: background 0.15s, color 0.15s;
}

.drawer-sublink:hover {
  background: var(--color-border-light);
  color: var(--color-primary);
}

/* ================================================================
   HERO
   ================================================================ */
.hero {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 320px;
  overflow: hidden;
  background: #d1d5db;
}

.hero-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}

.hero-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  padding: 1.5rem;
  text-align: center;
}

.hero-title {
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  font-weight: 700;
  color: #ffffff;
  white-space: pre-line;
  line-height: 1.25;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.hero-badge {
  display: inline-block;
  margin-top: 0.75rem;
  padding: 0.45rem 1.5rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  backdrop-filter: blur(4px);
}

/* ================================================================
   BREADCRUMBS
   ================================================================ */
.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  padding: 0.75rem 0;
  font-size: 0.82rem;
}

.breadcrumb-link {
  color: var(--color-text-muted);
  transition: color 0.15s;
}

.breadcrumb-link:hover {
  color: var(--color-primary);
}

.breadcrumb-sep {
  color: var(--color-text-light);
}

.breadcrumb-current {
  color: var(--color-text);
  font-weight: 500;
}

/* ================================================================
   HOME PAGE
   ================================================================ */
.home-welcome {
  text-align: center;
  padding: 2rem 1rem 0.5rem;
}

.home-welcome-title {
  font-size: clamp(1.1rem, 4vw, 1.5rem);
  font-weight: 700;
  color: var(--color-primary);
}

.home-welcome-sub {
  margin-top: 0.4rem;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.home-search {
  position: relative;
  width: 100%;
  max-width: 720px;
  margin: 1.25rem auto 0;
  padding: 0 1rem;
}

.home-search .icon-search {
  position: absolute;
  left: 1.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-light);
  pointer-events: none;
}

.home-categories {
  padding: 1.5rem 1rem 3rem;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  max-width: 600px;
  margin: 0 auto;
}

.category-card {
  display: flex;
  flex-direction: column;
  background: var(--color-white);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--color-border);
  transition: transform 0.2s, box-shadow 0.2s;
  color: var(--color-text);
}

.category-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.category-card-img {
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: #d1d5db;
}

.category-card-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.category-card-title {
  padding: 0.7rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  color: var(--color-text);
}

/* ================================================================
   PAGE CONTENT (category & topic shared)
   ================================================================ */
.page-content {
  padding: 0 1rem 3rem;
  max-width: 700px;
  margin: 0 auto;
}

.page-title {
  font-size: clamp(1.15rem, 4vw, 1.5rem);
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: 0.5rem;
}

.page-description {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  line-height: 1.7;
  margin-bottom: 1.5rem;
}

/* ================================================================
   TOPIC LIST (category page)
   ================================================================ */
.topic-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.topic-card {
  display: flex;
  gap: 0.85rem;
  background: var(--color-white);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--color-border);
  padding: 0.85rem;
  transition: transform 0.15s, box-shadow 0.15s;
  color: var(--color-text);
}

.topic-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.topic-card-img {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
  background: #d1d5db;
}

.topic-card-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.topic-card-body {
  flex: 1;
  min-width: 0;
  height: 80px;
}

.topic-card-title {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--color-text);
  margin-top: 0.3rem;
  margin-bottom: 0.3rem;
  line-height: 1.8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topic-card-desc {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  line-height: 1.8;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ================================================================
   PRODUCT DROPDOWN (topic page)
   ================================================================ */
.product-dropdown {
  position: relative;
  display: inline-block;
  margin-bottom: 1.5rem;
}

.product-dropdown-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 1.0rem;
  font-size: 0.8rem;
  font-family: var(--font);
  font-weight: 500;
  border: 2px solid var(--color-accent);
  border-radius: 999px;
  background: var(--color-white);
  color: var(--color-accent);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.product-dropdown-btn:hover {
  background: rgba(245, 158, 11, 0.06);
}

.product-dropdown-btn svg {
  flex-shrink: 0;
  transition: transform 0.2s;
}

.product-dropdown.open .product-dropdown-btn svg {
  transform: rotate(180deg);
}

.product-dropdown-btn.selected {
  background: #8b6f47;
  border-color: #8b6f47;
  color: #ffffff;
}

.product-dropdown-btn.selected:hover {
  background: #7a6140;
}

.product-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 100%;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 50;
  display: none;
  overflow: hidden;
}

.product-dropdown.open .product-dropdown-menu {
  display: block;
}

.product-dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.55rem 1.1rem;
  background: none;
  border: none;
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--color-text);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.product-dropdown-item:hover {
  background: var(--color-border-light);
}

.product-dropdown-item.active {
  color: #8b6f47;
  font-weight: 600;
}

/* ================================================================
   CONTENT SECTIONS (category-content & topic page)
   ================================================================ */
.content-sections {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.content-section {
  margin-bottom: 1.5rem;
}

.content-section-image {
  margin-bottom: 0.75rem;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #d1d5db;
}

.content-section-image img {
  width: 100%;
  height: auto;
}

.content-heading {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.4rem;
}

.content-body {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  line-height: 1.8;
}

.content-tip {
  margin-top: 1.5rem;
  padding: 1rem;
  background: rgba(245, 158, 11, 0.08);
  border-left: 3px solid var(--color-accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  line-height: 1.8;
}

.content-tip-image {
  margin-top: 1rem;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #d1d5db;
}

.content-tip-image img {
  width: 100%;
  height: auto;
  object-fit: cover;
}

/* ================================================================
   404 PAGE
   ================================================================ */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  padding: 2rem;
  background: var(--color-white);
}

.error-icon {
  font-size: clamp(3rem, 10vw, 5rem);
  line-height: 1;
  margin-bottom: 0.5rem;
}

.error-code {
  font-size: clamp(4.5rem, 15vw, 9rem);
  font-weight: 800;
  line-height: 1;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.error-title {
  margin-top: 0.25rem;
  font-size: clamp(1rem, 3vw, 1.35rem);
  font-weight: 600;
  color: var(--color-text);
}

.error-message {
  margin-top: 0.75rem;
  font-size: 0.95rem;
  color: var(--color-text-muted);
  max-width: 400px;
  line-height: 1.6;
}

.error-back-link {
  margin-top: 2rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.7rem 1.75rem;
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.2s, transform 0.15s;
}

.error-back-link:hover {
  background: var(--color-primary-light);
  color: #fff;
  transform: translateY(-1px);
}

/* ================================================================
   PLACEHOLDER IMAGE
   ================================================================ */
.placeholder-image[data-placeholder="true"] {
  background: #d1d5db;
  min-height: 60px;
}

/* ================================================================
   RESPONSIVE — TABLET (768px+)
   ================================================================ */
@media (min-width: 768px) {
  .navbar-inner {
    padding: 0.75rem 2rem;
  }

  .hero {
    max-height: 400px;
  }

  .home-welcome {
    padding: 3rem 2rem 1rem;
  }

  .home-categories {
    padding: 2rem 2rem 4rem;
  }

  .category-grid {
    grid-template-columns: repeat(3, 1fr);
    max-width: 800px;
    gap: 1.25rem;
  }

  .category-card-title {
    font-size: 0.95rem;
    padding: 0.85rem 1rem;
  }

  .page-content {
    padding: 0 2rem 4rem;
    max-width: 800px;
  }

  .topic-card-img {
    width: 100px;
    height: 100px;
  }

  .topic-card-title {
    font-size: 1.05rem;
  }

  .topic-card-desc {
    font-size: 0.85rem;
  }

  .drawer {
    width: 360px;
  }
}

/* ================================================================
   RESPONSIVE — DESKTOP (1024px+)
   ================================================================ */
@media (min-width: 1024px) {
  .navbar-inner {
    padding: 0.75rem 0;
    max-width: 1100px;
    margin: 0 auto;
    padding-left: 2rem;
    padding-right: 2rem;
  }

  .hero {
    max-height: 450px;
  }

  .home-welcome {
    padding: 3.5rem 2rem 1.5rem;
  }

  .home-welcome-title {
    font-size: 1.75rem;
  }

  .home-search {
    max-width: 480px;
  }

  .category-grid {
    max-width: 1000px;
    gap: 1.5rem;
  }

  .page-content {
    max-width: 900px;
  }

  .topic-card {
    padding: 1rem;
    gap: 1rem;
  }

  .topic-card-img {
    width: 120px;
    height: 100px;
  }
}

/* ================================================================
   RESPONSIVE — LARGE (1280px+)
   ================================================================ */
@media (min-width: 1280px) {
  .navbar-inner,
  .page-content {
    max-width: 1100px;
  }
}
