/* ===== หน้ากฎ (/rules) ===== */

.rules-body .nav {
  position: sticky;
}

.rl-wrap {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: clamp(20px, 4vh, 48px) clamp(16px, 3vw, 40px) 56px;
}

/* ---------- hero ---------- */
.rl-hero {
  text-align: center;
  max-width: 680px;
  margin: 0 auto clamp(20px, 3vh, 32px);
}

.rl-eyebrow {
  margin: 0 0 6px;
  font: 500 12px/1 var(--mono);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--faint);
}

.rl-hero h1 {
  margin: 0;
  font-size: clamp(28px, 2.4vw + 16px, 44px);
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.rl-sub {
  margin: 10px 0 20px;
  color: var(--muted);
}

.rl-search {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 50px;
  padding: 0 16px;
  border-radius: 14px;
  border: 1px solid var(--line-2);
  background: rgba(var(--surface-rgb), 0.9);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.rl-search:focus-within {
  border-color: var(--text);
  box-shadow: 0 0 0 4px rgba(var(--fg-rgb), 0.06);
}

.rl-search svg {
  width: 18px;
  height: 18px;
  flex: none;
  color: var(--faint);
}

.rl-search input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  background: none;
  color: var(--text);
  font: inherit;
}

.rl-search input::placeholder {
  color: var(--faint);
}

/* ---------- tabs ---------- */
.rl-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 24px;
}

