/* =========================
   Base & page background
   ========================= */
:root{
  /* One source of truth for the chat/form column on desktop */
  --chat-col-width: min(50vw, 1000px);
}

html, body {
  height: 100vh;
  margin: 0;
  padding: 0;
  font-size: 18px;
  font-family: "Noto Sans", "Segoe UI", Roboto, Arial, sans-serif;
  line-height: normal;
  background-color: #ffffff;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  background-image: url('/chat/static/images/DKSH-fantree-symbol_POS.png');
  background-repeat: no-repeat;
  background-position: left center;
  background-size: 30% auto;
}

/* =========================
   Header
   ========================= */
.top-header {
  width: 100%;
  background-color: #ba0020;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  position: relative;
  z-index: 10;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 30px;
}

.header-text-with-bubble { display: flex; align-items: center; gap: 6px; }
.header-text { color: #fff; font-weight: 500; font-size: 18px; line-height: 1; }

.header-bubble svg {
  height: 18px; width: auto; fill: #fff; display: block;
}

.header-logo { color: #fff; display: flex; align-items: center; white-space: nowrap; }
.header-logo img { display: block; height: 28px; }

/* =========================
   Main layout (non-scrolling)
   ========================= */
.main-container{
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: calc(100vh - 84px); /* header + footer spacing */
  width: 100%;
  max-width: 100%;
  margin: 30px 0 5px;
  padding: 20px 0 40px;
  box-sizing: border-box;
}

/* =========================
   Chat area
   ========================= */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0; /* allow child to size */
}

.chat-fade-wrapper {
  position: relative;
  flex: 1;
  overflow: hidden; /* keep fade masks functional */
}

/* The ONLY scrollable area */
.chat-scrollbox{
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;

  /* Center column using CSS grid */
  display: grid;
  grid-template-columns: 1fr min(var(--chat-col-width), 100%) 1fr;

  /* Natural row heights; stack from top */
  align-content: start;
  align-items: start;
  grid-auto-rows: max-content;
  row-gap: 16px;

  /* Scrollbar styling */
  scrollbar-width: thin;                    /* Firefox */
  scrollbar-color: rgba(0,0,0,.35) transparent;
}

.chat-scrollbox::-webkit-scrollbar { width: 10px; }            /* WebKit */
.chat-scrollbox::-webkit-scrollbar-track { background: transparent; }
.chat-scrollbox::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,.35);
  border-radius: 8px;
}

/* Place every direct child (messages, welcome, etc.) in the center column */
.chat-scrollbox > *{
  grid-column: 2;
  align-self: start; /* never stretch a tile vertically */
}

/* Empty/welcome state: pin content just above the form */
.chat-scrollbox.is-empty{
  align-content: end;         /* push to bottom of scrollbox */
  padding-bottom: 12px;       /* gap above the input form */
}

/* Welcome block alignment */
.welcome-wrapper{ display: flex; justify-content: flex-start; }
.welcome-box{
  margin: 0;
  max-width: 100%;
  font-size: 16px;
  line-height: inherit;
  text-align: left;
}
.welcome-box strong { font-weight: 600; }

