﻿/* ═══════════════════════════════════════════
   JAYbranding — 3-Column Grid Layout
   jb.177.jaysoft.dev | File-based MD site
   ═══════════════════════════════════════════ */

:root {
  --c-bg: #fafbfc;
  --c-surface: #ffffff;
  --c-border: #e5e7eb;
  --c-text: #1f2937;
  --c-muted: #6b7280;
  --c-primary: #1B96FE;
  --c-accent: #8B5CF6;
  --c-chat-bg: #f8fafc;
  --c-menu-bg: #f1f5f9;
  --sidebar-collapsed: 56px;
  --sidebar-menu-w: 340px;
  --sidebar-chat-w: 380px;
  --radius: 12px;
  --font-heading: 'Bai Jamjuree', system-ui, sans-serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font-body); color: var(--c-text); background: var(--c-bg);
  line-height: 1.7; min-height: 100vh;
}

/* ─── 3-Column Grid ─── */
.page-layout {
  display: grid;
  grid-template-columns: var(--sidebar-collapsed) 1fr var(--sidebar-collapsed);
  min-height: 100vh;
  transition: grid-template-columns .3s cubic-bezier(.4,0,.2,1);
}
.page-layout.menu-expanded { grid-template-columns: var(--sidebar-menu-w) 1fr var(--sidebar-collapsed); }
.page-layout.chat-expanded { grid-template-columns: var(--sidebar-collapsed) 1fr var(--sidebar-chat-w); }

/* ─── Sidebars (Col 1 & Col 3) ─── */
.col-sidebar {
  background: var(--c-surface); border-color: var(--c-border);
  display: flex; flex-shrink: 0; overflow: hidden;
  position: sticky; top: 0; height: 100vh;
}
.col-menu { border-right: 1px solid var(--c-border); }
.col-chat { border-left: 1px solid var(--c-border); justify-content: flex-end; }

.sidebar-icons {
  width: var(--sidebar-collapsed); min-width: var(--sidebar-collapsed);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 16px 0;
}
.sidebar-label {
  writing-mode: vertical-rl; font-size: 10px; font-weight: 600;
  letter-spacing: .15em; color: var(--c-muted); margin-top: 8px;
}
.sidebar-toggle {
  width: 36px; height: 36px; border: none; background: transparent;
  border-radius: 8px; cursor: pointer; display: flex; align-items: center;
  justify-content: center; color: var(--c-text); transition: background .15s;
}
.sidebar-toggle:hover { background: var(--c-menu-bg); }
.sidebar-toggle svg, .panel-close svg, .chat-send-btn svg { width: 20px; height: 20px; }

/* Sidebar panels (expanded) */
.sidebar-panel {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  opacity: 0; transition: opacity .2s;
}
.col-menu.expanded .sidebar-panel,
.col-chat.expanded .sidebar-panel { opacity: 1; }

.panel-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; border-bottom: 1px solid var(--c-border);
  font-weight: 600; font-family: var(--font-heading);
}
.panel-close {
  border: none; background: transparent; cursor: pointer;
  color: var(--c-muted); padding: 4px; border-radius: 6px; flex-shrink: 0;
}
.panel-close:hover { background: var(--c-menu-bg); color: var(--c-text); }
.panel-inner { flex: 1; overflow-y: auto; padding: 12px; }

/* ─── Menu Tree ─── */
.menu-tree { list-style: none; }
.menu-item { margin-bottom: 2px; }
.menu-link {
  display: flex; align-items: center; padding: 8px 12px; border-radius: 8px;
  color: var(--c-text); text-decoration: none; font-size: 14px; font-weight: 500;
  transition: all .15s; gap: 8px;
}
.menu-link:hover { background: var(--c-bg); color: var(--c-primary); }
.menu-link.active { background: #eff6ff; color: var(--c-primary); font-weight: 600; }
.menu-group-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--c-muted); padding: 16px 12px 6px; font-weight: 700;
}
.menu-child { padding-left: 16px; }
.menu-child .menu-link { font-size: 13px; font-weight: 400; }