.rl-tab {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(var(--surface-rgb), 0.85);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.rl-tab:hover {
  border-color: var(--line-2);
}

.rl-tab:active {
  transform: scale(0.98);
}

.rl-tab.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.rl-tab-ic {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
}

.rl-tab.on .rl-tab-ic {
  background: rgba(var(--bg-rgb), 0.14);
  color: var(--accent-ink);
}

.rl-tab-ic svg {
  width: 20px;
  height: 20px;
}

.rl-tab-tx {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.rl-tab-tx b {
  font-size: 15px;
  white-space: nowrap;
}

.rl-tab-tx small {
  font-size: 12px;
  opacity: 0.65;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- layout ---------- */
.rl-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}

.rl-side {
  position: sticky;
  top: calc(clamp(56px, 6vh + 20px, 72px) + 16px);
  max-height: calc(100vh - 120px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-right: 4px;
  scrollbar-width: thin;
}

.rl-side-hd {
  margin: 0 0 6px 12px;
  font: 500 11px/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
}

.rl-side a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  border-left: 2px solid transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.rl-side a:hover {
  background: rgba(var(--fg-rgb), 0.04);
  color: var(--text);
}

.rl-side a.on {
  background: rgba(var(--fg-rgb), 0.07);
  color: var(--text);
  font-weight: 600;
  border-left-color: var(--text);
  border-radius: 4px 10px 10px 4px;
}

.rl-side small {
  flex: none;
  font: 500 11px/1 var(--mono);
  padding: 3px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
}

/* ---------- content ---------- */
.rl-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.rl-cat-hd {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 4px 2px 6px;
}

.rl-cat-hd h2 {
  margin: 0;
  font-size: clamp(20px, 1vw + 14px, 26px);
}

.rl-cat-hd p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.rl-cat-ic {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 12px;
  border: 1px solid var(--line-2);
  background: var(--surface);
}

.rl-cat-ic svg {
  width: 22px;
  height: 22px;
}

.rl-sec {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: rgba(var(--surface-rgb), 0.92);
  overflow: hidden;
  scroll-margin-top: 90px;
}

.rl-sec-hd {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(var(--fg-rgb), 0.02);
}

.rl-sec-cat {
  display: block;
  margin-bottom: 2px;
  font: 500 11px/1.4 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
}

.rl-sec-hd h2 {
  margin: 0;
  font-size: 19px;
  line-height: 1.35;
}

.rl-sec-bd {
  padding: 10px 22px 18px;
}

.rl-h {
  margin: 18px 0 6px;
  padding-top: 14px;
  border-top: 1px dashed var(--line-2);
  font-size: 15.5px;
  line-height: 1.45;
}

.rl-sec-bd>.rl-h:first-child {
  margin-top: 6px;
  padding-top: 0;
  border-top: 0;
}

.rl-rule {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid rgba(var(--fg-rgb), 0.05);
}

.rl-rule:last-child {
  border-bottom: 0;
}

.rl-n {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-top: -1px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font: 600 12px/1 var(--mono);
  color: var(--muted);
}

.rl-dot {
  width: 6px;
  height: 6px;
  margin: 10px auto 0;
  border-radius: 50%;
  background: var(--faint);
}

.rl-tx,
.rl-p {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.65;
}

.rl-p {
  margin: 8px 0;
  color: var(--text);
}

.rl-p+.rl-p {
  margin-top: 0;
}

/* บรรทัด "หมายเหตุ" */
.rl-note {
  color: var(--muted);
  font-size: 0.94em;
}

/* บรรทัด "โทษ :" */
.rl-pen {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 6px;
  margin-top: 2px;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.92em;
  font-weight: 500;
}

/* ข้อที่เว็บต้นทางเน้นสีแดง */
.is-hl .rl-tx>span:first-child,
.rl-p.is-hl>span:first-child {
  color: var(--danger);
  font-weight: 500;
}

.is-hl .rl-n {
  background: var(--danger-soft);
  border-color: transparent;
  color: var(--danger);
}

/* ป้ายใบเหลือง / ส้ม / แดง */
.rl-card {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 8px 1px 6px;
  border-radius: 6px;
  font-size: 0.92em;
  font-weight: 600;
  white-space: nowrap;
  vertical-align: 1px;
}

.rl-card::before {
  content: '';
  width: 9px;
  height: 12px;
  border-radius: 2px;
  background: currentColor;
}

.rl-card-y {
  color: #d9a400;
  background: rgba(250, 204, 21, 0.14);
}

.rl-card-o {
  color: #f07b14;
  background: rgba(249, 115, 22, 0.14);
}

.rl-card-r {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.14);
}

:root[data-theme='light'] .rl-card-y {
  color: #946c00;
}

:root[data-theme='light'] .rl-card-o {
  color: #c2560a;
}

:root[data-theme='light'] .rl-card-r {
  color: #c81e1e;
}

.rl-content mark {
  background: rgba(250, 204, 21, 0.35);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

.rl-foot {
  margin: 6px 4px 0;
  font-size: 13px;
  color: var(--faint);
  text-align: center;
}

.rl-empty,
.rl-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 56px 20px;
  border: 1px dashed var(--line-2);
  border-radius: var(--r);
  color: var(--muted);
  text-align: center;
}

.rl-empty b {
  color: var(--text);
}

.rl-loading {
  flex-direction: row;
  justify-content: center;
  gap: 10px;
}

.rl-loading .spin {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--line-2);
  border-top-color: var(--text);
  animation: spin 0.8s linear infinite;
}

.rl-top {
  position: fixed;
  right: clamp(16px, 3vw, 32px);
  bottom: clamp(16px, 3vw, 32px);
  z-index: 15;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 8px 24px rgba(var(--shadow-rgb), 0.25);
  cursor: pointer;
}

.rl-top[hidden] {
  display: none;
}

.rl-top svg {
  width: 18px;
  height: 18px;
}

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .rl-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .rl-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  .rl-side {
    top: clamp(56px, 6vh + 20px, 72px);
    z-index: 5;
    max-height: none;
    flex-direction: row;
    gap: 6px;
    margin: 0 calc(-1 * clamp(16px, 3vw, 40px));
    padding: 10px clamp(16px, 3vw, 40px);
    overflow-x: auto;
    background: rgba(var(--bg-rgb), 0.86);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(var(--fg-rgb), 0.06);
    scrollbar-width: none;
  }

  .rl-side::-webkit-scrollbar {
    display: none;
  }

  .rl-side:empty {
    display: none;
  }

  .rl-side-hd {
    display: none;
  }

  .rl-side a {
    flex: none;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 6px 12px;
    white-space: nowrap;
    font-size: 13px;
  }

  .rl-side a.on {
    border-radius: 999px;
    border-color: var(--text);
    background: var(--accent);
    color: var(--accent-ink);
  }

  .rl-sec {
    scroll-margin-top: 140px;
  }
}

@media (max-width: 520px) {
  .rl-tab {
    padding: 10px;
    gap: 10px;
  }

  .rl-tab-ic {
    width: 32px;
    height: 32px;
  }

  .rl-tab-tx small {
    display: none;
  }

  .rl-sec-hd {
    padding: 14px 16px 12px;
  }

  .rl-sec-bd {
    padding: 6px 16px 14px;
  }

  .rl-rule {
    grid-template-columns: 26px minmax(0, 1fr);
    gap: 8px;
  }

  .rl-n {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }

  .nav-link.sm-icon span {
    display: none;
  }

  .nav-link.sm-icon {
    width: clamp(34px, 1vw + 26px, 42px);
    padding: 0;
    justify-content: center;
  }
}

/* ======================================================================
   ระบบแก้ไขกฎ (แอดมิน)
   ====================================================================== */
