* {
  box-sizing: border-box;
}

/* 범용 숨김 유틸 (.app-stage/.auth-gate 등 자체 display 규칙을 항상 이기도록 !important) */
.hidden {
  display: none !important;
}

html {
  height: 100%;
}

body {
  /* --app-height: JS가 window.innerHeight(실제 보이는 높이)로 채움 → 모바일 주소창
     접힘/펼침에도 입력창이 화면 아래로 밀리지 않게 고정. 미설정 시 100vh 폴백. */
  height: var(--app-height, 100vh);
  margin: 0;
  overscroll-behavior: none;
  font-family:
    "Noto Sans KR",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  background: linear-gradient(135deg, #68dcff 0%, #f7fbff 100%);
  /* 웹: 광고를 좌측 세로 컬럼으로, 나머지(로그인/챗봇)가 우측을 채움 */
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

/* 광고 영역: 웹에서는 좌측 세로 패널 (모바일은 하단 media query에서 상단 가로 배너로 전환) */
.ad-banner {
  flex: 0 0 auto;
  width: 168px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  padding: 16px 12px;
  background: #d1d5db;
  border-right: 1px solid #b9bfc7;
}

.ad-slot {
  flex: 1;
  width: 100%;
  max-height: 760px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed #9aa1ab;
  border-radius: 12px;
  background: #e5e7eb;
  color: #5b626b;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.6;
  text-align: center;
  padding: 16px;
}

.app-stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
}

button {
  border: none;
  cursor: pointer;
  font-weight: 700;
  transition:
    background 0.2s ease,
    transform 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
}

/* ===== 로그인 게이트 (첫 화면) ===== */
.auth-gate {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px 16px;
  overflow-y: auto;
}

.auth-card {
  width: min(400px, 100%);
  background: #ffffff;
  border-radius: 18px;
  box-shadow: 0 16px 40px rgba(0, 70, 120, 0.18);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.auth-brand {
  text-align: center;
}

.auth-sub {
  margin: 8px 0 0;
  color: #5a6b75;
  font-size: 13px;
  line-height: 1.5;
}

.auth-sub.error {
  color: #c92a2a;
}

.auth-tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: #eef4f8;
  border-radius: 999px;
}

.auth-tab {
  flex: 1;
  padding: 9px 0;
  border-radius: 999px;
  background: transparent;
  color: #5a6b75;
  font-size: 14px;
}

.auth-tab.active {
  background: #ffffff;
  color: #0c5e88;
  box-shadow: 0 2px 6px rgba(0, 70, 120, 0.12);
}

.auth-tab:hover {
  transform: none;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-form button[type="submit"] {
  margin-top: 2px;
  padding: 11px 20px;
  background: #00aeff;
  color: #ffffff;
  border-radius: 999px;
  font-size: 14px;
}

.auth-form button[type="submit"]:hover {
  background: #008ed1;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #9aa7b1;
  font-size: 12px;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #e1e8ee;
}

.kakao-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  border-radius: 999px;
  background: #fee500;
  color: #191600;
  font-size: 14px;
}

.kakao-btn:hover {
  background: #f5dc00;
}

.kakao-icon {
  display: inline-flex;
  align-items: center;
}

.kakao-consent {
  margin: -6px 0 0;
  text-align: center;
  font-size: 11px;
  line-height: 1.5;
  color: #8a98a3;
}

.kakao-consent a {
  color: #007db8;
  font-weight: 700;
}

.app-container {
  width: min(1040px, 100%);
  height: min(760px, 100%);
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(0, 70, 120, 0.18);
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  background: #f5f9fc;
  border-right: 1px solid #d9ebf5;
  padding: 18px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #007db8;
  font-size: 12px;
  font-weight: 800;
}

h1 {
  margin: 0;
  color: #172b3a;
  font-size: 22px;
}

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #00aeff;
  color: #ffffff;
  font-size: 24px;
  line-height: 1;
}

/* 건의사항 등 보조 아이콘 버튼: 흰 배경 + 테두리로 +(새 채팅)와 구분 */
.icon-btn.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border: 1px solid #cfe3ef;
  font-size: 17px;
}

.icon-btn.ghost:hover {
  background: #e8f7ff;
}

.new-chat-btn {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  background: #00aeff;
  color: #ffffff;
  font-size: 14px;
  margin-bottom: 18px;
}

.icon-btn:hover,
.new-chat-btn:hover,
#send-btn:hover {
  background: #008ed1;
}