/* ─── Col 2: Main Content ─── */
.col-main { min-width: 0; display: flex; justify-content: center; }
.content-wrapper { width: 100%; max-width: 800px; padding: 32px 40px; }
.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 24px; margin-bottom: 24px; border-bottom: 1px solid var(--c-border);
  position: relative;
}
.breadcrumb { font-size: 13px; color: var(--c-muted); }
.breadcrumb a { color: var(--c-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--c-primary); }

/* Logo left — hover to reveal home icon */
/* Top-hamburger (mobile menu button in top-bar) */
.top-hamburger {
  display: none; /* hidden on desktop */
  width: 36px; height: 36px; border: none; background: transparent;
  border-radius: 8px; cursor: pointer; color: var(--c-text);
  align-items: center; justify-content: center; transition: background .15s;
  flex-shrink: 0;
}
.top-hamburger:hover { background: var(--c-menu-bg); }
.top-hamburger svg { width: 20px; height: 20px; }

.top-logo {
  display: flex; align-items: center; gap: 8px; text-decoration: none;
  position: relative; flex-shrink: 0;
}
.top-logo img { height: 28px; width: auto; }
.top-logo-home {
  display: flex; align-items: center; opacity: 0; transform: translateX(-8px);
  transition: all .25s ease; color: var(--c-muted); max-width: 0; overflow: hidden;
}
.top-logo-home svg { width: 18px; height: 18px; flex-shrink: 0; }
.top-logo:hover .top-logo-home { opacity: 1; transform: translateX(0); max-width: 24px; }
.top-logo:hover { gap: 4px; }
@media (max-width: 768px) {
  .top-logo:hover .top-logo-home { opacity: 0; max-width: 0; }
  .top-logo:hover { gap: 8px; }
}

/* ─── Search Box ─── */
.search-box { display: flex; align-items: center; gap: 2px; }
.search-input {
  width: 180px; height: 36px; padding: 0 12px;
  border: 1px solid var(--c-border); border-radius: 8px;
  font-size: 14px; font-family: var(--font-body);
  color: var(--c-text); background: var(--c-bg);
  outline: none; transition: border-color .15s, width .2s;
}
.search-input:focus { border-color: var(--c-primary); width: 240px; }
.search-input::placeholder { color: var(--c-muted); }
.search-submit-btn {
  width: 36px; height: 36px; border: none; background: transparent;
  border-radius: 8px; cursor: pointer; display: flex; align-items: center;
  justify-content: center; color: var(--c-muted); flex-shrink: 0;
}
.search-submit-btn:hover { background: var(--c-menu-bg); color: var(--c-text); }
.search-submit-btn svg { width: 18px; height: 18px; }
.top-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.lang-switch {
  font-size: 12px; font-weight: 700; color: var(--c-muted); text-decoration: none;
  padding: 4px 10px; border-radius: 6px; border: 1px solid var(--c-border);
  transition: all .15s;
}
.lang-switch:hover { color: var(--c-primary); border-color: var(--c-primary); }

/* ─── Content Area (Markdown rendered) ─── */
.content-inner { animation: fadeIn .3s ease; }
.content-inner h1 { font-family: var(--font-heading); font-size: 2rem; font-weight: 700; margin-bottom: 16px; color: var(--c-text); }
.content-inner .page-title { font-family: var(--font-heading); font-size: 2rem; font-weight: 700; margin-bottom: 8px; color: var(--c-text); }
.content-inner .page-cover { width: 100%; max-height: 420px; object-fit: cover; border-radius: var(--radius); margin-bottom: 16px; }
.content-inner h2 { font-family: var(--font-heading); font-size: 1.5rem; font-weight: 600; margin: 32px 0 12px; color: var(--c-text); }
.content-inner h3 { font-family: var(--font-heading); font-size: 1.2rem; font-weight: 600; margin: 24px 0 8px; }
.content-inner p { margin-bottom: 16px; font-size: 1.05rem; }
.content-inner a { color: var(--c-primary); text-decoration: none; }
.content-inner a:hover { text-decoration: underline; }
.content-inner img { display: block; margin: 24px auto; max-width: 100%; height: auto; border-radius: var(--radius); box-shadow: 0 4px 15px rgba(0,0,0,0.08); }
.content-inner iframe { max-width: 100%; border-radius: var(--radius); }
.content-inner .yt-embed { max-width: 100%; }