/* Fade masks */
.fade-top, .fade-bottom{
  position: absolute; left: 0; width: 100%; height: 15px;
  pointer-events: none; z-index: 5;
}
.fade-top{ top: 0; background: linear-gradient(to bottom, #fff, rgba(255,255,255,0)); }
.fade-bottom{ bottom: 0; background: linear-gradient(to top, #fff, rgba(255,255,255,0)); }

/* =========================
   Messages
   ========================= */
.chat-message { width: fit-content; box-sizing: border-box; max-width: 100%; }

.bot-message, .user-message{
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 0;
  line-height: inherit;
}

/* Bot left */
.bot-message{
  flex-direction: row;
  justify-content: flex-start;
  background-color: #E9F9FC;
  margin-right: auto;
}

/* User right */
.user-message{
  flex-direction: row-reverse;
  justify-content: flex-end;
  background-color: #F3F3F3;
  margin-left: auto;
}

/* Avatars */
.chat-icon{ display: block; }
.bot-message .chat-icon{ margin: 0; flex-shrink: 0; margin-top: 2px; }
.user-message .chat-icon{ margin: 0; flex-shrink: 0; }

.chat-icon.bot-svg,
.chat-icon.user-svg{
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
}
.chat-icon.user-svg{ width: 28px; height: 28px; }
.chat-icon img{ width: 100%; height: 100%; display: block; }

.user-message .chat-bubble{ margin: 3px 0; }

/* Bubble text */
.chat-bubble{
  background: transparent;
  box-shadow: none;
  padding: 0;
  margin: 0;
  max-width: 88%;
  font-size: 14px;
  line-height: 1.5;
}

/* =========================
   Input form
   ========================= */
.form-wrapper{
  width: 100%;
  padding: 10px 0 0;
  display: flex;
  flex-direction: column;     /* ✅ stack input + disclaimer */
  align-items: center;        /* ✅ center both */
  justify-content: center;
  flex-shrink: 0;
}

.chat-form{
  width: var(--chat-col-width);
  max-width: none;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  padding: 0;
  border-radius: 0;
}

.input-wrapper{
  display: flex;
  align-items: center;
  width: 100%;
  max-width: none;
  background-color: #fff;
  border: 1px solid rgba(0,119,182,0.21);
  box-shadow: 0 12px 49px 0 rgba(0, 180, 216, 0.12);
  border-radius: 0;
  padding: 20px;
  transition: box-shadow 0.3s ease;
}

.input-wrapper textarea{
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  padding: 0;
  font-size: 16px;
  line-height: normal;
  color: #333;
  resize: none;
  height: inherit; min-height: inherit; max-height: inherit;
  overflow-y: auto;
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
}

.input-wrapper button{
  border: none;
  background: none;
  color: #777;
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  transition: color 0.2s ease;
  display: flex;
  align-items: center;
}

.input-wrapper .icon-btn img{ width: 22px; height: auto; }
.input-wrapper button:hover{ color: #1a73e8; }

.prompt-disclaimer {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
  color: rgba(0, 0, 0, 0.55); /* adjust for your theme */
  padding: 0 12px 6px;
  user-select: none;
}

.prompt-disclaimer.is-hidden {
  display: none;
}


/* =========================
   Bot response content
   ========================= */
.bot-response{ font-size: 14px; line-height: 1.5; margin-top: 1px; }

.bot-response p,
.bot-response a,
.bot-response ul,
.bot-response ol,
.bot-response li,
.bot-response table,
.bot-response th,
.bot-response td{
  font-size: inherit;
  line-height: 1.5;
  white-space: normal !important;
  word-break: break-word;
}

.bot-response p{ margin: 8px 0; padding: 5px 0; }
.bot-response p.sources-heading{ margin-top: 15px; }
.bot-response a{ color: #1a0dab; text-decoration: underline; }

.bot-response ul{ list-style-type: disc; padding-left: 20px; margin: 5px 0; }
.bot-response li{ margin-bottom: 5px; }

.bot-response table{
  border-collapse: collapse;
  table-layout: fixed;
  width: 100%;
  margin-top: 10px;
  overflow-x: auto;
  display: block;
}
.bot-response th, .bot-response td{
  border: 1px solid #d8d8d8;
  padding: 8px;
  text-align: left;
  vertical-align: top;
  word-wrap: break-word;
  min-width: 120px;
}
.bot-response th{
  background-color: #d8f8ff;
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================
   Feedback buttons
   ========================= */
.feedback-buttons{
  display: flex;
  justify-content: flex-start;
  gap: 16px;
  margin: 12px 0;
}

.btn-icon{
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  width: 32px; height: 32px;
  display: block;
  align-items: center; justify-content: center;
  transition: transform 0.2s ease;
}
.btn-icon.active{ color: green; }
.btn-icon svg{ width: 20px; height: 20px; stroke: currentColor; fill: none; }
.btn-icon:hover{ transform: scale(1.2); }

.btn-icon:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.bot-error-inline {
  display: flex;
  align-items: center;        /* vertical alignment */
  justify-content: space-between;
  gap: 12px;
}

.bot-error-inline p {
  margin: 0;                  /* remove default <p> spacing */
  flex: 1;                    /* take all available width */
}

.retry-inline {
  flex-shrink: 0;             /* prevent icon shrinking */
  opacity: 0.75;
}

.retry-inline:hover {
  opacity: 1;
}


/* =========================
   Footer & toast
   ========================= */
.footer{
  position: inherit;
  width: inherit;
  padding: 15px 30px;
  font-size: 0.7rem;
  color: #1A1A1A;
  z-index: 10;
}
.footer-content{
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.footer-left{ display: flex; align-items: center; gap: 12px; }
.footer-left .link-item + .link-item::before{
  content: "|"; margin: 0 8px; color: inherit; opacity: .6;
}
.footer-link{ color: inherit; text-decoration: none; }
.footer-link:hover, .footer-link:focus{ text-decoration: underline; }
.footer-copy{ color: rgba(26,26,26,0.55); }
.label-full{ display: inline; } .label-short{ display: none; }
.copy-full{ display: inline; } .copy-short{ display: none; }

.toast{
  visibility: hidden;
  min-width: 160px;
  background-color: #333;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 8px 12px;
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.3s ease, visibility 0s linear 0.3s;
}
.toast.show{ visibility: visible; opacity: 1; transition: opacity 0.3s ease; }

/* =========================
   Animations
   ========================= */
@keyframes fadeInUp{
  0%{ opacity: 0; transform: translateY(32px); }
  80%{ opacity: 1; transform: translateY(-4px); }
  100%{ opacity: 1; transform: translateY(0); }
}
.fade-in-up{ animation: fadeInUp 0.45s cubic-bezier(.43,.07,.69,.99); will-change: opacity, transform; }

.fade-in-welcome{
  opacity: 0;
  animation: fadeInOpacity 2s ease-in forwards;
  animation-delay: 0.3s;
}
@keyframes fadeInOpacity{ from{opacity:0;} to{opacity:1;} }



/* ===== Mobile ===== */
@media (max-width: 600px) {
  html {
    font-size: 14px;
  }

  /* HEADER */
  .top-header {
    display: flex;
  }

  .header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 44px;
    width: 100%;
    padding: 3px 20px;
  }

  .header-text-with-bubble {
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .header-text { line-height: 1; font-size: 16px; }
  .header-bubble svg { height: 16px; display: block; }

  .header-logo {
    display: flex;
    align-items: center;
  }
  .header-logo img {
    display: block;
    height: 24px;
  }

  /* MAIN */
  .main-container {
    width: 94vw !important;
    max-width: 94vw !important;
    min-width: 94vw !important;
    margin: 5px auto !important;
    padding: 20px 3px 0px!important;
    height: calc(100vh - 90px) !important;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    /* no scrolling on main; chat handles it */
  }

  /* CHAT AREA */
  .chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    margin: 0;
    min-height: 0;
  }

  .chat-fade-wrapper {
    position: relative;
    flex: 1;
    overflow: hidden; /* keep fades */
  }

  .chat-scrollbox {
    flex: 1;
    overflow-y: auto;          /* ✅ scroll in chat on mobile too */
    overflow-x: hidden;
    height: 100%;
    padding: 10px 0;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;

    /* visible scrollbar on mobile webkit */
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,.35) transparent;
  }
  .chat-scrollbox::-webkit-scrollbar { width: 10px; }
  .chat-scrollbox::-webkit-scrollbar-track { background: transparent; }
  .chat-scrollbox::-webkit-scrollbar-thumb { background: rgba(0,0,0,.35); border-radius: 8px; }

  .welcome-box {
    font-size: 14px;
  }
  /* Message bubble adjustments for mobile */
  .bot-message,
  .user-message {
    align-items: flex-start; /* align icon with first line */
    gap: 8px;
    padding: 10px 14px;
    border-radius: 0;
    max-width: 100%;
    width: fit-content;
    box-sizing: border-box;
  }

  .bot-message {
    flex-direction: row;
    justify-content: flex-start;
    background-color: #E9F9FC;
    margin-right: auto;
  }

  .bot-message .chat-icon {
    margin: 0; /* container padding handles spacing */
    flex-shrink: 0;
    margin-top: 10px;
  }

  .user-message {
    flex-direction: row-reverse;
    justify-content: flex-end;
    background-color: #F3F3F3;
    margin-left: auto;
    align-items: flex-start;
  }

  .chat-bubble {
    background: transparent;
    box-shadow: none;
    padding: 0;
    margin: 0;
    max-width: 85%;
    font-size: 1rem;
    line-height: 1.4;
    word-break: break-word;
  }

  .bot-response {
    font-size: 1rem;
    line-height: 1.6;
  }

  .bot-response p {
    margin: 1px 0 5px;
    padding-bottom: 5px;
  }

  .feedback-buttons {
    margin: 12px 0 14px;
  }

  .chat-icon.bot-svg,
  .chat-icon.user-svg {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    margin: 0;
  }

  .chat-icon img {
    display: block;
    margin-top: 0;
  }
  .chat-icon.bot-svg img {
    align-items: first baseline;
  }

  /* CHAT FORM */
  .chat-form {
    flex-direction: column;
    padding: 0;
    width: 100%;
  }

  .form-wrapper {
    width: 100%;
    padding: 0;
    display: flex;
    justify-content: center;
    margin-bottom: 30px;
  }

  .input-wrapper {
    flex-direction: row;
    width: 100%;
    max-width: 100%;
    padding: 4px 6px;
    border-radius: 0;
    min-width: unset;
    box-sizing: border-box;
  }

  .input-wrapper textarea {
      padding: 10px;
      font-size: 14px;
      width: 100%;
  }

  .input-wrapper button {
    font-size: 18px;
    padding: 10px;
  }

  /* FOOTER: single centered line */
  .footer {
    padding: 15px 20px;
    font: 12px;
  }

  .footer-left {
    display: flex;
    align-items: center;
    gap: 0;
  }

  .footer-left .link-item + .link-item::before {
    content: "|";
    margin: 0 10px;
    opacity: .6;
  }

  .footer-copy {
    margin-right: 0;
    white-space: nowrap;
  }

  /* Labels/copyright toggles */
  .label-full { display: none; }
  .label-short { display: inline; }
  .copy-full  { display: none; }
  .copy-short { display: inline; }
}