.session-panel {
  min-height: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
}

.session-title {
  color: #5a6b75;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 8px;
}

.session-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 2px;
}

.session-item {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #dbeaf3;
  border-radius: 8px;
  background: #ffffff;
  color: #273844;
  text-align: left;
}

.session-item.active {
  border-color: #00aeff;
  background: #e8f7ff;
}

.session-item-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.session-item-time,
.session-empty {
  color: #7a8b96;
  font-size: 12px;
}

.session-item-time {
  display: block;
  margin-top: 4px;
}

.session-empty {
  padding: 12px 4px;
  line-height: 1.5;
}

.chat-shell {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.header {
  background: #00aeff;
  color: white;
  padding: 15px 18px;
  font-weight: bold;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.auth-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.signup-btn {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.5);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
}

.signup-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* 사이드바 토글 버튼 / 배경: 웹에서는 숨김 (모바일 media query에서만 노출) */
.sidebar-toggle {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

input {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid #c7d5dd;
  border-radius: 999px;
  outline: none;
  font-size: 14px;
}

input:focus {
  border-color: #00aeff;
  box-shadow: 0 0 0 3px rgba(0, 174, 255, 0.16);
}

.agree-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #333;
  text-align: left;
}

.agree-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-width: 16px;
  padding: 0;
  border-radius: 4px;
  accent-color: #00aeff;
  cursor: pointer;
  flex-shrink: 0;
}

.agree-row a {
  color: #007db8;
  font-weight: 700;
}

#signup-status,
#login-status {
  margin-top: 10px;
  font-size: 12px;
  white-space: pre-line;
  min-height: 16px;
}

#signup-status.success,
#login-status.success {
  color: #16833a;
}

#signup-status.error,
#login-status.error {
  color: #c92a2a;
}

#signup-status.loading,
#login-status.loading {
  color: #58656d;
}

.chat-window {
  flex: 1;
  min-height: 0;
  padding: 20px;
  overflow-y: auto;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.input-area {
  padding: 15px;
  background: #f0f6fa;
  display: flex;
  gap: 10px;
}

.input-area input {
  flex: 1;
}

#send-btn {
  padding: 10px 20px;
  background: #00aeff;
  color: white;
  border-radius: 999px;
}

#send-btn:disabled,
.input-area input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

#send-btn:disabled:hover {
  transform: none;
  background: #00aeff;
}

.feedback-hint {
  padding: 8px 15px 0;
  color: #c92a2a;
  font-size: 12px;
  background: #f0f6fa;
}

.feedback-hint.shake {
  animation: fb-shake 0.4s ease;
}

@keyframes fb-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

.source-line {
  align-self: flex-start;
  max-width: min(80%, 620px);
  margin: -4px 0 2px;
  padding-left: 4px;
  font-size: 11px;
  color: #8a98a3;
  word-break: break-word;
}

/* ===== 피드백 위젯 ===== */
.feedback {
  align-self: flex-start;
  max-width: min(80%, 620px);
  margin: -2px 0 4px;
  padding: 8px 12px;
  border: 1px solid #e1e8ee;
  border-radius: 12px;
  background: #f7fafc;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fb-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fb-q {
  font-size: 12px;
  color: #5a6b75;
  margin-right: 2px;
}

.fb-btn {
  width: 34px;
  height: 28px;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid #d4dee6;
  font-size: 15px;
  line-height: 1;
}

.fb-btn:hover {
  background: #eef5fa;
}

.fb-btn.active {
  border-color: #00aeff;
  background: #e8f7ff;
}

.fb-reasons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.fb-chip {
  padding: 5px 12px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid #d4dee6;
  color: #44545f;
  font-size: 12px;
  font-weight: 600;
}

.fb-chip:hover {
  border-color: #00aeff;
  background: #e8f7ff;
  color: #0c5e88;
}

.fb-summary {
  font-size: 12px;
  font-weight: 700;
  color: #0c5e88;
}

.fb-comment-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.fb-comment {
  width: 100%;
  border: 1px solid #d4dee6;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  outline: none;
}

.fb-comment:focus {
  border-color: #00aeff;
  box-shadow: 0 0 0 3px rgba(0, 174, 255, 0.16);
}

.fb-comment-submit {
  align-self: flex-start;
  padding: 6px 14px;
  border-radius: 999px;
  background: #00aeff;
  color: #ffffff;
  font-size: 12px;
}