/* Media strip: overflow-x for side-by-side images/videos */
.media-strip { display: flex; gap: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; scroll-snap-type: x mandatory; padding-bottom: 8px; margin: 16px 0; cursor: grab; user-select: none; }
.media-strip.active { cursor: grabbing; }
.media-strip > * { flex: 0 0 auto; scroll-snap-align: start; min-width: 270px; max-width: 40%; }
.content-inner .media-strip > * { max-width: 40%; }
.media-strip > p, .media-strip > .yt-embed { margin: 0 !important; }
.content-inner .media-strip > blockquote {
  margin: 0 !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow) !important;
  border-left: none !important;
  padding: 16px 20px !important;
  background: var(--c-surface) !important;
  color: var(--c-text) !important;
}
.media-strip::-webkit-scrollbar { height: 4px; }
.media-strip::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 2px; }
.media-strip { scrollbar-width: thin; scrollbar-color: var(--c-border) transparent; }
.content-inner code { background: var(--c-menu-bg); padding: 2px 6px; border-radius: 4px; font-size: .9em; }
.content-inner pre { background: #1e293b; color: #e2e8f0; padding: 16px; border-radius: var(--radius); overflow-x: auto; margin: 16px 0; }
.content-inner pre code { background: transparent; padding: 0; color: inherit; }
.content-inner blockquote { border-left: 3px solid var(--c-primary); padding: 8px 16px; margin: 16px 0; color: var(--c-muted); background: var(--c-menu-bg); border-radius: 0 var(--radius) var(--radius) 0; }
.content-inner ul, .content-inner ol { margin: 8px 0 16px 20px; }
.content-inner li { margin-bottom: 6px; }
.content-inner table { border-collapse: collapse; margin: 16px 0; }
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 16px 0;
}
.table-wrapper table {
  width: auto;
  min-width: 100%;
  margin: 0;
}
.content-inner th, .content-inner td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--c-border); }
.content-inner th { font-weight: 600; background: var(--c-menu-bg); font-size: .9rem; }
.content-inner hr { border: none; border-top: 1px solid var(--c-border); margin: 32px 0; }

/* ─── FAQ Accordion ─── */
.content-inner details.faq {
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--c-surface);
  overflow: hidden;
}
.content-inner details.faq summary {
  padding: 14px 16px 14px 40px;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  list-style: none;
  position: relative;
  color: var(--c-text);
  user-select: none;
}
.content-inner details.faq summary::-webkit-details-marker { display: none; }
.content-inner details.faq summary::after {
  content: '+';
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.2rem;
  font-weight: 400;
  color: var(--c-muted);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  transition: all .2s;
}
.content-inner details.faq[open] summary::after {
  content: '−';
  background: var(--c-primary);
  color: #fff;
  border-color: var(--c-primary);
}
.content-inner details.faq .faq-body {
  padding: 0 16px 16px;
  color: var(--c-text);
  font-size: .95rem;
  line-height: 1.7;
}
.content-inner details.faq .faq-body strong,
.content-inner details.faq .faq-body b { font-weight: normal; }