.rl-sec-hd {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.rl-sec-ttl {
  min-width: 0;
}

.rl-tools {
  display: flex;
  gap: 6px;
  flex: none;
}

.rl-tbtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.rl-tbtn:hover:not(:disabled) {
  border-color: var(--text);
}

.rl-tbtn:disabled {
  opacity: 0.35;
  cursor: default;
}

.rl-tbtn.icon {
  width: 32px;
  padding: 0;
  justify-content: center;
}

.rl-tbtn svg,
.rl-add svg,
.rl-btn svg,
.rl-adminbar>svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.rl-adminbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid rgba(61, 220, 151, 0.35);
  background: var(--ok-soft);
  color: var(--ok);
}

.rl-adminbar div {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.rl-adminbar b {
  font-size: 14px;
}

.rl-adminbar span {
  font-size: 13px;
  color: var(--muted);
}

.rl-add {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  border-radius: var(--r);
  border: 1.5px dashed var(--line-2);
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.rl-add:hover {
  border-color: var(--text);
  color: var(--text);
}

.rl-me {
  color: var(--ok);
}

/* ---------- modal ---------- */
body.rl-lock {
  overflow: hidden;
}

.rl-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: clamp(0px, 3vw, 32px);
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: rlFade 0.15s ease;
}

@keyframes rlFade {
  from {
    opacity: 0;
  }
}

.rl-dlg {
  display: flex;
  flex-direction: column;
  width: min(1100px, 100%);
  height: min(860px, 100%);
  border-radius: var(--r);
  border: 1px solid var(--line-2);
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.rl-dlg-hd,
.rl-dlg-ft {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
}

.rl-dlg-hd {
  border-bottom: 1px solid var(--line);
}

.rl-dlg-hd b {
  font-size: 17px;
}

.rl-dlg-ft {
  border-top: 1px solid var(--line);
}

.rl-ft-r {
  display: flex;
  gap: 8px;
}

.rl-dlg-bd {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 18px;
}

.rl-fld {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.rl-fld input {
  height: 44px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  outline: 0;
}

.rl-fld input:focus,
#edBody:focus {
  border-color: var(--text);
}

.rl-edtabs {
  display: flex;
  align-items: center;
  gap: 4px;
}

.rl-edtabs>button {
  display: none;
  padding: 6px 12px;
  border-radius: 8px;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.rl-edtabs>button.on {
  background: var(--surface-2);
  color: var(--text);
}

.rl-edtools {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

.rl-mini {
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--line-2);
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}

.rl-mini:hover {
  color: var(--text);
  border-color: var(--text);
}

.rl-help {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 6px 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 13px;
}

.rl-help[hidden] {
  display: none;
}

.rl-help div {
  display: flex;
  gap: 10px;
  align-items: baseline;
}

.rl-help code {
  flex: none;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--bg);
  font: 12px var(--mono);
  white-space: nowrap;
}

.rl-help span {
  color: var(--muted);
}

.rl-edpanes {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

#edBody {
  width: 100%;
  height: 100%;
  min-height: 240px;
  resize: none;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--line-2);
  background: var(--bg);
  color: var(--text);
  font: 14.5px/1.7 'IBM Plex Sans Thai', system-ui, sans-serif;
  outline: 0;
  tab-size: 2;
}

.rl-edprev {
  min-height: 0;
  overflow: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(var(--fg-rgb), 0.015);
}

.rl-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: none;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.rl-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.rl-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.rl-btn.primary.loading span::after {
  content: '…';
}

.rl-btn.ghost:hover {
  border-color: var(--text);
}

.rl-btn.danger {
  border-color: transparent;
  color: var(--danger);
}

.rl-btn.danger:hover,
.rl-btn.danger.armed {
  background: var(--danger-soft);
}

.rl-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 200;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.rl-toast.bad {
  background: var(--danger);
  color: #fff;
}

.rl-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 760px) {
  .rl-modal {
    padding: 0;
  }

  .rl-dlg {
    height: 100%;
    border-radius: 0;
    border: 0;
  }

  .rl-edtabs>button {
    display: block;
  }

  .rl-edpanes {
    grid-template-columns: 1fr;
  }

  .rl-edpanes:not([data-view='preview']) .rl-edprev,
  .rl-edpanes[data-view='preview'] #edBody {
    display: none;
  }

  .rl-tbtn:not(.icon) span {
    display: none;
  }

  .rl-tbtn:not(.icon) {
    width: 32px;
    padding: 0;
    justify-content: center;
  }

  .rl-dlg-ft .rl-btn.danger span {
    display: none;
  }
}

@media (max-width: 760px) {
  .rl-dlg-ft .rl-btn.danger.armed span {
    display: inline;
  }
}

/* ======================================================================
   AI ตอบคำถามเรื่องกฎ
   ====================================================================== */
body.has-ai .rl-top {
  bottom: calc(clamp(16px, 3vw, 32px) + 60px);
}

