/* ========= Base / reset ========= */
* { box-sizing: border-box; }
:root {
  --container-max: 1100px;
  --pad-x: 16px;
  --brand: #1E90FF;
  --ink: #1c1c1c;
  --bg-soft: #f7f7f7;
  --border: #e5e7eb;
}

html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  font-family: Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

img, iframe, video { max-width: 100%; height: auto; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Constrain main containers */
header, main, footer, .contact-section, .vibe-embed {
  max-width: var(--container-max);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--pad-x);
  padding-right: var(--pad-x);
}

/* ========= Header / Footer ========= */
header, footer {
  padding: 20px;
  text-align: center;
  background: var(--bg-soft);
}

/* Simple nav */
.main-nav { display: flex; flex-wrap: wrap; gap: 12px; margin: 12px 0; }
.main-nav a { padding: 6px 10px; border-radius: 8px; }

/* ========= Layout (Flex, no floats) ========= */
main {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  padding: 20px;
}
aside {
  flex: 0 0 300px;
  width: 300px;
  position: sticky;
  top: 12px;
  z-index: 1;
}
section {
  flex: 1 1 auto;
  position: relative;
  z-index: 2; /* keep links above any injected widgets */
}

/* Safety: make sure injected widgets don't spill */
#sedo-widget-search,
.toc-widget { position: relative; z-index: 1; }