/* ─── Chat Widget ─── */
.chat-body { display: flex; flex-direction: column; height: 100%; }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg { max-width: 85%; padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.5; }
.chat-msg.bot { align-self: flex-start; background: var(--c-menu-bg); border-bottom-left-radius: 4px; }
.chat-msg.user { align-self: flex-end; background: var(--c-primary); color: white; border-bottom-right-radius: 4px; }
.chat-msg.error { align-self: flex-start; background: #fef2f2; color: #dc2626; font-size: 13px; }
.chat-msg ul, .chat-msg ol { margin: 4px 0; padding-left: 20px; }
.chat-msg li { margin-bottom: 2px; }
.chat-input-row {
  display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--c-border);
  background: var(--c-surface); align-items: flex-end;
}
.chat-input-row textarea {
  flex: 1; border: 1px solid var(--c-border); border-radius: 10px;
  padding: 10px 14px; font-family: var(--font-body); font-size: 14px;
  resize: none; outline: none; line-height: 1.4; background: var(--c-bg);
}
.chat-input-row textarea:focus { border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(27,150,254,.1); }
.chat-send-btn {
  width: 38px; height: 38px; border: none; background: var(--c-primary); color: white;
  border-radius: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background .15s;
}
.chat-send-btn:hover { background: #0b85e8; }
.chat-send-btn:disabled { opacity: .5; cursor: not-allowed; }
.chat-loading { align-self: flex-start; padding: 8px 16px; }
.chat-loading .dot-pulse { display: flex; gap: 4px; }
.chat-loading .dot-pulse span { width: 6px; height: 6px; background: var(--c-muted); border-radius: 50%; animation: pulse 1.4s infinite ease-in-out both; }
.chat-loading .dot-pulse span:nth-child(1) { animation-delay: -.32s; }
.chat-loading .dot-pulse span:nth-child(2) { animation-delay: -.16s; }

/* ─── Footer ─── */
.site-footer {
  margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--c-border);
  font-size: 13px; color: var(--c-muted); text-align: center;
}

/* ─── Panel Overlay (mobile) ─── */
.panel-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 90; backdrop-filter: blur(2px);
}

/* ─── Mobile (≤768px) ─── */
@media (max-width: 768px) {
  .page-layout, .page-layout.menu-expanded, .page-layout.chat-expanded {
    grid-template-columns: 1fr; /* Only Col 2 */
  }
  .top-bar {
    position: sticky; top: 0; z-index: 105;
    background: var(--c-surface); /* Make top bar solid white so it doesn't look gray/transparent */
    margin: -20px -16px 20px -16px;
    padding: 16px 16px 12px 16px;
    border-bottom: 1px solid var(--c-border);
  }
  .col-menu, .col-chat {
    position: fixed; top: 0; height: 100vh; z-index: 200; /* Full height over top-bar */
    transition: transform .3s cubic-bezier(.4,0,.2,1);
    width: var(--sidebar-menu-w);
  }
  .col-menu { left: 0; transform: translateX(-100%); }
  .col-menu.open { transform: translateX(0); }
  .col-chat { right: 0; transform: translateX(100%); }
  .col-chat.open { transform: translateX(0); }
  .panel-overlay { z-index: 150; } /* Overlay below menu but above top-bar */
  .panel-overlay.open { display: block; }
  .content-wrapper { padding: 20px 16px; max-width: 100%; overflow-x: hidden; }
  .content-inner h1 { font-size: 1.5rem; }
  .content-inner .page-title { font-size: 1.5rem; }

  /* Top-bar hamburger visible on mobile */
  .top-hamburger { display: flex; }

  /* Floating toggle buttons — keep chat, remove menu */
  .col-menu .sidebar-icons, .col-chat .sidebar-icons {
    display: none; /* hidden on mobile */
  }
  .sidebar-panel { opacity: 1; }

  .floating-menu-btn { display: none !important; }
  .floating-chat-btn {
    position: fixed; z-index: 95; width: 48px; height: 48px;
    border: none; border-radius: 50%; background: var(--c-primary); color: white;
    box-shadow: 0 4px 12px rgba(0,0,0,.2); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    bottom: 24px; right: 16px;
  }
  .floating-chat-btn svg { width: 22px; height: 22px; }
}

