:root {
  --chatbox-bg: #fafdff;
  --chatbox-header-bg: #f8f9fa;
  --chatbox-border: #e7ecef;
  --chatbox-shadow: 0 4px 32px #1a413733;
  --chatbox-title: #1c1c1c;
  --chatbox-msg-bg: #fff;
  --chatbox-msg-border: #e3e9ed;
  --chatbox-accent: #1c1c1c;
  --chatbox-link: #0d6efd;
  --chatbox-user: #232524;
  --chatbox-input-bg: #f9fafb;
  --chatbox-sendbtn-bg: #232524;
  --chatbox-sendbtn-disabled: #e3e3e3;
  --chatbox-sendbtn-disabled-txt: #999;
  --disclaimer-warn: #b90000;
  --chatbox-icon: #888;
  --mic-blue: #0d6efd;
  --mc-chatbox-gap: 30px;
  --mc-chatbox-cap: 900px;
  --mc-input-rows: 4;
  --mc-input-fs: 16px;
  --mc-input-lh: 1.4;
  --mc-input-vpad: 6px;
}

.mc-floating-chatbox,
.mc-chatbox-half-fullsize { z-index: 2147483647 !important; }

.mc-chatbox-overlay {
  z-index: 2147483646 !important;
  position: fixed;
  inset: 0;
  background: rgba(30, 40, 60, 0.35);
  transition: opacity 0.3s;
}

.mc-chatbox-openbtn,
.chatbox-openbtn,
.mc-bot-btn-stack { z-index: 2147483645 !important; }

.mc-floating-chatbox {
  position: fixed;
  right: var(--mc-chatbox-gap);
  bottom: var(--mc-chatbox-gap);
  width: 420px;
  min-height: 400px;
  height: clamp(400px, 70vh, var(--mc-chatbox-cap));
  max-height: min(70vh, var(--mc-chatbox-cap), calc(100dvh - (var(--mc-chatbox-gap) * 2)));
  background: var(--chatbox-bg);
  border-radius: 18px;
  box-shadow: var(--chatbox-shadow);
  border: 1px solid var(--chatbox-border);
  display: flex;
  flex-direction: column;
  animation: mc-fadein 0.4s;
  overflow: hidden;
  transition: all 0.18s cubic-bezier(.7,.2,.2,1);
}

@keyframes mc-fadein {
  from { opacity: 0; transform: translateY(40px); }
  to { opacity: 1; transform: none; }
}

.mc-floating-header {
  background: var(--chatbox-header-bg);
  border-bottom: 1px solid #e0e0e0;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 12px 12px 0 0;
  box-shadow: 0 2px 8px rgba(60, 60, 60, 0.04);
  font-size: 1.15rem;
}

.mc-chatbox-title {
  font-size: 16px;
  color: var(--chatbox-title);
  font-weight: 500;
  letter-spacing: 0.1px;
}

.mc-floating-actions { display: flex; align-items: center; gap: 3px; }

.mc-chatbox-fullscreen,
.mc-floating-close {
  background: transparent;
  border: none;
  color: var(--chatbox-icon);
  cursor: pointer;
  transition: color 0.15s;
}

.mc-chatbox-fullscreen {
  font-size: 20px;
  margin-right: 4px;
  padding: 0 6px;
}
.mc-chatbox-fullscreen:hover { color: var(--chatbox-title); }

.mc-floating-close {
  font-size: 22px;
  padding: 0 8px;
}
.mc-floating-close:hover { color: var(--chatbox-title); opacity: 1; }

.mc-chatbox-window {
  background: var(--chatbox-msg-bg);
  border: 1px solid var(--chatbox-msg-border);
  border-radius: 12px;
  flex: 1 1 auto;
  padding: 20px 14px;
  margin: 12px 14px 0 14px;
  display: flex;
  flex-direction: column;
  overflow-y: scroll;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable both-edges;
  scrollbar-width: thin;
  scrollbar-color: #9aa7b1 #f1f3f5;
  align-items: flex-start;
  text-align: left;
}

