/* 공통 배경 & 리셋은 /css/base.css 에서 처리 */

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background-color: #ffffff;  /* 💡 완전한 흰색으로 설정 */
  font-family: var(--font, sans-serif);  /* 폰트 지정 */
}

#toggle-sidebar {
  all: unset; /* 👉 브라우저 및 글로벌 스타일 초기화 */
  position: fixed;
  top: 96px;
  left: 16px;
  z-index: 1100;
  background-color: white;
  color: #333;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 0.5rem;
  cursor: pointer;
  transition: left 0.3s ease;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
}

#toggle-icon {
  line-height: 36px;
}

/* 사이드바 전체 */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 240px;
  height: 100%;
  background-color: #f9f9f9;
  border-right: 1px solid #ddd;
  padding: 1rem;
  box-shadow: 2px 0 8px rgba(0,0,0,0.05);
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  z-index: 1000;
  overflow-y: auto;

  scrollbar-width: thin; /* Firefox용 */
  scrollbar-color: rgba(0, 0, 0, 0.05) transparent;
}

.has-app-header #sidebar {
  top: 64px;
  height: calc(100% - 64px);
}

/* Chrome, Edge, Safari용 */
#sidebar::-webkit-scrollbar {
  width: 6px;
}

#sidebar::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

#sidebar::-webkit-scrollbar-track {
  background: transparent;
}

#sidebar.open {
  transform: translateX(0);
}

#sidebar h2 {
  margin-top: 0;
  font-size: 1.2rem;
  color: #333;
}

.sidebar-header {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sidebar-subject {
  margin: 0;
  color: #1e293b;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
}

#sidebar ul {
  list-style: none;
  padding: 0;
  margin-top: 1rem;
}

.sidebar-skeleton {
  height: 16px;
  margin: 0.5rem 0;
  border-radius: 6px;
}

#sidebar li {
  margin: 0.5rem 0;
  padding: 0.5rem;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.2s;
}

#sidebar li:hover {
  background-color: #eee;
}

.chapter-title {
  font-weight: bold;
  color: #444;
  background: #e0e0e0;
  padding: 0.4rem 0.6rem;
  margin-top: 1rem;
  border-radius: 6px;
  cursor: default;
  pointer-events: none;
}

.subchapter {
  padding: 0.4rem 0.6rem;
  margin-left: 1rem;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.2s;
}

.subchapter:hover {
  background-color: #eaeaea;
}

.subchapter.active {
  background:#007aff;
  color:#fff;
}

/* ---- 채팅창 ---- */
#chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  padding: 2rem 1rem;
  margin-bottom: 100px; /* 입력창 높이만큼 여백 확보 */
}

#chat-window {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-bottom: 130px; /* 입력창과 여유 공간 */
}

#chat-window img {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  display: block;
  margin: 0.5rem 0;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

.loading-placeholder {
  text-align: center;
  color: #60748a;
  padding: 1.5rem 0;
}

.chat-skeleton {
  height: 90px;
  border-radius: 16px;
  margin-right: auto;
  width: 90%;
}

.chat-skeleton:nth-child(2) {
  height: 70px;
  margin-left: auto;
  margin-right: 0;
  width: 85%;
}

.chat-skeleton:nth-child(3) {
  height: 60px;
  width: 70%;
}

form {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 800px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  gap: 0.5rem;
  border-top: 1px solid #eee;
  background: white;
  z-index: 100;
  align-items: flex-end;
}

.input-area textarea {
  flex: 1;
  padding: 0.4rem 1rem 0.3rem 1rem;
  font-size: 1rem;
  border-radius: 20px;
  border: 1px solid #ccc;
  outline: none;
  resize: none;
  line-height: 1.5;
  font-family: inherit;

  height: 30px;
  overflow-y: hidden;
}

.input-area textarea:focus {
  border-color: #007aff;
}

form button[type="submit"] {
  border-radius: 20px;
  background-color: #007aff;
  color: white;
  font-weight: bold;
  border: none;
  cursor: pointer;
  padding: 0.4rem 1.2rem;
  height: 40px;
  flex: 0 0 auto;
  align-self: flex-end;
}