/* ─── Animations ─── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%,80%,100% { transform: scale(0); } 40% { transform: scale(1); } }

/* ─── Listing Grid (blog/project/code index pages) ─── */
.listing-grid { margin-top: 24px; }
.listing-header { margin-bottom: 16px; }
.listing-header h2 { font-family: var(--font-heading); font-size: 1.1rem; font-weight: 600; color: var(--c-muted); }
.listing-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.listing-card {
  display: block; background: var(--c-surface); border-radius: var(--radius);
  border: 1px solid var(--c-border); text-decoration: none; color: var(--c-text);
  transition: all .15s; overflow: hidden;
}
.listing-card:hover { border-color: var(--c-primary); box-shadow: 0 4px 12px rgba(0,0,0,.08); }
.listing-card-body { padding: 16px 20px; }
.listing-card-body h3 {
  font-family: var(--font-heading); font-size: 1rem; font-weight: 600;
  margin: 0 0 8px; line-height: 1.4; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.listing-date { font-size: .8rem; color: var(--c-muted); display: block; margin-bottom: 6px; }
.listing-excerpt {
  font-size: .9rem; color: var(--c-muted); line-height: 1.5; margin: 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
@media (max-width: 768px) {
  .listing-cards { grid-template-columns: 1fr; }
}

/* ─── 404 page ─── */
.content-inner .error-404 { text-align: center; padding: 80px 0; }
.content-inner .error-404 h2 { font-size: 3rem; color: var(--c-muted); }
.content-inner .error-404 a { display: inline-block; margin-top: 16px; padding: 10px 20px; background: var(--c-primary); color: white; border-radius: 8px; text-decoration: none; }

/* ─── Carousel (CSS-only, scroll-snap, no JS) ─── */
.carousel {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch; gap: 16px;
  padding-bottom: 16px; scroll-behavior: smooth;
}
.carousel::-webkit-scrollbar { display: none; }
.carousel > * {
  scroll-snap-align: start; flex: 0 0 85%;
  max-width: 85%; min-width: 260px;
}
@media (min-width: 640px) { .carousel > * { flex: 0 0 45%; max-width: 45%; } }
@media (min-width: 1024px) { .carousel > * { flex: 0 0 30%; max-width: 30%; } }
.carousel-card {
  background: var(--c-surface); border-radius: var(--radius);
  border: 1px solid var(--c-border); overflow: hidden;
  box-shadow: var(--shadow);
}
.carousel-card img { width: 100%; height: 180px; object-fit: cover; margin: 0; border-radius: 0; }
.carousel-card-body { padding: 16px; }
.carousel-card-body h3 { margin: 0 0 8px; font-size: 1rem; }
.carousel-card-body p { font-size: .9rem; color: var(--c-muted); margin: 0; }

/* ─── Search Modal ─── */
.search-modal {
  display: none; position: fixed; inset: 0; z-index: 1000;
}
.search-modal-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,.5);
}
.search-modal-content {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 90vw; max-width: 900px; height: 85vh; max-height: 700px;
  background: var(--c-surface); border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  display: flex; flex-direction: column; overflow: hidden;
}
.search-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--c-border);
  font-weight: 600; font-family: var(--font-heading); flex-shrink: 0;
}
.search-modal-close {
  width: 32px; height: 32px; border: none; background: transparent;
  border-radius: 8px; cursor: pointer; display: flex; align-items: center;
  justify-content: center; color: var(--c-muted);
}
.search-modal-close:hover { background: var(--c-menu-bg); color: var(--c-text); }
.search-modal-close svg { width: 18px; height: 18px; }
.search-iframe {
  flex: 1; border: none; width: 100%;
}

/* Mobile: fullscreen modal */
@media (max-width: 768px) {
  .search-modal-content {
    width: 100vw; height: 100vh; max-width: none; max-height: none;
    border-radius: 0; top: 0; left: 0; transform: none;
  }
  .search-input { width: 120px; }
  .search-input:focus { width: 160px; }
}