.mc-chatbox-window::-webkit-scrollbar { width: 8px; }
.mc-chatbox-window::-webkit-scrollbar-thumb { background: #9aa7b1; border-radius: 6px; }
.mc-chatbox-window::-webkit-scrollbar-track { background: #f1f3f5; }

.mc-chatbox-message { margin-bottom: 9px; }
.mc-chatbox-author { font-weight: 600; white-space: nowrap; }
.mc-chatbox-text { white-space: pre-line; }

.mc-msg-user,
.mc-msg-gpt {
  color: var(--chatbox-user);
  font-size: 15px;
  line-height: 1.25;
}

.mc-chatbox-form {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 0 14px;
  margin: 6px 0 4px;
}

.mc-chatbox-input {
  flex: 1 1 0;
  border: 1px solid var(--chatbox-msg-border);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 15px;
}

.mc-chatbox-sendbtn {
  background: var(--chatbox-sendbtn-bg);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 5px 12px;
  font-size: 0.95rem;
  cursor: pointer;
}
.mc-chatbox-sendbtn:disabled {
  background: var(--chatbox-sendbtn-disabled);
  color: var(--chatbox-sendbtn-disabled-txt);
  cursor: not-allowed;
  opacity: 0.65;
}

.mc-chatbox-hint {
  text-align: center;
  font-size: 0.93em;
  color: var(--chatbox-title);
  margin: 4px 0 10px;
}
.mc-chatbox-hint small { font-size: 12px; }

.chatbot-disclaimer {
  display: block;
  font-size: 12px;
  line-height: 1.25;
  color: var(--chatbox-title);
  text-align: center;
  margin: 12px 0 6px;
}
.chatbot-disclaimer a {
  color: var(--chatbox-title);
  text-decoration: underline;
}

.mc-disclaimer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin: 5px 0 -5px;
}

#mc-disclaimer-hint {
  min-width: 80px;
  font-size: 14px;
  margin-left: 7px;
  line-height: 1.2;
  transition: opacity 0.18s;
  opacity: 1;
  pointer-events: auto;
  height: 14px;
  display: inline-block;
  vertical-align: middle;
}

#mc-disclaimer-toggle { display: none; }

.mc-slider-label {
  width: 36px;
  height: 20px;
  background: #ccc;
  border-radius: 18px;
  position: relative;
  display: inline-block;
  cursor: pointer;
}
.mc-slider-label::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.2s;
}
#mc-disclaimer-toggle:checked + .mc-slider-label { background: var(--chatbox-accent); }
#mc-disclaimer-toggle:checked + .mc-slider-label::before { left: 18px; background: #e0e0e0; }

.mc-chatbox-openbtn {
  background: var(--chatbox-accent);
  color: #fff;
  border: none;
  border-radius: 18px 0 0 18px;
  padding: 22px 10px;
  font-size: 16px;
  font-weight: 500;
  box-shadow: -1px 0 2px rgba(255,255,255,0.12),
              0 -1px 2px rgba(255,255,255,0.12),
              0 1px 2px rgba(255,255,255,0.12);
  cursor: pointer;
  opacity: 0.9;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  letter-spacing: 0.01em;
  display: block;
  transition: opacity 0.15s, background 0.15s, box-shadow 0.15s;
}
.mc-chatbox-openbtn:hover {
  opacity: 1;
  background: #232524;
  box-shadow: -2px 0 3px rgba(255,255,255,0.15),
              0 -2px 3px rgba(255,255,255,0.15),
              0 2px 3px rgba(255,255,255,0.15);
}