.btn-reset {
  position: fixed;
  right: 24px;
  bottom: 28px;
  background-color: #e3eaf3;
  color: #1e2a38;
  border: none;
  border-radius: 999px;
  font-weight: 600;
  padding: 0.45rem 1.1rem;
  cursor: pointer;
  transition: background-color 0.2s ease;
  height: 40px;
  z-index: 150;
}

.input-area {
  flex: 1 1 240px;
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

form button[type="submit"]:hover {
  background-color: #0060dd;
}

.btn-reset:hover {
  background-color: #cfd9ea;
}

.btn-reset:disabled {
  opacity: 0.6;
  cursor: default;
}



/* ---- 반응형: 작은 화면에서 사이드바 오버레이 ---- */
@media (max-width: 768px) {
  #chat-container { margin-left: 0; }
  #sidebar.open { transform: translateX(0); }
  /* 채팅창 좁은 화면 대응 */
  #chat-container {
    padding: 1rem 0.5rem;
    font-size: 0.95rem;
  }

  #chat-window {
    padding-bottom: 100px;  /* 모바일은 입력창이 작으니 여유 줄이기 */
  }

  form {
    padding: 0.5rem;
    gap: 0.3rem;
  }

  textarea {
    font-size: 0.9rem;
    padding: 0.3rem 0.8rem;
  }

  form button[type="submit"] {
    padding: 0.3rem 0.8rem;
    font-size: 0.9rem;
    height: 36px;
  }

  .btn-reset {
    right: 16px;
    bottom: 22px;
    padding: 0.35rem 0.9rem;
    font-size: 0.9rem;
    height: 36px;
  }

  .assistant, .user {
    font-size: 0.95rem;
    max-width: 90%;
    padding: 0.5rem 0.8rem;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  #chat-container {
    padding: 1.5rem 1rem;
    font-size: 1rem;
  }

  .assistant, .user {
    font-size: 1rem;
    max-width: 85%;
  }
}

/* ---- 코드 블록 스타일 ---- */
pre code {
  background: #2d2d2d;
  color: #f8f8f2;
  display: block;
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
}

/* assistant 메시지 스타일 */
.assistant {
  align-self: flex-start;
  background-color: #f1f1f1;
  color: #000000;
  max-width: 80%;
  padding: 0.5rem 1rem;
  border-radius: 18px;
  font-size: 1rem;
  line-height: 1.6;
  word-break: break-word;
  white-space: normal;
}

/* user 메시지 스타일도 추가해두면 안정적 */
.user {
  align-self: flex-end;
  background-color: #007aff;
  color: #ffffff;
  max-width: 80%;
  padding: 0.5rem 1rem;
  border-radius: 18px;
  font-size: 1rem;
  line-height: 1.6;
  word-break: break-word;
  white-space: normal;
}

/* ===== 모달 ===== */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

#modal-box {
  background: white;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  max-width: 90%;
  width: 360px;
  text-align: center;
  font-size: 1rem;
}

.modal-btns {
  margin-top: 1rem;
  display: flex;
  justify-content: center;
  gap: 1rem;
}

.modal-btns button {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
}

#modal-ok {
  background: #007aff;
  color: white;
}

#modal-cancel {
  background: #ccc;
  color: black;
}

/* 숨김 처리 */
.hidden { display: none !important; }

/* assistant 로딩 상태 깜빡임 */
.assistant.loading {
  animation: blink 1s infinite ease-in-out;
  opacity: 0.6;
}

/* 깜빡이는 효과 정의 */
@keyframes blink {
  0%   { opacity: 0.2; }
  50%  { opacity: 1; }
  100% { opacity: 0.2; }
}

/* 데스크톱(>768 px)에서, 사이드바가 열렸을 때 메인 영역 ½ 너비만큼 이동 */
@media (min-width: 769px) {
  #sidebar.open ~ #chat-container,
  #sidebar.open ~ form {                 /* 입력창(form)까지 같이 이동 */
    transform: translateX(120px);        /* 240 px 사이드바의 절반 = 120 px */
    transition: transform 0.3s ease;
  }
}