.fb-comment-submit:hover {
  background: #008ed1;
}

.fb-comment-submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.fb-done {
  font-size: 12px;
  color: #16833a;
  font-weight: 700;
}

.message {
  max-width: min(80%, 620px);
  padding: 10px 15px;
  border-radius: 15px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.user {
  align-self: flex-end;
  background: #68dcff;
  color: #101820;
  border-bottom-right-radius: 4px;
}

.bot {
  align-self: flex-start;
  background: #e9eef2;
  color: #101820;
  border-bottom-left-radius: 4px;
}

.message.loading {
  display: flex;
  gap: 4px;
  align-items: center;
  min-height: 20px;
}

.message.loading .dot {
  width: 5px;
  height: 5px;
  background: #6b7a84;
  border-radius: 50%;
  opacity: 0;
  animation: loading-dot 1.2s infinite;
}

.message.loading .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.message.loading .dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes loading-dot {
  0%,
  20% {
    opacity: 0;
  }
  30%,
  70% {
    opacity: 1;
  }
  80%,
  100% {
    opacity: 0;
  }
}

/* ===== 건의사항 모달 ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(16, 40, 56, 0.45);
}

.modal-card {
  width: min(460px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 70, 120, 0.28);
  padding: 22px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
  color: #172b3a;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #f0f6fa;
  color: #5a6b75;
  font-size: 20px;
  line-height: 1;
}

.modal-close:hover {
  background: #e1ecf3;
  transform: none;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: #44545f;
}

.modal-label select,
.modal-label textarea,
.modal-label input {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  font-weight: 400;
  padding: 10px 12px;
  border: 1px solid #c7d5dd;
  border-radius: 10px;
  outline: none;
}

.modal-label textarea {
  resize: vertical;
  min-height: 96px;
}

.modal-label select:focus,
.modal-label textarea:focus,
.modal-label input:focus {
  border-color: #00aeff;
  box-shadow: 0 0 0 3px rgba(0, 174, 255, 0.16);
}

.modal-submit {
  margin-top: 2px;
  padding: 11px 20px;
  background: #00aeff;
  color: #ffffff;
  border-radius: 999px;
  font-size: 14px;
}

.modal-submit:hover {
  background: #008ed1;
}

.modal-submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.modal-status {
  margin: 0;
  font-size: 12px;
  min-height: 16px;
  white-space: pre-line;
}

.modal-status.success {
  color: #16833a;
}

.modal-status.error {
  color: #c92a2a;
}

.modal-status.loading {
  color: #58656d;
}

@media (max-width: 760px) {
  /* 모바일: 광고를 상단 가로 배너로 (세로 컬럼 → 위/아래 스택) */
  body {
    flex-direction: column;
    /* JS가 채우기 전 폴백은 dvh(주소창 반영) → 입력창이 화면 밖으로 안 밀림 */
    height: var(--app-height, 100dvh);
  }

  .ad-banner {
    flex: 0 0 auto;
    width: 100%;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    padding: 8px 8px 0;
    border-right: none;
    border-bottom: 1px solid #b9bfc7;
  }

  .ad-slot {
    flex: 0 0 auto;
    width: min(970px, 100%);
    height: 60px;
    max-height: none;
    padding: 0 16px;
    line-height: 1.4;
  }

  .app-stage {
    padding: 8px;
  }

  /* 모바일: 사이드바를 그리드에서 빼고(채팅이 전체를 차지) 헤더 토글로 여닫는 드롭다운으로 */
  .app-container {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 14px;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
  }

  /* 토글 버튼 노출 (헤더 좌측) */
  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.5);
    font-size: 18px;
    line-height: 1;
  }

  .sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: none;
  }

  /* 사이드바: 컨테이너 상단에서 아래로 내려오는 드롭다운 오버레이 */
  .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
    max-height: 80%;
    border-right: none;
    border-bottom: 1px solid #d9ebf5;
    border-radius: 0 0 14px 14px;
    padding: 12px 12px 16px;
    box-shadow: 0 14px 28px rgba(0, 70, 120, 0.22);
    transform: translateY(-100%);
    transition: transform 0.28s ease;
  }

  .app-container.sidebar-open .sidebar {
    transform: translateY(0);
  }

  /* 드롭다운 뒤 배경 (열렸을 때만 클릭 가능) */
  .sidebar-backdrop {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 15;
    background: rgba(16, 40, 56, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
  }

  .app-container.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-header {
    margin-bottom: 10px;
  }

  .session-item {
    min-width: 0;
  }

  .header {
    padding: 12px;
  }

  .chat-window {
    padding: 14px;
  }
}