.mc-bot-btn-stack {
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.mc-chatbox-half-fullsize {
  position: fixed !important;
  top: 15px !important;
  left: 15px !important;
  right: 15px !important;
  bottom: 15px !important;
  border-radius: 18px !important;
  background: var(--chatbox-msg-bg) !important;
  box-shadow: 0 12px 48px rgba(0,0,0,0.25) !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
}

.mc-chatbox-half-fullsize .mc-chatbox-window { margin: 12px 14px 0; }
.mc-chatbox-half-fullsize .mc-chatbox-form { margin-bottom: 8px; padding: 0 14px; }

@media (max-width: 768px) {
  .mc-chatbox-fullscreen { display: none !important; }
  .mc-floating-chatbox,
  .mc-chatbox-half-fullsize {
    width: calc(100vw - 4vw) !important;
    left: 2vw !important;
    right: 2vw !important;
    bottom: 2vw !important;
    height: 68vh !important;
    max-height: 68vh !important;
    border-radius: 14px !important;
  }
  :root {
    --mc-input-rows: 2;
    --mc-input-fs: 17px;
    --mc-input-vpad: 10px;
  }
  .mc-floating-header { padding: 12px 16px; font-size: 1.06rem; }
  .mc-chatbox-title { font-size: 17px; }
  .mc-chatbox-window {
    margin: 10px 6px 0;
    padding: 18px 12px;
    font-size: clamp(1.02rem, 2.9vw, 1.15rem);
    line-height: 1.45;
  }
  .mc-msg-user,
  .mc-msg-gpt { font-size: 17px; line-height: 1.45; }
  .mc-chatbox-form { padding: 0 6px; gap: 10px; }
  .mc-chatbox-input {
    font-size: 17px;
    line-height: 1.4;
    padding: 10px 14px;
    min-height: 44px;
  }
  .mc-chatbox-sendbtn {
    font-size: 0.86rem !important;
    padding: 10px 14px;
    min-height: 44px;
    min-width: auto;
    border-radius: 12px;
  }
  .mc-chatbox-openbtn {
    border-radius: 16px 0 0 16px;
    padding: 20px 12px 20px 10px;
    font-size: 16px;
    min-height: 44px;
    box-shadow: -1px 0 2px rgba(255,255,255,0.12),
                0 -1px 2px rgba(255,255,255,0.12),
                0 1px 2px rgba(255,255,255,0.12);
  }
  .mc-chatbox-openbtn:hover {
    box-shadow: -2px 0 3px rgba(255,255,255,0.15),
                0 -2px 3px rgba(255,255,255,0.15),
                0 2px 3px rgba(255,255,255,0.15);
  }
  .chatbot-disclaimer {
    margin: 12px 1px 6px;
    padding: 0 8px;
    word-break: break-word;
    overflow-wrap: anywhere;
  }
  .chatbot-disclaimer a {
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
  }
  .mc-slider-label { width: 44px; height: 22px; border-radius: 20px; }
  .mc-slider-label::before { width: 18px; height: 18px; }
  #mc-disclaimer-hint { font-size: 12px; }
}

.mc-input-row {
  position: relative;
  width: 100%;
  max-width: 100%;
}

.mc-input-row .mc-chatbox-input {
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding-left: 44px;
  padding-right: 12px;
  line-height: var(--mc-input-lh);
  font-size: var(--mc-input-fs);
  padding-top: var(--mc-input-vpad);
  padding-bottom: var(--mc-input-vpad);
  min-height: calc(var(--mc-input-fs) * var(--mc-input-lh) + var(--mc-input-vpad) * 2 + 2px);
  max-height: calc(var(--mc-input-fs) * var(--mc-input-lh) * var(--mc-input-rows) + var(--mc-input-vpad) * 2 + 2px);
  resize: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable both-edges;
  scrollbar-width: thin;
}

.mc-mic-btn {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  cursor: pointer;
  opacity: .8;
  transition: background .15s ease, transform .15s ease, box-shadow .15s ease, color .15s ease, opacity .15s ease;
}

.mc-mic-btn:hover { opacity: 1; }
.mc-mic-btn:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.mc-mic-btn[hidden] { display: none; }
.mc-mic-btn svg { display: block; }
.mc-mic-btn svg path { fill: currentColor; }

.mc-mic-btn.active {
  background: var(--mic-blue);
  color: #fff;
  opacity: 1;
  border-radius: 50%;
  animation: mcMicBlink .9s steps(2,end) infinite, mcMicPulse 1.4s ease-in-out infinite;
}

@keyframes mcMicBlink {
  0% { filter: brightness(1); }
  50% { filter: brightness(1.15); }
  100% { filter: brightness(1); }
}

@keyframes mcMicPulse {
  0% { box-shadow: 0 0 0 0 rgba(13,110,253,.45); transform: translateY(-50%) scale(1); }
  70% { box-shadow: 0 0 0 10px rgba(13,110,253,0); transform: translateY(-50%) scale(1.02); }
  100% { box-shadow: 0 0 0 0 rgba(13,110,253,0); transform: translateY(-50%) scale(1); }
}

.mc-input-row .mc-chatbox-input::placeholder { opacity: .7; }
.mc-input-row .mc-chatbox-input::-webkit-scrollbar { width: 8px; }
.mc-input-row .mc-chatbox-input::-webkit-scrollbar-thumb { background: #9aa7b1; border-radius: 6px; }
.mc-input-row .mc-chatbox-input::-webkit-scrollbar-track { background: #f1f3f5; }

@media (max-width: 480px) {
  .mc-input-row .mc-chatbox-input {
    padding-left: 40px;
    resize: none;
    overflow-y: auto;
  }
  .mc-mic-btn {
    left: 8px;
    width: 24px;
    height: 24px;
  }
}