/* ========= TOC widget ========= */
.toc-widget {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 16px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.04);
}
.toc-title { margin: 0 0 8px; font-size: 15px; font-weight: 700; }
.toc-list { list-style: decimal inside; margin: 0; padding: 0; }
.toc-list li { margin: 6px 0; line-height: 1.4; }
.toc-list a { color: #1C1C1C; text-decoration: none; }
.toc-list a:hover { text-decoration: underline; }

/* ========= Floating chat trigger ========= */
.vibe-chat-btn {
  position: fixed; right: 20px; bottom: 20px;
  padding: 12px 16px; font-size: 14px; font-weight: 600;
  border: none; border-radius: 999px;
  background: var(--brand); color: #fff; cursor: pointer;
  box-shadow: 0 10px 24px rgba(30,144,255,0.25);
  z-index: 9998;
}

/* ========= Chat window ========= */
.vibe-chat-window {
  position: fixed; right: 20px; bottom: 80px;
  width: 380px; height: 520px; max-height: calc(100vh - 100px);
  background: #fff; border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
  display: none; flex-direction: column; overflow: hidden; z-index: 9999;
}
.vibe-chat-window.open { display: flex; }

.vibe-chat-header {
  background: #1C1C1C; color: #fff; padding: 10px 12px;
  display: flex; align-items: center; justify-content: space-between;
}
.vibe-chat-title { font-weight: 600; }
.vibe-chat-close { background: transparent; color: #fff; border: none; font-size: 20px; line-height: 1; cursor: pointer; }

/* Chat body / bubbles */
.vibe-chat-body {
  padding: 20px; background: #fafafa; overflow-y: auto; flex: 1; line-height: 1.6;
}
.vibe-msg {
  max-width: 85%; padding: 14px 16px; border-radius: 16px; margin: 12px 0;
  font-size: 15px; line-height: 1.6; box-shadow: 0 2px 5px rgba(0,0,0,0.08);
  word-wrap: break-word; white-space: pre-wrap;
}
.vibe-msg.user { margin-left: auto; background: #F1F1F1; }
.vibe-msg.bot  { margin-right: auto; background: #E0F0FF; }

/* Typing dots */
.vibe-typing { display: inline-flex; gap: 4px; padding: 8px 0 0; }
.vibe-typing span {
  width: 6px; height: 6px; border-radius: 50%; background: #c0c8d0;
  display: inline-block; animation: vbounce 1s infinite ease-in-out;
}
.vibe-typing span:nth-child(2) { animation-delay: 0.15s; }
.vibe-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes vbounce { 0%,80%,100%{transform:translateY(0);opacity:.6;}40%{transform:translateY(-6px);opacity:1;} }

/* Input area */
.vibe-chat-input {
  display: flex; align-items: center; gap: 10px; padding: 14px;
  border-top: 1px solid var(--border); background: #fff;
}
.vibe-chat-input textarea {
  flex: 1; resize: none; padding: 12px 14px; font-size: 14px;
  border: 1px solid #d1d5db; border-radius: 999px; outline: none;
  transition: border .2s, box-shadow .2s; min-height: 40px; max-height: 160px;
}
.vibe-chat-input textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(30,144,255,0.2); }
.vibe-chat-input button {
  padding: 12px 18px; font-size: 14px; border: none; border-radius: 999px;
  background: var(--brand); color: #fff; font-weight: 600; cursor: pointer;
  transition: background .2s, transform .1s;
}
.vibe-chat-input button:hover  { background: #187bcd; }
.vibe-chat-input button:active { transform: scale(0.95); }

/* ========= Embedded chat on homepage ========= */
.vibe-embed { margin: 0 auto 28px; padding: 16px 0; }
.vibe-embed h2 { margin: 0 0 6px; }
.vibe-embed-sub { margin: 0 0 12px; color: #555; }

.vibe-embed-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.vibe-embed-chips button {
  padding: 8px 12px; border: 1px solid #d1d5db; border-radius: 999px; background: #fff; cursor: pointer;
}
.vibe-embed-chips button:hover { background: #f3f4f6; }

.vibe-embed-box {
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.06);
  overflow: hidden;
}
.vibe-embed-body { padding: 18px; background: #fafafa; height: 380px; overflow-y: auto; }
.vibe-embed-input { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--border); background: #fff; }
.vibe-embed-input textarea {
  flex: 1; resize: none; padding: 12px 14px; font-size: 14px;
  border: 1px solid #d1d5db; border-radius: 999px; outline: none;
  transition: border .2s, box-shadow .2s; min-height: 40px; max-height: 160px;
}
.vibe-embed-input textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(30,144,255,0.2); }
.vibe-embed-input button {
  padding: 12px 18px; font-size: 14px; border: none; border-radius: 999px;
  background: var(--brand); color: #fff; font-weight: 600; cursor: pointer;
}
.vibe-embed-input button:hover { background: #187bcd; }

/* Optional: hide the floating bubble on the homepage only */
body.home .vibe-chat-btn { display: none; }

/* ========= Contact section ========= */
.contact-section {
  margin: 40px auto;
  padding: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
}
.contact-section h2 { margin-bottom: 8px; font-size: 20px; }
.contact-email { font-weight: 600; color: var(--brand); text-decoration: none; }
.contact-email:hover { text-decoration: underline; }

/* Footer clearance for floating chat (if enabled) */
footer { padding-bottom: 110px; }
@media (max-width: 640px) { footer { padding-bottom: 140px; } }

/* ========= Responsive (stack + clamps) ========= */
@media (max-width: 900px) {
  /* Stack columns */
  main { flex-direction: column; width: 100%; }
  aside, section { width: 100%; flex: 1 1 auto; position: static; margin: 0; min-width: 0; }
  .toc-widget, #sedo-widget-search { position: static; }

  /* Typography / spacing */
  header h1 { font-size: 1.6rem; line-height: 1.25; }
  header p { font-size: 1rem; }
  .main-nav a { padding: 10px 12px; font-size: 0.95rem; }

  /* Embedded chat */
  .vibe-embed { padding-top: 8px; }
  .vibe-embed-body { height: 300px; }
  .vibe-embed-input textarea { min-height: 44px; } /* comfortable tap target */

  /* Lists */
  .blog-list li { margin: 10px 0; }
}

@media (max-width: 640px) {
  /* Floating chat becomes full width-ish */
  .vibe-chat-window { right: 10px; left: 10px; width: auto; height: 60vh; bottom: 70px; }

  /* Reduce horizontal pressure */
  :root { --pad-x: 12px; }
  header h1 { font-size: 1.35rem; }
  .vibe-embed-input { gap: 8px; padding: 10px; }
  .vibe-embed-input button { padding: 12px 14px; }
  .vibe-msg { font-size: 14px; padding: 12px 14px; }

  /* Make banner/nav wrap nicely */
  header .main-nav { gap: 10px; }
}

/* ===== No-side-scroll hardening (all browsers) ===== */
html, body { width: 100%; overflow-x: hidden; }
article, section, .blog-list, .vibe-embed, .vibe-chat-body {
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
}
table { display: block; width: 100%; max-width: 100%; overflow-x: auto; }
pre, code { white-space: pre-wrap; word-break: break-word; }

/* ===== iOS Safari / DuckDuckGo (WebKit) specific ===== */
@supports (-webkit-touch-callout: none) {
  html, body { overflow-x: clip; } /* better than hidden on iOS */
  @media (max-width: 900px) { aside { position: static; } } /* sticky+flex quirk */
  /* 100vw quirk guards */
  header, main, footer, .vibe-embed, .vibe-embed-box { max-width: 100%; }
}

/* Third-party widget width clamps */
#sedo-widget-search, #sedo-widget-search * {
  max-width: 100%;
  box-sizing: border-box;
}
#sedo-widget-search input,
#sedo-widget-search select,
#sedo-widget-search button { max-width: 100%; }

/* Keep blog list always interactive above overlays */
.blog-list { position: relative; z-index: 2; }