/* ===== 라이트/다크 토글 버튼 ===== */
.theme-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 90;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(0, 70, 120, 0.15);
  box-shadow: 0 4px 12px rgba(0, 70, 120, 0.18);
}

.theme-toggle:hover {
  background: #ffffff;
}

/* ===== 다크 모드 ===== */
html.dark body {
  background: linear-gradient(135deg, #2c4d56 0%, #14242a 100%);
  color: #e6edf2;
}

/* 다크 모드 액센트: 밝은 시안(#00aeff) → 차분한 틸 */
.dark .header {
  background: #4d8c9e;
}

.dark .new-chat-btn,
.dark .icon-btn,
.dark #send-btn,
.dark .auth-form button[type="submit"],
.dark .modal-submit {
  background: #4d8c9e;
}

.dark .new-chat-btn:hover,
.dark .icon-btn:hover,
.dark #send-btn:hover,
.dark .auth-form button[type="submit"]:hover,
.dark .modal-submit:hover {
  background: #41798a;
}

/* 건의사항(📝) 아이콘 버튼은 외곽선형으로 구분 유지 */
.dark .icon-btn.ghost {
  background: #1d2930;
  border-color: #33424d;
}

.dark .icon-btn.ghost:hover {
  background: #243a47;
}

.dark .eyebrow {
  color: #6fb3c6;
}

.dark input:focus,
.dark textarea:focus,
.dark select:focus,
.dark .modal-label input:focus,
.dark .modal-label textarea:focus,
.dark .modal-label select:focus {
  border-color: #4d8c9e;
  box-shadow: 0 0 0 3px rgba(77, 140, 158, 0.25);
}

.dark .theme-toggle {
  background: rgba(30, 40, 50, 0.9);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.dark .theme-toggle:hover {
  background: #243039;
}

.dark .ad-banner {
  background: #161d24;
  border-color: #2a3742;
}

.dark .ad-slot {
  background: #1e2832;
  border-color: #3a4a55;
  color: #9fb0bc;
}

.dark .auth-card,
.dark .app-container,
.dark .modal-card {
  background: #1b2a31;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.dark h1,
.dark .modal-head h2 {
  color: #e6edf2;
}

.dark .auth-sub {
  color: #9fb0bc;
}

.dark .auth-tabs {
  background: #16212a;
}

.dark .auth-tab {
  color: #9fb0bc;
}

.dark .auth-tab.active {
  background: #243039;
  color: #74c2d6;
}

.dark .auth-divider {
  color: #6b7a85;
}

.dark .auth-divider::before,
.dark .auth-divider::after {
  background: #2c3a45;
}

.dark .sidebar {
  background: #121b20;
  border-color: #243139;
}

.dark .session-title,
.dark .fb-q {
  color: #9fb0bc;
}

.dark .session-item {
  background: #1c272d;
  border-color: #2b3a42;
  color: #cdd6dd;
}

.dark .session-item.active {
  border-color: #3fa3c4;
  background: #1c3640;
}

.dark .session-item-time,
.dark .session-empty,
.dark .source-line {
  color: #8395a1;
}

.dark .chat-window {
  background: #16252b;
}

.dark .input-area,
.dark .feedback-hint {
  background: #15222a;
}

.dark input,
.dark textarea,
.dark select,
.dark .modal-label input,
.dark .modal-label textarea,
.dark .modal-label select {
  background: #333b41;
  border-color: #424a51;
  color: #e6edf2;
}

.dark input::placeholder,
.dark textarea::placeholder {
  color: #6b7a85;
}

.dark .modal-label {
  color: #c2cdd6;
}

.dark .agree-row {
  color: #c2cdd6;
}

.dark .modal-close {
  background: #243039;
  color: #cdd6dd;
}

.dark .modal-close:hover {
  background: #2c3a45;
}

.dark .bot {
  background: #26323d;
  color: #e6edf2;
}

.dark .feedback {
  background: #1b262f;
  border-color: #2c3a45;
}

.dark .fb-btn,
.dark .fb-chip {
  background: #1f2c36;
  border-color: #33424d;
  color: #cdd6dd;
}

.dark .fb-btn:hover,
.dark .fb-chip:hover {
  background: #243a47;
}

.dark .fb-summary {
  color: #74c2d6;
}