.ai-fab {
  position: fixed;
  right: clamp(16px, 3vw, 32px);
  bottom: clamp(16px, 3vw, 32px);
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  padding: 0 20px 0 16px;
  border-radius: 999px;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: transform 0.15s;
}

.ai-fab:hover {
  transform: translateY(-2px);
}

.ai-fab[hidden],
.ai-box[hidden] {
  display: none;
}

.ai-fab svg {
  width: 20px;
  height: 20px;
}

/* ปุ่มลอยใช้โลโก้ ASYNC แทนไอคอน */
html:not(#ai) .ai-fab:not(#x) {
  padding-left: 6px !important;
  gap: 10px;
}

.ai-fab-logo {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: block;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.ai-box {
  position: fixed;
  right: clamp(16px, 3vw, 32px);
  bottom: clamp(16px, 3vw, 32px);
  z-index: 60;
  display: flex;
  flex-direction: column;
  width: min(400px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 110px));
  border-radius: 20px;
  border: 1px solid var(--line-2);
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  animation: aiIn 0.18s ease;
}

@keyframes aiIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}

.ai-hd {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 16px;
  border-bottom: 1px solid var(--line);
}

.ai-hd div {
  flex: 1;
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.ai-hd small {
  color: var(--faint);
  font-size: 12px;
}

.ai-ic {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
}

.ai-ic svg {
  width: 18px;
  height: 18px;
}

.ai-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  scroll-behavior: smooth;
}

.ai-msg {
  display: flex;
}

.ai-msg.me {
  justify-content: flex-end;
}

.ai-bub {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 14px;
  background: var(--surface-2);
  font-size: 14px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.ai-bub small {
  color: var(--faint);
}

.ai-msg.bot .ai-bub {
  border-top-left-radius: 4px;
}

.ai-msg.me .ai-bub {
  background: var(--accent);
  color: var(--accent-ink);
  border-top-right-radius: 4px;
}

.ai-bub.err {
  background: var(--danger-soft);
  color: var(--danger);
}

.ai-src {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(var(--fg-rgb), 0.08);
}

.ai-src small {
  width: 100%;
  font-size: 11px;
  letter-spacing: 0.06em;
}

.ai-src a {
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  font-size: 12.5px;
  text-decoration: none;
  color: var(--text);
}

.ai-src a:hover {
  border-color: var(--text);
}

.ai-unsure {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 13px;
  line-height: 1.5;
}

.ai-unsure svg {
  width: 16px;
  height: 16px;
  flex: none;
  margin-top: 2px;
}

.ai-ticket {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
  padding: 9px 12px;
  border-radius: 10px;
  background: #5865f2;
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
}

.ai-ticket:hover {
  filter: brightness(1.08);
}

.ai-ticket svg {
  width: 17px;
  height: 17px;
}

.ai-sug {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ai-sug button {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.ai-sug button:hover {
  color: var(--text);
  border-color: var(--text);
}

.ai-dots {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}

.ai-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: aiDot 1s infinite ease-in-out;
}

.ai-dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.ai-dots i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes aiDot {

  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }

  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.ai-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 6px;
  border-top: 1px solid var(--line);
}

.ai-form textarea {
  flex: 1;
  min-height: 42px;
  max-height: 120px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line-2);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14.5px;
  line-height: 1.45;
  resize: none;
  outline: 0;
}

.ai-form textarea:focus {
  border-color: var(--text);
}

.ai-send {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 12px;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}

.ai-send svg {
  width: 18px;
  height: 18px;
}

.ai-note {
  margin: 0;
  padding: 0 12px 10px;
  font-size: 11.5px;
  color: var(--faint);
  text-align: center;
}

@media (max-width: 640px) {
  .ai-box {
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    border-radius: 0;
    border: 0;
  }

  body.ai-open {
    overflow: hidden;
  }

  .ai-fab {
    height: 46px;
    padding: 0 16px 0 14px;
  }
}

.ai-left {
  margin-top: 8px;
  font-size: 12px;
  color: var(--faint);
}

/* ข้อที่ลิงก์มาจากคำตอบ AI — ไฮไลต์แวบนึง */
.rl-flash {
  animation: rlFlash 2.6s ease;
  border-radius: 10px;
}

@keyframes rlFlash {

  0%,
  35% {
    background: rgba(250, 204, 21, 0.18);
    box-shadow: 0 0 0 6px rgba(250, 204, 21, 0.18);
  }

  100% {
    background: transparent;
    box-shadow: 0 0 0 6px transparent;
  }
}

.ai-ic {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  padding: 0;
  background: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15);
}

.ai-ic img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  object-fit: contain;
}

.ai-hd {
  display: flex;
  align-items: center;
  gap: 12px;
}